diff --git a/WHATS_NEW b/WHATS_NEW index a35e9806f..5d1aeadf0 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.00 - =================================== + Simplify dev_manager_info(). Attempt to load missing targets using modprobe. Add -a to lvscan. Move mknodes into libdevmapper. diff --git a/include/.symlinks b/include/.symlinks index 201fb7208..c11c0acb8 100644 --- a/include/.symlinks +++ b/include/.symlinks @@ -37,6 +37,7 @@ ../lib/misc/crc.h ../lib/misc/intl.h ../lib/misc/lib.h +../lib/misc/lvm-exec.h ../lib/misc/lvm-file.h ../lib/misc/lvm-string.h ../lib/misc/selinux.h diff --git a/lib/Makefile.in b/lib/Makefile.in index 169893c27..5065c1cce 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -1,6 +1,6 @@ # # Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. -# Copyright (C) 2004 Red Hat, Inc. All rights reserved. +# Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. # # This file is part of the LVM2. # @@ -74,6 +74,7 @@ SOURCES =\ metadata/segtype.c \ metadata/snapshot_manip.c \ misc/crc.c \ + misc/lvm-exec.c \ misc/lvm-file.c \ misc/lvm-string.c \ mm/memlock.c \ diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 1fb93dcf4..3b2823be6 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -19,6 +19,7 @@ #include "memlock.h" #include "display.h" #include "fs.h" +#include "lvm-exec.h" #include "lvm-file.h" #include "lvm-string.h" #include "toolcontext.h" @@ -77,7 +78,7 @@ int target_present(const char *target_name) { return 0; } -int lv_info(const struct logical_volume *lv, struct lvinfo *info, +int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, struct lvinfo *info, int with_open_count) { return 0; @@ -256,48 +257,25 @@ int library_version(char *version, size_t size) if (!activation()) return 0; - if (!dm_get_library_version(version, size)) - return 0; - return 1; + return dm_get_library_version(version, size); } int driver_version(char *version, size_t size) { - int r = 0; - struct dm_task *dmt; - if (!activation()) return 0; log_very_verbose("Getting driver version"); - if (!(dmt = dm_task_create(DM_DEVICE_VERSION))) { - stack; - return 0; - } - if (!dm_task_run(dmt)) - log_error("Failed to get driver version"); - - if (!dm_task_get_driver_version(dmt, version, size)) - goto out; - - r = 1; - - out: - dm_task_destroy(dmt); - - return r; + return dm_driver_version(version, size); } -int target_present(const char *target_name) +static int _target_present(const char *target_name) { int r = 0; struct dm_task *dmt; struct dm_versions *target, *last_target; - if (!activation()) - return 0; - log_very_verbose("Getting target version for %s", target_name); if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS))) { stack; @@ -329,26 +307,54 @@ int target_present(const char *target_name) return r; } -/* - * Returns 1 if info structure populated, else 0 on failure. - */ -static int _lv_info(const struct logical_volume *lv, int mknodes, - struct lvinfo *info, int with_open_count) +int target_present(const char *target_name) { - int r; - struct dev_manager *dm; - struct dm_info dminfo; + char module[128]; if (!activation()) return 0; - if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name))) { +#ifdef MODPROBE_CMD + if (_target_present(target_name)) + return 1; + + if (lvm_snprintf(module, sizeof(module), "dm-%s", target_name) < 0) { + log_error("target_present module name too long: %s", target_name); + return 0; + } + + if (!exec_cmd(MODPROBE_CMD, module, "", "")) { + stack; + return 0; + } +#endif + + return _target_present(target_name); +} + +/* + * Returns 1 if info structure populated, else 0 on failure. + */ +static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, int with_mknodes, + struct lvinfo *info, int with_open_count) +{ + struct dm_info dminfo; + char *name; + + if (!activation()) + return 0; + + if (!(name = build_dm_name(cmd->mem, lv->vg->name, lv->name, NULL))) { stack; return 0; } - if (!(r = dev_manager_info(dm, lv, mknodes, with_open_count, &dminfo))) + log_debug("Getting device info for %s", name); + if (!dev_manager_info(name, lv->lvid.s, with_mknodes, with_open_count, &dminfo)) { + dm_pool_free(cmd->mem, name); stack; + return 0; + } info->exists = dminfo.exists; info->suspended = dminfo.suspended; @@ -357,14 +363,14 @@ static int _lv_info(const struct logical_volume *lv, int mknodes, info->minor = dminfo.minor; info->read_only = dminfo.read_only; - dev_manager_destroy(dm); - return r; + dm_pool_free(cmd->mem, name); + return 1; } -int lv_info(const struct logical_volume *lv, struct lvinfo *info, +int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, struct lvinfo *info, int with_open_count) { - return _lv_info(lv, 0, info, with_open_count); + return _lv_info(cmd, lv, 0, info, with_open_count); } int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, @@ -375,7 +381,7 @@ int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, if (!(lv = lv_from_lvid(cmd, lvid_s))) return 0; - return _lv_info(lv, 0, info, with_open_count); + return _lv_info(cmd, lv, 0, info, with_open_count); } /* @@ -403,7 +409,7 @@ int lv_snapshot_percent(struct logical_volume *lv, float *percent) } /* FIXME Merge with snapshot_percent */ -int lv_mirror_percent(struct logical_volume *lv, int wait, float *percent, +int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv, int wait, float *percent, uint32_t *event_nr) { int r; @@ -413,7 +419,7 @@ int lv_mirror_percent(struct logical_volume *lv, int wait, float *percent, if (!activation()) return 0; - if (!lv_info(lv, &info, 0)) { + if (!lv_info(cmd, lv, &info, 0)) { stack; return 0; } @@ -434,11 +440,11 @@ int lv_mirror_percent(struct logical_volume *lv, int wait, float *percent, return r; } -static int _lv_active(struct logical_volume *lv) +static int _lv_active(struct cmd_context *cmd, struct logical_volume *lv) { struct lvinfo info; - if (!lv_info(lv, &info, 0)) { + if (!lv_info(cmd, lv, &info, 0)) { stack; return -1; } @@ -446,11 +452,11 @@ static int _lv_active(struct logical_volume *lv) return info.exists; } -static int _lv_open_count(struct logical_volume *lv) +static int _lv_open_count(struct cmd_context *cmd, struct logical_volume *lv) { struct lvinfo info; - if (!lv_info(lv, &info, 1)) { + if (!lv_info(cmd, lv, &info, 1)) { stack; return -1; } @@ -524,7 +530,7 @@ int lvs_in_vg_activated(struct volume_group *vg) list_iterate_items(lvl, &vg->lvs) { if (lvl->lv->status & VISIBLE_LV) - count += (_lv_active(lvl->lv) == 1); + count += (_lv_active(vg->cmd, lvl->lv) == 1); } return count; @@ -540,7 +546,7 @@ int lvs_in_vg_opened(struct volume_group *vg) list_iterate_items(lvl, &vg->lvs) { if (lvl->lv->status & VISIBLE_LV) - count += (_lv_open_count(lvl->lv) > 0); + count += (_lv_open_count(vg->cmd, lvl->lv) > 0); } return count; @@ -563,7 +569,7 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s, return 1; } - if (!lv_info(lv, &info, 0)) { + if (!lv_info(cmd, lv, &info, 0)) { stack; return 0; } @@ -609,7 +615,7 @@ static int _lv_resume(struct cmd_context *cmd, const char *lvid_s, return 1; } - if (!lv_info(lv, &info, 0)) { + if (!lv_info(cmd, lv, &info, 0)) { stack; return 0; } @@ -654,7 +660,7 @@ int lv_deactivate(struct cmd_context *cmd, const char *lvid_s) return 1; } - if (!lv_info(lv, &info, 1)) { + if (!lv_info(cmd, lv, &info, 1)) { stack; return 0; } @@ -724,7 +730,7 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s, return 1; } - if (!lv_info(lv, &info, 0)) { + if (!lv_info(cmd, lv, &info, 0)) { stack; return 0; } @@ -766,7 +772,7 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv) return r; } - if (!_lv_info(lv, 1, &info, 0)) { + if (!_lv_info(cmd, lv, 1, &info, 0)) { stack; return 0; } diff --git a/lib/activate/activate.h b/lib/activate/activate.h index 2680c5923..98e0876ad 100644 --- a/lib/activate/activate.h +++ b/lib/activate/activate.h @@ -52,7 +52,7 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv); /* * Returns 1 if info structure has been populated, else 0. */ -int lv_info(const struct logical_volume *lv, struct lvinfo *info, +int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, struct lvinfo *info, int with_open_count); int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, struct lvinfo *info, int with_open_count); @@ -67,7 +67,7 @@ int lv_activation_filter(struct cmd_context *cmd, const char *lvid_s, * Returns 1 if percent has been set, else 0. */ int lv_snapshot_percent(struct logical_volume *lv, float *percent); -int lv_mirror_percent(struct logical_volume *lv, int wait, float *percent, +int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv, int wait, float *percent, uint32_t *event_nr); /* @@ -76,6 +76,4 @@ int lv_mirror_percent(struct logical_volume *lv, int wait, float *percent, int lvs_in_vg_activated(struct volume_group *vg); int lvs_in_vg_opened(struct volume_group *vg); -int lv_setup_cow_store(struct logical_volume *lv); - #endif diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index f0096b6ca..dd14145ca 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -267,6 +267,12 @@ static int _info(const char *name, const char *uuid, int mknodes, return 0; } +int dev_manager_info(const char *name, const char *uuid, + int with_mknodes, int with_open_count, struct dm_info *info) +{ + return _info(name, uuid, with_mknodes, with_open_count, info, NULL, NULL); +} + /* FIXME Interface must cope with multiple targets */ static int _status_run(const char *name, const char *uuid, unsigned long long *s, unsigned long long *l, @@ -986,32 +992,6 @@ void dev_manager_destroy(struct dev_manager *dm) dm_pool_destroy(dm->mem); } -int dev_manager_info(struct dev_manager *dm, const struct logical_volume *lv, - int mknodes, int with_open_count, struct dm_info *info) -{ - char *name; - - /* - * Build a name for the top layer. - */ - if (!(name = build_dm_name(dm->mem, lv->vg->name, lv->name, NULL))) { - stack; - return 0; - } - - /* - * Try and get some info on this device. - */ - log_debug("Getting device info for %s", name); - if (!_info(name, lv->lvid.s, mknodes, with_open_count, info, NULL, - NULL)) { - stack; - return 0; - } - - return 1; -} - int dev_manager_snapshot_percent(struct dev_manager *dm, struct logical_volume *lv, float *percent) { @@ -2208,3 +2188,4 @@ void dev_manager_exit(void) { dm_lib_exit(); } + diff --git a/lib/activate/dev_manager.h b/lib/activate/dev_manager.h index 1c32d56fe..e3e390edf 100644 --- a/lib/activate/dev_manager.h +++ b/lib/activate/dev_manager.h @@ -35,7 +35,7 @@ void dev_manager_exit(void); * (eg, an origin is created before its snapshot, but is not * unsuspended until the snapshot is also created.) */ -int dev_manager_info(struct dev_manager *dm, const struct logical_volume *lv, +int dev_manager_info(const char *name, const char *uuid, int mknodes, int with_open_count, struct dm_info *info); int dev_manager_snapshot_percent(struct dev_manager *dm, struct logical_volume *lv, float *percent); @@ -48,7 +48,6 @@ int dev_manager_deactivate(struct dev_manager *dm, struct logical_volume *lv); int dev_manager_lv_mknodes(const struct logical_volume *lv); int dev_manager_lv_rmnodes(const struct logical_volume *lv); -int dev_manager_mknodes(void); /* * Put the desired changes into effect. diff --git a/lib/display/display.c b/lib/display/display.c index 21634b42d..da63bc7a6 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -317,7 +317,7 @@ void lvdisplay_colons(struct logical_volume *lv) { int inkernel; struct lvinfo info; - inkernel = lv_info(lv, &info, 1) && info.exists; + inkernel = lv_info(lv->vg->cmd, lv, &info, 1) && info.exists; log_print("%s%s/%s:%s:%d:%d:-1:%d:%" PRIu64 ":%d:-1:%d:%d:%d:%d", lv->vg->cmd->dev_dir, @@ -347,7 +347,7 @@ int lvdisplay_full(struct cmd_context *cmd, struct logical_volume *lv, return 0; } - inkernel = lv_info(lv, &info, 1) && info.exists; + inkernel = lv_info(cmd, lv, &info, 1) && info.exists; log_print("--- Logical volume ---"); diff --git a/lib/report/report.c b/lib/report/report.c index 7770c0218..ef9fbc729 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -295,7 +295,7 @@ static int _lvkmaj_disp(struct report_handle *rh, struct field *field, struct lvinfo info; uint64_t minusone = UINT64_C(-1); - if (lv_info(lv, &info, 0) && info.exists) + if (lv_info(lv->vg->cmd, lv, &info, 0) && info.exists) return _int_disp(rh, field, &info.major); else return _int_disp(rh, field, &minusone); @@ -310,7 +310,7 @@ static int _lvkmin_disp(struct report_handle *rh, struct field *field, struct lvinfo info; uint64_t minusone = UINT64_C(-1); - if (lv_info(lv, &info, 0) && info.exists) + if (lv_info(lv->vg->cmd, lv, &info, 0) && info.exists) return _int_disp(rh, field, &info.minor); else return _int_disp(rh, field, &minusone); @@ -366,7 +366,7 @@ static int _lvstatus_disp(struct report_handle *rh, struct field *field, else repstr[3] = '-'; - if (lv_info(lv, &info, 1) && info.exists) { + if (lv_info(lv->vg->cmd, lv, &info, 1) && info.exists) { if (info.suspended) repstr[4] = 's'; /* Suspended */ else @@ -848,7 +848,7 @@ static int _snpercent_disp(struct report_handle *rh, struct field *field, } if (!(snap_seg = find_cow(lv)) || - (lv_info(snap_seg->cow, &info, 0) && !info.exists)) { + (lv_info(lv->vg->cmd, snap_seg->cow, &info, 0) && !info.exists)) { field->report_string = ""; *sortval = UINT64_C(0); field->sort_value = sortval; @@ -894,7 +894,7 @@ static int _copypercent_disp(struct report_handle *rh, struct field *field, } if ((!(lv->status & PVMOVE) && !(lv->status & MIRRORED)) || - !lv_mirror_percent(lv, 0, &percent, NULL)) { + !lv_mirror_percent(lv->vg->cmd, lv, 0, &percent, NULL)) { field->report_string = ""; *sortval = UINT64_C(0); field->sort_value = sortval; diff --git a/tools/lvchange.c b/tools/lvchange.c index b1b1434e5..13c2b7a48 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -262,7 +262,7 @@ static int lvchange_persistent(struct cmd_context *cmd, log_error("Major number must be specified with -My"); return 0; } - if (lv_info(lv, &info, 0) && info.exists && + if (lv_info(cmd, lv, &info, 0) && info.exists && !arg_count(cmd, force_ARG)) { if (yes_no_prompt("Logical volume %s will be " "deactivated temporarily. " diff --git a/tools/lvremove.c b/tools/lvremove.c index a523c7084..003c727c5 100644 --- a/tools/lvremove.c +++ b/tools/lvremove.c @@ -53,7 +53,7 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv, /* FIXME Ensure not referred to by another existing LVs */ - if (lv_info(lv, &info, 1)) { + if (lv_info(cmd, lv, &info, 1)) { if (info.open_count) { log_error("Can't remove open logical volume \"%s\"", lv->name); diff --git a/tools/lvresize.c b/tools/lvresize.c index f32801f5e..9469254f5 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -388,7 +388,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) } if (lp->mirrors && activation() && - lv_info(lv, &info, 0) && info.exists) { + lv_info(cmd, lv, &info, 0) && info.exists) { log_error("Mirrors cannot be resized while active yet."); return ECMD_FAILED; } @@ -402,7 +402,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) memset(&info, 0, sizeof(info)); - if (lv_info(lv, &info, 0) && info.exists) { + if (lv_info(cmd, lv, &info, 0) && info.exists) { log_error("Snapshot origin volumes can be resized " "only while inactive: try lvchange -an"); return ECMD_FAILED; @@ -421,7 +421,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) if (lp->resize == LV_REDUCE || lp->resizefs) { memset(&info, 0, sizeof(info)); - if (!lv_info(lv, &info, 1) && driver_version(NULL, 0)) { + if (!lv_info(cmd, lv, &info, 1) && driver_version(NULL, 0)) { log_error("lv_info failed: aborting"); return ECMD_FAILED; } diff --git a/tools/vgconvert.c b/tools/vgconvert.c index e50aac242..4ebf4e948 100644 --- a/tools/vgconvert.c +++ b/tools/vgconvert.c @@ -96,7 +96,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name, continue; if (lvnum_from_lvid(&lv->lvid) < MAX_RESTRICTED_LVS) continue; - if (lv_info(lv, &info, 0) && info.exists) { + if (lv_info(cmd, lv, &info, 0) && info.exists) { log_error("Logical volume %s must be " "deactivated before conversion.", lv->name);