/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=8:tabstop=8:
*
- * lustre/fid/fid_store.c
- * Lustre Sequence Manager
+ * GPL HEADER START
*
- * Copyright (c) 2006 Cluster File Systems, Inc.
- * Author: Yury Umanets <umka@clusterfs.com>
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * This file is part of the Lustre file system, http://www.lustre.org
- * Lustre is a trademark of Cluster File Systems, Inc.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
*
- * You may have signed or agreed to another license before downloading
- * this software. If so, you are bound by the terms and conditions
- * of that agreement, and the following does not apply to you. See the
- * LICENSE file included with this distribution for more information.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
*
- * If you did not agree to a different license, then this copy of Lustre
- * is open source software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
*
- * In either case, Lustre is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * license text for more details.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/fid/fid_store.c
+ *
+ * Lustre Sequence Manager
+ *
+ * Author: Yury Umanets <umka@clusterfs.com>
*/
#ifndef EXPORT_SYMTAB
#include "fid_internal.h"
#ifdef __KERNEL__
-enum {
- SEQ_TXN_STORE_CREDITS = 20
-};
static struct lu_buf *seq_store_buf(struct seq_thread_info *info)
{
return buf;
}
+struct thandle *seq_store_trans_start(struct lu_server_seq *seq,
+ const struct lu_env *env, int credit,
+ int sync)
+{
+ struct seq_thread_info *info;
+ struct dt_device *dt_dev;
+ struct thandle *th;
+ ENTRY;
+
+ dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev);
+ info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
+ LASSERT(info != NULL);
+
+ txn_param_init(&info->sti_txn, credit);
+ if (sync)
+ txn_param_sync(&info->sti_txn);
+
+ th = dt_dev->dd_ops->dt_trans_start(env, dt_dev, &info->sti_txn);
+ return th;
+}
+
+void seq_store_trans_stop(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);
+
+ dt_dev->dd_ops->dt_trans_stop(env, th);
+}
+
/* This function implies that caller takes care about locking. */
int seq_store_write(struct lu_server_seq *seq,
- const struct lu_env *env)
+ const struct lu_env *env,
+ struct thandle *th)
{
struct dt_object *dt_obj = seq->lss_obj;
struct seq_thread_info *info;
struct dt_device *dt_dev;
- struct thandle *th;
loff_t pos = 0;
- int rc;
- ENTRY;
+ int rc;
+ ENTRY;
dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev);
info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
LASSERT(info != NULL);
- /* Stub here, will fix it later. */
- txn_param_init(&info->sti_txn, SEQ_TXN_STORE_CREDITS);
+ /* Store ranges in le format. */
+ range_cpu_to_le(&info->sti_space, &seq->lss_space);
- th = dt_dev->dd_ops->dt_trans_start(env, dt_dev, &info->sti_txn);
- if (!IS_ERR(th)) {
- /* 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);
- 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;
- }
+ 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;
+ }
- dt_dev->dd_ops->dt_trans_stop(env, th);
- } else {
- rc = PTR_ERR(th);
+
+ RETURN(rc);
+}
+
+int seq_store_update(const struct lu_env *env, struct lu_server_seq *seq,
+ struct lu_seq_range *out, int sync)
+{
+ struct thandle *th;
+ int rc;
+ int credits = SEQ_TXN_STORE_CREDITS;
+
+ if (out != NULL)
+ credits += FLD_TXN_INDEX_INSERT_CREDITS;
+
+ th = seq_store_trans_start(seq, env, credits, sync);
+ if (IS_ERR(th))
+ RETURN(PTR_ERR(th));
+
+ rc = seq_store_write(seq, env, th);
+ if (rc) {
+ CERROR("%s: Can't write space data, rc %d\n",
+ seq->lss_name, 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);
+ }
}
-
- RETURN(rc);
+
+ seq_store_trans_stop(seq, env, th);
+ return rc;
}
/*
struct dt_object *dt_obj = seq->lss_obj;
struct seq_thread_info *info;
loff_t pos = 0;
- int rc;
- ENTRY;
+ int rc;
+ ENTRY;
info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
LASSERT(info != NULL);
rc = -ENODATA;
} else if (rc >= 0) {
CERROR("%s: Read only %d bytes of %d\n", seq->lss_name,
- rc, sizeof(info->sti_space));
+ rc, (int)sizeof(info->sti_space));
rc = -EIO;
}
-
- RETURN(rc);
+
+ RETURN(rc);
}
int seq_store_init(struct lu_server_seq *seq,
name = seq->lss_type == LUSTRE_SEQ_SERVER ?
LUSTRE_SEQ_SRV_NAME : LUSTRE_SEQ_CTL_NAME;
- dt_obj = dt_store_open(env, dt, name, &fid);
+ dt_obj = dt_store_open(env, dt, "", name, &fid);
if (!IS_ERR(dt_obj)) {
seq->lss_obj = dt_obj;
- rc = 0;
+ rc = 0;
} else {
CERROR("%s: Can't find \"%s\" obj %d\n",
- seq->lss_name, name, (int)PTR_ERR(dt_obj));
+ seq->lss_name, name, (int)PTR_ERR(dt_obj));
rc = PTR_ERR(dt_obj);
}