]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm/bitmap: examine-bitmap failed when bitmap is external mode
authorZhilong Liu <zlliu@suse.com>
Mon, 28 Aug 2017 09:24:27 +0000 (17:24 +0800)
committerJes Sorensen <jsorensen@fb.com>
Fri, 1 Sep 2017 15:19:58 +0000 (11:19 -0400)
--examine-bitmap: the bitmap_file_open() shouldn't omit the
regular file descriptor when the bitmap is external mode.
Such as: ./mdadm -X /mnt/3

This commit is partial revert of commit 0a6bff09d416
(mdadm/util: unify fstat checking blkdev into function)

Signed-off-by: Zhilong Liu <zlliu@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
bitmap.c

index 36536600b66ed8bf80dbe38a5baac7e61ac2fa2c..e38cb9650390235d481aeba3b3fa38b724e37910 100644 (file)
--- a/bitmap.c
+++ b/bitmap.c
@@ -183,6 +183,7 @@ static int
 bitmap_file_open(char *filename, struct supertype **stp, int node_num)
 {
        int fd;
+       struct stat stb;
        struct supertype *st = *stp;
 
        fd = open(filename, O_RDONLY|O_DIRECT);
@@ -192,7 +193,12 @@ bitmap_file_open(char *filename, struct supertype **stp, int node_num)
                return -1;
        }
 
-       if (fstat_is_blkdev(fd, filename, NULL)) {
+       if (fstat(fd, &stb) < 0) {
+               pr_err("fstat failed for %s: %s\n", filename, strerror(errno));
+               close(fd);
+               return -1;
+       }
+       if ((stb.st_mode & S_IFMT) == S_IFBLK) {
                /* block device, so we are probably after an internal bitmap */
                if (!st)
                        st = guess_super(fd);
@@ -211,11 +217,7 @@ bitmap_file_open(char *filename, struct supertype **stp, int node_num)
                                fd = -1;
                        }
                }
-
                *stp = st;
-       } else {
-               close(fd);
-               return -1;
        }
 
        return fd;