From nobody Wed Nov 5 16:33:09 2025 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536375798139138.37908225210344; Fri, 7 Sep 2018 20:03:18 -0700 (PDT) Received: from localhost ([::1]:41123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyTWc-00049R-RH for importer@patchew.org; Fri, 07 Sep 2018 23:03:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyTVZ-0002jZ-Fz for qemu-devel@nongnu.org; Fri, 07 Sep 2018 23:02:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fyTVW-0004a6-Ph for qemu-devel@nongnu.org; Fri, 07 Sep 2018 23:02:01 -0400 Received: from mail-it0-x234.google.com ([2607:f8b0:4001:c0b::234]:55133) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fyTVQ-0004Je-IR; Fri, 07 Sep 2018 23:01:52 -0400 Received: by mail-it0-x234.google.com with SMTP id f14-v6so23081714ita.4; Fri, 07 Sep 2018 20:01:52 -0700 (PDT) Received: from localhost.localdomain ([69.14.184.20]) by smtp.gmail.com with ESMTPSA id u5-v6sm2960058ioc.85.2018.09.07.20.01.49 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Sep 2018 20:01:49 -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=CaOU+zyoQFh8yWXMjz+X/pWvECoHzkpGJkTQoev6Nfk=; b=vMoK/Zg/yko8HegH0nfGTuRueeo8nAUBrXMaBBnC0hNu2M6WSMLwHATa2bMLvvugnI 7HI1EpK3ckOAwp2+mMDX9UXrs/C6OK6rpMHIPIXs80V17N/O1Clu+lw1DM6YIzvU//Sc 0utXJh8muz1Eus6CwzZxGDzFBm2xnuNRUokVe9yk3heHt06x9XbxyLdIfNkvDcLTNGc4 k9d7TzhfbCxktdxJaz8mMBmhF2NyMrr0Dfsvz4sCvYF+/ZdxYfWMCVjhULBBgsGrxVHa togHn2PsD6fF7/Wum8dacYurVX2CghTZo6Fn90dXq9tHSoHNNdOMLuASIakkiL5Xm+lq Jkpw== 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=CaOU+zyoQFh8yWXMjz+X/pWvECoHzkpGJkTQoev6Nfk=; b=p/hhNhD3nFSNpj/g/U8UqjGzkU8ISngOrNcqgAnulZ582wsMasi6XN4tgMvldsqRC2 IJrnqiUzGgd5Utw9+f9cLy431w5X6+anjpVFxvw1tIT2kgquPFYIjTmWrdZPXJYJGGfC bxwIdb84zPlRlyohNOnxpc0Id9SPuHj1M85rZ6bvLAhul/v04tbJDQO+f8FiCRGo5PUV LCSB7VhgfZE4XblICB/X8mnyqLbmXQBlS5snbZzLtQDB/fF8x/r6nH38Jw4Nppb/MGlW 5ZdaSK749dAA9g9D9drKBwEsSfYdRmN50NINiAHK4ShRwFG4Wr7hwj6XNrWgWaAJfFC2 AX/g== X-Gm-Message-State: APzg51BiwuJqjFVaPDfeQWfOpwenZUP56ZrJDbMk9v9ZzOjo0EbhI4g3 4dNVa1IfPa0ACqNMoydnKIw= X-Google-Smtp-Source: ANB0VdYfAAcrScghziECIhHBIHepJ2DPHa0CeGk/EVmBTrUyLwJfNdnIPXQ0JNtN4cbn406ScAL/Zw== X-Received: by 2002:a24:37d2:: with SMTP id r201-v6mr9268305itr.113.1536375710893; Fri, 07 Sep 2018 20:01:50 -0700 (PDT) From: John Arbuckle To: kwolf@redhat.com, mreitz@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 7 Sep 2018 23:01:36 -0400 Message-Id: <20180908030136.844-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:4001:c0b::234 Subject: [Qemu-devel] [PATCH] 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 --- qemu-img.c | 767 +++++++++++++++++++++++++++++++++++++++++++++++++++++----= ---- 1 file changed, 668 insertions(+), 99 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index b12f4cd..5eb38b8 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -76,11 +76,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 +100,639 @@ 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 fm" + "t]\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 pla" + "in\n" + " filename.\n" + "\n" + " -o Used with a comma separated list of format specific o= ption" + "s 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= roper" + "ties.\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 c" + "ommand\n" + " that supports it, the progress is reported when the p= roces" + "s\n" + " receives a \"SIGUSR1\" signal. Avoid using with the -= q opt" + "ion.\n" + "\n" + " -q Quiet mode - do not print any output (except errors).= Avoi" + "d\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= throu" + "gh,\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= firs" + "t.\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 = optio" + "ns 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 on" + "ly\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= \' fi" + "xes 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= ption" + "s 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= supp" + "ly\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= plai" + "n\n" + " filename.\n" + "\n" + " --object \'objectdef\' is a QEMU user creatable object definiti= on. S" + "ee the\n" + " qemu(1) manual page for a description of the object pr= opert" + "ies.\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 co" + "mmand\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= throu" + "gh,\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 f" + "mt]\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= initi" + "on. See\n" + " the qemu(1) manual page for a description of the = objec" + "t\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 whe" + "n 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= ption" + "s are\n" + " used.\n" + "\n" + " -s Enable strict mode. Comparisons differ when image= size" + "s\n" + " differ or if a sector is allocated in one image a= nd no" + "t\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 onl" + "y\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 t" + "o 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 pro" + "cess\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 s" + "ize.\n" + "\n" + " --object \'objectdef\' is a QEMU user creatable objec= t def" + "inition.\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 use" + "d for\n" + " a command that supports it, the progress is = repor" + "ted\n" + " when the process receives a \"SIGUSR1\" sign= al.\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\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 op" + "tions.\n" + "\n" + " -U Open the image in shared mode, allowing othe= r QEM" + "U\n" + " processes to open it in write mode. This opt= ion i" + "s only\n" + " allowed when opening images in read-only mod= e.\n" + "\n" + " -W Allow out-of-order writes to the destination= . Thi" + "s\n" + " option improves performance, but is only rec= ommen" + "ded\n" + " for preallocated devices like host devices o= r oth" + "er 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 o" + "pened.\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 by" + "tes 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= \"hu" + "man\" 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= ] [--si" + "ze 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= initi" + "on. See\n" + " the qemu(1) manual page for a description of the = objec" + "t\n" + " properties. The most common object type is a \'se= cret" + "\',\n" + " which is used to supply passwords and/or encrypti= on ke" + "ys.\n" + "\n" + " --output \'ofmt\' is \'human\' for human-readable output (= defau" + "lt) or\n" + " \'json\' for JSON output.\n" + "\n" + " --size If given act as if creating a new empty image fil= e usi" + "ng\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 f" + "ile.\n" + "\n" + " -t Specifies the cache mode that should be used with the des= tinat" + "ion\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 = comma" + "nd\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= imag" + "e\n" + " area should be allocated on the host.\n" + "\n" + " --shrink Informs qemu-img that the user acknowledges all l= oss o" + "f\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 { @@ -4954,6 +5486,43 @@ int main(int argc, char **argv) =20 cmdname =3D argv[optind]; =20 + /* print the help for this command */ + if (strcmp("--help", argv[optind + 1]) =3D=3D 0) { + if (strcmp("amend", cmdname) =3D=3D 0) { + help_amend(); + } else if (strcmp("bench", cmdname) =3D=3D 0) { + help_bench(); + } else if (strcmp("check", cmdname) =3D=3D 0) { + help_check(); + } else if (strcmp("commit", cmdname) =3D=3D 0) { + help_commit(); + } else if (strcmp("compare", cmdname) =3D=3D 0) { + help_compare(); + } else if (strcmp("convert", cmdname) =3D=3D 0) { + help_convert(); + } else if (strcmp("create", cmdname) =3D=3D 0) { + help_create(); + } else if (strcmp("dd", cmdname) =3D=3D 0) { + help_dd(); + } else if (strcmp("info", cmdname) =3D=3D 0) { + help_info(); + } else if (strcmp("map", cmdname) =3D=3D 0) { + help_map(); + } else if (strcmp("measure", cmdname) =3D=3D 0) { + help_measure(); + } else if (strcmp("snapshot", cmdname) =3D=3D 0) { + help_snapshot(); + } else if (strcmp("rebase", cmdname) =3D=3D 0) { + help_rebase(); + } else if (strcmp("resize", cmdname) =3D=3D 0) { + help_resize(); + } else { + printf("\'%s\' does not have help available for it\n\n", cmdna= me); + return -1; + } + return 0; + } + /* reset getopt_long scanning */ argc -=3D optind; if (argc < 1) { --=20 2.7.2