return 0;
}
- dev = dev_cache_get_by_devt(devt, cmd->filter);
+ dev = dev_cache_get_by_devt(cmd, devt, cmd->filter);
if (!dev && fallback)
- dev = dev_cache_get_by_devt(fallback, cmd->filter);
+ dev = dev_cache_get_by_devt(cmd, fallback, cmd->filter);
if (!dev) {
log_warn("WARNING: Device for PV %s not found or rejected by a filter.", pvid_txt);
was_silent = silent_mode();
init_silent(1);
- while ((dev = dev_iter_get(iter))) {
+ while ((dev = dev_iter_get(cmd, iter))) {
if (sigint_caught()) {
ret = 0;
stack;
#if 0
struct device *dev;
- if (!(dev = dev_cache_get_by_devt(devt, cmd->lvmetad_filter))) {
+ if (!(dev = dev_cache_get_by_devt(cmd, devt, cmd->lvmetad_filter))) {
log_error("_update_pv_in_udev no dev found");
return;
}
return reason;
}
-struct device *dev_cache_get(const char *name, struct dev_filter *f)
+struct device *dev_cache_get(struct cmd_context *cmd, const char *name, struct dev_filter *f)
{
struct stat buf;
struct device *d = (struct device *) dm_hash_lookup(_cache.names, name);
return d;
if (f && !(d->flags & DEV_REGULAR)) {
- ret = f->passes_filter(f, d);
+ ret = f->passes_filter(cmd, f, d);
if (ret == -EAGAIN) {
log_debug_devs("get device by name defer filter %s", dev_name(d));
* TODO This is very inefficient. We probably want a hash table indexed by
* major:minor for keys to speed up these lookups.
*/
-struct device *dev_cache_get_by_devt(dev_t dev, struct dev_filter *f)
+struct device *dev_cache_get_by_devt(struct cmd_context *cmd, dev_t dev, struct dev_filter *f)
{
char path[PATH_MAX];
const char *sysfs_dir;
if (!f)
return d;
- ret = f->passes_filter(f, d);
+ ret = f->passes_filter(cmd, f, d);
if (ret == -EAGAIN) {
log_debug_devs("get device by number defer filter %s", dev_name(d));
return d;
}
-struct device *dev_iter_get(struct dev_iter *iter)
+struct device *dev_iter_get(struct cmd_context *cmd, struct dev_iter *iter)
{
struct dev_filter *f;
int ret;
f = iter->filter;
if (f && !(d->flags & DEV_REGULAR)) {
- ret = f->passes_filter(f, d);
+ ret = f->passes_filter(cmd, f, d);
if (ret == -EAGAIN) {
log_debug_devs("get device by iter defer filter %s", dev_name(d));
#include "lib/device/device.h"
#include "lib/misc/lvm-wrappers.h"
+struct cmd_context;
+
/*
* predicate for devices.
*/
struct dev_filter {
- int (*passes_filter) (struct dev_filter * f, struct device * dev);
- void (*destroy) (struct dev_filter * f);
- void (*wipe) (struct dev_filter * f);
- int (*dump) (struct dev_filter * f, int merge_existing);
+ int (*passes_filter) (struct cmd_context *cmd, struct dev_filter *f, struct device *dev);
+ void (*destroy) (struct dev_filter *f);
+ void (*wipe) (struct dev_filter *f);
void *private;
unsigned use_count;
};
/*
* The global device cache.
*/
-struct cmd_context;
int dev_cache_init(struct cmd_context *cmd);
int dev_cache_exit(void);
+
/*
* Returns number of open devices.
*/
int dev_cache_add_dir(const char *path);
int dev_cache_add_loopfile(const char *path);
__attribute__((nonnull(1)))
-struct device *dev_cache_get(const char *name, struct dev_filter *f);
+struct device *dev_cache_get(struct cmd_context *cmd, const char *name, struct dev_filter *f);
const char *dev_cache_filtered_reason(const char *name);
// TODO
-struct device *dev_cache_get_by_devt(dev_t device, struct dev_filter *f);
+struct device *dev_cache_get_by_devt(struct cmd_context *cmd, dev_t device, struct dev_filter *f);
void dev_set_preferred_name(struct dm_str_list *sl, struct device *dev);
struct dev_iter;
struct dev_iter *dev_iter_create(struct dev_filter *f, int unused);
void dev_iter_destroy(struct dev_iter *iter);
-struct device *dev_iter_get(struct dev_iter *iter);
+struct device *dev_iter_get(struct cmd_context *cmd, struct dev_iter *iter);
void dev_reset_error_count(struct cmd_context *cmd);
#include "lib/filters/filter.h"
#include "lib/device/device.h"
-static int _and_p(struct dev_filter *f, struct device *dev)
+static int _and_p(struct cmd_context *cmd, struct dev_filter *f, struct device *dev)
{
struct dev_filter **filters;
int ret;
for (filters = (struct dev_filter **) f->private; *filters; ++filters) {
- ret = (*filters)->passes_filter(*filters, dev);
+ ret = (*filters)->passes_filter(cmd, *filters, dev);
if (!ret)
return 0; /* No 'stack': a filter, not an error. */
return 1;
}
-static int _and_p_with_dev_ext_info(struct dev_filter *f, struct device *dev)
+static int _and_p_with_dev_ext_info(struct cmd_context *cmd, struct dev_filter *f, struct device *dev)
{
int r;
dev_ext_enable(dev, external_device_info_source());
- r = _and_p(f, dev);
+ r = _and_p(cmd, f, dev);
dev_ext_disable(dev);
return r;
#define MSG_SKIPPING "%s: Skipping firmware RAID component device"
-static int _ignore_fwraid(struct dev_filter *f __attribute__((unused)),
+static int _ignore_fwraid(struct cmd_context *cmd, struct dev_filter *f __attribute__((unused)),
struct device *dev)
{
int ret;
dm_list_init(&_allow_devs);
}
-static int _passes_internal(struct dev_filter *f __attribute__((unused)),
+static int _passes_internal(struct cmd_context *cmd, struct dev_filter *f __attribute__((unused)),
struct device *dev)
{
struct device_list *devl;
* that lvm uses to be occasionally wrong.)
*/
+/*
+ * FIXME: for commands that want a full md check (pvcreate, vgcreate,
+ * vgextend), we do an extra read at the end of every device that the
+ * filter looks at. This isn't necessary; we only need to do the full
+ * md check on the PVs that these commands are trying to use.
+ */
+
/*
* Returns 0 if:
* the device is an md component and it should be ignored.
* that will not pass.
*/
-static int _passes_md_filter(struct device *dev, int full)
+static int _passes_md_filter(struct cmd_context *cmd, struct dev_filter *f __attribute__((unused)), struct device *dev)
{
int ret;
if (!md_filtering())
return 1;
- ret = dev_is_md(dev, NULL, full);
+ ret = dev_is_md(dev, NULL, cmd->use_full_md_check);
if (ret == -EAGAIN) {
/* let pass, call again after scan */
return 1;
}
-static int _passes_md_filter_lite(struct dev_filter *f __attribute__((unused)),
- struct device *dev)
-{
- return _passes_md_filter(dev, 0);
-}
-
-static int _passes_md_filter_full(struct dev_filter *f __attribute__((unused)),
- struct device *dev)
-{
- return _passes_md_filter(dev, 1);
-}
-
static void _destroy(struct dev_filter *f)
{
if (f->use_count)
return NULL;
}
- /*
- * FIXME: for commands that want a full md check (pvcreate, vgcreate,
- * vgextend), we do an extra read at the end of every device that the
- * filter looks at. This isn't necessary; we only need to do the full
- * md check on the PVs that these commands are trying to use.
- */
-
- if (cmd->use_full_md_check)
- f->passes_filter = _passes_md_filter_full;
- else
- f->passes_filter = _passes_md_filter_lite;
-
+ f->passes_filter = _passes_md_filter;
f->destroy = _destroy;
f->use_count = 0;
f->private = dt;
#define MSG_SKIPPING "%s: Skipping mpath component device"
-static int _ignore_mpath(struct dev_filter *f, struct device *dev)
+static int _ignore_mpath(struct cmd_context *cmd, struct dev_filter *f, struct device *dev)
{
if (_dev_is_mpath(f, dev) == 1) {
if (dev->ext.src == DEV_EXT_NONE)
#define MSG_SKIPPING "%s: Skipping: Partition table signature found"
-static int _passes_partitioned_filter(struct dev_filter *f, struct device *dev)
+static int _passes_partitioned_filter(struct cmd_context *cmd, struct dev_filter *f, struct device *dev)
{
struct dev_types *dt = (struct dev_types *) f->private;
int ret;
dm_hash_wipe(pf->devices);
}
-static int _lookup_p(struct dev_filter *f, struct device *dev)
+static int _lookup_p(struct cmd_context *cmd, struct dev_filter *f, struct device *dev)
{
struct pfilter *pf = (struct pfilter *) f->private;
void *l;
if (!l) {
dev->flags &= ~DEV_FILTER_AFTER_SCAN;
- pass = pf->real->passes_filter(pf->real, dev);
+ pass = pf->real->passes_filter(cmd, pf->real, dev);
if (!pass) {
/*
return r;
}
-static int _accept_p(struct dev_filter *f, struct device *dev)
+static int _accept_p(struct cmd_context *cmd, struct dev_filter *f, struct device *dev)
{
int m, first = 1, rejected = 0;
struct rfilter *rf = (struct rfilter *) f->private;
#define BUFSIZE 4096
-static int _ignore_signature(struct dev_filter *f __attribute__((unused)),
+static int _ignore_signature(struct cmd_context *cmd, struct dev_filter *f __attribute__((unused)),
struct device *dev)
{
char buf[BUFSIZE];
}
-static int _accept_p(struct dev_filter *f, struct device *dev)
+static int _accept_p(struct cmd_context *cmd, struct dev_filter *f, struct device *dev)
{
struct dev_set *ds = (struct dev_set *) f->private;
#include "lib/misc/lib.h"
#include "lib/filters/filter.h"
-static int _passes_lvm_type_device_filter(struct dev_filter *f, struct device *dev)
+static int _passes_lvm_type_device_filter(struct cmd_context *cmd, struct dev_filter *f, struct device *dev)
{
struct dev_types *dt = (struct dev_types *) f->private;
const char *name = dev_name(dev);
return 0;
}
-static int _passes_usable_filter(struct dev_filter *f, struct device *dev)
+static int _passes_usable_filter(struct cmd_context *cmd, struct dev_filter *f, struct device *dev)
{
filter_mode_t mode = *((filter_mode_t *) f->private);
struct dev_usable_check_params ucp = {0};
log_debug_devs("Scan filtering %s", dev_name(dev));
- pass = f->passes_filter(f, dev);
+ pass = f->passes_filter(cmd, f, dev);
if ((pass == -EAGAIN) || (dev->flags & DEV_FILTER_AFTER_SCAN)) {
/* Shouldn't happen */
return 0;
}
- while ((dev = dev_iter_get(iter))) {
+ while ((dev = dev_iter_get(cmd, iter))) {
if (!(devl = zalloc(sizeof(*devl))))
continue;
devl->dev = dev;
lv_info(cmd, lv, 0, &lvinfo, 0, 0);
devt = MKDEV(lvinfo.major, lvinfo.minor);
- if ((dev = dev_cache_get_by_devt(devt, NULL)))
+ if ((dev = dev_cache_get_by_devt(cmd, devt, NULL)))
label_scan_invalidate(dev);
}
if (!(iter = dev_iter_create(NULL, 0)))
return;
- while ((dev = dev_iter_get(iter))) {
+ while ((dev = dev_iter_get(cmd, iter))) {
if (_in_bcache(dev))
_scan_dev_close(dev);
}
log_print("Zeroing %u MiB on extended internal lvmlock LV...", extend_mb);
- if (!(dev = dev_cache_get(path, NULL))) {
+ if (!(dev = dev_cache_get(cmd, path, NULL))) {
log_error("Extend sanlock LV %s cannot find device.", display_lvname(lv));
return 0;
}
return 0;
}
- if (!(dev = dev_cache_get(name, NULL))) {
+ if (!(dev = dev_cache_get(lv->vg->cmd, name, NULL))) {
log_error("%s: not found: device not cleared", name);
return 0;
}
const char *pv_name)
{
struct pv_list *pvl;
- struct device *dev = dev_cache_get(pv_name, vg->cmd->filter);
+ struct device *dev = dev_cache_get(vg->cmd, pv_name, vg->cmd->filter);
/*
* If the device does not exist or is filtered out, don't bother trying
log_verbose("Writing log header for LV %s to device %s.", display_lvname(lv), name);
- if (!(dev = dev_cache_get(name, NULL))) {
+ if (!(dev = dev_cache_get(cmd, name, NULL))) {
log_error("%s: not found: log header not written.", name);
return 0;
}
int pv_parts_found;
int max_len;
-static int _get_max_dev_name_len(struct dev_filter *filter)
+static int _get_max_dev_name_len(struct cmd_context *cmd, struct dev_filter *filter)
{
int len = 0;
int maxlen = 0;
}
/* Do scan */
- for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) {
+ for (dev = dev_iter_get(cmd, iter); dev; dev = dev_iter_get(cmd, iter)) {
len = strlen(dev_name(dev));
if (len > maxlen)
maxlen = len;
/* Call before using dev_iter which uses filters which want bcache data. */
label_scan(cmd);
- max_len = _get_max_dev_name_len(cmd->full_filter);
+ max_len = _get_max_dev_name_len(cmd, cmd->full_filter);
if (!(iter = dev_iter_create(cmd->full_filter, 0))) {
log_error("dev_iter_create failed");
return ECMD_FAILED;
}
- for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) {
+ for (dev = dev_iter_get(cmd, iter); dev; dev = dev_iter_get(cmd, iter)) {
if (lvmcache_has_dev_info(dev)) {
if (!dev_get_size(dev, &size)) {
log_error("Couldn't get size of \"%s\"",
pv_name = argv[i];
- dev = dev_cache_get(pv_name, cmd->filter);
+ dev = dev_cache_get(cmd, pv_name, cmd->filter);
if (!dev) {
log_error("Device %s %s.", pv_name, dev_cache_filtered_reason(pv_name));
while (argc--) {
pv_name = *argv++;
if (pv_name[0] == '/') {
- if (!(dev = dev_cache_get(pv_name, cmd->lvmetad_filter))) {
+ if (!(dev = dev_cache_get(cmd, pv_name, cmd->lvmetad_filter))) {
/* Remove device path from lvmetad. */
log_debug("Removing dev %s from lvmetad cache.", pv_name);
- if ((dev = dev_cache_get(pv_name, NULL))) {
+ if ((dev = dev_cache_get(cmd, pv_name, NULL))) {
if (!_lvmetad_clear_dev(dev->dev, MAJOR(dev->dev), MINOR(dev->dev)))
remove_errors++;
} else {
}
devno = MKDEV((dev_t)major, (dev_t)minor);
- if (!(dev = dev_cache_get_by_devt(devno, cmd->lvmetad_filter))) {
+ if (!(dev = dev_cache_get_by_devt(cmd, devno, cmd->lvmetad_filter))) {
/* Remove major:minor from lvmetad. */
log_debug("Removing dev %d:%d from lvmetad cache.", major, minor);
if (!_lvmetad_clear_dev(devno, major, minor))
devno = MKDEV((dev_t)major, (dev_t)minor);
- if (!(dev = dev_cache_get_by_devt(devno, cmd->lvmetad_filter))) {
+ if (!(dev = dev_cache_get_by_devt(cmd, devno, cmd->lvmetad_filter))) {
/* Remove major:minor from lvmetad. */
log_debug("Removing dev %d:%d from lvmetad cache.", major, minor);
if (!_lvmetad_clear_dev(devno, major, minor))
if (single_args->args_are_pvs && args->argc) {
for (i = 0; i < args->argc; i++) {
- if (!rescan_done && !dev_cache_get(args->argv[i], cmd->full_filter)) {
+ if (!rescan_done && !dev_cache_get(cmd, args->argv[i], cmd->full_filter)) {
cmd->filter->wipe(cmd->filter);
/* FIXME scan only one device */
lvmcache_label_scan(cmd);
if (argc) {
for (; opt < argc; opt++) {
- if (!(dev = dev_cache_get(argv[opt], cmd->full_filter))) {
+ if (!(dev = dev_cache_get(cmd, argv[opt], cmd->full_filter))) {
log_error("Failed to find device "
"\"%s\".", argv[opt]);
ret_max = ECMD_FAILED;
goto out;
}
- while ((dev = dev_iter_get(iter)))
+ while ((dev = dev_iter_get(cmd, iter)))
{
if (!(label = lvmcache_get_dev_label(dev)))
continue;
return ECMD_FAILED;
}
- if (!(dil->dev = dev_cache_get(sl->str, cmd->filter))) {
+ if (!(dil->dev = dev_cache_get(cmd, sl->str, cmd->filter))) {
log_error("Failed to find device for physical volume \"%s\".", sl->str);
ret_max = ECMD_FAILED;
} else {
return ECMD_FAILED;
}
- while ((dev = dev_iter_get(iter))) {
+ while ((dev = dev_iter_get(cmd, iter))) {
if (!(dil = dm_pool_alloc(cmd->mem, sizeof(*dil)))) {
log_error("device_id_list alloc failed.");
goto out;
* Translate arg names into struct device's.
*/
dm_list_iterate_items(pd, &pp->arg_devices)
- pd->dev = dev_cache_get(pd->name, cmd->full_filter);
+ pd->dev = dev_cache_get(cmd, pd->name, cmd->full_filter);
/*
* Use process_each_pv to search all existing PVs and devices.