~ubuntu-branches/ubuntu/vivid/lvm2/vivid

« back to all changes in this revision

Viewing changes to lib/metadata/pv.c

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2012-05-01 20:27:50 UTC
  • mto: (3.1.23 sid)
  • mto: This revision was merged to the branch mainline in revision 72.
  • Revision ID: package-import@ubuntu.com-20120501202750-gljjjtblowwq9mw8
Tags: upstream-2.02.95
ImportĀ upstreamĀ versionĀ 2.02.95

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
{
144
144
        struct lvmcache_info *info;
145
145
 
146
 
        info = info_from_pvid((const char *)&pv->id.uuid, 0);
147
 
        return info ? dm_list_size(&info->mdas) : UINT64_C(0);
 
146
        info = lvmcache_info_from_pvid((const char *)&pv->id.uuid, 0);
 
147
        return info ? lvmcache_mda_count(info) : UINT64_C(0);
 
148
}
 
149
 
 
150
static int _count_unignored(struct metadata_area *mda, void *baton)
 
151
{
 
152
        uint32_t *count = baton;
 
153
        if (!mda_is_ignored(mda))
 
154
                (*count) ++;
 
155
        return 1;
148
156
}
149
157
 
150
158
uint32_t pv_mda_used_count(const struct physical_volume *pv)
151
159
{
152
160
        struct lvmcache_info *info;
153
 
        struct metadata_area *mda;
154
161
        uint32_t used_count=0;
155
162
 
156
 
        info = info_from_pvid((const char *)&pv->id.uuid, 0);
 
163
        info = lvmcache_info_from_pvid((const char *)&pv->id.uuid, 0);
157
164
        if (!info)
158
165
                return 0;
159
 
        dm_list_iterate_items(mda, &info->mdas) {
160
 
                if (!mda_is_ignored(mda))
161
 
                        used_count++;
162
 
        }
 
166
        lvmcache_foreach_mda(info, _count_unignored, &used_count);
163
167
        return used_count;
164
168
}
165
169
 
190
194
{
191
195
        char *repstr;
192
196
 
193
 
        if (!(repstr = dm_pool_zalloc(mem, 3))) {
 
197
        if (!(repstr = dm_pool_zalloc(mem, 4))) {
194
198
                log_error("dm_pool_alloc failed");
195
199
                return NULL;
196
200
        }
198
202
        repstr[0] = (pv->status & ALLOCATABLE_PV) ? 'a' : '-';
199
203
        repstr[1] = (pv->status & EXPORTED_VG) ? 'x' : '-';
200
204
        repstr[2] = (pv->status & MISSING_PV) ? 'm' : '-';
 
205
 
201
206
        return repstr;
202
207
}
203
208
 
208
213
        const char *pvid = (const char *)(&pv->id.uuid);
209
214
 
210
215
        /* PVs could have 2 mdas of different sizes (rounding effect) */
211
 
        if ((info = info_from_pvid(pvid, 0)))
212
 
                min_mda_size = find_min_mda_size(&info->mdas);
 
216
        if ((info = lvmcache_info_from_pvid(pvid, 0)))
 
217
                min_mda_size = lvmcache_smallest_mda_size(info);
213
218
        return min_mda_size;
214
219
}
215
220
 
 
221
static int _pv_mda_free(struct metadata_area *mda, void *baton) {
 
222
        uint64_t mda_free;
 
223
        uint64_t *freespace = baton;
 
224
 
 
225
        if (!mda->ops->mda_free_sectors)
 
226
                return 1;
 
227
 
 
228
        mda_free = mda->ops->mda_free_sectors(mda);
 
229
        if (mda_free < *freespace)
 
230
                *freespace = mda_free;
 
231
        return 1;
 
232
}
 
233
 
216
234
uint64_t pv_mda_free(const struct physical_volume *pv)
217
235
{
218
236
        struct lvmcache_info *info;
219
 
        uint64_t freespace = UINT64_MAX, mda_free;
 
237
        uint64_t freespace = UINT64_MAX;
220
238
        const char *pvid = (const char *)&pv->id.uuid;
221
 
        struct metadata_area *mda;
222
239
 
223
 
        if ((info = info_from_pvid(pvid, 0)))
224
 
                dm_list_iterate_items(mda, &info->mdas) {
225
 
                        if (!mda->ops->mda_free_sectors)
226
 
                                continue;
227
 
                        mda_free = mda->ops->mda_free_sectors(mda);
228
 
                        if (mda_free < freespace)
229
 
                                freespace = mda_free;
230
 
                }
 
240
        if ((info = lvmcache_info_from_pvid(pvid, 0)))
 
241
                lvmcache_foreach_mda(info, _pv_mda_free, &freespace);
231
242
 
232
243
        if (freespace == UINT64_MAX)
233
244
                freespace = UINT64_C(0);
 
245
 
234
246
        return freespace;
235
247
}
236
248
 
245
257
        return used;
246
258
}
247
259
 
 
260
struct _pv_mda_set_ignored_baton {
 
261
        unsigned mda_ignored;
 
262
        struct dm_list *mdas_in_use, *mdas_ignored, *mdas_to_change;
 
263
};
 
264
 
 
265
static int _pv_mda_set_ignored_one(struct metadata_area *mda, void *baton)
 
266
{
 
267
        struct _pv_mda_set_ignored_baton *b = baton;
 
268
        struct metadata_area *vg_mda, *tmda;
 
269
 
 
270
        if (mda_is_ignored(mda) && !b->mda_ignored) {
 
271
                /* Changing an ignored mda to one in_use requires moving it */
 
272
                dm_list_iterate_items_safe(vg_mda, tmda, b->mdas_ignored)
 
273
                        if (mda_locns_match(mda, vg_mda)) {
 
274
                                mda_set_ignored(vg_mda, b->mda_ignored);
 
275
                                dm_list_move(b->mdas_in_use, &vg_mda->list);
 
276
                        }
 
277
        }
 
278
 
 
279
        dm_list_iterate_items_safe(vg_mda, tmda, b->mdas_in_use)
 
280
                if (mda_locns_match(mda, vg_mda))
 
281
                        /* Don't move mda: needs writing to disk. */
 
282
                        mda_set_ignored(vg_mda, b->mda_ignored);
 
283
 
 
284
        mda_set_ignored(mda, b->mda_ignored);
 
285
        return 1;
 
286
}
 
287
 
248
288
unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored)
249
289
{
250
290
        struct lvmcache_info *info;
251
 
        struct metadata_area *mda, *vg_mda, *tmda;
252
 
        struct dm_list *mdas_in_use, *mdas_ignored, *mdas_to_change;
 
291
        struct _pv_mda_set_ignored_baton baton;
 
292
        struct metadata_area *mda;
253
293
 
254
 
        if (!(info = info_from_pvid((const char *)&pv->id.uuid, 0)))
 
294
        if (!(info = lvmcache_info_from_pvid((const char *)&pv->id.uuid, 0)))
255
295
                return_0;
256
296
 
257
 
        mdas_in_use = &pv->fid->metadata_areas_in_use;
258
 
        mdas_ignored = &pv->fid->metadata_areas_ignored;
259
 
        mdas_to_change = mda_ignored ? mdas_in_use : mdas_ignored;
 
297
        baton.mda_ignored = mda_ignored;
 
298
        baton.mdas_in_use = &pv->fid->metadata_areas_in_use;
 
299
        baton.mdas_ignored = &pv->fid->metadata_areas_ignored;
 
300
        baton.mdas_to_change = baton.mda_ignored ? baton.mdas_in_use : baton.mdas_ignored;
260
301
 
261
302
        if (is_orphan(pv)) {
262
 
                dm_list_iterate_items(mda, mdas_to_change)
263
 
                        mda_set_ignored(mda, mda_ignored);
 
303
                dm_list_iterate_items(mda, baton.mdas_to_change)
 
304
                        mda_set_ignored(mda, baton.mda_ignored);
264
305
                return 1;
265
306
        }
266
307
 
287
328
        /* FIXME: Try not to update the cache here! Also, try to iterate over
288
329
         *        PV mdas only using the format instance's index somehow
289
330
         *        (i.e. try to avoid using mda_locn_match call). */
290
 
        dm_list_iterate_items(mda, &info->mdas) {
291
 
                if (mda_is_ignored(mda) && !mda_ignored)
292
 
                        /* Changing an ignored mda to one in_use requires moving it */
293
 
                        dm_list_iterate_items_safe(vg_mda, tmda, mdas_ignored)
294
 
                                if (mda_locns_match(mda, vg_mda)) {
295
 
                                        mda_set_ignored(vg_mda, mda_ignored);
296
 
                                        dm_list_move(mdas_in_use, &vg_mda->list);
297
 
                                }
298
 
 
299
 
                dm_list_iterate_items_safe(vg_mda, tmda, mdas_in_use)
300
 
                        if (mda_locns_match(mda, vg_mda))
301
 
                                /* Don't move mda: needs writing to disk. */
302
 
                                mda_set_ignored(vg_mda, mda_ignored);
303
 
 
304
 
                mda_set_ignored(mda, mda_ignored);
305
 
        }
 
331
 
 
332
        lvmcache_foreach_mda(info, _pv_mda_set_ignored_one, &baton);
306
333
 
307
334
        return 1;
308
335
}