saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.22k stars 5.48k forks source link

[FEATURE REQUEST] salt.states.lvm.lv_present: support thin snapshots #60691

Open dseomn opened 3 years ago

dseomn commented 3 years ago

Describe the solution you'd like It would be nice if lvm.lv_present could create thin snapshots of thin volumes, and manage their size.

Describe alternatives you've considered It's probably possible to do at least some of that with cmd.run.

Additional context https://man7.org/linux/man-pages/man8/lvcreate.8.html says "the size option must not be used, otherwise a copy-on-write snapshot would be created" but from looking at https://github.com/saltstack/salt/blob/b54becb8b43cc9b7c00b2c0bc637ac534dc62896/salt/states/lvm.py#L313-L324 and https://github.com/saltstack/salt/blob/b54becb8b43cc9b7c00b2c0bc637ac534dc62896/salt/modules/linux_lvm.py#L515-L524 it seems there's no way to omit the size.

It looks like specifying both size and thinvolume to use the -V flag also wouldn't work:

root@k8sc0n0:~# lvdisplay /dev/k8sc0n0-vg/base_system 
  --- Logical volume ---
  LV Path                /dev/k8sc0n0-vg/base_system
  LV Name                base_system
  VG Name                k8sc0n0-vg
  LV UUID                ExqbJE-0Cfs-C2dO-UAKG-XAy7-7LyF-pIqeBC
  LV Write Access        read/write
  LV Creation host, time k8sc0n0, 2021-08-08 21:18:34 +0000
  LV Pool name           thin_pool
  LV Status              available
  # open                 0
  LV Size                2.00 GiB
  Mapped size            100.00%
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:11

root@k8sc0n0:~# lvcreate  -V 8G --name foo_system --snapshot k8sc0n0-vg/base_system
  Command does not accept option: --snapshot.

So I think supporting this would mean creating the snapshot and then separately resizing the snapshot if needed.

dseomn commented 3 years ago

I figured out a way to do this with cmd.run that seems to work: https://github.com/dseomn/system-configs/blob/2f52b2e32fc3c9b8ec24e55f51578618fec050ff/salt/file/virtual_machine/host/init.sls#L79-L95