From patchwork Sun Mar 28 17:07:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryota OZAKI X-Patchwork-Id: 48782 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AB939B7C33 for ; Mon, 29 Mar 2010 04:19:53 +1100 (EST) Received: from localhost ([127.0.0.1]:42167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nvw0m-0003R8-JY for incoming@patchwork.ozlabs.org; Sun, 28 Mar 2010 13:10:56 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NvvzP-0003Py-4A for qemu-devel@nongnu.org; Sun, 28 Mar 2010 13:09:31 -0400 Received: from [140.186.70.92] (port=39846 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NvvzM-0003Ob-MR for qemu-devel@nongnu.org; Sun, 28 Mar 2010 13:09:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NvvzL-0007eT-7i for qemu-devel@nongnu.org; Sun, 28 Mar 2010 13:09:28 -0400 Received: from mail-iw0-f171.google.com ([209.85.223.171]:48771) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NvvzL-0007eM-2c for qemu-devel@nongnu.org; Sun, 28 Mar 2010 13:09:27 -0400 Received: by iwn1 with SMTP id 1so6816858iwn.27 for ; Sun, 28 Mar 2010 10:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :message-id:x-mailer; bh=joJiSsRIOQ4SRd448HZBG+a3Y2D+9L6gJ9gJgjJXNrM=; b=FLNh0bSCkfTmyr4DIKk7hvqoniQV9xqrRU6Hy8JTdWNQtdSUH3FDENqUgbDTmQo88f Ix6pP9VKCjlp6/ZO3FvAmun7ttgC0kBjqTCxgNiQWVZHHWjUwj5DvW4WA0OrcCj3sGPw f5sAQWfNF1/vRIbpS9yFgAjL0pv0RGS2dDNSY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer; b=gWCxLw3oICR7lnYSfITmygFQicO8KvL2R82YPjp9R6ZTr9uZfmQRKTHBEaBoQWEnPq 9YiguVvRlacOUNyFRIiIa9XF42kQem6Ri+FDdUtKieW06qec7OXSjQY0XtDvaiDSDmgs K2hnLC6rnoMjCSjtGOQz+Qt33Ki9U6+647ufc= Received: by 10.231.172.210 with SMTP id m18mr1966926ibz.21.1269796166376; Sun, 28 Mar 2010 10:09:26 -0700 (PDT) Received: from localhost.localdomain (host105.nvlab.org [122.1.115.105]) by mx.google.com with ESMTPS id cm22sm2831437ibb.11.2010.03.28.10.09.24 (version=SSLv3 cipher=RC4-MD5); Sun, 28 Mar 2010 10:09:25 -0700 (PDT) From: Ryota Ozaki To: qemu-devel@nongnu.org Date: Mon, 29 Mar 2010 02:07:10 +0900 Message-Id: <1269796032-9166-1-git-send-email-ozaki.ryota@gmail.com> X-Mailer: git-send-email 1.6.5.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 1/3] qemu-nbd: Fix coding style X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Follow "Every indented statement is braced; even if the block contains just one statement." described in CODING_STYLE. Signed-off-by: Ryota Ozaki --- 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; }