cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH RHEL5] mkfs: Handle gfs2 creation on regular files
@ 2011-08-10 15:28 Andrew Price
  2011-08-10 15:34 ` Steven Whitehouse
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Price @ 2011-08-10 15:28 UTC (permalink / raw)
  To: cluster-devel.redhat.com

mkfs.gfs2 previously exited if the target volume was a regular file.
This patch allows creation of gfs2 file systems on regular files by
removing an exiting check. It also removes the check_mount() function and
replaces it with an fstat() call after opening the file to avoid races.

This patch is based on commit 9e213f6 upstream.

rhbz#720935

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/mkfs/main_mkfs.c |   39 +++++++--------------------------------
 1 files changed, 7 insertions(+), 32 deletions(-)

diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 80126d1..35d10ea 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -295,36 +295,6 @@ static void are_you_sure(struct gfs2_sbd *sdp)
 }
 
 /**
- * check_mount - check to see if device is mounted/busy
- * @device: the device to create the filesystem on
- *
- */
-
-static void check_mount(char *device)
-{
-	struct stat st_buf;
-	int fd;
-
-	if (stat(device, &st_buf) < 0)
-		die( _("could not stat device %s\n"), device);
-	if (!S_ISBLK(st_buf.st_mode))
-		die( _("%s is not a block device\n"), device);
-
-	fd = open(device, O_RDONLY | O_NONBLOCK | O_EXCL);
-
-	if (fd < 0) {
-		if (errno == EBUSY) {
-			die( _("device %s is busy\n"), device);
-		}
-	}
-	else {
-		close(fd);
-	}
-
-	return;
-}
-
-/**
  * print_results - print out summary information
  * @sdp: the command line
  *
@@ -381,6 +351,7 @@ main_mkfs(int argc, char *argv[])
 	int rgsize_specified = 0;
 	uint64_t real_device_size;
 	unsigned char uuid[16];
+	struct stat st_buf;
 
 	memset(sdp, 0, sizeof(struct gfs2_sbd));
 	sdp->bsize = GFS2_DEFAULT_BSIZE;
@@ -400,13 +371,17 @@ main_mkfs(int argc, char *argv[])
 
 	verify_arguments(sdp);
 
-	check_mount(sdp->device_name);
-
 	sdp->device_fd = open(sdp->device_name, O_RDWR);
 	if (sdp->device_fd < 0)
 		die( _("can't open device %s: %s\n"),
 		    sdp->device_name, strerror(errno));
 
+	if (fstat(sdp->device_fd, &st_buf) < 0) {
+		fprintf(stderr, _("could not fstat fd %d: %s\n"),
+			sdp->device_fd, strerror(errno));
+		exit(-1);
+	}
+
 	if (!sdp->override)
 		are_you_sure(sdp);
 
-- 
1.7.4.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Cluster-devel] [PATCH RHEL5] mkfs: Handle gfs2 creation on regular files
  2011-08-10 15:28 [Cluster-devel] [PATCH RHEL5] mkfs: Handle gfs2 creation on regular files Andrew Price
@ 2011-08-10 15:34 ` Steven Whitehouse
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Whitehouse @ 2011-08-10 15:34 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Hi,

Looks good to me. ACK,

Steve.

On Wed, 2011-08-10 at 16:28 +0100, Andrew Price wrote:
> mkfs.gfs2 previously exited if the target volume was a regular file.
> This patch allows creation of gfs2 file systems on regular files by
> removing an exiting check. It also removes the check_mount() function and
> replaces it with an fstat() call after opening the file to avoid races.
> 
> This patch is based on commit 9e213f6 upstream.
> 
> rhbz#720935
> 
> Signed-off-by: Andrew Price <anprice@redhat.com>
> ---
>  gfs2/mkfs/main_mkfs.c |   39 +++++++--------------------------------
>  1 files changed, 7 insertions(+), 32 deletions(-)
> 
> diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
> index 80126d1..35d10ea 100644
> --- a/gfs2/mkfs/main_mkfs.c
> +++ b/gfs2/mkfs/main_mkfs.c
> @@ -295,36 +295,6 @@ static void are_you_sure(struct gfs2_sbd *sdp)
>  }
>  
>  /**
> - * check_mount - check to see if device is mounted/busy
> - * @device: the device to create the filesystem on
> - *
> - */
> -
> -static void check_mount(char *device)
> -{
> -	struct stat st_buf;
> -	int fd;
> -
> -	if (stat(device, &st_buf) < 0)
> -		die( _("could not stat device %s\n"), device);
> -	if (!S_ISBLK(st_buf.st_mode))
> -		die( _("%s is not a block device\n"), device);
> -
> -	fd = open(device, O_RDONLY | O_NONBLOCK | O_EXCL);
> -
> -	if (fd < 0) {
> -		if (errno == EBUSY) {
> -			die( _("device %s is busy\n"), device);
> -		}
> -	}
> -	else {
> -		close(fd);
> -	}
> -
> -	return;
> -}
> -
> -/**
>   * print_results - print out summary information
>   * @sdp: the command line
>   *
> @@ -381,6 +351,7 @@ main_mkfs(int argc, char *argv[])
>  	int rgsize_specified = 0;
>  	uint64_t real_device_size;
>  	unsigned char uuid[16];
> +	struct stat st_buf;
>  
>  	memset(sdp, 0, sizeof(struct gfs2_sbd));
>  	sdp->bsize = GFS2_DEFAULT_BSIZE;
> @@ -400,13 +371,17 @@ main_mkfs(int argc, char *argv[])
>  
>  	verify_arguments(sdp);
>  
> -	check_mount(sdp->device_name);
> -
>  	sdp->device_fd = open(sdp->device_name, O_RDWR);
>  	if (sdp->device_fd < 0)
>  		die( _("can't open device %s: %s\n"),
>  		    sdp->device_name, strerror(errno));
>  
> +	if (fstat(sdp->device_fd, &st_buf) < 0) {
> +		fprintf(stderr, _("could not fstat fd %d: %s\n"),
> +			sdp->device_fd, strerror(errno));
> +		exit(-1);
> +	}
> +
>  	if (!sdp->override)
>  		are_you_sure(sdp);
>  




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-10 15:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-10 15:28 [Cluster-devel] [PATCH RHEL5] mkfs: Handle gfs2 creation on regular files Andrew Price
2011-08-10 15:34 ` Steven Whitehouse

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).