struct lv_segment *find_merging_cow(const struct logical_volume *origin) { if (!lv_is_merging_origin(origin)) return NULL; return find_cow(origin); }
int dev_manager_snapshot_percent(struct dev_manager *dm, const struct logical_volume *lv, float *percent, percent_range_t *percent_range) { char *name; const char *dlid; int fail_if_percent_unsupported = 0; if (lv_is_merging_origin(lv)) { /* * Set 'fail_if_percent_unsupported', otherwise passing * unsupported LV types to _percent will lead to a default * successful return with percent_range as PERCENT_100. * - For a merging origin, this will result in a polldaemon * that runs infinitely (because completion is PERCENT_0) * - We unfortunately don't yet _know_ if a snapshot-merge * target is active (activation is deferred if dev is open); * so we can't short-circuit origin devices based purely on * existing LVM LV attributes. */ fail_if_percent_unsupported = 1; } /* * Build a name for the top layer. */ if (!(name = build_dm_name(dm->mem, lv->vg->name, lv->name, NULL))) return_0; if (!(dlid = build_dm_uuid(dm->mem, lv->lvid.s, NULL))) return_0; /* * Try and get some info on this device. */ log_debug("Getting device status percentage for %s", name); if (!(_percent(dm, name, dlid, "snapshot", 0, NULL, percent, percent_range, NULL, fail_if_percent_unsupported))) return_0; /* FIXME dm_pool_free ? */ /* If the snapshot isn't available, percent will be -1 */ return 1; }
/* Check if given LV is usable as snapshot origin LV */ int validate_snapshot_origin(const struct logical_volume *origin_lv) { const char *err = NULL; /* For error string */ if (lv_is_cow(origin_lv)) err = "snapshots"; else if (lv_is_locked(origin_lv)) err = "locked volumes"; else if (lv_is_pvmove(origin_lv)) err = "pvmoved volumes"; else if (!lv_is_visible(origin_lv)) err = "hidden volumes"; else if (lv_is_merging_origin(origin_lv)) err = "an origin that has a merging snapshot"; else if (lv_is_cache_type(origin_lv) && !lv_is_cache(origin_lv)) err = "cache type volumes"; else if (lv_is_thin_type(origin_lv) && !lv_is_thin_volume(origin_lv)) err = "thin pool type volumes"; else if (lv_is_mirror_type(origin_lv)) { if (!lv_is_mirror(origin_lv)) err = "mirror subvolumes"; else { log_warn("WARNING: Snapshots of mirrors can deadlock under rare device failures."); log_warn("WARNING: Consider using the raid1 mirror type to avoid this."); log_warn("WARNING: See global/mirror_segtype_default in lvm.conf."); } } else if (lv_is_raid_type(origin_lv) && !lv_is_raid(origin_lv)) err = "raid subvolumes"; if (err) { log_error("Snapshots of %s are not supported.", err); return 0; } if (vg_is_clustered(origin_lv->vg) && lv_is_active(origin_lv) && !lv_is_active_exclusive_locally(origin_lv)) { log_error("Snapshot origin must be active exclusively."); 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; }