summaryrefslogtreecommitdiffstats
path: root/bitmap.c
diff options
context:
space:
mode:
authorJes Sorensen <Jes.Sorensen@redhat.com>2016-08-15 22:16:05 +0200
committerJes Sorensen <Jes.Sorensen@redhat.com>2016-08-15 22:16:05 +0200
commit9ca0de6241d0b8a2f396f06746bee50b0a5096b6 (patch)
treea11f191642150898a57a290a5f8635b551f2f83e /bitmap.c
parentsuper0: Clean up formatting in examine_super0() (diff)
downloadmdadm-9ca0de6241d0b8a2f396f06746bee50b0a5096b6.tar.xz
mdadm-9ca0de6241d0b8a2f396f06746bee50b0a5096b6.zip
bitmap: Simplify code for bitmap_file_open()
By switching to open+fstat rather than stat+open the code can be simplified and avoid duplicating the open handling. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Diffstat (limited to 'bitmap.c')
-rw-r--r--bitmap.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/bitmap.c b/bitmap.c
index 51dda8be..29c36a65 100644
--- a/bitmap.c
+++ b/bitmap.c
@@ -200,20 +200,24 @@ int bitmap_file_open(char *filename, struct supertype **stp, int node_num)
struct stat stb;
struct supertype *st = *stp;
- if (stat(filename, &stb) < 0) {
- pr_err("failed to find file %s: %s\n",
- filename, strerror(errno));
+ fd = open(filename, O_RDONLY|O_DIRECT);
+ if (fd < 0) {
+ pr_err("failed to open bitmap file %s: %s\n",
+ filename, strerror(errno));
return -1;
}
- if ((S_IFMT & stb.st_mode) == S_IFBLK) {
- fd = open(filename, O_RDONLY|O_DIRECT);
- if (fd < 0) {
- pr_err("failed to open bitmap file %s: %s\n",
- filename, strerror(errno));
- return -1;
- }
+
+ if (fstat(fd, &stb) < 0) {
+ pr_err("failed to determine bitmap file/device type: %s\n",
+ 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);
+ if (!st)
+ st = guess_super(fd);
if (!st) {
/* just look at device... */
lseek(fd, 0, 0);
@@ -231,13 +235,6 @@ int bitmap_file_open(char *filename, struct supertype **stp, int node_num)
}
*stp = st;
- } else {
- fd = open(filename, O_RDONLY|O_DIRECT);
- if (fd < 0) {
- pr_err("failed to open bitmap file %s: %s\n",
- filename, strerror(errno));
- return -1;
- }
}
return fd;