From nobody Mon Apr 29 05:01:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537890949522423.5403213964154; Tue, 25 Sep 2018 08:55:49 -0700 (PDT) Received: from localhost ([::1]:53913 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4pgi-0003Xu-8U for importer@patchew.org; Tue, 25 Sep 2018 11:55:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4pY1-00048p-NC for qemu-devel@nongnu.org; Tue, 25 Sep 2018 11:46:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4pRi-0006wQ-8y for qemu-devel@nongnu.org; Tue, 25 Sep 2018 11:40:20 -0400 Received: from mail-it1-x12f.google.com ([2607:f8b0:4864:20::12f]:52320) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g4pRe-0006uD-9D; Tue, 25 Sep 2018 11:40:14 -0400 Received: by mail-it1-x12f.google.com with SMTP id h3-v6so15999320ita.2; Tue, 25 Sep 2018 08:40:13 -0700 (PDT) Received: from localhost.localdomain (d14-69-20-184.try.wideopenwest.com. [69.14.184.20]) by smtp.gmail.com with ESMTPSA id b26-v6sm924291iod.38.2018.09.25.08.40.11 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 25 Sep 2018 08:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=OER5pp+4rRmkb3O0TANYG7rrw6lMbfGoCudTnpx206M=; b=on83xqDX3al+31v27Bp0vVcYfvvTVJ8Ipv8B64mhKTtMQzl8SjGOGdvnUDYyY4db8A mJxoRVzc4AcL3ZmyYoSC/IOCLcf0QZcovusxbGW4knYFPkzcsgRJafPuvCwT1a+kBt00 Ut4ORetygxD4qiv5slBmMMzfpTERoGSZObX6aYD3GBLMpwA8214oTl6orN65BK6e/Qwq KpJGVEoO2qpwzHG1VsQuPdw8aQhLmLUrFKT3Zc9vs3hrL4CMk6xdC4vCmco9680Miy5B iB7mCx/NSCsutvGnGgwUbfiwGgRFN8wSFmEqxdASVZb77bqucV/muVHYYYBV8MjPtcGm xlRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=OER5pp+4rRmkb3O0TANYG7rrw6lMbfGoCudTnpx206M=; b=sq1g0vGQmw0CRC3+0G27uOECD++BZnUsB1yM9Jm19y+QE5LEm7oesxe9WbqyZP7Qoj y1Gs47bDkp5EKjRtxJIwLJv/sShfUc55yiRKE1Tp25qtNNJV0nundBFw5jKpnuhv6gRb 5T2Q0Acs/V7q7gsZZbDuCW+ZYO1HXHzUhM3U3DHz4bXY8XGl4PSJB4BC3xHHKD6R9V01 KOU0uOrixBqGQJBvZL+66V84IJwXnH3dsRr+mxeqhUyeC6LH9OCDi7oSeQLK3bDHcema ZgAMuF3oAiQB2peV+uTopHMbqhqXFuLL01hdvmuqBF4mf3XgHo9bWmuD0HCP8I7x3y/3 C8Wg== X-Gm-Message-State: ABuFfoi3K89+q5GOo0SWE8FlEsljWk7x27JHza9J3kR0yS5QI7R/ikVa AGzmi9XsUhd6ujNK5sz//OY= X-Google-Smtp-Source: ACcGV62ui8LAr86jrcmpIjF7EpwKp04VFZETGKeEIyFLKXEFrEvQ9I9zroy3YG4FDQxtRNKIrZrSnw== X-Received: by 2002:a02:298b:: with SMTP id p133-v6mr1527154jap.17.1537890012736; Tue, 25 Sep 2018 08:40:12 -0700 (PDT) From: John Arbuckle To: mreitz@redhat.com, kwolf@redhat.com, qemu-block@nongnu.org, muriloo@linux.ibm.com, qemu-devel@nongnu.org Date: Tue, 25 Sep 2018 11:39:49 -0400 Message-Id: <20180925153949.1577-1-programmingkidx@gmail.com> X-Mailer: git-send-email 2.14.3 (Apple Git-98) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::12f Subject: [Qemu-devel] [PATCH v3] qemu-img.c: add help for each command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add the ability for the user to display help for a certain command.=20 Example: qemu-img create --help What is printed is all the options available to this command and an example. Signed-off-by: John Arbuckle Acked-by: Murilo Opsfelder Araujo --- v3 changes: Fixed a bug that caused qemu-img to crash when running a command without options. v2 changes: Removed block of string comparison code for each command. Added a help_func field to the img_cmd_t struct. Made strings longer than 80 characters wide. qemu-img.c | 660 +++++++++++++++++++++++++++++++++++++++++++++++++++------= ---- 1 file changed, 559 insertions(+), 101 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 1acddf693c..e4d9baa550 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -52,6 +52,7 @@ typedef struct img_cmd_t { const char *name; int (*handler)(int argc, char **argv); + void (*help_func)(void); } img_cmd_t; =20 enum { @@ -76,11 +77,6 @@ typedef enum OutputFormat { /* Default to cache=3Dwriteback as data integrity is not important for qem= u-img */ #define BDRV_DEFAULT_CACHE "writeback" =20 -static void format_print(void *opaque, const char *name) -{ - printf(" %s", name); -} - static void QEMU_NORETURN GCC_FMT_ATTR(1, 2) error_exit(const char *fmt, .= ..) { va_list ap; @@ -105,102 +101,546 @@ static void QEMU_NORETURN unrecognized_option(const= char *option) error_exit("unrecognized option '%s'", option); } =20 -/* Please keep in synch with qemu-img.texi */ -static void QEMU_NORETURN help(void) +/* Prints an overview of available help options */ +static void help(void) { const char *help_msg =3D - QEMU_IMG_VERSION - "usage: qemu-img [standard options] command [command options]\n" - "QEMU disk image utility\n" - "\n" - " '-h', '--help' display this help and exit\n" - " '-V', '--version' output version information and exit\n" - " '-T', '--trace' [[enable=3D]][,events=3D][,file=3D]\n" - " specify tracing options\n" - "\n" - "Command syntax:\n" -#define DEF(option, callback, arg_string) \ - " " arg_string "\n" -#include "qemu-img-cmds.h" -#undef DEF - "\n" - "Command parameters:\n" - " 'filename' is a disk image filename\n" - " 'objectdef' is a QEMU user creatable object definition. See = the qemu(1)\n" - " manual page for a description of the object properties. Th= e most common\n" - " object type is a 'secret', which is used to supply passwor= ds and/or\n" - " encryption keys.\n" - " 'fmt' is the disk image format. It is guessed automatically = in most cases\n" - " 'cache' is the cache mode used to write the output disk imag= e, the valid\n" - " options are: 'none', 'writeback' (default, except for conv= ert), 'writethrough',\n" - " 'directsync' and 'unsafe' (default for convert)\n" - " 'src_cache' is the cache mode used to read input disk images= , the valid\n" - " options are the same as for the 'cache' option\n" - " 'size' is the disk image size in bytes. Optional suffixes\n" - " 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (g= igabyte, 1024M),\n" - " 'T' (terabyte, 1024G), 'P' (petabyte, 1024T) and 'E' (exab= yte, 1024P) are\n" - " supported. 'b' is ignored.\n" - " 'output_filename' is the destination disk image filename\n" - " 'output_fmt' is the destination format\n" - " 'options' is a comma separated list of format specific optio= ns in a\n" - " name=3Dvalue format. Use -o ? for an overview of the optio= ns supported by the\n" - " used format\n" - " 'snapshot_param' is param used for internal snapshot, format= \n" - " is 'snapshot.id=3D[ID],snapshot.name=3D[NAME]', or\n" - " '[ID_OR_NAME]'\n" - " '-c' indicates that target image must be compressed (qcow fo= rmat only)\n" - " '-u' allows unsafe backing chains. For rebasing, it is assum= ed that old and\n" - " new backing file match exactly. The image doesn't need = a working\n" - " backing file before rebasing in this case (useful for r= enaming the\n" - " backing file). For image creation, allow creating witho= ut attempting\n" - " to open the backing file.\n" - " '-h' with or without a command shows this help and lists the= supported formats\n" - " '-p' show progress of command (only certain commands)\n" - " '-q' use Quiet mode - do not print any output (except errors= )\n" - " '-S' indicates the consecutive number of bytes (defaults to = 4k) that must\n" - " contain only zeros for qemu-img to create a sparse imag= e during\n" - " conversion. If the number of bytes is 0, the source wil= l not be scanned for\n" - " unallocated or zero sectors, and the destination image = will always be\n" - " fully allocated\n" - " '--output' takes the format in which the output must be done= (human or json)\n" - " '-n' skips the target volume creation (useful if the volume = is created\n" - " prior to running qemu-img)\n" - "\n" - "Parameters to check subcommand:\n" - " '-r' tries to repair any inconsistencies that are found duri= ng the check.\n" - " '-r leaks' repairs only cluster leaks, whereas '-r all'= fixes all\n" - " kinds of errors, with a higher risk of choosing the wro= ng fix or\n" - " hiding corruption that has already occurred.\n" - "\n" - "Parameters to convert subcommand:\n" - " '-m' specifies how many coroutines work in parallel during t= he convert\n" - " process (defaults to 8)\n" - " '-W' allow to write to the target out of order rather than s= equential\n" - "\n" - "Parameters to snapshot subcommand:\n" - " 'snapshot' is the name of the snapshot to create, apply or d= elete\n" - " '-a' applies a snapshot (revert disk to saved state)\n" - " '-c' creates a snapshot\n" - " '-d' deletes a snapshot\n" - " '-l' lists all snapshots in the given image\n" - "\n" - "Parameters to compare subcommand:\n" - " '-f' first image format\n" - " '-F' second image format\n" - " '-s' run in Strict mode - fail on different image size or se= ctor allocation\n" - "\n" - "Parameters to dd subcommand:\n" - " 'bs=3DBYTES' read and write up to BYTES bytes at a time " - "(default: 512)\n" - " 'count=3DN' copy only N input blocks\n" - " 'if=3DFILE' read from FILE\n" - " 'of=3DFILE' write to FILE\n" - " 'skip=3DN' skip N bs-sized blocks at the start of input\n"; - - printf("%s\nSupported formats:", help_msg); - bdrv_iterate_format(format_print, NULL); - printf("\n\n" QEMU_HELP_BOTTOM "\n"); - exit(EXIT_SUCCESS); + QEMU_IMG_VERSION + "usage: qemu-img [standard options] command [command options]\n" + "QEMU disk image utility\n" + "\n" + " '-h', '--help' display this help and exit\n" + " '-V', '--version' output version information and exit\n" + " '-T', '--trace' [[enable=3D]][,events=3D][,fi= le=3D]\n" + " specify tracing options\n" + "\n" + "Command:\n" + "\tamend Change options of an existing disk image\n" + "\tbench Run benchmarks on a given disk image\n" + "\tcheck Check the disk image for consistency or repair i= t\n" + "\tcommit Merge the disk image into its backing file\n" + "\tcompare Check if two images have the same content\n" + "\tconvert Convert an image file or snapshot into another f= ile\n" + "\tcreate Create a new disk image\n" + "\tdd Copies and converts an input file into another f= ile\n" + "\tinfo Gives information about the specified image file= \n" + "\tmap Dump the metadata of image filename\n" + "\tmeasure Calculate the file size required for a new image= \n" + "\tsnapshot List, apply, create or delete snapshots in a fil= e\n" + "\trebase Changes the backing file of an image file\n" + "\tresize Resize an image file\n" + "\n\nRun 'qemu-img --help' for details.\n" + "See for how to report bugs= .\n" + "More information on the QEMU project at .\n"; + printf("%s\n", help_msg); +} + +static void help_amend(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img amend [--object objectdef] [--image-opts] [-p] [-q] [= -f fmt]\n" + "[-t cache] -o options filename\n" + "\n" + "Command parameters:\n" + " -f The format of the image file.\n" + "\n" + "--image-opts Treat filename as a set of image options, instead of = a plain\n" + " filename.\n" + "\n" + " -o Used with a comma separated list of format specific o= ptions in a\n" + " name=3Dvalue format. Use \"-o help\" for an overview = of the options\n" + " supported by the used format.\n" + "\n" + "--object \'objectdef\' is a QEMU user creatable object definit= ion. See the\n" + " qemu(1) manual page for a description of the object p= roperties.\n" + " The most common object type is a \'secret\', which is= used to\n" + " supply passwords and/or encryption keys.\n" + "\n" + " -p Display progress bar. If the -p option is not used fo= r a command\n" + " that supports it, the progress is reported when the p= rocess\n" + " receives a \"SIGUSR1\" signal. Avoid using with the -= q option.\n" + "\n" + " -q Quiet mode - do not print any output (except errors).= Avoid\n" + " using with the -p option.\n" + "\n" + " -t Specifies the cache mode that should be used with the= \n" + " destination file. Options are: none, writeback, write= through,\n" + " directsync, and unsafe.\n" + "\n" + "Example:\n" + " qemu-img amend -o compat=3Dv3 -f qcow2 image.qcow2\n" + " qemu-img amend --object secret,id=3Dsec0,data=3Dtest --image-opts= \\\n" + " driver=3Dluks,key-secret=3Dsec0,file.filename=3Dtest.luks -o size= =3D2G\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_bench(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img bench [-c count] [-d depth] [-f fmt]\n" + "[--flush-interval=3Dflush_interval] [-n] [--no-drain] [-o offset]\n" + "[--pattern=3Dpattern] [-q] [-s buffer_size] [-S step_size] [-t cache]= [-w] [-U]\n" + "filename\n" + "\n" + "Command parameters:\n" + " -c Number of I/O requests to perform.\n" + "\n" + " -d Number of I/O requests done in parallel.\n" + "\n" + " -f The format of the image file.\n" + "\n" + " --flush-interval How often a flush should take place.\n" + "\n" + " -n Use native AIO backend if possible.\n" + "\n" + " --no-drain Issue a flush without draining the request queue= first.\n" + "\n" + " -o The starting position.\n" + "\n" + " --pattern The byte pattern used to in write tests.\n" + "\n" + " -q Quiet mode - do not print any output (except err= ors).\n" + " There\'s no progress bar in case both -q and -p = options are\n" + " used.\n" + "\n" + " -s buffer_size in bytes.\n" + "\n" + " -S Increases current position by step_size.\n" + "\n" + " -t Specifies the cache mode that should be used wit= h the\n" + " destination file. Options are: none, writeback,= \n" + " writethrough, directsync, and unsafe.\n" + "\n" + " -w Perform write test.\n" + "\n" + " -U Open the image in shared mode, allowing other QE= MU\n" + " processes to open it in write mode. This option = is only\n" + " allowed when opening images in read-only mode.\n" + "\n" + "Example:\n" + " qemu-img bench -c 20000 -d 50000 -f qcow2 image.qcow2\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_check(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img check [--object objectdef] [--image-opts] [-q] [-f fm= t]\n" + "[--output=3Dofmt] [-r [leaks | all]] [-T src_cache] [-U] filename\n" + "\n" + "Command parameters:\n" + " -f The format of the image file.\n" + "\n" + " -q Use Quiet mode - do not print any output (except errors).= \n" + "\n" + " -r Tries to repair any inconsistencies that are found during= the check.\n" + " \'-r leaks\' repairs only cluster leaks, whereas \'-r all= \' fixes all\n" + " kinds of errors, with a higher risk of choosing the wrong= fix or\n" + " hiding corruption that has already occurred.\n" + "\n" + " -T \'src_cache\' is the cache mode used to read input disk i= mages, the\n" + " valid options are the same as for the \'cache\' option. O= ptions are:\n" + " none, writeback, writethrough, directsync, and unsafe.\n" + "\n" + " --object \'objectdef\' is a QEMU user creatable object definition.= See the\n" + " qemu(1) manual page for a description of the object prope= rties. The\n" + " most common object type is a \'secret\', which is used to= supply\n" + " passwords and/or encryption keys.\n" + "\n" + " --output \'ofmt\' is \'human\' for human-readable output (default)= or \'json\' for\n" + " JSON output.\n" + "\n" + "Example:\n" + " qemu-img check image.qcow2\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_commit(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img commit [--object objectdef] [--image-opts] [-q] [-f f= mt]\n" + "[-t cache] [-b base] [-d] [-p] filename\n" + "\n" + "Command parameters:\n" + " -b The base image or backing file.\n" + "\n" + " -d Skip emptying filename.\n" + "\n" + " -f The format of the image file.\n" + "\n" + " --image-opts Treat filename as a set of image options, instead of a= plain\n" + " filename.\n" + "\n" + " --object \'objectdef\' is a QEMU user creatable object definiti= on. See the\n" + " qemu(1) manual page for a description of the object pr= operties.\n" + " The most common object type is a \'secret\', which is = used to\n" + " supply passwords and/or encryption keys.\n" + "\n" + " -p Display progress bar. If the -p option is not used for= a command\n" + " that supports it, the progress is reported when the pr= ocess\n" + " receives a \"SIGUSR1\" signal.\n" + "\n" + " -q Quiet mode - do not print any output (except errors). = There\'s no\n" + " progress bar in case both -q and -p options are used.\= n" + "\n" + " -t Specifies the cache mode that should be used with the\= n" + " destination file. Options are: none, writeback, write= through,\n" + " directsync, and unsafe.\n" + "\n" + "Example:\n" + " qemu-img commit image.qcow2\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_compare(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img compare [--object objectdef] [--image-opts] [-f fmt] = [-F fmt]\n" + "[-T src_cache] [-p] [-q] [-s] [-U] filename1 filename2\n" + "\n" + "Command parameters:\n" + " -f First image\'s format.\n" + "\n" + " -F Second image\'s format.\n" + "\n" + " --image-opts Treat filename as a set of image options, instead= of a plain\n" + " filename.\n" + "\n" + " -T Specifies the cache mode that should be used with= the source\n" + " file. Options are: none, writeback, writethrough,= \n" + " directsync, and unsafe.\n" + "\n" + " --object \'objectdef\' is a QEMU user creatable object def= inition. See\n" + " the qemu(1) manual page for a description of the = object\n" + " properties. The most common object type is a \'se= cret\', which\n" + " is used to supply passwords and/or encryption key= s.\n" + "\n" + " -p Display progress bar. If the -p option is not use= d for a\n" + " command that supports it, the progress is reporte= d when the\n" + " process receives a \"SIGUSR1\" signal.\n" + "\n" + " -q Quiet mode - do not print any output (except erro= rs).\n" + " There\'s no progress bar in case both -q and -p o= ptions are\n" + " used.\n" + "\n" + " -s Enable strict mode. Comparisons differ when image= sizes\n" + " differ or if a sector is allocated in one image a= nd not\n" + " allocated in the other image.\n" + "\n" + " -U Open the image in shared mode, allowing other QEM= U\n" + " processes to open it in write mode. This option i= s only\n" + " allowed when opening images in read-only mode.\n" + "\n" + "Example:\n" + " qemu-img compare image1.qcow image2.qcow2\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_convert(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img convert [--object objectdef] [--image-opts]\n" + "[--target-image-opts] [-U] [-c] [-p] [-q] [-n] [-f fmt] [-t cache]\n" + "[-T src_cache] [-O output_fmt] [-B backing_file] [-o options]\n" + "[-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size]\n" + "[-m num_coroutines] [-W] filename [filename2 [...]] output_filename\n" + "\n" + "Command parameters:\n" + " -B Force the output image to be created as a co= py on write\n" + " image of the specified base image.\n" + "\n" + " -c Compress the output image file.\n" + "\n" + " -f The format of the image file.\n" + "\n" + " --image-opts Indicates that the source filename parameter= is to be\n" + " interpreted as a full option string, not a p= lain\n" + " filename.\n" + "\n" + " -l Specifies a snapshot parameter.\n" + "\n" + " -m Number of parallel coroutines for the conver= t process\n" + "\n" + " -n Skip the creation of the target volume.\n" + "\n" + " -O Format of the output file.\n" + "\n" + " -o Allows for specifying options like virtual d= isk size.\n" + "\n" + " --object \'objectdef\' is a QEMU user creatable objec= t definition.\n" + " See the qemu(1) manual page for a descriptio= n of the\n" + " object properties. The most common object ty= pe is a\n" + " \'secret\', which is used to supply password= s and/or\n" + " encryption keys.\n" + "\n" + " -p Display progress bar. If the -p option is no= t used for\n" + " a command that supports it, the progress is = reported\n" + " when the process receives a \"SIGUSR1\" sign= al.\n" + "\n" + " -q Quiet mode - do not print any output (except= errors).\n" + " There\'s no progress bar in case both -q and= -p options\n" + " are used.\n" + "\n" + " -S The consecutive number of bytes (defaults to= 4k) that\n" + " must contain only zeros for qemu-img to crea= te a sparse\n" + " image during conversion.\n" + "\n" + " -s The name or ID of the snapshot to use.\n" + "\n" + " -T Specifies the cache mode that should be used= with the\n" + " source file.\n" + "\n" + " -t Specifies the cache mode that should be used= with the\n" + " destination file. Options are: none, writeba= ck,\n" + " writethrough, directsync, and unsafe.\n" + "\n" + "--target-image-opts Indicates whether the source filename includ= es options.\n" + "\n" + " -U Open the image in shared mode, allowing othe= r QEMU\n" + " processes to open it in write mode. This opt= ion is only\n" + " allowed when opening images in read-only mod= e.\n" + "\n" + " -W Allow out-of-order writes to the destination= . This\n" + " option improves performance, but is only rec= ommended\n" + " for preallocated devices like host devices o= r other raw\n" + " block devices.\n" + "\n" + "Example:\n" + " qemu-img convert -f raw -O qcow2 image.img image.qcow2\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_create(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img create [--object objectdef] [-q] [-f fmt] [-b backing= _file]\n" + "[-F backing_fmt] [-u] [-o options] filename [size]\n" + "\n" + "Command parameters:\n" + " -b The backing file used to base the output file on.\n" + "\n" + " -f The format of the image file.\n" + "\n" + " -F The format of the backing file.\n" + "\n" + " -u Create the image file even if the backing file cannot= be opened.\n" + "\n" + " -o Allows for specifying options like virtual disk size.= \n" + "\n" + "--object \'objectdef\' is a QEMU user creatable object definit= ion.\n" + " See the qemu(1) manual page for a description of the\= n" + " object properties. The most common object type is a\n" + " \'secret\', which is used to supply passwords and/or\= n" + " encryption keys.\n" + "\n" + "Example:\n" + " qemu-img create -f qcow2 image.qcow2 10G\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_dd(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img dd [-f fmt] [-O output_fmt] [bs=3Dblock_size] [count= =3Dblocks]\n" + "[skip=3Dblocks] if=3Dinput of=3Doutput\n" + "\n" + "Command parameters:\n" + " bs Size of the blocks used in reading and writing (5= 12 bytes is\n" + " the default).\n" + "\n" + " count The limit to how many blocks to read.\n" + "\n" + " -f The format of the image file.\n" + "\n" + " if The input file.\n" + "\n" + " -O Format of the output file.\n" + "\n" + " of The output file.\n" + "\n" + " skip Number of blocks to skip.\n" + "\n" + "Example:\n" + " qemu-img dd if=3D/dev/cdrom -O raw of=3Dcd.iso\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_info(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img info [-f fmt] [--output=3Dofmt] [--backing-chain] fil= ename\n" + "\n" + "Command parameters:\n" + " --backing-chain Recursively enumerate thru each disk imag= e in the\n" + " chain for information.\n" + "\n" + " -f The format of the image file.\n" + "\n" + "--output The output format of this command. Can be= \"human\" or\n" + " \"json\".\n" + "\n" + "Example:\n" + " qemu-img info image.qcow2\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_map(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img map [-f fmt] [--output=3Dofmt] filename\n" + "\n" + "Command parameters:\n" + " -f The format of the image file.\n" + "\n" + "--output The output format of this command. Can be \"human= \" or \"json\".\n" + "\n" + "Example:\n" + " qemu-img map image.qcow2\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_measure(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img measure [--output=3Dofmt] [-O output_fmt] [-o options= ] [--size N ]\n" + "[--object objectdef] [--image-opts] [-f fmt] [-l snapshot_param]\n" + "filename\n" + "\n" + "Command parameters:\n" + " -f The format of the image file.\n" + "\n" + " --image-opts Indicates that the source filename parameter is t= o be\n" + " interpreted as a full option string, not a plain\= n" + " filename.\n" + "\n" + " -l Specifies a snapshot parameter.\n" + "\n" + " -O Format of the output file.\n" + "\n" + " -o Allows for specifying options.\n" + "\n" + " --object \'objectdef\' is a QEMU user creatable object def= inition. See\n" + " the qemu(1) manual page for a description of the = object\n" + " properties. The most common object type is a \'se= cret\',\n" + " which is used to supply passwords and/or encrypti= on keys.\n" + "\n" + " --output \'ofmt\' is \'human\' for human-readable output (= default) or\n" + " \'json\' for JSON output.\n" + "\n" + " --size If given act as if creating a new empty image fil= e using\n" + " qemu-img create.\n" + "\n" + "Example:\n" + " qemu-img measure -O qcow2 --size 5G\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_snapshot(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img snapshot [-l | -a snapshot | -c snapshot | -d snapsho= t ]\n" + "filename\n" + "\n" + "Command parameters:\n" + " -a Applies the snapshot.\n" + "\n" + " -c Create a snapshot.\n" + "\n" + " -d Deletes a snapshot.\n" + "\n" + " -l Lists all snapshots\n" + "\n" + "Example:\n" + " qemu-img snapshot -l image.qcow2\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_rebase(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img rebase [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -= b\n" + "backing_file [-F backing_fmt] filename\n" + "\n" + "Command parameters:\n" + " -b The new backing file.\n" + "\n" + " -F The format for the new backing file.\n" + "\n" + " -f The format of the image file being rebased.\n" + "\n" + " -T Specifies the cache mode that should be used with the sou= rce file.\n" + "\n" + " -t Specifies the cache mode that should be used with the des= tination\n" + " file. Options are: none, writeback, writethrough, directs= ync, and\n" + " unsafe.\n" + "\n" + " -p Display progress bar. If the -p option is not used for a = command\n" + " that supports it, the progress is reported when the proce= ss\n" + " receives a \"SIGUSR1\" signal.\n" + "\n" + " -u Operate in unsafe mode.\n" + "\n" + "Example:\n" + " qemu-img rebase -b backing.img diff.qcow2\n" + "\n" + "\n"; + printf("%s", msg); +} + +static void help_resize(void) +{ + const char *msg =3D + "\n" + "usage: qemu-img resize [--shrink] [--preallocation=3Dprealloc] filena= me\n" + "[+ | -] size\n" + "\n" + "Command parameters:\n" + " --preallocation When growing an image, specify how the additional= image\n" + " area should be allocated on the host.\n" + "\n" + " --shrink Informs qemu-img that the user acknowledges all l= oss of\n" + " data beyond the truncated image\'s end.\n" + "\n" + "Example:\n" + " qemu-img resize image.qcow2 20G\n"; + printf("%s", msg); } =20 static QemuOptsList qemu_object_opts =3D { @@ -4886,7 +5326,7 @@ out: return ret; } =20 -static const img_cmd_t img_cmds[] =3D { +static img_cmd_t img_cmds[] =3D { #define DEF(option, callback, arg_string) \ { option, callback }, #include "qemu-img-cmds.h" @@ -4894,6 +5334,12 @@ static const img_cmd_t img_cmds[] =3D { { NULL, NULL, }, }; =20 +/* These functions will be added to the img_cmds array */ +void (*help_functions[])(void) =3D {help_amend, help_bench, help_check,\ + help_commit, help_compare, help_convert, help_create, help_dd, help_in= fo,\ + help_map, help_measure, help_snapshot, help_rebase, help_resize}; + + int main(int argc, char **argv) { const img_cmd_t *cmd; @@ -4970,10 +5416,22 @@ int main(int argc, char **argv) trace_init_file(trace_file); qemu_set_log(LOG_TRACE); =20 + /* Add all the help functions to the array */ + int i; + for (i =3D 0; i < ARRAY_SIZE(help_functions); i++) { + img_cmds[i].help_func =3D help_functions[i]; + } + /* find the command */ for (cmd =3D img_cmds; cmd->name !=3D NULL; cmd++) { if (!strcmp(cmdname, cmd->name)) { - return cmd->handler(argc, argv); + if ((argc > (optind + 1)) && + strcmp("--help", argv[optind + 1]) =3D=3D 0) { + cmd->help_func(); + return 0; + } else { + return cmd->handler(argc, argv); + } } } =20 --=20 2.14.3 (Apple Git-98)