X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Ffid%2Ffid_handler.c;h=caea0dc6fac9c3f297b92231fb2d0aa69e2d5981;hp=140e1547f98632e0f3db1cadb536d105e8e2ea79;hb=919b358468e13a0ba8719bd4a4c135e11017dd8b;hpb=d016a086b68ca4af2dcbfefc3917b9291efd8d62 diff --git a/lustre/fid/fid_handler.c b/lustre/fid/fid_handler.c index 140e154..caea0dc 100644 --- a/lustre/fid/fid_handler.c +++ b/lustre/fid/fid_handler.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -29,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Whamcloud, Inc. + * Copyright (c) 2011, 2013, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -42,21 +40,12 @@ * Author: Yury Umanets */ -#ifndef EXPORT_SYMTAB -# define EXPORT_SYMTAB -#endif #define DEBUG_SUBSYSTEM S_FID -#ifdef __KERNEL__ -# include -# include -#else /* __KERNEL__ */ -# include -#endif - +#include +#include #include #include -#include #include #include #include @@ -64,7 +53,8 @@ #include #include "fid_internal.h" -#ifdef __KERNEL__ +static void seq_server_proc_fini(struct lu_server_seq *seq); + /* Assigns client to sequence controller node. */ int seq_server_set_cli(struct lu_server_seq *seq, struct lu_client_seq *cli, @@ -77,7 +67,7 @@ int seq_server_set_cli(struct lu_server_seq *seq, * Ask client for new range, assign that range to ->seq_space and write * seq state to backing store should be atomic. */ - cfs_mutex_lock(&seq->lss_mutex); + mutex_lock(&seq->lss_mutex); if (cli == NULL) { CDEBUG(D_INFO, "%s: Detached sequence client %s\n", @@ -86,20 +76,20 @@ int seq_server_set_cli(struct lu_server_seq *seq, GOTO(out_up, rc = 0); } - if (seq->lss_cli != NULL) { - CERROR("%s: Sequence controller is already " - "assigned\n", seq->lss_name); - GOTO(out_up, rc = -EINVAL); - } + if (seq->lss_cli != NULL) { + CDEBUG(D_HA, "%s: Sequence controller is already " + "assigned\n", seq->lss_name); + GOTO(out_up, rc = -EEXIST); + } CDEBUG(D_INFO, "%s: Attached sequence controller %s\n", seq->lss_name, cli->lcs_name); - seq->lss_cli = cli; - cli->lcs_space.lsr_index = seq->lss_site->ms_node_id; - EXIT; + seq->lss_cli = cli; + cli->lcs_space.lsr_index = seq->lss_site->ss_node_id; + EXIT; out_up: - cfs_mutex_unlock(&seq->lss_mutex); + mutex_unlock(&seq->lss_mutex); return rc; } EXPORT_SYMBOL(seq_server_set_cli); @@ -127,26 +117,26 @@ static int __seq_server_alloc_super(struct lu_server_seq *seq, struct lu_seq_range *out, const struct lu_env *env) { - struct lu_seq_range *space = &seq->lss_space; - int rc; - ENTRY; + struct lu_seq_range *space = &seq->lss_space; + int rc; + ENTRY; - LASSERT(range_is_sane(space)); + LASSERT(range_is_sane(space)); - if (range_is_exhausted(space)) { - CERROR("%s: Sequences space is exhausted\n", - seq->lss_name); - RETURN(-ENOSPC); - } else { - range_alloc(out, space, seq->lss_width); - } + if (range_is_exhausted(space)) { + CERROR("%s: Sequences space is exhausted\n", + seq->lss_name); + RETURN(-ENOSPC); + } else { + range_alloc(out, space, seq->lss_width); + } - rc = seq_store_update(env, seq, out, 1 /* sync */); + rc = seq_store_update(env, seq, out, 1 /* sync */); - CDEBUG(D_INFO, "%s: super-sequence allocation rc = %d " - DRANGE"\n", seq->lss_name, rc, PRANGE(out)); + LCONSOLE_INFO("%s: super-sequence allocation rc = %d " DRANGE"\n", + seq->lss_name, rc, PRANGE(out)); - RETURN(rc); + RETURN(rc); } int seq_server_alloc_super(struct lu_server_seq *seq, @@ -156,13 +146,48 @@ int seq_server_alloc_super(struct lu_server_seq *seq, int rc; ENTRY; - cfs_mutex_lock(&seq->lss_mutex); + mutex_lock(&seq->lss_mutex); rc = __seq_server_alloc_super(seq, out, env); - cfs_mutex_unlock(&seq->lss_mutex); + mutex_unlock(&seq->lss_mutex); RETURN(rc); } +int seq_server_alloc_spec(struct lu_server_seq *seq, + struct lu_seq_range *spec, + const struct lu_env *env) +{ + struct lu_seq_range *space = &seq->lss_space; + int rc = -ENOSPC; + ENTRY; + + /* + * In some cases (like recovery after a disaster) + * we may need to allocate sequences manually + * Notice some sequences can be lost if requested + * range doesn't start at the beginning of current + * free space. Also notice it's not possible now + * to allocate sequences out of natural order. + */ + if (spec->lsr_start >= spec->lsr_end) + RETURN(-EINVAL); + if (spec->lsr_flags != LU_SEQ_RANGE_MDT && + spec->lsr_flags != LU_SEQ_RANGE_OST) + RETURN(-EINVAL); + + mutex_lock(&seq->lss_mutex); + if (spec->lsr_start >= space->lsr_start) { + space->lsr_start = spec->lsr_end; + rc = seq_store_update(env, seq, spec, 1 /* sync */); + + LCONSOLE_INFO("%s: "DRANGE" sequences allocated: rc = %d \n", + seq->lss_name, PRANGE(spec), rc); + } + mutex_unlock(&seq->lss_mutex); + + RETURN(rc); +} + static int __seq_set_init(const struct lu_env *env, struct lu_server_seq *seq) { @@ -209,7 +234,7 @@ static int range_alloc_set(const struct lu_env *env, if (range_is_exhausted(loset)) { /* reached high water mark. */ - struct lu_device *dev = seq->lss_site->ms_lu.ls_top_dev; + struct lu_device *dev = seq->lss_site->ss_lu->ls_top_dev; int obd_num_clients = dev->ld_obd->obd_num_exports; __u64 set_sz; @@ -240,40 +265,44 @@ static int __seq_server_alloc_meta(struct lu_server_seq *seq, struct lu_seq_range *out, const struct lu_env *env) { - struct lu_seq_range *space = &seq->lss_space; - int rc = 0; - - ENTRY; - - LASSERT(range_is_sane(space)); - - /* Check if available space ends and allocate new super seq */ - if (range_is_exhausted(space)) { - if (!seq->lss_cli) { - CERROR("%s: No sequence controller is attached.\n", - seq->lss_name); - RETURN(-ENODEV); - } - - rc = seq_client_alloc_super(seq->lss_cli, env); - if (rc) { - CERROR("%s: Can't allocate super-sequence, rc %d\n", - seq->lss_name, rc); - RETURN(rc); - } - - /* Saving new range to allocation space. */ - *space = seq->lss_cli->lcs_space; - LASSERT(range_is_sane(space)); - } - - rc = range_alloc_set(env, out, seq); - if (rc == 0) { - CDEBUG(D_INFO, "%s: Allocated meta-sequence " - DRANGE"\n", seq->lss_name, PRANGE(out)); - } - - RETURN(rc); + struct lu_seq_range *space = &seq->lss_space; + int rc = 0; + + ENTRY; + + LASSERT(range_is_sane(space)); + + /* Check if available space ends and allocate new super seq */ + if (range_is_exhausted(space)) { + if (!seq->lss_cli) { + CERROR("%s: No sequence controller is attached.\n", + seq->lss_name); + RETURN(-ENODEV); + } + + rc = seq_client_alloc_super(seq->lss_cli, env); + if (rc) { + CERROR("%s: Can't allocate super-sequence, rc %d\n", + seq->lss_name, rc); + RETURN(rc); + } + + /* Saving new range to allocation space. */ + *space = seq->lss_cli->lcs_space; + LASSERT(range_is_sane(space)); + } + + rc = range_alloc_set(env, out, seq); + if (rc != 0) { + CERROR("%s: Allocated meta-sequence failed: rc = %d\n", + seq->lss_name, rc); + RETURN(rc); + } + + CDEBUG(D_INFO, "%s: Allocated meta-sequence " DRANGE"\n", + seq->lss_name, PRANGE(out)); + + RETURN(rc); } int seq_server_alloc_meta(struct lu_server_seq *seq, @@ -283,9 +312,9 @@ int seq_server_alloc_meta(struct lu_server_seq *seq, int rc; ENTRY; - cfs_mutex_lock(&seq->lss_mutex); + mutex_lock(&seq->lss_mutex); rc = __seq_server_alloc_meta(seq, out, env); - cfs_mutex_unlock(&seq->lss_mutex); + mutex_unlock(&seq->lss_mutex); RETURN(rc); } @@ -295,130 +324,88 @@ static int seq_server_handle(struct lu_site *site, const struct lu_env *env, __u32 opc, struct lu_seq_range *out) { - int rc; - struct md_site *mite; - ENTRY; - - mite = lu_site2md(site); - switch (opc) { - case SEQ_ALLOC_META: - if (!mite->ms_server_seq) { - CERROR("Sequence server is not " - "initialized\n"); - RETURN(-EINVAL); - } - rc = seq_server_alloc_meta(mite->ms_server_seq, out, env); - break; - case SEQ_ALLOC_SUPER: - if (!mite->ms_control_seq) { - CERROR("Sequence controller is not " - "initialized\n"); - RETURN(-EINVAL); - } - rc = seq_server_alloc_super(mite->ms_control_seq, out, env); - break; - default: - rc = -EINVAL; - break; - } - - RETURN(rc); + int rc; + struct seq_server_site *ss_site; + ENTRY; + + ss_site = lu_site2seq(site); + + switch (opc) { + case SEQ_ALLOC_META: + if (!ss_site->ss_server_seq) { + CERROR("Sequence server is not " + "initialized\n"); + RETURN(-EINVAL); + } + rc = seq_server_alloc_meta(ss_site->ss_server_seq, out, env); + break; + case SEQ_ALLOC_SUPER: + if (!ss_site->ss_control_seq) { + CERROR("Sequence controller is not " + "initialized\n"); + RETURN(-EINVAL); + } + rc = seq_server_alloc_super(ss_site->ss_control_seq, out, env); + break; + default: + rc = -EINVAL; + break; + } + + RETURN(rc); } -static int seq_req_handle(struct ptlrpc_request *req, - const struct lu_env *env, - struct seq_thread_info *info) +static int seq_handler(struct tgt_session_info *tsi) { - struct lu_seq_range *out, *tmp; - struct lu_site *site; - int rc = -EPROTO; - __u32 *opc; - ENTRY; + struct lu_seq_range *out, *tmp; + struct lu_site *site; + int rc; + __u32 *opc; - LASSERT(!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)); - site = req->rq_export->exp_obd->obd_lu_dev->ld_site; - LASSERT(site != NULL); + ENTRY; - rc = req_capsule_server_pack(info->sti_pill); - if (rc) - RETURN(err_serious(rc)); + LASSERT(!(lustre_msg_get_flags(tgt_ses_req(tsi)->rq_reqmsg) & MSG_REPLAY)); + site = tsi->tsi_exp->exp_obd->obd_lu_dev->ld_site; + LASSERT(site != NULL); - opc = req_capsule_client_get(info->sti_pill, &RMF_SEQ_OPC); - if (opc != NULL) { - out = req_capsule_server_get(info->sti_pill, &RMF_SEQ_RANGE); - if (out == NULL) - RETURN(err_serious(-EPROTO)); + opc = req_capsule_client_get(tsi->tsi_pill, &RMF_SEQ_OPC); + if (opc != NULL) { + out = req_capsule_server_get(tsi->tsi_pill, &RMF_SEQ_RANGE); + if (out == NULL) + RETURN(err_serious(-EPROTO)); - tmp = req_capsule_client_get(info->sti_pill, &RMF_SEQ_RANGE); + tmp = req_capsule_client_get(tsi->tsi_pill, &RMF_SEQ_RANGE); - /* seq client passed mdt id, we need to pass that using out - * range parameter */ + /* seq client passed mdt id, we need to pass that using out + * range parameter */ - out->lsr_index = tmp->lsr_index; - out->lsr_flags = tmp->lsr_flags; - rc = seq_server_handle(site, env, *opc, out); - } else - rc = err_serious(-EPROTO); + out->lsr_index = tmp->lsr_index; + out->lsr_flags = tmp->lsr_flags; + rc = seq_server_handle(site, tsi->tsi_env, *opc, out); + } else { + rc = err_serious(-EPROTO); + } - RETURN(rc); + RETURN(rc); } +struct tgt_handler seq_handlers[] = { +TGT_SEQ_HDL(HABEO_REFERO, SEQ_QUERY, seq_handler), +}; +EXPORT_SYMBOL(seq_handlers); + /* context key constructor/destructor: seq_key_init, seq_key_fini */ LU_KEY_INIT_FINI(seq, struct seq_thread_info); /* context key: seq_thread_key */ -LU_CONTEXT_KEY_DEFINE(seq, LCT_MD_THREAD); - -static void seq_thread_info_init(struct ptlrpc_request *req, - struct seq_thread_info *info) -{ - info->sti_pill = &req->rq_pill; - /* Init request capsule */ - req_capsule_init(info->sti_pill, req, RCL_SERVER); - req_capsule_set(info->sti_pill, &RQF_SEQ_QUERY); -} +LU_CONTEXT_KEY_DEFINE(seq, LCT_MD_THREAD | LCT_DT_THREAD); -static void seq_thread_info_fini(struct seq_thread_info *info) -{ - req_capsule_fini(info->sti_pill); -} - -static int seq_handle(struct ptlrpc_request *req) -{ - const struct lu_env *env; - struct seq_thread_info *info; - int rc; - - env = req->rq_svc_thread->t_env; - LASSERT(env != NULL); - - info = lu_context_key_get(&env->le_ctx, &seq_thread_key); - LASSERT(info != NULL); +extern const struct file_operations seq_fld_proc_seq_fops; - seq_thread_info_init(req, info); - rc = seq_req_handle(req, env, info); - /* XXX: we don't need replay but MDT assign transno in any case, - * remove it manually before reply*/ - lustre_msg_set_transno(req->rq_repmsg, 0); - seq_thread_info_fini(info); - - return rc; -} - -/* - * Entry point for handling FLD RPCs called from MDT. - */ -int seq_query(struct com_thread_info *info) -{ - return seq_handle(info->cti_pill->rc_req); -} -EXPORT_SYMBOL(seq_query); - -static void seq_server_proc_fini(struct lu_server_seq *seq); - -#ifdef LPROCFS static int seq_server_proc_init(struct lu_server_seq *seq) { +#ifdef LPROCFS + int rc; ENTRY; @@ -438,15 +425,29 @@ static int seq_server_proc_init(struct lu_server_seq *seq) GOTO(out_cleanup, rc); } + if (seq->lss_type == LUSTRE_SEQ_CONTROLLER) { + rc = lprocfs_seq_create(seq->lss_proc_dir, "fldb", 0644, + &seq_fld_proc_seq_fops, seq); + if (rc) { + CERROR("%s: Can't create fldb for sequence manager " + "proc: rc = %d\n", seq->lss_name, rc); + GOTO(out_cleanup, rc); + } + } + RETURN(0); out_cleanup: seq_server_proc_fini(seq); return rc; +#else /* LPROCFS */ + return 0; +#endif } static void seq_server_proc_fini(struct lu_server_seq *seq) { +#ifdef LPROCFS ENTRY; if (seq->lss_proc_dir != NULL) { if (!IS_ERR(seq->lss_proc_dir)) @@ -454,43 +455,45 @@ static void seq_server_proc_fini(struct lu_server_seq *seq) seq->lss_proc_dir = NULL; } EXIT; +#endif /* LPROCFS */ } -#else -static int seq_server_proc_init(struct lu_server_seq *seq) -{ - return 0; -} - -static void seq_server_proc_fini(struct lu_server_seq *seq) -{ - return; -} -#endif - int seq_server_init(struct lu_server_seq *seq, - struct dt_device *dev, - const char *prefix, - enum lu_mgr_type type, - struct md_site *ms, - const struct lu_env *env) + struct dt_device *dev, + const char *prefix, + enum lu_mgr_type type, + struct seq_server_site *ss, + const struct lu_env *env) { - int rc, is_srv = (type == LUSTRE_SEQ_SERVER); - ENTRY; - - LASSERT(dev != NULL); - LASSERT(prefix != NULL); - - seq->lss_cli = NULL; - seq->lss_type = type; - seq->lss_site = ms; - range_init(&seq->lss_space); + int rc, is_srv = (type == LUSTRE_SEQ_SERVER); + ENTRY; + + LASSERT(dev != NULL); + LASSERT(prefix != NULL); + LASSERT(ss != NULL); + LASSERT(ss->ss_lu != NULL); + + /* A compile-time check for FIDs that used to be in lustre_idl.h + * but is moved here to remove CLASSERT/LASSERT in that header. + * Check all lu_fid fields are converted in fid_cpu_to_le() and friends + * and that there is no padding added by compiler to the struct. */ + { + struct lu_fid tst; + + CLASSERT(sizeof(tst) == sizeof(tst.f_seq) + + sizeof(tst.f_oid) + sizeof(tst.f_ver)); + } + + seq->lss_cli = NULL; + seq->lss_type = type; + seq->lss_site = ss; + range_init(&seq->lss_space); range_init(&seq->lss_lowater_set); range_init(&seq->lss_hiwater_set); seq->lss_set_width = LUSTRE_SEQ_BATCH_WIDTH; - cfs_mutex_init(&seq->lss_mutex); + mutex_init(&seq->lss_mutex); seq->lss_width = is_srv ? LUSTRE_SEQ_META_WIDTH : LUSTRE_SEQ_SUPER_WIDTH; @@ -510,10 +513,11 @@ int seq_server_init(struct lu_server_seq *seq, LUSTRE_SEQ_ZERO_RANGE: LUSTRE_SEQ_SPACE_RANGE; - seq->lss_space.lsr_index = ms->ms_node_id; - CDEBUG(D_INFO, "%s: No data found " - "on store. Initialize space\n", - seq->lss_name); + LASSERT(ss != NULL); + seq->lss_space.lsr_index = ss->ss_node_id; + LCONSOLE_INFO("%s: No data found " + "on store. Initialize space\n", + seq->lss_name); rc = seq_store_update(env, seq, NULL, 0); if (rc) { @@ -557,51 +561,40 @@ void seq_server_fini(struct lu_server_seq *seq, } EXPORT_SYMBOL(seq_server_fini); -cfs_proc_dir_entry_t *seq_type_proc_dir = NULL; - -static struct lu_local_obj_desc llod_seq_srv = { - .llod_name = LUSTRE_SEQ_SRV_NAME, - .llod_oid = FID_SEQ_SRV_OID, - .llod_is_index = 0, -}; - -static struct lu_local_obj_desc llod_seq_ctl = { - .llod_name = LUSTRE_SEQ_CTL_NAME, - .llod_oid = FID_SEQ_CTL_OID, - .llod_is_index = 0, -}; - -static int __init fid_mod_init(void) +int seq_site_fini(const struct lu_env *env, struct seq_server_site *ss) { - seq_type_proc_dir = lprocfs_register(LUSTRE_SEQ_NAME, - proc_lustre_root, - NULL, NULL); - if (IS_ERR(seq_type_proc_dir)) - return PTR_ERR(seq_type_proc_dir); - - llo_local_obj_register(&llod_seq_srv); - llo_local_obj_register(&llod_seq_ctl); - - LU_CONTEXT_KEY_INIT(&seq_thread_key); - lu_context_key_register(&seq_thread_key); - return 0; + if (ss == NULL) + RETURN(0); + + 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_control_seq) { + seq_server_fini(ss->ss_control_seq, env); + OBD_FREE_PTR(ss->ss_control_seq); + ss->ss_control_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; + } + + RETURN(0); } +EXPORT_SYMBOL(seq_site_fini); -static void __exit fid_mod_exit(void) +int fid_server_mod_init(void) { - llo_local_obj_unregister(&llod_seq_srv); - llo_local_obj_unregister(&llod_seq_ctl); - - lu_context_key_degister(&seq_thread_key); - if (seq_type_proc_dir != NULL && !IS_ERR(seq_type_proc_dir)) { - lprocfs_remove(&seq_type_proc_dir); - seq_type_proc_dir = NULL; - } + LU_CONTEXT_KEY_INIT(&seq_thread_key); + return lu_context_key_register(&seq_thread_key); } -MODULE_AUTHOR("Sun Microsystems, Inc. "); -MODULE_DESCRIPTION("Lustre FID Module"); -MODULE_LICENSE("GPL"); - -cfs_module(fid, "0.1.0", fid_mod_init, fid_mod_exit); -#endif +void fid_server_mod_exit(void) +{ + lu_context_key_degister(&seq_thread_key); +}