From 6438e16571e5fe07f1f0fd78d54f6f22ff4c743f Mon Sep 17 00:00:00 2001 From: rread Date: Thu, 20 Feb 2003 05:31:27 +0000 Subject: [PATCH] Update b_multinet minor conflicts found in mds/handler.c and niobuf.c --- lustre/extN/ext3-2.4-ino_t.diff | 138 ++++++++++++++++++++++++++ lustre/include/linux/lustre_handles.h | 39 ++++++++ lustre/kernel_patches/pc/lustre-2.5.pc | 11 +++ lustre/kernel_patches/series/vanilla-2.5 | 1 + lustre/obdclass/lustre_handles.c | 162 +++++++++++++++++++++++++++++++ lustre/ptlrpc/lustre_peer.c | 125 ++++++++++++++++++++++++ lustre/tests/statone.c | 60 ++++++++++++ 7 files changed, 536 insertions(+) create mode 100644 lustre/extN/ext3-2.4-ino_t.diff create mode 100644 lustre/include/linux/lustre_handles.h create mode 100644 lustre/kernel_patches/pc/lustre-2.5.pc create mode 100644 lustre/kernel_patches/series/vanilla-2.5 create mode 100644 lustre/obdclass/lustre_handles.c create mode 100644 lustre/ptlrpc/lustre_peer.c create mode 100644 lustre/tests/statone.c diff --git a/lustre/extN/ext3-2.4-ino_t.diff b/lustre/extN/ext3-2.4-ino_t.diff new file mode 100644 index 0000000..ce1bd88 --- /dev/null +++ b/lustre/extN/ext3-2.4-ino_t.diff @@ -0,0 +1,138 @@ +--- linux/fs/ext3/ialloc.c.orig Sat Oct 19 11:42:23 2002 ++++ linux/fs/ext3/ialloc.c Sat Jan 4 12:14:18 2003 +@@ -64,8 +64,8 @@ static int read_inode_bitmap (struct sup + if (!bh) { + ext3_error (sb, "read_inode_bitmap", + "Cannot read inode bitmap - " +- "block_group = %lu, inode_bitmap = %lu", +- block_group, (unsigned long) gdp->bg_inode_bitmap); ++ "block_group = %lu, inode_bitmap = %u", ++ block_group, gdp->bg_inode_bitmap); + retval = -EIO; + } + /* +@@ -531,19 +532,19 @@ out: + } + + /* Verify that we are loading a valid orphan from disk */ +-struct inode *ext3_orphan_get (struct super_block * sb, ino_t ino) ++struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino) + { +- ino_t max_ino = le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count); ++ unsigned long max_ino = le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count); + unsigned long block_group; + int bit; + int bitmap_nr; + struct buffer_head *bh; + struct inode *inode = NULL; +- ++ + /* Error cases - e2fsck has already cleaned up for us */ + if (ino > max_ino) { + ext3_warning(sb, __FUNCTION__, +- "bad orphan ino %ld! e2fsck was run?\n", ino); ++ "bad orphan ino %lu! e2fsck was run?\n", ino); + return NULL; + } + +@@ -552,7 +553,7 @@ struct inode *ext3_orphan_get (struct su + if ((bitmap_nr = load_inode_bitmap(sb, block_group)) < 0 || + !(bh = EXT3_SB(sb)->s_inode_bitmap[bitmap_nr])) { + ext3_warning(sb, __FUNCTION__, +- "inode bitmap error for orphan %ld\n", ino); ++ "inode bitmap error for orphan %lu\n", ino); + return NULL; + } + +@@ -563,7 +564,7 @@ struct inode *ext3_orphan_get (struct su + if (!ext3_test_bit(bit, bh->b_data) || !(inode = iget(sb, ino)) || + is_bad_inode(inode) || NEXT_ORPHAN(inode) > max_ino) { + ext3_warning(sb, __FUNCTION__, +- "bad orphan inode %ld! e2fsck was run?\n", ino); ++ "bad orphan inode %lu! e2fsck was run?\n", ino); + printk(KERN_NOTICE "ext3_test_bit(bit=%d, block=%ld) = %d\n", + bit, bh->b_blocknr, ext3_test_bit(bit, bh->b_data)); + printk(KERN_NOTICE "inode=%p\n", inode); +@@ -570,9 +571,9 @@ struct inode *ext3_orphan_get (struct su + if (inode) { + printk(KERN_NOTICE "is_bad_inode(inode)=%d\n", + is_bad_inode(inode)); +- printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%d\n", ++ printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n", + NEXT_ORPHAN(inode)); +- printk(KERN_NOTICE "max_ino=%ld\n", max_ino); ++ printk(KERN_NOTICE "max_ino=%lu\n", max_ino); + } + /* Avoid freeing blocks if we got a bad deleted inode */ + if (inode && inode->i_nlink == 0) +--- linux/fs/ext3/namei.c.orig Sat Oct 19 11:42:45 2002 ++++ linux/fs/ext3/namei.c Sat Jan 4 12:13:27 2003 +@@ -716,10 +716,10 @@ int ext3_orphan_del(handle_t *handle, st + { + struct list_head *prev; + struct ext3_sb_info *sbi; +- ino_t ino_next; ++ unsigned long ino_next; + struct ext3_iloc iloc; + int err = 0; +- ++ + lock_super(inode->i_sb); + if (list_empty(&inode->u.ext3_i.i_orphan)) { + unlock_super(inode->i_sb); +@@ -730,7 +730,7 @@ int ext3_orphan_del(handle_t *handle, st + prev = inode->u.ext3_i.i_orphan.prev; + sbi = EXT3_SB(inode->i_sb); + +- jbd_debug(4, "remove inode %ld from orphan list\n", inode->i_ino); ++ jbd_debug(4, "remove inode %lu from orphan list\n", inode->i_ino); + + list_del(&inode->u.ext3_i.i_orphan); + INIT_LIST_HEAD(&inode->u.ext3_i.i_orphan); +@@ -741,13 +741,13 @@ int ext3_orphan_del(handle_t *handle, st + * list in memory. */ + if (!handle) + goto out; +- ++ + err = ext3_reserve_inode_write(handle, inode, &iloc); + if (err) + goto out_err; + + if (prev == &sbi->s_orphan) { +- jbd_debug(4, "superblock will point to %ld\n", ino_next); ++ jbd_debug(4, "superblock will point to %lu\n", ino_next); + BUFFER_TRACE(sbi->s_sbh, "get_write_access"); + err = ext3_journal_get_write_access(handle, sbi->s_sbh); + if (err) +@@ -758,8 +758,8 @@ int ext3_orphan_del(handle_t *handle, st + struct ext3_iloc iloc2; + struct inode *i_prev = + list_entry(prev, struct inode, u.ext3_i.i_orphan); +- +- jbd_debug(4, "orphan inode %ld will point to %ld\n", ++ ++ jbd_debug(4, "orphan inode %lu will point to %lu\n", + i_prev->i_ino, ino_next); + err = ext3_reserve_inode_write(handle, i_prev, &iloc2); + if (err) +@@ -774,7 +774,7 @@ int ext3_orphan_del(handle_t *handle, st + if (err) + goto out_brelse; + +-out_err: ++out_err: + ext3_std_error(inode->i_sb, err); + out: + unlock_super(inode->i_sb); +--- linux/include/linux/ext3_fs.h.orig Thu Jan 2 16:10:24 2003 ++++ linux/include/linux/ext3_fs.h Sat Jan 4 12:25:41 2003 +@@ -622,7 +622,7 @@ extern int ext3_sync_file (struct file * + /* ialloc.c */ + extern struct inode * ext3_new_inode (handle_t *, const struct inode *, int); + extern void ext3_free_inode (handle_t *, struct inode *); +-extern struct inode * ext3_orphan_get (struct super_block *, ino_t); ++extern struct inode * ext3_orphan_get (struct super_block *, unsigned long); + extern unsigned long ext3_count_free_inodes (struct super_block *); + extern void ext3_check_inodes_bitmap (struct super_block *); + extern unsigned long ext3_count_free (struct buffer_head *, unsigned); diff --git a/lustre/include/linux/lustre_handles.h b/lustre/include/linux/lustre_handles.h new file mode 100644 index 0000000..993a323 --- /dev/null +++ b/lustre/include/linux/lustre_handles.h @@ -0,0 +1,39 @@ +#ifndef __LINUX_HANDLES_H_ +#define __LINUX_HANDLES_H_ + +#ifdef __KERNEL__ +#include +#include +#include +#endif + +typedef void (*portals_handle_addref_cb)(void *object); + +/* These handles are most easily used by having them appear at the very top of + * whatever object that you want to make handles for. ie: + * + * struct ldlm_lock { + * struct portals_handle handle; + * ... + * }; + * + * Now you're able to assign the results of cookie2handle directly to an + * ldlm_lock. If it's not at the top, you'll want to hack up a macro that + * uses some offsetof() magic. */ + +struct portals_handle { + struct list_head h_link; + __u64 h_cookie; + portals_handle_addref_cb h_addref; +}; + +/* handles.c */ + +/* Add a handle to the hash table */ +void portals_handle_hash(struct portals_handle *, portals_handle_addref_cb); +void portals_handle_unhash(struct portals_handle *); +void *portals_handle2object(__u64 cookie); +int portals_handle_init(void); +void portals_handle_cleanup(void); + +#endif diff --git a/lustre/kernel_patches/pc/lustre-2.5.pc b/lustre/kernel_patches/pc/lustre-2.5.pc new file mode 100644 index 0000000..71434ea --- /dev/null +++ b/lustre/kernel_patches/pc/lustre-2.5.pc @@ -0,0 +1,11 @@ +arch/um/kernel/mem.c +fs/namei.c +fs/nfsd/vfs.c +fs/sysfs/inode.c +include/linux/dcache.h +include/linux/fs.h +include/linux/namei.h +include/linux/slab.h +kernel/ksyms.c +mm/slab.c +net/unix/af_unix.c diff --git a/lustre/kernel_patches/series/vanilla-2.5 b/lustre/kernel_patches/series/vanilla-2.5 new file mode 100644 index 0000000..2dcc98f --- /dev/null +++ b/lustre/kernel_patches/series/vanilla-2.5 @@ -0,0 +1 @@ +lustre-2.5.patch diff --git a/lustre/obdclass/lustre_handles.c b/lustre/obdclass/lustre_handles.c new file mode 100644 index 0000000..f0987c4 --- /dev/null +++ b/lustre/obdclass/lustre_handles.c @@ -0,0 +1,162 @@ +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: + * + * Copyright (C) 2002 Cluster File Systems, Inc. + * Author: Phil Schwan + * + * This file is part of Portals, http://www.sf.net/projects/sandiaportals/ + * + * Portals is free software; you can redistribute it and/or + * modify it under the terms of version 2.1 of the GNU Lesser General + * Public License as published by the Free Software Foundation. + * + * Portals 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Portals; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include + +#define DEBUG_SUBSYSTEM S_PORTALS + +#include +#include + +static spinlock_t handle_lock = SPIN_LOCK_UNLOCKED; +static spinlock_t random_lock = SPIN_LOCK_UNLOCKED; +static struct list_head *handle_hash = NULL; +static int handle_count = 0; + +#define HANDLE_HASH_SIZE (1 << 14) +#define HANDLE_HASH_MASK (HANDLE_HASH_SIZE - 1) + +void class_handle_hash(struct portals_handle *h, portals_handle_addref_cb cb) +{ + struct list_head *bucket; + ENTRY; + + LASSERT(h != NULL); + LASSERT(list_empty(&h->h_link)); + + /* My hypothesis is that get_random_bytes, if called from two threads at + * the same time, will return the same bytes. -phil */ + spin_lock(&random_lock); + get_random_bytes(&h->h_cookie, sizeof(h->h_cookie)); + spin_unlock(&random_lock); + + h->h_addref = cb; + + bucket = handle_hash + (h->h_cookie & HANDLE_HASH_MASK); + + CDEBUG(D_INFO, "adding object %p with handle "LPX64" to hash\n", + h, h->h_cookie); + + spin_lock(&handle_lock); + list_add(&h->h_link, bucket); + handle_count++; + spin_unlock(&handle_lock); + EXIT; +} + +static void class_handle_unhash_nolock(struct portals_handle *h) +{ + LASSERT(!list_empty(&h->h_link)); + + CDEBUG(D_INFO, "removing object %p with handle "LPX64" from hash\n", + h, h->h_cookie); + + handle_count--; + list_del_init(&h->h_link); +} + +void class_handle_unhash(struct portals_handle *h) +{ + spin_lock(&handle_lock); + class_handle_unhash_nolock(h); + spin_unlock(&handle_lock); +} + +void *class_handle2object(__u64 cookie) +{ + struct list_head *bucket, *tmp; + void *retval = NULL; + ENTRY; + + LASSERT(handle_hash != NULL); + + spin_lock(&handle_lock); + bucket = handle_hash + (cookie & HANDLE_HASH_MASK); + + list_for_each(tmp, bucket) { + struct portals_handle *h; + h = list_entry(tmp, struct portals_handle, h_link); + + if (h->h_cookie == cookie) { + h->h_addref(h); + retval = h; + break; + } + } + spin_unlock(&handle_lock); + + RETURN(retval); +} + +int class_handle_init(void) +{ + struct list_head *bucket; + + LASSERT(handle_hash == NULL); + + PORTAL_ALLOC(handle_hash, sizeof(*handle_hash) * HANDLE_HASH_SIZE); + if (handle_hash == NULL) + return -ENOMEM; + + for (bucket = handle_hash + HANDLE_HASH_SIZE - 1; bucket >= handle_hash; + bucket--) + INIT_LIST_HEAD(bucket); + + return 0; +} + +static void cleanup_all_handles(void) +{ + int i; + + spin_lock(&handle_lock); + for (i = 0; i < HANDLE_HASH_SIZE; i++) { + struct list_head *tmp, *pos; + list_for_each_safe(tmp, pos, &(handle_hash[i])) { + struct portals_handle *h; + h = list_entry(tmp, struct portals_handle, h_link); + + CERROR("forcing cleanup for handle "LPX64"\n", + h->h_cookie); + + class_handle_unhash_nolock(h); + } + } + spin_lock(&handle_lock); +} + +void class_handle_cleanup(void) +{ + LASSERT(handle_hash != NULL); + + if (handle_count != 0) { + CERROR("handle_count at cleanup: %d\n", handle_count); + cleanup_all_handles(); + } + + PORTAL_FREE(handle_hash, sizeof(*handle_hash) * HANDLE_HASH_SIZE); + handle_hash = NULL; + + if (handle_count) + CERROR("leaked %d handles\n", handle_count); +} diff --git a/lustre/ptlrpc/lustre_peer.c b/lustre/ptlrpc/lustre_peer.c new file mode 100644 index 0000000..d9042f8 --- /dev/null +++ b/lustre/ptlrpc/lustre_peer.c @@ -0,0 +1,125 @@ + + + +struct uuid_nid_data { + struct list_head head; + char *uuid; + __u32 nid; + __u32 nal; + ptl_handle_ni_t ni; +}; + + +/* FIXME: This should probably become more elegant than a global linked list */ +static struct list_head g_uuid_list; +static spinlock_t g_uuid_lock; + + +int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer) +{ + struct list_head *tmp; + + spin_lock (&g_uuid_lock); + + list_for_each(tmp, &g_uuid_list) { + struct uuid_nid_data *data = + list_entry(tmp, struct uuid_nid_data, head); + + if (strcmp(data->uuid, uuid) == 0) { + peer->peer_nid = data->nid; + peer->peer_ni = data->ni; + + spin_unlock (&g_uuid_lock); + return 0; + } + } + + spin_unlock (&g_uuid_lock); + return -1; +} + +/* delete only one entry if uuid is specified, otherwise delete all */ +static int lustre_add_uuid(char *uuid, __u64 nid, __u32 nal) +{ + const ptl_handle_ni_t *nip; + struct uuid_nid_data *data; + int rc; + int nob = strnlen (uuid, PAGE_SIZE) + 1; + + if (nob > PAGE_SIZE) + return -EINVAL; + + nip = lustre_get_ni (nal); + if (nip == NULL) { + CERROR("get_ni failed: is the NAL module loaded?\n"); + return -EIO; + } + + rc = -ENOMEM; + PORTAL_ALLOC(data, sizeof(*data)); + if (data == NULL) + goto fail_0; + + PORTAL_ALLOC(data->uuid, nob); + if (data == NULL) + goto fail_1; + + memcpy(data->uuid, uuid, nob); + data->nid = nid; + data->nal = nal; + data->ni = *nip; + + spin_lock (&g_uuid_lock); + + list_add(&data->head, &g_uuid_list); + + spin_unlock (&g_uuid_lock); + + return 0; + + fail_1: + PORTAL_FREE (data, sizeof (*data)); + fail_0: + lustre_put_ni (nal); + return (rc); +} + +static int lustre_del_uuid (char *uuid) +{ + struct list_head deathrow; + struct list_head *tmp; + struct list_head *n; + struct uuid_nid_data *data; + + INIT_LIST_HEAD (&deathrow); + + spin_lock (&g_uuid_lock); + + list_for_each_safe(tmp, n, &g_uuid_list) { + data = list_entry(tmp, struct uuid_nid_data, head); + + if (uuid == NULL || strcmp(data->uuid, uuid) == 0) { + list_del (&data->head); + list_add (&data->head, &deathrow); + if (uuid) + break; + } + } + + spin_unlock (&g_uuid_lock); + + if (list_empty (&deathrow)) + return -EINVAL; + + do { + data = list_entry(deathrow.next, struct uuid_nid_data, head); + + list_del (&data->head); + + lustre_put_ni (data->nal); + PORTAL_FREE(data->uuid, strlen(data->uuid) + 1); + PORTAL_FREE(data, sizeof(*data)); + } while (!list_empty (&deathrow)); + + return 0; +} diff --git a/lustre/tests/statone.c b/lustre/tests/statone.c new file mode 100644 index 0000000..5250984 --- /dev/null +++ b/lustre/tests/statone.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +int main(int argc, char **argv) +{ + struct obd_ioctl_data data; + char rawbuf[8192], parent[4096], *buf = rawbuf, *base, *t; + int max = sizeof(rawbuf), fd, offset, rc; + + if (argc != 2) { + printf("usage: %s filename\n", argv[0]); + return 1; + } + + base = argv[1]; + t = strrchr(base, '/'); + if (!t) { + strcpy(parent, "."); + offset = -1; + } else { + strncpy(parent, base, t - base); + offset = t - base - 1; + } + + fd = open(parent, O_RDONLY); + if (fd < 0) { + printf("open(%s) error: %s\n", parent, strerror(errno)); + exit(errno); + } + + memset(&data, 0, sizeof(data)); + data.ioc_version = OBD_IOCTL_VERSION; + data.ioc_len = sizeof(data); + if (offset >= 0) + data.ioc_inlbuf1 = base + offset + 2; + else + data.ioc_inlbuf1 = base; + data.ioc_inllen1 = strlen(data.ioc_inlbuf1) + 1; + + if (obd_ioctl_pack(&data, &buf, max)) { + printf("ioctl_pack failed.\n"); + exit(1); + } + + rc = ioctl(fd, IOC_MDC_LOOKUP, buf); + if (rc < 0) { + printf("ioctl(%s/%s) error: %s\n", parent, + data.ioc_inlbuf1, strerror(errno)); + exit(errno); + } + + return 0; +} -- 1.8.3.1