void memlock_init(struct cmd_context *cmd) { /* When threaded, caller already limited stack size so just use the default. */ _size_stack = 1024ULL * (cmd->threaded ? DEFAULT_RESERVED_STACK : find_config_tree_int(cmd, activation_reserved_stack_CFG, NULL)); _size_malloc_tmp = find_config_tree_int(cmd, activation_reserved_memory_CFG, NULL) * 1024ULL; _default_priority = find_config_tree_int(cmd, activation_process_priority_CFG, NULL); }
void memlock_init(struct cmd_context *cmd) { _size_stack = find_config_tree_int(cmd, "activation/reserved_stack", DEFAULT_RESERVED_STACK) * 1024; _size_malloc_tmp = find_config_tree_int(cmd, "activation/reserved_memory", DEFAULT_RESERVED_MEMORY) * 1024; _default_priority = find_config_tree_int(cmd, "activation/process_priority", DEFAULT_PROCESS_PRIORITY); }
void memlock_init(struct cmd_context *cmd) { /* When threaded, caller already limited stack size so just use the default. */ _size_stack = 1024ULL * (cmd->threaded ? DEFAULT_RESERVED_STACK : find_config_tree_int(cmd, "activation/reserved_stack", DEFAULT_RESERVED_STACK)); _size_malloc_tmp = find_config_tree_int(cmd, "activation/reserved_memory", DEFAULT_RESERVED_MEMORY) * 1024ULL; _default_priority = find_config_tree_int(cmd, "activation/process_priority", DEFAULT_PROCESS_PRIORITY); }
static void _read_history(struct cmd_context *cmd) { char hist_file[PATH_MAX]; if (!_hist_file(hist_file, sizeof(hist_file))) return; if (read_history(hist_file)) log_very_verbose("Couldn't read history from %s.", hist_file); stifle_history(find_config_tree_int(cmd, shell_history_size_CFG, NULL)); }
static struct mirror_state *_mirrored_init_target(struct dm_pool *mem, struct cmd_context *cmd) { struct mirror_state *mirr_state; if (!(mirr_state = dm_pool_alloc(mem, sizeof(*mirr_state)))) { log_error("struct mirr_state allocation failed"); return NULL; } mirr_state->default_region_size = 2 * find_config_tree_int(cmd, "activation/mirror_region_size", DEFAULT_MIRROR_REGION_SIZE); return mirr_state; }
int fill_vdo_target_params(struct cmd_context *cmd, struct dm_vdo_target_params *vtp, struct profile *profile) { const char *policy; // TODO: Postpone filling data to the moment when VG is known with profile. // TODO: Maybe add more lvm cmdline switches to set profile settings. vtp->use_compression = find_config_tree_int(cmd, allocation_vdo_use_compression_CFG, profile); vtp->use_deduplication = find_config_tree_int(cmd, allocation_vdo_use_deduplication_CFG, profile); vtp->use_metadata_hints = find_config_tree_int(cmd, allocation_vdo_use_metadata_hints_CFG, profile); vtp->minimum_io_size = find_config_tree_int(cmd, allocation_vdo_minimum_io_size_CFG, profile); vtp->block_map_cache_size_mb = find_config_tree_int64(cmd, allocation_vdo_block_map_cache_size_mb_CFG, profile); vtp->block_map_era_length = find_config_tree_int(cmd, allocation_vdo_block_map_era_length_CFG, profile); vtp->check_point_frequency = find_config_tree_int(cmd, allocation_vdo_check_point_frequency_CFG, profile); vtp->use_sparse_index = find_config_tree_int(cmd, allocation_vdo_use_sparse_index_CFG, profile); vtp->index_memory_size_mb = find_config_tree_int64(cmd, allocation_vdo_index_memory_size_mb_CFG, profile); vtp->slab_size_mb = find_config_tree_int(cmd, allocation_vdo_slab_size_mb_CFG, profile); vtp->ack_threads = find_config_tree_int(cmd, allocation_vdo_ack_threads_CFG, profile); vtp->bio_threads = find_config_tree_int(cmd, allocation_vdo_bio_threads_CFG, profile); vtp->bio_rotation = find_config_tree_int(cmd, allocation_vdo_bio_rotation_CFG, profile); vtp->cpu_threads = find_config_tree_int(cmd, allocation_vdo_cpu_threads_CFG, profile); vtp->hash_zone_threads = find_config_tree_int(cmd, allocation_vdo_hash_zone_threads_CFG, profile); vtp->logical_threads = find_config_tree_int(cmd, allocation_vdo_logical_threads_CFG, profile); vtp->physical_threads = find_config_tree_int(cmd, allocation_vdo_physical_threads_CFG, profile); vtp->max_discard = find_config_tree_int(cmd, allocation_vdo_max_discard_CFG, profile); policy = find_config_tree_str(cmd, allocation_vdo_write_policy_CFG, profile); if (!get_vdo_write_policy(&vtp->write_policy, policy)) return_0; return 1; }
static int _report(struct cmd_context *cmd, int argc, char **argv, report_type_t report_type) { void *report_handle; const char *opts; char *str; const char *keys = NULL, *options = NULL, *separator; int r = ECMD_PROCESSED; int aligned, buffered, headings; unsigned args_are_pvs; aligned = find_config_tree_int(cmd, "report/aligned", DEFAULT_REP_ALIGNED); buffered = find_config_tree_int(cmd, "report/buffered", DEFAULT_REP_BUFFERED); headings = find_config_tree_int(cmd, "report/headings", DEFAULT_REP_HEADINGS); separator = find_config_tree_str(cmd, "report/separator", DEFAULT_REP_SEPARATOR); args_are_pvs = (report_type == PVS || report_type == PVSEGS) ? 1 : 0; switch (report_type) { case LVS: keys = find_config_tree_str(cmd, "report/lvs_sort", DEFAULT_LVS_SORT); if (!arg_count(cmd, verbose_ARG)) options = find_config_tree_str(cmd, "report/lvs_cols", DEFAULT_LVS_COLS); else options = find_config_tree_str(cmd, "report/lvs_cols_verbose", DEFAULT_LVS_COLS_VERB); break; case VGS: keys = find_config_tree_str(cmd, "report/vgs_sort", DEFAULT_VGS_SORT); if (!arg_count(cmd, verbose_ARG)) options = find_config_tree_str(cmd, "report/vgs_cols", DEFAULT_VGS_COLS); else options = find_config_tree_str(cmd, "report/vgs_cols_verbose", DEFAULT_VGS_COLS_VERB); break; case PVS: keys = find_config_tree_str(cmd, "report/pvs_sort", DEFAULT_PVS_SORT); if (!arg_count(cmd, verbose_ARG)) options = find_config_tree_str(cmd, "report/pvs_cols", DEFAULT_PVS_COLS); else options = find_config_tree_str(cmd, "report/pvs_cols_verbose", DEFAULT_PVS_COLS_VERB); break; case SEGS: keys = find_config_tree_str(cmd, "report/segs_sort", DEFAULT_SEGS_SORT); if (!arg_count(cmd, verbose_ARG)) options = find_config_tree_str(cmd, "report/segs_cols", DEFAULT_SEGS_COLS); else options = find_config_tree_str(cmd, "report/segs_cols_verbose", DEFAULT_SEGS_COLS_VERB); break; case PVSEGS: keys = find_config_tree_str(cmd, "report/pvsegs_sort", DEFAULT_PVSEGS_SORT); if (!arg_count(cmd, verbose_ARG)) options = find_config_tree_str(cmd, "report/pvsegs_cols", DEFAULT_PVSEGS_COLS); else options = find_config_tree_str(cmd, "report/pvsegs_cols_verbose", DEFAULT_PVSEGS_COLS_VERB); break; } /* If -o supplied use it, else use default for report_type */ if (arg_count(cmd, options_ARG)) { opts = arg_str_value(cmd, options_ARG, ""); if (!opts || !*opts) { log_error("Invalid options string: %s", opts); return 0; } if (*opts == '+') { if (!(str = dm_pool_alloc(cmd->mem, strlen(options) + strlen(opts) + 1))) { log_error("options string allocation failed"); return 0; } strcpy(str, options); strcat(str, ","); strcat(str, opts + 1); options = str; } else options = opts; } /* -O overrides default sort settings */ if (arg_count(cmd, sort_ARG)) keys = arg_str_value(cmd, sort_ARG, ""); if (arg_count(cmd, separator_ARG)) separator = arg_str_value(cmd, separator_ARG, " "); if (arg_count(cmd, separator_ARG)) aligned = 0; if (arg_count(cmd, aligned_ARG)) aligned = 1; if (arg_count(cmd, unbuffered_ARG) && !arg_count(cmd, sort_ARG)) buffered = 0; if (arg_count(cmd, noheadings_ARG)) headings = 0; if (!(report_handle = report_init(cmd, options, keys, &report_type, separator, aligned, buffered, headings))) return_0; /* Ensure options selected are compatible */ if (report_type & SEGS) report_type |= LVS; if (report_type & PVSEGS) report_type |= PVS; if ((report_type & LVS) && (report_type & PVS)) { log_error("Can't report LV and PV fields at the same time"); dm_report_free(report_handle); return 0; } /* Change report type if fields specified makes this necessary */ if (report_type & SEGS) report_type = SEGS; else if (report_type & LVS) report_type = LVS; else if (report_type & PVSEGS) report_type = PVSEGS; else if (report_type & PVS) report_type = PVS; switch (report_type) { case LVS: r = process_each_lv(cmd, argc, argv, LCK_VG_READ, report_handle, &_lvs_single); break; case VGS: r = process_each_vg(cmd, argc, argv, LCK_VG_READ, 0, report_handle, &_vgs_single); break; case PVS: if (args_are_pvs) r = process_each_pv(cmd, argc, argv, NULL, report_handle, &_pvs_single); else r = process_each_vg(cmd, argc, argv, LCK_VG_READ, 0, report_handle, &_pvs_in_vg); break; case SEGS: r = process_each_lv(cmd, argc, argv, LCK_VG_READ, report_handle, &_lvsegs_single); break; case PVSEGS: if (args_are_pvs) r = process_each_pv(cmd, argc, argv, NULL, report_handle, &_pvsegs_single); else r = process_each_vg(cmd, argc, argv, LCK_VG_READ, 0, report_handle, &_pvsegs_in_vg); break; } dm_report_output(report_handle); dm_report_free(report_handle); return r; }
/* * Select a locking type * type: locking type; if < 0, then read config tree value */ int init_locking(int type, struct cmd_context *cmd, int suppress_messages) { if (getenv("LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES")) suppress_messages = 1; if (type < 0) type = find_config_tree_int(cmd, global_locking_type_CFG, NULL); _blocking_supported = find_config_tree_bool(cmd, global_wait_for_locks_CFG, NULL); switch (type) { case 0: init_no_locking(&_locking, cmd, suppress_messages); log_warn("WARNING: Locking disabled. Be careful! " "This could corrupt your metadata."); return 1; case 1: log_very_verbose("%sFile-based locking selected.", _blocking_supported ? "" : "Non-blocking "); if (!init_file_locking(&_locking, cmd, suppress_messages)) { log_error_suppress(suppress_messages, "File-based locking initialisation failed."); break; } return 1; #ifdef HAVE_LIBDL case 2: if (!is_static()) { log_very_verbose("External locking selected."); if (init_external_locking(&_locking, cmd, suppress_messages)) return 1; } if (!find_config_tree_bool(cmd, global_fallback_to_clustered_locking_CFG, NULL)) { log_error_suppress(suppress_messages, "External locking initialisation failed."); break; } #endif #ifdef CLUSTER_LOCKING_INTERNAL log_very_verbose("Falling back to internal clustered locking."); /* Fall through */ case 3: log_very_verbose("Cluster locking selected."); if (!init_cluster_locking(&_locking, cmd, suppress_messages)) { log_error_suppress(suppress_messages, "Internal cluster locking initialisation failed."); break; } return 1; #endif case 4: log_verbose("Read-only locking selected. " "Only read operations permitted."); if (!init_readonly_locking(&_locking, cmd, suppress_messages)) break; return 1; default: log_error("Unknown locking type requested."); return 0; } if ((type == 2 || type == 3) && find_config_tree_bool(cmd, global_fallback_to_local_locking_CFG, NULL)) { log_warn_suppress(suppress_messages, "WARNING: Falling back to local file-based locking."); log_warn_suppress(suppress_messages, "Volume Groups with the clustered attribute will " "be inaccessible."); if (init_file_locking(&_locking, cmd, suppress_messages)) return 1; else log_error_suppress(suppress_messages, "File-based locking initialisation failed."); } if (!ignorelockingfailure()) return 0; log_verbose("Locking disabled - only read operations permitted."); init_readonly_locking(&_locking, cmd, suppress_messages); return 1; }
static int pvcreate_single(struct cmd_context *cmd, const char *pv_name, void *handle) { struct pvcreate_params *pp = (struct pvcreate_params *) handle; void *pv; void *existing_pv; struct id id, *idp = NULL; const char *uuid = NULL; uint64_t size = 0; struct device *dev; struct list mdas; int pvmetadatacopies; uint64_t pvmetadatasize; struct volume_group *vg; const char *restorefile; uint64_t pe_start = 0; uint32_t extent_count = 0, extent_size = 0; if (arg_count(cmd, uuidstr_ARG)) { uuid = arg_str_value(cmd, uuidstr_ARG, ""); if (!id_read_format(&id, uuid)) return EINVALID_CMD_LINE; if ((dev = device_from_pvid(cmd, &id)) && (dev != dev_cache_get(pv_name, cmd->filter))) { log_error("uuid %s already in use on \"%s\"", uuid, dev_name(dev)); return ECMD_FAILED; } idp = &id; } if (arg_count(cmd, restorefile_ARG)) { restorefile = arg_str_value(cmd, restorefile_ARG, ""); /* The uuid won't already exist */ init_partial(1); if (!(vg = backup_read_vg(cmd, NULL, restorefile))) { log_error("Unable to read volume group from %s", restorefile); return ECMD_FAILED; } init_partial(0); if (!(existing_pv = find_pv_in_vg_by_uuid(vg, idp))) { log_error("Can't find uuid %s in backup file %s", uuid, restorefile); return ECMD_FAILED; } pe_start = pv_pe_start(existing_pv); extent_size = pv_pe_size(existing_pv); extent_count = pv_pe_count(existing_pv); } if (!lock_vol(cmd, ORPHAN, LCK_VG_WRITE)) { log_error("Can't get lock for orphan PVs"); return ECMD_FAILED; } if (!pvcreate_check(cmd, pv_name)) goto error; if (sigint_caught()) goto error; if (arg_sign_value(cmd, physicalvolumesize_ARG, 0) == SIGN_MINUS) { log_error("Physical volume size may not be negative"); goto error; } size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0)) * 2; if (arg_sign_value(cmd, metadatasize_ARG, 0) == SIGN_MINUS) { log_error("Metadata size may not be negative"); goto error; } pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG, UINT64_C(0)) * 2; if (!pvmetadatasize) pvmetadatasize = find_config_tree_int(cmd, "metadata/pvmetadatasize", DEFAULT_PVMETADATASIZE); pvmetadatacopies = arg_int_value(cmd, metadatacopies_ARG, -1); if (pvmetadatacopies < 0) pvmetadatacopies = find_config_tree_int(cmd, "metadata/pvmetadatacopies", DEFAULT_PVMETADATACOPIES); if (!(dev = dev_cache_get(pv_name, cmd->filter))) { log_error("%s: Couldn't find device. Check your filters?", pv_name); goto error; } list_init(&mdas); if (!(pv = pv_create(cmd->fmt, dev, idp, size, pe_start, extent_count, extent_size, pvmetadatacopies, pvmetadatasize, &mdas))) { log_error("Failed to setup physical volume \"%s\"", pv_name); goto error; } log_verbose("Set up physical volume for \"%s\" with %" PRIu64 " available sectors", pv_name, pv_size(pv)); /* Wipe existing label first */ if (!label_remove(pv_dev(pv))) { log_error("Failed to wipe existing label on %s", pv_name); goto error; } if (pp->zero) { log_verbose("Zeroing start of device %s", pv_name); if (!dev_open_quiet(dev)) { log_error("%s not opened: device not zeroed", pv_name); goto error; } if (!dev_set(dev, UINT64_C(0), (size_t) 2048, 0)) { log_error("%s not wiped: aborting", pv_name); dev_close(dev); goto error; } dev_close(dev); } log_very_verbose("Writing physical volume data to disk \"%s\"", pv_name); if (!(pv_write(cmd, (struct physical_volume *)pv, &mdas, arg_int64_value(cmd, labelsector_ARG, DEFAULT_LABELSECTOR)))) { log_error("Failed to write physical volume \"%s\"", pv_name); goto error; } log_print("Physical volume \"%s\" successfully created", pv_name); unlock_vg(cmd, ORPHAN); return ECMD_PROCESSED; error: unlock_vg(cmd, ORPHAN); return ECMD_FAILED; }