X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fofd%2Fofd_dev.c;h=4c2fec31c8291a8624bacf28d07540854dd95248;hp=b3c582bfc5e51d809bce4991c359f85b3f1fac8d;hb=498bc06f24720234b43d3b98f02fedd0688ab60f;hpb=731178dbad095cc11e52b14266042a301142ebd7 diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index b3c582b..4c2fec3 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -27,7 +27,7 @@ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Whamcloud, Inc. + * Copyright (c) 2012, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -44,6 +44,7 @@ #include #include +#include #include "ofd_internal.h" @@ -61,85 +62,83 @@ static struct lu_kmem_descr ofd_caches[] = { } }; +static int ofd_connect_to_next(const struct lu_env *env, struct ofd_device *m, + const char *next, struct obd_export **exp) +{ + struct obd_connect_data *data = NULL; + struct obd_device *obd; + int rc; + ENTRY; + + OBD_ALLOC_PTR(data); + if (data == NULL) + GOTO(out, rc = -ENOMEM); + + obd = class_name2obd(next); + if (obd == NULL) { + CERROR("%s: can't locate next device: %s\n", + m->ofd_dt_dev.dd_lu_dev.ld_obd->obd_name, next); + GOTO(out, rc = -ENOTCONN); + } + + data->ocd_connect_flags = OBD_CONNECT_VERSION; + data->ocd_version = LUSTRE_VERSION_CODE; + + rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL); + if (rc) { + CERROR("%s: cannot connect to next dev %s: rc = %d\n", + m->ofd_dt_dev.dd_lu_dev.ld_obd->obd_name, next, rc); + GOTO(out, rc); + } + + m->ofd_dt_dev.dd_lu_dev.ld_site = + m->ofd_osd_exp->exp_obd->obd_lu_dev->ld_site; + LASSERT(m->ofd_dt_dev.dd_lu_dev.ld_site); + m->ofd_osd = lu2dt_dev(m->ofd_osd_exp->exp_obd->obd_lu_dev); + m->ofd_dt_dev.dd_lu_dev.ld_site->ls_top_dev = &m->ofd_dt_dev.dd_lu_dev; + +out: + if (data) + OBD_FREE_PTR(data); + RETURN(rc); +} + static int ofd_stack_init(const struct lu_env *env, struct ofd_device *m, struct lustre_cfg *cfg) { - struct lu_device *ofd_lu = &m->ofd_dt_dev.dd_lu_dev; const char *dev = lustre_cfg_string(cfg, 0); - struct obd_type *type; - struct lu_device_type *ldt; struct lu_device *d; struct ofd_thread_info *info = ofd_info(env); struct lustre_mount_info *lmi; int rc; + char *osdname; ENTRY; - lmi = server_get_mount_2(dev); + lmi = server_get_mount(dev); if (lmi == NULL) { CERROR("Cannot get mount info for %s!\n", dev); RETURN(-ENODEV); } - type = class_get_type(s2lsi(lmi->lmi_sb)->lsi_osd_type); - if (!type) { - CERROR("Unknown type: '%s'\n", - s2lsi(lmi->lmi_sb)->lsi_osd_type); - RETURN(-ENODEV); - } - - rc = lu_env_refill((struct lu_env *)env); - if (rc != 0) { - CERROR("Failure to refill session: '%d'\n", rc); - GOTO(out_type, rc); - } - - ldt = type->typ_lu; - if (ldt == NULL) { - CERROR("type: '%s'\n", s2lsi(lmi->lmi_sb)->lsi_osd_type); - GOTO(out_type, rc = -EINVAL); - } + /* find bottom osd */ + OBD_ALLOC(osdname, MTI_NAME_MAXLEN); + if (osdname == NULL) + RETURN(-ENOMEM); - ldt->ldt_obd_type = type; - d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg); - if (IS_ERR(d)) { - CERROR("Cannot allocate device: '%s'\n", - s2lsi(lmi->lmi_sb)->lsi_osd_type); - GOTO(out_type, rc = -ENODEV); - } + snprintf(osdname, MTI_NAME_MAXLEN, "%s-osd", dev); + rc = ofd_connect_to_next(env, m, osdname, &m->ofd_osd_exp); + OBD_FREE(osdname, MTI_NAME_MAXLEN); + if (rc) + RETURN(rc); - LASSERT(ofd_lu->ld_site); - d->ld_site = ofd_lu->ld_site; + d = m->ofd_osd_exp->exp_obd->obd_lu_dev; + LASSERT(d); + m->ofd_osd = lu2dt_dev(d); snprintf(info->fti_u.name, sizeof(info->fti_u.name), "%s-osd", lustre_cfg_string(cfg, 0)); - type->typ_refcnt++; - rc = ldt->ldt_ops->ldto_device_init(env, d, dev, NULL); - if (rc) { - CERROR("can't init device '%s', rc = %d\n", - s2lsi(lmi->lmi_sb)->lsi_osd_type, rc); - GOTO(out_free, rc); - } - lu_device_get(d); - lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init); - - m->ofd_osd = lu2dt_dev(d); - - /* process setup config */ - rc = d->ld_ops->ldo_process_config(env, d, cfg); - if (rc) - GOTO(out_fini, rc); - - RETURN(rc); - -out_fini: - ldt->ldt_ops->ldto_device_fini(env, d); -out_free: - type->typ_refcnt--; - ldt->ldt_ops->ldto_device_free(env, d); -out_type: - class_put_type(type); RETURN(rc); } @@ -172,12 +171,21 @@ static void ofd_stack_fini(const struct lu_env *env, struct ofd_device *m, top->ld_ops->ldo_process_config(env, top, lcfg); lustre_cfg_free(lcfg); - lu_stack_fini(env, &m->ofd_osd->dd_lu_dev); + lu_site_purge(env, top->ld_site, ~0); + + LASSERT(m->ofd_osd_exp); + obd_disconnect(m->ofd_osd_exp); m->ofd_osd = NULL; EXIT; } +/* For interoperability, see mdt_interop_param[]. */ +static struct cfg_interop_param ofd_interop_param[] = { + { "ost.quota_type", NULL }, + { NULL } +}; + /* used by MGS to process specific configurations */ static int ofd_process_config(const struct lu_env *env, struct lu_device *d, struct lustre_cfg *cfg) @@ -193,6 +201,38 @@ static int ofd_process_config(const struct lu_env *env, struct lu_device *d, case LCFG_PARAM: { struct lprocfs_static_vars lvars; + /* For interoperability */ + struct cfg_interop_param *ptr = NULL; + struct lustre_cfg *old_cfg = NULL; + char *param = NULL; + + param = lustre_cfg_string(cfg, 1); + if (param == NULL) { + CERROR("param is empty\n"); + rc = -EINVAL; + break; + } + + ptr = class_find_old_param(param, ofd_interop_param); + if (ptr != NULL) { + if (ptr->new_param == NULL) { + rc = 0; + CWARN("For interoperability, skip this %s." + " It is obsolete.\n", ptr->old_param); + break; + } + + CWARN("Found old param %s, changed it to %s.\n", + ptr->old_param, ptr->new_param); + + old_cfg = cfg; + cfg = lustre_cfg_rename(old_cfg, ptr->new_param); + if (IS_ERR(cfg)) { + rc = PTR_ERR(cfg); + break; + } + } + lprocfs_ofd_init_vars(&lvars); rc = class_process_proc_param(PARAM_OST, lvars.obd_vars, cfg, d->ld_obd); @@ -292,17 +332,39 @@ static struct lu_object *ofd_object_alloc(const struct lu_env *env, extern int ost_handle(struct ptlrpc_request *req); -static int ofd_start(const struct lu_env *env, struct lu_device *dev) +static int ofd_prepare(const struct lu_env *env, struct lu_device *pdev, + struct lu_device *dev) { + struct ofd_thread_info *info; struct ofd_device *ofd = ofd_dev(dev); + struct obd_device *obd = ofd_obd(ofd); struct lu_device *next = &ofd->ofd_osd->dd_lu_dev; int rc; ENTRY; + rc = lu_env_refill((struct lu_env *)env); + if (rc != 0) { + CERROR("Failure to refill session: '%d'\n", rc); + RETURN(rc); + } + + info = ofd_info_init(env, NULL); + if (info == NULL) + RETURN(-EFAULT); + /* initialize lower device */ rc = next->ld_ops->ldo_prepare(env, dev, next); + target_recovery_init(&ofd->ofd_lut, ost_handle); + LASSERT(obd->obd_no_conn); + spin_lock(&obd->obd_dev_lock); + obd->obd_no_conn = 0; + spin_unlock(&obd->obd_dev_lock); + + if (obd->obd_recovering == 0) + ofd_postrecov(env, ofd); + RETURN(rc); } @@ -321,7 +383,8 @@ static int ofd_recovery_complete(const struct lu_env *env, * precreate request size (see ofd_grant_create() */ ofd_grant_connect(env, dev->ld_obd->obd_self_export, - OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace); + OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace, + false); rc = next->ld_ops->ldo_recovery_complete(env, next); RETURN(rc); } @@ -330,6 +393,7 @@ static struct lu_device_operations ofd_lu_ops = { .ldo_object_alloc = ofd_object_alloc, .ldo_process_config = ofd_process_config, .ldo_recovery_complete = ofd_recovery_complete, + .ldo_prepare = ofd_prepare, }; static int ofd_procfs_init(struct ofd_device *ofd) @@ -364,18 +428,12 @@ static int ofd_procfs_init(struct ofd_device *ofd) lprocfs_counter_init(obd->obd_stats, LPROC_OFD_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes"); - rc = lproc_ofd_attach_seqstat(obd); - if (rc) { - CERROR("%s: create seqstat failed: %d.\n", obd->obd_name, rc); - GOTO(free_obd_stats, rc); - } - entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL); if (IS_ERR(entry)) { rc = PTR_ERR(entry); CERROR("%s: error %d setting up lprocfs for %s\n", obd->obd_name, rc, "exports"); - GOTO(free_obd_stats, rc); + GOTO(obd_cleanup, rc); } obd->obd_proc_exports_entry = entry; @@ -386,30 +444,152 @@ static int ofd_procfs_init(struct ofd_device *ofd) rc = PTR_ERR(entry); CERROR("%s: add proc entry 'clear' failed: %d.\n", obd->obd_name, rc); - GOTO(free_obd_stats, rc); + GOTO(obd_cleanup, rc); } - RETURN(0); -free_obd_stats: - lprocfs_free_obd_stats(obd); + rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST, + ofd_stats_counter_init); + if (rc) + GOTO(remove_entry_clear, rc); + RETURN(0); +remove_entry_clear: + lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry); obd_cleanup: lprocfs_obd_cleanup(obd); + lprocfs_free_obd_stats(obd); + return rc; } -static int ofd_procfs_fini(struct ofd_device *ofd) +static void ofd_procfs_add_brw_stats_symlink(struct ofd_device *ofd) +{ + struct obd_device *obd = ofd_obd(ofd); + struct obd_device *osd_obd = ofd->ofd_osd_exp->exp_obd; + cfs_proc_dir_entry_t *osd_root = osd_obd->obd_type->typ_procroot; + cfs_proc_dir_entry_t *osd_dir; + + osd_dir = lprocfs_srch(osd_root, obd->obd_name); + if (osd_dir == NULL) + return; + + if (lprocfs_srch(osd_dir, "brw_stats") != NULL) + lprocfs_add_symlink("brw_stats", obd->obd_proc_entry, + "../../%s/%s/brw_stats", + osd_root->name, osd_dir->name); + + if (lprocfs_srch(osd_dir, "read_cache_enable") != NULL) + lprocfs_add_symlink("read_cache_enable", obd->obd_proc_entry, + "../../%s/%s/read_cache_enable", + osd_root->name, osd_dir->name); + + if (lprocfs_srch(osd_dir, "readcache_max_filesize") != NULL) + lprocfs_add_symlink("readcache_max_filesize", + obd->obd_proc_entry, + "../../%s/%s/readcache_max_filesize", + osd_root->name, osd_dir->name); + + if (lprocfs_srch(osd_dir, "writethrough_cache_enable") != NULL) + lprocfs_add_symlink("writethrough_cache_enable", + obd->obd_proc_entry, + "../../%s/%s/writethrough_cache_enable", + osd_root->name, osd_dir->name); +} + +static void ofd_procfs_fini(struct ofd_device *ofd) { struct obd_device *obd = ofd_obd(ofd); + lprocfs_remove_proc_entry("writethrough_cache_enable", + obd->obd_proc_entry); + lprocfs_remove_proc_entry("readcache_max_filesize", + obd->obd_proc_entry); + lprocfs_remove_proc_entry("read_cache_enable", obd->obd_proc_entry); + lprocfs_remove_proc_entry("brw_stats", obd->obd_proc_entry); lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry); lprocfs_free_per_client_stats(obd); - lprocfs_free_obd_stats(obd); lprocfs_obd_cleanup(obd); - return 0; + lprocfs_free_obd_stats(obd); + lprocfs_job_stats_fini(obd); } extern int ost_handle(struct ptlrpc_request *req); +int ofd_fid_fini(const struct lu_env *env, struct ofd_device *ofd) +{ + return seq_site_fini(env, &ofd->ofd_seq_site); +} + +int ofd_fid_init(const struct lu_env *env, struct ofd_device *ofd) +{ + struct seq_server_site *ss = &ofd->ofd_seq_site; + struct lu_device *lu = &ofd->ofd_dt_dev.dd_lu_dev; + char *obd_name = ofd_name(ofd); + char *name = NULL; + int rc = 0; + + ss = &ofd->ofd_seq_site; + lu->ld_site->ld_seq_site = ss; + ss->ss_lu = lu->ld_site; + ss->ss_node_id = ofd->ofd_lut.lut_lsd.lsd_osd_index; + + OBD_ALLOC_PTR(ss->ss_server_seq); + if (ss->ss_server_seq == NULL) + GOTO(out_free, rc = -ENOMEM); + + OBD_ALLOC(name, strlen(obd_name) + 10); + if (!name) { + OBD_FREE_PTR(ss->ss_server_seq); + ss->ss_server_seq = NULL; + GOTO(out_free, rc = -ENOMEM); + } + + rc = seq_server_init(ss->ss_server_seq, ofd->ofd_osd, obd_name, + LUSTRE_SEQ_SERVER, ss, env); + if (rc) { + CERROR("%s : seq server init error %d\n", obd_name, rc); + GOTO(out_free, rc); + } + ss->ss_server_seq->lss_space.lsr_index = ss->ss_node_id; + + OBD_ALLOC_PTR(ss->ss_client_seq); + if (ss->ss_client_seq == NULL) + GOTO(out_free, -ENOMEM); + + snprintf(name, strlen(obd_name) + 6, "%p-super", obd_name); + rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_DATA, + name, NULL); + if (rc) { + CERROR("%s : seq client init error %d\n", obd_name, rc); + GOTO(out_free, rc); + } + OBD_FREE(name, strlen(obd_name) + 10); + name = NULL; + + rc = seq_server_set_cli(ss->ss_server_seq, ss->ss_client_seq, env); + +out_free: + if (rc) { + if (ss->ss_server_seq) { + seq_server_fini(ss->ss_server_seq, env); + OBD_FREE_PTR(ss->ss_server_seq); + ss->ss_server_seq = NULL; + } + + if (ss->ss_client_seq) { + seq_client_fini(ss->ss_client_seq); + OBD_FREE_PTR(ss->ss_client_seq); + ss->ss_client_seq = NULL; + } + + if (name) { + OBD_FREE(name, strlen(obd_name) + 10); + name = NULL; + } + } + + return rc; +} + static int ofd_init0(const struct lu_env *env, struct ofd_device *m, struct lu_device_type *ldt, struct lustre_cfg *cfg) { @@ -436,27 +616,28 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, m->ofd_fmd_max_num = OFD_FMD_MAX_NUM_DEFAULT; m->ofd_fmd_max_age = OFD_FMD_MAX_AGE_DEFAULT; - cfs_spin_lock_init(&m->ofd_flags_lock); + spin_lock_init(&m->ofd_flags_lock); m->ofd_raid_degraded = 0; m->ofd_syncjournal = 0; ofd_slc_set(m); m->ofd_grant_compat_disable = 0; /* statfs data */ - cfs_spin_lock_init(&m->ofd_osfs_lock); + spin_lock_init(&m->ofd_osfs_lock); m->ofd_osfs_age = cfs_time_shift_64(-1000); m->ofd_osfs_unstable = 0; m->ofd_statfs_inflight = 0; m->ofd_osfs_inflight = 0; /* grant data */ - cfs_spin_lock_init(&m->ofd_grant_lock); + spin_lock_init(&m->ofd_grant_lock); m->ofd_tot_dirty = 0; m->ofd_tot_granted = 0; m->ofd_tot_pending = 0; - m->ofd_max_group = 0; + m->ofd_seq_count = 0; - cfs_rwlock_init(&obd->u.filter.fo_sptlrpc_lock); + spin_lock_init(&m->ofd_batch_lock); + rwlock_init(&obd->u.filter.fo_sptlrpc_lock); sptlrpc_rule_set_init(&obd->u.filter.fo_sptlrpc_rset); obd->u.filter.fo_fl_oss_capa = 0; @@ -477,7 +658,9 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, } /* No connection accepted until configurations will finish */ + spin_lock(&obd->obd_dev_lock); obd->obd_no_conn = 1; + spin_unlock(&obd->obd_dev_lock); obd->obd_replayable = 1; if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) { char *str = lustre_cfg_string(cfg, 4); @@ -492,17 +675,14 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, if (info == NULL) RETURN(-EFAULT); - rc = lu_site_init(&m->ofd_site, &m->ofd_dt_dev.dd_lu_dev); - if (rc) - GOTO(err_fini_proc, rc); - m->ofd_site.ls_top_dev = &m->ofd_dt_dev.dd_lu_dev; - rc = ofd_stack_init(env, m, cfg); if (rc) { CERROR("Can't init device stack, rc %d\n", rc); - GOTO(err_lu_site, rc); + GOTO(err_fini_proc, rc); } + ofd_procfs_add_brw_stats_symlink(m); + /* populate cached statfs data */ osfs = &ofd_info(env)->fti_u.osfs; rc = ofd_statfs_internal(env, m, osfs, 0, NULL); @@ -515,9 +695,14 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, obd->obd_name, osfs->os_bsize); GOTO(err_fini_stack, rc = -EPROTO); } - m->ofd_blockbits = cfs_fls(osfs->os_bsize) - 1; + m->ofd_blockbits = fls(osfs->os_bsize) - 1; - snprintf(info->fti_u.name, sizeof(info->fti_u.name), "filter-%p", m); + m->ofd_precreate_batch = OFD_PRECREATE_BATCH_DEFAULT; + if (osfs->os_bsize * osfs->os_blocks < OFD_PRECREATE_SMALL_FS) + m->ofd_precreate_batch = OFD_PRECREATE_BATCH_SMALL; + + snprintf(info->fti_u.name, sizeof(info->fti_u.name), "%s-%s", + "filter"/*LUSTRE_OST_NAME*/, obd->obd_uuid.uuid); m->ofd_namespace = ldlm_namespace_new(obd, info->fti_u.name, LDLM_NAMESPACE_SERVER, LDLM_NAMESPACE_GREEDY, @@ -543,11 +728,7 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, m->ofd_grant_ratio = ofd_grant_ratio_conv(m->ofd_dt_conf.ddp_grant_reserved); - rc = ofd_start(env, &m->ofd_dt_dev.dd_lu_dev); - if (rc) - GOTO(err_fini_stack, rc); - - rc = lut_init(env, &m->ofd_lut, obd, m->ofd_osd); + rc = tgt_init(env, &m->ofd_lut, obd, m->ofd_osd); if (rc) GOTO(err_free_ns, rc); @@ -555,25 +736,14 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, if (rc) GOTO(err_fini_lut, rc); - target_recovery_init(&m->ofd_lut, ost_handle); - - rc = lu_site_init_finish(&m->ofd_site); - if (rc) - GOTO(err_fs_cleanup, rc); - RETURN(0); -err_fs_cleanup: - target_recovery_fini(obd); - ofd_fs_cleanup(env, m); err_fini_lut: - lut_fini(env, &m->ofd_lut); + tgt_fini(env, &m->ofd_lut); err_free_ns: ldlm_namespace_free(m->ofd_namespace, 0, obd->obd_force); obd->obd_namespace = m->ofd_namespace = NULL; err_fini_stack: ofd_stack_fini(env, m, &m->ofd_osd->dd_lu_dev); -err_lu_site: - lu_site_fini(&m->ofd_site); err_fini_proc: ofd_procfs_fini(m); return rc; @@ -588,7 +758,7 @@ static void ofd_fini(const struct lu_env *env, struct ofd_device *m) obd_exports_barrier(obd); obd_zombie_barrier(); - lut_fini(env, &m->ofd_lut); + tgt_fini(env, &m->ofd_lut); ofd_fs_cleanup(env, m); ofd_free_capa_keys(m); @@ -600,10 +770,10 @@ static void ofd_fini(const struct lu_env *env, struct ofd_device *m) d->ld_obd->obd_namespace = m->ofd_namespace = NULL; } - ofd_stack_fini(env, m, m->ofd_site.ls_top_dev); - lu_site_fini(&m->ofd_site); + ofd_stack_fini(env, m, &m->ofd_dt_dev.dd_lu_dev); ofd_procfs_fini(m); LASSERT(cfs_atomic_read(&d->ld_ref) == 0); + server_put_mount(obd->obd_name, NULL); EXIT; }