Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xfsprogs cli #3444

Merged
merged 4 commits into from
Oct 3, 2023
Merged

Xfsprogs cli #3444

merged 4 commits into from
Oct 3, 2023

Conversation

vyaghras
Copy link
Contributor

@vyaghras vyaghras commented Sep 12, 2023

Issue number:

Completes parts of # 3272

Description of changes:
Rewrite xfs_info, xfs_admin and fsck.xfs cli for bottlerocket as Bottlerocket does not have a shell.

  • xfs_info cli: This works for both mounted and unmounted target. It fetches data using
    xfs_spaceman when the target is mounted and use xfs_db in case of
    unmounted target.
    Param "-t" for mtab is not included in this cli as
    xfs_spaceman -p xfs_info -c "info" -t "$mtab" "${target}"
    do not produce expected output. The cli can be used as:
    • xfs_info -V
    • xfs_info $target where target is mount_point or block_device
  • xfs_admin cli : All the commands for xfs progs that are listed on
    https://man7.org/linux/man-pages/man8/xfs_admin.8.html
    can be executed using this CLI.
  • fsck.xfs: We are keeping it open for interactive sesssion too, though it is
    recommended to invoke xfs_repair for Normal administrative filesystem
    repairs directly.

Testing done:

  • xfs_admin
  • xfs_admin -u $device - For unmounted device
sudo xfs_admin -u /dev/nvme3n1p1
UUID = 405fabf4-0e29-40e9-a291-61400aac4fbb
______________________________________________
cargo run --bin xfs_admin --  -u /dev/nvme3n1p1
UUID = 405fabf4-0e29-40e9-a291-61400aac4fbb
  • xfs_admin -l /dev/nvme3n1p1 - For unmounted device
sudo xfs_admin -l /dev/nvme3n1p1
label = ""
______________________________________________
cargo run --bin xfs_admin --  -l /dev/nvme3n1p1
label = ""
  • xfs_admin -u $device - For mounted device
xfs_admin -u /dev/nvme1n1p1
UUID = 03837d91-7a4a-4d9e-ab0c-176502893af4
  • xfs_admin -l /dev/nvme3n1p1 - For mounted device
xfs_admin -l /dev/nvme1n1p1
label = " "
  • xfs_admin -V
sudo xfs_admin -V
xfs_admin version 5.0.0
_____________________________________________
 cargo run --bin xfs_admin --  -V
xfs_admin version 5.0.0
  • xfs_admin -- -e $device
sudo xfs_admin -e /dev/nvme3n1p1
unwritten extents always enabled for v5 superblocks.
versionnum [0xbca5+0x18a] = V5,NLINK,DIRV2,ALIGN,LOGV2,EXTFLG,SECTOR,MOREBITS,ATTR2,LAZYSBCOUNT,PROJID32BIT,CRC,FTYPE,FINOBT,SPARSE_INODES,REFLINK
______________________________________________
cargo run --bin xfs_admin --  -e /dev/nvme3n1p1
unwritten extents always enabled for v5 superblocks.
versionnum [0xbca5+0x18a] = V5,NLINK,DIRV2,ALIGN,LOGV2,EXTFLG,SECTOR,MOREBITS,ATTR2,LAZYSBCOUNT,PROJID32BIT,CRC,FTYPE,FINOBT,SPARSE_INODES,REFLINK
  • xfs_admin -L new_label $device
sudo xfs_admin -L new_label /dev/nvme3n1p1
writing all SBs
new label = "new_label"
sudo xfs_admin -L -- /dev/nvme3n1p1
writing all SBs
new label = ""
_____________________________________________
cargo run --bin xfs_admin --  -L new_label /dev/nvme3n1p1
writing all SBs
new label = "new_label"
 cargo run --bin xfs_admin --  -L -- /dev/nvme3n1p1
writing all SBs
new label = ""

Mounted device
xfs_admin -L new_label /dev/nvme1n1p1
label = "new_label"
xfs_admin -L -- /dev/nvme1n1p1
label = " "
  • xfs_admin -c 1 -O inobtcount=1 $device
  • xfs_admin -f $device
  • xfs_admin -j $device
sudo xfs_admin -j /dev/nvme3n1p1
Version 2 logs always enabled for v5 superblocks.
versionnum [0xbca5+0x18a] = V5,NLINK,DIRV2,ALIGN,LOGV2,EXTFLG,SECTOR,MOREBITS,ATTR2,LAZYSBCOUNT,PROJID32BIT,CRC,FTYPE,FINOBT,SPARSE_INODES,REFLINK
________________________________________________
cargo run --bin xfs_admin --  -j /dev/nvme3n1p1
Version 2 logs always enabled for v5 superblocks.
versionnum [0xbca5+0x18a] = V5,NLINK,DIRV2,ALIGN,LOGV2,EXTFLG,SECTOR,MOREBITS,ATTR2,LAZYSBCOUNT,PROJID32BIT,CRC,FTYPE,FINOBT,SPARSE_INODES,REFLINK
  • xfs_admin -p $device
// Unmounted filesystem
sudo xfs_admin -p /dev/nvme3n1p1
xfs_admin: Cannot change projid32bit on v5 superblocks.
_________________________________________________
cargo run --bin xfs_admin --  -p /dev/nvme3n1p1
xfs_admin: Cannot change projid32bit on v5 superblocks

// Mounted filesystem
// Error message and error code is different because of xfs_progs version
sudo xfs_admin -p /dev/nvme0n1p1
xfs_admin: /dev/nvme0n1p1 contains a mounted filesystem
echo $?
1
__________________________________________________
cargo run --bin xfs_admin --  -p /dev/nvme0n1p1
filesystem is mounted /
echo $?
2
  • xfs_admin -U c1b9d5a2-f162-11cf-9ece-0020afc76f16 $device
xfs_admin -U c1b9d5a2-f162-11cf-9ece-0020afc76f16 /dev/nvme3n1p1
Clearing log and setting UUID
writing all SBs
new UUID = c1b9d5a2-f162-11cf-9ece-0020afc76f16
sudo xfs_admin -U 405fabf4-0e29-40e9-a291-61400aac4fbb /dev/nvme3n1p1
Clearing log and setting UUID
writing all SBs
new UUID = 405fabf4-0e29-40e9-a291-61400aac4fbb
__________________________________________________
cargo run --bin xfs_admin --  -U c1b9d5a2-f162-11cf-9ece-0020afc76f16 /dev/nvme3n1p1
Clearing log and setting UUID
writing all SBs
new UUID = c1b9d5a2-f162-11cf-9ece-0020afc76f16
cargo run --bin xfs_admin --  -U 405fabf4-0e29-40e9-a291-61400aac4fbb /dev/nvme3n1p1
Clearing log and setting UUID
writing all SBs
new UUID = 405fabf4-0e29-40e9-a291-61400aac4fbb
  • Fail when device is not provided
sudo xfs_admin -u
Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-U uuid] device
echo $?
2
__________________________________________________
cargo run --bin xfs_admin --  -u
Couldn't parse target block-device
echo $?
2
  • xfs_info
  • xfs_info -V
sudo xfs_info  -V
xfs_info version 5.0.0
 echo $?
0
__________________________________________________
cargo run --bin xfs_info --  -V
xfs_info version 5.0.0
echo $?
0
  • Fail when device is not provided
sudo xfs_info 
Usage: xfs_info [-V] [-t mtab] [mountpoint|device|file]
echo $?
2
__________________________________________________
cargo run --bin xfs_info --
Couldn't parse target  mount-point | block-device | file-image
[ec2-user@ip-172-31-46-161 xfscli]$ echo $?
2
  • xfs_info $device
// Unmounted device
sudo xfs_info /dev/nvme3n1p1
meta-data=/dev/nvme3n1p1         isize=512    agcount=4, agsize=6553536 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=26214144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=12799, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
________________________________________________________
cargo run --bin xfs_info --  /dev/nvme3n1p1
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `/home/ec2-user/bottlerocket/sources/target/debug/xfs_info /dev/nvme3n1p1`
meta-data=/dev/nvme3n1p1         isize=512    agcount=4, agsize=6553536 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=26214144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=12799, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

// Mounted device
findmnt /dev/nvme4n1p1
TARGET   SOURCE         FSTYPE
/volume2 /dev/nvme4n1p1 xfs 

xfs_info /dev/nvme4n1p1
meta-data=/dev/nvme4n1p1         isize=512    agcount=4, agsize=6553536 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=26214144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=12799, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
_______________________________________________________
cargo run --bin xfs_info --  /dev/nvme4n1p1
meta-data=/dev/nvme4n1p1         isize=512    agcount=4, agsize=6553536 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=26214144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=12799, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
  • fsck.xfs
  • fsck.xfs -a /dev/nvme3n1p1 -- Do nothing, successfully
sudo fsck.xfs  -a /dev/nvme3n1p1
/sbin/fsck.xfs: XFS file system.
echo $?
0
_________________________________________________
cargo run --bin fsck_xfs --  -a /dev/nvme3n1p1
xfs fsck : XFS file system.
echo $?
0

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

@vyaghras vyaghras marked this pull request as draft September 12, 2023 06:28
@vyaghras vyaghras force-pushed the xfsprogs-cli branch 5 times, most recently from f453313 to 516e668 Compare September 12, 2023 16:20
@vyaghras vyaghras marked this pull request as ready for review September 12, 2023 17:18
packages/os/os.spec Outdated Show resolved Hide resolved
packages/os/os.spec Show resolved Hide resolved
sources/xfscli/Cargo.toml Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_info.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_info.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_fsck.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_fsck.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_fsck.rs Outdated Show resolved Hide resolved
@vyaghras vyaghras force-pushed the xfsprogs-cli branch 3 times, most recently from 6d9dadd to b05a227 Compare September 15, 2023 00:06
sources/xfscli/src/bin/fsck_xfs.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/fsck_xfs.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/fsck_xfs.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/fsck_xfs.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/fsck_xfs.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/lib.rs Outdated Show resolved Hide resolved
sources/xfscli/src/lib.rs Show resolved Hide resolved
@vyaghras vyaghras force-pushed the xfsprogs-cli branch 7 times, most recently from 01930db to 9e68835 Compare September 20, 2023 23:25
sources/xfscli/src/error.rs Outdated Show resolved Hide resolved
sources/xfscli/src/error.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/fsck_xfs.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/fsck_xfs.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/lib.rs Outdated Show resolved Hide resolved
sources/xfscli/src/lib.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
sources/xfscli/Cargo.toml Outdated Show resolved Hide resolved
sources/xfscli/src/bin/fsck_xfs.rs Outdated Show resolved Hide resolved
sources/xfscli/src/bin/xfs_admin.rs Outdated Show resolved Hide resolved
@vyaghras
Copy link
Contributor Author

Update in ⬆️ push:

  1. Changing all the expect errors in to errors using snafu.
  2. Moving all the fsck related errors in a separate file.(To keep it clean as that command has specific error return codes).
  3. Change error codes for all the general errors like Command unsuccessful, Unable to read data to 8( Operational error).

sources/xfscli/src/bin/fsck_xfs.rs Outdated Show resolved Hide resolved
sources/xfscli/src/fsckerror.rs Outdated Show resolved Hide resolved
Build and install xfs_info, xfs_admin and fsck.xfs cli to os spec.
Also add Cargo.toml for xfscli package.

pick 412d8bad packages: update cni-plugins to 1.3.0
@vyaghras vyaghras force-pushed the xfsprogs-cli branch 2 times, most recently from 8604ecd to e0a0bf2 Compare September 28, 2023 18:16
@vyaghras
Copy link
Contributor Author

Update in ⬆️ push:
Moved fsck cli(main.rs) and error file in a module fsck_xfs.

Copy link
Contributor

@cbgbt cbgbt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! 🚀

})
}

// Query xfs spaceman to get xfs information
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'm sorry to have missed this in a previous pass, but these should be docstring comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed these comments to Docstring comments

All the commands for xfs progs that are listed on
https://man7.org/linux/man-pages/man8/xfs_admin.8.html
can be executed using this CLI.

This CLI executes xfs_repair when -O arg and -c arg options
are provided.

It executes xfs_io to get the queried information for the mounted
filesystem and xfs_db for unmounted filesystem.
The cli can be used as:
- xfs_info -V
- xfs_info $target where target is mount_point or block_device

This works for both mounted and unmounted target. It fetches data using
xfs_spaceman when the target is mounted and use xfs_db in case of
unmounted target.

Param "-t" for mtab is not included in this cli as
xfs_spaceman -p xfs_info -c "info" -t "$mtab" "${target}"
do not produce expected output.
This cli has been rewritten in Rust as bottlerocket does not have
shell.
This CLI is intented to get called uninteractively:
1. By Kubernetes
2. By systemd-fsck-root.service - This is disabled by default in
   bottlerocket.

In case of Kubernetes, this binary will be used to repair the filesystem
when it exists.
We are keeping it open for interactive sesssion too, though it is
recommended to invoke xfs_repair for Normal administrative filesystem
repairs directly.
@vyaghras
Copy link
Contributor Author

Update in ⬆️ push:
Changed all comments in lib.rs to Docstring comments

Copy link
Contributor

@yeazelm yeazelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚢

@vyaghras vyaghras merged commit e61a30a into bottlerocket-os:develop Oct 3, 2023
48 checks passed
@vyaghras vyaghras deleted the xfsprogs-cli branch October 3, 2023 14:23
@stmcginnis stmcginnis mentioned this pull request Oct 23, 2023
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants