X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ffid%2Ffid_store.c;h=9edd13c0c97503bdb17e5aebacc9d444c615f3de;hb=ac5044566b97c7f6881bed817c2ed9752a0c6d63;hp=648fe865aa85a20ceba408c22427fcac1317f394;hpb=69aab7682269b2820b43354abc13fc5ba853e1d0;p=fs%2Flustre-release.git diff --git a/lustre/fid/fid_store.c b/lustre/fid/fid_store.c index 648fe86..9edd13c 100644 --- a/lustre/fid/fid_store.c +++ b/lustre/fid/fid_store.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2012, Whamcloud, Inc. + * Copyright (c) 2011, 2014, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -42,24 +42,13 @@ #define DEBUG_SUBSYSTEM S_FID -#ifdef __KERNEL__ -# include -# include -#else /* __KERNEL__ */ -# include -#endif - -#include -#include +#include #include -#include #include -#include #include +#include #include "fid_internal.h" -#ifdef __KERNEL__ - static struct lu_buf *seq_store_buf(struct seq_thread_info *info) { struct lu_buf *buf; @@ -88,26 +77,6 @@ void seq_update_cb(struct lu_env *env, struct thandle *th, OBD_FREE_PTR(ccb); } -struct thandle *seq_store_trans_create(struct lu_server_seq *seq, - const struct lu_env *env) -{ - struct dt_device *dt_dev; - - dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev); - return dt_trans_create(env, dt_dev); -} - -int seq_store_trans_start(struct lu_server_seq *seq, const struct lu_env *env, - struct thandle *th) -{ - struct dt_device *dt_dev; - ENTRY; - - dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev); - - return dt_trans_start(env, dt_dev, th); -} - int seq_update_cb_add(struct thandle *th, struct lu_server_seq *seq) { struct seq_update_callback *ccb; @@ -123,9 +92,8 @@ int seq_update_cb_add(struct thandle *th, struct lu_server_seq *seq) dcb = &ccb->suc_cb; dcb->dcb_func = seq_update_cb; - CFS_INIT_LIST_HEAD(&dcb->dcb_linkage); - strncpy(dcb->dcb_name, "seq_update_cb", MAX_COMMIT_CB_STR_LEN); - dcb->dcb_name[MAX_COMMIT_CB_STR_LEN - 1] = '\0'; + INIT_LIST_HEAD(&dcb->dcb_linkage); + strlcpy(dcb->dcb_name, "seq_update_cb", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) @@ -133,106 +101,67 @@ int seq_update_cb_add(struct thandle *th, struct lu_server_seq *seq) return rc; } -int seq_declare_store_write(struct lu_server_seq *seq, - const struct lu_env *env, - struct thandle *th) -{ - struct dt_object *dt_obj = seq->lss_obj; - int rc; - ENTRY; - - rc = dt_obj->do_body_ops->dbo_declare_write(env, dt_obj, - sizeof(struct lu_seq_range), - 0, th); - return rc; -} - /* This function implies that caller takes care about locking. */ -int seq_store_write(struct lu_server_seq *seq, - const struct lu_env *env, - struct thandle *th) -{ - struct dt_object *dt_obj = seq->lss_obj; - struct seq_thread_info *info; - loff_t pos = 0; - int rc; - ENTRY; - - info = lu_context_key_get(&env->le_ctx, &seq_thread_key); - LASSERT(info != NULL); - - /* Store ranges in le format. */ - range_cpu_to_le(&info->sti_space, &seq->lss_space); - - rc = dt_obj->do_body_ops->dbo_write(env, dt_obj, - seq_store_buf(info), - &pos, th, BYPASS_CAPA, 1); - if (rc == sizeof(info->sti_space)) { - CDEBUG(D_INFO, "%s: Space - "DRANGE"\n", - seq->lss_name, PRANGE(&seq->lss_space)); - rc = 0; - } else if (rc >= 0) { - rc = -EIO; - } - - - RETURN(rc); -} - int seq_store_update(const struct lu_env *env, struct lu_server_seq *seq, struct lu_seq_range *out, int sync) { - struct dt_device *dt_dev; - struct thandle *th; - int rc; - ENTRY; - - dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev); + struct dt_device *dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev); + struct seq_thread_info *info; + struct thandle *th; + loff_t pos = 0; + int rc; - th = seq_store_trans_create(seq, env); - if (IS_ERR(th)) - RETURN(PTR_ERR(th)); + info = lu_context_key_get(&env->le_ctx, &seq_thread_key); + LASSERT(info != NULL); - rc = seq_declare_store_write(seq, env, th); - if (rc) - GOTO(exit, rc); + th = dt_trans_create(env, dt_dev); + if (IS_ERR(th)) + RETURN(PTR_ERR(th)); - if (out != NULL) { - rc = fld_declare_server_create(seq->lss_site->ms_server_fld, - env, th); - if (rc) - GOTO(exit, rc); - } + /* Store ranges in le format. */ + range_cpu_to_le(&info->sti_space, &seq->lss_space); - rc = seq_store_trans_start(seq, env, th); - if (rc) - GOTO(exit, rc); - - rc = seq_store_write(seq, env, th); - if (rc) { - CERROR("%s: Can't write space data, rc %d\n", - seq->lss_name, rc); - GOTO(exit,rc); - } else if (out != NULL) { - rc = fld_server_create(seq->lss_site->ms_server_fld, - env, out, th); - if (rc) { - CERROR("%s: Can't Update fld database, rc %d\n", - seq->lss_name, rc); - GOTO(exit,rc); - } - } + rc = dt_declare_record_write(env, seq->lss_obj, + seq_store_buf(info), 0, th); + if (rc) + GOTO(exit, rc); - /* next sequence update will need sync until this update is committed - * in case of sync operation this is not needed obviously */ - if (!sync) - /* if callback can't be added then sync always */ - sync = !!seq_update_cb_add(th, seq); + if (out != NULL) { + rc = fld_declare_server_create(env, + seq->lss_site->ss_server_fld, + out, th); + if (rc) + GOTO(exit, rc); + } - th->th_sync |= sync; + rc = dt_trans_start_local(env, dt_dev, th); + if (rc) + GOTO(exit, rc); + + rc = dt_record_write(env, seq->lss_obj, seq_store_buf(info), &pos, th); + if (rc) { + CERROR("%s: Can't write space data, rc %d\n", + seq->lss_name, rc); + GOTO(exit, rc); + } else if (out != NULL) { + rc = fld_server_create(env, seq->lss_site->ss_server_fld, out, + th); + if (rc) { + CERROR("%s: Can't Update fld database, rc %d\n", + seq->lss_name, rc); + GOTO(exit, rc); + } + } + /* next sequence update will need sync until this update is committed + * in case of sync operation this is not needed obviously */ + if (!sync) + /* if callback can't be added then sync always */ + sync = !!seq_update_cb_add(th, seq); + + th->th_sync |= sync; exit: - dt_trans_stop(env, dt_dev, th); - return rc; + dt_trans_stop(env, dt_dev, th); + return rc; } /* @@ -242,7 +171,6 @@ exit: int seq_store_read(struct lu_server_seq *seq, const struct lu_env *env) { - struct dt_object *dt_obj = seq->lss_obj; struct seq_thread_info *info; loff_t pos = 0; int rc; @@ -251,8 +179,7 @@ int seq_store_read(struct lu_server_seq *seq, info = lu_context_key_get(&env->le_ctx, &seq_thread_key); LASSERT(info != NULL); - rc = dt_obj->do_body_ops->dbo_read(env, dt_obj, seq_store_buf(info), - &pos, BYPASS_CAPA); + rc = dt_read(env, seq->lss_obj, seq_store_buf(info), &pos); if (rc == sizeof(info->sti_space)) { range_le_to_cpu(&seq->lss_space, &info->sti_space); @@ -261,7 +188,7 @@ int seq_store_read(struct lu_server_seq *seq, rc = 0; } else if (rc == 0) { rc = -ENODATA; - } else if (rc >= 0) { + } else if (rc > 0) { CERROR("%s: Read only %d bytes of %d\n", seq->lss_name, rc, (int)sizeof(info->sti_space)); rc = -EIO; @@ -275,15 +202,27 @@ int seq_store_init(struct lu_server_seq *seq, struct dt_device *dt) { struct dt_object *dt_obj; - struct lu_fid fid; + struct lu_fid fid; + struct lu_attr attr; + struct dt_object_format dof; const char *name; int rc; ENTRY; - name = seq->lss_type == LUSTRE_SEQ_SERVER ? - LUSTRE_SEQ_SRV_NAME : LUSTRE_SEQ_CTL_NAME; + name = seq->lss_type == LUSTRE_SEQ_SERVER ? + LUSTRE_SEQ_SRV_NAME : LUSTRE_SEQ_CTL_NAME; + + if (seq->lss_type == LUSTRE_SEQ_SERVER) + lu_local_obj_fid(&fid, FID_SEQ_SRV_OID); + else + lu_local_obj_fid(&fid, FID_SEQ_CTL_OID); + + memset(&attr, 0, sizeof(attr)); + attr.la_valid = LA_MODE; + attr.la_mode = S_IFREG | 0666; + dof.dof_type = DFT_REGULAR; - dt_obj = dt_store_open(env, dt, "", name, &fid); + dt_obj = dt_find_or_create(env, dt, &fid, &dof, &attr); if (!IS_ERR(dt_obj)) { seq->lss_obj = dt_obj; rc = 0; @@ -309,4 +248,3 @@ void seq_store_fini(struct lu_server_seq *seq, EXIT; } -#endif