From: Chunyan Liu <cyliu@suse.com>
To: stefanha@gmail.com
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v4 3/3] Add -f option to qemu-nbd
Date: Fri, 2 Dec 2011 23:27:56 +0800 [thread overview]
Message-ID: <1322839676-7559-3-git-send-email-cyliu@suse.com> (raw)
In-Reply-To: <1322839676-7559-1-git-send-email-cyliu@suse.com>
Add -f option to qemu-nbd so that it can find a free nbd device and connect
disk.img to that device.
Changes to v3:
a. According to Stefan's suggestion, loop over /dev/nbd%d to do "qemu-nbd -f
disk.img", if fails, try next device.
b. syntax "qemu-nbd -f disk.img" only
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
qemu-nbd.c | 25 ++++++++++++++++++++++---
1 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 83ae30f..431373d 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -400,7 +400,7 @@ static int nbd_setup(void)
int main(int argc, char **argv)
{
- const char *sopt = "hVb:o:p:rsnP:c:dvk:e:t";
+ const char *sopt = "hVb:o:p:rsnP:c:dvk:e:tf";
struct option lopt[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'V' },
@@ -417,12 +417,14 @@ int main(int argc, char **argv)
{ "shared", 1, NULL, 'e' },
{ "persistent", 0, NULL, 't' },
{ "verbose", 0, NULL, 'v' },
+ { "find", 0, NULL, 'f' },
{ NULL, 0, NULL, 0 }
};
int ch;
int opt_ind = 0;
char *end;
int ret = 0;
+ int find = 0;
/* The client thread uses SIGTERM to interrupt the server. A signal
* handler ensures that "qemu-nbd -v -c" exits with a nice status code.
@@ -491,6 +493,9 @@ int main(int argc, char **argv)
case 'c':
device = optarg;
break;
+ case 'f':
+ find = 1;
+ break;
case 'e':
shared = strtol(optarg, &end, 0);
if (*end) {
@@ -541,7 +546,7 @@ int main(int argc, char **argv)
return 0;
}
- if (device && !verbose) {
+ if ((device || find) && !verbose) {
int stderr_fd[2];
pid_t pid;
@@ -596,7 +601,21 @@ int main(int argc, char **argv)
atexit(bdrv_close_all);
srcpath = argv[optind];
- ret = nbd_setup();
+ if (!find) {
+ ret = nbd_setup();
+ } else {
+ int max_nbd = 16;
+ int i;
+ for (i = 0; i < max_nbd; i++) {
+ if (!asprintf(&device, "/dev/nbd%d", i))
+ continue;
+ ret = nbd_setup();
+ if (ret != EXIT_SUCCESS) {
+ free(device);
+ continue;
+ }
+ }
+ }
exit(ret);
}
--
1.7.3.4
prev parent reply other threads:[~2011-12-02 15:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-02 15:27 [Qemu-devel] [PATCH v4 1/3] Update ioctl order in nbd_init() to detect EBUSY Chunyan Liu
2011-12-02 15:27 ` [Qemu-devel] [PATCH v4 2/3] Extract code to nbd_setup function to be used for many purposes Chunyan Liu
2011-12-02 16:32 ` Paolo Bonzini
2011-12-05 5:46 ` Chunyan Liu
2011-12-05 13:16 ` Stefan Hajnoczi
2011-12-06 6:56 ` Chunyan Liu
2011-12-06 7:59 ` Paolo Bonzini
2011-12-06 8:42 ` Chunyan Liu
2011-12-06 8:44 ` Paolo Bonzini
2011-12-06 9:01 ` Chunyan Liu
2011-12-07 4:23 ` Chunyan Liu
2011-12-07 9:44 ` Paolo Bonzini
2011-12-08 11:55 ` Stefan Hajnoczi
2011-12-09 8:31 ` Chunyan Liu
2011-12-09 9:36 ` Stefan Hajnoczi
2011-12-02 15:27 ` Chunyan Liu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1322839676-7559-3-git-send-email-cyliu@suse.com \
--to=cyliu@suse.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).