diff mbox

[2/2] btrfs-progs: use function is_block_device() instead

Message ID 1433139918-820-2-git-send-email-anand.jain@oracle.com (mailing list archive)
State Accepted
Headers show

Commit Message

Anand Jain June 1, 2015, 6:25 a.m. UTC
Here the delete code as below, is trying to check if the provided device
is a block device, there is a function for it. use it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-replace.c | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)

Comments

David Sterba June 2, 2015, 3:17 p.m. UTC | #1
On Mon, Jun 01, 2015 at 02:25:18PM +0800, Anand Jain wrote:
> Here the delete code as below, is trying to check if the provided device
> is a block device, there is a function for it. use it.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-replace.c b/cmds-replace.c
index 0787ce3..e6bc27e 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -120,14 +120,12 @@  static int cmd_start_replace(int argc, char **argv)
 	int ret;
 	int c;
 	int fdmnt = -1;
-	int fdsrcdev = -1;
 	int fddstdev = -1;
 	char *path;
 	char *srcdev;
 	char *dstdev = NULL;
 	int avoid_reading_from_srcdev = 0;
 	int force_using_targetdev = 0;
-	struct stat st;
 	u64 dstdev_block_count;
 	int do_not_background = 0;
 	int mixed = 0;
@@ -214,28 +212,9 @@  static int cmd_start_replace(int argc, char **argv)
 
 	if (is_numerical(srcdev)) {
 		start_args.start.srcdevid = arg_strtou64(srcdev);
-	} else {
-		fdsrcdev = open(srcdev, O_RDWR);
-		if (fdsrcdev < 0) {
-			fprintf(stderr, "Error: Unable to open device '%s'\n",
-				srcdev);
-			fprintf(stderr, "\tTry using the devid instead of the path\n");
-			goto leave_with_error;
-		}
-		ret = fstat(fdsrcdev, &st);
-		if (ret) {
-			fprintf(stderr, "Error: Unable to stat '%s'\n", srcdev);
-			goto leave_with_error;
-		}
-		if (!S_ISBLK(st.st_mode)) {
-			fprintf(stderr, "Error: '%s' is not a block device\n",
-				srcdev);
-			goto leave_with_error;
-		}
+	} else if (is_block_device(srcdev)) {
 		strncpy((char *)start_args.start.srcdev_name, srcdev,
 			BTRFS_DEVICE_PATH_NAME_MAX);
-		close(fdsrcdev);
-		fdsrcdev = -1;
 		start_args.start.srcdevid = 0;
 	}
 
@@ -308,8 +287,6 @@  leave_with_error:
 		free(dstdev);
 	if (fdmnt != -1)
 		close(fdmnt);
-	if (fdsrcdev != -1)
-		close(fdsrcdev);
 	if (fddstdev != -1)
 		close(fddstdev);
 	return 1;