summaryrefslogtreecommitdiff
path: root/tools/pvcreate.c
Commit message (Collapse)AuthorAgeFilesLines
* exit with error when --devicesfile name doesn't existDavid Teigland2022-07-061-1/+2
|
* device usage based on devices fileDavid Teigland2021-02-231-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The LVM devices file lists devices that lvm can use. The default file is /etc/lvm/devices/system.devices, and the lvmdevices(8) command is used to add or remove device entries. If the file does not exist, or if lvm.conf includes use_devicesfile=0, then lvm will not use a devices file. When the devices file is in use, the regex filter is not used, and the filter settings in lvm.conf or on the command line are ignored. LVM records devices in the devices file using hardware-specific IDs, such as the WWID, and attempts to use subsystem-specific IDs for virtual device types. These device IDs are also written in the VG metadata. When no hardware or virtual ID is available, lvm falls back using the unstable device name as the device ID. When devnames are used, lvm performs extra scanning to find devices if their devname changes, e.g. after reboot. When proper device IDs are used, an lvm command will not look at devices outside the devices file, but when devnames are used as a fallback, lvm will scan devices outside the devices file to locate PVs on renamed devices. A config setting search_for_devnames can be used to control the scanning for renamed devname entries. Related to the devices file, the new command option --devices <devnames> allows a list of devices to be specified for the command to use, overriding the devices file. The listed devices act as a sort of devices file in terms of limiting which devices lvm will see and use. Devices that are not listed will appear to be missing to the lvm command. Multiple devices files can be kept in /etc/lvm/devices, which allows lvm to be used with different sets of devices, e.g. system devices do not need to be exposed to a specific application, and the application can use lvm on its own set of devices that are not exposed to the system. The option --devicesfile <filename> is used to select the devices file to use with the command. Without the option set, the default system devices file is used. Setting --devicesfile "" causes lvm to not use a devices file. An existing, empty devices file means lvm will see no devices. The new command vgimportdevices adds PVs from a VG to the devices file and updates the VG metadata to include the device IDs. vgimportdevices -a will import all VGs into the system devices file. LVM commands run by dmeventd not use a devices file by default, and will look at all devices on the system. A devices file can be created for dmeventd (/etc/lvm/devices/dmeventd.devices) If this file exists, lvm commands run by dmeventd will use it. Internal implementaion: - device_ids_read - read the devices file . add struct dev_use (du) to cmd->use_devices for each devices file entry - dev_cache_scan - get /dev entries . add struct device (dev) to dev_cache for each device on the system - device_ids_match - match devices file entries to /dev entries . match each du on cmd->use_devices to a dev in dev_cache, using device ID . on match, set du->dev, dev->id, dev->flags MATCHED_USE_ID - label_scan - read lvm headers and metadata from devices . filters are applied, those that do not need data from the device . filter-deviceid skips devs without MATCHED_USE_ID, i.e. skips /dev entries that are not listed in the devices file . read lvm label from dev . filters are applied, those that use data from the device . read lvm metadata from dev . add info/vginfo structs for PVs/VGs (info is "lvmcache") - device_ids_find_renamed_devs - handle devices with unstable devname ID where devname changed . this step only needed when devs do not have proper device IDs, and their dev names change, e.g. after reboot sdb becomes sdc. . detect incorrect match because PVID in the devices file entry does not match the PVID found when the device was read above . undo incorrect match between du and dev above . search system devices for new location of PVID . update devices file with new devnames for PVIDs on renamed devices . label_scan the renamed devs - continue with command processing
* move the setting of use_full_md_check flagDavid Teigland2019-05-211-3/+0
| | | | | from each command to one location in command init. No functional change.
* pvcreate: call label scan prior to pvcreate_each_deviceDavid Teigland2019-04-301-2/+3
| | | | | | and don't call it from inside pvcreate_each_device. This avoids having to repeat it for users of pvcreate_each_device (pvcreate/pvremove/vgcreate/vgextend.)
* locking: unify global lock for flock and lockdDavid Teigland2019-04-291-9/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There have been two file locks used to protect lvm "global state": "ORPHANS" and "GLOBAL". Commands that used the ORPHAN flock in exclusive mode: pvcreate, pvremove, vgcreate, vgextend, vgremove, vgcfgrestore Commands that used the ORPHAN flock in shared mode: vgimportclone, pvs, pvscan, pvresize, pvmove, pvdisplay, pvchange, fullreport Commands that used the GLOBAL flock in exclusive mode: pvchange, pvscan, vgimportclone, vgscan Commands that used the GLOBAL flock in shared mode: pvscan --cache, pvs The ORPHAN lock covers the important cases of serializing the use of orphan PVs. It also partially covers the reporting of orphan PVs (although not correctly as explained below.) The GLOBAL lock doesn't seem to have a clear purpose (it may have eroded over time.) Neither lock correctly protects the VG namespace, or orphan PV properties. To simplify and correct these issues, the two separate flocks are combined into the one GLOBAL flock, and this flock is used from the locking sites that are in place for the lvmlockd global lock. The logic behind the lvmlockd (distributed) global lock is that any command that changes "global state" needs to take the global lock in ex mode. Global state in lvm is: the list of VG names, the set of orphan PVs, and any properties of orphan PVs. Reading this global state can use the global lock in sh mode to ensure it doesn't change while being reported. The locking of global state now looks like: lockd_global() previously named lockd_gl(), acquires the distributed global lock through lvmlockd. This is unchanged. It serializes distributed lvm commands that are changing global state. This is a no-op when lvmlockd is not in use. lockf_global() acquires an flock on a local file. It serializes local lvm commands that are changing global state. lock_global() first calls lockf_global() to acquire the local flock for global state, and if this succeeds, it calls lockd_global() to acquire the distributed lock for global state. Replace instances of lockd_gl() with lock_global(), so that the existing sites for lvmlockd global state locking are now also used for local file locking of global state. Remove the previous file locking calls lock_vol(GLOBAL) and lock_vol(ORPHAN). The following commands which change global state are now serialized with the exclusive global flock: pvchange (of orphan), pvresize (of orphan), pvcreate, pvremove, vgcreate, vgextend, vgremove, vgreduce, vgrename, vgcfgrestore, vgimportclone, vgmerge, vgsplit Commands that use a shared flock to read global state (and will be serialized against the prior list) are those that use process_each functions that are based on processing a list of all VG names, or all PVs. The list of all VGs or all PVs is global state and the shared lock prevents those lists from changing while the command is processing them. The ORPHAN lock previously attempted to produce an accurate listing of orphan PVs, but it was only acquired at the end of the command during the fake vg_read of the fake orphan vg. This is not when orphan PVs were determined; they were determined by elimination beforehand by processing all real VGs, and subtracting the PVs in the real VGs from the list of all PVs that had been identified during the initial scan. This is fixed by holding the single global lock in shared mode while processing all VGs to determine the list of orphan PVs.
* add device hints to reduce scanningDavid Teigland2019-01-151-0/+2
| | | | | | | Save the list of PVs in /run/lvm/hints. These hints are used to reduce scanning in a number of commands to only the PVs on the system, or only the PVs in a requested VG (rather than all devices on the system.)
* Remove lvmetadDavid Teigland2018-07-111-11/+0
| | | | | | | | | | | | | Native disk scanning is now both reduced and async/parallel, which makes it comparable in performance (and often faster) when compared to lvm using lvmetad. Autoactivation now uses local temp files to record online PVs, and no longer requires lvmetad. There should be no apparent command-level change in behavior.
* filter: use bcache for filter readsDavid Teigland2018-05-101-0/+3
| | | | | | | | | | | | Filters are still applied before any device reading or the label scan, but any filter checks that want to read the device are skipped and the device is flagged. After bcache is populated, but before lvm looks for devices (i.e. before label scan), the filters are reapplied to the devices that were flagged above. The filters will then find the data they need in bcache.
* tidy: Add missing underscores to statics.Alasdair G Kergon2017-10-181-6/+6
|
* pvcreate: Use maximum metadata area size with --restorefileAlasdair G Kergon2017-08-111-0/+9
| | | | | | If the PV was originally created with a larger-than-default metadata area the restored one wasn't and might not even be large enough to hold the metadata!
* pvcreate: add prompt when setting dev sizeDavid Teigland2017-04-271-2/+2
| | | | | | | | | | If the device size does not match the size requested by --setphysicalvolumesize, then prompt the user. Make the pvcreate checking/prompting code handle multiple prompts for the same device, since the new prompt can be in addition to the existing prompt when the PV is in a VG.
* lvmetad: two phase vg_updateDavid Teigland2016-06-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, a command sent lvmetad new VG metadata in vg_commit(). In vg_commit(), devices are suspended, so any memory allocation done by the command while sending to lvmetad, or by lvmetad while updating its cache could deadlock if memory reclaim was triggered. Now lvmetad is updated in unlock_vg(), after devices are resumed. The new method for updating VG metadata in lvmetad is in two phases: 1. In vg_write(), before devices are suspended, the command sends lvmetad a short message ("set_vg_info") telling it what the new VG seqno will be. lvmetad sees that the seqno is newer than the seqno of its cached VG, so it sets the INVALID flag for the cached VG. If sending the message to lvmetad fails, the command fails before the metadata is committed and the change is not made. If sending the message succeeds, vg_commit() is called. 2. In unlock_vg(), after devices are resumed, the command sends lvmetad the standard vg_update message with the new metadata. lvmetad sees that the seqno in the new metadata matches the seqno it saved from set_vg_info, and knows it has the latest copy, so it clears the INVALID flag for the cached VG. If a command fails between 1 and 2 (after committing the VG on disk, but before sending lvmetad the new metadata), the cached VG retains the INVALID flag in lvmetad. A subsequent command will read the cached VG from lvmetad, see the INVALID flag, ignore the cached copy, read the VG from disk instead, update the lvmetad copy with the latest copy from disk, (this clears the INVALID flag in lvmetad), and use the correct VG metadata for the command. (This INVALID mechanism already existed for use by lvmlockd.)
* tools: Use arg_is_set instead of arg_count.Alasdair G Kergon2016-06-211-6/+6
|
* toollib: add 'parent' field to processing_handle; init report format only if ↵Peter Rajnoha2016-06-201-1/+1
| | | | | | | | | | | | | there's no parent If there's parent processing handle, we don't need to create completely new report group and status report - we'll just reuse the one already initialized for the parent. Currently, the situation where this matter is when doing internal report to do the selection for processing commands where we have parent processing handle for the command itself and processing handle for the selection part (that is selection for non-reporting tools).
* pvcreate: fix setting uuid argDavid Teigland2016-02-251-0/+1
| | | | | Commit 4de6caf5 ("redefine pvcreate structs") left out setting the "idp" pointer to the "id" arg.
* replace pvcreate_params with pvcreate_each_paramsDavid Teigland2016-02-251-10/+10
| | | | | | | | | | "pvcreate_each_params" was a temporary name used to transition from the old "pvcreate_params". Remove the old pvcreate_params struct and rename the new pvcreate_each_params struct to pvcreate_params. Rename various pvcreate_each_params terms to simply pvcreate_params.
* redefine pvcreate structsDavid Teigland2016-02-251-8/+8
| | | | | | New pv_create_args struct contains all the specific parameters for creating a PV, independent of the command.
* pvcreate: use the common toollib pv createDavid Teigland2016-02-251-51/+92
|
* doc: change fsf addressZdenek Kabelac2016-01-211-1/+1
| | | | | Hmm rpmlint suggest fsf is using a different address these days, so lets keep it up-to-date
* Add lvmlockddev-dct-lvmlockd-AZDavid Teigland2015-07-021-0/+4
|
* vgextend: Use process_each_vg.David Teigland2015-02-131-1/+1
| | | | | Tags and --select are not yet supported because new code is needed to ensure exactly one VG matches before the VG starts to be processed.
* pvcreate: Fix cache state with filters/sig wiping.Alasdair G Kergon2014-08-141-9/+0
| | | | | | | | | | | | | | | | | | | | | _pvcreate_check() has two missing requirements: After refreshing filters there must be a rescan. (Otherwise the persistent filter may remain empty.) After wiping a signature, the filters must be refreshed. (A device that was previously excluded by the filter due to its signature might now need to be included.) If several devices are added at once, the repeated scanning isn't strictly needed, but we can address that later as part of the command processing restructuring (by grouping the devices). Replace the new pvcreate code added by commit 54685c20fc9dfb155a2e5bc9d8cf5f0aad944305 "filters: fix regression caused by commit e80884cd080cad7e10be4588e3493b9000649426" with this change to _pvcreate_check(). The filter refresh problem dates back to commit acb4b5e4de3c49d36fe756f6fb9997ec179b89c2 "Fix pvcreate device check."
* filters: fix regression caused by commit ↵Peter Rajnoha2014-08-011-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | e80884cd080cad7e10be4588e3493b9000649426 Commit e80884cd080cad7e10be4588e3493b9000649426 tried to dump filters for them to be reevaluated when creating a PV to avoid overwriting any existing signature that may have been created after last scan/filtering. However, we need to call refresh_filters instead of persistent_filter->dump since dump requires proper rescannig to fill up the persistent filter again. However, this is true only for pvcreate but not for vgcreate with PV creation where the scanning happens before this PV creation and hence the next rescan (if not full scan), does not fill the persistent filter. Also, move refresh_filters so that it's called sooner and only for pvcreate, vgcreate already calls lvmcache_label_scan(cmd, 2) which then calls refresh_filters itself, so no need to reevaluate this again. This caused the persistent filter (/etc/lvm/cache/.cache file) to be wrong and contain only the PV just being processed with vgcreate <vg_name> <pv_name_to_create>. This regression caused other block devices to be filtered out in case the vgcreate with PV creation was used and then the persistent filter is used by any other LVM command afterwards.
* tools: remove metadata-exported.hAlasdair G Kergon2013-07-091-1/+0
| | | | metadata-exported.h is included by tools.h
* pvcreate: remove metadata.h headerAlasdair G Kergon2013-07-091-2/+1
| | | | | Files in tools/ should only use metadata-exported.h not metadata.h. Rename pvcreate_locked to pvcreate_single.
* lvresize: separate validation from actionAlasdair G Kergon2013-07-061-2/+1
| | | | | | | | | Start separating the validation from the action in the basic lvresize code moved to the library. Remove incorrect use of command line error codes from lvresize library functions. Move errors.h to tools directory to reinforce this, exporting public versions of the error codes in lvm2cmd.h for dmeventd plugins to use.
* sigint: improve logic on for sigint reactionZdenek Kabelac2013-07-031-3/+3
| | | | | | | | | | | | Fix and improve handling on sigint. Always check for signal presence *before* calling of command, so it will not call the command when break was hit. If the command has been finished succesfully there is no problem to mark the command ok and not report interrupt at all. Fix cuple related stack; reports and assignments.
* lib2app: Added PV create. V2Tony Asleson2013-07-021-9/+2
| | | | | | V2: Correct call to lock_vol Signed-off-by: Tony Asleson <tasleson@redhat.com>
* config: add profile arg to find_config_tree_boolPeter Rajnoha2013-07-021-1/+1
|
* locking: Make it possible to pass down an LV to activation code.Petr Rockai2013-06-101-1/+1
| | | | | | | Previously, we have relied on UUIDs alone, and on lvmcache to make getting a "new copy" of VG metadata fast. If the code which triggers the activation has the correct VG metadata at hand (the version which is currently on disk), it can now hand it to the activation code directly.
* refactor: rename embedding area -> bootloader areaPeter Rajnoha2013-05-281-2/+2
|
* config: refer to config nodes using assigned IDsPeter Rajnoha2013-03-061-3/+1
| | | | | | | | | | | | | | | For example, the old call and reference: find_config_tree_str(cmd, "devices/dir", DEFAULT_DEV_DIR) ...now becomes: find_config_tree_str(cmd, devices_dir_CFG) So we're referring to the named configuration ID instead of passing the configuration path and the default value is taken from central config definition in config_settings.h automatically.
* pv_header_extension: add support for writing PV header extension (flags & ↵Peter Rajnoha2013-02-261-0/+2
| | | | | | | | | | | | | | | | | | | Embedding Area) The PV header extension information (PV header extension version, flags and list of Embedding Area locations) is stored just beyond the PV header base. When calculating the Embedding Area start value (ea_start), the same logic is used as when calculating the pe_start value for Data Area - the value must follow exactly the same alignment restrictions for its start value (the alignment detected automatically or provided via command line using the --dataalignment and --dataalignmentoffset arguments). The Embedding Area is placed at the very start of the PV, starting at ea_start. The Data Area starting at pe_start is placed next. The pe_start is still properly aligned. Due to the pe_start alignment, it's possible that the resulting Embedding Area size (ea_size) ends up bigger in size than requested (but never less than requested).
* pv_header_extension: add support for reading PV header extension (flags & ↵Peter Rajnoha2013-02-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Embedding Area) New tools with PV header extension support will read the extension if it exists and it's not an error if it does not exist (so old PVs will still work seamlessly with new tools). Old tools without PV header extension support will just ignore any extension. As for the Embedding Area location information (its start and size), there are actually two places where this is stored: - PV header extension - VG metadata The VG metadata contains a copy of what's written in the PV header extension about the Embedding Area location (NULL value is not copied): physical_volumes { pv0 { id = "AkSSRf-difg-fCCZ-NjAN-qP49-1zzg-S0Fd4T" device = "/dev/sda" # Hint only status = ["ALLOCATABLE"] flags = [] dev_size = 262144 # 128 Megabytes pe_start = 67584 pe_count = 23 # 92 Megabytes ea_start = 2048 ea_size = 65536 # 32 Megabytes } } The new metadata fields are "ea_start" and "ea_size". This is mostly useful when restoring the PV by using existing metadata backups (e.g. pvcreate --restorefile ...). New tools does not require these two fields to exist in VG metadata, they're not compulsory. Therefore, reading old VG metadata which doesn't contain any Embedding Area information will not end up with any kind of error but only a debug message that the ea_start and ea_size values were not found. Old tools just ignore these extra fields in VG metadata.
* cleanup: add struct pvcreate_restorable_params and move relevant items from ↵Peter Rajnoha2013-02-261-10/+10
| | | | | | | | pvcreate_params Extract restorable PV creation parameters from struct pvcreate_params into a separate struct pvcreate_restorable_params for clarity and also for better maintainability when adding any new items later.
* pvcreate: fix leak on error pathZdenek Kabelac2012-10-191-0/+1
| | | | | Missing vg release on error path. Add tests for few more error cases.
* Using enum types for enumsZdenek Kabelac2012-02-281-1/+1
| | | | alloc_policy_t, dm_string_mangling_t, percent_range_t, sign_t
* The lvmetad client-side integration. Only active when use_lvmetad = 1 is set inPetr Rockai2012-02-231-0/+1
| | | | lvm.conf *and* lvmetad is running.
* Add free_orphan_vgZdenek Kabelac2012-02-131-1/+0
| | | | | | | Move commod code to destroy orphan VG into free_orphan_vg() function. Use orphan vgmem for creation of PV lists. Remove some free_pv_fid() calls (FIXME: check all of them) FIXME: Check whether we could merge release_vg back again for all VGs.
* Move the core of the lib/config/config.c functionality into libdevmapper,Petr Rockai2011-08-301-1/+1
| | | | | | | leaving behind the LVM-specific parts of the code (convenience wrappers that handle `struct device` and `struct cmd_context`, basically). A number of functions have been renamed (in addition to getting a dm_ prefix) -- namely, all of the config interface now has a dm_config_ prefix.
* Replace free_vg with release_vgZdenek Kabelac2011-08-101-1/+1
| | | | | | | | Move the free_vg() to vg.c and replace free_vg with release_vg and make the _free_vg internal. Patch is needed for sharing VG in vginfo cache so the release_vg function name is a better fit here.
* Defer writing PV labels to vg_write.Alasdair Kergon2011-06-011-1/+1
| | | | Store label_sector only in struct physical_volume.
* Add new free_pv_fid fn and use it throughout to free all attached fids.Peter Rajnoha2011-03-111-1/+3
| | | | | | | | Since format instances will use own memory pool, it's necessary to properly deallocate it. For now, only fid is deallocated. The PV structure itself still uses cmd mempool mostly, but anytime we'd like to add a mempool in the struct physical_volume, we can just rename this fn to free_pv and add the code (like we have free_vg fn for VGs).
* Rename vg_release to free_vg.Alasdair Kergon2010-12-081-1/+1
|
* Add escape sequence for ':' and '@' found in device names used as PVs.Peter Rajnoha2010-09-231-0/+2
|
* Require --restorefile when using pvcreate --uuid.Mike Snitzer2010-08-121-0/+10
| | | | | | | | | Introduce --norestorefile to allow user to override the new requirement. This can also be overridden with "devices/require_restorefile_with_uuid" in lvm.conf -- however the default is 1. Signed-off-by: Mike Snitzer <snitzer@redhat.com>
* replace existing_pv with existing_pvlAlasdair Kergon2010-03-161-5/+5
|
* Look up missing PVs by uuid not dev_name in _pvs_single to avoid invalid stat.Alasdair Kergon2010-03-161-1/+1
| | | | Make find_pv_in_vg_by_uuid() return same type as related functions.
* Rename pvcreate_params processing functions to better match <object><action>.Dave Wysochanski2009-11-011-4/+4
| | | | | | Rename fill_default_pvcreate_params to pvcreate_params_set_defaults. Rename pvcreate_validate_restore_params to pvcreate_restore_params_validate. Rename pvcreate_validate_params to pvcreate_params_validate.
* Move pvcreate_validate_params into toollib to allow calling from mutiple tools.Dave Wysochanski2009-10-051-108/+0
| | | | | For implicit pvcreate support, we need to call this from vgcreate and vgextend, so move it into toollib.