Commit 2fe4ffc3 authored by Li Nan's avatar Li Nan Committed by Song Liu

md: merge the check of capabilities into md_ioctl_valid()

There is no functional change. Just to make code cleaner.
Signed-off-by: default avatarLi Nan <linan122@huawei.com>
Reviewed-by: default avatarYu Kuai <yukuai3@huawei.com>
Signed-off-by: default avatarSong Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20240226031444.3606764-2-linan666@huaweicloud.com
parent 82c6515d
...@@ -7522,16 +7522,17 @@ static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo) ...@@ -7522,16 +7522,17 @@ static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo)
return 0; return 0;
} }
static inline bool md_ioctl_valid(unsigned int cmd) static inline int md_ioctl_valid(unsigned int cmd)
{ {
switch (cmd) { switch (cmd) {
case ADD_NEW_DISK:
case GET_ARRAY_INFO: case GET_ARRAY_INFO:
case GET_BITMAP_FILE:
case GET_DISK_INFO: case GET_DISK_INFO:
case RAID_VERSION:
return 0;
case ADD_NEW_DISK:
case GET_BITMAP_FILE:
case HOT_ADD_DISK: case HOT_ADD_DISK:
case HOT_REMOVE_DISK: case HOT_REMOVE_DISK:
case RAID_VERSION:
case RESTART_ARRAY_RW: case RESTART_ARRAY_RW:
case RUN_ARRAY: case RUN_ARRAY:
case SET_ARRAY_INFO: case SET_ARRAY_INFO:
...@@ -7540,9 +7541,11 @@ static inline bool md_ioctl_valid(unsigned int cmd) ...@@ -7540,9 +7541,11 @@ static inline bool md_ioctl_valid(unsigned int cmd)
case STOP_ARRAY: case STOP_ARRAY:
case STOP_ARRAY_RO: case STOP_ARRAY_RO:
case CLUSTERED_DISK_NACK: case CLUSTERED_DISK_NACK:
return true; if (!capable(CAP_SYS_ADMIN))
return -EACCES;
return 0;
default: default:
return false; return -ENOTTY;
} }
} }
...@@ -7602,18 +7605,9 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, ...@@ -7602,18 +7605,9 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
struct mddev *mddev = NULL; struct mddev *mddev = NULL;
bool did_set_md_closing = false; bool did_set_md_closing = false;
if (!md_ioctl_valid(cmd)) err = md_ioctl_valid(cmd);
return -ENOTTY; if (err)
return err;
switch (cmd) {
case RAID_VERSION:
case GET_ARRAY_INFO:
case GET_DISK_INFO:
break;
default:
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
}
/* /*
* Commands dealing with the RAID driver but not any * Commands dealing with the RAID driver but not any
......
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