GOTO(out, rc = -ENXIO);
} else if (KEY_IS("last_id")) {
obd_id *ids = val;
- int size = sizeof(obd_id);
+ unsigned int size = sizeof(obd_id);
for (i = 0; i < lov->desc.ld_tgt_count; i++) {
if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
continue;
static int mds_set_info_rpc(struct obd_export *exp, struct ptlrpc_request *req)
{
- char *key;
- __u32 *val;
- int keylen, rc = 0;
+ void *key, *val;
+ int keylen, vallen, rc = 0;
ENTRY;
key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
}
keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
- val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, sizeof(*val));
- if (val == NULL) {
- DEBUG_REQ(D_HA, req, "no set_info val");
- RETURN(-EFAULT);
- }
+ val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
+ vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
rc = lustre_pack_reply(req, 1, NULL, NULL);
if (rc)
RETURN(rc);
lustre_msg_set_status(req->rq_repmsg, 0);
- if (keylen < strlen("read-only") ||
- memcmp(key, "read-only", keylen) != 0)
- RETURN(-EINVAL);
+ if (KEY_IS("read-only")) {
+ if (val == NULL || vallen < sizeof(__u32)) {
+ DEBUG_REQ(D_HA, req, "no set_info val");
+ RETURN(-EFAULT);
+ }
- if (*val)
- exp->exp_connect_flags |= OBD_CONNECT_RDONLY;
- else
- exp->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
+ if (*(__u32 *)val)
+ exp->exp_connect_flags |= OBD_CONNECT_RDONLY;
+ else
+ exp->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
+ } else {
+ RETURN(-EINVAL);
+ }
RETURN(0);
}
RETURN(-EINVAL);
}
- if (keylen == strlen("blocksize") &&
- memcmp(key, "blocksize", keylen) == 0) {
+ if (KEY_IS("blocksize")) {
__u32 *blocksize = val;
+ if (blocksize) {
+ if (*vallen < sizeof(*blocksize))
+ RETURN(-EOVERFLOW);
+ *blocksize = obd->u.obt.obt_sb->s_blocksize;
+ }
*vallen = sizeof(*blocksize);
- *blocksize = obd->u.obt.obt_sb->s_blocksize;
RETURN(0);
}
- if (keylen == strlen("blocksize_bits") &&
- memcmp(key, "blocksize_bits", keylen) == 0) {
+ if (KEY_IS("blocksize_bits")) {
__u32 *blocksize_bits = val;
+ if (blocksize_bits) {
+ if (*vallen < sizeof(*blocksize_bits))
+ RETURN(-EOVERFLOW);
+ *blocksize_bits = obd->u.obt.obt_sb->s_blocksize_bits;
+ }
*vallen = sizeof(*blocksize_bits);
- *blocksize_bits = obd->u.obt.obt_sb->s_blocksize_bits;
RETURN(0);
}
- if (keylen >= strlen("last_id") && memcmp(key, "last_id", 7) == 0) {
+ if (KEY_IS("last_id")) {
obd_id *last_id = val;
/* FIXME: object groups */
- *last_id = filter_last_id(&obd->u.filter, 0);
+ if (last_id) {
+ if (*vallen < sizeof(*last_id))
+ RETURN(-EOVERFLOW);
+ *last_id = filter_last_id(&obd->u.filter, 0);
+ }
+ *vallen = sizeof(*last_id);
RETURN(0);
}
+
CDEBUG(D_IOCTL, "invalid key\n");
RETURN(-EINVAL);
}
RETURN(0);
}
- if (keylen < strlen(KEY_MDS_CONN) ||
- memcmp(key, KEY_MDS_CONN, keylen) != 0)
+ if (!KEY_IS(KEY_MDS_CONN))
RETURN(-EINVAL);
LCONSOLE_WARN("%s: received MDS connection from %s\n", obd->obd_name,
if (!vallen || !val)
RETURN(-EFAULT);
- if (keylen > strlen("lock_to_stripe") &&
- strcmp(key, "lock_to_stripe") == 0) {
+ if (KEY_IS("lock_to_stripe")) {
__u32 *stripe = val;
*vallen = sizeof(*stripe);
*stripe = 0;
RETURN(0);
- } else if (keylen >= strlen("last_id") && strcmp(key, "last_id") == 0) {
+ } else if (KEY_IS("last_id")) {
struct ptlrpc_request *req;
obd_id *reply;
char *bufs[2] = { NULL, key };
static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
{
- char *key;
+ void *key, *reply;
int keylen, rc = 0;
- int size[2] = { sizeof(struct ptlrpc_body), sizeof(obd_id) };
- obd_id *reply;
+ int size[2] = { sizeof(struct ptlrpc_body), 0 };
ENTRY;
key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
}
keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
- if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0)
- RETURN(-EPROTO);
+ /* call once to get the size to allocate the reply buffer */
+ rc = obd_get_info(exp, keylen, key, &size[1], NULL);
+ if (rc)
+ RETURN(rc);
rc = lustre_pack_reply(req, 2, size, NULL);
if (rc)
RETURN(rc);
reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*reply));
+ /* call again to fill in the reply buffer */
rc = obd_get_info(exp, keylen, key, size, reply);
lustre_msg_set_status(req->rq_repmsg, 0);
+
RETURN(rc);
}