partx: add BLKPG_RES_PARTITION support
PATCH 2/4 partx: add BLKPG_RES_PARTITION support
Add new respart shell command and enhance partx update command to use BLKPG_RES_PARTITION to resize an existing partition while it is in use.
--- partx/Makefile.am | 4 ++-- partx/partx.c | 9 +++++++++ partx/partx.h | 19 +++++++++++++++++++ partx/respart.8 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ partx/respart.c | 31 +++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 partx/respart.8 create mode 100644 partx/respart.c
partx/Makefile.am +2 -2
@@ -1,7 +1,7 @@ include $(top_srcdir)/config/include-Makefile.am -usrsbin_exec_PROGRAMS = addpart delpart -dist_man_MANS = addpart.8 delpart.8 +usrsbin_exec_PROGRAMS = addpart delpart respart +dist_man_MANS = addpart.8 delpart.8 respart.8 usrsbin_exec_PROGRAMS += partx partx_SOURCES = partx.c partx.h \
partx/partx.c +9 -0
@@ -467,6 +467,15 @@ static int upd_parts(int fd, const char *device, dev_t devno, {if (i < nparts) i++; +if (err ==-1 && errno ==EBUSY ) + { +/* try to resize */ + err =partx_res_partition (fd, n, start, size); +if (verbose) +printf (_ ("%s: partition #%d resized\n" ), device, n); +if (err ==0 ) +continue ; + }if (err ==0 &&partx_add_partition (fd, n, start, size) ==0 ) {if (verbose)printf (_ ("%s: partition #%d added\n" ), device, n);
partx/partx.h +19 -0
@@ -41,4 +41,23 @@ static inline int partx_add_partition(int fd, int partno, return ioctl(fd, BLKPG, &a); } +static inline int partx_res_partition (int fd,int partno, +unsigned long start,unsigned long size) +{ +struct blkpg_ioctl_arg a; +struct blkpg_partition p; + + p.pno = partno; + p.start = start <<9 ; + p.length = size <<9 ; + p.devname[0 ] =0 ; + p.volname[0 ] =0 ; + a.op =BLKPG_RES_PARTITION ; + a.flags =0 ; + a.datalen =sizeof (p); + a.data = &p; + +return ioctl (fd,BLKPG , &a); +} +#endif /* UTIL_LINUX_PARTX_H */
partx/respart.8 new file +46 -0
46 lines not on this page · raw message
partx/respart.c new file +31 -0
@@ -0,0 +1,31 @@ +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> + +#include "partx.h" + +int +main (int argc,char **argv) +{ +int fd; + +if (argc !=5 ) { +fprintf (stderr, +"usage: %s diskdevice partitionnr start length\n" , + argv[0 ]); +exit (1 ); + } +if ((fd =open (argv[1 ],O_RDONLY )) <0 ) { +perror (argv[1 ]); +exit (1 ); + } + +if (partx_res_partition (fd,atoi (argv[2 ]), +atoll (argv[3 ]), +atoll (argv[4 ]))) { +perror ("BLKPG" ); +exit (1 ); + } + +return 0 ; +}
Signature · 1 line
1.7.5.4
Quoted 58 lines · Phillip Susi
Add new respart shell command and enhance partx update command to use
BLKPG_RES_PARTITIONto resize an existing partition while it is in use.Signed-off-by Phillip Susi <[email protected]>--- partx/Makefile.am | 4 ++-- partx/partx.c | 9 +++++++++ partx/partx.h | 19 +++++++++++++++++++ partx/respart.8 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ partx/respart.c | 31 +++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 partx/respart.8 create mode 100644 partx/respart.cpartx/Makefile.am +2
-2@@ -1,7 +1,7 @@ include $(top_srcdir)/config/include-Makefile.am -usrsbin_exec_PROGRAMS = addpart delpart -dist_man_MANS = addpart.8 delpart.8 +usrsbin_exec_PROGRAMS = addpart delpart respart +dist_man_MANS = addpart.8 delpart.8 respart.8 usrsbin_exec_PROGRAMS += partx partx_SOURCES = partx.c partx.h \partx/partx.c +9
-0@@ -467,6 +467,15 @@ static int upd_parts(int fd, const char *device, dev_t devno, {if (i < nparts) i++; +if (err ==-1 && errno ==EBUSY ) + { +/* try to resize */ + err =partx_res_partition (fd, n, start, size); +if (verbose) +printf (_ ("%s: partition #%d resized\n" ), device, n); +if (err ==0 ) +continue ; + }if (err ==0 &&partx_add_partition (fd, n, start, size) ==0 ) {if (verbose)printf (_ ("%s: partition #%d added\n" ), device, n);partx/partx.h +2
-0@@ -41,4 +41,23 @@ static inline int partx_add_partition(int fd, int partno,return ioctl (fd,BLKPG , &a); } +static inline int partx_res_partition (int fd,int partno, +unsigned long start,unsigned long size)
partx/partx.h static inline int partx_add_partition(int fd, int partno, · line 55
Quoted 10 lines
partx/partx.h +10
-0+{ +struct blkpg_ioctl_arg a; +struct blkpg_partition p; + + p.pno = partno; + p.start = start <<9 ; + p.length = size <<9 ; + p.devname[0 ] =0 ; + p.volname[0 ] =0 ; + a.op =BLKPG_RES_PARTITION ;
I like the idea, but we should wait until your BLKPG resize patches are accepted in mainline before applying here. Also, assuming they make it into the kernel, this patch would break partx compilation on older kernels.
- Davidlohr
Quoted 4 lines · Davidlohr Bueso
I like the idea, but we should wait until your BLKPG resize patches are accepted in mainline before applying here. Also, assuming they make it into the kernel, this patch would break partx compilation on older kernels.
Indeed. I thought that util-linux was closely enough tied to the kernel that it didn't care about building on older kernels? I put #ifdefs around the code using it in parted, but didn't think it was needed for util-linux. Easy enough to add them back if you think it's necessary.
Karel Zak
maintainerQuoted 10 lines · Phillip Susi
Quoted 4 lines · Davidlohr Bueso
I like the idea, but we should wait until your BLKPG resize patches are accepted in mainline before applying here. Also, assuming they make it into the kernel, this patch would break partx compilation on older kernels.
Indeed. I thought that util-linux was closely enough tied to the kernel that it didn't care about building on older kernels? I put #ifdefs around the code using it in parted, but didn't think it was needed for util-linux.
The command line (our API) should not depend on kernel features, so we usually use fallback definitions (see for example include/blkdev.h) in case that libc/kernel header files are too old.
Quoted 1 line
Easy enough to add them back if you think it's necessary.
This is detail ;-) I'll fix it before commit.
The more important is to have kernel part in Linus' tree...
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com