]> sourceware.org Git - lvm2.git/commitdiff
Add pv_mda_size, pv_mda_free, and pv_used functions, call from 'disp' functions.
authorDave Wysochanski <dwysocha@redhat.com>
Thu, 30 Sep 2010 14:09:10 +0000 (14:09 +0000)
committerDave Wysochanski <dwysocha@redhat.com>
Thu, 30 Sep 2010 14:09:10 +0000 (14:09 +0000)
lib/metadata/pv.c
lib/metadata/pv.h
lib/report/report.c

index 5d2969373b4de7879ef5270a5205385eb517e1cf..8b4dbf572aeb736fa33a77e6a902f9e92912c713 100644 (file)
@@ -187,6 +187,50 @@ char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv)
        return repstr;
 }
 
+uint64_t pv_mda_size(const struct physical_volume *pv)
+{
+       struct lvmcache_info *info;
+       uint64_t min_mda_size = 0;
+       const char *pvid = (const char *)(&pv->id.uuid);
+
+       /* PVs could have 2 mdas of different sizes (rounding effect) */
+       if ((info = info_from_pvid(pvid, 0)))
+               min_mda_size = find_min_mda_size(&info->mdas);
+       return min_mda_size;
+}
+
+uint64_t pv_mda_free(const struct physical_volume *pv)
+{
+       struct lvmcache_info *info;
+       uint64_t freespace = UINT64_MAX, mda_free;
+       const char *pvid = (const char *)&pv->id.uuid;
+       struct metadata_area *mda;
+
+       if ((info = info_from_pvid(pvid, 0)))
+               dm_list_iterate_items(mda, &info->mdas) {
+                       if (!mda->ops->mda_free_sectors)
+                               continue;
+                       mda_free = mda->ops->mda_free_sectors(mda);
+                       if (mda_free < freespace)
+                               freespace = mda_free;
+               }
+
+       if (freespace == UINT64_MAX)
+               freespace = UINT64_C(0);
+       return freespace;
+}
+
+uint64_t pv_used(const struct physical_volume *pv)
+{
+       uint64_t used;
+
+       if (!pv->pe_count)
+               used = 0LL;
+       else
+               used = (uint64_t) pv->pe_alloc_count * pv->pe_size;
+       return used;
+}
+
 unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored)
 {
        struct lvmcache_info *info;
index 14133c7129ca18910bab685c4df583e84703167e..295f811002e29aac37da51a504e1e666fd176d78 100644 (file)
@@ -67,6 +67,9 @@ uint32_t pv_pe_size(const struct physical_volume *pv);
 uint64_t pv_pe_start(const struct physical_volume *pv);
 uint32_t pv_pe_count(const struct physical_volume *pv);
 uint32_t pv_pe_alloc_count(const struct physical_volume *pv);
+uint64_t pv_mda_size(const struct physical_volume *pv);
+uint64_t pv_mda_free(const struct physical_volume *pv);
+uint64_t pv_used(const struct physical_volume *pv);
 uint32_t pv_mda_count(const struct physical_volume *pv);
 uint32_t pv_mda_used_count(const struct physical_volume *pv);
 unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored);
index cac4f8beda7b0e29aa64bf41e0a1214c846f0733..95f4550d2950f3d6c8d507540a6a6d7866d028df 100644 (file)
@@ -597,10 +597,7 @@ static int _pvused_disp(struct dm_report *rh, struct dm_pool *mem,
            (const struct physical_volume *) data;
        uint64_t used;
 
-       if (!pv->pe_count)
-               used = 0LL;
-       else
-               used = (uint64_t) pv->pe_alloc_count * pv->pe_size;
+       used = pv_used(pv);
 
        return _size64_disp(rh, mem, field, &used, private);
 }
@@ -754,22 +751,11 @@ static int _pvmdafree_disp(struct dm_report *rh, struct dm_pool *mem,
                           struct dm_report_field *field,
                           const void *data, void *private)
 {
-       struct lvmcache_info *info;
-       uint64_t freespace = UINT64_MAX, mda_free;
-       const char *pvid = (const char *)(&((const struct id *) data)->uuid);
-       struct metadata_area *mda;
-
-       if ((info = info_from_pvid(pvid, 0)))
-               dm_list_iterate_items(mda, &info->mdas) {
-                       if (!mda->ops->mda_free_sectors)
-                               continue;
-                       mda_free = mda->ops->mda_free_sectors(mda);
-                       if (mda_free < freespace)
-                               freespace = mda_free;
-               }
+       const struct physical_volume *pv =
+           (const struct physical_volume *) data;
+       uint64_t freespace;
 
-       if (freespace == UINT64_MAX)
-               freespace = UINT64_C(0);
+       freespace = pv_mda_free(pv);
 
        return _size64_disp(rh, mem, field, &freespace, private);
 }
@@ -778,13 +764,11 @@ static int _pvmdasize_disp(struct dm_report *rh, struct dm_pool *mem,
                           struct dm_report_field *field,
                           const void *data, void *private)
 {
-       struct lvmcache_info *info;
-       uint64_t min_mda_size = 0;
-       const char *pvid = (const char *)(&((const struct id *) data)->uuid);
+       const struct physical_volume *pv =
+           (const struct physical_volume *) data;
+       uint64_t min_mda_size;
 
-       /* PVs could have 2 mdas of different sizes (rounding effect) */
-       if ((info = info_from_pvid(pvid, 0)))
-               min_mda_size = find_min_mda_size(&info->mdas);
+       min_mda_size = pv_mda_size(pv);
 
        return _size64_disp(rh, mem, field, &min_mda_size, private);
 }
This page took 0.036333 seconds and 5 git commands to generate.