Commit 402fba76 authored by James Simmons's avatar James Simmons Committed by Greg Kroah-Hartman

staging: lustre: uapi: don't memory allocate in UAPI header

The inline function lustre_cfg_new() calls kzalloc() but
this is a UAPI header. Remove kzalloc() and rename the
function to lustre_cfg_init(). The lustre kernel code
that was calling lustre_cfg_new() can doing the memory
allocation and pass the new buffer to lustre_cfg_init()
to fill in.
Signed-off-by: default avatarJames Simmons <uja.ornl@yahoo.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6401
Reviewed-on: https://review.whamcloud.com/26966Reviewed-by: default avatarQuentin Bouget <quentin.bouget@cea.fr>
Reviewed-by: default avatarBen Evans <bevans@cray.com>
Reviewed-by: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarJames Simmons <jsimmons@infradead.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 18bd2084
...@@ -222,18 +222,12 @@ static inline __u32 lustre_cfg_len(__u32 bufcount, __u32 *buflens) ...@@ -222,18 +222,12 @@ static inline __u32 lustre_cfg_len(__u32 bufcount, __u32 *buflens)
#include "obd_support.h" #include "obd_support.h"
static inline struct lustre_cfg *lustre_cfg_new(int cmd, static inline void lustre_cfg_init(struct lustre_cfg *lcfg, int cmd,
struct lustre_cfg_bufs *bufs) struct lustre_cfg_bufs *bufs)
{ {
struct lustre_cfg *lcfg;
char *ptr; char *ptr;
int i; int i;
lcfg = kzalloc(lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen),
GFP_NOFS);
if (!lcfg)
return ERR_PTR(-ENOMEM);
lcfg->lcfg_version = LUSTRE_CFG_VERSION; lcfg->lcfg_version = LUSTRE_CFG_VERSION;
lcfg->lcfg_command = cmd; lcfg->lcfg_command = cmd;
lcfg->lcfg_bufcount = bufs->lcfg_bufcount; lcfg->lcfg_bufcount = bufs->lcfg_bufcount;
...@@ -243,7 +237,6 @@ static inline struct lustre_cfg *lustre_cfg_new(int cmd, ...@@ -243,7 +237,6 @@ static inline struct lustre_cfg *lustre_cfg_new(int cmd,
lcfg->lcfg_buflens[i] = bufs->lcfg_buflen[i]; lcfg->lcfg_buflens[i] = bufs->lcfg_buflen[i];
LOGL((char *)bufs->lcfg_buf[i], bufs->lcfg_buflen[i], ptr); LOGL((char *)bufs->lcfg_buf[i], bufs->lcfg_buflen[i], ptr);
} }
return lcfg;
} }
static inline int lustre_cfg_sanity_check(void *buf, size_t len) static inline int lustre_cfg_sanity_check(void *buf, size_t len)
......
...@@ -1155,6 +1155,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc, ...@@ -1155,6 +1155,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
char *cname; char *cname;
char *params; char *params;
char *uuid; char *uuid;
size_t len;
rc = -EINVAL; rc = -EINVAL;
if (datalen < sizeof(*entry)) if (datalen < sizeof(*entry))
...@@ -1283,11 +1284,13 @@ static int mgc_apply_recover_logs(struct obd_device *mgc, ...@@ -1283,11 +1284,13 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
lustre_cfg_bufs_set_string(&bufs, 1, params); lustre_cfg_bufs_set_string(&bufs, 1, params);
rc = -ENOMEM; rc = -ENOMEM;
lcfg = lustre_cfg_new(LCFG_PARAM, &bufs); len = lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen);
if (IS_ERR(lcfg)) { lcfg = kzalloc(len, GFP_NOFS);
CERROR("mgc: cannot allocate memory\n"); if (!lcfg) {
rc = -ENOMEM;
break; break;
} }
lustre_cfg_init(lcfg, LCFG_PARAM, &bufs);
CDEBUG(D_INFO, "ir apply logs %lld/%lld for %s -> %s\n", CDEBUG(D_INFO, "ir apply logs %lld/%lld for %s -> %s\n",
prev_version, max_version, obdname, params); prev_version, max_version, obdname, params);
......
...@@ -1107,6 +1107,7 @@ int class_config_llog_handler(const struct lu_env *env, ...@@ -1107,6 +1107,7 @@ int class_config_llog_handler(const struct lu_env *env,
struct lustre_cfg_bufs bufs; struct lustre_cfg_bufs bufs;
char *inst_name = NULL; char *inst_name = NULL;
int inst_len = 0; int inst_len = 0;
size_t lcfg_len;
int inst = 0, swab = 0; int inst = 0, swab = 0;
lcfg = (struct lustre_cfg *)cfg_buf; lcfg = (struct lustre_cfg *)cfg_buf;
...@@ -1238,8 +1239,14 @@ int class_config_llog_handler(const struct lu_env *env, ...@@ -1238,8 +1239,14 @@ int class_config_llog_handler(const struct lu_env *env,
clli->cfg_obdname); clli->cfg_obdname);
} }
lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs); lcfg_len = lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen);
lcfg_new = kzalloc(lcfg_len, GFP_NOFS);
if (!lcfg_new) {
rc = -ENOMEM;
goto out;
}
lustre_cfg_init(lcfg_new, lcfg->lcfg_command, &bufs);
lcfg_new->lcfg_num = lcfg->lcfg_num; lcfg_new->lcfg_num = lcfg->lcfg_num;
lcfg_new->lcfg_flags = lcfg->lcfg_flags; lcfg_new->lcfg_flags = lcfg->lcfg_flags;
...@@ -1426,9 +1433,11 @@ int class_manual_cleanup(struct obd_device *obd) ...@@ -1426,9 +1433,11 @@ int class_manual_cleanup(struct obd_device *obd)
lustre_cfg_bufs_reset(&bufs, obd->obd_name); lustre_cfg_bufs_reset(&bufs, obd->obd_name);
lustre_cfg_bufs_set_string(&bufs, 1, flags); lustre_cfg_bufs_set_string(&bufs, 1, flags);
lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); lcfg = kzalloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen),
if (IS_ERR(lcfg)) GFP_NOFS);
return PTR_ERR(lcfg); if (!lcfg)
return -ENOMEM;
lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
rc = class_process_config(lcfg); rc = class_process_config(lcfg);
if (rc) { if (rc) {
......
...@@ -88,10 +88,17 @@ int lustre_process_log(struct super_block *sb, char *logname, ...@@ -88,10 +88,17 @@ int lustre_process_log(struct super_block *sb, char *logname,
lustre_cfg_bufs_set_string(bufs, 1, logname); lustre_cfg_bufs_set_string(bufs, 1, logname);
lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg)); lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb)); lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
lcfg = lustre_cfg_new(LCFG_LOG_START, bufs); lcfg = kzalloc(lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen),
GFP_NOFS);
if (!lcfg) {
rc = -ENOMEM;
goto out;
}
lustre_cfg_init(lcfg, LCFG_LOG_START, bufs);
rc = obd_process_config(mgc, sizeof(*lcfg), lcfg); rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
kfree(lcfg); kfree(lcfg);
out:
kfree(bufs); kfree(bufs);
if (rc == -EINVAL) if (rc == -EINVAL)
...@@ -126,7 +133,12 @@ int lustre_end_log(struct super_block *sb, char *logname, ...@@ -126,7 +133,12 @@ int lustre_end_log(struct super_block *sb, char *logname,
lustre_cfg_bufs_set_string(&bufs, 1, logname); lustre_cfg_bufs_set_string(&bufs, 1, logname);
if (cfg) if (cfg)
lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg)); lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs); lcfg = kzalloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen),
GFP_NOFS);
if (!lcfg)
return -ENOMEM;
lustre_cfg_init(lcfg, LCFG_LOG_END, &bufs);
rc = obd_process_config(mgc, sizeof(*lcfg), lcfg); rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
kfree(lcfg); kfree(lcfg);
return rc; return rc;
...@@ -158,7 +170,11 @@ static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd, ...@@ -158,7 +170,11 @@ static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
if (s4) if (s4)
lustre_cfg_bufs_set_string(&bufs, 4, s4); lustre_cfg_bufs_set_string(&bufs, 4, s4);
lcfg = lustre_cfg_new(cmd, &bufs); lcfg = kzalloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen),
GFP_NOFS);
if (!lcfg)
return -ENOMEM;
lustre_cfg_init(lcfg, cmd, &bufs);
lcfg->lcfg_nid = nid; lcfg->lcfg_nid = nid;
rc = class_process_config(lcfg); rc = class_process_config(lcfg);
kfree(lcfg); kfree(lcfg);
......
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