obd_config.c

来自「lustre 1.6.5 source code」· C语言 代码 · 共 1,244 行 · 第 1/3 页

C
1,244
字号
                        case 'F':                                obd->obd_force = 1;                                break;                        case 'A':                                LCONSOLE_WARN("Failing over %s\n",                                               obd->obd_name);                                obd->obd_fail = 1;                                obd->obd_no_transno = 1;                                obd->obd_no_recov = 1;                                /* Set the obd readonly if we can */                                if (OBP(obd, iocontrol))                                        obd_iocontrol(OBD_IOC_SET_READONLY,                                                      obd->obd_self_export,                                                      0, NULL, NULL);                                break;                        default:                                CERROR("unrecognised flag '%c'\n",                                       *flag);                        }        }        /* The three references that should be remaining are the         * obd_self_export and the attach and setup references. */        if (atomic_read(&obd->obd_refcount) > 3) {#if 0           /* We should never fail to cleanup with mountconf */                 if (!(obd->obd_fail || obd->obd_force)) {                        CERROR("OBD %s is still busy with %d references\n"                               "You should stop active file system users,"                               " or use the --force option to cleanup.\n",                               obd->obd_name, atomic_read(&obd->obd_refcount));                        dump_exports(obd);                        /* Allow a failed cleanup to try again. */                        obd->obd_stopping = 0;                        RETURN(-EBUSY);                }#endif                /* refcounf - 3 might be the number of real exports                    (excluding self export). But class_incref is called                   by other things as well, so don't count on it. */                CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d\n",                       obd->obd_name, atomic_read(&obd->obd_refcount) - 3);                dump_exports(obd);                class_disconnect_exports(obd);        }        LASSERT(obd->obd_self_export);        /* destroy an uuid-export hash body */        lustre_hash_exit(&obd->obd_uuid_hash_body);        /* destroy a nid-export hash body */        lustre_hash_exit(&obd->obd_nid_hash_body);        /* destroy a nid-stats hash body */        lustre_hash_exit(&obd->obd_nid_stats_hash_body);        /* Precleanup stage 1, we must make sure all exports (other than the           self-export) get destroyed. */        err = obd_precleanup(obd, OBD_CLEANUP_EXPORTS);        if (err)                CERROR("Precleanup %s returned %d\n",                       obd->obd_name, err);        class_decref(obd);        obd->obd_set_up = 0;        RETURN(0);}struct obd_device *class_incref(struct obd_device *obd){        atomic_inc(&obd->obd_refcount);        CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,               atomic_read(&obd->obd_refcount));        return obd;}void class_decref(struct obd_device *obd){        int err;        int refs;        spin_lock(&obd->obd_dev_lock);        atomic_dec(&obd->obd_refcount);        refs = atomic_read(&obd->obd_refcount);        spin_unlock(&obd->obd_dev_lock);        CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);        if ((refs == 1) && obd->obd_stopping) {                /* All exports (other than the self-export) have been                   destroyed; there should be no more in-progress ops                   by this point.*/                /* if we're not stopping, we didn't finish setup */                /* Precleanup stage 2,  do other type-specific                   cleanup requiring the self-export. */                err = obd_precleanup(obd, OBD_CLEANUP_SELF_EXP);                if (err)                        CERROR("Precleanup %s returned %d\n",                               obd->obd_name, err);                spin_lock(&obd->obd_self_export->exp_lock);                obd->obd_self_export->exp_flags |=                        (obd->obd_fail ? OBD_OPT_FAILOVER : 0) |                        (obd->obd_force ? OBD_OPT_FORCE : 0);                spin_unlock(&obd->obd_self_export->exp_lock);                /* note that we'll recurse into class_decref again */                class_unlink_export(obd->obd_self_export);                return;        }        if (refs == 0) {                CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",                       obd->obd_name, obd->obd_uuid.uuid);                LASSERT(!obd->obd_attached);                if (obd->obd_stopping) {                        /* If we're not stopping, we were never set up */                        err = obd_cleanup(obd);                        if (err)                                CERROR("Cleanup %s returned %d\n",                                       obd->obd_name, err);                }                if (OBP(obd, detach)) {                        err = OBP(obd,detach)(obd);                        if (err)                                CERROR("Detach returned %d\n", err);                }                class_release_dev(obd);        }}int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg){        struct obd_import *imp;        struct obd_uuid uuid;        int rc;        ENTRY;        if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||            LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {                CERROR("invalid conn_uuid\n");                RETURN(-EINVAL);        }        if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&            strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&             strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {                CERROR("can't add connection on non-client dev\n");                RETURN(-EINVAL);        }        imp = obd->u.cli.cl_import;        if (!imp) {                CERROR("try to add conn on immature client dev\n");                RETURN(-EINVAL);        }        obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));        rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);        RETURN(rc);}int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg){        struct obd_import *imp;        struct obd_uuid uuid;        int rc;        ENTRY;        if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||            LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {                CERROR("invalid conn_uuid\n");                RETURN(-EINVAL);        }        if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&            strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {                CERROR("can't del connection on non-client dev\n");                RETURN(-EINVAL);        }        imp = obd->u.cli.cl_import;        if (!imp) {                CERROR("try to del conn on immature client dev\n");                RETURN(-EINVAL);        }        obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));        rc = obd_del_conn(imp, &uuid);        RETURN(rc);}CFS_LIST_HEAD(lustre_profile_list);struct lustre_profile *class_get_profile(char * prof){        struct lustre_profile *lprof;        ENTRY;        list_for_each_entry(lprof, &lustre_profile_list, lp_list) {                if (!strcmp(lprof->lp_profile, prof)) {                        RETURN(lprof);                }        }        RETURN(NULL);}int class_add_profile(int proflen, char *prof, int osclen, char *osc,                      int mdclen, char *mdc){        struct lustre_profile *lprof;        int err = 0;        ENTRY;        CDEBUG(D_CONFIG, "Add profile %s\n", prof);        OBD_ALLOC(lprof, sizeof(*lprof));        if (lprof == NULL)                RETURN(-ENOMEM);        CFS_INIT_LIST_HEAD(&lprof->lp_list);        LASSERT(proflen == (strlen(prof) + 1));        OBD_ALLOC(lprof->lp_profile, proflen);        if (lprof->lp_profile == NULL)                GOTO(out, err = -ENOMEM);        memcpy(lprof->lp_profile, prof, proflen);        LASSERT(osclen == (strlen(osc) + 1));        OBD_ALLOC(lprof->lp_osc, osclen);        if (lprof->lp_osc == NULL)                GOTO(out, err = -ENOMEM);        memcpy(lprof->lp_osc, osc, osclen);        if (mdclen > 0) {                LASSERT(mdclen == (strlen(mdc) + 1));                OBD_ALLOC(lprof->lp_mdc, mdclen);                if (lprof->lp_mdc == NULL)                        GOTO(out, err = -ENOMEM);                memcpy(lprof->lp_mdc, mdc, mdclen);        }        list_add(&lprof->lp_list, &lustre_profile_list);        RETURN(err);out:        if (lprof->lp_mdc)                OBD_FREE(lprof->lp_mdc, mdclen);        if (lprof->lp_osc)                OBD_FREE(lprof->lp_osc, osclen);        if (lprof->lp_profile)                OBD_FREE(lprof->lp_profile, proflen);        OBD_FREE(lprof, sizeof(*lprof));                RETURN(err);}void class_del_profile(char *prof){        struct lustre_profile *lprof;        ENTRY;        CDEBUG(D_CONFIG, "Del profile %s\n", prof);        lprof = class_get_profile(prof);        if (lprof) {                list_del(&lprof->lp_list);                OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);                OBD_FREE(lprof->lp_osc, strlen(lprof->lp_osc) + 1);                if (lprof->lp_mdc)                        OBD_FREE(lprof->lp_mdc, strlen(lprof->lp_mdc) + 1);                OBD_FREE(lprof, sizeof *lprof);        }        EXIT;}/* COMPAT_146 */void class_del_profiles(void){        struct lustre_profile *lprof, *n;        ENTRY;        list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {                list_del(&lprof->lp_list);                OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);                OBD_FREE(lprof->lp_osc, strlen(lprof->lp_osc) + 1);                if (lprof->lp_mdc)                        OBD_FREE(lprof->lp_mdc, strlen(lprof->lp_mdc) + 1);                OBD_FREE(lprof, sizeof *lprof);        }        EXIT;}/* We can't call ll_process_config directly because it lives in a module that   must be loaded after this one. */static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg)){        client_process_config = cpc;}EXPORT_SYMBOL(lustre_register_client_process_config);int class_process_config(struct lustre_cfg *lcfg){        struct obd_device *obd;        int err;        LASSERT(lcfg && !IS_ERR(lcfg));        CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);        /* Commands that don't need a device */        switch(lcfg->lcfg_command) {        case LCFG_ATTACH: {                err = class_attach(lcfg);                GOTO(out, err);        }        case LCFG_ADD_UUID: {                CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid "LPX64                       " (%s)\n", lustre_cfg_string(lcfg, 1),                       lcfg->lcfg_nid, libcfs_nid2str(lcfg->lcfg_nid));                err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);                GOTO(out, err);        }        case LCFG_DEL_UUID: {                CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",                       (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)                       ? "<all uuids>" : lustre_cfg_string(lcfg, 1));                err = class_del_uuid(lustre_cfg_string(lcfg, 1));                GOTO(out, err);        }        case LCFG_MOUNTOPT: {                CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",                       lustre_cfg_string(lcfg, 1),                       lustre_cfg_string(lcfg, 2),                       lustre_cfg_string(lcfg, 3));                /* set these mount options somewhere, so ll_fill_super                 * can find them. */                err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),                                        lustre_cfg_string(lcfg, 1),                                        LUSTRE_CFG_BUFLEN(lcfg, 2),                                        lustre_cfg_string(lcfg, 2),                                        LUSTRE_CFG_BUFLEN(lcfg, 3),                                        lustre_cfg_string(lcfg, 3));                GOTO(out, err);        }        case LCFG_DEL_MOUNTOPT: {                CDEBUG(D_IOCTL, "mountopt: profile %s\n",                       lustre_cfg_string(lcfg, 1));                class_del_profile(lustre_cfg_string(lcfg, 1));                GOTO(out, err = 0);        }        case LCFG_SET_TIMEOUT: {                CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",                       obd_timeout, lcfg->lcfg_num);                obd_timeout = max(lcfg->lcfg_num, 1U);                GOTO(out, err = 0);        }        case LCFG_SET_UPCALL: {                LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");                /* COMPAT_146 Don't fail on old configs */                GOTO(out, err = 0);        }        case LCFG_MARKER: {                struct cfg_marker *marker;                marker = lustre_cfg_buf(lcfg, 1);                CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,                      marker->cm_flags, marker->cm_tgtname, marker->cm_comment);                GOTO(out, err = 0);        }        case LCFG_PARAM: {                /* llite has no obd */                if ((class_match_param(lustre_cfg_string(lcfg, 1),                                        PARAM_LLITE, 0) == 0) &&                    client_process_config) {                        err = (*client_process_config)(lcfg);                        GOTO(out, err);                }                /* Fall through */                break;        }        }        /* Commands that require a device */        obd = class_name2obd(lustre_cfg_string(lcfg, 0));        if (obd == NULL) {                if (!LUSTRE_CFG_BUFLEN(lcfg, 0))                        CERROR("this lcfg command requires a device name\n");                else                        CERROR("no device for: %s\n",                               lustre_cfg_string(lcfg, 0));                GOTO(out, err = -EINVAL);        }        switch(lcfg->lcfg_command) {        case LCFG_SETUP: {                err = class_setup(obd, lcfg);                GOTO(out, err);        }        case LCFG_DETACH: {                err = class_detach(obd, lcfg);                GOTO(out, err = 0);        }        case LCFG_CLEANUP: {                err = class_cleanup(obd, lcfg);                GOTO(out, err = 0);        }        case LCFG_ADD_CONN: {                err = class_add_conn(obd, lcfg);                GOTO(out, err = 0);        }        case LCFG_DEL_CONN: {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?