qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/3] qemu-nbd: Fix coding style


From: Ryota Ozaki
Subject: [Qemu-devel] [PATCH 1/3] qemu-nbd: Fix coding style
Date: Mon, 29 Mar 2010 02:07:10 +0900

Follow "Every indented statement is braced; even if the block
contains just one statement." described in CODING_STYLE.

Signed-off-by: Ryota Ozaki <address@hidden>
---
 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]