Commit 1e594bb2 authored by NeilBrown's avatar NeilBrown

md: tidy up set_bitmap_file

1/ delay setting mddev->bitmap_info.file until 'f' looks
   usable, so we don't have to unset it.
2/ Don't allow bitmap file to be set if bitmap_info.file
   is already set.
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent f4ad3d38
...@@ -5851,22 +5851,24 @@ static int set_bitmap_file(struct mddev *mddev, int fd) ...@@ -5851,22 +5851,24 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
if (fd >= 0) { if (fd >= 0) {
struct inode *inode; struct inode *inode;
if (mddev->bitmap) struct file *f;
if (mddev->bitmap || mddev->bitmap_info.file)
return -EEXIST; /* cannot add when bitmap is present */ return -EEXIST; /* cannot add when bitmap is present */
mddev->bitmap_info.file = fget(fd); f = fget(fd);
if (mddev->bitmap_info.file == NULL) { if (f == NULL) {
printk(KERN_ERR "%s: error: failed to get bitmap file\n", printk(KERN_ERR "%s: error: failed to get bitmap file\n",
mdname(mddev)); mdname(mddev));
return -EBADF; return -EBADF;
} }
inode = mddev->bitmap_info.file->f_mapping->host; inode = f->f_mapping->host;
if (!S_ISREG(inode->i_mode)) { if (!S_ISREG(inode->i_mode)) {
printk(KERN_ERR "%s: error: bitmap file must be a regular file\n", printk(KERN_ERR "%s: error: bitmap file must be a regular file\n",
mdname(mddev)); mdname(mddev));
err = -EBADF; err = -EBADF;
} else if (!(mddev->bitmap_info.file->f_mode & FMODE_WRITE)) { } else if (!(f->f_mode & FMODE_WRITE)) {
printk(KERN_ERR "%s: error: bitmap file must open for write\n", printk(KERN_ERR "%s: error: bitmap file must open for write\n",
mdname(mddev)); mdname(mddev));
err = -EBADF; err = -EBADF;
...@@ -5876,10 +5878,10 @@ static int set_bitmap_file(struct mddev *mddev, int fd) ...@@ -5876,10 +5878,10 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
err = -EBUSY; err = -EBUSY;
} }
if (err) { if (err) {
fput(mddev->bitmap_info.file); fput(f);
mddev->bitmap_info.file = NULL;
return err; return err;
} }
mddev->bitmap_info.file = f;
mddev->bitmap_info.offset = 0; /* file overrides offset */ mddev->bitmap_info.offset = 0; /* file overrides offset */
} else if (mddev->bitmap == NULL) } else if (mddev->bitmap == NULL)
return -ENOENT; /* cannot remove what isn't there */ return -ENOENT; /* cannot remove what isn't there */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment