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

« back to all changes in this revision

Viewing changes to tools/pvscan.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:
1
1
/*
2
2
 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3
 
 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
 
3
 * Copyright (C) 2004-2012 Red Hat, Inc. All rights reserved.
4
4
 *
5
5
 * This file is part of LVM2.
6
6
 *
15
15
 
16
16
#include "tools.h"
17
17
 
 
18
#include "lvmetad.h"
 
19
#include "lvmcache.h"
 
20
 
18
21
int pv_max_name_len = 0;
19
22
int vg_max_name_len = 0;
20
23
 
96
99
                                           pv_pe_size(pv)));
97
100
}
98
101
 
99
 
int pvscan(struct cmd_context *cmd, int argc __attribute__((unused)),
100
 
           char **argv __attribute__((unused)))
 
102
static int _pvscan_lvmetad_all_devs(struct cmd_context *cmd)
 
103
{
 
104
        struct dev_iter *iter;
 
105
        struct device *dev;
 
106
        int r = 1;
 
107
 
 
108
        if (!(iter = dev_iter_create(cmd->filter, 1))) {
 
109
                log_error("dev_iter creation failed");
 
110
                return 0;
 
111
        }
 
112
 
 
113
        while ((dev = dev_iter_get(iter))) {
 
114
                if (!pvscan_lvmetad_single(cmd, dev)) {
 
115
                        r = 0;
 
116
                        break;
 
117
                }
 
118
 
 
119
                if (sigint_caught())
 
120
                        break;
 
121
        }
 
122
 
 
123
        dev_iter_destroy(iter);
 
124
 
 
125
        return r;
 
126
}
 
127
 
 
128
static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
 
129
{
 
130
        int ret = ECMD_PROCESSED;
 
131
        struct device *dev;
 
132
        const char *pv_name;
 
133
        int32_t major = -1;
 
134
        int32_t minor = -1;
 
135
        int devno_args = 0;
 
136
        struct arg_value_group_list *current_group;
 
137
        dev_t devno;
 
138
        char *buf;
 
139
 
 
140
        if (arg_count(cmd, major_ARG) + arg_count(cmd, minor_ARG))
 
141
                devno_args = 1;
 
142
 
 
143
        if (devno_args && (!arg_count(cmd, major_ARG) || !arg_count(cmd, minor_ARG))) {
 
144
                log_error("Both --major and --minor required to identify devices.");
 
145
                return EINVALID_CMD_LINE;
 
146
        }
 
147
        
 
148
        if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_READ)) {
 
149
                log_error("Unable to obtain global lock.");
 
150
                return ECMD_FAILED;
 
151
        }
 
152
 
 
153
        /* Scan everything? */
 
154
        if (!argc && !devno_args) {
 
155
                if (!_pvscan_lvmetad_all_devs(cmd))
 
156
                        ret = ECMD_FAILED;
 
157
                goto out;
 
158
        }
 
159
 
 
160
        log_verbose("Using physical volume(s) on command line");
 
161
 
 
162
        /* Process any command line PVs first. */
 
163
        while (argc--) {
 
164
                pv_name = *argv++;
 
165
                dev = dev_cache_get(pv_name, NULL);
 
166
                if (!dev) {
 
167
                        log_error("Physical Volume %s not found.", pv_name);
 
168
                        ret = ECMD_FAILED;
 
169
                        continue;
 
170
                }
 
171
 
 
172
                if (!pvscan_lvmetad_single(cmd, dev)) {
 
173
                        ret = ECMD_FAILED;
 
174
                        break;
 
175
                }
 
176
                if (sigint_caught())
 
177
                        break;
 
178
        }
 
179
 
 
180
        if (!devno_args)
 
181
                goto out;
 
182
 
 
183
        /* Process any grouped --major --minor args */
 
184
        dm_list_iterate_items(current_group, &cmd->arg_value_groups) {
 
185
                major = grouped_arg_int_value(current_group->arg_values, major_ARG, major);
 
186
                minor = grouped_arg_int_value(current_group->arg_values, minor_ARG, minor);
 
187
 
 
188
                if (major < 0 || minor < 0)
 
189
                        continue;
 
190
 
 
191
                devno = MKDEV(major, minor);
 
192
 
 
193
                if (!(dev = dev_cache_get_by_devt(devno, NULL))) {
 
194
                        if (!dm_asprintf(&buf, "%" PRIi32 ":%" PRIi32, major, minor))
 
195
                                stack;
 
196
                        /* FIXME Filters? */
 
197
                        if (!lvmetad_pv_gone(devno, buf ? : "")) {
 
198
                                ret = ECMD_FAILED;
 
199
                                if (buf)
 
200
                                        dm_free(buf);
 
201
                                break;
 
202
                        }
 
203
 
 
204
                        log_print("Device %s not found. "
 
205
                                  "Cleared from lvmetad cache.", buf ? : "");
 
206
                        if (buf)
 
207
                                dm_free(buf);
 
208
                        continue;
 
209
                }
 
210
 
 
211
                if (!pvscan_lvmetad_single(cmd, dev)) {
 
212
                        ret = ECMD_FAILED;
 
213
                        break;
 
214
                }
 
215
 
 
216
                if (sigint_caught())
 
217
                        break;
 
218
        }
 
219
 
 
220
out:
 
221
        unlock_vg(cmd, VG_GLOBAL);
 
222
 
 
223
        return ret;
 
224
}
 
225
 
 
226
int pvscan(struct cmd_context *cmd, int argc, char **argv)
101
227
{
102
228
        int new_pvs_found = 0;
103
229
        int pvs_found = 0;
113
239
        pv_max_name_len = 0;
114
240
        vg_max_name_len = 0;
115
241
 
 
242
        if (arg_count(cmd, cache_ARG))
 
243
                return _pvscan_lvmetad(cmd, argc, argv);
 
244
 
 
245
        if (arg_count(cmd, major_ARG) + arg_count(cmd, minor_ARG)) {
 
246
                log_error("--major and --minor are only valid with --cache.");
 
247
                return EINVALID_CMD_LINE;
 
248
        }
 
249
 
116
250
        if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) {
117
251
                log_error("Options -e and -n are incompatible");
118
252
                return EINVALID_CMD_LINE;
131
265
        persistent_filter_wipe(cmd->filter);
132
266
        lvmcache_destroy(cmd, 1);
133
267
 
 
268
        /* populate lvmcache */
 
269
        if (!lvmetad_vg_list_to_lvmcache(cmd))
 
270
                stack;
 
271
 
134
272
        log_verbose("Walking through all physical volumes");
135
273
        if (!(pvslist = get_pvs(cmd))) {
136
274
                unlock_vg(cmd, VG_GLOBAL);
143
281
                pv = pvl->pv;
144
282
 
145
283
                if ((arg_count(cmd, exported_ARG)
146
 
                     && !(pv_status(pv) & EXPORTED_VG))
147
 
                    || (arg_count(cmd, novolumegroup_ARG) && (!is_orphan(pv)))) {
 
284
                     && !(pv_status(pv) & EXPORTED_VG)) ||
 
285
                    (arg_count(cmd, novolumegroup_ARG) && (!is_orphan(pv)))) {
148
286
                        dm_list_del(&pvl->list);
 
287
                        free_pv_fid(pv);
149
288
                        continue;
150
289
                }
151
290
 
184
323
        vg_max_name_len += 2;
185
324
 
186
325
        dm_list_iterate_items(pvl, pvslist) {
187
 
            _pvscan_display_single(cmd, pvl->pv, NULL);
188
 
            free_pv_fid(pvl->pv);
 
326
                _pvscan_display_single(cmd, pvl->pv, NULL);
 
327
                free_pv_fid(pvl->pv);
189
328
        }
190
329
 
191
330
        if (!pvs_found) {