Add configuration variables for iscsi
PATCH 1/1 Add configuration variables for iscsi
Kevin, List
This is version 2 of the patch to add configuration variables for iSCSI.
This version adds the feature to specify configuration blocks that apply to a specific target name, allowing qemu to use different settings if/when connecting one guest to multiple different iscsi targets.
This patch adds configuration variables for iSCSI to set initiator-name to use when logging in to the target, which type of header-digest to negotiate with the target and username and password for CHAP authentication.
This allows specifying a initiator-name either from the command line -iscsi initiator-name=iqn.2004-01.com.example:test
or from a configuration file included with -readconfig [iscsi]
initiator-name = iqn.2004-01.com.example:test header-digest = CRC32C|CRC32C-NONE|NONE-CRC32C|NONE
user = CHAP username
password = CHAP password
In the configuration file it is also possible to set a target specific configuratyion block using the header
[iscsi "iqn.target.name"]
When a iscsi session is initialized, it will first try to use a configuration section that matches the target name.
If no such block is found, it will fall-back to try the default [iscsi] section instead.
regards
ronnie sahlberg
PATCH 1/1 iSCSI: add configuration variables for iSCSI
This patch adds configuration variables for iSCSI to set initiator-name to use when logging in to the target, which type of header-digest to negotiate with the target and username and password for CHAP authentication.
This allows specifying a initiator-name either from the command line -iscsi initiator-name=iqn.2004-01.com.example:test
or from a configuration file included with -readconfig
[iscsi]
initiator-name = iqn.2004-01.com.example:test
header-digest = CRC32C|CRC32C-NONE|NONE-CRC32C|NONE
user = CHAP username
password = CHAP passwordIf you use several different targets, you can also configure this on a per target basis by using a group name:
[iscsi "iqn.target.name"]
...--- block/iscsi.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++---- qemu-config.c | 27 +++++++++++ qemu-doc.texi | 38 +++++++++++++++- qemu-options.hx | 16 +++++-- vl.c | 8 +++ 5 files changed, 213 insertions(+), 15 deletions(-)
block/iscsi.c +129 -10
@@ -455,6 +455,109 @@ iscsi_connect_cb(struct iscsi_context *iscsi, int status, void *command_data, } } +static int parse_chap (struct iscsi_context *iscsi,const char *target) +{ +QemuOptsList *list; +QemuOpts *opts; +const char *user =NULL ; +const char *password =NULL ; + + list =qemu_find_opts ("iscsi" ); +if (!list) { +return 0 ; + } + + opts =qemu_opts_find (list, target); +if (opts ==NULL ) { + opts =QTAILQ_FIRST (&list->head); +if (!opts) { +return 0 ; + } + } + + user =qemu_opt_get (opts,"user" ); +if (!user) { +return 0 ; + } + + password =qemu_opt_get (opts,"password" ); +if (!password) { +error_report ("CHAP username specified but no password was given" ); +return -1 ; + } + +if (iscsi_set_initiator_username_pwd (iscsi, user, password)) { +error_report ("Failed to set initiator username and password" ); +return -1 ; + } + +return 0 ; +} + +static void parse_header_digest (struct iscsi_context *iscsi,const char *target) +{ +QemuOptsList *list; +QemuOpts *opts; +const char *digest =NULL ; + + list =qemu_find_opts ("iscsi" ); +if (!list) { +return ; + } + + opts =qemu_opts_find (list, target); +if (opts ==NULL ) { + opts =QTAILQ_FIRST (&list->head); +if (!opts) { +return ; + } + } + + digest =qemu_opt_get (opts,"header-digest" ); +if (!digest) { +return ; + } + +if (!strcmp (digest,"CRC32C" )) { +iscsi_set_header_digest (iscsi,ISCSI_HEADER_DIGEST_CRC32C ); + }else if (!strcmp (digest,"NONE" )) { +iscsi_set_header_digest (iscsi,ISCSI_HEADER_DIGEST_NONE ); + }else if (!strcmp (digest,"CRC32C-NONE" )) { +iscsi_set_header_digest (iscsi,ISCSI_HEADER_DIGEST_CRC32C_NONE ); + }else if (!strcmp (digest,"NONE-CRC32C" )) { +iscsi_set_header_digest (iscsi,ISCSI_HEADER_DIGEST_NONE_CRC32C ); + }else { +error_report ("Invalid header-digest setting : %s" , digest); + } +} + +static char *parse_initiator_name (const char *target) +{ +QemuOptsList *list; +QemuOpts *opts; +const char *name =NULL ; + + list =qemu_find_opts ("iscsi" ); +if (!list) { +return g_strdup ("iqn.2008-11.org.linux-kvm" ); + } + + opts =qemu_opts_find (list, target); +if (opts ==NULL ) { + opts =QTAILQ_FIRST (&list->head); +if (!opts) { +return g_strdup ("iqn.2008-11.org.linux-kvm" ); + } + } + + name =qemu_opt_get (opts,"initiator-name" ); +if (!name) { +return g_strdup ("iqn.2008-11.org.linux-kvm" ); + } + +return g_strdup (name); +} +/* * We support iscsi url's on the form * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
@@ -465,6 +568,7 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags)struct iscsi_context *iscsi =NULL ;struct iscsi_url *iscsi_url =NULL ;struct IscsiTask task; +char *initiator_name =NULL ;int ret;if ((BDRV_SECTOR_SIZE %512 ) !=0 ) {
@@ -474,16 +578,6 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags)return -EINVAL ; } -memset (iscsilun,0 ,sizeof (IscsiLun)); - -/* Should really append the KVM name after the ':' here */ - iscsi =iscsi_create_context ("iqn.2008-11.org.linux-kvm:" ); -if (iscsi ==NULL ) { -error_report ("iSCSI: Failed to create iSCSI context." ); - ret = -ENOMEM ; - goto failed; - } - iscsi_url =iscsi_parse_full_url (iscsi, filename);if (iscsi_url ==NULL ) { error_report("Failed to parse URL : %s %s", filename,
@@ -492,6 +586,17 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) goto failed; } +memset (iscsilun,0 ,sizeof (IscsiLun)); + + initiator_name =parse_initiator_name (iscsi_url->target); + + iscsi =iscsi_create_context (initiator_name); +if (iscsi ==NULL ) { +error_report ("iSCSI: Failed to create iSCSI context." ); + ret = -ENOMEM ; + goto failed; + } +if (iscsi_set_targetname (iscsi, iscsi_url->target)) {error_report ("iSCSI: Failed to set target name." ); ret = -EINVAL ;
@@ -507,6 +612,14 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags) goto failed; } } + +/* check if we got CHAP username/password via the options */ +if (parse_chap (iscsi, iscsi_url->target) !=0 ) { +error_report ("iSCSI: Failed to set CHAP user/password" ); + ret = -EINVAL ; + goto failed; + } +if (iscsi_set_session_type (iscsi,ISCSI_SESSION_NORMAL ) !=0 ) {error_report ("iSCSI: Failed to set session type to normal." ); ret = -EINVAL ;
@@ -515,6 +628,9 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags)iscsi_set_header_digest (iscsi,ISCSI_HEADER_DIGEST_NONE_CRC32C ); +/* check if we got HEADER_DIGEST via the options */ +parse_header_digest (iscsi, iscsi_url->target); + task.iscsilun = iscsilun; task.status =0 ; task.complete =0 ;
@@ -548,6 +664,9 @@ static int iscsi_open(BlockDriverState *bs, const char *filename, int flags)return 0 ; failed: +if (initiator_name !=NULL ) { +g_free (initiator_name); + }if (iscsi_url !=NULL ) {iscsi_destroy_url (iscsi_url); }
qemu-config.c +27 -0
@@ -118,6 +118,32 @@ static QemuOptsList qemu_drive_opts = { }, }; +static QemuOptsList qemu_iscsi_opts = { + .name ="iscsi" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_iscsi_opts.head), + .desc = { + { + .name ="user" , + .type =QEMU_OPT_STRING , + .help ="username for CHAP authentication to target" , + },{ + .name ="password" , + .type =QEMU_OPT_STRING , + .help ="password for CHAP authentication to target" , + },{ + .name ="header-digest" , + .type =QEMU_OPT_STRING , + .help ="HeaderDigest setting. " +"{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}" , + },{ + .name ="initiator-name" , + .type =QEMU_OPT_STRING , + .help ="Initiator iqn name to use when connecting" , + }, + {/* end of list */ } + }, +}; +static QemuOptsList qemu_chardev_opts = { .name ="chardev" , .implied_opt_name ="backend" ,
@@ -563,6 +589,7 @@ static QemuOptsList *vm_config_groups[32] = { &qemu_option_rom_opts, &qemu_machine_opts, &qemu_boot_opts, + &qemu_iscsi_opts, NULL, };
qemu-doc.texi +37 -1
@@ -730,6 +730,41 @@ export LIBISCSI_CHAP_PASSWORD=<password> iscsi://<host>/<target-iqn-name>/<lun> @end example +Various session related parameters can be set via special options, either +in a configuration file provided via '-readconfig' or directly on the +command line. + +@example +Setting a specific initiator name to use when logging in to the target +-iscsi initiator-name=iqn.qemu.test:my-initiator +@end example + +@example +Controlling which type of header digest to negotiate with the target +-iscsi header-digest=CRC32C|CRC32C-NONE|NONE-CRC32C|NONE +@end example + +These can also be set via a configuration file +@example +[iscsi] + user = "CHAP username" + password = "CHAP password" + initiator-name = "iqn.qemu.test:my-initiator" + # header digest is one of CRC32C|CRC32C-NONE|NONE-CRC32C|NONE + header-digest = "CRC32C" +@end example + +Settign the target name allows different options for different targets +@example +[iscsi "iqn.target.name"] + user = "CHAP username" + password = "CHAP password" + initiator-name = "iqn.qemu.test:my-initiator" + # header digest is one of CRC32C|CRC32C-NONE|NONE-CRC32C|NONE + header-digest = "CRC32C" +@end example + + Howto set up a simple iSCSI target on loopback and accessing it via QEMU: @example This example shows how to set up an iSCSI target with one CDROM and one DISK
@@ -744,7 +779,8 @@ tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 2 \ -b /IMAGES/cd.iso --device-type=cd tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL -qemu-system-i386 -boot d -drive file=iscsi://127.0.0.1/iqn.qemu.test/1 \ +qemu-system-i386 -iscsi initiator-name=iqn.qemu.test:my-initiator \ + -boot d -drive file=iscsi://127.0.0.1/iqn.qemu.test/1 \ -cdrom iscsi://127.0.0.1/iqn.qemu.test/2 @end example
qemu-options.hx +12 -4
@@ -1761,24 +1761,32 @@ Syntax for specifying iSCSI LUNs is Example (without authentication): @example -qemu -cdrom iscsi://192.0.2.1/iqn.2001-04.com.example/2 \ ---drive file=iscsi://192.0.2.1/iqn.2001-04.com.example/1 +qemu -iscsi initiator-name=iqn.2001-04.com.example:my-initiator \ +-cdrom iscsi://192.0.2.1/iqn.2001-04.com.example/2 \ +-drive file=iscsi://192.0.2.1/iqn.2001-04.com.example/1 @end example Example (CHAP username/password via URL): @example -qemu --drive file=iscsi://user%password@@192.0.2.1/iqn.2001-04.com.example/1 +qemu -drive file=iscsi://user%password@@192.0.2.1/iqn.2001-04.com.example/1 @end example Example (CHAP username/password via environment variables): @example LIBISCSI_CHAP_USERNAME="user" \ LIBISCSI_CHAP_PASSWORD="password" \ -qemu --drive file=iscsi://192.0.2.1/iqn.2001-04.com.example/1 +qemu -drive file=iscsi://192.0.2.1/iqn.2001-04.com.example/1 @end example iSCSI support is an optional feature of QEMU and only available when compiled and linked against libiscsi. +ETEXI +DEF("iscsi", HAS_ARG, QEMU_OPTION_iscsi, + "-iscsi [user=user][,password=password]\n" + " [,header-digest=CRC32C|CR32C-NONE|NONE-CRC32C|NONE\n" + " [,initiator-name=iqn]\n" + " iSCSI session parameters\n", QEMU_ARCH_ALL) +STEXI @item NBD QEMU supports NBD (Network Block Devices) both using TCP protocol as well
vl.c +8 -0
@@ -2496,6 +2496,14 @@ int main(int argc, char **argv, char **envp)exit (1 ); }break ; +#ifdef CONFIG_LIBISCSI +case QEMU_OPTION_iscsi: + opts =qemu_opts_parse (qemu_find_opts ("iscsi" ), optarg,0 ); +if (!opts) { +exit (1 ); + } +break ; +#endif #ifdef CONFIG_SLIRP case QEMU_OPTION_tftp: legacy_tftp_prefix = optarg;
Signature · 1 line
1.7.3.1
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
Quoted 5 lines · Ronnie Sahlberg
This patch adds configuration variables for iSCSI to set initiator-name to use when logging in to the target, which type of header-digest to negotiate with the target and username and password for CHAP authentication.
Quoted 9 lines
This allows specifying a initiator-name either from the command line -iscsi initiator-name=iqn.2004-01.com.example:test
or from a configuration file included with -readconfig[iscsi] initiator-name = iqn.2004-01.com.example:test header-digest = CRC32C|CRC32C-NONE|NONE-CRC32C|NONE user = CHAP username password = CHAP password
Can -readconfig support reading from an inherited fd, rather than only taking a file name that qemu has to open()? That way, libvirt could create a pipe, pass in the fd with something like '-readconfig fd:nnn', then pass in the configuration data over the pipe without ever having to store the unencrypted CHAP password in an on-disk file (libvirt has mechanisms already in place for storing authentication data in a secure manner, but once libvirt has decrypted secure storage into something that qemu can consume, writing it out to a temporary file on disk defeats some of the security).
Quoted 18 lines
+++ b/qemu-doc.texi
qemu-doc.texi +13
-0@@ -730,6 +730,41 @@ export LIBISCSI_CHAP_PASSWORD=<password> iscsi://<host>/<target-iqn-name>/<lun> @end example +Various session related parameters can be set via special options, either +in a configuration file provided via '-readconfig' or directly on the +command line. + +@example +Setting a specific initiator name to use when logging in to the target +-iscsi initiator-name=iqn.qemu.test:my-initiator +@end example + +@example +Controlling which type of header digest to negotiate with the target +-iscsi header-digest=CRC32C|CRC32C-NONE|NONE-CRC32C|NONE +@end example
qemu-doc.texi export LIBISCSI_CHAP_PASSWORD=<password> · line 755
Quoted 10 lines
qemu-doc.texi +10
-0+ +These can also be set via a configuration file +@example +[iscsi] + user = "CHAP username" + password = "CHAP password" + initiator-name = "iqn.qemu.test:my-initiator" + # header digest is one of CRC32C|CRC32C-NONE|NONE-CRC32C|NONE + header-digest = "CRC32C" +@end example
Can you give an actual command line that uses -readconfig, as part of your example?
Review export LIBISCSI_CHAP_PASSWORD=<password> · line 757
Quoted 2 lines
(quoted diff) +2
-0+ +Settign the target name allows different options for different targets
s/Settign/Setting/
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
Quoted 4 lines · Eric Blake
Can -readconfig support reading from an inherited fd, rather than only taking a file name that qemu has to
open()?
...
Quoted 4 lines
Can you give an actual command line that uses -readconfig, as part of your example?
Thanks for the review Eric.
I will update the patch with an example using -readconfig and fix the typo.
Yes, -readconfig can read from a pipe() and it can also read from an arbitrary file descriptor.
Reading from a pipe :
cat iscsi.conf | ./x86_64-softmmu/qemu-system-x86_64 -enable-kvm -display vnc=127.0.0.1:0 -drive file=iscsi://127.0.0.1/iqn.ronnie.test/1 -readconfig /proc/self/fd/0
Read from an arbitrary filedescriptor inherited from the parent process :
9<iscsi.conf ./x86_64-softmmu/qemu-system-x86_64 -enable-kvm -display vnc=127.0.0.1:0 -drive file=iscsi://127.0.0.1/iqn.ronnie.test/1 -readconfig /proc/self/fd/9
The second example shows how you can have qemu read from an arbitrary descriptor that is inherited from the parent process (the shell in this case)
I imagine you would pipe() then fork() and pass the read side of your pipe to qemu here ?
If this works well or at least in some acceptable form it might be useful for other users needing to pass sensitive config data into QEMU too?
regards
ronnie sahlberg
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
Quoted 4 lines · ronnie sahlberg
Read from an arbitrary filedescriptor inherited from the parent process :
9<iscsi.conf ./x86_64-softmmu/qemu-system-x86_64 -enable-kvm -display vnc=127.0.0.1:0 -drive file=iscsi://127.0.0.1/iqn.ronnie.test/1 -readconfig/proc/self/fd/9
That requires the existence of procfs, which is not portable (although it does work on Linux). I'd rather see:
-readconfig fd:9
which matches things for -incoming; that is, if -readconfig starts with '/' or '.', it is a filename; otherwise, it is a protocol:value designation, where we recognize at least the fd: protocol where a value is the incoming fd, but we could also recognize things like exec:
protocol which is an arbitrary command to use via popen.
Quoted 2 lines
I imagine you would
pipe()thenfork()and pass the read side of your pipe to qemu here ?
Yes, the idea is that libvirt would rather pipe() and then pass the read size fd to qemu, so that libvirt's handling of the decrypted secret information is only ever passed over the pipe and not stored on disk.
Quoted 3 lines
If this works well or at least in some acceptable form it might be useful for other users needing to pass sensitive config data into QEMU too?
Yes, the fd: notation of -incoming should be reusable in multiple contexsts, including any other location where sensitive information must be passed in.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
Fair enough.
I will send a separate tiny patch to add 'fd:<n>' support to specify to qemu to -readconfig from a preexisting filedescriptor.
Other protocols like 'exec:' can easily be added later as needed.
regards
ronnie sahlberg
Quoted 36 lines · Eric Blake
Quoted 4 lines · ronnie sahlberg
Read from an arbitrary filedescriptor inherited from the parent process :
9<iscsi.conf ./x86_64-softmmu/qemu-system-x86_64 -enable-kvm -display vnc=127.0.0.1:0 -drive file=iscsi://127.0.0.1/iqn.ronnie.test/1 -readconfig/proc/self/fd/9That requires the existence of procfs, which is not portable (although it does work on Linux). I'd rather see:
-readconfig fd:9
which matches things for -incoming; that is, if -readconfig starts with '/' or '.', it is a filename; otherwise, it is a protocol:value designation, where we recognize at least the fd: protocol where a value is the incoming fd, but we could also recognize things like exec:
protocol which is an arbitrary command to use via popen.Quoted 2 lines
I imagine you would
pipe()thenfork()and pass the read side of your pipe to qemu here ?Yes, the idea is that libvirt would rather
pipe()and then pass the read size fd to qemu, so that libvirt's handling of the decrypted secret information is only ever passed over the pipe and not stored on disk.Quoted 3 lines
If this works well or at least in some acceptable form it might be useful for other users needing to pass sensitive config data into QEMU too?
Yes, the fd: notation of -incoming should be reusable in multiple contexsts, including any other location where sensitive information must be passed in.
--
Eric Blake [email protected] +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
In reply to Eric BlakeAm 25.01.2012 16:57, schrieb Eric Blake:
Quoted 9 lines · ronnie sahlberg
Quoted 4 lines
Read from an arbitrary filedescriptor inherited from the parent process :
9<iscsi.conf ./x86_64-softmmu/qemu-system-x86_64 -enable-kvm -display vnc=127.0.0.1:0 -drive file=iscsi://127.0.0.1/iqn.ronnie.test/1 -readconfig/proc/self/fd/9That requires the existence of procfs, which is not portable (although it does work on Linux). I'd rather see:
Quoted 7 lines
-readconfig fd:9
which matches things for -incoming; that is, if -readconfig starts with '/' or '.', it is a filename; otherwise, it is a protocol:value designation, where we recognize at least the fd: protocol where a value is the incoming fd, but we could also recognize things like exec:
protocol which is an arbitrary command to use via popen.
Magic prefixes like this have one big problem: What if someone has a config file called "fd:9"? We have the very same problem with protocols in the block layer and while in the general case it's a convenient syntax, we've come to hate it in cases where it misinterprets things.
Kevin
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
Kevin,
Collissions are bad, but what about
IF ! STRNCMP (filename, "/proc/self/fd/", 14) THEN
fopen(filename, "r")
ELSE
fdopen(atoi(filename+14), "r")
FI
modulo better validation for the atio() arguments.
Probability of anyone using "/proc/self/fd/" as a prefix for normal files is very small.
Small enough it will be justifiable to say "do that and you are on your own". ?
regards
ronnie sahlberg
Quoted 24 lines · Kevin Wolf
Am 25.01.2012 16:57, schrieb Eric Blake:
Quoted 9 lines · ronnie sahlberg
Quoted 4 lines
Read from an arbitra filedescriptor inherited from the parent process :
9<iscsi.conf ./x86_64-softmmu/qemu-system-x86_64 -enable-kvm -display vnc=127.0.0.1:0 -drive file=iscsi://127.0.0.1/iqn.ronnie.test/1 -readconfig/proc/self/fd/9That requires the existence of procfs, which is not portable (although it does work on Linux). I'd rather see:
Quoted 7 lines
-readconfig fd:9
which matches things for -incoming; that is, if -readconfig starts with '/' or '.', it is a filename; otherwise, it is a protocol:value designation, where we recognize at least the fd: protocol where a value is the incoming fd, but we could also recognize things like exec:
protocol which is an arbitrary command to use via popen.Magic prefixes like this have one big problem: What if someone has a config file called "fd:9"? We have the very same problem with protocols in the block layer and while in the general case it's a convenient syntax, we've come to hate it in cases where it misinterprets things.
Kevin
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
Am 26.01.2012 10:18, schrieb ronnie sahlberg:
Quoted 8 lines
Kevin,
Collissions are bad, but what about
IF ! STRNCMP (filename, "
/proc/self/fd/", 14) THEN
fopen(filename, "r")
ELSEfdopen(atoi(filename+14), "r")
Quoted 8 lines
FI
modulo better validation for the
atio()arguments.Probability of anyone using "
/proc/self/fd/" as a prefix for normal files is very small.
Small enough it will be justifiable to say "do that and you are on your own". ?
Interesting idea. Maybe that could work.
Kevin
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
Ok so what about this
You use a filename starting with "/proc/self/fd/" and you dont have a proc filesystem mounted? you are on your own!
regards
ronnie sahlberg
Quoted 14 lines · Kevin Wolf
Am 26.01.2012 10:18, schrieb ronnie sahlberg:
Quoted 13 lines
Kevin,
Collissions are bad, but what about
IF ! STRNCMP (filename, "
/proc/self/fd/", 14) THENfopen(filename, "r")
ELSE
fdopen(atoi(filename+14), "r")
FImodulo better validation for the
atio()arguments.
Quoted 7 lines
Quoted 3 lines
Probability of anyone using "
/proc/self/fd/" as a prefix for normal files is very small.
Small enough it will be justifiable to say "do that and you are on your own". ?Interesting idea. Maybe that could work.
Kevin
From 65aa496d77b839f1c48745fc5545e3e6772f724c Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <[email protected]>
Date: Thu, 26 Jan 2012 20:47:40 +1100
Subject: [PATCH] READCONFIG: make /proc/self/fd/ a magic prefix to refer to a specific
filedesriptor inherited from the parent.
--- qemu-config.c | 16 ++++++++++++++-- qemu-options.hx | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-)
qemu-config.c +14 -2
@@ -770,8 +770,20 @@ out:int qemu_read_config_file (const char *filename) { -FILE *f =fopen (filename,"r" ); -int ret; +FILE *f; +int ret, fd; +char *ptr =NULL ; + +if (strncmp (filename,"/proc/self/fd/" ,14 )) { + f =fopen (filename,"r" ); + }else { + errno =0 ; + fd =strtol (filename +14 , &ptr,10 ); +if (errno !=0 || ptr == filename +14 || *ptr !='\0' ) { +return -EINVAL ; + } + f =fdopen (fd,"r" ); + }if (f ==NULL ) {return -errno;
qemu-options.hx +2 -1
@@ -2577,7 +2577,8 @@ DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, STEXI @item -readconfig @var{file} @findex -readconfig -Read device configuration from @var{file}. +Read device configuration from @var{file}. Use '/proc/self/fd/<n>' as filename +to read from an existing, inherited, filedesriptor. ETEXI DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, "-writeconfig <file>\n"
Signature · 1 line
1.7.3.1
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
Quoted 4 lines · ronnie sahlberg
Ok so what about this
You use a filename starting with "
/proc/self/fd/" and you dont have a proc filesystem mounted? you are on your own!
No you're not:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
IF ! STRNCMP (filename, "
/proc/self/fd/", 14) THEN
fopen(filename, "r")
ELSEfdopen(atoi(filename+14), "r")FI
If the filename starts with /proc/self/fd/, qemu will not try to open that file but parse the rest of the string as a filedescriptor number.
/mjt
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
Quoted 5 lines · Michael Tokarev
Quoted 4 lines · ronnie sahlberg
Ok so what about this
You use a filename starting with "
/proc/self/fd/" and you dont have a proc filesystem mounted? you are on your own!
BTW, usual idiom (which was implemented in gawk for example) is to use /dev/fd/N here, not /proc/self/fd/N which is really linux-specific. Linux traditionally had that symlinked to /proc/self/fd, so it should work as is on linux too. (I think /dev/fd/N is more widely used than /proc/self/fd -- solaris? *bsd?)
/mjt
Quoted 14 lines
No you're not:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
IF ! STRNCMP (filename, "
/proc/self/fd/", 14) THENfopen(filename, "r")
ELSEfdopen(atoi(filename+14), "r")
FIIf the filename starts with
/proc/self/fd/, qemu will not try to open that file but parse the rest of the string as a filedescriptor number./mjt
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
In reply to ronnie sahlbergQuoted 4 lines · ronnie sahlberg
Ok so what about this
You use a filename starting with "
/proc/self/fd/" and you dont have a proc filesystem mounted? you are on your own!
IMHO that would be bad - turning what could easily be a platform neutral feature into one that only works on Linux, just to avoid dealing with command line parsing properly.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH] iSCSI: add configuration variables for iSCSI
In reply to Kevin WolfOn 26.01.2012 13:08, Kevin Wolf wrote:
[]
Quoted 3 lines
Quoted 1 line
-readconfig fd:9
Magic prefixes like this have one big problem: What if someone has a config file called "fd:9"? We have the very same problem with protocols
-readconfig ./fd:9
does the trick.
Quoted 2 lines
in the block layer and while in the general case it's a convenient syntax, we've come to hate it in cases where it misinterprets things.
/mjt