From patchwork Thu Sep 1 21:55:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Goyal X-Patchwork-Id: 1120692 Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p81LxJrE009880 for ; Thu, 1 Sep 2011 21:59:40 GMT Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p81LtdUq023894; Thu, 1 Sep 2011 17:55:40 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p81LtbCt027585 for ; Thu, 1 Sep 2011 17:55:37 -0400 Received: from machine.usersys.redhat.com (vpn-11-19.rdu.redhat.com [10.11.11.19]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p81LtVFK032147; Thu, 1 Sep 2011 17:55:31 -0400 Received: by machine.usersys.redhat.com (Postfix, from userid 10451) id 55925201FF; Thu, 1 Sep 2011 17:55:31 -0400 (EDT) From: Vivek Goyal To: linux-kernel@vger.kernel.org, jaxboe@fusionio.com, dm-devel@redhat.com Date: Thu, 1 Sep 2011 17:55:28 -0400 Message-Id: <1314914128-3171-3-git-send-email-vgoyal@redhat.com> In-Reply-To: <1314914128-3171-1-git-send-email-vgoyal@redhat.com> References: <1314914128-3171-1-git-send-email-vgoyal@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: kzak@redhat.com, vgoyal@redhat.com Subject: [dm-devel] [PATCH 1/1] extendpart: A new command line to extend an existing partition X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 01 Sep 2011 21:59:40 +0000 (UTC) This is along the lines of addpart and delpart to modify in kernel partition table and does not touch the ondisk data structures. Signed-off-by: Vivek Goyal --- partx/Makefile.am | 2 +- partx/extendpart.c | 29 +++++++++++++++++++++++++++++ partx/partx.h | 20 ++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletions(-) create mode 100644 partx/extendpart.c diff --git a/partx/Makefile.am b/partx/Makefile.am index 6a72942..f84126d 100644 --- a/partx/Makefile.am +++ b/partx/Makefile.am @@ -1,6 +1,6 @@ include $(top_srcdir)/config/include-Makefile.am -usrsbin_exec_PROGRAMS = addpart delpart +usrsbin_exec_PROGRAMS = addpart delpart extendpart dist_man_MANS = addpart.8 delpart.8 usrsbin_exec_PROGRAMS += partx diff --git a/partx/extendpart.c b/partx/extendpart.c new file mode 100644 index 0000000..a9577c2 --- /dev/null +++ b/partx/extendpart.c @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "partx.h" + +int +main(int argc, char **argv) +{ + int fd; + + if (argc != 4) { + fprintf(stderr, + "usage: %s diskdevice partitionnr size\n", + argv[0]); + exit(1); + } + if ((fd = open(argv[1], O_RDONLY)) < 0) { + perror(argv[1]); + exit(1); + } + + if (partx_extend_partition(fd, atoi(argv[2]), atoll(argv[3]))) { + perror("BLKPG"); + exit(1); + } + + return 0; +} diff --git a/partx/partx.h b/partx/partx.h index b40fa8f..1acbff9 100644 --- a/partx/partx.h +++ b/partx/partx.h @@ -41,4 +41,24 @@ static inline int partx_add_partition(int fd, int partno, return ioctl(fd, BLKPG, &a); } +static inline int partx_extend_partition(int fd, int partno, + unsigned long size) +{ + struct blkpg_ioctl_arg a; + struct blkpg_partition p; + + p.pno = partno; + /* p.start is unused for extend operation */ + p.start = 0; + p.length = size << 9; + p.devname[0] = 0; + p.volname[0] = 0; + a.op = BLKPG_EXTEND_PARTITION; + a.flags = 0; + a.datalen = sizeof(p); + a.data = &p; + + return ioctl(fd, BLKPG, &a); +} + #endif /* UTIL_LINUX_PARTX_H */