elastio / elastio-snap

kernel module for taking block-level snapshots and incremental backups of Linux block devices
GNU General Public License v2.0
19 stars 7 forks source link

Share all api to elioctl #191

Closed kgermanov closed 1 year ago

kgermanov commented 1 year ago

Share all IOCTL API on elioctl

e-kov commented 1 year ago

I'm not sure what is the purpose of this change, especially about info IOCTL. Because new added command elioctl info X duplicates output of the cat /proc/elastio-snap-info. And you could just read this file from elioctl and parse a part by minor, probably )

Anyway, there are few minor remarks:

  1. The new commands are missing in the bash completion file https://github.com/elastio/elastio-snap/blob/cc5dd438e996adf0491d21c123480ccd0a33a0be/app/bash_completion.d/elioctl#L7
  2. get-free-minor w/o sudo returns wrong error: error interpreting get_free_minor parameters: Numerical result out of range instead of driver returned an error performing specified action. check dmesg for more info: Permission denied.

All other looks fine. Thanks for fixing manual!)

kgermanov commented 1 year ago

@e-kov, About info - yes, we can parse /proc/elastio-snap-info, But problems in that we need parse json. With this subcommand we can simple do such:

root@user-vm:/# elioctl info 1 | grep "fallocate" | cut -d ':' -f 2 |  grep -oP '(\w*)'
7462295961

Main goal in that elioctl share all available API. As result client does not need write code to link with library.

e-kov commented 1 year ago

@e-kov, About info - yes, we can parse /proc/elastio-snap-info, But problems in that we need parse json. With this subcommand we can simple do such:

root@user-vm:/# elioctl info 1 | grep "fallocate" | cut -d ':' -f 2 |  grep -oP '(\w*)'
7462295961

Main goal in that elioctl share all available API. As result client does not need write code to link with library.

@kgermanov I don't mind to add this subcommand. But it also returns the same json, but for the single device )

Let's say we have 2 snapshot devices:

elastio@debian11-amd64-build:~/elastio-snap$ cat /proc/elastio-snap-info
{
    "version": "0.11.0",
    "devices": [
        {
            "minor": 0,
            "cow_file": "/cow",
            "block_device": "/dev/vda1",
            "max_cache": 314572800,
            "fallocate": 21372076032,
            "seq_id": 1,
            "uuid": "bcb141aed7ca4794bc14db0025a23861",
            "version": 1,
            "nr_changed_blocks": 108,
            "state": 3
        },
        {
            "minor": 1,
            "cow_file": "/cow",
            "block_device": "/dev/loop0",
            "max_cache": 314572800,
            "fallocate": 26214400,
            "seq_id": 1,
            "uuid": "a7382d3c41414fbbb23952e09fcea0bc",
            "version": 1,
            "nr_changed_blocks": 68,
            "state": 3
        }
    ]
}

And we need to know fallocate of the device with the minor 1, We can use jq for this purpose:

elastio@debian11-amd64-build:~/elastio-snap$ jq '.devices[] | select(.minor==1) | .fallocate' /proc/elastio-snap-info
26214400

And with the new subcommand we don't need filter devices array from the global part and specify minor as an argument, but not a query:

elastio@debian11-amd64-build:~/elastio-snap$ sudo elioctl info 1 | jq '.fallocate'
26214400
kgermanov commented 1 year ago

@ e-kov, Fixed uint parser.