From 159e73443f2c9d0e6953db7ec0b8fc1983110e28 Mon Sep 17 00:00:00 2001 From: nikita Date: Sat, 15 Apr 2006 22:41:48 +0000 Subject: [PATCH] osd: add object index prototype --- lustre/osd/Makefile.in | 2 +- lustre/osd/osd_oi.c | 219 +++++++++++++++++++++++++++++++++++++++++++++++++ lustre/osd/osd_oi.h | 71 ++++++++++++++++ 3 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 lustre/osd/osd_oi.c create mode 100644 lustre/osd/osd_oi.h diff --git a/lustre/osd/Makefile.in b/lustre/osd/Makefile.in index 7835805..abe785b 100644 --- a/lustre/osd/Makefile.in +++ b/lustre/osd/Makefile.in @@ -1,4 +1,4 @@ MODULES := osd -osd-objs := osd_handler.o +osd-objs := osd_handler.o osd_oi.o @INCLUDE_RULES@ diff --git a/lustre/osd/osd_oi.c b/lustre/osd/osd_oi.c new file mode 100644 index 0000000..8040bc3 --- /dev/null +++ b/lustre/osd/osd_oi.c @@ -0,0 +1,219 @@ +/* -*- 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 + * + * 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 + +/* LUSTRE_VERSION_CODE */ +#include +/* + * struct OBD_{ALLOC,FREE}*() + * OBD_FAIL_CHECK + */ +#include + +/* fid_is_local() */ +#include + +#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); +} diff --git a/lustre/osd/osd_oi.h b/lustre/osd/osd_oi.h new file mode 100644 index 0000000..c432678 --- /dev/null +++ b/lustre/osd/osd_oi.h @@ -0,0 +1,71 @@ +/* -*- 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 + * + * 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 + +#include + +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 */ -- 1.8.3.1