~ubuntu-branches/debian/sid/lvm2/sid

« back to all changes in this revision

Viewing changes to lib/metadata/pv_manip.c

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2014-08-19 15:37:06 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20140819153706-i1gaio8lg534dara
Tags: 2.02.109-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
246
246
        return 1;
247
247
}
248
248
 
 
249
static int _merge_free_pv_segment(struct pv_segment *peg)
 
250
{
 
251
        struct dm_list *l;
 
252
        struct pv_segment *merge_peg;
 
253
 
 
254
        if (peg->lvseg) {
 
255
                log_error(INTERNAL_ERROR
 
256
                          "_merge_free_pv_seg called on a"
 
257
                          " segment that is not free.");
 
258
                return 0;
 
259
        }
 
260
 
 
261
        /*
 
262
         * FIXME:
 
263
         * Should we free the list element once it is deleted
 
264
         * from the list?  I think not.  It is likely part of
 
265
         * a mempool.
 
266
         */
 
267
        /* Attempt to merge with Free space before */
 
268
        if ((l = dm_list_prev(&peg->pv->segments, &peg->list))) {
 
269
                merge_peg = dm_list_item(l, struct pv_segment);
 
270
                if (!merge_peg->lvseg) {
 
271
                        merge_peg->len += peg->len;
 
272
                        dm_list_del(&peg->list);
 
273
                        peg = merge_peg;
 
274
                }
 
275
        }
 
276
 
 
277
        /* Attempt to merge with Free space after */
 
278
        if ((l = dm_list_next(&peg->pv->segments, &peg->list))) {
 
279
                merge_peg = dm_list_item(l, struct pv_segment);
 
280
                if (!merge_peg->lvseg) {
 
281
                        peg->len += merge_peg->len;
 
282
                        dm_list_del(&merge_peg->list);
 
283
                }
 
284
        }
 
285
 
 
286
        return 1;
 
287
}
 
288
 
 
289
/*
 
290
 * release_pv_segment
 
291
 * @peg
 
292
 * @area_reduction
 
293
 *
 
294
 * WARNING: When release_pv_segment is called, the freed space may be
 
295
 *          merged into the 'pv_segment's before and after it in the
 
296
 *          list if they are also free.  Thus, any iterators of the
 
297
 *          'pv->segments' list that call this function must be aware
 
298
 *          that the list can change in a way that is unsafe even for
 
299
 *          *_safe iterators.  Restart the iterator in these cases.
 
300
 *
 
301
 * Returns: 1 on success, 0 on failure
 
302
 */
249
303
int release_pv_segment(struct pv_segment *peg, uint32_t area_reduction)
250
304
{
 
305
        struct dm_list *l;
 
306
        struct pv_segment *merge_peg;
 
307
 
251
308
        if (!peg->lvseg) {
252
309
                log_error("release_pv_segment with unallocated segment: "
253
310
                          "%s PE %" PRIu32, pv_dev_name(peg->pv), peg->pe);
261
318
                peg->lvseg = NULL;
262
319
                peg->lv_area = 0;
263
320
 
264
 
                /* FIXME merge free space */
265
 
 
266
 
                return 1;
 
321
                return _merge_free_pv_segment(peg);
267
322
        }
268
323
 
269
324
        if (!pv_split_segment(peg->lvseg->lv->vg->vgmem,
271
326
                              area_reduction, NULL))
272
327
                return_0;
273
328
 
 
329
        /* The segment after 'peg' now holds free space, try to merge it */
 
330
        if ((l = dm_list_next(&peg->pv->segments, &peg->list))) {
 
331
                merge_peg = dm_list_item(l, struct pv_segment);
 
332
                return _merge_free_pv_segment(merge_peg);
 
333
        }
 
334
 
274
335
        return 1;
275
336
}
276
337
 
733
794
                    unsigned prompt)
734
795
{
735
796
        struct device *dev;
 
797
        struct lvmcache_info *info;
736
798
        int r = 0;
737
799
 
738
800
        if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
749
811
                goto out;
750
812
        }
751
813
 
 
814
        info = lvmcache_info_from_pvid(dev->pvid, 1);
 
815
 
752
816
        if (!dev_test_excl(dev)) {
753
817
                /* FIXME Detect whether device-mapper is still using the device */
754
818
                log_error("Can't open %s exclusively - not removing. "
762
826
                goto out;
763
827
        }
764
828
 
 
829
        if (info)
 
830
                lvmcache_del(info);
 
831
 
765
832
        if (!lvmetad_pv_gone_by_dev(dev, NULL))
766
833
                goto_out;
767
834