--- /dev/null
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * lustre/osd/osd_oi.c
+ * Object Index.
+ *
+ * Copyright (c) 2006 Cluster File Systems, Inc.
+ * Author: Nikita Danilov <nikita@clusterfs.com>
+ *
+ * This file is part of the Lustre file system, http://www.lustre.org
+ * Lustre is a trademark of Cluster File Systems, Inc.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#ifndef EXPORT_SYMTAB
+# define EXPORT_SYMTAB
+#endif
+#define DEBUG_SUBSYSTEM S_MDS
+
+#include <linux/module.h>
+
+/* LUSTRE_VERSION_CODE */
+#include <linux/lustre_ver.h>
+/*
+ * struct OBD_{ALLOC,FREE}*()
+ * OBD_FAIL_CHECK
+ */
+#include <linux/obd_support.h>
+
+/* fid_is_local() */
+#include <linux/lustre_fid.h>
+
+#include "osd_oi.h"
+/* osd_lookup(), struct osd_thread_info */
+#include "osd_internal.h"
+
+static struct lu_fid *oi_fid_key(struct osd_thread_info *info,
+ const struct lu_fid *fid);
+static void osd_oi_init0(struct osd_oi *oi);
+
+static const char osd_oi_dirname[] = "oi";
+
+int osd_oi_init(struct osd_oi *oi, struct dentry *root, struct lu_site *site)
+{
+ int result;
+
+ oi->oi_dir = osd_lookup(root,
+ osd_oi_dirname, (sizeof osd_oi_dirname) - 1);
+ if (IS_ERR(oi->oi_dir)) {
+ result = PTR_ERR(oi->oi_dir);
+ oi->oi_dir = NULL;
+ } else {
+ result = 0;
+ init_rwsem(&oi->oi_lock);
+ oi->oi_site = site;
+ }
+ /*
+ * XXX prototype stuff: add root fid.
+ */
+ osd_oi_init0(oi);
+ return result;
+}
+
+void osd_oi_fini(struct osd_oi *oi)
+{
+ if (oi->oi_dir != NULL) {
+ dput(oi->oi_dir);
+ oi->oi_dir = NULL;
+ }
+}
+
+void osd_oi_read_lock(struct osd_oi *oi)
+{
+ down_read(&oi->oi_lock);
+}
+
+void osd_oi_read_unlock(struct osd_oi *oi)
+{
+ up_read(&oi->oi_lock);
+}
+
+void osd_oi_write_lock(struct osd_oi *oi)
+{
+ down_write(&oi->oi_lock);
+}
+
+void osd_oi_write_unlock(struct osd_oi *oi)
+{
+ up_write(&oi->oi_lock);
+}
+
+static struct lu_fid *oi_fid_key(struct osd_thread_info *info,
+ const struct lu_fid *fid)
+{
+ fid_to_le(&info->oti_fid, fid);
+ return &info->oti_fid;
+}
+
+/****************************************************************************
+ * XXX prototype.
+ ****************************************************************************/
+
+struct oi_entry {
+ struct lu_fid oe_key;
+ struct osd_inode_id oe_rec;
+ struct list_head oe_linkage;
+};
+
+static CFS_LIST_HEAD(oi_head);
+
+static struct oi_entry *oi_lookup(const struct lu_fid *fid)
+{
+ struct oi_entry *entry;
+
+ list_for_each_entry(entry, &oi_head, oe_linkage) {
+ if (lu_fid_eq(fid, &entry->oe_key))
+ return entry;
+ }
+ return NULL;
+}
+
+/*
+ * Locking: requires at least read lock on oi.
+ */
+int osd_oi_lookup(struct osd_thread_info *info, struct osd_oi *oi,
+ const struct lu_fid *fid, struct osd_inode_id *id)
+{
+ struct oi_entry *entry;
+ int result;
+
+ LASSERT(fid_is_local(oi->oi_site, fid));
+ entry = oi_lookup(fid);
+ if (entry != NULL) {
+ *id = entry->oe_rec;
+ result = 0;
+ } else
+ result = -ENOENT;
+ return result;
+}
+
+/*
+ * Locking: requires write lock on oi.
+ */
+int osd_oi_insert(struct osd_thread_info *info, struct osd_oi *oi,
+ const struct lu_fid *fid, const struct osd_inode_id *id)
+{
+ struct oi_entry *entry;
+ int result;
+
+ LASSERT(fid_is_local(oi->oi_site, fid));
+ entry = oi_lookup(fid);
+ if (entry == NULL) {
+ OBD_ALLOC_PTR(entry);
+ if (entry != NULL) {
+ entry->oe_key = *fid;
+ entry->oe_rec = *id;
+ list_add(&entry->oe_linkage, &oi_head);
+ result = 0;
+ } else
+ result = -ENOMEM;
+ } else
+ result = -EEXIST;
+ return result;
+}
+
+/*
+ * Locking: requires write lock on oi.
+ */
+int osd_oi_delete(struct osd_thread_info *info,
+ struct osd_oi *oi, const struct lu_fid *fid)
+{
+ struct oi_entry *entry;
+ int result;
+
+ LASSERT(fid_is_local(oi->oi_site, fid));
+ entry = oi_lookup(fid);
+ if (entry != NULL) {
+ list_del(&entry->oe_linkage);
+ OBD_FREE_PTR(entry);
+ result = 0;
+ } else
+ result = -ENOENT;
+ return result;
+}
+
+#define LDISKFS_ROOT_INO 2 /* Root inode */
+
+/* XXX used by osd_root_get() */
+const struct lu_fid root_fid = {
+ .f_seq = LUSTRE_ROOT_FID_SEQ,
+ .f_oid = LUSTRE_ROOT_FID_OID,
+ .f_ver = 0
+};
+
+static const struct osd_inode_id root_id = {
+ .oii_ino = LDISKFS_ROOT_INO,
+ .oii_gen = 0
+};
+
+static void osd_oi_init0(struct osd_oi *oi)
+{
+ int result;
+ result = osd_oi_insert(NULL, oi, &root_fid, &root_id);
+ LASSERT(result == 0);
+}
--- /dev/null
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * lustre/osd/osd_oi.h
+ * OSD Object Index
+ *
+ * Copyright (c) 2006 Cluster File Systems, Inc.
+ * Author: Nikita Danilov <nikita@clusterfs.com>
+ *
+ * This file is part of the Lustre file system, http://www.lustre.org
+ * Lustre is a trademark of Cluster File Systems, Inc.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#ifndef _OSD_OI_H
+#define _OSD_OI_H
+
+#if defined(__KERNEL__)
+
+/* struct rw_semaphore */
+#include <linux/rwsem.h>
+
+#include <linux/lu_object.h>
+
+struct dentry;
+struct lu_fid;
+struct osd_thread_info;
+struct lu_site;
+
+struct osd_oi {
+ struct dentry *oi_dir;
+ struct rw_semaphore oi_lock;
+ struct lu_site *oi_site;
+};
+
+struct osd_inode_id {
+ __u64 oii_ino;
+ __u32 oii_gen;
+};
+
+int osd_oi_init(struct osd_oi *oi, struct dentry *root, struct lu_site *s);
+void osd_oi_fini(struct osd_oi *oi);
+
+void osd_oi_read_lock(struct osd_oi *oi);
+void osd_oi_read_unlock(struct osd_oi *oi);
+void osd_oi_write_lock(struct osd_oi *oi);
+void osd_oi_write_unlock(struct osd_oi *oi);
+
+int osd_oi_lookup(struct osd_thread_info *info, struct osd_oi *oi,
+ const struct lu_fid *fid, struct osd_inode_id *id);
+int osd_oi_insert(struct osd_thread_info *info, struct osd_oi *oi,
+ const struct lu_fid *fid, const struct osd_inode_id *id);
+int osd_oi_delete(struct osd_thread_info *info,
+ struct osd_oi *oi, const struct lu_fid *fid);
+
+#endif /* __KERNEL__ */
+#endif /* _OSD_OI_H */