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

« back to all changes in this revision

Viewing changes to lib/metadata/pv.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:
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
}