~ubuntu-branches/ubuntu/saucy/lvm2/saucy-proposed

« back to all changes in this revision

Viewing changes to lib/format_pool/disk_rep.c

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2012-08-14 14:35:57 UTC
  • mfrom: (3.1.25 sid)
  • Revision ID: package-import@ubuntu.com-20120814143557-93aill2tp3kf3o30
Tags: 2.02.95-4ubuntu1
* Merge from Debian unstable, remaining changes:
  - debian/patches/avoid-dev-block.patch: Prefer any other device name over
    names in /dev/block/ since lvm.conf won't handle this.
  - debian/rules:
    - copy .po file to .pot file for Rosetta (Ubuntu specific).
  - debian/{dmsetup,lvm2}-udeb.install:
    - install initramfs and udev hooks in udebs (Debian bug 504341).
  - auto-start VGs as their PVs are discovered (Ubuntu specific):
    - add debian/tree/lvm2/lib/udev/rules.d/85-lvm2.rules: use watershed plus
      the sledgehammer of vgscan/vgchange to turn on VGs as they come online.
    - debian/tree/lvm2/usr/share/initramfs-tools/scripts/hooks/lvm2:
      - add 85-lvm2.rules to the list of udev rules to copy.
      - depend on udev.
    - debian/control:
      - add versioned Depend on watershed in lvm2 for udev rules.
      - add Depends on watershed-udeb in lvm2-udeb for udev rules.
      - add versioned Depend/Breaks on udev in dmsetup for udev rules.
      - add Depend on initramfs-tools in dmsetup so system is not potentially
        rendered unbootable by out-of-order dpkg configuration.
    - debian/rules:
      - do not install local-top scripts since Ubuntu mounts root using udev.
      - do not install init scripts for lvm2, since udev starts LVM.
    - debian/lvm2.postinst: handle missing lvm2 init script.
    - debian/tree/dmsetup/lib/udev/rules.d/60-persistent-storage-dm.rules:
      watch dm devices for changes with inotify
  - add mountroot failure hooks to help fix bad boots (Debian bug 468115):
    - debian/tree/lvm2/usr/share/initramfs-tools/scripts/init-premount/lvm2
  - remaining changes to upstream event manager packages (Debian bug 514706):
    - debian/rules:
      - enable dmeventd during configure.
    - debian/dmeventd.{8,manpages}: install dmeventd files.
  - rename debian/clvm.defaults to debian/clvm.default so it is installed
    correctly.
  - debian/control: add dmsetup-udeb to libdevmapper1.02.1-udeb recommends.
  - debian/rules: make sure dmsetup and lvm2 initramfs-tools scripts are
    executable.  When the Ubuntu-specific ones are added with a patch,
    they may lose their executable bit.
  - Add and install clvmd resource agent
  - Add dependency on libudev-dev to libdevmapper-dev so that the .pc file
    works.
  - debian/{clvmd.ra,clvm.init}:
    - create /run/lvm if it doesn't exist.
  - debian/clvm.init:
    - exit 3 if not running on status action.
  - Call dh_installman so that our dmeventd manpage actually gets installed
  - Install the missing fsadm manpage.

 * libdevmapper-dev:
  - move .so symlinks and pkgconfig files to multiarched locations.
  - mark libdevmapper-dev M-A: same

 * libdevmapper-event1.02.1:
  - Add Breaks: dmeventd (<< 2.02.95-4ubuntu1) due to debian symbol rename

 * debian/lvm2.{preinst,postinst,postrm}:
  - Implement removal of obsolete /etc/init.d/lvm2 conffile, which
    should not have been re-introduced in Quantal.

 * Dropped Changes, included in Debian:
  - Mostly included packages for upstream event manager (Debian bug 514706).
  - debian/patches/rules-subdir.patch: removed as reordering will cause
    build failure with dmeventd.
  - debian/patches/libdm-event-static.patch: removed as other static libs
    aren't being built anymore either.
  - Update symbols for libdevmapper-event.
  - Update libdevmapper-event, dmeventd descriptions to match Debian
    boilerplate.

 * Disappeared Changes:
  - Don't install documentation in udebs. No diff found, but no docs are
    installed into udebs either.

 * Resurected Changes:
  - corrected dropping the wrong init script. Now clvm.init is shipped
    and lvm2.init is dropped in favor of udev rules as per original
    intention (LP: #1037033).

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
                                  (char *) &vgid, 0)))
102
102
                return_0;
103
103
        if (label)
104
 
                *label = info->label;
105
 
 
106
 
        info->device_size = xlate32_be(pd->pl_blocks) << SECTOR_SHIFT;
107
 
        dm_list_init(&info->mdas);
108
 
 
109
 
        info->status &= ~CACHE_INVALID;
 
104
                *label = lvmcache_get_label(info);
 
105
 
 
106
        lvmcache_set_device_size(info, xlate32_be(pd->pl_blocks) << SECTOR_SHIFT);
 
107
        lvmcache_del_mdas(info);
 
108
        lvmcache_make_valid(info);
110
109
 
111
110
        pl->dev = dev;
112
111
        pl->pv = NULL;
236
235
 
237
236
}
238
237
 
239
 
static int _read_vg_pds(const struct format_type *fmt, struct dm_pool *mem,
240
 
                        struct lvmcache_vginfo *vginfo, struct dm_list *head,
 
238
struct _read_pool_pv_baton {
 
239
        const struct format_type *fmt;
 
240
        struct dm_pool *mem, *tmpmem;
 
241
        struct pool_list *pl;
 
242
        struct dm_list *head;
 
243
        const char *vgname;
 
244
        uint32_t *sp_devs;
 
245
        int sp_count;
 
246
        int failed;
 
247
        int empty;
 
248
};
 
249
 
 
250
static int _read_pool_pv(struct lvmcache_info *info, void *baton)
 
251
{
 
252
        struct _read_pool_pv_baton *b = baton;
 
253
 
 
254
        b->empty = 0;
 
255
 
 
256
        if (lvmcache_device(info) &&
 
257
            !(b->pl = read_pool_disk(b->fmt, lvmcache_device(info), b->mem, b->vgname)))
 
258
                return 0;
 
259
 
 
260
        /*
 
261
         * We need to keep track of the total expected number
 
262
         * of devices per subpool
 
263
         */
 
264
        if (!b->sp_count) {
 
265
                /* FIXME pl left uninitialised if !info->dev */
 
266
                if (!b->pl) {
 
267
                        log_error(INTERNAL_ERROR "device is missing");
 
268
                        dm_pool_destroy(b->tmpmem);
 
269
                        b->failed = 1;
 
270
                        return 0;
 
271
                }
 
272
                b->sp_count = b->pl->pd.pl_subpools;
 
273
                if (!(b->sp_devs =
 
274
                      dm_pool_zalloc(b->tmpmem,
 
275
                                     sizeof(uint32_t) * b->sp_count))) {
 
276
                        log_error("Unable to allocate %d 32-bit uints",
 
277
                                  b->sp_count);
 
278
                        dm_pool_destroy(b->tmpmem);
 
279
                        b->failed = 1;
 
280
                        return 0;
 
281
                }
 
282
        }
 
283
 
 
284
        /*
 
285
         * watch out for a pool label with a different subpool
 
286
         * count than the original - give up if it does
 
287
         */
 
288
        if (b->sp_count != b->pl->pd.pl_subpools)
 
289
                return 0;
 
290
 
 
291
        _add_pl_to_list(b->head, b->pl);
 
292
 
 
293
        if (b->sp_count > b->pl->pd.pl_sp_id && b->sp_devs[b->pl->pd.pl_sp_id] == 0)
 
294
                b->sp_devs[b->pl->pd.pl_sp_id] = b->pl->pd.pl_sp_devs;
 
295
 
 
296
        return 1;
 
297
}
 
298
 
 
299
static int _read_vg_pds(struct _read_pool_pv_baton *b,
 
300
                        struct lvmcache_vginfo *vginfo,
241
301
                        uint32_t *devcount)
242
302
{
243
 
        struct lvmcache_info *info;
244
 
        struct pool_list *pl = NULL;
245
 
        struct dm_pool *tmpmem;
246
 
 
247
 
        uint32_t sp_count = 0;
248
 
        uint32_t *sp_devs = NULL;
249
303
        uint32_t i;
250
304
 
 
305
        b->sp_count = 0;
 
306
        b->sp_devs = NULL;
 
307
        b->failed = 0;
 
308
        b->pl = NULL;
 
309
 
251
310
        /* FIXME: maybe should return a different error in memory
252
311
         * allocation failure */
253
 
        if (!(tmpmem = dm_pool_create("pool read_vg", 512)))
 
312
        if (!(b->tmpmem = dm_pool_create("pool read_vg", 512)))
254
313
                return_0;
255
314
 
256
 
        dm_list_iterate_items(info, &vginfo->infos) {
257
 
                if (info->dev &&
258
 
                    !(pl = read_pool_disk(fmt, info->dev, mem, vginfo->vgname)))
259
 
                            break;
260
 
                /*
261
 
                 * We need to keep track of the total expected number
262
 
                 * of devices per subpool
263
 
                 */
264
 
                if (!sp_count) {
265
 
                        /* FIXME pl left uninitialised if !info->dev */
266
 
                        if (!pl) {
267
 
                                log_error(INTERNAL_ERROR "device is missing");
268
 
                                dm_pool_destroy(tmpmem);
269
 
                                return 0;
270
 
                        }
271
 
                        sp_count = pl->pd.pl_subpools;
272
 
                        if (!(sp_devs =
273
 
                              dm_pool_zalloc(tmpmem,
274
 
                                          sizeof(uint32_t) * sp_count))) {
275
 
                                log_error("Unable to allocate %d 32-bit uints",
276
 
                                          sp_count);
277
 
                                dm_pool_destroy(tmpmem);
278
 
                                return 0;
279
 
                        }
280
 
                }
281
 
                /*
282
 
                 * watch out for a pool label with a different subpool
283
 
                 * count than the original - give up if it does
284
 
                 */
285
 
                if (sp_count != pl->pd.pl_subpools)
286
 
                        break;
287
 
 
288
 
                _add_pl_to_list(head, pl);
289
 
 
290
 
                if (sp_count > pl->pd.pl_sp_id && sp_devs[pl->pd.pl_sp_id] == 0)
291
 
                        sp_devs[pl->pd.pl_sp_id] = pl->pd.pl_sp_devs;
292
 
        }
 
315
        lvmcache_foreach_pv(vginfo, _read_pool_pv, b);
293
316
 
294
317
        *devcount = 0;
295
 
        for (i = 0; i < sp_count; i++)
296
 
                *devcount += sp_devs[i];
297
 
 
298
 
        dm_pool_destroy(tmpmem);
299
 
 
300
 
        if (pl && *pl->pd.pl_pool_name)
 
318
        for (i = 0; i < b->sp_count; i++)
 
319
                *devcount += b->sp_devs[i];
 
320
 
 
321
        dm_pool_destroy(b->tmpmem);
 
322
 
 
323
        if (b->pl && *b->pl->pd.pl_pool_name)
301
324
                return 1;
302
325
 
303
326
        return 0;
311
334
        uint32_t totaldevs;
312
335
        int full_scan = -1;
313
336
 
 
337
        struct _read_pool_pv_baton baton;
 
338
 
 
339
        baton.vgname = vg_name;
 
340
        baton.mem = mem;
 
341
        baton.fmt = fmt;
 
342
        baton.head = pdhead;
 
343
        baton.empty = 1;
 
344
 
314
345
        do {
315
346
                /*
316
347
                 * If the cache scanning doesn't work, this will never work
317
348
                 */
318
 
                if (vg_name && (vginfo = vginfo_from_vgname(vg_name, NULL)) &&
319
 
                    vginfo->infos.n) {
320
 
 
321
 
                        if (_read_vg_pds(fmt, mem, vginfo, pdhead, &totaldevs)) {
322
 
                                /*
323
 
                                 * If we found all the devices we were
324
 
                                 * expecting, return success
325
 
                                 */
326
 
                                if (dm_list_size(pdhead) == totaldevs)
327
 
                                        return 1;
328
 
 
329
 
                                /*
330
 
                                 * accept partial pool if we've done a full
331
 
                                 * rescan of the cache
332
 
                                 */
333
 
                                if (full_scan > 0)
334
 
                                        return 1;
335
 
                        }
 
349
                if (vg_name && (vginfo = lvmcache_vginfo_from_vgname(vg_name, NULL)) &&
 
350
                    _read_vg_pds(&baton, vginfo, &totaldevs) && !baton.empty)
 
351
                {
 
352
                        /*
 
353
                         * If we found all the devices we were expecting, return
 
354
                         * success
 
355
                         */
 
356
                        if (dm_list_size(pdhead) == totaldevs)
 
357
                                return 1;
 
358
 
 
359
                        /*
 
360
                         * accept partial pool if we've done a full rescan of
 
361
                         * the cache
 
362
                         */
 
363
                        if (full_scan > 0)
 
364
                                return 1;
336
365
                }
 
366
 
337
367
                /* Failed */
338
368
                dm_list_init(pdhead);
339
369