int lvm_lv_activate(lv_t lv) { if (!lv || !lv->vg || vg_read_error(lv->vg) || !lv->vg->cmd) return -1; /* FIXME: handle pvmove stuff later */ if (lv->status & LOCKED) { log_error("Unable to activate locked LV"); return -1; } /* FIXME: handle lvconvert stuff later */ if (lv->status & CONVERTING) { log_error("Unable to activate LV with in-progress lvconvert"); return -1; } if (lv_is_origin(lv)) { log_verbose("Activating logical volume \"%s\" " "exclusively", lv->name); if (!activate_lv_excl(lv->vg->cmd, lv)) { log_error("Activate exclusive failed."); return -1; } } else { log_verbose("Activating logical volume \"%s\"", lv->name); if (!activate_lv(lv->vg->cmd, lv)) { log_error("Activate failed."); return -1; } } return 0; }
static int _lvchange_activate(struct cmd_context *cmd, struct logical_volume *lv) { int activate; activate = arg_uint_value(cmd, activate_ARG, 0); if (lv_is_cow(lv) && !lv_is_virtual_origin(origin_from_cow(lv))) lv = origin_from_cow(lv); if (activate == CHANGE_AAY) { if (!lv_passes_auto_activation_filter(cmd, lv)) return 1; activate = CHANGE_ALY; } if (activate == CHANGE_ALN) { log_verbose("Deactivating logical volume \"%s\" locally", lv->name); if (!deactivate_lv_local(cmd, lv)) return_0; } else if (activate == CHANGE_AN) { log_verbose("Deactivating logical volume \"%s\"", lv->name); if (!deactivate_lv(cmd, lv)) return_0; } else { if ((activate == CHANGE_AE) || lv_is_origin(lv) || lv_is_thin_type(lv)) { log_verbose("Activating logical volume \"%s\" " "exclusively", lv->name); if (!activate_lv_excl(cmd, lv)) return_0; } else if (activate == CHANGE_ALY) { log_verbose("Activating logical volume \"%s\" locally", lv->name); if (!activate_lv_local(cmd, lv)) return_0; } else { log_verbose("Activating logical volume \"%s\"", lv->name); if (!activate_lv(cmd, lv)) return_0; } if (background_polling()) lv_spawn_background_polling(cmd, lv); } return 1; }
/* * Cleanup orphan device in the table with temporary activation * since in the suspend() we can't deactivate unused nodes * and the resume() phase mishandles orphan nodes. * * TODO: improve libdm to handle this case automatically */ static int _cleanup_orphan_lv(struct logical_volume *lv) { lv->status |= LV_TEMPORARY; if (!activate_lv(lv->vg->cmd, lv)) { log_error("Failed to activate temporary %s", lv->name); return 0; } if (!deactivate_lv(lv->vg->cmd, lv)) { log_error("Failed to deactivate temporary %s", lv->name); return 0; } lv->status &= ~LV_TEMPORARY; return 1; }
static int lvchange_availability(struct cmd_context *cmd, struct logical_volume *lv) { int activate; activate = arg_uint_value(cmd, available_ARG, 0); if (activate == CHANGE_ALN) { log_verbose("Deactivating logical volume \"%s\" locally", lv->name); if (!deactivate_lv_local(cmd, lv)) return_0; } else if (activate == CHANGE_AN) { log_verbose("Deactivating logical volume \"%s\"", lv->name); if (!deactivate_lv(cmd, lv)) return_0; } else { if (lv_is_origin(lv) || (activate == CHANGE_AE)) { log_verbose("Activating logical volume \"%s\" " "exclusively", lv->name); if (!activate_lv_excl(cmd, lv)) return_0; } else if (activate == CHANGE_ALY) { log_verbose("Activating logical volume \"%s\" locally", lv->name); if (!activate_lv_local(cmd, lv)) return_0; } else { log_verbose("Activating logical volume \"%s\"", lv->name); if (!activate_lv(cmd, lv)) return_0; } if (background_polling()) lv_spawn_background_polling(cmd, lv); } return 1; }
static int lvchange_persistent(struct cmd_context *cmd, struct logical_volume *lv) { struct lvinfo info; int active = 0; if (!strcmp(arg_str_value(cmd, persistent_ARG, "n"), "n")) { if (!(lv->status & FIXED_MINOR)) { log_error("Minor number is already not persistent " "for \"%s\"", lv->name); return 0; } lv->status &= ~FIXED_MINOR; lv->minor = -1; lv->major = -1; log_verbose("Disabling persistent device number for \"%s\"", lv->name); } else { if (!arg_count(cmd, minor_ARG) && lv->minor < 0) { log_error("Minor number must be specified with -My"); return 0; } if (arg_count(cmd, major_ARG) > 1) { log_error("Option -j/--major may not be repeated."); return 0; } if (arg_count(cmd, minor_ARG) > 1) { log_error("Option --minor may not be repeated."); return 0; } if (!arg_count(cmd, major_ARG) && lv->major < 0) { log_error("Major number must be specified with -My"); return 0; } if (lv_info(cmd, lv, 0, &info, 0, 0) && info.exists) active = 1; if (active && !arg_count(cmd, force_ARG) && yes_no_prompt("Logical volume %s will be " "deactivated temporarily. " "Continue? [y/n]: ", lv->name) == 'n') { log_error("%s device number not changed.", lv->name); return 0; } if (sigint_caught()) return 0; log_verbose("Ensuring %s is inactive.", lv->name); if (!deactivate_lv(cmd, lv)) { log_error("%s: deactivation failed", lv->name); return 0; } lv->status |= FIXED_MINOR; lv->minor = arg_int_value(cmd, minor_ARG, lv->minor); lv->major = arg_int_value(cmd, major_ARG, lv->major); log_verbose("Setting persistent device number to (%d, %d) " "for \"%s\"", lv->major, lv->minor, lv->name); } log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); if (!vg_write(lv->vg) || !vg_commit(lv->vg)) return_0; backup(lv->vg); if (active) { log_verbose("Re-activating logical volume \"%s\"", lv->name); if (!activate_lv(cmd, lv)) { log_error("%s: reactivation failed", lv->name); return 0; } } return 1; }
static int lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv) { int active = 0; int monitored; struct lvinfo info; struct logical_volume *log_lv; if (!(lv->status & MIRRORED)) { log_error("Unable to resync %s because it is not mirrored.", lv->name); return 1; } if (lv->status & PVMOVE) { log_error("Unable to resync pvmove volume %s", lv->name); return 0; } if (lv->status & LOCKED) { log_error("Unable to resync locked volume %s", lv->name); return 0; } if (lv_info(cmd, lv, 0, &info, 1, 0)) { if (info.open_count) { log_error("Can't resync open logical volume \"%s\"", lv->name); return 0; } if (info.exists) { if (!arg_count(cmd, yes_ARG) && yes_no_prompt("Do you really want to deactivate " "logical volume %s to resync it? [y/n]: ", lv->name) == 'n') { log_error("Logical volume \"%s\" not resynced", lv->name); return 0; } if (sigint_caught()) return 0; active = 1; } } /* Activate exclusively to ensure no nodes still have LV active */ monitored = dmeventd_monitor_mode(); init_dmeventd_monitor(0); if (!deactivate_lv(cmd, lv)) { log_error("Unable to deactivate %s for resync", lv->name); return 0; } if (vg_is_clustered(lv->vg) && lv_is_active(lv)) { log_error("Can't get exclusive access to clustered volume %s", lv->name); return 0; } init_dmeventd_monitor(monitored); log_lv = first_seg(lv)->log_lv; log_very_verbose("Starting resync of %s%s%s mirror \"%s\"", (active) ? "active " : "", vg_is_clustered(lv->vg) ? "clustered " : "", (log_lv) ? "disk-logged" : "core-logged", lv->name); /* * If this mirror has a core log (i.e. !log_lv), * then simply deactivating/activating will cause * it to reset the sync status. We only need to * worry about persistent logs. */ if (!log_lv && !(lv->status & LV_NOTSYNCED)) { if (active && !activate_lv(cmd, lv)) { log_error("Failed to reactivate %s to resynchronize " "mirror", lv->name); return 0; } return 1; } lv->status &= ~LV_NOTSYNCED; if (log_lv) { /* Separate mirror log so we can clear it */ detach_mirror_log(first_seg(lv)); if (!vg_write(lv->vg)) { log_error("Failed to write intermediate VG metadata."); if (!attach_mirror_log(first_seg(lv), log_lv)) stack; if (active && !activate_lv(cmd, lv)) stack; return 0; } if (!vg_commit(lv->vg)) { log_error("Failed to commit intermediate VG metadata."); if (!attach_mirror_log(first_seg(lv), log_lv)) stack; if (active && !activate_lv(cmd, lv)) stack; return 0; } backup(lv->vg); if (!activate_lv(cmd, log_lv)) { log_error("Unable to activate %s for mirror log resync", log_lv->name); return 0; } log_very_verbose("Clearing log device %s", log_lv->name); if (!set_lv(cmd, log_lv, log_lv->size, 0)) { log_error("Unable to reset sync status for %s", lv->name); if (!deactivate_lv(cmd, log_lv)) log_error("Failed to deactivate log LV after " "wiping failed"); return 0; } if (!deactivate_lv(cmd, log_lv)) { log_error("Unable to deactivate log LV %s after wiping " "for resync", log_lv->name); return 0; } /* Put mirror log back in place */ if (!attach_mirror_log(first_seg(lv), log_lv)) stack; } log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); if (!vg_write(lv->vg) || !vg_commit(lv->vg)) { log_error("Failed to update metadata on disk."); return 0; } if (active && !activate_lv(cmd, lv)) { log_error("Failed to reactivate %s after resync", lv->name); return 0; } return 1; }
int vg_remove_snapshot(struct logical_volume *cow) { int merging_snapshot = 0; struct logical_volume *origin = origin_from_cow(cow); int is_origin_active = lv_is_active(origin); if (is_origin_active && lv_is_virtual_origin(origin)) { if (!deactivate_lv(origin->vg->cmd, origin)) { log_error("Failed to deactivate logical volume \"%s\"", origin->name); return 0; } is_origin_active = 0; } dm_list_del(&cow->snapshot->origin_list); origin->origin_count--; if (lv_is_merging_origin(origin) && (find_snapshot(origin) == find_snapshot(cow))) { clear_snapshot_merge(origin); /* * preload origin IFF "snapshot-merge" target is active * - IMPORTANT: avoids preload if inactivate merge is pending */ if (lv_has_target_type(origin->vg->vgmem, origin, NULL, TARGET_NAME_SNAPSHOT_MERGE)) { /* * preload origin to: * - allow proper release of -cow * - avoid allocations with other devices suspended * when transitioning from "snapshot-merge" to * "snapshot-origin after a merge completes. */ merging_snapshot = 1; } } if (!lv_remove(cow->snapshot->lv)) { log_error("Failed to remove internal snapshot LV %s", cow->snapshot->lv->name); return 0; } cow->snapshot = NULL; lv_set_visible(cow); /* format1 must do the change in one step, with the commit last. */ if (!(origin->vg->fid->fmt->features & FMT_MDAS)) { /* Get the lock for COW volume */ if (is_origin_active && !activate_lv(cow->vg->cmd, cow)) { log_error("Unable to activate logical volume \"%s\"", cow->name); return 0; } return 1; } if (!vg_write(origin->vg)) return_0; /* Skip call suspend, if device is not active */ if (is_origin_active && !suspend_lv(origin->vg->cmd, origin)) { log_error("Failed to refresh %s without snapshot.", origin->name); vg_revert(origin->vg); return 0; } if (!vg_commit(origin->vg)) return_0; if (is_origin_active) { /* * If the snapshot was active and the COW LV is taken away * the LV lock on cluster has to be grabbed, so use * activate_lv() which resumes suspend cow device. */ if (!merging_snapshot && !activate_lv(cow->vg->cmd, cow)) { log_error("Failed to activate %s.", cow->name); return 0; } if (!resume_lv(origin->vg->cmd, origin)) { log_error("Failed to resume %s.", origin->name); return 0; } /* * For merged snapshot and clustered VG activate cow LV so * the following call to deactivate_lv() can clean-up table * entries. For this clustered lock need to be held. */ if (vg_is_clustered(cow->vg) && merging_snapshot && !activate_lv(cow->vg->cmd, cow)) { log_error("Failed to activate %s.", cow->name); return 0; } } return 1; }