Commit ad8c28a9 authored by Jeff Layton's avatar Jeff Layton Committed by Ilya Dryomov

ceph: convert int fields in ceph_mount_options to unsigned int

Most of these values should never be negative, so convert them to
unsigned values. Add some sanity checking to the parsed values, and
clean up some unneeded casts.

Note that while caps_max should never be negative, this patch leaves
it signed, since this value ends up later being compared to a signed
counter. Just ensure that userland never passes in a negative value
for caps_max.
Signed-off-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent e42617b8
...@@ -2032,12 +2032,13 @@ int ceph_alloc_readdir_reply_buffer(struct ceph_mds_request *req, ...@@ -2032,12 +2032,13 @@ int ceph_alloc_readdir_reply_buffer(struct ceph_mds_request *req,
struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info; struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info;
struct ceph_mount_options *opt = req->r_mdsc->fsc->mount_options; struct ceph_mount_options *opt = req->r_mdsc->fsc->mount_options;
size_t size = sizeof(struct ceph_mds_reply_dir_entry); size_t size = sizeof(struct ceph_mds_reply_dir_entry);
int order, num_entries; unsigned int num_entries;
int order;
spin_lock(&ci->i_ceph_lock); spin_lock(&ci->i_ceph_lock);
num_entries = ci->i_files + ci->i_subdirs; num_entries = ci->i_files + ci->i_subdirs;
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
num_entries = max(num_entries, 1); num_entries = max(num_entries, 1U);
num_entries = min(num_entries, opt->max_readdir); num_entries = min(num_entries, opt->max_readdir);
order = get_order(size * num_entries); order = get_order(size * num_entries);
......
...@@ -172,10 +172,10 @@ static const struct fs_parameter_enum ceph_mount_param_enums[] = { ...@@ -172,10 +172,10 @@ static const struct fs_parameter_enum ceph_mount_param_enums[] = {
static const struct fs_parameter_spec ceph_mount_param_specs[] = { static const struct fs_parameter_spec ceph_mount_param_specs[] = {
fsparam_flag_no ("acl", Opt_acl), fsparam_flag_no ("acl", Opt_acl),
fsparam_flag_no ("asyncreaddir", Opt_asyncreaddir), fsparam_flag_no ("asyncreaddir", Opt_asyncreaddir),
fsparam_u32 ("caps_max", Opt_caps_max), fsparam_s32 ("caps_max", Opt_caps_max),
fsparam_u32 ("caps_wanted_delay_max", Opt_caps_wanted_delay_max), fsparam_u32 ("caps_wanted_delay_max", Opt_caps_wanted_delay_max),
fsparam_u32 ("caps_wanted_delay_min", Opt_caps_wanted_delay_min), fsparam_u32 ("caps_wanted_delay_min", Opt_caps_wanted_delay_min),
fsparam_s32 ("write_congestion_kb", Opt_congestion_kb), fsparam_u32 ("write_congestion_kb", Opt_congestion_kb),
fsparam_flag_no ("copyfrom", Opt_copyfrom), fsparam_flag_no ("copyfrom", Opt_copyfrom),
fsparam_flag_no ("dcache", Opt_dcache), fsparam_flag_no ("dcache", Opt_dcache),
fsparam_flag_no ("dirstat", Opt_dirstat), fsparam_flag_no ("dirstat", Opt_dirstat),
...@@ -187,8 +187,8 @@ static const struct fs_parameter_spec ceph_mount_param_specs[] = { ...@@ -187,8 +187,8 @@ static const struct fs_parameter_spec ceph_mount_param_specs[] = {
fsparam_flag_no ("quotadf", Opt_quotadf), fsparam_flag_no ("quotadf", Opt_quotadf),
fsparam_u32 ("rasize", Opt_rasize), fsparam_u32 ("rasize", Opt_rasize),
fsparam_flag_no ("rbytes", Opt_rbytes), fsparam_flag_no ("rbytes", Opt_rbytes),
fsparam_s32 ("readdir_max_bytes", Opt_readdir_max_bytes), fsparam_u32 ("readdir_max_bytes", Opt_readdir_max_bytes),
fsparam_s32 ("readdir_max_entries", Opt_readdir_max_entries), fsparam_u32 ("readdir_max_entries", Opt_readdir_max_entries),
fsparam_enum ("recover_session", Opt_recover_session), fsparam_enum ("recover_session", Opt_recover_session),
fsparam_flag_no ("require_active_mds", Opt_require_active_mds), fsparam_flag_no ("require_active_mds", Opt_require_active_mds),
fsparam_u32 ("rsize", Opt_rsize), fsparam_u32 ("rsize", Opt_rsize),
...@@ -328,7 +328,9 @@ static int ceph_parse_mount_param(struct fs_context *fc, ...@@ -328,7 +328,9 @@ static int ceph_parse_mount_param(struct fs_context *fc,
fsopt->caps_wanted_delay_max = result.uint_32; fsopt->caps_wanted_delay_max = result.uint_32;
break; break;
case Opt_caps_max: case Opt_caps_max:
fsopt->caps_max = result.uint_32; if (result.int_32 < 0)
goto out_of_range;
fsopt->caps_max = result.int_32;
break; break;
case Opt_readdir_max_entries: case Opt_readdir_max_entries:
if (result.uint_32 < 1) if (result.uint_32 < 1)
...@@ -547,25 +549,25 @@ static int ceph_show_options(struct seq_file *m, struct dentry *root) ...@@ -547,25 +549,25 @@ static int ceph_show_options(struct seq_file *m, struct dentry *root)
seq_show_option(m, "recover_session", "clean"); seq_show_option(m, "recover_session", "clean");
if (fsopt->wsize != CEPH_MAX_WRITE_SIZE) if (fsopt->wsize != CEPH_MAX_WRITE_SIZE)
seq_printf(m, ",wsize=%d", fsopt->wsize); seq_printf(m, ",wsize=%u", fsopt->wsize);
if (fsopt->rsize != CEPH_MAX_READ_SIZE) if (fsopt->rsize != CEPH_MAX_READ_SIZE)
seq_printf(m, ",rsize=%d", fsopt->rsize); seq_printf(m, ",rsize=%u", fsopt->rsize);
if (fsopt->rasize != CEPH_RASIZE_DEFAULT) if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
seq_printf(m, ",rasize=%d", fsopt->rasize); seq_printf(m, ",rasize=%u", fsopt->rasize);
if (fsopt->congestion_kb != default_congestion_kb()) if (fsopt->congestion_kb != default_congestion_kb())
seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb); seq_printf(m, ",write_congestion_kb=%u", fsopt->congestion_kb);
if (fsopt->caps_max) if (fsopt->caps_max)
seq_printf(m, ",caps_max=%d", fsopt->caps_max); seq_printf(m, ",caps_max=%d", fsopt->caps_max);
if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT) if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
seq_printf(m, ",caps_wanted_delay_min=%d", seq_printf(m, ",caps_wanted_delay_min=%u",
fsopt->caps_wanted_delay_min); fsopt->caps_wanted_delay_min);
if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT) if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
seq_printf(m, ",caps_wanted_delay_max=%d", seq_printf(m, ",caps_wanted_delay_max=%u",
fsopt->caps_wanted_delay_max); fsopt->caps_wanted_delay_max);
if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT) if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir); seq_printf(m, ",readdir_max_entries=%u", fsopt->max_readdir);
if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT) if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes); seq_printf(m, ",readdir_max_bytes=%u", fsopt->max_readdir_bytes);
if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT)) if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
seq_show_option(m, "snapdirname", fsopt->snapdir_name); seq_show_option(m, "snapdirname", fsopt->snapdir_name);
......
...@@ -73,16 +73,16 @@ ...@@ -73,16 +73,16 @@
#define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */ #define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */
struct ceph_mount_options { struct ceph_mount_options {
int flags; unsigned int flags;
int wsize; /* max write size */ unsigned int wsize; /* max write size */
int rsize; /* max read size */ unsigned int rsize; /* max read size */
int rasize; /* max readahead */ unsigned int rasize; /* max readahead */
int congestion_kb; /* max writeback in flight */ unsigned int congestion_kb; /* max writeback in flight */
int caps_wanted_delay_min, caps_wanted_delay_max; unsigned int caps_wanted_delay_min, caps_wanted_delay_max;
int caps_max; int caps_max;
int max_readdir; /* max readdir result (entires) */ unsigned int max_readdir; /* max readdir result (entries) */
int max_readdir_bytes; /* max readdir result (bytes) */ unsigned int max_readdir_bytes; /* max readdir result (bytes) */
/* /*
* everything above this point can be memcmp'd; everything below * everything above this point can be memcmp'd; everything below
......
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