// Copyright (c) Vitaliy Filippov, 2019+ // License: VNPL-1.1 (see README.md for details) /** * CLI tool and also a library for administrative tasks */ #include #include #include "cli.h" #include "epoll_manager.h" #include "cluster_client.h" #include "pg_states.h" #include "str_util.h" static const char *exe_name = NULL; static const char* help_text = "Vitastor command-line tool " VITASTOR_VERSION "\n" "(c) Vitaliy Filippov, 2019+ (VNPL-1.1)\n" "\n" "COMMANDS:\n" "\n" "vitastor-cli status\n" " Show cluster status\n" "\n" "vitastor-cli df\n" " Show pool space statistics\n" "\n" "vitastor-cli ls [-l] [-p POOL] [--sort FIELD] [-r] [-n N] [ ...]\n" " List images (only matching patterns if passed).\n" " --exact Do not match glob patterns as names, select only exact name matches.\n" " -p|--pool POOL Filter images by pool ID or name\n" " -l|--long Also report allocated size and I/O statistics\n" " --del Also include delete operation statistics\n" " --sort FIELD Sort by specified field (name, size, used_size, _)\n" " -r|--reverse Sort in descending order\n" " -n|--count N Only list first N items\n" " --tree Show image snapshot/clone tree\n" "\n" "vitastor-cli create -s|--size [-p|--pool ] [--parent [@]] \n" " Create an image. You may use K/M/G/T suffixes for . If --parent is specified,\n" " a copy-on-write image clone is created. Parent must be a snapshot (readonly image).\n" " Pool must be specified if there is more than one pool.\n" "\n" "vitastor-cli create --snapshot [-p|--pool ] \n" "vitastor-cli snap-create [-p|--pool ] @\n" " Create a snapshot of image . May be used live if only a single writer is active.\n" "\n" "vitastor-cli modify [--rename ] [--resize ] [--readonly | --readwrite] [-f|--force] [--down-ok]\n" " Rename, resize image or change its readonly status. Images with children can't be made read-write.\n" " If the new size is smaller than the old size, extra data will be purged.\n" " You should resize file system in the image, if present, before shrinking it.\n" " --deleted 1|0 Set/clear 'deleted image' flag (set automatically during unfinished deletes).\n" " -f|--force Proceed with shrinking or setting readwrite flag even if the image has children.\n" " --down-ok Proceed with shrinking even if some data will be left on unavailable OSDs.\n" "\n" "vitastor-cli dd [iimg= | if=] [oimg= | of=] [bs=1M]\n" " [count=N] [seek/oseek=N] [skip/iseek=M] [iodepth=N] [status=progress]\n" " [conv=nocreat,noerror,nofsync,trunc,nosparse] [iflag=direct] [oflag=direct,append]\n" " Copy data between Vitastor images, files and pipes.\n" " Options can be specified in classic dd style (key=value) or like usual (--key value).\n" " iimg= Copy from Vitastor image \n" " if= Copy from file \n" " oimg= Copy to Vitastor image \n" " of= Copy to file \n" " bs=1M Set copy block size\n" " count=N Copy only N input blocks. If N ends in B it counts bytes, not blocks\n" " seek/oseek=N Skip N output blocks. If N ends in B it counts bytes, not blocks\n" " skip/iseek=N Skip N input blocks. If N ends in B it counts bytes, not blocks\n" " iodepth=N Send N reads or writes in parallel (default 4)\n" " status=LEVEL The LEVEL of information to print to stderr: none/noxfer/progress\n" " size=N Specify size for the created output file/image (defaults to input size)\n" " iflag=direct For input files only: use direct I/O\n" " oflag=direct For output files only: use direct I/O\n" " oflag=append For files only: append to output file\n" " conv=nocreat Do not create output file/image\n" " conv=trunc Truncate output file/image\n" " conv=noerror Continue copying after errors\n" " conv=nofsync Do not call fsync before finishing (default behaviour is fsync)\n" " conv=nosparse Write all output blocks including all-zero blocks\n" "\n" "vitastor-cli rm []\n" "vitastor-cli rm (--exact|--matching) ...\n" " Remove layer(s) and rebase all their children accordingly.\n" " In the first form, remove or layers between and its child .\n" " In the second form, remove all images with exact or pattern-matched names.\n" " --writers-stopped allows optimised removal in case of a single 'slim' read-write\n" " child and 'fat' removed parent: the child is merged into parent and parent is renamed\n" " to child in that case. In other cases parent layers are always merged into children.\n" " --exact Remove multiple images with names matching given glob patterns.\n" " --matching Remove multiple images with given names\n" " --writers-stopped Allow renaming inodes over their read/write children.\n" " --down-ok Continue deletion/merging even if some data will be left on unavailable OSDs.\n" "\n" "vitastor-cli flatten \n" " Flatten a layer, i.e. merge data and detach it from parents.\n" "\n" "vitastor-cli rm-data --pool --inode [--wait-list] [--min-offset ]\n" " Remove inode data without changing metadata.\n" " --wait-list Retrieve full objects listings before starting to remove objects.\n" " Requires more memory, but allows to show correct removal progress.\n" " --min-offset Purge only data starting with specified offset.\n" " --max-offset Purge only data before specified offset.\n" " --client_wait_up_timeout 16 Timeout for waiting until PGs are up in seconds.\n" "\n" "vitastor-cli merge-data [--target ]\n" " Merge layer data without changing metadata. Merge .. to .\n" " must be a child of and may be one of the layers between\n" " and , including and .\n" "\n" "vitastor-cli describe [OPTIONS]\n" " Describe unclean object locations in the cluster. Options:\n" " --osds \n" " Only list objects from primary OSD(s) .\n" " --object-state \n" " Only list objects in given state(s). State(s) may include:\n" " degraded, misplaced, incomplete, corrupted, inconsistent.\n" " --pool \n" " Only list objects in the given pool.\n" " --pg \n" " Only list objects in the given PG of the pool.\n" " --inode, --min-inode, --max-inode\n" " Restrict listing to specific inode numbers.\n" " --min-offset, --max-offset\n" " Restrict listing to specific offsets inside inodes.\n" "\n" "vitastor-cli fix [--objects ] [--bad-osds ] [--part ] [--check no]\n" " Fix inconsistent objects in the cluster by deleting some copies.\n" " --objects \n" " Objects to fix, either in plain text or JSON format. If not specified,\n" " object list will be read from STDIN in one of the same formats.\n" " Plain text format: 0x:0x 0x:0x ...\n" " JSON format: [{\"inode\":\"0x...\",\"stripe\":\"0x...\"},...]\n" " --bad-osds \n" " Remove inconsistent copies/parts of objects from these OSDs, effectively\n" " marking them bad and allowing Vitastor to recover objects from other copies.\n" " --part \n" " Only remove EC part (from 0 to pg_size-1), required for extreme\n" " edge cases where one OSD has multiple parts of a EC object.\n" " --check no\n" " Do not recheck that requested objects are actually inconsistent,\n" " delete requested copies/parts anyway.\n" "\n" "vitastor-cli alloc-osd\n" " Allocate a new OSD number and reserve it by creating empty /osd/stats/ key.\n" "\n" "vitastor-cli rm-osd [--force] [--allow-data-loss] [--dry-run] [osd_id...]\n" " Remove metadata and configuration for specified OSD(s) from etcd.\n" " Refuses to remove OSDs with data without --force and --allow-data-loss.\n" " With --dry-run only checks if deletion is possible without data loss and\n" " redundancy degradation.\n" "\n" "vitastor-cli osd-tree [-l|--long]\n" " Show current OSD tree, optionally with I/O statistics if -l is specified.\n" "\n" "vitastor-cli osds|ls-osd|osd-ls [-l|--long]\n" " Show current OSDs as list, optionally with I/O statistics if -l is specified.\n" "\n" "vitastor-cli modify-osd [--tags tag1,tag2,...] [--reweight ] [--noout true/false] \n" " Set OSD reweight, tags or noout flag.\n" "\n" "vitastor-cli pg-list|pg-ls|list-pg|ls-pg|ls-pgs|pgs [OPTIONS] [state1+state2] [^state3] [...]\n" " List PGs with any of listed state filters (^ or ! in the beginning is negation). Options:\n" " --pool Only list PGs of the given pool.\n" " --min Only list PGs with number >= min.\n" " --max Only list PGs with number <= max.\n" " --osd 1,2,... Only list PGs with some data on specified OSD(s).\n" " Examples:\n" " vitastor-cli pg-list active+degraded\n" " vitastor-cli pg-list ^active\n" "\n" "vitastor-cli create-pool|pool-create (-s |--ec +) -n [OPTIONS]\n" " Create a pool. Required parameters:\n" " -s|--pg_size R Number of replicas for replicated pools\n" " --ec N+K Number of data (N) and parity (K) chunks for erasure-coded pools\n" " -n|--pg_count N PG count for the new pool (start with 10*/pg_size rounded to a power of 2)\n" " Optional parameters:\n" " --pg_minsize R or N+K minus number of failures to tolerate without downtime\n" " --failure_domain host Failure domain: host, osd or a level from placement_levels. Default: host\n" " --root_node Put pool only on child OSDs of this placement tree node\n" " --osd_tags [,]... Put pool only on OSDs tagged with all specified tags\n" " --block_size 128k Put pool only on OSDs with this data block size\n" " --bitmap_granularity 4k Put pool only on OSDs with this logical sector size\n" " --immediate_commit all Put pool only on OSDs with this or larger immediate_commit (none < small < all)\n" " --level_placement Use additional failure domain rules (example: \"dc=112233\")\n" " --raw_placement Specify raw PG generation rules (see documentation for details)\n" " --local_reads primary Local read policy for replicated pools: primary, nearest or random\n" " --primary_affinity_tags tags Prefer to put primary copies on OSDs with all specified tags\n" " --scrub_interval