* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2012, 2016, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
struct kmem_cache *lovsub_object_kmem;
struct lu_kmem_descr lov_caches[] = {
- {
- .ckd_cache = &lov_lock_kmem,
- .ckd_name = "lov_lock_kmem",
- .ckd_size = sizeof (struct lov_lock)
- },
- {
- .ckd_cache = &lov_object_kmem,
- .ckd_name = "lov_object_kmem",
- .ckd_size = sizeof (struct lov_object)
- },
- {
- .ckd_cache = &lov_thread_kmem,
- .ckd_name = "lov_thread_kmem",
- .ckd_size = sizeof (struct lov_thread_info)
- },
- {
- .ckd_cache = &lov_session_kmem,
- .ckd_name = "lov_session_kmem",
- .ckd_size = sizeof (struct lov_session)
- },
- {
- .ckd_cache = &lovsub_object_kmem,
- .ckd_name = "lovsub_object_kmem",
- .ckd_size = sizeof (struct lovsub_object)
- },
- {
- .ckd_cache = NULL
- }
+ {
+ .ckd_cache = &lov_lock_kmem,
+ .ckd_name = "lov_lock_kmem",
+ .ckd_size = sizeof(struct lov_lock)
+ },
+ {
+ .ckd_cache = &lov_object_kmem,
+ .ckd_name = "lov_object_kmem",
+ .ckd_size = sizeof(struct lov_object)
+ },
+ {
+ .ckd_cache = &lov_thread_kmem,
+ .ckd_name = "lov_thread_kmem",
+ .ckd_size = sizeof(struct lov_thread_info)
+ },
+ {
+ .ckd_cache = &lov_session_kmem,
+ .ckd_name = "lov_session_kmem",
+ .ckd_size = sizeof(struct lov_session)
+ },
+ {
+ .ckd_cache = &lovsub_object_kmem,
+ .ckd_name = "lovsub_object_kmem",
+ .ckd_size = sizeof(struct lovsub_object)
+ },
+ {
+ .ckd_cache = NULL
+ }
};
/*****************************************************************************
struct lov_thread_info *info;
OBD_SLAB_ALLOC_PTR_GFP(info, lov_thread_kmem, GFP_NOFS);
- if (info == NULL)
+ if (!info)
info = ERR_PTR(-ENOMEM);
return info;
}
}
struct lu_context_key lov_key = {
- .lct_tags = LCT_CL_THREAD,
- .lct_init = lov_key_init,
- .lct_fini = lov_key_fini
+ .lct_tags = LCT_CL_THREAD,
+ .lct_init = lov_key_init,
+ .lct_fini = lov_key_fini
};
static void *lov_session_key_init(const struct lu_context *ctx,
struct lov_session *info;
OBD_SLAB_ALLOC_PTR_GFP(info, lov_session_kmem, GFP_NOFS);
- if (info == NULL)
+ if (!info)
info = ERR_PTR(-ENOMEM);
return info;
}
static void lov_session_key_fini(const struct lu_context *ctx,
- struct lu_context_key *key, void *data)
+ struct lu_context_key *key, void *data)
{
- struct lov_session *info = data;
- OBD_SLAB_FREE_PTR(info, lov_session_kmem);
+ struct lov_session *info = data;
+
+ OBD_SLAB_FREE_PTR(info, lov_session_kmem);
}
struct lu_context_key lov_session_key = {
- .lct_tags = LCT_SESSION,
- .lct_init = lov_session_key_init,
- .lct_fini = lov_session_key_fini
+ .lct_tags = LCT_SESSION,
+ .lct_init = lov_session_key_init,
+ .lct_fini = lov_session_key_fini
};
/* type constructor/destructor: lov_type_{init,fini,start,stop}() */
LASSERT(ld->ld_lov != NULL);
- if (ld->ld_lmv != NULL) {
+ if (ld->ld_lmv) {
class_decref(ld->ld_lmv, "lov", d);
ld->ld_lmv = NULL;
}
- if (ld->ld_md_tgts != NULL) {
+ if (ld->ld_md_tgts) {
for (i = 0; i < ld->ld_md_tgts_nr; i++) {
- if (ld->ld_md_tgts[i].ldm_mdc == NULL)
+ if (!ld->ld_md_tgts[i].ldm_mdc)
continue;
cl_stack_fini(env, ld->ld_md_tgts[i].ldm_mdc);
}
}
- if (ld->ld_target != NULL) {
+ if (ld->ld_target) {
lov_foreach_target(ld, i) {
struct lovsub_device *lsd;
lsd = ld->ld_target[i];
- if (lsd != NULL) {
+ if (lsd) {
cl_stack_fini(env, lovsub2cl_dev(lsd));
ld->ld_target[i] = NULL;
}
}
static int lov_device_init(const struct lu_env *env, struct lu_device *d,
- const char *name, struct lu_device *next)
+ const char *name, struct lu_device *next)
{
struct lov_device *ld = lu2lov_dev(d);
int i;
mdc = ld->ld_lov->lov_mdc_tgts[i].lmtd_mdc;
idx = ld->ld_lov->lov_mdc_tgts[i].lmtd_index;
- if (mdc == NULL)
+ if (!mdc)
continue;
rc = lov_mdc_dev_init(env, ld, mdc->obd_lu_dev, idx, i);
}
}
- if (ld->ld_target == NULL)
+ if (!ld->ld_target)
RETURN(0);
lov_foreach_target(ld, i) {
struct lov_tgt_desc *desc;
desc = ld->ld_lov->lov_tgts[i];
- if (desc == NULL)
+ if (!desc)
continue;
cl = cl_type_setup(env, &ld->ld_site, &lovsub_device_type,
/* Free the lov specific data created for the back end lu_device. */
static struct lu_device *lov_device_free(const struct lu_env *env,
- struct lu_device *d)
+ struct lu_device *d)
{
struct lov_device *ld = lu2lov_dev(d);
const int nr = ld->ld_target_nr;
cl_device_fini(lu2cl_dev(d));
if (ld->ld_target) {
- OBD_FREE(ld->ld_target, nr * sizeof ld->ld_target[0]);
+ OBD_FREE_PTR_ARRAY(ld->ld_target, nr);
ld->ld_target = NULL;
}
if (ld->ld_md_tgts) {
- OBD_FREE(ld->ld_md_tgts,
- sizeof(*ld->ld_md_tgts) * LOV_MDC_TGT_MAX);
+ OBD_FREE_PTR_ARRAY(ld->ld_md_tgts, LOV_MDC_TGT_MAX);
ld->ld_md_tgts = NULL;
}
/* free array of MDCs */
if (ld->ld_lov->lov_mdc_tgts) {
- OBD_FREE(ld->ld_lov->lov_mdc_tgts,
- sizeof(*ld->ld_lov->lov_mdc_tgts) * LOV_MDC_TGT_MAX);
+ OBD_FREE_PTR_ARRAY(ld->ld_lov->lov_mdc_tgts, LOV_MDC_TGT_MAX);
ld->ld_lov->lov_mdc_tgts = NULL;
}
}
static void lov_cl_del_target(const struct lu_env *env, struct lu_device *dev,
- __u32 index)
+ __u32 index)
{
- struct lov_device *ld = lu2lov_dev(dev);
- ENTRY;
+ struct lov_device *ld = lu2lov_dev(dev);
- if (ld->ld_target[index] != NULL) {
- cl_stack_fini(env, lovsub2cl_dev(ld->ld_target[index]));
- ld->ld_target[index] = NULL;
- }
- EXIT;
+ ENTRY;
+
+ if (ld->ld_target[index]) {
+ cl_stack_fini(env, lovsub2cl_dev(ld->ld_target[index]));
+ ld->ld_target[index] = NULL;
+ }
+ EXIT;
}
static int lov_expand_targets(const struct lu_env *env, struct lov_device *dev)
struct lovsub_device **newd;
const size_t sz = sizeof(newd[0]);
- OBD_ALLOC(newd, tgt_size * sz);
- if (newd != NULL) {
+ OBD_ALLOC_PTR_ARRAY(newd, tgt_size);
+ if (newd) {
if (sub_size > 0) {
memcpy(newd, dev->ld_target, sub_size * sz);
OBD_FREE(dev->ld_target, sub_size * sz);
}
static int lov_cl_add_target(const struct lu_env *env, struct lu_device *dev,
- __u32 index)
+ __u32 index)
{
- struct obd_device *obd = dev->ld_obd;
- struct lov_device *ld = lu2lov_dev(dev);
- struct lov_tgt_desc *tgt;
- struct lovsub_device *lsd;
- struct cl_device *cl;
- int rc;
- ENTRY;
-
- obd_getref(obd);
-
- tgt = obd->u.lov.lov_tgts[index];
- LASSERT(tgt != NULL);
- LASSERT(tgt->ltd_obd != NULL);
-
- if (!tgt->ltd_obd->obd_set_up) {
- CERROR("Target %s not set up\n", obd_uuid2str(&tgt->ltd_uuid));
- RETURN(-EINVAL);
- }
+ struct obd_device *obd = dev->ld_obd;
+ struct lov_device *ld = lu2lov_dev(dev);
+ struct lov_tgt_desc *tgt;
+ struct lovsub_device *lsd;
+ struct cl_device *cl;
+ int rc;
+
+ ENTRY;
+
+ lov_tgts_getref(obd);
+
+ tgt = obd->u.lov.lov_tgts[index];
+ LASSERT(tgt != NULL);
+ LASSERT(tgt->ltd_obd != NULL);
+
+ if (!tgt->ltd_obd->obd_set_up) {
+ CERROR("Target %s not set up\n", obd_uuid2str(&tgt->ltd_uuid));
+ RETURN(-EINVAL);
+ }
rc = lov_expand_targets(env, ld);
if (rc == 0 && ld->ld_flags & LOV_DEV_INITIALIZED) {
rc = PTR_ERR(cl);
}
}
- obd_putref(obd);
- RETURN(rc);
+
+ lov_tgts_putref(obd);
+
+ RETURN(rc);
}
/**
LASSERT(mdc != NULL);
if (ld->ld_md_tgts_nr == LOV_MDC_TGT_MAX) {
- /* If the maximum value of LOV_MDC_TGT_MAX will become too
+ /*
+ * If the maximum value of LOV_MDC_TGT_MAX will become too
* small then all MD target handling must be rewritten in LOD
* manner, check lod_add_device() and related functionality.
*/
RETURN(-ERANGE);
}
- /* grab FLD from lmv, do that here, when first MDC is added
- * to be sure LMV is set up and can be found */
- if (ld->ld_lmv == NULL) {
+ /*
+ * grab FLD from lmv, do that here, when first MDC is added
+ * to be sure LMV is set up and can be found
+ */
+ if (!ld->ld_lmv) {
next = 0;
while ((lmv_obd = class_devices_in_group(&lov_obd->obd_uuid,
&next)) != NULL) {
strlen(LUSTRE_LMV_NAME)) == 0))
break;
}
- if (lmv_obd == NULL) {
+ if (!lmv_obd) {
CERROR("%s: cannot find LMV OBD by UUID (%s)\n",
lov_obd->obd_name,
obd_uuid2str(&lmv_obd->obd_uuid));
}
static int lov_process_config(const struct lu_env *env,
- struct lu_device *d, struct lustre_cfg *cfg)
+ struct lu_device *d, struct lustre_cfg *cfg)
{
struct obd_device *obd = d->ld_obd;
int cmd;
int rc;
int gen;
- __u32 index;
+ u32 index;
- obd_getref(obd);
+ lov_tgts_getref(obd);
cmd = cfg->lcfg_command;
break;
case LCFG_ADD_MDC:
{
- struct obd_device *mdc;
- struct obd_uuid tgt_uuid;
+ struct obd_device *mdc;
+ struct obd_uuid tgt_uuid;
- /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
- * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
+ /*
+ * modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
+ * 2:0 3:1 4:lustre-MDT0000-mdc_UUID
+ */
if (LUSTRE_CFG_BUFLEN(cfg, 1) > sizeof(tgt_uuid.uuid))
GOTO(out, rc = -EINVAL);
obd_str2uuid(&tgt_uuid, lustre_cfg_buf(cfg, 1));
- if (sscanf(lustre_cfg_buf(cfg, 2), "%d", &index) != 1)
- GOTO(out, rc = -EINVAL);
+ rc = kstrtou32(lustre_cfg_buf(cfg, 2), 10, &index);
+ if (rc)
+ GOTO(out, rc);
mdc = class_find_client_obd(&tgt_uuid, LUSTRE_MDC_NAME,
&obd->obd_uuid);
- if (mdc == NULL)
+ if (!mdc)
GOTO(out, rc = -ENODEV);
rc = lov_add_mdc_target(env, d, mdc, index);
break;
}
}
out:
- obd_putref(obd);
+ lov_tgts_putref(obd);
RETURN(rc);
}
static const struct lu_device_operations lov_lu_ops = {
- .ldo_object_alloc = lov_object_alloc,
- .ldo_process_config = lov_process_config,
+ .ldo_object_alloc = lov_object_alloc,
+ .ldo_process_config = lov_process_config,
};
static struct lu_device *lov_device_alloc(const struct lu_env *env,
- struct lu_device_type *t,
- struct lustre_cfg *cfg)
+ struct lu_device_type *t,
+ struct lustre_cfg *cfg)
{
- struct lu_device *d;
- struct lov_device *ld;
- struct obd_device *obd;
- int rc;
+ struct lu_device *d;
+ struct lov_device *ld;
+ struct obd_device *obd;
+ int rc;
- OBD_ALLOC_PTR(ld);
- if (ld == NULL)
- RETURN(ERR_PTR(-ENOMEM));
+ OBD_ALLOC_PTR(ld);
+ if (!ld)
+ RETURN(ERR_PTR(-ENOMEM));
cl_device_init(&ld->ld_cl, t);
d = lov2lu_dev(ld);
d->ld_ops = &lov_lu_ops;
- /* setup the LOV OBD */
- obd = class_name2obd(lustre_cfg_string(cfg, 0));
- LASSERT(obd != NULL);
- rc = lov_setup(obd, cfg);
+ /* setup the LOV OBD */
+ obd = class_name2obd(lustre_cfg_string(cfg, 0));
+ LASSERT(obd != NULL);
+ rc = lov_setup(obd, cfg);
if (rc)
GOTO(out, rc);
/* Alloc MDC devices array */
/* XXX: need dynamic allocation at some moment */
- OBD_ALLOC(ld->ld_md_tgts, sizeof(*ld->ld_md_tgts) * LOV_MDC_TGT_MAX);
- if (ld->ld_md_tgts == NULL)
+ OBD_ALLOC_PTR_ARRAY(ld->ld_md_tgts, LOV_MDC_TGT_MAX);
+ if (!ld->ld_md_tgts)
GOTO(out, rc = -ENOMEM);
ld->ld_md_tgts_nr = 0;
ld->ld_lov = &obd->u.lov;
- OBD_ALLOC(ld->ld_lov->lov_mdc_tgts,
- sizeof(*ld->ld_lov->lov_mdc_tgts) * LOV_MDC_TGT_MAX);
- if (ld->ld_lov->lov_mdc_tgts == NULL)
+ OBD_ALLOC_PTR_ARRAY(ld->ld_lov->lov_mdc_tgts, LOV_MDC_TGT_MAX);
+ if (!ld->ld_lov->lov_mdc_tgts)
GOTO(out_md_tgts, rc = -ENOMEM);
rc = lu_site_init(&ld->ld_site, d);
out_site:
lu_site_fini(&ld->ld_site);
out_mdc_tgts:
- OBD_FREE(ld->ld_lov->lov_mdc_tgts,
- sizeof(*ld->ld_lov->lov_mdc_tgts) * LOV_MDC_TGT_MAX);
+ OBD_FREE_PTR_ARRAY(ld->ld_lov->lov_mdc_tgts, LOV_MDC_TGT_MAX);
ld->ld_lov->lov_mdc_tgts = NULL;
out_md_tgts:
- OBD_FREE(ld->ld_md_tgts, sizeof(*ld->ld_md_tgts) * LOV_MDC_TGT_MAX);
+ OBD_FREE_PTR_ARRAY(ld->ld_md_tgts, LOV_MDC_TGT_MAX);
ld->ld_md_tgts = NULL;
out:
OBD_FREE_PTR(ld);
}
static const struct lu_device_type_operations lov_device_type_ops = {
- .ldto_init = lov_type_init,
- .ldto_fini = lov_type_fini,
+ .ldto_init = lov_type_init,
+ .ldto_fini = lov_type_fini,
- .ldto_start = lov_type_start,
- .ldto_stop = lov_type_stop,
+ .ldto_start = lov_type_start,
+ .ldto_stop = lov_type_stop,
- .ldto_device_alloc = lov_device_alloc,
- .ldto_device_free = lov_device_free,
+ .ldto_device_alloc = lov_device_alloc,
+ .ldto_device_free = lov_device_free,
- .ldto_device_init = lov_device_init,
- .ldto_device_fini = lov_device_fini
+ .ldto_device_init = lov_device_init,
+ .ldto_device_fini = lov_device_fini
};
struct lu_device_type lov_device_type = {
- .ldt_tags = LU_DEVICE_CL,
- .ldt_name = LUSTRE_LOV_NAME,
- .ldt_ops = &lov_device_type_ops,
- .ldt_ctx_tags = LCT_CL_THREAD
+ .ldt_tags = LU_DEVICE_CL,
+ .ldt_name = LUSTRE_LOV_NAME,
+ .ldt_ops = &lov_device_type_ops,
+ .ldt_ctx_tags = LCT_CL_THREAD
};
/** @} lov */