From: Ryota Ozaki <ozaki.ryota@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/3] qemu-nbd: Fix coding style
Date: Mon, 29 Mar 2010 02:07:10 +0900 [thread overview]
Message-ID: <1269796032-9166-1-git-send-email-ozaki.ryota@gmail.com> (raw)
Follow "Every indented statement is braced; even if the block
contains just one statement." described in CODING_STYLE.
Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
---
qemu-nbd.c | 60 ++++++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 40 insertions(+), 20 deletions(-)
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 6d854d3..00b8896 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -113,8 +113,9 @@ static int find_partition(BlockDriverState *bs, int partition,
int i;
int ext_partnum = 4;
- if (bdrv_read(bs, 0, data, 1))
+ if (bdrv_read(bs, 0, data, 1)) {
errx(EXIT_FAILURE, "error while reading");
+ }
if (data[510] != 0x55 || data[511] != 0xaa) {
errno = -EINVAL;
@@ -124,21 +125,24 @@ static int find_partition(BlockDriverState *bs, int partition,
for (i = 0; i < 4; i++) {
read_partition(&data[446 + 16 * i], &mbr[i]);
- if (!mbr[i].nb_sectors_abs)
+ if (!mbr[i].nb_sectors_abs) {
continue;
+ }
if (mbr[i].system == 0xF || mbr[i].system == 0x5) {
struct partition_record ext[4];
uint8_t data1[512];
int j;
- if (bdrv_read(bs, mbr[i].start_sector_abs, data1, 1))
+ if (bdrv_read(bs, mbr[i].start_sector_abs, data1, 1)) {
errx(EXIT_FAILURE, "error while reading");
+ }
for (j = 0; j < 4; j++) {
read_partition(&data1[446 + 16 * j], &ext[j]);
- if (!ext[j].nb_sectors_abs)
+ if (!ext[j].nb_sectors_abs) {
continue;
+ }
if ((ext_partnum + j + 1) == partition) {
*offset = (uint64_t)ext[j].start_sector_abs << 9;
@@ -169,8 +173,9 @@ static void show_parts(const char *device)
* modprobe nbd max_part=63
*/
nbd = open(device, O_RDWR);
- if (nbd != -1)
+ if (nbd != -1) {
close(nbd);
+ }
exit(0);
}
}
@@ -262,15 +267,18 @@ int main(int argc, char **argv)
break;
case 'P':
partition = strtol(optarg, &end, 0);
- if (*end)
+ if (*end) {
errx(EXIT_FAILURE, "Invalid partition `%s'", optarg);
- if (partition < 1 || partition > 8)
+ }
+ if (partition < 1 || partition > 8) {
errx(EXIT_FAILURE, "Invalid partition %d", partition);
+ }
break;
case 'k':
socket = optarg;
- if (socket[0] != '/')
+ if (socket[0] != '/') {
errx(EXIT_FAILURE, "socket path must be absolute\n");
+ }
break;
case 'd':
disconnect = true;
@@ -315,8 +323,9 @@ int main(int argc, char **argv)
if (disconnect) {
fd = open(argv[optind], O_RDWR);
- if (fd == -1)
+ if (fd == -1) {
errx(EXIT_FAILURE, "Cannot open %s", argv[optind]);
+ }
nbd_disconnect(fd);
@@ -330,17 +339,20 @@ int main(int argc, char **argv)
bdrv_init();
bs = bdrv_new("hda");
- if (bs == NULL)
+ if (bs == NULL) {
return 1;
+ }
- if (bdrv_open(bs, argv[optind], flags) < 0)
+ if (bdrv_open(bs, argv[optind], flags) < 0) {
return 1;
+ }
fd_size = bs->total_sectors * 512;
if (partition != -1 &&
- find_partition(bs, partition, &dev_offset, &fd_size))
+ find_partition(bs, partition, &dev_offset, &fd_size)) {
errx(EXIT_FAILURE, "Could not find partition %d", partition);
+ }
if (device) {
pid_t pid;
@@ -360,8 +372,9 @@ int main(int argc, char **argv)
}
pid = fork();
- if (pid < 0)
+ if (pid < 0) {
return 1;
+ }
if (pid != 0) {
off_t size;
size_t blocksize;
@@ -372,8 +385,9 @@ int main(int argc, char **argv)
do {
sock = unix_socket_outgoing(socket);
if (sock == -1) {
- if (errno != ENOENT && errno != ECONNREFUSED)
+ if (errno != ENOENT && errno != ECONNREFUSED) {
goto out;
+ }
sleep(1); /* wait children */
}
} while (sock == -1);
@@ -422,14 +436,16 @@ int main(int argc, char **argv)
sharing_fds[0] = tcp_socket_incoming(bindto, port);
}
- if (sharing_fds[0] == -1)
+ if (sharing_fds[0] == -1) {
return 1;
+ }
max_fd = sharing_fds[0];
nb_fds++;
data = qemu_memalign(512, NBD_BUFFER_SIZE);
- if (data == NULL)
+ if (data == NULL) {
errx(EXIT_FAILURE, "Cannot allocate data buffer");
+ }
do {
@@ -438,11 +454,13 @@ int main(int argc, char **argv)
FD_SET(sharing_fds[i], &fds);
ret = select(max_fd + 1, &fds, NULL, NULL, NULL);
- if (ret == -1)
+ if (ret == -1) {
break;
+ }
- if (FD_ISSET(sharing_fds[0], &fds))
+ if (FD_ISSET(sharing_fds[0], &fds)) {
ret--;
+ }
for (i = 1; i < nb_fds && ret; i++) {
if (FD_ISSET(sharing_fds[i], &fds)) {
if (nbd_trip(bs, sharing_fds[i], fd_size, dev_offset,
@@ -463,8 +481,9 @@ int main(int argc, char **argv)
&addr_len);
if (sharing_fds[nb_fds] != -1 &&
nbd_negotiate(sharing_fds[nb_fds], fd_size) != -1) {
- if (sharing_fds[nb_fds] > max_fd)
+ if (sharing_fds[nb_fds] > max_fd) {
max_fd = sharing_fds[nb_fds];
+ }
nb_fds++;
}
}
@@ -475,8 +494,9 @@ int main(int argc, char **argv)
close(sharing_fds[0]);
bdrv_close(bs);
qemu_free(sharing_fds);
- if (socket)
+ if (socket) {
unlink(socket);
+ }
return 0;
}
--
1.6.5.2
next reply other threads:[~2010-03-28 17:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-28 17:07 Ryota Ozaki [this message]
2010-03-28 17:07 ` [Qemu-devel] [PATCH 2/3] qemu-nbd: Extend read-only option to nbd device file Ryota Ozaki
2010-03-29 10:54 ` Kevin Wolf
2010-05-02 21:51 ` Ryota Ozaki
2010-03-28 17:07 ` [Qemu-devel] [PATCH 3/3] qemu-nbd: Improve error reporting Ryota Ozaki
2010-03-29 11:03 ` Kevin Wolf
2010-05-02 21:52 ` Ryota Ozaki
2010-05-03 17:01 ` Anthony Liguori
2010-05-04 7:29 ` Kevin Wolf
2010-03-29 10:44 ` [Qemu-devel] [PATCH 1/3] qemu-nbd: Fix coding style Kevin Wolf
2010-05-02 21:50 ` Ryota Ozaki
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=1269796032-9166-1-git-send-email-ozaki.ryota@gmail.com \
--to=ozaki.ryota@gmail.com \
--cc=qemu-devel@nongnu.org \
/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).