2
2
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3
* Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
3
* Copyright (C) 2004-2012 Red Hat, Inc. All rights reserved.
5
5
* This file is part of LVM2.
150
int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, unsigned origin_only,
150
int lvm_dm_prefix_check(int major, int minor, const char *prefix)
154
int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, int use_layer,
151
155
struct lvinfo *info, int with_open_count, int with_read_ahead)
155
int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
156
unsigned origin_only,
159
int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, int use_layer,
157
160
struct lvinfo *info, int with_open_count, int with_read_ahead)
164
int lv_check_not_in_use(struct cmd_context *cmd __attribute__((unused)),
165
struct logical_volume *lv, struct lvinfo *info)
161
169
int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent)
170
int lvs_in_vg_activated(struct volume_group *vg)
178
int lv_raid_percent(const struct logical_volume *lv, percent_t *percent)
182
int lv_thin_pool_percent(const struct logical_volume *lv, int metadata,
187
int lv_thin_percent(const struct logical_volume *lv, int mapped,
192
int lv_thin_pool_transaction_id(const struct logical_volume *lv,
193
uint64_t *transaction_id)
197
int lvs_in_vg_activated(const struct volume_group *vg)
192
219
int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s,
193
unsigned origin_only, unsigned exclusive)
220
unsigned origin_only, unsigned exclusive, unsigned revert)
226
253
void activation_exit(void)
229
int lv_is_active(struct logical_volume *lv)
233
int lv_is_active_exclusive_locally(struct logical_volume *lv)
237
int lv_is_active_exclusive_remotely(struct logical_volume *lv)
257
int lv_is_active(const struct logical_volume *lv)
261
int lv_is_active_but_not_locally(const struct logical_volume *lv)
265
int lv_is_active_exclusive(const struct logical_volume *lv)
269
int lv_is_active_exclusive_locally(const struct logical_volume *lv)
273
int lv_is_active_exclusive_remotely(const struct logical_volume *lv)
241
278
int lv_check_transient(struct logical_volume *lv)
245
282
int monitor_dev_for_events(struct cmd_context *cmd, struct logical_volume *lv,
246
struct lv_activate_opts *laopts, int monitor)
283
const struct lv_activate_opts *laopts, int monitor)
293
int add_areas_line(struct dev_manager *dm, struct lv_segment *seg,
294
struct dm_tree_node *node, uint32_t start_area,
299
int device_is_usable(struct device *dev)
303
int lv_has_target_type(struct dm_pool *mem, struct logical_volume *lv,
304
const char *layer, const char *target_type)
250
308
#else /* DEVMAPPER_SUPPORT */
252
310
static int _activation = 1;
270
328
return _activation;
273
static int _passes_activation_filter(struct cmd_context *cmd,
274
struct logical_volume *lv)
331
static int _passes_volumes_filter(struct cmd_context *cmd,
332
struct logical_volume *lv,
333
const struct dm_config_node *cn,
334
const char *config_path)
276
const struct config_node *cn;
277
const struct config_value *cv;
336
const struct dm_config_value *cv;
281
if (!(cn = find_config_tree_node(cmd, "activation/volume_list"))) {
282
log_verbose("activation/volume_list configuration setting "
283
"not defined, checking only host tags for %s/%s",
284
lv->vg->name, lv->name);
286
/* If no host tags defined, activate */
287
if (dm_list_empty(&cmd->tags))
290
/* If any host tag matches any LV or VG tag, activate */
291
if (str_list_match_list(&cmd->tags, &lv->tags, NULL) ||
292
str_list_match_list(&cmd->tags, &lv->vg->tags, NULL))
295
log_verbose("No host tag matches %s/%s",
296
lv->vg->name, lv->name);
302
log_verbose("activation/volume_list configuration setting "
303
"defined, checking the list to match %s/%s",
304
lv->vg->name, lv->name);
338
static char path[PATH_MAX];
340
log_verbose("%s configuration setting defined: "
341
"Checking the list to match %s/%s",
342
config_path, lv->vg->name, lv->name);
306
344
for (cv = cn->v; cv; cv = cv->next) {
307
if (cv->type != CFG_STRING) {
308
log_error("Ignoring invalid string in config file "
309
"activation/volume_list");
345
if (cv->type != DM_CFG_STRING) {
346
log_error("Ignoring invalid string in config file %s",
314
log_error("Ignoring empty string in config file "
315
"activation/volume_list");
352
log_error("Ignoring empty string in config file %s",
362
log_verbose("No item supplied in activation/volume_list configuration "
363
"setting matches %s/%s", lv->vg->name, lv->name);
400
log_verbose("No item supplied in %s configuration setting "
401
"matches %s/%s", config_path, lv->vg->name, lv->name);
406
static int _passes_activation_filter(struct cmd_context *cmd,
407
struct logical_volume *lv)
409
const struct dm_config_node *cn;
411
if (!(cn = find_config_tree_node(cmd, "activation/volume_list"))) {
412
log_verbose("activation/volume_list configuration setting "
413
"not defined: Checking only host tags for %s/%s",
414
lv->vg->name, lv->name);
416
/* If no host tags defined, activate */
417
if (dm_list_empty(&cmd->tags))
420
/* If any host tag matches any LV or VG tag, activate */
421
if (str_list_match_list(&cmd->tags, &lv->tags, NULL) ||
422
str_list_match_list(&cmd->tags, &lv->vg->tags, NULL))
425
log_verbose("No host tag matches %s/%s",
426
lv->vg->name, lv->name);
432
return _passes_volumes_filter(cmd, lv, cn, "activation/volume_list");
435
static int _passes_readonly_filter(struct cmd_context *cmd,
436
struct logical_volume *lv)
438
const struct dm_config_node *cn;
440
if (!(cn = find_config_tree_node(cmd, "activation/read_only_volume_list")))
443
return _passes_volumes_filter(cmd, lv, cn, "activation/read_only_volume_list");
368
446
int library_version(char *version, size_t size)
370
448
if (!activation())
510
int lvm_dm_prefix_check(int major, int minor, const char *prefix)
516
if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
519
if (!dm_task_set_minor(dmt, minor) ||
520
!dm_task_set_major(dmt, major) ||
522
!(uuid = dm_task_get_uuid(dmt))) {
523
dm_task_destroy(dmt);
527
r = strncasecmp(uuid, prefix, strlen(prefix));
528
dm_task_destroy(dmt);
428
533
int module_present(struct cmd_context *cmd, const char *target_name)
472
577
* Returns 1 if info structure populated, else 0 on failure.
474
int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, unsigned origin_only,
579
int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, int use_layer,
475
580
struct lvinfo *info, int with_open_count, int with_read_ahead)
477
582
struct dm_info dminfo;
479
585
if (!activation())
491
597
fs_unlock(); /* For non clustered - wait if there are non-delete ops */
494
if (!dev_manager_info(lv->vg->cmd->mem, lv, origin_only ? "real" : NULL, with_open_count,
600
if (use_layer && lv_is_thin_pool(lv))
602
else if (use_layer && lv_is_origin(lv))
607
if (!dev_manager_info(lv->vg->cmd->mem, lv, layer, with_open_count,
495
608
with_read_ahead, &dminfo, &info->read_ahead))
510
int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
511
unsigned origin_only,
623
int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s, int use_layer,
512
624
struct lvinfo *info, int with_open_count, int with_read_ahead)
517
629
if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
520
if (!lv_is_origin(lv))
523
r = lv_info(cmd, lv, origin_only, info, with_open_count, with_read_ahead);
632
r = lv_info(cmd, lv, use_layer, info, with_open_count, with_read_ahead);
524
633
release_vg(lv->vg);
638
int lv_check_not_in_use(struct cmd_context *cmd __attribute__((unused)),
639
struct logical_volume *lv, struct lvinfo *info)
644
/* If sysfs is not used, use open_count information only. */
645
if (!*dm_sysfs_dir()) {
646
if (info->open_count) {
647
log_error("Logical volume %s/%s in use.",
648
lv->vg->name, lv->name);
655
if (dm_device_has_holders(info->major, info->minor)) {
656
log_error("Logical volume %s/%s is used by another device.",
657
lv->vg->name, lv->name);
661
if (dm_device_has_mounted_fs(info->major, info->minor)) {
662
log_error("Logical volume %s/%s contains a filesystem in use.",
663
lv->vg->name, lv->name);
530
671
* Returns 1 if percent set, else 0 on failure.
616
757
return lv_mirror_percent(lv->vg->cmd, lv, 0, percent, NULL);
619
static int _lv_active(struct cmd_context *cmd, struct logical_volume *lv)
761
* Returns data or metadata percent usage, depends on metadata 0/1.
762
* Returns 1 if percent set, else 0 on failure.
764
int lv_thin_pool_percent(const struct logical_volume *lv, int metadata,
768
struct dev_manager *dm;
773
log_debug("Checking thin %sdata percent for LV %s/%s",
774
(metadata) ? "meta" : "", lv->vg->name, lv->name);
776
if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name, 1)))
779
if (!(r = dev_manager_thin_pool_percent(dm, lv, metadata, percent)))
782
dev_manager_destroy(dm);
788
* Returns 1 if percent set, else 0 on failure.
790
int lv_thin_percent(const struct logical_volume *lv,
791
int mapped, percent_t *percent)
794
struct dev_manager *dm;
799
log_debug("Checking thin percent for LV %s/%s",
800
lv->vg->name, lv->name);
802
if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name, 1)))
805
if (!(r = dev_manager_thin_percent(dm, lv, mapped, percent)))
808
dev_manager_destroy(dm);
814
* Returns 1 if transaction_id set, else 0 on failure.
816
int lv_thin_pool_transaction_id(const struct logical_volume *lv,
817
uint64_t *transaction_id)
820
struct dev_manager *dm;
821
struct dm_status_thin_pool *status;
826
log_debug("Checking thin percent for LV %s/%s",
827
lv->vg->name, lv->name);
829
if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name, 1)))
832
if (!(r = dev_manager_thin_pool_status(dm, lv, &status)))
835
*transaction_id = status->transaction_id;
837
dev_manager_destroy(dm);
842
static int _lv_active(struct cmd_context *cmd, const struct logical_volume *lv)
621
844
struct lvinfo info;
658
881
static int _lv_preload(struct logical_volume *lv, struct lv_activate_opts *laopts,
659
882
int *flush_required)
662
885
struct dev_manager *dm;
886
int old_readonly = laopts->read_only;
888
laopts->read_only = _passes_readonly_filter(lv->vg->cmd, lv);
664
890
if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name, (lv->status & PVMOVE) ? 0 : 1)))
667
893
if (!(r = dev_manager_preload(dm, lv, laopts, flush_required)))
670
896
dev_manager_destroy(dm);
898
laopts->read_only = old_readonly;
766
997
* Returns: 0 or 1
768
static int _lv_is_active(struct logical_volume *lv,
999
static int _lv_is_active(const struct logical_volume *lv,
769
1000
int *locally, int *exclusive)
771
1002
int r, l, e; /* remote, local, and exclusive */
796
1028
* New users of this function who specifically ask for 'exclusive'
797
1029
* will be given an error message.
801
log_error("Unable to determine exclusivity of %s",
806
/* FIXME: Is this fallback alright? */
807
if (activate_lv_excl(lv->vg->cmd, lv)) {
808
if (!deactivate_lv(lv->vg->cmd, lv))
810
/* FIXME: locally & exclusive are undefined. */
813
/* FIXME: Check exclusive value here. */
1031
log_error("Unable to determine exclusivity of %s", lv->name);
1036
* We used to attempt activate_lv_excl_local(lv->vg->cmd, lv) here,
1037
* but it's unreliable.
829
int lv_is_active(struct logical_volume *lv)
1055
int lv_is_active(const struct logical_volume *lv)
831
1057
return _lv_is_active(lv, NULL, NULL);
834
int lv_is_active_but_not_locally(struct logical_volume *lv)
1060
int lv_is_active_but_not_locally(const struct logical_volume *lv)
837
1063
return _lv_is_active(lv, &l, NULL) && !l;
840
int lv_is_active_exclusive_locally(struct logical_volume *lv)
1066
int lv_is_active_exclusive(const struct logical_volume *lv)
1070
return _lv_is_active(lv, NULL, &e) && e;
1073
int lv_is_active_exclusive_locally(const struct logical_volume *lv)
844
1077
return _lv_is_active(lv, &l, &e) && l && e;
847
int lv_is_active_exclusive_remotely(struct logical_volume *lv)
1080
int lv_is_active_exclusive_remotely(const struct logical_volume *lv)
1129
static char *_build_target_uuid(struct cmd_context *cmd, struct logical_volume *lv)
1133
if (lv_is_thin_pool(lv))
1134
layer = "tpool"; /* Monitor "tpool" for the "thin pool". */
1135
else if (lv_is_origin(lv))
1136
layer = "real"; /* Monitor "real" for "snapshot-origin". */
1140
return build_dm_uuid(cmd->mem, lv->lvid.s, layer);
896
1143
int target_registered_with_dmeventd(struct cmd_context *cmd, const char *dso,
897
1144
struct logical_volume *lv, int *pending)
900
1147
enum dm_event_mask evmask = 0;
901
1148
struct dm_event_handler *dmevh;
908
/* We always monitor the "real" device, never the "snapshot-origin" itself. */
909
if (!(uuid = build_dm_uuid(cmd->mem, lv->lvid.s, lv_is_origin(lv) ? "real" : NULL)))
1154
if (!(uuid = _build_target_uuid(cmd, lv)))
912
1157
if (!(dmevh = _create_dm_event_handler(cmd, uuid, dso, 0, DM_EVENT_ALL_ERRORS)))
941
1186
/* We always monitor the "real" device, never the "snapshot-origin" itself. */
942
if (!(uuid = build_dm_uuid(cmd->mem, lv->lvid.s, lv_is_origin(lv) ? "real" : NULL)))
1187
if (!(uuid = _build_target_uuid(cmd, lv)))
945
1190
if (!(dmevh = _create_dm_event_handler(cmd, uuid, dso, timeout,
1284
/* Returns success if the device is not active */
1285
int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s, unsigned origin_only)
1530
* In a cluster, set exclusive to indicate that only one node is using the
1531
* device. Any preloaded tables may then use non-clustered targets.
1533
* Returns success if the device is not active
1535
int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s, unsigned origin_only, unsigned exclusive)
1287
struct lv_activate_opts laopts = { .origin_only = origin_only };
1537
struct lv_activate_opts laopts = {
1538
.origin_only = origin_only,
1539
.exclusive = exclusive
1289
1542
return _lv_suspend(cmd, lvid_s, &laopts, 0);
1305
* @exclusive: This parameter only has an affect in cluster-context.
1306
* It forces local target type to be used (instead of
1307
* cluster-aware type).
1308
* @error_if_not_active
1310
1553
static int _lv_resume(struct cmd_context *cmd, const char *lvid_s,
1311
1554
struct lv_activate_opts *laopts, int error_if_not_active)
1313
1556
struct logical_volume *lv;
1314
1557
struct lvinfo info;
1559
int messages_only = 0;
1317
1561
if (!activation())
1320
1564
if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
1567
if (lv_is_thin_pool(lv) && laopts->origin_only)
1323
1570
if (!lv_is_origin(lv))
1324
1571
laopts->origin_only = 0;
1326
1573
if (test_mode()) {
1327
_skip("Resuming %s%s.", lv->name, laopts->origin_only ? " without snapshots" : "");
1574
_skip("Resuming %s%s%s.", lv->name, laopts->origin_only ? " without snapshots" : "",
1575
laopts->revert ? " (reverting)" : "");
1332
log_debug("Resuming LV %s/%s%s%s.", lv->vg->name, lv->name,
1580
log_debug("Resuming LV %s/%s%s%s%s.", lv->vg->name, lv->name,
1333
1581
error_if_not_active ? "" : " if active",
1334
laopts->origin_only ? " without snapshots" : "");
1582
laopts->origin_only ? " without snapshots" : "",
1583
laopts->revert ? " (reverting)" : "");
1336
1585
if (!lv_info(cmd, lv, laopts->origin_only, &info, 0, 0))
1339
if (!info.exists || !info.suspended) {
1588
if (!info.exists || !(info.suspended || messages_only)) {
1340
1589
if (error_if_not_active)
1364
/* Returns success if the device is not active */
1616
* In a cluster, set exclusive to indicate that only one node is using the
1617
* device. Any tables loaded may then use non-clustered targets.
1620
* @exclusive This parameter only has an affect in cluster-context.
1621
* It forces local target type to be used (instead of
1622
* cluster-aware type).
1623
* Returns success if the device is not active
1365
1625
int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s,
1366
unsigned origin_only, unsigned exclusive)
1626
unsigned origin_only, unsigned exclusive,
1368
1629
struct lv_activate_opts laopts = {
1369
1630
.origin_only = origin_only,
1371
* When targets are activated exclusively in a cluster, the
1372
* non-clustered target should be used. This only happens
1373
* if exclusive is set.
1375
.exclusive = exclusive
1631
.exclusive = exclusive,
1378
1635
return _lv_resume(cmd, lvid_s, &laopts, 0);
1538
log_debug("Activating %s/%s%s.", lv->vg->name, lv->name,
1539
laopts->exclusive ? " exclusively" : "");
1794
laopts->read_only = _passes_readonly_filter(cmd, lv);
1796
log_debug("Activating %s/%s%s%s.", lv->vg->name, lv->name,
1797
laopts->exclusive ? " exclusively" : "",
1798
laopts->read_only ? " read-only" : "");
1541
1800
if (!lv_info(cmd, lv, 0, &info, 0, 0))
1544
if (info.exists && !info.suspended && info.live_table) {
1806
if (info.exists && !info.suspended && info.live_table &&
1807
(info.read_only == read_only_lv(lv, laopts))) {