summaryrefslogtreecommitdiff
path: root/tools/vgchange.c
Commit message (Collapse)AuthorAgeFilesLines
* vgchange: allow changing system ID with majority of PVsDavid Teigland2023-03-081-0/+21
| | | | | | when used with --majoritypvs. This allows the fail-over of a VG between systems by changing the VG system ID when a PV is missing.
* cov: drop unneeded headerZdenek Kabelac2023-02-131-1/+0
|
* vgchange autoactivation: skip regex filter containing symlinksDavid Teigland2023-01-311-0/+1
| | | | | | | | | | | | "vgchange -aay --autoactivation event" is called by our udev rule. When the udev rule runs, symlinks for devices may not all be created yet. If the regex filter contains symlinks, it won't work correctly. This command uses devices that already passed through pvscan. Since pvscan applies the regex filter correctly, this command inherits the filtering from pvscan and can skip the regex filter itself. See the previous commit "pvscan: use alternate device names from DEVLINKS to check filter"
* vgchange monitor: don't use udev infoDavid Teigland2022-03-251-0/+11
| | | | | vgchange --monitor y is run during startup when udev is being initialized and is not yet ready to be used.
* vgchange autoactivation: error path cleanupDavid Teigland2021-11-151-16/+20
| | | | | | | If the optimized label scan fails (using online files), then clear the device state prior to falling back to the standard label_scan. This avoids printing output about unexpected state.
* vgchange autoactivation: lock vg early to avoid second label scanDavid Teigland2021-11-101-26/+32
| | | | | | | Copy another optimization from pvscan -aay to vgchange -aay. When using the optimized label scan for only one VG, acquire the VG lock prior to the scan. This allows vg_read to then skip the repeated label scan that normally happens after locking the vg.
* vgchange: move autoactivation setup codeDavid Teigland2021-11-101-57/+102
| | | | into its own function, no functional change.
* vgchange -aay: improve unexpected command variationsDavid Teigland2021-11-081-5/+42
| | | | | | | | | | | | | | | | | | | | | | | | | For completeness and consistency, adjust the behavior for some variations of: vgchange -aay --autoactivation event [vgname] The current standard use is with a VG name arg, and the command is only called when all pvs_online files exist. This is the optimal case, in which only pvs_online devs are read. This remains the same. Clean up behaviors for some other unexpected uses of the command: . With no VG name arg, the command activates any VGs that are complete according to pvs_online. If no pvs_online files exist, it does nothing. . If a VG name is used but no PVs online files exist for the VG, or the PVs online files are incomplete, then consider there could be a problem with the pvs_online files, and fall back to a full label scan prior to attempting the activation.
* vgchange -aay: optimize device list using pvs_online filesDavid Teigland2021-11-051-4/+17
| | | | | | | | | | | | | | | | | | | | | | | Port another optimization from pvscan -aay to vgchange -aay: "pvscan: only add device args to dev cache" This optimization avoids doing a full dev_cache_scan, and instead populates dev-cache with only the devices in the VG being activated. This involves shifting the use of pvs_online files from the hints interface up to the higher level label_scan interface. This specialized label_scan is structured around creating a list of devices from the pvs_online files. Previously, a list of all devices was created first, and then reduced based on the pvs_online files. The initial step of listing all devices was slow when thousands of devices are present on the system. This optimization extends the previous optimization that used pvs_online files to limit the devices that were actually scanned (i.e. reading to identify the device): "vgchange -aay: optimize device scan using pvs_online files"
* vgchange -aay: optimize device scan using pvs_online filesDavid Teigland2021-11-041-2/+54
| | | | | | | | | | | | | | | | | | | Port the old pvscan -aay scanning optimization to vgchange -aay. The optimization uses pvs_online files created by pvscan --cache to derive a list of devices to use when activating a VG. This allows autoactivation of a VG to avoid scanning all devices, and only scan the devices used by the VG itself. The optimization is applied internally using the device hints interface. The new option "--autoactivation event" is given to pvscan and vgchange commands that are called by event activation. This informs the command that it is being used for event activation, so that it can apply checks and optimizations that are specific to event activation. Those include: - skipping the command if lvm.conf event_activation=0 - checking that a VG is complete before activating it - using pvs_online files to limit device scanning
* device_id: update stacked PVs for vgchange uuidDavid Teigland2021-10-041-0/+18
| | | | | If a VG uuid is changed, update the device_id of any PVs stacked on LVs in the changed VG.
* devices file: avoid updating entry dev names in some casesDavid Teigland2021-08-051-0/+3
| | | | | | Avoid thrashing changes to devices file device names by some commands that are run during startup when devnames are still being set up.
* archive: avoid abuse of internal flagZdenek Kabelac2021-06-091-1/+3
| | | | | Since archive is now postponned we use internal variable 'changed' to mark we need to commit new metadata.
* backup: automatically store data on vg_unlockZdenek Kabelac2021-06-091-6/+0
| | | | | | | | | | Previously there have been necessary explicit call of backup (often either forgotten or over-used). With this patch the necessity to store backup is remember at vg_commit and once the VG is unlocked, the committed metadata are automatically store in backup file. This may possibly alter some printed messages from command when the backup is now taken later.
* archiving: take archive automaticallyZdenek Kabelac2021-06-091-8/+0
| | | | | | | | | | | | | Instead of calling explicit archive with command processing logic, move this step towards 1st. vg_write() call, which will automatically store archive of committed metadata. This slightly changes some error path where the error in archiving was detected earlier in the command, while now some on going command 'actions' might have been, but will be simply scratched in case of error (since even new metadata would not have been even written). So general effect should be only some command message ordering.
* Add metadata-based autoactivation property for VG and LVDavid Teigland2021-04-071-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The autoactivation property can be specified in lvcreate or vgcreate for new LVs/VGs, and the property can be changed by lvchange or vgchange for existing LVs/VGs. --setautoactivation y|n enables|disables autoactivation of a VG or LV. Autoactivation is enabled by default, which is consistent with past behavior. The disabled state is stored as a new flag in the VG metadata, and the absence of the flag allows autoactivation. If autoactivation is disabled for the VG, then no LVs in the VG will be autoactivated (the LV autoactivation property will have no effect.) When autoactivation is enabled for the VG, then autoactivation can be controlled on individual LVs. The state of this property can be reported for LVs/VGs using the "-o autoactivation" option in lvs/vgs commands, which will report "enabled", or "" for the disabled state. Previous versions of lvm do not recognize this property. Since autoactivation is enabled by default, the disabled setting will have no effect in older lvm versions. If the VG is modified by older lvm versions, the disabled state will also be dropped from the metadata. The autoactivation property is an alternative to using the lvm.conf auto_activation_volume_list, which is still applied to to VGs/LVs in addition to the new property. If VG or LV autoactivation is disabled either in metadata or in auto_activation_volume_list, it will not be autoactivated. An autoactivation command will silently skip activating an LV when the autoactivation property is disabled. To determine the effective autoactivation behavior for a specific LV, multiple settings would need to be checked: the VG autoactivation property, the LV autoactivation property, the auto_activation_volume_list. The "activation skip" property would also be relevant, since it applies to both normal and auto activation.
* cov: check for deactivation failureZdenek Kabelac2020-05-201-2/+7
|
* vgchange: remove bogus option restrictionDavid Teigland2019-10-211-6/+0
| | | | for -A with -a
* exported vg handlingDavid Teigland2019-06-251-18/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The exported VG checking/enforcement was scattered and inconsistent. This centralizes it and makes it consistent, following the existing approach for foreign and shared VGs/PVs, which are very similar to exported VGs/PVs. The access policy that now applies to foreign/shared/exported VGs/PVs, is that if a foreign/shared/exported VG/PV is named on the command line (i.e. explicitly requested by the user), and the command is not permitted to operate on it because it is foreign/shared/exported, then an access error is reported and the command exits with an error. But, if the command is processing all VGs/PVs, and happens to come across a foreign/shared/exported VG/PV (that is not explicitly named on the command line), then the command silently skips it and does not produce an error. A command using tags or --select handles inaccessible VGs/PVs the same way as a command processing all VGs/PVs, and will not report/return errors if these inaccessible VGs/PVs exist. The new policy fixes the exit codes on a somewhat random set of commands that previously exited with an error if they were looking at all VGs/PVs and an exported VG existed on the system. There should be no change to which commands are allowed/disallowed on exported VGs/PVs. Certain LV commands (lvs/lvdisplay/lvscan) would previously not display LVs from an exported VG (for unknown reasons). This has not changed. The lvm fullreport command would previously report info about an exported VG but not about the LVs in it. This has changed to include all info from the exported VG.
* scanning: open devs rw when rescanning for writeDavid Teigland2019-06-211-1/+3
| | | | | | | When vg_read rescans devices with the intention of writing the VG, the label rescan can open the devs RW so they do not need to be closed and reopened RW in dev_write_bytes.
* vgchange: don't fail monitor command if vg is exportedDavid Teigland2019-06-201-0/+2
| | | | | | | | | When monitoring, skip exported VGs without causing a command failure. The lvm2-monitor service runs 'vgchange --monitor y', so any exported VG on the system would cause the service to fail.
* vgchange: change debug message levelDavid Teigland2019-06-111-2/+2
| | | | A debug message was mistakely left visible.
* locking: unify global lock for flock and lockdDavid Teigland2019-04-291-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* lvmlockd: make lockstart wait for existing startDavid Teigland2019-01-161-1/+4
| | | | | | | | | | | | | | | | | | If there are two independent scripts doing: vgchange --lockstart vg lvchange -ay vg/lv The first vgchange to do the lockstart will wait for the lockstart to complete before returning. The second vgchange to do the lockstart will see that the start is already in progress (from the first) and will do nothing. This means the second does not wait for any lockstart to complete, and moves on to the lvchange which may find the lockspace still starting and fail. To fix this, make the vgchange lockstart command wait for any lockstart's in progress to complete.
* cov: ensure lock_type is not NULLZdenek Kabelac2018-12-211-3/+3
|
* lvmlockd: vgchange locktype with yes optionDavid Teigland2018-11-271-1/+2
| | | | for auto response to yes/no prompt.
* cov: remove unused assignsZdenek Kabelac2018-11-051-1/+1
|
* lvmlockd: deactivate lvmlock LV in vgchangeDavid Teigland2018-11-011-0/+12
| | | | | | When changing a VG to lock_type sanlock, the internal lvmlock LV was left active at the end of vgchange. It shouldn't be active until lockstart.
* Remove lvmetadDavid Teigland2018-07-111-14/+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.
* vgchange: vdo supportZdenek Kabelac2018-07-091-1/+6
| | | | | | | Support vgchange usage with VDO segtype. Also changing extent size need small update for vdo virtual extent. TODO: API needs enhancements so it's not about adding ifs() everywhere.
* vgchange: start polling with activationZdenek Kabelac2018-06-141-14/+9
| | | | | | | | | | | | | | Shuffle code for better readability as set of conditions was hard to follow. Make it obvious the refresh & activate path is handling monitoring and polling on its own. So the only --monitor and --poll option needs explicit care. Option --monitor without option --poll will now as a result of this patch NOT start polling. So command: vgchange --monitor n is no longer a polling starter.
* pvscan: move start of polling into vgchangeZdenek Kabelac2018-06-141-6/+19
| | | | | | | | | Restoring polling for activated volumes lost with my recent commit: 75fed05d3ef648583764ff56cc577e0f3eba1bba and move start of polling directly into _activate_lvs_in_vg() - as there we know exactly if there was some volume even activated. Also make it sharing same code for pvscan -aay.
* vgchange: trace faling activationZdenek Kabelac2018-06-141-2/+5
| | | | Trace failed activation and directly assign 0 returning failure.
* vgchange: move active assingZdenek Kabelac2018-06-141-2/+3
| | | | Make eval of activate_ARG reusable.
* vgchange: fix error code in error pathZdenek Kabelac2018-06-141-1/+1
| | | | | This rather hard to hit error path used wrong return value to signal real error.
* lvmlockd: update method for changing clustered VGDavid Teigland2018-06-131-0/+1
| | | | | | | | The previous method for forcibly changing a clustered VG to a local VG involved using -cn and locking_type 0. Since those options are deprecated, replace it with the same command used for other forced lock type changes: vgchange --locktype none --lockopt force.
* vgchange: start polling with optionZdenek Kabelac2018-06-111-0/+1
| | | | | Polling start either with '--refresh' or with '--poll' option specified.
* use exclusive file lock on VG for activationDavid Teigland2018-06-071-1/+1
| | | | | | | | | Make activation commands: vgchange -ay, lvchange -ay, pvscan -aay take an exclusive file lock on the VG to serialize multiple concurrent activation commands which could otherwise interfere with each other.
* Remove unused clvm variations for active LVsDavid Teigland2018-06-071-14/+2
| | | | | | | | | | | | | | | | | | Different flavors of activate_lv() and lv_is_active() which are meaningful in a clustered VG can be eliminated and replaced with whatever that flavor already falls back to in a local VG. e.g. lv_is_active_exclusive_locally() is distinct from lv_is_active() in a clustered VG, but in a local VG they are equivalent. So, all instances of the variant are replaced with the basic local equivalent. For local VGs, the same behavior remains as before. For shared VGs, lvmlockd was written with the explicit requirement of local behavior from these functions (lvmlockd requires locking_type 1), so the behavior in shared VGs also remains the same.
* Remove clvmd and associated codeDavid Teigland2018-06-051-139/+0
| | | | More code reduction and simplification can follow.
* lvmlockd: primarily use vg_is_sharedDavid Teigland2018-06-011-1/+1
| | | | | to check if a vg uses an lvmlockd lock_type, instead of the equivalent but longer is_lockd_type.
* Remove lvm1 and pool disk formatsDavid Teigland2018-04-301-10/+0
| | | | | | | | | | | There are likely more bits of code that can be removed, e.g. lvm1/pool-specific bits of code that were identified using FMT flags. The vgconvert command can likely be reduced further. The lvm1-specific config settings should probably have some other fields set for proper deprecation.
* vgchange: invalidate bcache for stacked LVs when deactivatingDavid Teigland2018-04-201-6/+11
| | | | | An LV with a stacked PV will be open in bcache and needs to be invalidated to close the fd before attempting to deactivate.
* coverity: ensure lock_type is not NULLZdenek Kabelac2018-03-171-2/+2
|
* activation: support activation of component LVsZdenek Kabelac2018-03-061-1/+3
| | | | | | | | | | | | | | Occasionaly users may need to peek into 'component devices. Normally lvm2 does not let users activation component. This patch adds special mode where user can activate component LV in a 'read-only' mode i.e.: lvchange -ay vg/pool_tdata All devices can be deactivated with: lvchange -an vg | vgchange -an....
* cleanup: debug messageZdenek Kabelac2017-12-081-3/+3
|
* cleanup: switch to standard queryZdenek Kabelac2017-12-081-8/+1
| | | | | In /tools part we should mostly use standard functions lv_is_active* unless there is good reason to not use it.
* vgchange: drop extra countingZdenek Kabelac2017-12-081-1/+1
| | | | | As the loop for background polling _poll_lvs_in_vg checks for active LVs, avoid doing unnecessary extra check before.
* tidy: Add missing underscores to statics.Alasdair G Kergon2017-10-181-4/+4
|
* replicator: remove the codeDavid Teigland2017-10-131-8/+2
| | | | | It has not been used in a long time and is not expected to be used further.