Tuan Hoang
2019-Nov-05 08:49 UTC
[Libguestfs] [PATCH v2 RESEND] direct, fish: add command launch_blocksize
Add a new launch command for direct backend, which allows specifying the blocksize to the disks. The name is `launch_blocksize`, accompanied alias is `run-blocksize`. Example: $ guestfish --listen -a raw.img $ guestfish --remote -- launch_blocksize 4096 The actual qemu command is: [...] -device virtio-scsi-ccw,id=scsi -drive file=raw.img,cache=writeback,id=hd0,if=none -device scsi-hd,drive=hd0,physical_block_size=4096,logical_block_size=4096 [...] Ideally it would be better to invoke optional option to `launch` command like: $ guestfish --remote -- launch --blocksize 4096 Signed-off-by: Tuan Hoang <tmhoang@linux.ibm.com> --- generator/actions_core.ml | 11 +++++++++++ lib/guestfs-internal.h | 3 +++ lib/launch-direct.c | 6 ++++++ lib/launch.c | 14 ++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/generator/actions_core.ml b/generator/actions_core.ml index 7b6568b..cfe735a 100644 --- a/generator/actions_core.ml +++ b/generator/actions_core.ml @@ -38,6 +38,17 @@ it will not give an error (for historical reasons), the precise behaviour when you do this is not well defined. Handles are very cheap to create, so create a new one for each launch." }; + { defaults with + name = "launch_blocksize"; added = (1, 40, 2); + style = RErr, [Int "blocksize"], []; + fish_alias = ["run-blocksize"]; progress = true; config_only = true; + shortdesc = "launch the backend with blocksize for disks"; + longdesc = "\ +Similar to \"launch\" call, but requires an integer as blocksize for disks. + +A call of \"launch_blocksize 512\" is equivalent of \"launch\" since the +default blocksize for qemu is 512." }; + { defaults with name = "add_drive_ro"; added = (1, 0, 38); style = RErr, [String (PlainString, "filename")], []; diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h index 75b8a5c..e9b7057 100644 --- a/lib/guestfs-internal.h +++ b/lib/guestfs-internal.h @@ -513,6 +513,9 @@ struct guestfs_h { /* Used by lib/info.c. -1 = not tested or error; else 0 or 1. */ int qemu_img_supports_U_option; + + /* Used by guestfish's launch_blocksize call */ + int blocksize; }; /** diff --git a/lib/launch-direct.c b/lib/launch-direct.c index ee2dcb8..54cd8c6 100644 --- a/lib/launch-direct.c +++ b/lib/launch-direct.c @@ -315,6 +315,12 @@ add_drive (guestfs_h *g, struct backend_direct_data *data, start_list ("-device") { append_list ("scsi-hd"); append_list_format ("drive=hd%zu", i); + if (g->blocksize >= 512 && g->blocksize <= 32768 + && (g->blocksize & (g->blocksize-1)) == 0) + { + append_list_format ("physical_block_size=%d", g->blocksize); + append_list_format ("logical_block_size=%d", g->blocksize); + } if (drv->disk_label) append_list_format ("serial=%s", drv->disk_label); } end_list (); diff --git a/lib/launch.c b/lib/launch.c index eb7f85c..8edf7b1 100644 --- a/lib/launch.c +++ b/lib/launch.c @@ -53,6 +53,20 @@ static struct backend { const struct backend_ops *ops; } *backends = NULL; +int +guestfs_impl_launch_blocksize (guestfs_h *g, int blocksize) +{ + if (blocksize >= 512 && blocksize <= 32768 + && (blocksize & (blocksize-1)) == 0) { + g->blocksize = blocksize; + return guestfs_impl_launch (g); + } + else { + error (g, _("blocksize must be a power of 2 between 512 and 32768")); + return -1; + } +} + int guestfs_impl_launch (guestfs_h *g) { -- 2.21.0
Richard W.M. Jones
2019-Nov-12 09:11 UTC
Re: [Libguestfs] [PATCH v2 RESEND] direct, fish: add command launch_blocksize
On Tue, Nov 05, 2019 at 09:49:08AM +0100, Tuan Hoang wrote:> Add a new launch command for direct backend, which allows specifying the > blocksize to the disks. The name is `launch_blocksize`, accompanied alias is > `run-blocksize`. > > Example: > > $ guestfish --listen -a raw.img > $ guestfish --remote -- launch_blocksize 4096NACK TBH, I don't understand why this new command is needed. A considerably simpler and more obvious way is to follow what the --format option does already. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Seemingly Similar Threads
- [PATCH v3 RESEND] direct, fish: add blocksize as optional argument for launch command
- Re: [RFC] lib: allow to specify physical/logical block size for disks
- [RFC] lib: allow to specify physical/logical block size for disks
- [PATCH v2] lib: add support for disks with 4096 bytes sector size
- [PATCH] lib: allow to specify physical/logical block size for disks