From b346671fa196abaf82ed3e1842f981209f7887af Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 16 Jan 2006 11:31:24 +0000 Subject: [PATCH 001/292] [PATCH] Export tty_write_message() for GFS2 quota code The kernel's existing quota code makes use of tty_write_message() to inform the user of certain events. GFS2 also uses the same mechanism so we export it here to avoid code duplication in GFS2. Signed-off-by: Steven Whitehouse --- kernel/printk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/printk.c b/kernel/printk.c index 13ced0f7828f..7ba79ad895e4 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -999,6 +999,7 @@ void tty_write_message(struct tty_struct *tty, char *msg) tty->driver->write(tty, msg, strlen(msg)); return; } +EXPORT_SYMBOL_GPL(tty_write_message); /* * printk rate limiting, lifted from the networking subsystem. From fba7b940194465ac7a8f0cdf793959fb5fbb8834 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Mon, 16 Jan 2006 11:48:01 +0000 Subject: [PATCH 002/292] [PATCH] Add fs_subsys to enable filesystems to use sysfs This creates an "fs" subdirectory in sysfs so that GFS2 (or any other filesystem, come to that) can make use of sysfs. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/namespace.c | 5 +++++ include/linux/fs.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/fs/namespace.c b/fs/namespace.c index 8bc15b362d23..ce97becff461 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -48,6 +48,10 @@ static int hash_mask __read_mostly, hash_bits __read_mostly; static kmem_cache_t *mnt_cache; static struct rw_semaphore namespace_sem; +/* /sys/fs */ +decl_subsys(fs, NULL, NULL); +EXPORT_SYMBOL_GPL(fs_subsys); + static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry) { unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES); @@ -1725,6 +1729,7 @@ void __init mnt_init(unsigned long mempages) i--; } while (i); sysfs_init(); + subsystem_register(&fs_subsys); init_rootfs(); init_mount_tree(); } diff --git a/include/linux/fs.h b/include/linux/fs.h index 552cedfa6064..eabc80d22bbc 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1293,6 +1293,9 @@ extern int vfs_statfs(struct super_block *, struct kstatfs *); #define FLOCK_VERIFY_READ 1 #define FLOCK_VERIFY_WRITE 2 +/* /sys/fs */ +extern struct subsystem fs_subsys; + extern int locks_mandatory_locked(struct inode *); extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); From f7825dcf8c7301cfd3724eb40c5b443cc85ab7b8 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Mon, 16 Jan 2006 16:43:37 +0000 Subject: [PATCH 003/292] [GFS2] Hook GFS2 into the Kbuild system Adds GFS2 into fs/Kconfig and adds a Makefile entry Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/Kconfig | 1 + fs/Makefile | 1 + 2 files changed, 2 insertions(+) diff --git a/fs/Kconfig b/fs/Kconfig index ef78e3a42d32..bec8afa5704d 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -323,6 +323,7 @@ config FS_POSIX_ACL default n source "fs/xfs/Kconfig" +source "fs/gfs2/Kconfig" config OCFS2_FS tristate "OCFS2 file system support (EXPERIMENTAL)" diff --git a/fs/Makefile b/fs/Makefile index 1db711319c80..0922727732c5 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -103,3 +103,4 @@ obj-$(CONFIG_HPPFS) += hppfs/ obj-$(CONFIG_DEBUG_FS) += debugfs/ obj-$(CONFIG_CONFIGFS_FS) += configfs/ obj-$(CONFIG_OCFS2_FS) += ocfs2/ +obj-$(CONFIG_GFS2_FS) += gfs2/ From b3b94faa5fe5968827ba0640ee9fba4b3e7f736e Mon Sep 17 00:00:00 2001 From: David Teigland Date: Mon, 16 Jan 2006 16:50:04 +0000 Subject: [PATCH 004/292] [GFS2] The core of GFS2 This patch contains all the core files for GFS2. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/Kconfig | 46 + fs/gfs2/Makefile | 44 + fs/gfs2/acl.c | 312 +++++ fs/gfs2/acl.h | 37 + fs/gfs2/bits.c | 178 +++ fs/gfs2/bits.h | 28 + fs/gfs2/bmap.c | 1206 +++++++++++++++++ fs/gfs2/bmap.h | 39 + fs/gfs2/daemon.c | 225 ++++ fs/gfs2/daemon.h | 20 + fs/gfs2/dir.c | 2157 ++++++++++++++++++++++++++++++ fs/gfs2/dir.h | 51 + fs/gfs2/eaops.c | 185 +++ fs/gfs2/eaops.h | 30 + fs/gfs2/eattr.c | 1620 ++++++++++++++++++++++ fs/gfs2/eattr.h | 90 ++ fs/gfs2/format.h | 21 + fs/gfs2/gfs2.h | 62 + fs/gfs2/glock.c | 2513 +++++++++++++++++++++++++++++++++++ fs/gfs2/glock.h | 143 ++ fs/gfs2/glops.c | 487 +++++++ fs/gfs2/glops.h | 23 + fs/gfs2/incore.h | 703 ++++++++++ fs/gfs2/inode.c | 1805 +++++++++++++++++++++++++ fs/gfs2/inode.h | 74 ++ fs/gfs2/jdata.c | 382 ++++++ fs/gfs2/jdata.h | 52 + fs/gfs2/lm.c | 235 ++++ fs/gfs2/lm.h | 42 + fs/gfs2/lm_interface.h | 295 ++++ fs/gfs2/locking.c | 192 +++ fs/gfs2/log.c | 659 +++++++++ fs/gfs2/log.h | 68 + fs/gfs2/lops.c | 534 ++++++++ fs/gfs2/lops.h | 96 ++ fs/gfs2/lvb.c | 48 + fs/gfs2/lvb.h | 28 + fs/gfs2/main.c | 103 ++ fs/gfs2/meta_io.c | 876 ++++++++++++ fs/gfs2/meta_io.h | 88 ++ fs/gfs2/mount.c | 211 +++ fs/gfs2/mount.h | 15 + fs/gfs2/ondisk.c | 590 ++++++++ fs/gfs2/ops_address.c | 515 +++++++ fs/gfs2/ops_address.h | 15 + fs/gfs2/ops_dentry.c | 117 ++ fs/gfs2/ops_dentry.h | 15 + fs/gfs2/ops_export.c | 310 +++++ fs/gfs2/ops_export.h | 15 + fs/gfs2/ops_file.c | 1597 ++++++++++++++++++++++ fs/gfs2/ops_file.h | 16 + fs/gfs2/ops_fstype.c | 879 ++++++++++++ fs/gfs2/ops_fstype.h | 15 + fs/gfs2/ops_inode.c | 1265 ++++++++++++++++++ fs/gfs2/ops_inode.h | 18 + fs/gfs2/ops_super.c | 401 ++++++ fs/gfs2/ops_super.h | 15 + fs/gfs2/ops_vm.c | 199 +++ fs/gfs2/ops_vm.h | 16 + fs/gfs2/page.c | 273 ++++ fs/gfs2/page.h | 23 + fs/gfs2/quota.c | 1238 +++++++++++++++++ fs/gfs2/quota.h | 34 + fs/gfs2/recovery.c | 570 ++++++++ fs/gfs2/recovery.h | 32 + fs/gfs2/resize.c | 291 ++++ fs/gfs2/resize.h | 19 + fs/gfs2/rgrp.c | 1361 +++++++++++++++++++ fs/gfs2/rgrp.h | 62 + fs/gfs2/super.c | 944 +++++++++++++ fs/gfs2/super.h | 55 + fs/gfs2/sys.c | 640 +++++++++ fs/gfs2/sys.h | 24 + fs/gfs2/trans.c | 214 +++ fs/gfs2/trans.h | 40 + fs/gfs2/unlinked.c | 453 +++++++ fs/gfs2/unlinked.h | 25 + fs/gfs2/util.c | 273 ++++ fs/gfs2/util.h | 180 +++ include/linux/gfs2_ioctl.h | 32 + include/linux/gfs2_ondisk.h | 454 +++++++ 81 files changed, 29258 insertions(+) create mode 100644 fs/gfs2/Kconfig create mode 100644 fs/gfs2/Makefile create mode 100644 fs/gfs2/acl.c create mode 100644 fs/gfs2/acl.h create mode 100644 fs/gfs2/bits.c create mode 100644 fs/gfs2/bits.h create mode 100644 fs/gfs2/bmap.c create mode 100644 fs/gfs2/bmap.h create mode 100644 fs/gfs2/daemon.c create mode 100644 fs/gfs2/daemon.h create mode 100644 fs/gfs2/dir.c create mode 100644 fs/gfs2/dir.h create mode 100644 fs/gfs2/eaops.c create mode 100644 fs/gfs2/eaops.h create mode 100644 fs/gfs2/eattr.c create mode 100644 fs/gfs2/eattr.h create mode 100644 fs/gfs2/format.h create mode 100644 fs/gfs2/gfs2.h create mode 100644 fs/gfs2/glock.c create mode 100644 fs/gfs2/glock.h create mode 100644 fs/gfs2/glops.c create mode 100644 fs/gfs2/glops.h create mode 100644 fs/gfs2/incore.h create mode 100644 fs/gfs2/inode.c create mode 100644 fs/gfs2/inode.h create mode 100644 fs/gfs2/jdata.c create mode 100644 fs/gfs2/jdata.h create mode 100644 fs/gfs2/lm.c create mode 100644 fs/gfs2/lm.h create mode 100644 fs/gfs2/lm_interface.h create mode 100644 fs/gfs2/locking.c create mode 100644 fs/gfs2/log.c create mode 100644 fs/gfs2/log.h create mode 100644 fs/gfs2/lops.c create mode 100644 fs/gfs2/lops.h create mode 100644 fs/gfs2/lvb.c create mode 100644 fs/gfs2/lvb.h create mode 100644 fs/gfs2/main.c create mode 100644 fs/gfs2/meta_io.c create mode 100644 fs/gfs2/meta_io.h create mode 100644 fs/gfs2/mount.c create mode 100644 fs/gfs2/mount.h create mode 100644 fs/gfs2/ondisk.c create mode 100644 fs/gfs2/ops_address.c create mode 100644 fs/gfs2/ops_address.h create mode 100644 fs/gfs2/ops_dentry.c create mode 100644 fs/gfs2/ops_dentry.h create mode 100644 fs/gfs2/ops_export.c create mode 100644 fs/gfs2/ops_export.h create mode 100644 fs/gfs2/ops_file.c create mode 100644 fs/gfs2/ops_file.h create mode 100644 fs/gfs2/ops_fstype.c create mode 100644 fs/gfs2/ops_fstype.h create mode 100644 fs/gfs2/ops_inode.c create mode 100644 fs/gfs2/ops_inode.h create mode 100644 fs/gfs2/ops_super.c create mode 100644 fs/gfs2/ops_super.h create mode 100644 fs/gfs2/ops_vm.c create mode 100644 fs/gfs2/ops_vm.h create mode 100644 fs/gfs2/page.c create mode 100644 fs/gfs2/page.h create mode 100644 fs/gfs2/quota.c create mode 100644 fs/gfs2/quota.h create mode 100644 fs/gfs2/recovery.c create mode 100644 fs/gfs2/recovery.h create mode 100644 fs/gfs2/resize.c create mode 100644 fs/gfs2/resize.h create mode 100644 fs/gfs2/rgrp.c create mode 100644 fs/gfs2/rgrp.h create mode 100644 fs/gfs2/super.c create mode 100644 fs/gfs2/super.h create mode 100644 fs/gfs2/sys.c create mode 100644 fs/gfs2/sys.h create mode 100644 fs/gfs2/trans.c create mode 100644 fs/gfs2/trans.h create mode 100644 fs/gfs2/unlinked.c create mode 100644 fs/gfs2/unlinked.h create mode 100644 fs/gfs2/util.c create mode 100644 fs/gfs2/util.h create mode 100644 include/linux/gfs2_ioctl.h create mode 100644 include/linux/gfs2_ondisk.h diff --git a/fs/gfs2/Kconfig b/fs/gfs2/Kconfig new file mode 100644 index 000000000000..17cb44bea1c0 --- /dev/null +++ b/fs/gfs2/Kconfig @@ -0,0 +1,46 @@ +config GFS2_FS + tristate "GFS2 file system support" + default m + depends on EXPERIMENTAL + select FS_POSIX_ACL + select SYSFS + help + A cluster filesystem. + + Allows a cluster of computers to simultaneously use a block device + that is shared between them (with FC, iSCSI, NBD, etc...). GFS reads + and writes to the block device like a local filesystem, but also uses + a lock module to allow the computers coordinate their I/O so + filesystem consistency is maintained. One of the nifty features of + GFS is perfect consistency -- changes made to the filesystem on one + machine show up immediately on all other machines in the cluster. + + To use the GFS2 filesystem, you will need to enable one or more of + the below locking modules. Documentation and utilities for GFS2 can + be found here: http://sources.redhat.com/cluster/gfs/ + +config GFS2_FS_LOCKING_NOLOCK + tristate "GFS2 \"nolock\" locking module" + depends on GFS2_FS + help + Single node locking module for GFS2. + + Use this module if you want to use GFS2 on a single node without + its clustering features. You can still take advantage of the + large file support, and upgrade to running a full cluster later on + if required. + + If you will only be using GFS2 in cluster mode, you do not need this + module. + +config GFS2_FS_LOCKING_DLM + tristate "GFS2 DLM locking module" + depends on GFS2_FS + select DLM + help + Multiple node locking module for GFS2 + + Most users of GFS2 will require this module. It provides the locking + interface between GFS2 and the DLM, which is required to use GFS2 + in a cluster environment. + diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile new file mode 100644 index 000000000000..b1bac4f199db --- /dev/null +++ b/fs/gfs2/Makefile @@ -0,0 +1,44 @@ +obj-$(CONFIG_GFS2_FS) += gfs2.o +gfs2-y := \ + acl.o \ + bits.o \ + bmap.o \ + daemon.o \ + dir.o \ + eaops.o \ + eattr.o \ + glock.o \ + glops.o \ + inode.o \ + jdata.o \ + lm.o \ + log.o \ + lops.o \ + locking.o \ + lvb.o \ + main.o \ + meta_io.o \ + mount.o \ + ondisk.o \ + ops_address.o \ + ops_dentry.o \ + ops_export.o \ + ops_file.o \ + ops_fstype.o \ + ops_inode.o \ + ops_super.o \ + ops_vm.o \ + page.o \ + quota.o \ + resize.o \ + recovery.o \ + rgrp.o \ + super.o \ + sys.o \ + trans.o \ + unlinked.o \ + util.o + +obj-$(CONFIG_GFS2_LOCKING_NOLOCK) += locking/nolock/ +obj-$(CONFIG_GFS2_LOCKING_DLM) += locking/dlm/ + diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c new file mode 100644 index 000000000000..33c465a2ab53 --- /dev/null +++ b/fs/gfs2/acl.c @@ -0,0 +1,312 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "acl.h" +#include "eaops.h" +#include "eattr.h" +#include "glock.h" +#include "inode.h" +#include "meta_io.h" +#include "trans.h" + +#define ACL_ACCESS 1 +#define ACL_DEFAULT 0 + +int gfs2_acl_validate_set(struct gfs2_inode *ip, int access, + struct gfs2_ea_request *er, + int *remove, mode_t *mode) +{ + struct posix_acl *acl; + int error; + + error = gfs2_acl_validate_remove(ip, access); + if (error) + return error; + + if (!er->er_data) + return -EINVAL; + + acl = posix_acl_from_xattr(er->er_data, er->er_data_len); + if (IS_ERR(acl)) + return PTR_ERR(acl); + if (!acl) { + *remove = 1; + return 0; + } + + error = posix_acl_valid(acl); + if (error) + goto out; + + if (access) { + error = posix_acl_equiv_mode(acl, mode); + if (!error) + *remove = 1; + else if (error > 0) + error = 0; + } + + out: + posix_acl_release(acl); + + return error; +} + +int gfs2_acl_validate_remove(struct gfs2_inode *ip, int access) +{ + if (!ip->i_sbd->sd_args.ar_posix_acl) + return -EOPNOTSUPP; + if (current->fsuid != ip->i_di.di_uid && !capable(CAP_FOWNER)) + return -EPERM; + if (S_ISLNK(ip->i_di.di_mode)) + return -EOPNOTSUPP; + if (!access && !S_ISDIR(ip->i_di.di_mode)) + return -EACCES; + + return 0; +} + +static int acl_get(struct gfs2_inode *ip, int access, struct posix_acl **acl, + struct gfs2_ea_location *el, char **data, unsigned int *len) +{ + struct gfs2_ea_request er; + struct gfs2_ea_location el_this; + int error; + + if (!ip->i_di.di_eattr) + return 0; + + memset(&er, 0, sizeof(struct gfs2_ea_request)); + if (access) { + er.er_name = GFS2_POSIX_ACL_ACCESS; + er.er_name_len = GFS2_POSIX_ACL_ACCESS_LEN; + } else { + er.er_name = GFS2_POSIX_ACL_DEFAULT; + er.er_name_len = GFS2_POSIX_ACL_DEFAULT_LEN; + } + er.er_type = GFS2_EATYPE_SYS; + + if (!el) + el = &el_this; + + error = gfs2_ea_find(ip, &er, el); + if (error) + return error; + if (!el->el_ea) + return 0; + if (!GFS2_EA_DATA_LEN(el->el_ea)) + goto out; + + er.er_data_len = GFS2_EA_DATA_LEN(el->el_ea); + er.er_data = kmalloc(er.er_data_len, GFP_KERNEL); + error = -ENOMEM; + if (!er.er_data) + goto out; + + error = gfs2_ea_get_copy(ip, el, er.er_data); + if (error) + goto out_kfree; + + if (acl) { + *acl = posix_acl_from_xattr(er.er_data, er.er_data_len); + if (IS_ERR(*acl)) + error = PTR_ERR(*acl); + } + + out_kfree: + if (error || !data) + kfree(er.er_data); + else { + *data = er.er_data; + *len = er.er_data_len; + } + + out: + if (error || el == &el_this) + brelse(el->el_bh); + + return error; +} + +/** + * gfs2_check_acl_locked - Check an ACL to see if we're allowed to do something + * @inode: the file we want to do something to + * @mask: what we want to do + * + * Returns: errno + */ + +int gfs2_check_acl_locked(struct inode *inode, int mask) +{ + struct posix_acl *acl = NULL; + int error; + + error = acl_get(get_v2ip(inode), ACL_ACCESS, &acl, NULL, NULL, NULL); + if (error) + return error; + + if (acl) { + error = posix_acl_permission(inode, acl, mask); + posix_acl_release(acl); + return error; + } + + return -EAGAIN; +} + +int gfs2_check_acl(struct inode *inode, int mask) +{ + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_holder i_gh; + int error; + + error = gfs2_glock_nq_init(ip->i_gl, + LM_ST_SHARED, LM_FLAG_ANY, + &i_gh); + if (!error) { + error = gfs2_check_acl_locked(inode, mask); + gfs2_glock_dq_uninit(&i_gh); + } + + return error; +} + +static int munge_mode(struct gfs2_inode *ip, mode_t mode) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head *dibh; + int error; + + error = gfs2_trans_begin(sdp, RES_DINODE, 0); + if (error) + return error; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + gfs2_assert_withdraw(sdp, + (ip->i_di.di_mode & S_IFMT) == (mode & S_IFMT)); + ip->i_di.di_mode = mode; + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + gfs2_trans_end(sdp); + + return 0; +} + +int gfs2_acl_create(struct gfs2_inode *dip, struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct posix_acl *acl = NULL, *clone; + struct gfs2_ea_request er; + mode_t mode = ip->i_di.di_mode; + int error; + + if (!sdp->sd_args.ar_posix_acl) + return 0; + if (S_ISLNK(ip->i_di.di_mode)) + return 0; + + memset(&er, 0, sizeof(struct gfs2_ea_request)); + er.er_type = GFS2_EATYPE_SYS; + + error = acl_get(dip, ACL_DEFAULT, &acl, NULL, + &er.er_data, &er.er_data_len); + if (error) + return error; + if (!acl) { + mode &= ~current->fs->umask; + if (mode != ip->i_di.di_mode) + error = munge_mode(ip, mode); + return error; + } + + clone = posix_acl_clone(acl, GFP_KERNEL); + error = -ENOMEM; + if (!clone) + goto out; + posix_acl_release(acl); + acl = clone; + + if (S_ISDIR(ip->i_di.di_mode)) { + er.er_name = GFS2_POSIX_ACL_DEFAULT; + er.er_name_len = GFS2_POSIX_ACL_DEFAULT_LEN; + error = gfs2_system_eaops.eo_set(ip, &er); + if (error) + goto out; + } + + error = posix_acl_create_masq(acl, &mode); + if (error < 0) + goto out; + if (error > 0) { + er.er_name = GFS2_POSIX_ACL_ACCESS; + er.er_name_len = GFS2_POSIX_ACL_ACCESS_LEN; + posix_acl_to_xattr(acl, er.er_data, er.er_data_len); + er.er_mode = mode; + er.er_flags = GFS2_ERF_MODE; + error = gfs2_system_eaops.eo_set(ip, &er); + if (error) + goto out; + } else + munge_mode(ip, mode); + + out: + posix_acl_release(acl); + kfree(er.er_data); + return error; +} + +int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr) +{ + struct posix_acl *acl = NULL, *clone; + struct gfs2_ea_location el; + char *data; + unsigned int len; + int error; + + error = acl_get(ip, ACL_ACCESS, &acl, &el, &data, &len); + if (error) + return error; + if (!acl) + return gfs2_setattr_simple(ip, attr); + + clone = posix_acl_clone(acl, GFP_KERNEL); + error = -ENOMEM; + if (!clone) + goto out; + posix_acl_release(acl); + acl = clone; + + error = posix_acl_chmod_masq(acl, attr->ia_mode); + if (!error) { + posix_acl_to_xattr(acl, data, len); + error = gfs2_ea_acl_chmod(ip, &el, attr, data); + } + + out: + posix_acl_release(acl); + brelse(el.el_bh); + kfree(data); + + return error; +} + diff --git a/fs/gfs2/acl.h b/fs/gfs2/acl.h new file mode 100644 index 000000000000..a174b4f6bcc2 --- /dev/null +++ b/fs/gfs2/acl.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __ACL_DOT_H__ +#define __ACL_DOT_H__ + +#define GFS2_POSIX_ACL_ACCESS "posix_acl_access" +#define GFS2_POSIX_ACL_ACCESS_LEN 16 +#define GFS2_POSIX_ACL_DEFAULT "posix_acl_default" +#define GFS2_POSIX_ACL_DEFAULT_LEN 17 + +#define GFS2_ACL_IS_ACCESS(name, len) \ + ((len) == GFS2_POSIX_ACL_ACCESS_LEN && \ + !memcmp(GFS2_POSIX_ACL_ACCESS, (name), (len))) + +#define GFS2_ACL_IS_DEFAULT(name, len) \ + ((len) == GFS2_POSIX_ACL_DEFAULT_LEN && \ + !memcmp(GFS2_POSIX_ACL_DEFAULT, (name), (len))) + +struct gfs2_ea_request; + +int gfs2_acl_validate_set(struct gfs2_inode *ip, int access, + struct gfs2_ea_request *er, + int *remove, mode_t *mode); +int gfs2_acl_validate_remove(struct gfs2_inode *ip, int access); +int gfs2_check_acl_locked(struct inode *inode, int mask); +int gfs2_check_acl(struct inode *inode, int mask); +int gfs2_acl_create(struct gfs2_inode *dip, struct gfs2_inode *ip); +int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr); + +#endif /* __ACL_DOT_H__ */ diff --git a/fs/gfs2/bits.c b/fs/gfs2/bits.c new file mode 100644 index 000000000000..57d420a86adf --- /dev/null +++ b/fs/gfs2/bits.c @@ -0,0 +1,178 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +/* + * These routines are used by the resource group routines (rgrp.c) + * to keep track of block allocation. Each block is represented by two + * bits. One bit indicates whether or not the block is used. (1=used, + * 0=free) The other bit indicates whether or not the block contains a + * dinode or not. (1=dinode, 0=not-dinode) So, each byte represents + * GFS2_NBBY (i.e. 4) blocks. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bits.h" + +static const char valid_change[16] = { + /* current */ + /* n */ 0, 1, 0, 1, + /* e */ 1, 0, 0, 0, + /* w */ 0, 0, 0, 0, + 1, 0, 0, 0 +}; + +/** + * gfs2_setbit - Set a bit in the bitmaps + * @buffer: the buffer that holds the bitmaps + * @buflen: the length (in bytes) of the buffer + * @block: the block to set + * @new_state: the new state of the block + * + */ + +void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, uint32_t block, unsigned char new_state) +{ + unsigned char *byte, *end, cur_state; + unsigned int bit; + + byte = buffer + (block / GFS2_NBBY); + bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; + end = buffer + buflen; + + gfs2_assert(rgd->rd_sbd, byte < end); + + cur_state = (*byte >> bit) & GFS2_BIT_MASK; + + if (valid_change[new_state * 4 + cur_state]) { + *byte ^= cur_state << bit; + *byte |= new_state << bit; + } else + gfs2_consist_rgrpd(rgd); +} + +/** + * gfs2_testbit - test a bit in the bitmaps + * @buffer: the buffer that holds the bitmaps + * @buflen: the length (in bytes) of the buffer + * @block: the block to read + * + */ + +unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, uint32_t block) +{ + unsigned char *byte, *end, cur_state; + unsigned int bit; + + byte = buffer + (block / GFS2_NBBY); + bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; + end = buffer + buflen; + + gfs2_assert(rgd->rd_sbd, byte < end); + + cur_state = (*byte >> bit) & GFS2_BIT_MASK; + + return cur_state; +} + +/** + * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing + * a block in a given allocation state. + * @buffer: the buffer that holds the bitmaps + * @buflen: the length (in bytes) of the buffer + * @goal: start search at this block's bit-pair (within @buffer) + * @old_state: GFS2_BLKST_XXX the state of the block we're looking for; + * bit 0 = alloc(1)/free(0), bit 1 = meta(1)/data(0) + * + * Scope of @goal and returned block number is only within this bitmap buffer, + * not entire rgrp or filesystem. @buffer will be offset from the actual + * beginning of a bitmap block buffer, skipping any header structures. + * + * Return: the block number (bitmap buffer scope) that was found + */ + +uint32_t gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, uint32_t goal, + unsigned char old_state) +{ + unsigned char *byte, *end, alloc; + uint32_t blk = goal; + unsigned int bit; + + byte = buffer + (goal / GFS2_NBBY); + bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE; + end = buffer + buflen; + alloc = (old_state & 1) ? 0 : 0x55; + + while (byte < end) { + if ((*byte & 0x55) == alloc) { + blk += (8 - bit) >> 1; + + bit = 0; + byte++; + + continue; + } + + if (((*byte >> bit) & GFS2_BIT_MASK) == old_state) + return blk; + + bit += GFS2_BIT_SIZE; + if (bit >= 8) { + bit = 0; + byte++; + } + + blk++; + } + + return BFITNOENT; +} + +/** + * gfs2_bitcount - count the number of bits in a certain state + * @buffer: the buffer that holds the bitmaps + * @buflen: the length (in bytes) of the buffer + * @state: the state of the block we're looking for + * + * Returns: The number of bits + */ + +uint32_t gfs2_bitcount(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, unsigned char state) +{ + unsigned char *byte = buffer; + unsigned char *end = buffer + buflen; + unsigned char state1 = state << 2; + unsigned char state2 = state << 4; + unsigned char state3 = state << 6; + uint32_t count = 0; + + for (; byte < end; byte++) { + if (((*byte) & 0x03) == state) + count++; + if (((*byte) & 0x0C) == state1) + count++; + if (((*byte) & 0x30) == state2) + count++; + if (((*byte) & 0xC0) == state3) + count++; + } + + return count; +} + diff --git a/fs/gfs2/bits.h b/fs/gfs2/bits.h new file mode 100644 index 000000000000..36ccbdcb1eef --- /dev/null +++ b/fs/gfs2/bits.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __BITS_DOT_H__ +#define __BITS_DOT_H__ + +#define BFITNOENT 0xFFFFFFFF + +void gfs2_setbit(struct gfs2_rgrpd *rgd, + unsigned char *buffer, unsigned int buflen, + uint32_t block, unsigned char new_state); +unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, + unsigned char *buffer, unsigned int buflen, + uint32_t block); +uint32_t gfs2_bitfit(struct gfs2_rgrpd *rgd, + unsigned char *buffer, unsigned int buflen, + uint32_t goal, unsigned char old_state); +uint32_t gfs2_bitcount(struct gfs2_rgrpd *rgd, + unsigned char *buffer, unsigned int buflen, + unsigned char state); + +#endif /* __BITS_DOT_H__ */ diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c new file mode 100644 index 000000000000..4b4e295b3bf5 --- /dev/null +++ b/fs/gfs2/bmap.c @@ -0,0 +1,1206 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "glock.h" +#include "inode.h" +#include "jdata.h" +#include "meta_io.h" +#include "page.h" +#include "quota.h" +#include "rgrp.h" +#include "trans.h" + +/* This doesn't need to be that large as max 64 bit pointers in a 4k + * block is 512, so __u16 is fine for that. It saves stack space to + * keep it small. + */ +struct metapath { + __u16 mp_list[GFS2_MAX_META_HEIGHT]; +}; + +typedef int (*block_call_t) (struct gfs2_inode *ip, struct buffer_head *dibh, + struct buffer_head *bh, uint64_t *top, + uint64_t *bottom, unsigned int height, + void *data); + +struct strip_mine { + int sm_first; + unsigned int sm_height; +}; + +/** + * @gfs2_unstuffer_sync - Synchronously unstuff a dinode + * @ip: + * @dibh: + * @block: + * @private: + * + * Cheat and use a metadata buffer instead of a data page. + * + * Returns: errno + */ + +int gfs2_unstuffer_sync(struct gfs2_inode *ip, struct buffer_head *dibh, + uint64_t block, void *private) +{ + struct buffer_head *bh; + int error; + + bh = gfs2_meta_new(ip->i_gl, block); + + gfs2_buffer_copy_tail(bh, 0, dibh, sizeof(struct gfs2_dinode)); + + set_buffer_dirty(bh); + error = sync_dirty_buffer(bh); + + brelse(bh); + + return error; +} + +/** + * gfs2_unstuff_dinode - Unstuff a dinode when the data has grown too big + * @ip: The GFS2 inode to unstuff + * @unstuffer: the routine that handles unstuffing a non-zero length file + * @private: private data for the unstuffer + * + * This routine unstuffs a dinode and returns it to a "normal" state such + * that the height can be grown in the traditional way. + * + * Returns: errno + */ + +int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, + void *private) +{ + struct buffer_head *bh, *dibh; + uint64_t block = 0; + int journaled = gfs2_is_jdata(ip); + int error; + + down_write(&ip->i_rw_mutex); + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto out; + + if (ip->i_di.di_size) { + /* Get a free block, fill it with the stuffed data, + and write it out to disk */ + + if (journaled) { + block = gfs2_alloc_meta(ip); + + error = gfs2_jdata_get_buffer(ip, block, 1, &bh); + if (error) + goto out_brelse; + gfs2_buffer_copy_tail(bh, + sizeof(struct gfs2_meta_header), + dibh, sizeof(struct gfs2_dinode)); + brelse(bh); + } else { + block = gfs2_alloc_data(ip); + + error = unstuffer(ip, dibh, block, private); + if (error) + goto out_brelse; + } + } + + /* Set up the pointer to the new block */ + + gfs2_trans_add_bh(ip->i_gl, dibh); + + gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); + + if (ip->i_di.di_size) { + *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) = cpu_to_be64(block); + ip->i_di.di_blocks++; + } + + ip->i_di.di_height = 1; + + gfs2_dinode_out(&ip->i_di, dibh->b_data); + + out_brelse: + brelse(dibh); + + out: + up_write(&ip->i_rw_mutex); + + return error; +} + +/** + * calc_tree_height - Calculate the height of a metadata tree + * @ip: The GFS2 inode + * @size: The proposed size of the file + * + * Work out how tall a metadata tree needs to be in order to accommodate a + * file of a particular size. If size is less than the current size of + * the inode, then the current size of the inode is used instead of the + * supplied one. + * + * Returns: the height the tree should be + */ + +static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + uint64_t *arr; + unsigned int max, height; + + if (ip->i_di.di_size > size) + size = ip->i_di.di_size; + + if (gfs2_is_jdata(ip)) { + arr = sdp->sd_jheightsize; + max = sdp->sd_max_jheight; + } else { + arr = sdp->sd_heightsize; + max = sdp->sd_max_height; + } + + for (height = 0; height < max; height++) + if (arr[height] >= size) + break; + + return height; +} + +/** + * build_height - Build a metadata tree of the requested height + * @ip: The GFS2 inode + * @height: The height to build to + * + * This routine makes sure that the metadata tree is tall enough to hold + * "size" bytes of data. + * + * Returns: errno + */ + +static int build_height(struct gfs2_inode *ip, int height) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head *bh, *dibh; + uint64_t block = 0, *bp; + unsigned int x; + int new_block; + int error; + + while (ip->i_di.di_height < height) { + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + return error; + + new_block = 0; + bp = (uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)); + for (x = 0; x < sdp->sd_diptrs; x++, bp++) + if (*bp) { + new_block = 1; + break; + } + + if (new_block) { + /* Get a new block, fill it with the old direct + pointers, and write it out */ + + block = gfs2_alloc_meta(ip); + + bh = gfs2_meta_new(ip->i_gl, block); + gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_metatype_set(bh, + GFS2_METATYPE_IN, + GFS2_FORMAT_IN); + gfs2_buffer_copy_tail(bh, + sizeof(struct gfs2_meta_header), + dibh, sizeof(struct gfs2_dinode)); + + brelse(bh); + } + + /* Set up the new direct pointer and write it out to disk */ + + gfs2_trans_add_bh(ip->i_gl, dibh); + + gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); + + if (new_block) { + *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) = cpu_to_be64(block); + ip->i_di.di_blocks++; + } + + ip->i_di.di_height++; + + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + return 0; +} + +/** + * find_metapath - Find path through the metadata tree + * @ip: The inode pointer + * @mp: The metapath to return the result in + * @block: The disk block to look up + * + * This routine returns a struct metapath structure that defines a path + * through the metadata of inode "ip" to get to block "block". + * + * Example: + * Given: "ip" is a height 3 file, "offset" is 101342453, and this is a + * filesystem with a blocksize of 4096. + * + * find_metapath() would return a struct metapath structure set to: + * mp_offset = 101342453, mp_height = 3, mp_list[0] = 0, mp_list[1] = 48, + * and mp_list[2] = 165. + * + * That means that in order to get to the block containing the byte at + * offset 101342453, we would load the indirect block pointed to by pointer + * 0 in the dinode. We would then load the indirect block pointed to by + * pointer 48 in that indirect block. We would then load the data block + * pointed to by pointer 165 in that indirect block. + * + * ---------------------------------------- + * | Dinode | | + * | | 4| + * | |0 1 2 3 4 5 9| + * | | 6| + * ---------------------------------------- + * | + * | + * V + * ---------------------------------------- + * | Indirect Block | + * | 5| + * | 4 4 4 4 4 5 5 1| + * |0 5 6 7 8 9 0 1 2| + * ---------------------------------------- + * | + * | + * V + * ---------------------------------------- + * | Indirect Block | + * | 1 1 1 1 1 5| + * | 6 6 6 6 6 1| + * |0 3 4 5 6 7 2| + * ---------------------------------------- + * | + * | + * V + * ---------------------------------------- + * | Data block containing offset | + * | 101342453 | + * | | + * | | + * ---------------------------------------- + * + */ + +static void find_metapath(struct gfs2_inode *ip, uint64_t block, struct metapath *mp) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + uint64_t b = block; + unsigned int i; + + for (i = ip->i_di.di_height; i--;) + mp->mp_list[i] = (__u16)do_div(b, sdp->sd_inptrs); + +} + +/** + * metapointer - Return pointer to start of metadata in a buffer + * @bh: The buffer + * @height: The metadata height (0 = dinode) + * @mp: The metapath + * + * Return a pointer to the block number of the next height of the metadata + * tree given a buffer containing the pointer to the current height of the + * metadata tree. + */ + +static inline uint64_t *metapointer(struct buffer_head *bh, + unsigned int height, struct metapath *mp) +{ + unsigned int head_size = (height > 0) ? + sizeof(struct gfs2_meta_header) : sizeof(struct gfs2_dinode); + + return ((uint64_t *)(bh->b_data + head_size)) + mp->mp_list[height]; +} + +/** + * lookup_block - Get the next metadata block in metadata tree + * @ip: The GFS2 inode + * @bh: Buffer containing the pointers to metadata blocks + * @height: The height of the tree (0 = dinode) + * @mp: The metapath + * @create: Non-zero if we may create a new meatdata block + * @new: Used to indicate if we did create a new metadata block + * @block: the returned disk block number + * + * Given a metatree, complete to a particular height, checks to see if the next + * height of the tree exists. If not the next height of the tree is created. + * The block number of the next height of the metadata tree is returned. + * + */ + +static void lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, + unsigned int height, struct metapath *mp, int create, + int *new, uint64_t *block) +{ + uint64_t *ptr = metapointer(bh, height, mp); + + if (*ptr) { + *block = be64_to_cpu(*ptr); + return; + } + + *block = 0; + + if (!create) + return; + + if (height == ip->i_di.di_height - 1 && + !gfs2_is_jdata(ip)) + *block = gfs2_alloc_data(ip); + else + *block = gfs2_alloc_meta(ip); + + gfs2_trans_add_bh(ip->i_gl, bh); + + *ptr = cpu_to_be64(*block); + ip->i_di.di_blocks++; + + *new = 1; +} + +/** + * gfs2_block_map - Map a block from an inode to a disk block + * @ip: The GFS2 inode + * @lblock: The logical block number + * @new: Value/Result argument (1 = may create/did create new blocks) + * @dblock: the disk block number of the start of an extent + * @extlen: the size of the extent + * + * Find the block number on the current device which corresponds to an + * inode's block. If the block had to be created, "new" will be set. + * + * Returns: errno + */ + +int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, + uint64_t *dblock, uint32_t *extlen) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head *bh; + struct metapath mp; + int create = *new; + unsigned int bsize; + unsigned int height; + unsigned int end_of_metadata; + unsigned int x; + int error = 0; + + *new = 0; + *dblock = 0; + if (extlen) + *extlen = 0; + + if (create) + down_write(&ip->i_rw_mutex); + else + down_read(&ip->i_rw_mutex); + + if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) + goto out; + + bsize = (gfs2_is_jdata(ip)) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize; + + height = calc_tree_height(ip, (lblock + 1) * bsize); + if (ip->i_di.di_height < height) { + if (!create) + goto out; + + error = build_height(ip, height); + if (error) + goto out; + } + + find_metapath(ip, lblock, &mp); + end_of_metadata = ip->i_di.di_height - 1; + + error = gfs2_meta_inode_buffer(ip, &bh); + if (error) + goto out; + + for (x = 0; x < end_of_metadata; x++) { + lookup_block(ip, bh, x, &mp, create, new, dblock); + brelse(bh); + if (!*dblock) + goto out; + + error = gfs2_meta_indirect_buffer(ip, x+1, *dblock, *new, &bh); + if (error) + goto out; + } + + lookup_block(ip, bh, end_of_metadata, &mp, create, new, dblock); + + if (extlen && *dblock) { + *extlen = 1; + + if (!*new) { + uint64_t tmp_dblock; + int tmp_new; + unsigned int nptrs; + + nptrs = (end_of_metadata) ? sdp->sd_inptrs : + sdp->sd_diptrs; + + while (++mp.mp_list[end_of_metadata] < nptrs) { + lookup_block(ip, bh, end_of_metadata, &mp, + 0, &tmp_new, &tmp_dblock); + + if (*dblock + *extlen != tmp_dblock) + break; + + (*extlen)++; + } + } + } + + brelse(bh); + + if (*new) { + error = gfs2_meta_inode_buffer(ip, &bh); + if (!error) { + gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_dinode_out(&ip->i_di, bh->b_data); + brelse(bh); + } + } + + out: + if (create) + up_write(&ip->i_rw_mutex); + else + up_read(&ip->i_rw_mutex); + + return error; +} + +/** + * recursive_scan - recursively scan through the end of a file + * @ip: the inode + * @dibh: the dinode buffer + * @mp: the path through the metadata to the point to start + * @height: the height the recursion is at + * @block: the indirect block to look at + * @first: 1 if this is the first block + * @bc: the call to make for each piece of metadata + * @data: data opaque to this function to pass to @bc + * + * When this is first called @height and @block should be zero and + * @first should be 1. + * + * Returns: errno + */ + +static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh, + struct metapath *mp, unsigned int height, + uint64_t block, int first, block_call_t bc, + void *data) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head *bh = NULL; + uint64_t *top, *bottom; + uint64_t bn; + int error; + int mh_size = sizeof(struct gfs2_meta_header); + + if (!height) { + error = gfs2_meta_inode_buffer(ip, &bh); + if (error) + return error; + dibh = bh; + + top = (uint64_t *)(bh->b_data + sizeof(struct gfs2_dinode)) + + mp->mp_list[0]; + bottom = (uint64_t *)(bh->b_data + sizeof(struct gfs2_dinode)) + + sdp->sd_diptrs; + } else { + error = gfs2_meta_indirect_buffer(ip, height, block, 0, &bh); + if (error) + return error; + + top = (uint64_t *)(bh->b_data + mh_size) + + ((first) ? mp->mp_list[height] : 0); + + bottom = (uint64_t *)(bh->b_data + mh_size) + sdp->sd_inptrs; + } + + error = bc(ip, dibh, bh, top, bottom, height, data); + if (error) + goto out; + + if (height < ip->i_di.di_height - 1) + for (; top < bottom; top++, first = 0) { + if (!*top) + continue; + + bn = be64_to_cpu(*top); + + error = recursive_scan(ip, dibh, mp, height + 1, bn, + first, bc, data); + if (error) + break; + } + + out: + brelse(bh); + + return error; +} + +/** + * do_strip - Look for a layer a particular layer of the file and strip it off + * @ip: the inode + * @dibh: the dinode buffer + * @bh: A buffer of pointers + * @top: The first pointer in the buffer + * @bottom: One more than the last pointer + * @height: the height this buffer is at + * @data: a pointer to a struct strip_mine + * + * Returns: errno + */ + +static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, + struct buffer_head *bh, uint64_t *top, uint64_t *bottom, + unsigned int height, void *data) +{ + struct strip_mine *sm = (struct strip_mine *)data; + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_rgrp_list rlist; + uint64_t bn, bstart; + uint32_t blen; + uint64_t *p; + unsigned int rg_blocks = 0; + int metadata; + unsigned int revokes = 0; + int x; + int error; + + if (!*top) + sm->sm_first = 0; + + if (height != sm->sm_height) + return 0; + + if (sm->sm_first) { + top++; + sm->sm_first = 0; + } + + metadata = (height != ip->i_di.di_height - 1) || gfs2_is_jdata(ip); + if (metadata) + revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs; + + error = gfs2_rindex_hold(sdp, &ip->i_alloc.al_ri_gh); + if (error) + return error; + + memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); + bstart = 0; + blen = 0; + + for (p = top; p < bottom; p++) { + if (!*p) + continue; + + bn = be64_to_cpu(*p); + + if (bstart + blen == bn) + blen++; + else { + if (bstart) + gfs2_rlist_add(sdp, &rlist, bstart); + + bstart = bn; + blen = 1; + } + } + + if (bstart) + gfs2_rlist_add(sdp, &rlist, bstart); + else + goto out; /* Nothing to do */ + + gfs2_rlist_alloc(&rlist, LM_ST_EXCLUSIVE, 0); + + for (x = 0; x < rlist.rl_rgrps; x++) { + struct gfs2_rgrpd *rgd; + rgd = get_gl2rgd(rlist.rl_ghs[x].gh_gl); + rg_blocks += rgd->rd_ri.ri_length; + } + + error = gfs2_glock_nq_m(rlist.rl_rgrps, rlist.rl_ghs); + if (error) + goto out_rlist; + + error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + + RES_INDIRECT + RES_STATFS + RES_QUOTA, + revokes); + if (error) + goto out_rg_gunlock; + + down_write(&ip->i_rw_mutex); + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, bh); + + bstart = 0; + blen = 0; + + for (p = top; p < bottom; p++) { + if (!*p) + continue; + + bn = be64_to_cpu(*p); + + if (bstart + blen == bn) + blen++; + else { + if (bstart) { + if (metadata) + gfs2_free_meta(ip, bstart, blen); + else + gfs2_free_data(ip, bstart, blen); + } + + bstart = bn; + blen = 1; + } + + *p = 0; + if (!ip->i_di.di_blocks) + gfs2_consist_inode(ip); + ip->i_di.di_blocks--; + } + if (bstart) { + if (metadata) + gfs2_free_meta(ip, bstart, blen); + else + gfs2_free_data(ip, bstart, blen); + } + + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + + gfs2_dinode_out(&ip->i_di, dibh->b_data); + + up_write(&ip->i_rw_mutex); + + gfs2_trans_end(sdp); + + out_rg_gunlock: + gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); + + out_rlist: + gfs2_rlist_free(&rlist); + + out: + gfs2_glock_dq_uninit(&ip->i_alloc.al_ri_gh); + + return error; +} + +/** + * do_grow - Make a file look bigger than it is + * @ip: the inode + * @size: the size to set the file to + * + * Called with an exclusive lock on @ip. + * + * Returns: errno + */ + +static int do_grow(struct gfs2_inode *ip, uint64_t size) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al; + struct buffer_head *dibh; + unsigned int h; + int error; + + al = gfs2_alloc_get(ip); + + error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out; + + error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid); + if (error) + goto out_gunlock_q; + + al->al_requested = sdp->sd_max_height + RES_DATA; + + error = gfs2_inplace_reserve(ip); + if (error) + goto out_gunlock_q; + + error = gfs2_trans_begin(sdp, + sdp->sd_max_height + al->al_rgd->rd_ri.ri_length + + RES_JDATA + RES_DINODE + RES_STATFS + RES_QUOTA, 0); + if (error) + goto out_ipres; + + if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) { + if (gfs2_is_stuffed(ip)) { + error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, + NULL); + if (error) + goto out_end_trans; + } + + h = calc_tree_height(ip, size); + if (ip->i_di.di_height < h) { + down_write(&ip->i_rw_mutex); + error = build_height(ip, h); + up_write(&ip->i_rw_mutex); + if (error) + goto out_end_trans; + } + } + + ip->i_di.di_size = size; + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto out_end_trans; + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + + out_end_trans: + gfs2_trans_end(sdp); + + out_ipres: + gfs2_inplace_release(ip); + + out_gunlock_q: + gfs2_quota_unlock(ip); + + out: + gfs2_alloc_put(ip); + + return error; +} + +static int truncator_journaled(struct gfs2_inode *ip, uint64_t size) +{ + uint64_t lbn, dbn; + uint32_t off; + struct buffer_head *bh; + int new = 0; + int error; + + lbn = size; + off = do_div(lbn, ip->i_sbd->sd_jbsize); + + error = gfs2_block_map(ip, lbn, &new, &dbn, NULL); + if (error || !dbn) + return error; + + error = gfs2_jdata_get_buffer(ip, dbn, 0, &bh); + if (error) + return error; + + gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header) + off); + + brelse(bh); + + return 0; +} + +static int trunc_start(struct gfs2_inode *ip, uint64_t size, + gfs2_truncator_t truncator) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head *dibh; + int journaled = gfs2_is_jdata(ip); + int error; + + error = gfs2_trans_begin(sdp, + RES_DINODE + ((journaled) ? RES_JDATA : 0), 0); + if (error) + return error; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto out; + + if (gfs2_is_stuffed(ip)) { + ip->i_di.di_size = size; + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode) + size); + error = 1; + + } else { + if (journaled) { + uint64_t junk = size; + /* we're just interested in the modulus */ + if (do_div(junk, sdp->sd_jbsize)) + error = truncator_journaled(ip, size); + } else if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1)) + error = truncator(ip, size); + + if (!error) { + ip->i_di.di_size = size; + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + ip->i_di.di_flags |= GFS2_DIF_TRUNC_IN_PROG; + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + } + } + + brelse(dibh); + + out: + gfs2_trans_end(sdp); + + return error; +} + +static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size) +{ + unsigned int height = ip->i_di.di_height; + uint64_t lblock; + struct metapath mp; + int error; + + if (!size) + lblock = 0; + else if (gfs2_is_jdata(ip)) { + lblock = size - 1; + do_div(lblock, ip->i_sbd->sd_jbsize); + } else + lblock = (size - 1) >> ip->i_sbd->sd_sb.sb_bsize_shift; + + find_metapath(ip, lblock, &mp); + gfs2_alloc_get(ip); + + error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out; + + while (height--) { + struct strip_mine sm; + sm.sm_first = !!size; + sm.sm_height = height; + + error = recursive_scan(ip, NULL, &mp, 0, 0, 1, do_strip, &sm); + if (error) + break; + } + + gfs2_quota_unhold(ip); + + out: + gfs2_alloc_put(ip); + return error; +} + +static int trunc_end(struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head *dibh; + int error; + + error = gfs2_trans_begin(sdp, RES_DINODE, 0); + if (error) + return error; + + down_write(&ip->i_rw_mutex); + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto out; + + if (!ip->i_di.di_size) { + ip->i_di.di_height = 0; + ip->i_di.di_goal_meta = + ip->i_di.di_goal_data = + ip->i_num.no_addr; + gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); + } + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + ip->i_di.di_flags &= ~GFS2_DIF_TRUNC_IN_PROG; + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + + out: + up_write(&ip->i_rw_mutex); + + gfs2_trans_end(sdp); + + return error; +} + +/** + * do_shrink - make a file smaller + * @ip: the inode + * @size: the size to make the file + * @truncator: function to truncate the last partial block + * + * Called with an exclusive lock on @ip. + * + * Returns: errno + */ + +static int do_shrink(struct gfs2_inode *ip, uint64_t size, + gfs2_truncator_t truncator) +{ + int error; + + error = trunc_start(ip, size, truncator); + if (error < 0) + return error; + if (error > 0) + return 0; + + error = trunc_dealloc(ip, size); + if (!error) + error = trunc_end(ip); + + return error; +} + +/** + * gfs2_truncatei - make a file a give size + * @ip: the inode + * @size: the size to make the file + * @truncator: function to truncate the last partial block + * + * The file size can grow, shrink, or stay the same size. + * + * Returns: errno + */ + +int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size, + gfs2_truncator_t truncator) +{ + int error; + + if (gfs2_assert_warn(ip->i_sbd, S_ISREG(ip->i_di.di_mode))) + return -EINVAL; + + if (size > ip->i_di.di_size) + error = do_grow(ip, size); + else + error = do_shrink(ip, size, truncator); + + return error; +} + +int gfs2_truncatei_resume(struct gfs2_inode *ip) +{ + int error; + error = trunc_dealloc(ip, ip->i_di.di_size); + if (!error) + error = trunc_end(ip); + return error; +} + +int gfs2_file_dealloc(struct gfs2_inode *ip) +{ + return trunc_dealloc(ip, 0); +} + +/** + * gfs2_write_calc_reserv - calculate number of blocks needed to write to a file + * @ip: the file + * @len: the number of bytes to be written to the file + * @data_blocks: returns the number of data blocks required + * @ind_blocks: returns the number of indirect blocks required + * + */ + +void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, + unsigned int *data_blocks, unsigned int *ind_blocks) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + unsigned int tmp; + + if (gfs2_is_jdata(ip)) { + *data_blocks = DIV_RU(len, sdp->sd_jbsize) + 2; + *ind_blocks = 3 * (sdp->sd_max_jheight - 1); + } else { + *data_blocks = (len >> sdp->sd_sb.sb_bsize_shift) + 3; + *ind_blocks = 3 * (sdp->sd_max_height - 1); + } + + for (tmp = *data_blocks; tmp > sdp->sd_diptrs;) { + tmp = DIV_RU(tmp, sdp->sd_inptrs); + *ind_blocks += tmp; + } +} + +/** + * gfs2_write_alloc_required - figure out if a write will require an allocation + * @ip: the file being written to + * @offset: the offset to write to + * @len: the number of bytes being written + * @alloc_required: set to 1 if an alloc is required, 0 otherwise + * + * Returns: errno + */ + +int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, + unsigned int len, int *alloc_required) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + uint64_t lblock, lblock_stop, dblock; + uint32_t extlen; + int new = 0; + int error = 0; + + *alloc_required = 0; + + if (!len) + return 0; + + if (gfs2_is_stuffed(ip)) { + if (offset + len > + sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) + *alloc_required = 1; + return 0; + } + + if (gfs2_is_jdata(ip)) { + unsigned int bsize = sdp->sd_jbsize; + lblock = offset; + do_div(lblock, bsize); + lblock_stop = offset + len + bsize - 1; + do_div(lblock_stop, bsize); + } else { + unsigned int shift = sdp->sd_sb.sb_bsize_shift; + lblock = offset >> shift; + lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift; + } + + for (; lblock < lblock_stop; lblock += extlen) { + error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); + if (error) + return error; + + if (!dblock) { + *alloc_required = 1; + return 0; + } + } + + return 0; +} + +/** + * do_gfm - Copy out the dinode/indirect blocks of a file + * @ip: the file + * @dibh: the dinode buffer + * @bh: the indirect buffer we're looking at + * @top: the first pointer in the block + * @bottom: one more than the last pointer in the block + * @height: the height the block is at + * @data: a pointer to a struct gfs2_user_buffer structure + * + * If this is a journaled file, copy out the data too. + * + * Returns: errno + */ + +static int do_gfm(struct gfs2_inode *ip, struct buffer_head *dibh, + struct buffer_head *bh, uint64_t *top, uint64_t *bottom, + unsigned int height, void *data) +{ + struct gfs2_user_buffer *ub = (struct gfs2_user_buffer *)data; + int error; + + error = gfs2_add_bh_to_ub(ub, bh); + if (error) + return error; + + if (!S_ISDIR(ip->i_di.di_mode) || + height + 1 != ip->i_di.di_height) + return 0; + + for (; top < bottom; top++) + if (*top) { + struct buffer_head *data_bh; + + error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*top), + DIO_START | DIO_WAIT, + &data_bh); + if (error) + return error; + + error = gfs2_add_bh_to_ub(ub, data_bh); + + brelse(data_bh); + + if (error) + return error; + } + + return 0; +} + +/** + * gfs2_get_file_meta - return all the metadata for a file + * @ip: the file + * @ub: the structure representing the meta + * + * Returns: errno + */ + +int gfs2_get_file_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub) +{ + int error; + + if (gfs2_is_stuffed(ip)) { + struct buffer_head *dibh; + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + error = gfs2_add_bh_to_ub(ub, dibh); + brelse(dibh); + } + } else { + struct metapath mp; + find_metapath(ip, 0, &mp); + error = recursive_scan(ip, NULL, &mp, 0, 0, 1, do_gfm, ub); + } + + return error; +} + diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h new file mode 100644 index 000000000000..de16e44f049f --- /dev/null +++ b/fs/gfs2/bmap.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __BMAP_DOT_H__ +#define __BMAP_DOT_H__ + +typedef int (*gfs2_unstuffer_t) (struct gfs2_inode * ip, + struct buffer_head * dibh, uint64_t block, + void *private); +int gfs2_unstuffer_sync(struct gfs2_inode *ip, struct buffer_head *dibh, + uint64_t block, void *private); +int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, + void *private); + +int gfs2_block_map(struct gfs2_inode *ip, + uint64_t lblock, int *new, + uint64_t *dblock, uint32_t *extlen); + +typedef int (*gfs2_truncator_t) (struct gfs2_inode * ip, uint64_t size); +int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size, + gfs2_truncator_t truncator); +int gfs2_truncatei_resume(struct gfs2_inode *ip); +int gfs2_file_dealloc(struct gfs2_inode *ip); + +void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, + unsigned int *data_blocks, + unsigned int *ind_blocks); +int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, + unsigned int len, int *alloc_required); + +int gfs2_get_file_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub); + +#endif /* __BMAP_DOT_H__ */ diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c new file mode 100644 index 000000000000..cff8d5368d21 --- /dev/null +++ b/fs/gfs2/daemon.c @@ -0,0 +1,225 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "daemon.h" +#include "glock.h" +#include "log.h" +#include "quota.h" +#include "recovery.h" +#include "super.h" +#include "unlinked.h" + +/* This uses schedule_timeout() instead of msleep() because it's good for + the daemons to wake up more often than the timeout when unmounting so + the user's unmount doesn't sit there forever. + + The kthread functions used to start these daemons block and flush signals. */ + +/** + * gfs2_scand - Look for cached glocks and inodes to toss from memory + * @sdp: Pointer to GFS2 superblock + * + * One of these daemons runs, finding candidates to add to sd_reclaim_list. + * See gfs2_glockd() + */ + +int gfs2_scand(void *data) +{ + struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + unsigned long t; + + while (!kthread_should_stop()) { + gfs2_scand_internal(sdp); + t = gfs2_tune_get(sdp, gt_scand_secs) * HZ; + schedule_timeout_interruptible(t); + } + + return 0; +} + +/** + * gfs2_glockd - Reclaim unused glock structures + * @sdp: Pointer to GFS2 superblock + * + * One or more of these daemons run, reclaiming glocks on sd_reclaim_list. + * Number of daemons can be set by user, with num_glockd mount option. + */ + +int gfs2_glockd(void *data) +{ + struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + DECLARE_WAITQUEUE(wait_chan, current); + + while (!kthread_should_stop()) { + while (atomic_read(&sdp->sd_reclaim_count)) + gfs2_reclaim_glock(sdp); + + set_current_state(TASK_INTERRUPTIBLE); + add_wait_queue(&sdp->sd_reclaim_wq, &wait_chan); + if (!atomic_read(&sdp->sd_reclaim_count) && + !kthread_should_stop()) + schedule(); + remove_wait_queue(&sdp->sd_reclaim_wq, &wait_chan); + set_current_state(TASK_RUNNING); + } + + return 0; +} + +/** + * gfs2_recoverd - Recover dead machine's journals + * @sdp: Pointer to GFS2 superblock + * + */ + +int gfs2_recoverd(void *data) +{ + struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + unsigned long t; + + while (!kthread_should_stop()) { + gfs2_check_journals(sdp); + t = gfs2_tune_get(sdp, gt_recoverd_secs) * HZ; + schedule_timeout_interruptible(t); + } + + return 0; +} + +/** + * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks + * @sdp: Pointer to GFS2 superblock + * + * Also, periodically check to make sure that we're using the most recent + * journal index. + */ + +int gfs2_logd(void *data) +{ + struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + struct gfs2_holder ji_gh; + unsigned long t; + + while (!kthread_should_stop()) { + /* Advance the log tail */ + + t = sdp->sd_log_flush_time + + gfs2_tune_get(sdp, gt_log_flush_secs) * HZ; + + gfs2_ail1_empty(sdp, DIO_ALL); + + if (time_after_eq(jiffies, t)) { + gfs2_log_flush(sdp); + sdp->sd_log_flush_time = jiffies; + } + + /* Check for latest journal index */ + + t = sdp->sd_jindex_refresh_time + + gfs2_tune_get(sdp, gt_jindex_refresh_secs) * HZ; + + if (time_after_eq(jiffies, t)) { + if (!gfs2_jindex_hold(sdp, &ji_gh)) + gfs2_glock_dq_uninit(&ji_gh); + sdp->sd_jindex_refresh_time = jiffies; + } + + t = gfs2_tune_get(sdp, gt_logd_secs) * HZ; + schedule_timeout_interruptible(t); + } + + return 0; +} + +/** + * gfs2_quotad - Write cached quota changes into the quota file + * @sdp: Pointer to GFS2 superblock + * + */ + +int gfs2_quotad(void *data) +{ + struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + unsigned long t; + int error; + + while (!kthread_should_stop()) { + /* Update the master statfs file */ + + t = sdp->sd_statfs_sync_time + + gfs2_tune_get(sdp, gt_statfs_quantum) * HZ; + + if (time_after_eq(jiffies, t)) { + error = gfs2_statfs_sync(sdp); + if (error && + error != -EROFS && + !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) + fs_err(sdp, "quotad: (1) error=%d\n", error); + sdp->sd_statfs_sync_time = jiffies; + } + + /* Update quota file */ + + t = sdp->sd_quota_sync_time + + gfs2_tune_get(sdp, gt_quota_quantum) * HZ; + + if (time_after_eq(jiffies, t)) { + error = gfs2_quota_sync(sdp); + if (error && + error != -EROFS && + !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) + fs_err(sdp, "quotad: (2) error=%d\n", error); + sdp->sd_quota_sync_time = jiffies; + } + + gfs2_quota_scan(sdp); + + t = gfs2_tune_get(sdp, gt_quotad_secs) * HZ; + schedule_timeout_interruptible(t); + } + + return 0; +} + +/** + * gfs2_inoded - Deallocate unlinked inodes + * @sdp: Pointer to GFS2 superblock + * + */ + +int gfs2_inoded(void *data) +{ + struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + unsigned long t; + int error; + + while (!kthread_should_stop()) { + error = gfs2_unlinked_dealloc(sdp); + if (error && + error != -EROFS && + !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) + fs_err(sdp, "inoded: error = %d\n", error); + + t = gfs2_tune_get(sdp, gt_inoded_secs) * HZ; + schedule_timeout_interruptible(t); + } + + return 0; +} + diff --git a/fs/gfs2/daemon.h b/fs/gfs2/daemon.h new file mode 100644 index 000000000000..a27fdeda5fbb --- /dev/null +++ b/fs/gfs2/daemon.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __DAEMON_DOT_H__ +#define __DAEMON_DOT_H__ + +int gfs2_scand(void *data); +int gfs2_glockd(void *data); +int gfs2_recoverd(void *data); +int gfs2_logd(void *data); +int gfs2_quotad(void *data); +int gfs2_inoded(void *data); + +#endif /* __DAEMON_DOT_H__ */ diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c new file mode 100644 index 000000000000..6b1dc3dc3a2d --- /dev/null +++ b/fs/gfs2/dir.c @@ -0,0 +1,2157 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +/* +* Implements Extendible Hashing as described in: +* "Extendible Hashing" by Fagin, et al in +* __ACM Trans. on Database Systems__, Sept 1979. +* +* +* Here's the layout of dirents which is essentially the same as that of ext2 +* within a single block. The field de_name_len is the number of bytes +* actually required for the name (no null terminator). The field de_rec_len +* is the number of bytes allocated to the dirent. The offset of the next +* dirent in the block is (dirent + dirent->de_rec_len). When a dirent is +* deleted, the preceding dirent inherits its allocated space, ie +* prev->de_rec_len += deleted->de_rec_len. Since the next dirent is obtained +* by adding de_rec_len to the current dirent, this essentially causes the +* deleted dirent to get jumped over when iterating through all the dirents. +* +* When deleting the first dirent in a block, there is no previous dirent so +* the field de_ino is set to zero to designate it as deleted. When allocating +* a dirent, gfs2_dirent_alloc iterates through the dirents in a block. If the +* first dirent has (de_ino == 0) and de_rec_len is large enough, this first +* dirent is allocated. Otherwise it must go through all the 'used' dirents +* searching for one in which the amount of total space minus the amount of +* used space will provide enough space for the new dirent. +* +* There are two types of blocks in which dirents reside. In a stuffed dinode, +* the dirents begin at offset sizeof(struct gfs2_dinode) from the beginning of +* the block. In leaves, they begin at offset sizeof(struct gfs2_leaf) from the +* beginning of the leaf block. The dirents reside in leaves when +* +* dip->i_di.di_flags & GFS2_DIF_EXHASH is true +* +* Otherwise, the dirents are "linear", within a single stuffed dinode block. +* +* When the dirents are in leaves, the actual contents of the directory file are +* used as an array of 64-bit block pointers pointing to the leaf blocks. The +* dirents are NOT in the directory file itself. There can be more than one block +* pointer in the array that points to the same leaf. In fact, when a directory +* is first converted from linear to exhash, all of the pointers point to the +* same leaf. +* +* When a leaf is completely full, the size of the hash table can be +* doubled unless it is already at the maximum size which is hard coded into +* GFS2_DIR_MAX_DEPTH. After that, leaves are chained together in a linked list, +* but never before the maximum hash table size has been reached. +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "dir.h" +#include "glock.h" +#include "inode.h" +#include "jdata.h" +#include "meta_io.h" +#include "quota.h" +#include "rgrp.h" +#include "trans.h" + +#define IS_LEAF 1 /* Hashed (leaf) directory */ +#define IS_DINODE 2 /* Linear (stuffed dinode block) directory */ + +#if 1 +#define gfs2_disk_hash2offset(h) (((uint64_t)(h)) >> 1) +#define gfs2_dir_offset2hash(p) ((uint32_t)(((uint64_t)(p)) << 1)) +#else +#define gfs2_disk_hash2offset(h) (((uint64_t)(h))) +#define gfs2_dir_offset2hash(p) ((uint32_t)(((uint64_t)(p)))) +#endif + +typedef int (*leaf_call_t) (struct gfs2_inode *dip, + uint32_t index, uint32_t len, uint64_t leaf_no, + void *data); + +/** + * int gfs2_filecmp - Compare two filenames + * @file1: The first filename + * @file2: The second filename + * @len_of_file2: The length of the second file + * + * This routine compares two filenames and returns 1 if they are equal. + * + * Returns: 1 if the files are the same, otherwise 0. + */ + +int gfs2_filecmp(struct qstr *file1, char *file2, int len_of_file2) +{ + if (file1->len != len_of_file2) + return 0; + if (memcmp(file1->name, file2, file1->len)) + return 0; + return 1; +} + +/** + * dirent_first - Return the first dirent + * @dip: the directory + * @bh: The buffer + * @dent: Pointer to list of dirents + * + * return first dirent whether bh points to leaf or stuffed dinode + * + * Returns: IS_LEAF, IS_DINODE, or -errno + */ + +static int dirent_first(struct gfs2_inode *dip, struct buffer_head *bh, + struct gfs2_dirent **dent) +{ + struct gfs2_meta_header *h = (struct gfs2_meta_header *)bh->b_data; + + if (be16_to_cpu(h->mh_type) == GFS2_METATYPE_LF) { + if (gfs2_meta_check(dip->i_sbd, bh)) + return -EIO; + *dent = (struct gfs2_dirent *)(bh->b_data + + sizeof(struct gfs2_leaf)); + return IS_LEAF; + } else { + if (gfs2_metatype_check(dip->i_sbd, bh, GFS2_METATYPE_DI)) + return -EIO; + *dent = (struct gfs2_dirent *)(bh->b_data + + sizeof(struct gfs2_dinode)); + return IS_DINODE; + } +} + +/** + * dirent_next - Next dirent + * @dip: the directory + * @bh: The buffer + * @dent: Pointer to list of dirents + * + * Returns: 0 on success, error code otherwise + */ + +static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, + struct gfs2_dirent **dent) +{ + struct gfs2_dirent *tmp, *cur; + char *bh_end; + uint32_t cur_rec_len; + + cur = *dent; + bh_end = bh->b_data + bh->b_size; + cur_rec_len = be32_to_cpu(cur->de_rec_len); + + if ((char *)cur + cur_rec_len >= bh_end) { + if ((char *)cur + cur_rec_len > bh_end) { + gfs2_consist_inode(dip); + return -EIO; + } + return -ENOENT; + } + + tmp = (struct gfs2_dirent *)((char *)cur + cur_rec_len); + + if ((char *)tmp + be32_to_cpu(tmp->de_rec_len) > bh_end) { + gfs2_consist_inode(dip); + return -EIO; + } + /* Only the first dent could ever have de_inum.no_addr == 0 */ + if (!tmp->de_inum.no_addr) { + gfs2_consist_inode(dip); + return -EIO; + } + + *dent = tmp; + + return 0; +} + +/** + * dirent_del - Delete a dirent + * @dip: The GFS2 inode + * @bh: The buffer + * @prev: The previous dirent + * @cur: The current dirent + * + */ + +static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh, + struct gfs2_dirent *prev, struct gfs2_dirent *cur) +{ + uint32_t cur_rec_len, prev_rec_len; + + if (!cur->de_inum.no_addr) { + gfs2_consist_inode(dip); + return; + } + + gfs2_trans_add_bh(dip->i_gl, bh); + + /* If there is no prev entry, this is the first entry in the block. + The de_rec_len is already as big as it needs to be. Just zero + out the inode number and return. */ + + if (!prev) { + cur->de_inum.no_addr = 0; /* No endianess worries */ + return; + } + + /* Combine this dentry with the previous one. */ + + prev_rec_len = be32_to_cpu(prev->de_rec_len); + cur_rec_len = be32_to_cpu(cur->de_rec_len); + + if ((char *)prev + prev_rec_len != (char *)cur) + gfs2_consist_inode(dip); + if ((char *)cur + cur_rec_len > bh->b_data + bh->b_size) + gfs2_consist_inode(dip); + + prev_rec_len += cur_rec_len; + prev->de_rec_len = cpu_to_be32(prev_rec_len); +} + +/** + * gfs2_dirent_alloc - Allocate a directory entry + * @dip: The GFS2 inode + * @bh: The buffer + * @name_len: The length of the name + * @dent_out: Pointer to list of dirents + * + * Returns: 0 on success, error code otherwise + */ + +int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, + int name_len, struct gfs2_dirent **dent_out) +{ + struct gfs2_dirent *dent, *new; + unsigned int rec_len = GFS2_DIRENT_SIZE(name_len); + unsigned int entries = 0, offset = 0; + int type; + + type = dirent_first(dip, bh, &dent); + if (type < 0) + return type; + + if (type == IS_LEAF) { + struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data; + entries = be16_to_cpu(leaf->lf_entries); + offset = sizeof(struct gfs2_leaf); + } else { + struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data; + entries = be32_to_cpu(dinode->di_entries); + offset = sizeof(struct gfs2_dinode); + } + + if (!entries) { + if (dent->de_inum.no_addr) { + gfs2_consist_inode(dip); + return -EIO; + } + + gfs2_trans_add_bh(dip->i_gl, bh); + + dent->de_rec_len = bh->b_size - offset; + dent->de_rec_len = cpu_to_be32(dent->de_rec_len); + dent->de_name_len = name_len; + + *dent_out = dent; + return 0; + } + + do { + uint32_t cur_rec_len, cur_name_len; + + cur_rec_len = be32_to_cpu(dent->de_rec_len); + cur_name_len = dent->de_name_len; + + if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || + (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) { + gfs2_trans_add_bh(dip->i_gl, bh); + + if (dent->de_inum.no_addr) { + new = (struct gfs2_dirent *)((char *)dent + + GFS2_DIRENT_SIZE(cur_name_len)); + memset(new, 0, sizeof(struct gfs2_dirent)); + + new->de_rec_len = cur_rec_len - GFS2_DIRENT_SIZE(cur_name_len); + new->de_rec_len = cpu_to_be32(new->de_rec_len); + new->de_name_len = name_len; + + dent->de_rec_len = cur_rec_len - be32_to_cpu(new->de_rec_len); + dent->de_rec_len = cpu_to_be32(dent->de_rec_len); + + *dent_out = new; + return 0; + } + + dent->de_name_len = name_len; + + *dent_out = dent; + return 0; + } + } while (dirent_next(dip, bh, &dent) == 0); + + return -ENOSPC; +} + +/** + * dirent_fits - See if we can fit a entry in this buffer + * @dip: The GFS2 inode + * @bh: The buffer + * @name_len: The length of the name + * + * Returns: 1 if it can fit, 0 otherwise + */ + +static int dirent_fits(struct gfs2_inode *dip, struct buffer_head *bh, + int name_len) +{ + struct gfs2_dirent *dent; + unsigned int rec_len = GFS2_DIRENT_SIZE(name_len); + unsigned int entries = 0; + int type; + + type = dirent_first(dip, bh, &dent); + if (type < 0) + return type; + + if (type == IS_LEAF) { + struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data; + entries = be16_to_cpu(leaf->lf_entries); + } else { + struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data; + entries = be32_to_cpu(dinode->di_entries); + } + + if (!entries) + return 1; + + do { + uint32_t cur_rec_len, cur_name_len; + + cur_rec_len = be32_to_cpu(dent->de_rec_len); + cur_name_len = dent->de_name_len; + + if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || + (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) + return 1; + } while (dirent_next(dip, bh, &dent) == 0); + + return 0; +} + +static int leaf_search(struct gfs2_inode *dip, struct buffer_head *bh, + struct qstr *filename, struct gfs2_dirent **dent_out, + struct gfs2_dirent **dent_prev) +{ + uint32_t hash; + struct gfs2_dirent *dent, *prev = NULL; + unsigned int entries = 0; + int type; + + type = dirent_first(dip, bh, &dent); + if (type < 0) + return type; + + if (type == IS_LEAF) { + struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data; + entries = be16_to_cpu(leaf->lf_entries); + } else if (type == IS_DINODE) { + struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data; + entries = be32_to_cpu(dinode->di_entries); + } + + hash = gfs2_disk_hash(filename->name, filename->len); + + do { + if (!dent->de_inum.no_addr) { + prev = dent; + continue; + } + + if (be32_to_cpu(dent->de_hash) == hash && + gfs2_filecmp(filename, (char *)(dent + 1), + dent->de_name_len)) { + *dent_out = dent; + if (dent_prev) + *dent_prev = prev; + + return 0; + } + + prev = dent; + } while (dirent_next(dip, bh, &dent) == 0); + + return -ENOENT; +} + +static int get_leaf(struct gfs2_inode *dip, uint64_t leaf_no, + struct buffer_head **bhp) +{ + int error; + + error = gfs2_meta_read(dip->i_gl, leaf_no, DIO_START | DIO_WAIT, bhp); + if (!error && gfs2_metatype_check(dip->i_sbd, *bhp, GFS2_METATYPE_LF)) + error = -EIO; + + return error; +} + +/** + * get_leaf_nr - Get a leaf number associated with the index + * @dip: The GFS2 inode + * @index: + * @leaf_out: + * + * Returns: 0 on success, error code otherwise + */ + +static int get_leaf_nr(struct gfs2_inode *dip, uint32_t index, + uint64_t *leaf_out) +{ + uint64_t leaf_no; + int error; + + error = gfs2_jdata_read_mem(dip, (char *)&leaf_no, + index * sizeof(uint64_t), + sizeof(uint64_t)); + if (error != sizeof(uint64_t)) + return (error < 0) ? error : -EIO; + + *leaf_out = be64_to_cpu(leaf_no); + + return 0; +} + +static int get_first_leaf(struct gfs2_inode *dip, uint32_t index, + struct buffer_head **bh_out) +{ + uint64_t leaf_no; + int error; + + error = get_leaf_nr(dip, index, &leaf_no); + if (!error) + error = get_leaf(dip, leaf_no, bh_out); + + return error; +} + +static int get_next_leaf(struct gfs2_inode *dip, struct buffer_head *bh_in, + struct buffer_head **bh_out) +{ + struct gfs2_leaf *leaf; + int error; + + leaf = (struct gfs2_leaf *)bh_in->b_data; + + if (!leaf->lf_next) + error = -ENOENT; + else + error = get_leaf(dip, be64_to_cpu(leaf->lf_next), bh_out); + + return error; +} + +static int linked_leaf_search(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_dirent **dent_out, + struct gfs2_dirent **dent_prev, + struct buffer_head **bh_out) +{ + struct buffer_head *bh = NULL, *bh_next; + uint32_t hsize, index; + uint32_t hash; + int error; + + hsize = 1 << dip->i_di.di_depth; + if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { + gfs2_consist_inode(dip); + return -EIO; + } + + /* Figure out the address of the leaf node. */ + + hash = gfs2_disk_hash(filename->name, filename->len); + index = hash >> (32 - dip->i_di.di_depth); + + error = get_first_leaf(dip, index, &bh_next); + if (error) + return error; + + /* Find the entry */ + + do { + brelse(bh); + + bh = bh_next; + + error = leaf_search(dip, bh, filename, dent_out, dent_prev); + switch (error) { + case 0: + *bh_out = bh; + return 0; + + case -ENOENT: + break; + + default: + brelse(bh); + return error; + } + + error = get_next_leaf(dip, bh, &bh_next); + } + while (!error); + + brelse(bh); + + return error; +} + +/** + * dir_make_exhash - Convert a stuffed directory into an ExHash directory + * @dip: The GFS2 inode + * + * Returns: 0 on success, error code otherwise + */ + +static int dir_make_exhash(struct gfs2_inode *dip) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_dirent *dent; + struct buffer_head *bh, *dibh; + struct gfs2_leaf *leaf; + int y; + uint32_t x; + uint64_t *lp, bn; + int error; + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (error) + return error; + + /* Allocate a new block for the first leaf node */ + + bn = gfs2_alloc_meta(dip); + + /* Turn over a new leaf */ + + bh = gfs2_meta_new(dip->i_gl, bn); + gfs2_trans_add_bh(dip->i_gl, bh); + gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); + gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); + + /* Fill in the leaf structure */ + + leaf = (struct gfs2_leaf *)bh->b_data; + + gfs2_assert(sdp, dip->i_di.di_entries < (1 << 16)); + + leaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE); + leaf->lf_entries = cpu_to_be16(dip->i_di.di_entries); + + /* Copy dirents */ + + gfs2_buffer_copy_tail(bh, sizeof(struct gfs2_leaf), dibh, + sizeof(struct gfs2_dinode)); + + /* Find last entry */ + + x = 0; + dirent_first(dip, bh, &dent); + + do { + if (!dent->de_inum.no_addr) + continue; + if (++x == dip->i_di.di_entries) + break; + } + while (dirent_next(dip, bh, &dent) == 0); + + /* Adjust the last dirent's record length + (Remember that dent still points to the last entry.) */ + + dent->de_rec_len = be32_to_cpu(dent->de_rec_len) + + sizeof(struct gfs2_dinode) - + sizeof(struct gfs2_leaf); + dent->de_rec_len = cpu_to_be32(dent->de_rec_len); + + brelse(bh); + + /* We're done with the new leaf block, now setup the new + hash table. */ + + gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); + + lp = (uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)); + + for (x = sdp->sd_hash_ptrs; x--; lp++) + *lp = cpu_to_be64(bn); + + dip->i_di.di_size = sdp->sd_sb.sb_bsize / 2; + dip->i_di.di_blocks++; + dip->i_di.di_flags |= GFS2_DIF_EXHASH; + dip->i_di.di_payload_format = 0; + + for (x = sdp->sd_hash_ptrs, y = -1; x; x >>= 1, y++) ; + dip->i_di.di_depth = y; + + gfs2_dinode_out(&dip->i_di, dibh->b_data); + + brelse(dibh); + + return 0; +} + +/** + * dir_split_leaf - Split a leaf block into two + * @dip: The GFS2 inode + * @index: + * @leaf_no: + * + * Returns: 0 on success, error code on failure + */ + +static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, + uint64_t leaf_no) +{ + struct buffer_head *nbh, *obh, *dibh; + struct gfs2_leaf *nleaf, *oleaf; + struct gfs2_dirent *dent, *prev = NULL, *next = NULL, *new; + uint32_t start, len, half_len, divider; + uint64_t bn, *lp; + uint32_t name_len; + int x, moved = 0; + int error; + + /* Allocate the new leaf block */ + + bn = gfs2_alloc_meta(dip); + + /* Get the new leaf block */ + + nbh = gfs2_meta_new(dip->i_gl, bn); + gfs2_trans_add_bh(dip->i_gl, nbh); + gfs2_metatype_set(nbh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); + gfs2_buffer_clear_tail(nbh, sizeof(struct gfs2_meta_header)); + + nleaf = (struct gfs2_leaf *)nbh->b_data; + + nleaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE); + + /* Get the old leaf block */ + + error = get_leaf(dip, leaf_no, &obh); + if (error) + goto fail; + + gfs2_trans_add_bh(dip->i_gl, obh); + + oleaf = (struct gfs2_leaf *)obh->b_data; + + /* Compute the start and len of leaf pointers in the hash table. */ + + len = 1 << (dip->i_di.di_depth - be16_to_cpu(oleaf->lf_depth)); + half_len = len >> 1; + if (!half_len) { + gfs2_consist_inode(dip); + error = -EIO; + goto fail_brelse; + } + + start = (index & ~(len - 1)); + + /* Change the pointers. + Don't bother distinguishing stuffed from non-stuffed. + This code is complicated enough already. */ + + lp = kcalloc(half_len, sizeof(uint64_t), GFP_KERNEL | __GFP_NOFAIL); + + error = gfs2_jdata_read_mem(dip, (char *)lp, start * sizeof(uint64_t), + half_len * sizeof(uint64_t)); + if (error != half_len * sizeof(uint64_t)) { + if (error >= 0) + error = -EIO; + goto fail_lpfree; + } + + /* Change the pointers */ + + for (x = 0; x < half_len; x++) + lp[x] = cpu_to_be64(bn); + + error = gfs2_jdata_write_mem(dip, (char *)lp, start * sizeof(uint64_t), + half_len * sizeof(uint64_t)); + if (error != half_len * sizeof(uint64_t)) { + if (error >= 0) + error = -EIO; + goto fail_lpfree; + } + + kfree(lp); + + /* Compute the divider */ + + divider = (start + half_len) << (32 - dip->i_di.di_depth); + + /* Copy the entries */ + + dirent_first(dip, obh, &dent); + + do { + next = dent; + if (dirent_next(dip, obh, &next)) + next = NULL; + + if (dent->de_inum.no_addr && + be32_to_cpu(dent->de_hash) < divider) { + name_len = dent->de_name_len; + + gfs2_dirent_alloc(dip, nbh, name_len, &new); + + new->de_inum = dent->de_inum; /* No endian worries */ + new->de_hash = dent->de_hash; /* No endian worries */ + new->de_type = dent->de_type; /* No endian worries */ + memcpy((char *)(new + 1), (char *)(dent + 1), + name_len); + + nleaf->lf_entries = be16_to_cpu(nleaf->lf_entries)+1; + nleaf->lf_entries = cpu_to_be16(nleaf->lf_entries); + + dirent_del(dip, obh, prev, dent); + + if (!oleaf->lf_entries) + gfs2_consist_inode(dip); + oleaf->lf_entries = be16_to_cpu(oleaf->lf_entries)-1; + oleaf->lf_entries = cpu_to_be16(oleaf->lf_entries); + + if (!prev) + prev = dent; + + moved = 1; + } else + prev = dent; + + dent = next; + } + while (dent); + + /* If none of the entries got moved into the new leaf, + artificially fill in the first entry. */ + + if (!moved) { + gfs2_dirent_alloc(dip, nbh, 0, &new); + new->de_inum.no_addr = 0; + } + + oleaf->lf_depth = be16_to_cpu(oleaf->lf_depth) + 1; + oleaf->lf_depth = cpu_to_be16(oleaf->lf_depth); + nleaf->lf_depth = oleaf->lf_depth; + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (!gfs2_assert_withdraw(dip->i_sbd, !error)) { + dip->i_di.di_blocks++; + gfs2_dinode_out(&dip->i_di, dibh->b_data); + brelse(dibh); + } + + brelse(obh); + brelse(nbh); + + return error; + + fail_lpfree: + kfree(lp); + + fail_brelse: + brelse(obh); + + fail: + brelse(nbh); + return error; +} + +/** + * dir_double_exhash - Double size of ExHash table + * @dip: The GFS2 dinode + * + * Returns: 0 on success, error code on failure + */ + +static int dir_double_exhash(struct gfs2_inode *dip) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct buffer_head *dibh; + uint32_t hsize; + uint64_t *buf; + uint64_t *from, *to; + uint64_t block; + int x; + int error = 0; + + hsize = 1 << dip->i_di.di_depth; + if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { + gfs2_consist_inode(dip); + return -EIO; + } + + /* Allocate both the "from" and "to" buffers in one big chunk */ + + buf = kcalloc(3, sdp->sd_hash_bsize, GFP_KERNEL | __GFP_NOFAIL); + + for (block = dip->i_di.di_size >> sdp->sd_hash_bsize_shift; block--;) { + error = gfs2_jdata_read_mem(dip, (char *)buf, + block * sdp->sd_hash_bsize, + sdp->sd_hash_bsize); + if (error != sdp->sd_hash_bsize) { + if (error >= 0) + error = -EIO; + goto fail; + } + + from = buf; + to = (uint64_t *)((char *)buf + sdp->sd_hash_bsize); + + for (x = sdp->sd_hash_ptrs; x--; from++) { + *to++ = *from; /* No endianess worries */ + *to++ = *from; + } + + error = gfs2_jdata_write_mem(dip, + (char *)buf + sdp->sd_hash_bsize, + block * sdp->sd_sb.sb_bsize, + sdp->sd_sb.sb_bsize); + if (error != sdp->sd_sb.sb_bsize) { + if (error >= 0) + error = -EIO; + goto fail; + } + } + + kfree(buf); + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (!gfs2_assert_withdraw(sdp, !error)) { + dip->i_di.di_depth++; + gfs2_dinode_out(&dip->i_di, dibh->b_data); + brelse(dibh); + } + + return error; + + fail: + kfree(buf); + + return error; +} + +/** + * compare_dents - compare directory entries by hash value + * @a: first dent + * @b: second dent + * + * When comparing the hash entries of @a to @b: + * gt: returns 1 + * lt: returns -1 + * eq: returns 0 + */ + +static int compare_dents(const void *a, const void *b) +{ + struct gfs2_dirent *dent_a, *dent_b; + uint32_t hash_a, hash_b; + int ret = 0; + + dent_a = *(struct gfs2_dirent **)a; + hash_a = dent_a->de_hash; + hash_a = be32_to_cpu(hash_a); + + dent_b = *(struct gfs2_dirent **)b; + hash_b = dent_b->de_hash; + hash_b = be32_to_cpu(hash_b); + + if (hash_a > hash_b) + ret = 1; + else if (hash_a < hash_b) + ret = -1; + else { + unsigned int len_a = dent_a->de_name_len; + unsigned int len_b = dent_b->de_name_len; + + if (len_a > len_b) + ret = 1; + else if (len_a < len_b) + ret = -1; + else + ret = memcmp((char *)(dent_a + 1), + (char *)(dent_b + 1), + len_a); + } + + return ret; +} + +/** + * do_filldir_main - read out directory entries + * @dip: The GFS2 inode + * @offset: The offset in the file to read from + * @opaque: opaque data to pass to filldir + * @filldir: The function to pass entries to + * @darr: an array of struct gfs2_dirent pointers to read + * @entries: the number of entries in darr + * @copied: pointer to int that's non-zero if a entry has been copied out + * + * Jump through some hoops to make sure that if there are hash collsions, + * they are read out at the beginning of a buffer. We want to minimize + * the possibility that they will fall into different readdir buffers or + * that someone will want to seek to that location. + * + * Returns: errno, >0 on exception from filldir + */ + +static int do_filldir_main(struct gfs2_inode *dip, uint64_t *offset, + void *opaque, gfs2_filldir_t filldir, + struct gfs2_dirent **darr, uint32_t entries, + int *copied) +{ + struct gfs2_dirent *dent, *dent_next; + struct gfs2_inum inum; + uint64_t off, off_next; + unsigned int x, y; + int run = 0; + int error = 0; + + sort(darr, entries, sizeof(struct gfs2_dirent *), compare_dents, NULL); + + dent_next = darr[0]; + off_next = be32_to_cpu(dent_next->de_hash); + off_next = gfs2_disk_hash2offset(off_next); + + for (x = 0, y = 1; x < entries; x++, y++) { + dent = dent_next; + off = off_next; + + if (y < entries) { + dent_next = darr[y]; + off_next = be32_to_cpu(dent_next->de_hash); + off_next = gfs2_disk_hash2offset(off_next); + + if (off < *offset) + continue; + *offset = off; + + if (off_next == off) { + if (*copied && !run) + return 1; + run = 1; + } else + run = 0; + } else { + if (off < *offset) + continue; + *offset = off; + } + + gfs2_inum_in(&inum, (char *)&dent->de_inum); + + error = filldir(opaque, (char *)(dent + 1), + dent->de_name_len, + off, &inum, + dent->de_type); + if (error) + return 1; + + *copied = 1; + } + + /* Increment the *offset by one, so the next time we come into the + do_filldir fxn, we get the next entry instead of the last one in the + current leaf */ + + (*offset)++; + + return 0; +} + +/** + * do_filldir_single - Read directory entries out of a single block + * @dip: The GFS2 inode + * @offset: The offset in the file to read from + * @opaque: opaque data to pass to filldir + * @filldir: The function to pass entries to + * @bh: the block + * @entries: the number of entries in the block + * @copied: pointer to int that's non-zero if a entry has been copied out + * + * Returns: errno, >0 on exception from filldir + */ + +static int do_filldir_single(struct gfs2_inode *dip, uint64_t *offset, + void *opaque, gfs2_filldir_t filldir, + struct buffer_head *bh, uint32_t entries, + int *copied) +{ + struct gfs2_dirent **darr; + struct gfs2_dirent *de; + unsigned int e = 0; + int error; + + if (!entries) + return 0; + + darr = kcalloc(entries, sizeof(struct gfs2_dirent *), GFP_KERNEL); + if (!darr) + return -ENOMEM; + + dirent_first(dip, bh, &de); + do { + if (!de->de_inum.no_addr) + continue; + if (e >= entries) { + gfs2_consist_inode(dip); + error = -EIO; + goto out; + } + darr[e++] = de; + } + while (dirent_next(dip, bh, &de) == 0); + + if (e != entries) { + gfs2_consist_inode(dip); + error = -EIO; + goto out; + } + + error = do_filldir_main(dip, offset, opaque, filldir, darr, + entries, copied); + + out: + kfree(darr); + + return error; +} + +/** + * do_filldir_multi - Read directory entries out of a linked leaf list + * @dip: The GFS2 inode + * @offset: The offset in the file to read from + * @opaque: opaque data to pass to filldir + * @filldir: The function to pass entries to + * @bh: the first leaf in the list + * @copied: pointer to int that's non-zero if a entry has been copied out + * + * Returns: errno, >0 on exception from filldir + */ + +static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset, + void *opaque, gfs2_filldir_t filldir, + struct buffer_head *bh, int *copied) +{ + struct buffer_head **larr = NULL; + struct gfs2_dirent **darr; + struct gfs2_leaf *leaf; + struct buffer_head *tmp_bh; + struct gfs2_dirent *de; + unsigned int entries, e = 0; + unsigned int leaves = 0, l = 0; + unsigned int x; + uint64_t ln; + int error = 0; + + /* Count leaves and entries */ + + leaf = (struct gfs2_leaf *)bh->b_data; + entries = be16_to_cpu(leaf->lf_entries); + ln = leaf->lf_next; + + while (ln) { + ln = be64_to_cpu(ln); + + error = get_leaf(dip, ln, &tmp_bh); + if (error) + return error; + + leaf = (struct gfs2_leaf *)tmp_bh->b_data; + if (leaf->lf_entries) { + entries += be16_to_cpu(leaf->lf_entries); + leaves++; + } + ln = leaf->lf_next; + + brelse(tmp_bh); + } + + if (!entries) + return 0; + + if (leaves) { + larr = kcalloc(leaves, sizeof(struct buffer_head *),GFP_KERNEL); + if (!larr) + return -ENOMEM; + } + + darr = kcalloc(entries, sizeof(struct gfs2_dirent *), GFP_KERNEL); + if (!darr) { + kfree(larr); + return -ENOMEM; + } + + leaf = (struct gfs2_leaf *)bh->b_data; + if (leaf->lf_entries) { + dirent_first(dip, bh, &de); + do { + if (!de->de_inum.no_addr) + continue; + if (e >= entries) { + gfs2_consist_inode(dip); + error = -EIO; + goto out; + } + darr[e++] = de; + } + while (dirent_next(dip, bh, &de) == 0); + } + ln = leaf->lf_next; + + while (ln) { + ln = be64_to_cpu(ln); + + error = get_leaf(dip, ln, &tmp_bh); + if (error) + goto out; + + leaf = (struct gfs2_leaf *)tmp_bh->b_data; + if (leaf->lf_entries) { + dirent_first(dip, tmp_bh, &de); + do { + if (!de->de_inum.no_addr) + continue; + if (e >= entries) { + gfs2_consist_inode(dip); + error = -EIO; + goto out; + } + darr[e++] = de; + } + while (dirent_next(dip, tmp_bh, &de) == 0); + + larr[l++] = tmp_bh; + + ln = leaf->lf_next; + } else { + ln = leaf->lf_next; + brelse(tmp_bh); + } + } + + if (gfs2_assert_withdraw(dip->i_sbd, l == leaves)) { + error = -EIO; + goto out; + } + if (e != entries) { + gfs2_consist_inode(dip); + error = -EIO; + goto out; + } + + error = do_filldir_main(dip, offset, opaque, filldir, darr, + entries, copied); + + out: + kfree(darr); + for (x = 0; x < l; x++) + brelse(larr[x]); + kfree(larr); + + return error; +} + +/** + * dir_e_search - Search exhash (leaf) dir for inode matching name + * @dip: The GFS2 inode + * @filename: Filename string + * @inode: If non-NULL, function fills with formal inode # and block address + * @type: If non-NULL, function fills with DT_... dinode type + * + * Returns: + */ + +static int dir_e_search(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int *type) +{ + struct buffer_head *bh; + struct gfs2_dirent *dent; + int error; + + error = linked_leaf_search(dip, filename, &dent, NULL, &bh); + if (error) + return error; + + if (inum) + gfs2_inum_in(inum, (char *)&dent->de_inum); + if (type) + *type = dent->de_type; + + brelse(bh); + + return 0; +} + +static int dir_e_add(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int type) +{ + struct buffer_head *bh, *nbh, *dibh; + struct gfs2_leaf *leaf, *nleaf; + struct gfs2_dirent *dent; + uint32_t hsize, index; + uint32_t hash; + uint64_t leaf_no, bn; + int error; + + restart: + hsize = 1 << dip->i_di.di_depth; + if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { + gfs2_consist_inode(dip); + return -EIO; + } + + /* Figure out the address of the leaf node. */ + + hash = gfs2_disk_hash(filename->name, filename->len); + index = hash >> (32 - dip->i_di.di_depth); + + error = get_leaf_nr(dip, index, &leaf_no); + if (error) + return error; + + /* Add entry to the leaf */ + + for (;;) { + error = get_leaf(dip, leaf_no, &bh); + if (error) + return error; + + leaf = (struct gfs2_leaf *)bh->b_data; + + if (gfs2_dirent_alloc(dip, bh, filename->len, &dent)) { + + if (be16_to_cpu(leaf->lf_depth) < dip->i_di.di_depth) { + /* Can we split the leaf? */ + + brelse(bh); + + error = dir_split_leaf(dip, index, leaf_no); + if (error) + return error; + + goto restart; + + } else if (dip->i_di.di_depth < GFS2_DIR_MAX_DEPTH) { + /* Can we double the hash table? */ + + brelse(bh); + + error = dir_double_exhash(dip); + if (error) + return error; + + goto restart; + + } else if (leaf->lf_next) { + /* Can we try the next leaf in the list? */ + leaf_no = be64_to_cpu(leaf->lf_next); + brelse(bh); + continue; + + } else { + /* Create a new leaf and add it to the list. */ + + bn = gfs2_alloc_meta(dip); + + nbh = gfs2_meta_new(dip->i_gl, bn); + gfs2_trans_add_bh(dip->i_gl, nbh); + gfs2_metatype_set(nbh, + GFS2_METATYPE_LF, + GFS2_FORMAT_LF); + gfs2_buffer_clear_tail(nbh, + sizeof(struct gfs2_meta_header)); + + gfs2_trans_add_bh(dip->i_gl, bh); + leaf->lf_next = cpu_to_be64(bn); + + nleaf = (struct gfs2_leaf *)nbh->b_data; + nleaf->lf_depth = leaf->lf_depth; + nleaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE); + + gfs2_dirent_alloc(dip, nbh, filename->len, + &dent); + + dip->i_di.di_blocks++; + + brelse(bh); + + bh = nbh; + leaf = nleaf; + } + } + + /* If the gfs2_dirent_alloc() succeeded, it pinned the "bh" */ + + gfs2_inum_out(inum, (char *)&dent->de_inum); + dent->de_hash = cpu_to_be32(hash); + dent->de_type = type; + memcpy((char *)(dent + 1), filename->name, filename->len); + + leaf->lf_entries = be16_to_cpu(leaf->lf_entries) + 1; + leaf->lf_entries = cpu_to_be16(leaf->lf_entries); + + brelse(bh); + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (error) + return error; + + dip->i_di.di_entries++; + dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); + + gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_dinode_out(&dip->i_di, dibh->b_data); + brelse(dibh); + + return 0; + } + + return -ENOENT; +} + +static int dir_e_del(struct gfs2_inode *dip, struct qstr *filename) +{ + struct buffer_head *bh, *dibh; + struct gfs2_dirent *dent, *prev; + struct gfs2_leaf *leaf; + unsigned int entries; + int error; + + error = linked_leaf_search(dip, filename, &dent, &prev, &bh); + if (error == -ENOENT) { + gfs2_consist_inode(dip); + return -EIO; + } + if (error) + return error; + + dirent_del(dip, bh, prev, dent); /* Pins bh */ + + leaf = (struct gfs2_leaf *)bh->b_data; + entries = be16_to_cpu(leaf->lf_entries); + if (!entries) + gfs2_consist_inode(dip); + entries--; + leaf->lf_entries = cpu_to_be16(entries); + + brelse(bh); + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (error) + return error; + + if (!dip->i_di.di_entries) + gfs2_consist_inode(dip); + dip->i_di.di_entries--; + dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); + + gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_dinode_out(&dip->i_di, dibh->b_data); + brelse(dibh); + + return 0; +} + +/** + * dir_e_read - Reads the entries from a directory into a filldir buffer + * @dip: dinode pointer + * @offset: the hash of the last entry read shifted to the right once + * @opaque: buffer for the filldir function to fill + * @filldir: points to the filldir function to use + * + * Returns: errno + */ + +static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, + gfs2_filldir_t filldir) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct buffer_head *bh; + struct gfs2_leaf leaf; + uint32_t hsize, len; + uint32_t ht_offset, lp_offset, ht_offset_cur = -1; + uint32_t hash, index; + uint64_t *lp; + int copied = 0; + int error = 0; + + hsize = 1 << dip->i_di.di_depth; + if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { + gfs2_consist_inode(dip); + return -EIO; + } + + hash = gfs2_dir_offset2hash(*offset); + index = hash >> (32 - dip->i_di.di_depth); + + lp = kmalloc(sdp->sd_hash_bsize, GFP_KERNEL); + if (!lp) + return -ENOMEM; + + while (index < hsize) { + lp_offset = index & (sdp->sd_hash_ptrs - 1); + ht_offset = index - lp_offset; + + if (ht_offset_cur != ht_offset) { + error = gfs2_jdata_read_mem(dip, (char *)lp, + ht_offset * sizeof(uint64_t), + sdp->sd_hash_bsize); + if (error != sdp->sd_hash_bsize) { + if (error >= 0) + error = -EIO; + goto out; + } + ht_offset_cur = ht_offset; + } + + error = get_leaf(dip, be64_to_cpu(lp[lp_offset]), &bh); + if (error) + goto out; + + gfs2_leaf_in(&leaf, bh->b_data); + + if (leaf.lf_next) + error = do_filldir_multi(dip, offset, opaque, filldir, + bh, &copied); + else + error = do_filldir_single(dip, offset, opaque, filldir, + bh, leaf.lf_entries, &copied); + + brelse(bh); + + if (error) { + if (error > 0) + error = 0; + goto out; + } + + len = 1 << (dip->i_di.di_depth - leaf.lf_depth); + index = (index & ~(len - 1)) + len; + } + + out: + kfree(lp); + + return error; +} + +static int dir_e_mvino(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int new_type) +{ + struct buffer_head *bh, *dibh; + struct gfs2_dirent *dent; + int error; + + error = linked_leaf_search(dip, filename, &dent, NULL, &bh); + if (error == -ENOENT) { + gfs2_consist_inode(dip); + return -EIO; + } + if (error) + return error; + + gfs2_trans_add_bh(dip->i_gl, bh); + + gfs2_inum_out(inum, (char *)&dent->de_inum); + dent->de_type = new_type; + + brelse(bh); + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (error) + return error; + + dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); + + gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_dinode_out(&dip->i_di, dibh->b_data); + brelse(dibh); + + return 0; +} + +/** + * dir_l_search - Search linear (stuffed dinode) dir for inode matching name + * @dip: The GFS2 inode + * @filename: Filename string + * @inode: If non-NULL, function fills with formal inode # and block address + * @type: If non-NULL, function fills with DT_... dinode type + * + * Returns: + */ + +static int dir_l_search(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int *type) +{ + struct buffer_head *dibh; + struct gfs2_dirent *dent; + int error; + + if (!gfs2_is_stuffed(dip)) { + gfs2_consist_inode(dip); + return -EIO; + } + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (error) + return error; + + error = leaf_search(dip, dibh, filename, &dent, NULL); + if (!error) { + if (inum) + gfs2_inum_in(inum, (char *)&dent->de_inum); + if (type) + *type = dent->de_type; + } + + brelse(dibh); + + return error; +} + +static int dir_l_add(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int type) +{ + struct buffer_head *dibh; + struct gfs2_dirent *dent; + int error; + + if (!gfs2_is_stuffed(dip)) { + gfs2_consist_inode(dip); + return -EIO; + } + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (error) + return error; + + if (gfs2_dirent_alloc(dip, dibh, filename->len, &dent)) { + brelse(dibh); + + error = dir_make_exhash(dip); + if (!error) + error = dir_e_add(dip, filename, inum, type); + + return error; + } + + /* gfs2_dirent_alloc() pins */ + + gfs2_inum_out(inum, (char *)&dent->de_inum); + dent->de_hash = gfs2_disk_hash(filename->name, filename->len); + dent->de_hash = cpu_to_be32(dent->de_hash); + dent->de_type = type; + memcpy((char *)(dent + 1), filename->name, filename->len); + + dip->i_di.di_entries++; + dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); + + gfs2_dinode_out(&dip->i_di, dibh->b_data); + brelse(dibh); + + return 0; +} + +static int dir_l_del(struct gfs2_inode *dip, struct qstr *filename) +{ + struct buffer_head *dibh; + struct gfs2_dirent *dent, *prev; + int error; + + if (!gfs2_is_stuffed(dip)) { + gfs2_consist_inode(dip); + return -EIO; + } + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (error) + return error; + + error = leaf_search(dip, dibh, filename, &dent, &prev); + if (error == -ENOENT) { + gfs2_consist_inode(dip); + error = -EIO; + goto out; + } + if (error) + goto out; + + dirent_del(dip, dibh, prev, dent); + + /* dirent_del() pins */ + + if (!dip->i_di.di_entries) + gfs2_consist_inode(dip); + dip->i_di.di_entries--; + + dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); + + gfs2_dinode_out(&dip->i_di, dibh->b_data); + + out: + brelse(dibh); + + return error; +} + +static int dir_l_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, + gfs2_filldir_t filldir) +{ + struct buffer_head *dibh; + int copied = 0; + int error; + + if (!gfs2_is_stuffed(dip)) { + gfs2_consist_inode(dip); + return -EIO; + } + + if (!dip->i_di.di_entries) + return 0; + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (error) + return error; + + error = do_filldir_single(dip, offset, + opaque, filldir, + dibh, dip->i_di.di_entries, + &copied); + if (error > 0) + error = 0; + + brelse(dibh); + + return error; +} + +static int dir_l_mvino(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int new_type) +{ + struct buffer_head *dibh; + struct gfs2_dirent *dent; + int error; + + if (!gfs2_is_stuffed(dip)) { + gfs2_consist_inode(dip); + return -EIO; + } + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (error) + return error; + + error = leaf_search(dip, dibh, filename, &dent, NULL); + if (error == -ENOENT) { + gfs2_consist_inode(dip); + error = -EIO; + goto out; + } + if (error) + goto out; + + gfs2_trans_add_bh(dip->i_gl, dibh); + + gfs2_inum_out(inum, (char *)&dent->de_inum); + dent->de_type = new_type; + + dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); + + gfs2_dinode_out(&dip->i_di, dibh->b_data); + + out: + brelse(dibh); + + return error; +} + +/** + * gfs2_dir_search - Search a directory + * @dip: The GFS2 inode + * @filename: + * @inode: + * + * This routine searches a directory for a file or another directory. + * Assumes a glock is held on dip. + * + * Returns: errno + */ + +int gfs2_dir_search(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int *type) +{ + int error; + + if (dip->i_di.di_flags & GFS2_DIF_EXHASH) + error = dir_e_search(dip, filename, inum, type); + else + error = dir_l_search(dip, filename, inum, type); + + return error; +} + +/** + * gfs2_dir_add - Add new filename into directory + * @dip: The GFS2 inode + * @filename: The new name + * @inode: The inode number of the entry + * @type: The type of the entry + * + * Returns: 0 on success, error code on failure + */ + +int gfs2_dir_add(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int type) +{ + int error; + + if (dip->i_di.di_flags & GFS2_DIF_EXHASH) + error = dir_e_add(dip, filename, inum, type); + else + error = dir_l_add(dip, filename, inum, type); + + return error; +} + +/** + * gfs2_dir_del - Delete a directory entry + * @dip: The GFS2 inode + * @filename: The filename + * + * Returns: 0 on success, error code on failure + */ + +int gfs2_dir_del(struct gfs2_inode *dip, struct qstr *filename) +{ + int error; + + if (dip->i_di.di_flags & GFS2_DIF_EXHASH) + error = dir_e_del(dip, filename); + else + error = dir_l_del(dip, filename); + + return error; +} + +int gfs2_dir_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, + gfs2_filldir_t filldir) +{ + int error; + + if (dip->i_di.di_flags & GFS2_DIF_EXHASH) + error = dir_e_read(dip, offset, opaque, filldir); + else + error = dir_l_read(dip, offset, opaque, filldir); + + return error; +} + +/** + * gfs2_dir_mvino - Change inode number of directory entry + * @dip: The GFS2 inode + * @filename: + * @new_inode: + * + * This routine changes the inode number of a directory entry. It's used + * by rename to change ".." when a directory is moved. + * Assumes a glock is held on dvp. + * + * Returns: errno + */ + +int gfs2_dir_mvino(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int new_type) +{ + int error; + + if (dip->i_di.di_flags & GFS2_DIF_EXHASH) + error = dir_e_mvino(dip, filename, inum, new_type); + else + error = dir_l_mvino(dip, filename, inum, new_type); + + return error; +} + +/** + * foreach_leaf - call a function for each leaf in a directory + * @dip: the directory + * @lc: the function to call for each each + * @data: private data to pass to it + * + * Returns: errno + */ + +static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct buffer_head *bh; + struct gfs2_leaf leaf; + uint32_t hsize, len; + uint32_t ht_offset, lp_offset, ht_offset_cur = -1; + uint32_t index = 0; + uint64_t *lp; + uint64_t leaf_no; + int error = 0; + + hsize = 1 << dip->i_di.di_depth; + if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { + gfs2_consist_inode(dip); + return -EIO; + } + + lp = kmalloc(sdp->sd_hash_bsize, GFP_KERNEL); + if (!lp) + return -ENOMEM; + + while (index < hsize) { + lp_offset = index & (sdp->sd_hash_ptrs - 1); + ht_offset = index - lp_offset; + + if (ht_offset_cur != ht_offset) { + error = gfs2_jdata_read_mem(dip, (char *)lp, + ht_offset * sizeof(uint64_t), + sdp->sd_hash_bsize); + if (error != sdp->sd_hash_bsize) { + if (error >= 0) + error = -EIO; + goto out; + } + ht_offset_cur = ht_offset; + } + + leaf_no = be64_to_cpu(lp[lp_offset]); + if (leaf_no) { + error = get_leaf(dip, leaf_no, &bh); + if (error) + goto out; + gfs2_leaf_in(&leaf, bh->b_data); + brelse(bh); + + len = 1 << (dip->i_di.di_depth - leaf.lf_depth); + + error = lc(dip, index, len, leaf_no, data); + if (error) + goto out; + + index = (index & ~(len - 1)) + len; + } else + index++; + } + + if (index != hsize) { + gfs2_consist_inode(dip); + error = -EIO; + } + + out: + kfree(lp); + + return error; +} + +/** + * leaf_dealloc - Deallocate a directory leaf + * @dip: the directory + * @index: the hash table offset in the directory + * @len: the number of pointers to this leaf + * @leaf_no: the leaf number + * @data: not used + * + * Returns: errno + */ + +static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, + uint64_t leaf_no, void *data) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_leaf tmp_leaf; + struct gfs2_rgrp_list rlist; + struct buffer_head *bh, *dibh; + uint64_t blk; + unsigned int rg_blocks = 0, l_blocks = 0; + char *ht; + unsigned int x, size = len * sizeof(uint64_t); + int error; + + memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); + + ht = kzalloc(size, GFP_KERNEL); + if (!ht) + return -ENOMEM; + + gfs2_alloc_get(dip); + + error = gfs2_quota_hold(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out; + + error = gfs2_rindex_hold(sdp, &dip->i_alloc.al_ri_gh); + if (error) + goto out_qs; + + /* Count the number of leaves */ + + for (blk = leaf_no; blk; blk = tmp_leaf.lf_next) { + error = get_leaf(dip, blk, &bh); + if (error) + goto out_rlist; + gfs2_leaf_in(&tmp_leaf, (bh)->b_data); + brelse(bh); + + gfs2_rlist_add(sdp, &rlist, blk); + l_blocks++; + } + + gfs2_rlist_alloc(&rlist, LM_ST_EXCLUSIVE, 0); + + for (x = 0; x < rlist.rl_rgrps; x++) { + struct gfs2_rgrpd *rgd; + rgd = get_gl2rgd(rlist.rl_ghs[x].gh_gl); + rg_blocks += rgd->rd_ri.ri_length; + } + + error = gfs2_glock_nq_m(rlist.rl_rgrps, rlist.rl_ghs); + if (error) + goto out_rlist; + + error = gfs2_trans_begin(sdp, + rg_blocks + (DIV_RU(size, sdp->sd_jbsize) + 1) + + RES_DINODE + RES_STATFS + RES_QUOTA, l_blocks); + if (error) + goto out_rg_gunlock; + + for (blk = leaf_no; blk; blk = tmp_leaf.lf_next) { + error = get_leaf(dip, blk, &bh); + if (error) + goto out_end_trans; + gfs2_leaf_in(&tmp_leaf, bh->b_data); + brelse(bh); + + gfs2_free_meta(dip, blk, 1); + + if (!dip->i_di.di_blocks) + gfs2_consist_inode(dip); + dip->i_di.di_blocks--; + } + + error = gfs2_jdata_write_mem(dip, ht, index * sizeof(uint64_t), size); + if (error != size) { + if (error >= 0) + error = -EIO; + goto out_end_trans; + } + + error = gfs2_meta_inode_buffer(dip, &dibh); + if (error) + goto out_end_trans; + + gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_dinode_out(&dip->i_di, dibh->b_data); + brelse(dibh); + + out_end_trans: + gfs2_trans_end(sdp); + + out_rg_gunlock: + gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); + + out_rlist: + gfs2_rlist_free(&rlist); + gfs2_glock_dq_uninit(&dip->i_alloc.al_ri_gh); + + out_qs: + gfs2_quota_unhold(dip); + + out: + gfs2_alloc_put(dip); + kfree(ht); + + return error; +} + +/** + * gfs2_dir_exhash_dealloc - free all the leaf blocks in a directory + * @dip: the directory + * + * Dealloc all on-disk directory leaves to FREEMETA state + * Change on-disk inode type to "regular file" + * + * Returns: errno + */ + +int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct buffer_head *bh; + int error; + + /* Dealloc on-disk leaves to FREEMETA state */ + error = foreach_leaf(dip, leaf_dealloc, NULL); + if (error) + return error; + + /* Make this a regular file in case we crash. + (We don't want to free these blocks a second time.) */ + + error = gfs2_trans_begin(sdp, RES_DINODE, 0); + if (error) + return error; + + error = gfs2_meta_inode_buffer(dip, &bh); + if (!error) { + gfs2_trans_add_bh(dip->i_gl, bh); + ((struct gfs2_dinode *)bh->b_data)->di_mode = cpu_to_be32(S_IFREG); + brelse(bh); + } + + gfs2_trans_end(sdp); + + return error; +} + +/** + * gfs2_diradd_alloc_required - find if adding entry will require an allocation + * @ip: the file being written to + * @filname: the filename that's going to be added + * @alloc_required: set to 1 if an alloc is required, 0 otherwise + * + * Returns: errno + */ + +int gfs2_diradd_alloc_required(struct gfs2_inode *dip, struct qstr *filename, + int *alloc_required) +{ + struct buffer_head *bh = NULL, *bh_next; + uint32_t hsize, hash, index; + int error = 0; + + *alloc_required = 0; + + if (dip->i_di.di_flags & GFS2_DIF_EXHASH) { + hsize = 1 << dip->i_di.di_depth; + if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { + gfs2_consist_inode(dip); + return -EIO; + } + + hash = gfs2_disk_hash(filename->name, filename->len); + index = hash >> (32 - dip->i_di.di_depth); + + error = get_first_leaf(dip, index, &bh_next); + if (error) + return error; + + do { + brelse(bh); + + bh = bh_next; + + if (dirent_fits(dip, bh, filename->len)) + break; + + error = get_next_leaf(dip, bh, &bh_next); + if (error == -ENOENT) { + *alloc_required = 1; + error = 0; + break; + } + } + while (!error); + + brelse(bh); + } else { + error = gfs2_meta_inode_buffer(dip, &bh); + if (error) + return error; + + if (!dirent_fits(dip, bh, filename->len)) + *alloc_required = 1; + + brelse(bh); + } + + return error; +} + +/** + * do_gdm - copy out one leaf (or list of leaves) + * @dip: the directory + * @index: the hash table offset in the directory + * @len: the number of pointers to this leaf + * @leaf_no: the leaf number + * @data: a pointer to a struct gfs2_user_buffer structure + * + * Returns: errno + */ + +static int do_gdm(struct gfs2_inode *dip, uint32_t index, uint32_t len, + uint64_t leaf_no, void *data) +{ + struct gfs2_user_buffer *ub = (struct gfs2_user_buffer *)data; + struct gfs2_leaf leaf; + struct buffer_head *bh; + uint64_t blk; + int error = 0; + + for (blk = leaf_no; blk; blk = leaf.lf_next) { + error = get_leaf(dip, blk, &bh); + if (error) + break; + + gfs2_leaf_in(&leaf, bh->b_data); + + error = gfs2_add_bh_to_ub(ub, bh); + + brelse(bh); + + if (error) + break; + } + + return error; +} + +/** + * gfs2_get_dir_meta - return all the leaf blocks of a directory + * @dip: the directory + * @ub: the structure representing the meta + * + * Returns: errno + */ + +int gfs2_get_dir_meta(struct gfs2_inode *dip, struct gfs2_user_buffer *ub) +{ + return foreach_leaf(dip, do_gdm, ub); +} + diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h new file mode 100644 index 000000000000..79f77aab4264 --- /dev/null +++ b/fs/gfs2/dir.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __DIR_DOT_H__ +#define __DIR_DOT_H__ + +/** + * gfs2_filldir_t - Report a directory entry to the caller of gfs2_dir_read() + * @opaque: opaque data used by the function + * @name: the name of the directory entry + * @length: the length of the name + * @offset: the entry's offset in the directory + * @inum: the inode number the entry points to + * @type: the type of inode the entry points to + * + * Returns: 0 on success, 1 if buffer full + */ + +typedef int (*gfs2_filldir_t) (void *opaque, + const char *name, unsigned int length, + uint64_t offset, + struct gfs2_inum *inum, unsigned int type); + +int gfs2_filecmp(struct qstr *file1, char *file2, int len_of_file2); +int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, + int name_len, struct gfs2_dirent **dent_out); + +int gfs2_dir_search(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int *type); +int gfs2_dir_add(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *inum, unsigned int type); +int gfs2_dir_del(struct gfs2_inode *dip, struct qstr *filename); +int gfs2_dir_read(struct gfs2_inode *dip, uint64_t * offset, void *opaque, + gfs2_filldir_t filldir); +int gfs2_dir_mvino(struct gfs2_inode *dip, struct qstr *filename, + struct gfs2_inum *new_inum, unsigned int new_type); + +int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip); + +int gfs2_diradd_alloc_required(struct gfs2_inode *dip, struct qstr *filename, + int *alloc_required); + +int gfs2_get_dir_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub); + +#endif /* __DIR_DOT_H__ */ diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c new file mode 100644 index 000000000000..2914731250c5 --- /dev/null +++ b/fs/gfs2/eaops.c @@ -0,0 +1,185 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "acl.h" +#include "eaops.h" +#include "eattr.h" + +/** + * gfs2_ea_name2type - get the type of the ea, and truncate type from the name + * @namep: ea name, possibly with type appended + * + * Returns: GFS2_EATYPE_XXX + */ + +unsigned int gfs2_ea_name2type(const char *name, char **truncated_name) +{ + unsigned int type; + + if (strncmp(name, "system.", 7) == 0) { + type = GFS2_EATYPE_SYS; + if (truncated_name) + *truncated_name = strchr(name, '.') + 1; + } else if (strncmp(name, "user.", 5) == 0) { + type = GFS2_EATYPE_USR; + if (truncated_name) + *truncated_name = strchr(name, '.') + 1; + } else { + type = GFS2_EATYPE_UNUSED; + if (truncated_name) + *truncated_name = NULL; + } + + return type; +} + +static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct inode *inode = ip->i_vnode; + int error = permission(inode, MAY_READ, NULL); + if (error) + return error; + + return gfs2_ea_get_i(ip, er); +} + +static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct inode *inode = ip->i_vnode; + + if (S_ISREG(inode->i_mode) || + (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) { + int error = permission(inode, MAY_WRITE, NULL); + if (error) + return error; + } else + return -EPERM; + + return gfs2_ea_set_i(ip, er); +} + +static int user_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct inode *inode = ip->i_vnode; + + if (S_ISREG(inode->i_mode) || + (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) { + int error = permission(inode, MAY_WRITE, NULL); + if (error) + return error; + } else + return -EPERM; + + return gfs2_ea_remove_i(ip, er); +} + +static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) && + !GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len) && + !capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (ip->i_sbd->sd_args.ar_posix_acl == 0 && + (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) || + GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len))) + return -EOPNOTSUPP; + + + + return gfs2_ea_get_i(ip, er); +} + +static int system_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + int remove = 0; + int error; + + if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) { + if (!(er->er_flags & GFS2_ERF_MODE)) { + er->er_mode = ip->i_di.di_mode; + er->er_flags |= GFS2_ERF_MODE; + } + error = gfs2_acl_validate_set(ip, 1, er, + &remove, &er->er_mode); + if (error) + return error; + error = gfs2_ea_set_i(ip, er); + if (error) + return error; + if (remove) + gfs2_ea_remove_i(ip, er); + return 0; + + } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) { + error = gfs2_acl_validate_set(ip, 0, er, + &remove, NULL); + if (error) + return error; + if (!remove) + error = gfs2_ea_set_i(ip, er); + else { + error = gfs2_ea_remove_i(ip, er); + if (error == -ENODATA) + error = 0; + } + return error; + } + + return -EPERM; +} + +static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) { + int error = gfs2_acl_validate_remove(ip, 1); + if (error) + return error; + + } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) { + int error = gfs2_acl_validate_remove(ip, 0); + if (error) + return error; + + } else + return -EPERM; + + return gfs2_ea_remove_i(ip, er); +} + +struct gfs2_eattr_operations gfs2_user_eaops = { + .eo_get = user_eo_get, + .eo_set = user_eo_set, + .eo_remove = user_eo_remove, + .eo_name = "user", +}; + +struct gfs2_eattr_operations gfs2_system_eaops = { + .eo_get = system_eo_get, + .eo_set = system_eo_set, + .eo_remove = system_eo_remove, + .eo_name = "system", +}; + +struct gfs2_eattr_operations *gfs2_ea_ops[] = { + NULL, + &gfs2_user_eaops, + &gfs2_system_eaops, +}; + diff --git a/fs/gfs2/eaops.h b/fs/gfs2/eaops.h new file mode 100644 index 000000000000..f83c497eddca --- /dev/null +++ b/fs/gfs2/eaops.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __EAOPS_DOT_H__ +#define __EAOPS_DOT_H__ + +struct gfs2_ea_request; + +struct gfs2_eattr_operations { + int (*eo_get) (struct gfs2_inode *ip, struct gfs2_ea_request *er); + int (*eo_set) (struct gfs2_inode *ip, struct gfs2_ea_request *er); + int (*eo_remove) (struct gfs2_inode *ip, struct gfs2_ea_request *er); + char *eo_name; +}; + +unsigned int gfs2_ea_name2type(const char *name, char **truncated_name); + +extern struct gfs2_eattr_operations gfs2_user_eaops; +extern struct gfs2_eattr_operations gfs2_system_eaops; + +extern struct gfs2_eattr_operations *gfs2_ea_ops[]; + +#endif /* __EAOPS_DOT_H__ */ + diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c new file mode 100644 index 000000000000..63a5cf1e2472 --- /dev/null +++ b/fs/gfs2/eattr.c @@ -0,0 +1,1620 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "acl.h" +#include "eaops.h" +#include "eattr.h" +#include "glock.h" +#include "inode.h" +#include "meta_io.h" +#include "quota.h" +#include "rgrp.h" +#include "trans.h" + +/** + * ea_calc_size - returns the acutal number of bytes the request will take up + * (not counting any unstuffed data blocks) + * @sdp: + * @er: + * @size: + * + * Returns: 1 if the EA should be stuffed + */ + +static int ea_calc_size(struct gfs2_sbd *sdp, struct gfs2_ea_request *er, + unsigned int *size) +{ + *size = GFS2_EAREQ_SIZE_STUFFED(er); + if (*size <= sdp->sd_jbsize) + return 1; + + *size = GFS2_EAREQ_SIZE_UNSTUFFED(sdp, er); + + return 0; +} + +static int ea_check_size(struct gfs2_sbd *sdp, struct gfs2_ea_request *er) +{ + unsigned int size; + + if (er->er_data_len > GFS2_EA_MAX_DATA_LEN) + return -ERANGE; + + ea_calc_size(sdp, er, &size); + + /* This can only happen with 512 byte blocks */ + if (size > sdp->sd_jbsize) + return -ERANGE; + + return 0; +} + +typedef int (*ea_call_t) (struct gfs2_inode *ip, + struct buffer_head *bh, + struct gfs2_ea_header *ea, + struct gfs2_ea_header *prev, + void *private); + +static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, + ea_call_t ea_call, void *data) +{ + struct gfs2_ea_header *ea, *prev = NULL; + int error = 0; + + if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_EA)) + return -EIO; + + for (ea = GFS2_EA_BH2FIRST(bh);; prev = ea, ea = GFS2_EA2NEXT(ea)) { + if (!GFS2_EA_REC_LEN(ea)) + goto fail; + if (!(bh->b_data <= (char *)ea && + (char *)GFS2_EA2NEXT(ea) <= + bh->b_data + bh->b_size)) + goto fail; + if (!GFS2_EATYPE_VALID(ea->ea_type)) + goto fail; + + error = ea_call(ip, bh, ea, prev, data); + if (error) + return error; + + if (GFS2_EA_IS_LAST(ea)) { + if ((char *)GFS2_EA2NEXT(ea) != + bh->b_data + bh->b_size) + goto fail; + break; + } + } + + return error; + + fail: + gfs2_consist_inode(ip); + return -EIO; +} + +static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) +{ + struct buffer_head *bh, *eabh; + uint64_t *eablk, *end; + int error; + + error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, + DIO_START | DIO_WAIT, &bh); + if (error) + return error; + + if (!(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT)) { + error = ea_foreach_i(ip, bh, ea_call, data); + goto out; + } + + if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_IN)) { + error = -EIO; + goto out; + } + + eablk = (uint64_t *)(bh->b_data + sizeof(struct gfs2_meta_header)); + end = eablk + ip->i_sbd->sd_inptrs; + + for (; eablk < end; eablk++) { + uint64_t bn; + + if (!*eablk) + break; + bn = be64_to_cpu(*eablk); + + error = gfs2_meta_read(ip->i_gl, bn, DIO_START | DIO_WAIT, + &eabh); + if (error) + break; + error = ea_foreach_i(ip, eabh, ea_call, data); + brelse(eabh); + if (error) + break; + } + out: + brelse(bh); + + return error; +} + +struct ea_find { + struct gfs2_ea_request *ef_er; + struct gfs2_ea_location *ef_el; +}; + +static int ea_find_i(struct gfs2_inode *ip, struct buffer_head *bh, + struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, + void *private) +{ + struct ea_find *ef = private; + struct gfs2_ea_request *er = ef->ef_er; + + if (ea->ea_type == GFS2_EATYPE_UNUSED) + return 0; + + if (ea->ea_type == er->er_type) { + if (ea->ea_name_len == er->er_name_len && + !memcmp(GFS2_EA2NAME(ea), er->er_name, ea->ea_name_len)) { + struct gfs2_ea_location *el = ef->ef_el; + get_bh(bh); + el->el_bh = bh; + el->el_ea = ea; + el->el_prev = prev; + return 1; + } + } + +#if 0 + else if ((ip->i_di.di_flags & GFS2_DIF_EA_PACKED) && + er->er_type == GFS2_EATYPE_SYS) + return 1; +#endif + + return 0; +} + +int gfs2_ea_find(struct gfs2_inode *ip, struct gfs2_ea_request *er, + struct gfs2_ea_location *el) +{ + struct ea_find ef; + int error; + + ef.ef_er = er; + ef.ef_el = el; + + memset(el, 0, sizeof(struct gfs2_ea_location)); + + error = ea_foreach(ip, ea_find_i, &ef); + if (error > 0) + return 0; + + return error; +} + +/** + * ea_dealloc_unstuffed - + * @ip: + * @bh: + * @ea: + * @prev: + * @private: + * + * Take advantage of the fact that all unstuffed blocks are + * allocated from the same RG. But watch, this may not always + * be true. + * + * Returns: errno + */ + +static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, + struct gfs2_ea_header *ea, + struct gfs2_ea_header *prev, void *private) +{ + int *leave = private; + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_rgrpd *rgd; + struct gfs2_holder rg_gh; + struct buffer_head *dibh; + uint64_t *dataptrs, bn = 0; + uint64_t bstart = 0; + unsigned int blen = 0; + unsigned int blks = 0; + unsigned int x; + int error; + + if (GFS2_EA_IS_STUFFED(ea)) + return 0; + + dataptrs = GFS2_EA2DATAPTRS(ea); + for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) + if (*dataptrs) { + blks++; + bn = be64_to_cpu(*dataptrs); + } + if (!blks) + return 0; + + rgd = gfs2_blk2rgrpd(sdp, bn); + if (!rgd) { + gfs2_consist_inode(ip); + return -EIO; + } + + error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &rg_gh); + if (error) + return error; + + error = gfs2_trans_begin(sdp, rgd->rd_ri.ri_length + + RES_DINODE + RES_EATTR + RES_STATFS + + RES_QUOTA, blks); + if (error) + goto out_gunlock; + + gfs2_trans_add_bh(ip->i_gl, bh); + + dataptrs = GFS2_EA2DATAPTRS(ea); + for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) { + if (!*dataptrs) + break; + bn = be64_to_cpu(*dataptrs); + + if (bstart + blen == bn) + blen++; + else { + if (bstart) + gfs2_free_meta(ip, bstart, blen); + bstart = bn; + blen = 1; + } + + *dataptrs = 0; + if (!ip->i_di.di_blocks) + gfs2_consist_inode(ip); + ip->i_di.di_blocks--; + } + if (bstart) + gfs2_free_meta(ip, bstart, blen); + + if (prev && !leave) { + uint32_t len; + + len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea); + prev->ea_rec_len = cpu_to_be32(len); + + if (GFS2_EA_IS_LAST(ea)) + prev->ea_flags |= GFS2_EAFLAG_LAST; + } else { + ea->ea_type = GFS2_EATYPE_UNUSED; + ea->ea_num_ptrs = 0; + } + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + ip->i_di.di_ctime = get_seconds(); + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + gfs2_trans_end(sdp); + + out_gunlock: + gfs2_glock_dq_uninit(&rg_gh); + + return error; +} + +static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, + struct gfs2_ea_header *ea, + struct gfs2_ea_header *prev, int leave) +{ + struct gfs2_alloc *al; + int error; + + al = gfs2_alloc_get(ip); + + error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out_alloc; + + error = gfs2_rindex_hold(ip->i_sbd, &al->al_ri_gh); + if (error) + goto out_quota; + + error = ea_dealloc_unstuffed(ip, + bh, ea, prev, + (leave) ? &error : NULL); + + gfs2_glock_dq_uninit(&al->al_ri_gh); + + out_quota: + gfs2_quota_unhold(ip); + + out_alloc: + gfs2_alloc_put(ip); + + return error; +} + +/******************************************************************************/ + +static int gfs2_ea_repack_i(struct gfs2_inode *ip) +{ + return -EOPNOTSUPP; +} + +int gfs2_ea_repack(struct gfs2_inode *ip) +{ + struct gfs2_holder gh; + int error; + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); + if (error) + return error; + + /* Some sort of permissions checking would be nice */ + + error = gfs2_ea_repack_i(ip); + + gfs2_glock_dq_uninit(&gh); + + return error; +} + +struct ea_list { + struct gfs2_ea_request *ei_er; + unsigned int ei_size; +}; + +static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, + struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, + void *private) +{ + struct ea_list *ei = private; + struct gfs2_ea_request *er = ei->ei_er; + unsigned int ea_size = GFS2_EA_STRLEN(ea); + + if (ea->ea_type == GFS2_EATYPE_UNUSED) + return 0; + + if (er->er_data_len) { + char *prefix; + unsigned int l; + char c = 0; + + if (ei->ei_size + ea_size > er->er_data_len) + return -ERANGE; + + if (ea->ea_type == GFS2_EATYPE_USR) { + prefix = "user."; + l = 5; + } else { + prefix = "system."; + l = 7; + } + + memcpy(er->er_data + ei->ei_size, + prefix, l); + memcpy(er->er_data + ei->ei_size + l, + GFS2_EA2NAME(ea), + ea->ea_name_len); + memcpy(er->er_data + ei->ei_size + + ea_size - 1, + &c, 1); + } + + ei->ei_size += ea_size; + + return 0; +} + +/** + * gfs2_ea_list - + * @ip: + * @er: + * + * Returns: actual size of data on success, -errno on error + */ + +int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct gfs2_holder i_gh; + int error; + + if (!er->er_data || !er->er_data_len) { + er->er_data = NULL; + er->er_data_len = 0; + } + + error = gfs2_glock_nq_init(ip->i_gl, + LM_ST_SHARED, LM_FLAG_ANY, + &i_gh); + if (error) + return error; + + if (ip->i_di.di_eattr) { + struct ea_list ei = { .ei_er = er, .ei_size = 0 }; + + error = ea_foreach(ip, ea_list_i, &ei); + if (!error) + error = ei.ei_size; + } + + gfs2_glock_dq_uninit(&i_gh); + + return error; +} + +/** + * ea_get_unstuffed - actually copies the unstuffed data into the + * request buffer + * @ip: + * @ea: + * @data: + * + * Returns: errno + */ + +static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, + char *data) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head **bh; + unsigned int amount = GFS2_EA_DATA_LEN(ea); + unsigned int nptrs = DIV_RU(amount, sdp->sd_jbsize); + uint64_t *dataptrs = GFS2_EA2DATAPTRS(ea); + unsigned int x; + int error = 0; + + bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_KERNEL); + if (!bh) + return -ENOMEM; + + for (x = 0; x < nptrs; x++) { + error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), + DIO_START, bh + x); + if (error) { + while (x--) + brelse(bh[x]); + goto out; + } + dataptrs++; + } + + for (x = 0; x < nptrs; x++) { + error = gfs2_meta_reread(sdp, bh[x], DIO_WAIT); + if (error) { + for (; x < nptrs; x++) + brelse(bh[x]); + goto out; + } + if (gfs2_metatype_check(sdp, bh[x], GFS2_METATYPE_ED)) { + for (; x < nptrs; x++) + brelse(bh[x]); + error = -EIO; + goto out; + } + + memcpy(data, + bh[x]->b_data + sizeof(struct gfs2_meta_header), + (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); + + amount -= sdp->sd_jbsize; + data += sdp->sd_jbsize; + + brelse(bh[x]); + } + + out: + kfree(bh); + + return error; +} + +int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el, + char *data) +{ + if (GFS2_EA_IS_STUFFED(el->el_ea)) { + memcpy(data, + GFS2_EA2DATA(el->el_ea), + GFS2_EA_DATA_LEN(el->el_ea)); + return 0; + } else + return ea_get_unstuffed(ip, el->el_ea, data); +} + +/** + * gfs2_ea_get_i - + * @ip: + * @er: + * + * Returns: actual size of data on success, -errno on error + */ + +int gfs2_ea_get_i(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct gfs2_ea_location el; + int error; + + if (!ip->i_di.di_eattr) + return -ENODATA; + + error = gfs2_ea_find(ip, er, &el); + if (error) + return error; + if (!el.el_ea) + return -ENODATA; + + if (er->er_data_len) { + if (GFS2_EA_DATA_LEN(el.el_ea) > er->er_data_len) + error = -ERANGE; + else + error = gfs2_ea_get_copy(ip, &el, er->er_data); + } + if (!error) + error = GFS2_EA_DATA_LEN(el.el_ea); + + brelse(el.el_bh); + + return error; +} + +/** + * gfs2_ea_get - + * @ip: + * @er: + * + * Returns: actual size of data on success, -errno on error + */ + +int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct gfs2_holder i_gh; + int error; + + if (!er->er_name_len || + er->er_name_len > GFS2_EA_MAX_NAME_LEN) + return -EINVAL; + if (!er->er_data || !er->er_data_len) { + er->er_data = NULL; + er->er_data_len = 0; + } + + error = gfs2_glock_nq_init(ip->i_gl, + LM_ST_SHARED, LM_FLAG_ANY, + &i_gh); + if (error) + return error; + + error = gfs2_ea_ops[er->er_type]->eo_get(ip, er); + + gfs2_glock_dq_uninit(&i_gh); + + return error; +} + +/** + * ea_alloc_blk - allocates a new block for extended attributes. + * @ip: A pointer to the inode that's getting extended attributes + * @bhp: + * + * Returns: errno + */ + +static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_ea_header *ea; + uint64_t block; + + block = gfs2_alloc_meta(ip); + + *bhp = gfs2_meta_new(ip->i_gl, block); + gfs2_trans_add_bh(ip->i_gl, *bhp); + gfs2_metatype_set(*bhp, GFS2_METATYPE_EA, GFS2_FORMAT_EA); + gfs2_buffer_clear_tail(*bhp, sizeof(struct gfs2_meta_header)); + + ea = GFS2_EA_BH2FIRST(*bhp); + ea->ea_rec_len = cpu_to_be32(sdp->sd_jbsize); + ea->ea_type = GFS2_EATYPE_UNUSED; + ea->ea_flags = GFS2_EAFLAG_LAST; + ea->ea_num_ptrs = 0; + + ip->i_di.di_blocks++; + + return 0; +} + +/** + * ea_write - writes the request info to an ea, creating new blocks if + * necessary + * @ip: inode that is being modified + * @ea: the location of the new ea in a block + * @er: the write request + * + * Note: does not update ea_rec_len or the GFS2_EAFLAG_LAST bin of ea_flags + * + * returns : errno + */ + +static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, + struct gfs2_ea_request *er) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + + ea->ea_data_len = cpu_to_be32(er->er_data_len); + ea->ea_name_len = er->er_name_len; + ea->ea_type = er->er_type; + ea->__pad = 0; + + memcpy(GFS2_EA2NAME(ea), er->er_name, er->er_name_len); + + if (GFS2_EAREQ_SIZE_STUFFED(er) <= sdp->sd_jbsize) { + ea->ea_num_ptrs = 0; + memcpy(GFS2_EA2DATA(ea), er->er_data, er->er_data_len); + } else { + uint64_t *dataptr = GFS2_EA2DATAPTRS(ea); + const char *data = er->er_data; + unsigned int data_len = er->er_data_len; + unsigned int copy; + unsigned int x; + + ea->ea_num_ptrs = DIV_RU(er->er_data_len, sdp->sd_jbsize); + for (x = 0; x < ea->ea_num_ptrs; x++) { + struct buffer_head *bh; + uint64_t block; + int mh_size = sizeof(struct gfs2_meta_header); + + block = gfs2_alloc_meta(ip); + + bh = gfs2_meta_new(ip->i_gl, block); + gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_metatype_set(bh, GFS2_METATYPE_ED, GFS2_FORMAT_ED); + + ip->i_di.di_blocks++; + + copy = (data_len > sdp->sd_jbsize) ? sdp->sd_jbsize : + data_len; + memcpy(bh->b_data + mh_size, data, copy); + if (copy < sdp->sd_jbsize) + memset(bh->b_data + mh_size + copy, 0, + sdp->sd_jbsize - copy); + + *dataptr++ = cpu_to_be64((uint64_t)bh->b_blocknr); + data += copy; + data_len -= copy; + + brelse(bh); + } + + gfs2_assert_withdraw(sdp, !data_len); + } + + return 0; +} + +typedef int (*ea_skeleton_call_t) (struct gfs2_inode *ip, + struct gfs2_ea_request *er, + void *private); + +static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, + unsigned int blks, + ea_skeleton_call_t skeleton_call, + void *private) +{ + struct gfs2_alloc *al; + struct buffer_head *dibh; + int error; + + al = gfs2_alloc_get(ip); + + error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out; + + error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid); + if (error) + goto out_gunlock_q; + + al->al_requested = blks; + + error = gfs2_inplace_reserve(ip); + if (error) + goto out_gunlock_q; + + error = gfs2_trans_begin(ip->i_sbd, + blks + al->al_rgd->rd_ri.ri_length + + RES_DINODE + RES_STATFS + RES_QUOTA, 0); + if (error) + goto out_ipres; + + error = skeleton_call(ip, er, private); + if (error) + goto out_end_trans; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + if (er->er_flags & GFS2_ERF_MODE) { + gfs2_assert_withdraw(ip->i_sbd, + (ip->i_di.di_mode & S_IFMT) == + (er->er_mode & S_IFMT)); + ip->i_di.di_mode = er->er_mode; + } + ip->i_di.di_ctime = get_seconds(); + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + out_end_trans: + gfs2_trans_end(ip->i_sbd); + + out_ipres: + gfs2_inplace_release(ip); + + out_gunlock_q: + gfs2_quota_unlock(ip); + + out: + gfs2_alloc_put(ip); + + return error; +} + +static int ea_init_i(struct gfs2_inode *ip, struct gfs2_ea_request *er, + void *private) +{ + struct buffer_head *bh; + int error; + + error = ea_alloc_blk(ip, &bh); + if (error) + return error; + + ip->i_di.di_eattr = bh->b_blocknr; + error = ea_write(ip, GFS2_EA_BH2FIRST(bh), er); + + brelse(bh); + + return error; +} + +/** + * ea_init - initializes a new eattr block + * @ip: + * @er: + * + * Returns: errno + */ + +static int ea_init(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + unsigned int jbsize = ip->i_sbd->sd_jbsize; + unsigned int blks = 1; + + if (GFS2_EAREQ_SIZE_STUFFED(er) > jbsize) + blks += DIV_RU(er->er_data_len, jbsize); + + return ea_alloc_skeleton(ip, er, blks, ea_init_i, NULL); +} + +static struct gfs2_ea_header *ea_split_ea(struct gfs2_ea_header *ea) +{ + uint32_t ea_size = GFS2_EA_SIZE(ea); + struct gfs2_ea_header *new = (struct gfs2_ea_header *)((char *)ea + ea_size); + uint32_t new_size = GFS2_EA_REC_LEN(ea) - ea_size; + int last = ea->ea_flags & GFS2_EAFLAG_LAST; + + ea->ea_rec_len = cpu_to_be32(ea_size); + ea->ea_flags ^= last; + + new->ea_rec_len = cpu_to_be32(new_size); + new->ea_flags = last; + + return new; +} + +static void ea_set_remove_stuffed(struct gfs2_inode *ip, + struct gfs2_ea_location *el) +{ + struct gfs2_ea_header *ea = el->el_ea; + struct gfs2_ea_header *prev = el->el_prev; + uint32_t len; + + gfs2_trans_add_bh(ip->i_gl, el->el_bh); + + if (!prev || !GFS2_EA_IS_STUFFED(ea)) { + ea->ea_type = GFS2_EATYPE_UNUSED; + return; + } else if (GFS2_EA2NEXT(prev) != ea) { + prev = GFS2_EA2NEXT(prev); + gfs2_assert_withdraw(ip->i_sbd, GFS2_EA2NEXT(prev) == ea); + } + + len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea); + prev->ea_rec_len = cpu_to_be32(len); + + if (GFS2_EA_IS_LAST(ea)) + prev->ea_flags |= GFS2_EAFLAG_LAST; +} + +struct ea_set { + int ea_split; + + struct gfs2_ea_request *es_er; + struct gfs2_ea_location *es_el; + + struct buffer_head *es_bh; + struct gfs2_ea_header *es_ea; +}; + +static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh, + struct gfs2_ea_header *ea, struct ea_set *es) +{ + struct gfs2_ea_request *er = es->es_er; + struct buffer_head *dibh; + int error; + + error = gfs2_trans_begin(ip->i_sbd, RES_DINODE + 2 * RES_EATTR, 0); + if (error) + return error; + + gfs2_trans_add_bh(ip->i_gl, bh); + + if (es->ea_split) + ea = ea_split_ea(ea); + + ea_write(ip, ea, er); + + if (es->es_el) + ea_set_remove_stuffed(ip, es->es_el); + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto out; + + if (er->er_flags & GFS2_ERF_MODE) { + gfs2_assert_withdraw(ip->i_sbd, + (ip->i_di.di_mode & S_IFMT) == (er->er_mode & S_IFMT)); + ip->i_di.di_mode = er->er_mode; + } + ip->i_di.di_ctime = get_seconds(); + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + out: + gfs2_trans_end(ip->i_sbd); + + return error; +} + +static int ea_set_simple_alloc(struct gfs2_inode *ip, + struct gfs2_ea_request *er, void *private) +{ + struct ea_set *es = private; + struct gfs2_ea_header *ea = es->es_ea; + int error; + + gfs2_trans_add_bh(ip->i_gl, es->es_bh); + + if (es->ea_split) + ea = ea_split_ea(ea); + + error = ea_write(ip, ea, er); + if (error) + return error; + + if (es->es_el) + ea_set_remove_stuffed(ip, es->es_el); + + return 0; +} + +static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh, + struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, + void *private) +{ + struct ea_set *es = private; + unsigned int size; + int stuffed; + int error; + + stuffed = ea_calc_size(ip->i_sbd, es->es_er, &size); + + if (ea->ea_type == GFS2_EATYPE_UNUSED) { + if (GFS2_EA_REC_LEN(ea) < size) + return 0; + if (!GFS2_EA_IS_STUFFED(ea)) { + error = ea_remove_unstuffed(ip, bh, ea, prev, 1); + if (error) + return error; + } + es->ea_split = 0; + } else if (GFS2_EA_REC_LEN(ea) - GFS2_EA_SIZE(ea) >= size) + es->ea_split = 1; + else + return 0; + + if (stuffed) { + error = ea_set_simple_noalloc(ip, bh, ea, es); + if (error) + return error; + } else { + unsigned int blks; + + es->es_bh = bh; + es->es_ea = ea; + blks = 2 + DIV_RU(es->es_er->er_data_len, ip->i_sbd->sd_jbsize); + + error = ea_alloc_skeleton(ip, es->es_er, blks, + ea_set_simple_alloc, es); + if (error) + return error; + } + + return 1; +} + +static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, + void *private) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head *indbh, *newbh; + uint64_t *eablk; + int error; + int mh_size = sizeof(struct gfs2_meta_header); + + if (ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT) { + uint64_t *end; + + error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, + DIO_START | DIO_WAIT, &indbh); + if (error) + return error; + + if (gfs2_metatype_check(sdp, indbh, GFS2_METATYPE_IN)) { + error = -EIO; + goto out; + } + + eablk = (uint64_t *)(indbh->b_data + mh_size); + end = eablk + sdp->sd_inptrs; + + for (; eablk < end; eablk++) + if (!*eablk) + break; + + if (eablk == end) { + error = -ENOSPC; + goto out; + } + + gfs2_trans_add_bh(ip->i_gl, indbh); + } else { + uint64_t blk; + + blk = gfs2_alloc_meta(ip); + + indbh = gfs2_meta_new(ip->i_gl, blk); + gfs2_trans_add_bh(ip->i_gl, indbh); + gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); + gfs2_buffer_clear_tail(indbh, mh_size); + + eablk = (uint64_t *)(indbh->b_data + mh_size); + *eablk = cpu_to_be64(ip->i_di.di_eattr); + ip->i_di.di_eattr = blk; + ip->i_di.di_flags |= GFS2_DIF_EA_INDIRECT; + ip->i_di.di_blocks++; + + eablk++; + } + + error = ea_alloc_blk(ip, &newbh); + if (error) + goto out; + + *eablk = cpu_to_be64((uint64_t)newbh->b_blocknr); + error = ea_write(ip, GFS2_EA_BH2FIRST(newbh), er); + brelse(newbh); + if (error) + goto out; + + if (private) + ea_set_remove_stuffed(ip, (struct gfs2_ea_location *)private); + + out: + brelse(indbh); + + return error; +} + +static int ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er, + struct gfs2_ea_location *el) +{ + struct ea_set es; + unsigned int blks = 2; + int error; + + memset(&es, 0, sizeof(struct ea_set)); + es.es_er = er; + es.es_el = el; + + error = ea_foreach(ip, ea_set_simple, &es); + if (error > 0) + return 0; + if (error) + return error; + + if (!(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT)) + blks++; + if (GFS2_EAREQ_SIZE_STUFFED(er) > ip->i_sbd->sd_jbsize) + blks += DIV_RU(er->er_data_len, ip->i_sbd->sd_jbsize); + + return ea_alloc_skeleton(ip, er, blks, ea_set_block, el); +} + +static int ea_set_remove_unstuffed(struct gfs2_inode *ip, + struct gfs2_ea_location *el) +{ + if (el->el_prev && GFS2_EA2NEXT(el->el_prev) != el->el_ea) { + el->el_prev = GFS2_EA2NEXT(el->el_prev); + gfs2_assert_withdraw(ip->i_sbd, + GFS2_EA2NEXT(el->el_prev) == el->el_ea); + } + + return ea_remove_unstuffed(ip, el->el_bh, el->el_ea, el->el_prev,0); +} + +int gfs2_ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct gfs2_ea_location el; + int error; + + if (!ip->i_di.di_eattr) { + if (er->er_flags & XATTR_REPLACE) + return -ENODATA; + return ea_init(ip, er); + } + + error = gfs2_ea_find(ip, er, &el); + if (error) + return error; + + if (el.el_ea) { + if (ip->i_di.di_flags & GFS2_DIF_APPENDONLY) { + brelse(el.el_bh); + return -EPERM; + } + + error = -EEXIST; + if (!(er->er_flags & XATTR_CREATE)) { + int unstuffed = !GFS2_EA_IS_STUFFED(el.el_ea); + error = ea_set_i(ip, er, &el); + if (!error && unstuffed) + ea_set_remove_unstuffed(ip, &el); + } + + brelse(el.el_bh); + } else { + error = -ENODATA; + if (!(er->er_flags & XATTR_REPLACE)) + error = ea_set_i(ip, er, NULL); + } + + return error; +} + +int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct gfs2_holder i_gh; + int error; + + if (!er->er_name_len || + er->er_name_len > GFS2_EA_MAX_NAME_LEN) + return -EINVAL; + if (!er->er_data || !er->er_data_len) { + er->er_data = NULL; + er->er_data_len = 0; + } + error = ea_check_size(ip->i_sbd, er); + if (error) + return error; + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); + if (error) + return error; + + if (IS_IMMUTABLE(ip->i_vnode)) + error = -EPERM; + else + error = gfs2_ea_ops[er->er_type]->eo_set(ip, er); + + gfs2_glock_dq_uninit(&i_gh); + + return error; +} + +static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el) +{ + struct gfs2_ea_header *ea = el->el_ea; + struct gfs2_ea_header *prev = el->el_prev; + struct buffer_head *dibh; + int error; + + error = gfs2_trans_begin(ip->i_sbd, RES_DINODE + RES_EATTR, 0); + if (error) + return error; + + gfs2_trans_add_bh(ip->i_gl, el->el_bh); + + if (prev) { + uint32_t len; + + len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea); + prev->ea_rec_len = cpu_to_be32(len); + + if (GFS2_EA_IS_LAST(ea)) + prev->ea_flags |= GFS2_EAFLAG_LAST; + } else + ea->ea_type = GFS2_EATYPE_UNUSED; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + ip->i_di.di_ctime = get_seconds(); + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + gfs2_trans_end(ip->i_sbd); + + return error; +} + +int gfs2_ea_remove_i(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct gfs2_ea_location el; + int error; + + if (!ip->i_di.di_eattr) + return -ENODATA; + + error = gfs2_ea_find(ip, er, &el); + if (error) + return error; + if (!el.el_ea) + return -ENODATA; + + if (GFS2_EA_IS_STUFFED(el.el_ea)) + error = ea_remove_stuffed(ip, &el); + else + error = ea_remove_unstuffed(ip, el.el_bh, el.el_ea, el.el_prev, + 0); + + brelse(el.el_bh); + + return error; +} + +/** + * gfs2_ea_remove - sets (or creates or replaces) an extended attribute + * @ip: pointer to the inode of the target file + * @er: request information + * + * Returns: errno + */ + +int gfs2_ea_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct gfs2_holder i_gh; + int error; + + if (!er->er_name_len || er->er_name_len > GFS2_EA_MAX_NAME_LEN) + return -EINVAL; + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); + if (error) + return error; + + if (IS_IMMUTABLE(ip->i_vnode) || IS_APPEND(ip->i_vnode)) + error = -EPERM; + else + error = gfs2_ea_ops[er->er_type]->eo_remove(ip, er); + + gfs2_glock_dq_uninit(&i_gh); + + return error; +} + +static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, + struct gfs2_ea_header *ea, char *data) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head **bh; + unsigned int amount = GFS2_EA_DATA_LEN(ea); + unsigned int nptrs = DIV_RU(amount, sdp->sd_jbsize); + uint64_t *dataptrs = GFS2_EA2DATAPTRS(ea); + unsigned int x; + int error; + + bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_KERNEL); + if (!bh) + return -ENOMEM; + + error = gfs2_trans_begin(sdp, nptrs + RES_DINODE, 0); + if (error) + goto out; + + for (x = 0; x < nptrs; x++) { + error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), + DIO_START, bh + x); + if (error) { + while (x--) + brelse(bh[x]); + goto fail; + } + dataptrs++; + } + + for (x = 0; x < nptrs; x++) { + error = gfs2_meta_reread(sdp, bh[x], DIO_WAIT); + if (error) { + for (; x < nptrs; x++) + brelse(bh[x]); + goto fail; + } + if (gfs2_metatype_check(sdp, bh[x], GFS2_METATYPE_ED)) { + for (; x < nptrs; x++) + brelse(bh[x]); + error = -EIO; + goto fail; + } + + gfs2_trans_add_bh(ip->i_gl, bh[x]); + + memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), + data, + (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); + + amount -= sdp->sd_jbsize; + data += sdp->sd_jbsize; + + brelse(bh[x]); + } + + out: + kfree(bh); + + return error; + + fail: + gfs2_trans_end(sdp); + kfree(bh); + + return error; +} + +int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el, + struct iattr *attr, char *data) +{ + struct buffer_head *dibh; + int error; + + if (GFS2_EA_IS_STUFFED(el->el_ea)) { + error = gfs2_trans_begin(ip->i_sbd, RES_DINODE + RES_EATTR, 0); + if (error) + return error; + + gfs2_trans_add_bh(ip->i_gl, el->el_bh); + memcpy(GFS2_EA2DATA(el->el_ea), + data, + GFS2_EA_DATA_LEN(el->el_ea)); + } else + error = ea_acl_chmod_unstuffed(ip, el->el_ea, data); + + if (error) + return error; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + error = inode_setattr(ip->i_vnode, attr); + gfs2_assert_warn(ip->i_sbd, !error); + gfs2_inode_attr_out(ip); + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + gfs2_trans_end(ip->i_sbd); + + return error; +} + +static int ea_dealloc_indirect(struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_rgrp_list rlist; + struct buffer_head *indbh, *dibh; + uint64_t *eablk, *end; + unsigned int rg_blocks = 0; + uint64_t bstart = 0; + unsigned int blen = 0; + unsigned int blks = 0; + unsigned int x; + int error; + + memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); + + error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, + DIO_START | DIO_WAIT, &indbh); + if (error) + return error; + + if (gfs2_metatype_check(sdp, indbh, GFS2_METATYPE_IN)) { + error = -EIO; + goto out; + } + + eablk = (uint64_t *)(indbh->b_data + sizeof(struct gfs2_meta_header)); + end = eablk + sdp->sd_inptrs; + + for (; eablk < end; eablk++) { + uint64_t bn; + + if (!*eablk) + break; + bn = be64_to_cpu(*eablk); + + if (bstart + blen == bn) + blen++; + else { + if (bstart) + gfs2_rlist_add(sdp, &rlist, bstart); + bstart = bn; + blen = 1; + } + blks++; + } + if (bstart) + gfs2_rlist_add(sdp, &rlist, bstart); + else + goto out; + + gfs2_rlist_alloc(&rlist, LM_ST_EXCLUSIVE, 0); + + for (x = 0; x < rlist.rl_rgrps; x++) { + struct gfs2_rgrpd *rgd; + rgd = get_gl2rgd(rlist.rl_ghs[x].gh_gl); + rg_blocks += rgd->rd_ri.ri_length; + } + + error = gfs2_glock_nq_m(rlist.rl_rgrps, rlist.rl_ghs); + if (error) + goto out_rlist_free; + + error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + + RES_INDIRECT + RES_STATFS + + RES_QUOTA, blks); + if (error) + goto out_gunlock; + + gfs2_trans_add_bh(ip->i_gl, indbh); + + eablk = (uint64_t *)(indbh->b_data + sizeof(struct gfs2_meta_header)); + bstart = 0; + blen = 0; + + for (; eablk < end; eablk++) { + uint64_t bn; + + if (!*eablk) + break; + bn = be64_to_cpu(*eablk); + + if (bstart + blen == bn) + blen++; + else { + if (bstart) + gfs2_free_meta(ip, bstart, blen); + bstart = bn; + blen = 1; + } + + *eablk = 0; + if (!ip->i_di.di_blocks) + gfs2_consist_inode(ip); + ip->i_di.di_blocks--; + } + if (bstart) + gfs2_free_meta(ip, bstart, blen); + + ip->i_di.di_flags &= ~GFS2_DIF_EA_INDIRECT; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + gfs2_trans_end(sdp); + + out_gunlock: + gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); + + out_rlist_free: + gfs2_rlist_free(&rlist); + + out: + brelse(indbh); + + return error; +} + +static int ea_dealloc_block(struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = &ip->i_alloc; + struct gfs2_rgrpd *rgd; + struct buffer_head *dibh; + int error; + + rgd = gfs2_blk2rgrpd(sdp, ip->i_di.di_eattr); + if (!rgd) { + gfs2_consist_inode(ip); + return -EIO; + } + + error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, + &al->al_rgd_gh); + if (error) + return error; + + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_DINODE + + RES_STATFS + RES_QUOTA, 1); + if (error) + goto out_gunlock; + + gfs2_free_meta(ip, ip->i_di.di_eattr, 1); + + ip->i_di.di_eattr = 0; + if (!ip->i_di.di_blocks) + gfs2_consist_inode(ip); + ip->i_di.di_blocks--; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + gfs2_trans_end(sdp); + + out_gunlock: + gfs2_glock_dq_uninit(&al->al_rgd_gh); + + return error; +} + +/** + * gfs2_ea_dealloc - deallocate the extended attribute fork + * @ip: the inode + * + * Returns: errno + */ + +int gfs2_ea_dealloc(struct gfs2_inode *ip) +{ + struct gfs2_alloc *al; + int error; + + al = gfs2_alloc_get(ip); + + error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out_alloc; + + error = gfs2_rindex_hold(ip->i_sbd, &al->al_ri_gh); + if (error) + goto out_quota; + + error = ea_foreach(ip, ea_dealloc_unstuffed, NULL); + if (error) + goto out_rindex; + + if (ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT) { + error = ea_dealloc_indirect(ip); + if (error) + goto out_rindex; + } + + error = ea_dealloc_block(ip); + + out_rindex: + gfs2_glock_dq_uninit(&al->al_ri_gh); + + out_quota: + gfs2_quota_unhold(ip); + + out_alloc: + gfs2_alloc_put(ip); + + return error; +} + +/** + * gfs2_get_eattr_meta - return all the eattr blocks of a file + * @dip: the directory + * @ub: the structure representing the user buffer to copy to + * + * Returns: errno + */ + +int gfs2_get_eattr_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub) +{ + struct buffer_head *bh; + int error; + + error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, + DIO_START | DIO_WAIT, &bh); + if (error) + return error; + + gfs2_add_bh_to_ub(ub, bh); + + if (ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT) { + struct buffer_head *eabh; + uint64_t *eablk, *end; + + if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_IN)) { + error = -EIO; + goto out; + } + + eablk = (uint64_t *)(bh->b_data + + sizeof(struct gfs2_meta_header)); + end = eablk + ip->i_sbd->sd_inptrs; + + for (; eablk < end; eablk++) { + uint64_t bn; + + if (!*eablk) + break; + bn = be64_to_cpu(*eablk); + + error = gfs2_meta_read(ip->i_gl, bn, + DIO_START | DIO_WAIT, &eabh); + if (error) + break; + gfs2_add_bh_to_ub(ub, eabh); + brelse(eabh); + if (error) + break; + } + } + + out: + brelse(bh); + + return error; +} + diff --git a/fs/gfs2/eattr.h b/fs/gfs2/eattr.h new file mode 100644 index 000000000000..a64039295759 --- /dev/null +++ b/fs/gfs2/eattr.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __EATTR_DOT_H__ +#define __EATTR_DOT_H__ + +#define GFS2_EA_REC_LEN(ea) be32_to_cpu((ea)->ea_rec_len) +#define GFS2_EA_DATA_LEN(ea) be32_to_cpu((ea)->ea_data_len) + +#define GFS2_EA_SIZE(ea) \ +ALIGN(sizeof(struct gfs2_ea_header) + (ea)->ea_name_len + \ + ((GFS2_EA_IS_STUFFED(ea)) ? GFS2_EA_DATA_LEN(ea) : \ + (sizeof(uint64_t) * (ea)->ea_num_ptrs)), 8) + +#define GFS2_EA_STRLEN(ea) \ +((((ea)->ea_type == GFS2_EATYPE_USR) ? 5 : 7) + (ea)->ea_name_len + 1) + +#define GFS2_EA_IS_STUFFED(ea) (!(ea)->ea_num_ptrs) +#define GFS2_EA_IS_LAST(ea) ((ea)->ea_flags & GFS2_EAFLAG_LAST) + +#define GFS2_EAREQ_SIZE_STUFFED(er) \ +ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + (er)->er_data_len, 8) + +#define GFS2_EAREQ_SIZE_UNSTUFFED(sdp, er) \ +ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + \ + sizeof(uint64_t) * DIV_RU((er)->er_data_len, (sdp)->sd_jbsize), 8) + +#define GFS2_EA2NAME(ea) ((char *)((struct gfs2_ea_header *)(ea) + 1)) +#define GFS2_EA2DATA(ea) (GFS2_EA2NAME(ea) + (ea)->ea_name_len) + +#define GFS2_EA2DATAPTRS(ea) \ +((uint64_t *)(GFS2_EA2NAME(ea) + ALIGN((ea)->ea_name_len, 8))) + +#define GFS2_EA2NEXT(ea) \ +((struct gfs2_ea_header *)((char *)(ea) + GFS2_EA_REC_LEN(ea))) + +#define GFS2_EA_BH2FIRST(bh) \ +((struct gfs2_ea_header *)((bh)->b_data + sizeof(struct gfs2_meta_header))) + +#define GFS2_ERF_MODE 0x80000000 + +struct gfs2_ea_request { + char *er_name; + char *er_data; + unsigned int er_name_len; + unsigned int er_data_len; + unsigned int er_type; /* GFS2_EATYPE_... */ + int er_flags; + mode_t er_mode; +}; + +struct gfs2_ea_location { + struct buffer_head *el_bh; + struct gfs2_ea_header *el_ea; + struct gfs2_ea_header *el_prev; +}; + +int gfs2_ea_repack(struct gfs2_inode *ip); + +int gfs2_ea_get_i(struct gfs2_inode *ip, struct gfs2_ea_request *er); +int gfs2_ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er); +int gfs2_ea_remove_i(struct gfs2_inode *ip, struct gfs2_ea_request *er); + +int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er); +int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er); +int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er); +int gfs2_ea_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er); + +int gfs2_ea_dealloc(struct gfs2_inode *ip); + +int gfs2_get_eattr_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub); + +/* Exported to acl.c */ + +int gfs2_ea_find(struct gfs2_inode *ip, + struct gfs2_ea_request *er, + struct gfs2_ea_location *el); +int gfs2_ea_get_copy(struct gfs2_inode *ip, + struct gfs2_ea_location *el, + char *data); +int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el, + struct iattr *attr, char *data); + +#endif /* __EATTR_DOT_H__ */ diff --git a/fs/gfs2/format.h b/fs/gfs2/format.h new file mode 100644 index 000000000000..c7bf32ce3eca --- /dev/null +++ b/fs/gfs2/format.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __FORMAT_DOT_H__ +#define __FORMAT_DOT_H__ + +static const uint32_t gfs2_old_fs_formats[] = { + 0 +}; + +static const uint32_t gfs2_old_multihost_formats[] = { + 0 +}; + +#endif /* __FORMAT_DOT_H__ */ diff --git a/fs/gfs2/gfs2.h b/fs/gfs2/gfs2.h new file mode 100644 index 000000000000..a5d118238466 --- /dev/null +++ b/fs/gfs2/gfs2.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __GFS2_DOT_H__ +#define __GFS2_DOT_H__ + +#include + +#include "lm_interface.h" +#include "lvb.h" +#include "incore.h" +#include "util.h" + +enum { + NO_CREATE = 0, + CREATE = 1, +}; + +enum { + NO_WAIT = 0, + WAIT = 1, +}; + +enum { + NO_FORCE = 0, + FORCE = 1, +}; + +/* Divide num by den. Round up if there is a remainder. */ +#define DIV_RU(num, den) (((num) + (den) - 1) / (den)) + +#define GFS2_FAST_NAME_SIZE 8 + +#define get_v2sdp(sb) ((struct gfs2_sbd *)(sb)->s_fs_info) +#define set_v2sdp(sb, sdp) (sb)->s_fs_info = (sdp) +#define get_v2ip(inode) ((struct gfs2_inode *)(inode)->u.generic_ip) +#define set_v2ip(inode, ip) (inode)->u.generic_ip = (ip) +#define get_v2fp(file) ((struct gfs2_file *)(file)->private_data) +#define set_v2fp(file, fp) (file)->private_data = (fp) +#define get_v2bd(bh) ((struct gfs2_bufdata *)(bh)->b_private) +#define set_v2bd(bh, bd) (bh)->b_private = (bd) +#define get_v2db(bh) ((struct gfs2_databuf *)(bh)->b_private) +#define set_v2db(bh, db) (bh)->b_private = (db) + +#define get_transaction ((struct gfs2_trans *)(current->journal_info)) +#define set_transaction(tr) (current->journal_info) = (tr) + +#define get_gl2ip(gl) ((struct gfs2_inode *)(gl)->gl_object) +#define set_gl2ip(gl, ip) (gl)->gl_object = (ip) +#define get_gl2rgd(gl) ((struct gfs2_rgrpd *)(gl)->gl_object) +#define set_gl2rgd(gl, rgd) (gl)->gl_object = (rgd) +#define get_gl2gl(gl) ((struct gfs2_glock *)(gl)->gl_object) +#define set_gl2gl(gl, gl2) (gl)->gl_object = (gl2) + +#endif /* __GFS2_DOT_H__ */ + diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c new file mode 100644 index 000000000000..321945fde12d --- /dev/null +++ b/fs/gfs2/glock.c @@ -0,0 +1,2513 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "glock.h" +#include "glops.h" +#include "inode.h" +#include "lm.h" +#include "lops.h" +#include "meta_io.h" +#include "quota.h" +#include "super.h" + +/* Must be kept in sync with the beginning of struct gfs2_glock */ +struct glock_plug { + struct list_head gl_list; + unsigned long gl_flags; +}; + +struct greedy { + struct gfs2_holder gr_gh; + struct work_struct gr_work; +}; + +typedef void (*glock_examiner) (struct gfs2_glock * gl); + +/** + * relaxed_state_ok - is a requested lock compatible with the current lock mode? + * @actual: the current state of the lock + * @requested: the lock state that was requested by the caller + * @flags: the modifier flags passed in by the caller + * + * Returns: 1 if the locks are compatible, 0 otherwise + */ + +static inline int relaxed_state_ok(unsigned int actual, unsigned requested, + int flags) +{ + if (actual == requested) + return 1; + + if (flags & GL_EXACT) + return 0; + + if (actual == LM_ST_EXCLUSIVE && requested == LM_ST_SHARED) + return 1; + + if (actual != LM_ST_UNLOCKED && (flags & LM_FLAG_ANY)) + return 1; + + return 0; +} + +/** + * gl_hash() - Turn glock number into hash bucket number + * @lock: The glock number + * + * Returns: The number of the corresponding hash bucket + */ + +static unsigned int gl_hash(struct lm_lockname *name) +{ + unsigned int h; + + h = jhash(&name->ln_number, sizeof(uint64_t), 0); + h = jhash(&name->ln_type, sizeof(unsigned int), h); + h &= GFS2_GL_HASH_MASK; + + return h; +} + +/** + * glock_free() - Perform a few checks and then release struct gfs2_glock + * @gl: The glock to release + * + * Also calls lock module to release its internal structure for this glock. + * + */ + +static void glock_free(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct inode *aspace = gl->gl_aspace; + + gfs2_lm_put_lock(sdp, gl->gl_lock); + + if (aspace) + gfs2_aspace_put(aspace); + + kmem_cache_free(gfs2_glock_cachep, gl); + + atomic_dec(&sdp->sd_glock_count); +} + +/** + * gfs2_glock_hold() - increment reference count on glock + * @gl: The glock to hold + * + */ + +void gfs2_glock_hold(struct gfs2_glock *gl) +{ + kref_get(&gl->gl_ref); +} + +/* All work is done after the return from kref_put() so we + can release the write_lock before the free. */ + +static void kill_glock(struct kref *kref) +{ + struct gfs2_glock *gl = container_of(kref, struct gfs2_glock, gl_ref); + struct gfs2_sbd *sdp = gl->gl_sbd; + + gfs2_assert(sdp, gl->gl_state == LM_ST_UNLOCKED); + gfs2_assert(sdp, list_empty(&gl->gl_reclaim)); + gfs2_assert(sdp, list_empty(&gl->gl_holders)); + gfs2_assert(sdp, list_empty(&gl->gl_waiters1)); + gfs2_assert(sdp, list_empty(&gl->gl_waiters2)); + gfs2_assert(sdp, list_empty(&gl->gl_waiters3)); +} + +/** + * gfs2_glock_put() - Decrement reference count on glock + * @gl: The glock to put + * + */ + +int gfs2_glock_put(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_gl_hash_bucket *bucket = gl->gl_bucket; + int rv = 0; + + down(&sdp->sd_invalidate_inodes_mutex); + + write_lock(&bucket->hb_lock); + if (kref_put(&gl->gl_ref, kill_glock)) { + list_del_init(&gl->gl_list); + write_unlock(&bucket->hb_lock); + glock_free(gl); + rv = 1; + goto out; + } + write_unlock(&bucket->hb_lock); + out: + up(&sdp->sd_invalidate_inodes_mutex); + return rv; +} + +/** + * queue_empty - check to see if a glock's queue is empty + * @gl: the glock + * @head: the head of the queue to check + * + * This function protects the list in the event that a process already + * has a holder on the list and is adding a second holder for itself. + * The glmutex lock is what generally prevents processes from working + * on the same glock at once, but the special case of adding a second + * holder for yourself ("recursive" locking) doesn't involve locking + * glmutex, making the spin lock necessary. + * + * Returns: 1 if the queue is empty + */ + +static inline int queue_empty(struct gfs2_glock *gl, struct list_head *head) +{ + int empty; + spin_lock(&gl->gl_spin); + empty = list_empty(head); + spin_unlock(&gl->gl_spin); + return empty; +} + +/** + * search_bucket() - Find struct gfs2_glock by lock number + * @bucket: the bucket to search + * @name: The lock name + * + * Returns: NULL, or the struct gfs2_glock with the requested number + */ + +static struct gfs2_glock *search_bucket(struct gfs2_gl_hash_bucket *bucket, + struct lm_lockname *name) +{ + struct gfs2_glock *gl; + + list_for_each_entry(gl, &bucket->hb_list, gl_list) { + if (test_bit(GLF_PLUG, &gl->gl_flags)) + continue; + if (!lm_name_equal(&gl->gl_name, name)) + continue; + + kref_get(&gl->gl_ref); + + return gl; + } + + return NULL; +} + +/** + * gfs2_glock_find() - Find glock by lock number + * @sdp: The GFS2 superblock + * @name: The lock name + * + * Returns: NULL, or the struct gfs2_glock with the requested number + */ + +struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, + struct lm_lockname *name) +{ + struct gfs2_gl_hash_bucket *bucket = &sdp->sd_gl_hash[gl_hash(name)]; + struct gfs2_glock *gl; + + read_lock(&bucket->hb_lock); + gl = search_bucket(bucket, name); + read_unlock(&bucket->hb_lock); + + return gl; +} + +/** + * gfs2_glock_get() - Get a glock, or create one if one doesn't exist + * @sdp: The GFS2 superblock + * @number: the lock number + * @glops: The glock_operations to use + * @create: If 0, don't create the glock if it doesn't exist + * @glp: the glock is returned here + * + * This does not lock a glock, just finds/creates structures for one. + * + * Returns: errno + */ + +int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, + struct gfs2_glock_operations *glops, int create, + struct gfs2_glock **glp) +{ + struct lm_lockname name; + struct gfs2_glock *gl, *tmp; + struct gfs2_gl_hash_bucket *bucket; + int error; + + name.ln_number = number; + name.ln_type = glops->go_type; + bucket = &sdp->sd_gl_hash[gl_hash(&name)]; + + read_lock(&bucket->hb_lock); + gl = search_bucket(bucket, &name); + read_unlock(&bucket->hb_lock); + + if (gl || !create) { + *glp = gl; + return 0; + } + + gl = kmem_cache_alloc(gfs2_glock_cachep, GFP_KERNEL); + if (!gl) + return -ENOMEM; + + memset(gl, 0, sizeof(struct gfs2_glock)); + + INIT_LIST_HEAD(&gl->gl_list); + gl->gl_name = name; + kref_init(&gl->gl_ref); + + spin_lock_init(&gl->gl_spin); + + gl->gl_state = LM_ST_UNLOCKED; + INIT_LIST_HEAD(&gl->gl_holders); + INIT_LIST_HEAD(&gl->gl_waiters1); + INIT_LIST_HEAD(&gl->gl_waiters2); + INIT_LIST_HEAD(&gl->gl_waiters3); + + gl->gl_ops = glops; + + gl->gl_bucket = bucket; + INIT_LIST_HEAD(&gl->gl_reclaim); + + gl->gl_sbd = sdp; + + lops_init_le(&gl->gl_le, &gfs2_glock_lops); + INIT_LIST_HEAD(&gl->gl_ail_list); + + /* If this glock protects actual on-disk data or metadata blocks, + create a VFS inode to manage the pages/buffers holding them. */ + if (glops == &gfs2_inode_glops || + glops == &gfs2_rgrp_glops || + glops == &gfs2_meta_glops) { + gl->gl_aspace = gfs2_aspace_get(sdp); + if (!gl->gl_aspace) { + error = -ENOMEM; + goto fail; + } + } + + error = gfs2_lm_get_lock(sdp, &name, &gl->gl_lock); + if (error) + goto fail_aspace; + + atomic_inc(&sdp->sd_glock_count); + + write_lock(&bucket->hb_lock); + tmp = search_bucket(bucket, &name); + if (tmp) { + write_unlock(&bucket->hb_lock); + glock_free(gl); + gl = tmp; + } else { + list_add_tail(&gl->gl_list, &bucket->hb_list); + write_unlock(&bucket->hb_lock); + } + + *glp = gl; + + return 0; + + fail_aspace: + if (gl->gl_aspace) + gfs2_aspace_put(gl->gl_aspace); + + fail: + kmem_cache_free(gfs2_glock_cachep, gl); + + return error; +} + +/** + * gfs2_holder_init - initialize a struct gfs2_holder in the default way + * @gl: the glock + * @state: the state we're requesting + * @flags: the modifier flags + * @gh: the holder structure + * + */ + +void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, int flags, + struct gfs2_holder *gh) +{ + INIT_LIST_HEAD(&gh->gh_list); + gh->gh_gl = gl; + gh->gh_owner = (flags & GL_NEVER_RECURSE) ? NULL : current; + gh->gh_state = state; + gh->gh_flags = flags; + gh->gh_error = 0; + gh->gh_iflags = 0; + init_completion(&gh->gh_wait); + + if (gh->gh_state == LM_ST_EXCLUSIVE) + gh->gh_flags |= GL_LOCAL_EXCL; + + gfs2_glock_hold(gl); +} + +/** + * gfs2_holder_reinit - reinitialize a struct gfs2_holder so we can requeue it + * @state: the state we're requesting + * @flags: the modifier flags + * @gh: the holder structure + * + * Don't mess with the glock. + * + */ + +void gfs2_holder_reinit(unsigned int state, int flags, struct gfs2_holder *gh) +{ + gh->gh_state = state; + gh->gh_flags = flags; + if (gh->gh_state == LM_ST_EXCLUSIVE) + gh->gh_flags |= GL_LOCAL_EXCL; + + gh->gh_iflags &= 1 << HIF_ALLOCED; +} + +/** + * gfs2_holder_uninit - uninitialize a holder structure (drop glock reference) + * @gh: the holder structure + * + */ + +void gfs2_holder_uninit(struct gfs2_holder *gh) +{ + gfs2_glock_put(gh->gh_gl); + gh->gh_gl = NULL; +} + +/** + * gfs2_holder_get - get a struct gfs2_holder structure + * @gl: the glock + * @state: the state we're requesting + * @flags: the modifier flags + * @gfp_flags: __GFP_NOFAIL + * + * Figure out how big an impact this function has. Either: + * 1) Replace it with a cache of structures hanging off the struct gfs2_sbd + * 2) Leave it like it is + * + * Returns: the holder structure, NULL on ENOMEM + */ + +struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl, unsigned int state, + int flags, gfp_t gfp_flags) +{ + struct gfs2_holder *gh; + + gh = kmalloc(sizeof(struct gfs2_holder), gfp_flags); + if (!gh) + return NULL; + + gfs2_holder_init(gl, state, flags, gh); + set_bit(HIF_ALLOCED, &gh->gh_iflags); + + return gh; +} + +/** + * gfs2_holder_put - get rid of a struct gfs2_holder structure + * @gh: the holder structure + * + */ + +void gfs2_holder_put(struct gfs2_holder *gh) +{ + gfs2_holder_uninit(gh); + kfree(gh); +} + +/** + * handle_recurse - put other holder structures (marked recursive) + * into the holders list + * @gh: the holder structure + * + */ + +static void handle_recurse(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_holder *tmp_gh, *safe; + int found = 0; + + if (gfs2_assert_warn(sdp, gh->gh_owner)) + return; + + list_for_each_entry_safe(tmp_gh, safe, &gl->gl_waiters3, gh_list) { + if (tmp_gh->gh_owner != gh->gh_owner) + continue; + + gfs2_assert_warn(sdp, + test_bit(HIF_RECURSE, &tmp_gh->gh_iflags)); + + list_move_tail(&tmp_gh->gh_list, &gl->gl_holders); + tmp_gh->gh_error = 0; + set_bit(HIF_HOLDER, &tmp_gh->gh_iflags); + + complete(&tmp_gh->gh_wait); + + found = 1; + } + + gfs2_assert_warn(sdp, found); +} + +/** + * do_unrecurse - a recursive holder was just dropped of the waiters3 list + * @gh: the holder + * + * If there is only one other recursive holder, clear its HIF_RECURSE bit. + * If there is more than one, leave them alone. + * + */ + +static void do_unrecurse(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_holder *tmp_gh, *last_gh = NULL; + int found = 0; + + if (gfs2_assert_warn(sdp, gh->gh_owner)) + return; + + list_for_each_entry(tmp_gh, &gl->gl_waiters3, gh_list) { + if (tmp_gh->gh_owner != gh->gh_owner) + continue; + + gfs2_assert_warn(sdp, + test_bit(HIF_RECURSE, &tmp_gh->gh_iflags)); + + if (found) + return; + + found = 1; + last_gh = tmp_gh; + } + + if (!gfs2_assert_warn(sdp, found)) + clear_bit(HIF_RECURSE, &last_gh->gh_iflags); +} + +/** + * rq_mutex - process a mutex request in the queue + * @gh: the glock holder + * + * Returns: 1 if the queue is blocked + */ + +static int rq_mutex(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + + list_del_init(&gh->gh_list); + /* gh->gh_error never examined. */ + set_bit(GLF_LOCK, &gl->gl_flags); + complete(&gh->gh_wait); + + return 1; +} + +/** + * rq_promote - process a promote request in the queue + * @gh: the glock holder + * + * Acquire a new inter-node lock, or change a lock state to more restrictive. + * + * Returns: 1 if the queue is blocked + */ + +static int rq_promote(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_glock_operations *glops = gl->gl_ops; + int recurse; + + if (!relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) { + if (list_empty(&gl->gl_holders)) { + gl->gl_req_gh = gh; + set_bit(GLF_LOCK, &gl->gl_flags); + spin_unlock(&gl->gl_spin); + + if (atomic_read(&sdp->sd_reclaim_count) > + gfs2_tune_get(sdp, gt_reclaim_limit) && + !(gh->gh_flags & LM_FLAG_PRIORITY)) { + gfs2_reclaim_glock(sdp); + gfs2_reclaim_glock(sdp); + } + + glops->go_xmote_th(gl, gh->gh_state, + gh->gh_flags); + + spin_lock(&gl->gl_spin); + } + return 1; + } + + if (list_empty(&gl->gl_holders)) { + set_bit(HIF_FIRST, &gh->gh_iflags); + set_bit(GLF_LOCK, &gl->gl_flags); + recurse = 0; + } else { + struct gfs2_holder *next_gh; + if (gh->gh_flags & GL_LOCAL_EXCL) + return 1; + next_gh = list_entry(gl->gl_holders.next, struct gfs2_holder, + gh_list); + if (next_gh->gh_flags & GL_LOCAL_EXCL) + return 1; + recurse = test_bit(HIF_RECURSE, &gh->gh_iflags); + } + + list_move_tail(&gh->gh_list, &gl->gl_holders); + gh->gh_error = 0; + set_bit(HIF_HOLDER, &gh->gh_iflags); + + if (recurse) + handle_recurse(gh); + + complete(&gh->gh_wait); + + return 0; +} + +/** + * rq_demote - process a demote request in the queue + * @gh: the glock holder + * + * Returns: 1 if the queue is blocked + */ + +static int rq_demote(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_glock_operations *glops = gl->gl_ops; + + if (!list_empty(&gl->gl_holders)) + return 1; + + if (gl->gl_state == gh->gh_state || gl->gl_state == LM_ST_UNLOCKED) { + list_del_init(&gh->gh_list); + gh->gh_error = 0; + spin_unlock(&gl->gl_spin); + if (test_bit(HIF_DEALLOC, &gh->gh_iflags)) + gfs2_holder_put(gh); + else + complete(&gh->gh_wait); + spin_lock(&gl->gl_spin); + } else { + gl->gl_req_gh = gh; + set_bit(GLF_LOCK, &gl->gl_flags); + spin_unlock(&gl->gl_spin); + + if (gh->gh_state == LM_ST_UNLOCKED || + gl->gl_state != LM_ST_EXCLUSIVE) + glops->go_drop_th(gl); + else + glops->go_xmote_th(gl, gh->gh_state, gh->gh_flags); + + spin_lock(&gl->gl_spin); + } + + return 0; +} + +/** + * rq_greedy - process a queued request to drop greedy status + * @gh: the glock holder + * + * Returns: 1 if the queue is blocked + */ + +static int rq_greedy(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + + list_del_init(&gh->gh_list); + /* gh->gh_error never examined. */ + clear_bit(GLF_GREEDY, &gl->gl_flags); + spin_unlock(&gl->gl_spin); + + gfs2_holder_uninit(gh); + kfree(container_of(gh, struct greedy, gr_gh)); + + spin_lock(&gl->gl_spin); + + return 0; +} + +/** + * run_queue - process holder structures on a glock + * @gl: the glock + * + */ + +static void run_queue(struct gfs2_glock *gl) +{ + struct gfs2_holder *gh; + int blocked = 1; + + for (;;) { + if (test_bit(GLF_LOCK, &gl->gl_flags)) + break; + + if (!list_empty(&gl->gl_waiters1)) { + gh = list_entry(gl->gl_waiters1.next, + struct gfs2_holder, gh_list); + + if (test_bit(HIF_MUTEX, &gh->gh_iflags)) + blocked = rq_mutex(gh); + else + gfs2_assert_warn(gl->gl_sbd, 0); + + } else if (!list_empty(&gl->gl_waiters2) && + !test_bit(GLF_SKIP_WAITERS2, &gl->gl_flags)) { + gh = list_entry(gl->gl_waiters2.next, + struct gfs2_holder, gh_list); + + if (test_bit(HIF_DEMOTE, &gh->gh_iflags)) + blocked = rq_demote(gh); + else if (test_bit(HIF_GREEDY, &gh->gh_iflags)) + blocked = rq_greedy(gh); + else + gfs2_assert_warn(gl->gl_sbd, 0); + + } else if (!list_empty(&gl->gl_waiters3)) { + gh = list_entry(gl->gl_waiters3.next, + struct gfs2_holder, gh_list); + + if (test_bit(HIF_PROMOTE, &gh->gh_iflags)) + blocked = rq_promote(gh); + else + gfs2_assert_warn(gl->gl_sbd, 0); + + } else + break; + + if (blocked) + break; + } +} + +/** + * gfs2_glmutex_lock - acquire a local lock on a glock + * @gl: the glock + * + * Gives caller exclusive access to manipulate a glock structure. + */ + +void gfs2_glmutex_lock(struct gfs2_glock *gl) +{ + struct gfs2_holder gh; + + gfs2_holder_init(gl, 0, 0, &gh); + set_bit(HIF_MUTEX, &gh.gh_iflags); + + spin_lock(&gl->gl_spin); + if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) + list_add_tail(&gh.gh_list, &gl->gl_waiters1); + else + complete(&gh.gh_wait); + spin_unlock(&gl->gl_spin); + + wait_for_completion(&gh.gh_wait); + gfs2_holder_uninit(&gh); +} + +/** + * gfs2_glmutex_trylock - try to acquire a local lock on a glock + * @gl: the glock + * + * Returns: 1 if the glock is acquired + */ + +int gfs2_glmutex_trylock(struct gfs2_glock *gl) +{ + int acquired = 1; + + spin_lock(&gl->gl_spin); + if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) + acquired = 0; + spin_unlock(&gl->gl_spin); + + return acquired; +} + +/** + * gfs2_glmutex_unlock - release a local lock on a glock + * @gl: the glock + * + */ + +void gfs2_glmutex_unlock(struct gfs2_glock *gl) +{ + spin_lock(&gl->gl_spin); + clear_bit(GLF_LOCK, &gl->gl_flags); + run_queue(gl); + spin_unlock(&gl->gl_spin); +} + +/** + * handle_callback - add a demote request to a lock's queue + * @gl: the glock + * @state: the state the caller wants us to change to + * + */ + +static void handle_callback(struct gfs2_glock *gl, unsigned int state) +{ + struct gfs2_holder *gh, *new_gh = NULL; + + restart: + spin_lock(&gl->gl_spin); + + list_for_each_entry(gh, &gl->gl_waiters2, gh_list) { + if (test_bit(HIF_DEMOTE, &gh->gh_iflags) && + gl->gl_req_gh != gh) { + if (gh->gh_state != state) + gh->gh_state = LM_ST_UNLOCKED; + goto out; + } + } + + if (new_gh) { + list_add_tail(&new_gh->gh_list, &gl->gl_waiters2); + new_gh = NULL; + } else { + spin_unlock(&gl->gl_spin); + + new_gh = gfs2_holder_get(gl, state, + LM_FLAG_TRY | GL_NEVER_RECURSE, + GFP_KERNEL | __GFP_NOFAIL), + set_bit(HIF_DEMOTE, &new_gh->gh_iflags); + set_bit(HIF_DEALLOC, &new_gh->gh_iflags); + + goto restart; + } + + out: + spin_unlock(&gl->gl_spin); + + if (new_gh) + gfs2_holder_put(new_gh); +} + +/** + * state_change - record that the glock is now in a different state + * @gl: the glock + * @new_state the new state + * + */ + +static void state_change(struct gfs2_glock *gl, unsigned int new_state) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + int held1, held2; + + held1 = (gl->gl_state != LM_ST_UNLOCKED); + held2 = (new_state != LM_ST_UNLOCKED); + + if (held1 != held2) { + if (held2) { + atomic_inc(&sdp->sd_glock_held_count); + gfs2_glock_hold(gl); + } else { + atomic_dec(&sdp->sd_glock_held_count); + gfs2_glock_put(gl); + } + } + + gl->gl_state = new_state; +} + +/** + * xmote_bh - Called after the lock module is done acquiring a lock + * @gl: The glock in question + * @ret: the int returned from the lock module + * + */ + +static void xmote_bh(struct gfs2_glock *gl, unsigned int ret) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_glock_operations *glops = gl->gl_ops; + struct gfs2_holder *gh = gl->gl_req_gh; + int prev_state = gl->gl_state; + int op_done = 1; + + gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags)); + gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders)); + gfs2_assert_warn(sdp, !(ret & LM_OUT_ASYNC)); + + state_change(gl, ret & LM_OUT_ST_MASK); + + if (prev_state != LM_ST_UNLOCKED && !(ret & LM_OUT_CACHEABLE)) { + if (glops->go_inval) + glops->go_inval(gl, DIO_METADATA | DIO_DATA); + } else if (gl->gl_state == LM_ST_DEFERRED) { + /* We might not want to do this here. + Look at moving to the inode glops. */ + if (glops->go_inval) + glops->go_inval(gl, DIO_DATA); + } + + /* Deal with each possible exit condition */ + + if (!gh) + gl->gl_stamp = jiffies; + + else if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) { + spin_lock(&gl->gl_spin); + list_del_init(&gh->gh_list); + gh->gh_error = -EIO; + if (test_bit(HIF_RECURSE, &gh->gh_iflags)) + do_unrecurse(gh); + spin_unlock(&gl->gl_spin); + + } else if (test_bit(HIF_DEMOTE, &gh->gh_iflags)) { + spin_lock(&gl->gl_spin); + list_del_init(&gh->gh_list); + if (gl->gl_state == gh->gh_state || + gl->gl_state == LM_ST_UNLOCKED) + gh->gh_error = 0; + else { + if (gfs2_assert_warn(sdp, gh->gh_flags & + (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) == -1) + fs_warn(sdp, "ret = 0x%.8X\n", ret); + gh->gh_error = GLR_TRYFAILED; + } + spin_unlock(&gl->gl_spin); + + if (ret & LM_OUT_CANCELED) + handle_callback(gl, LM_ST_UNLOCKED); /* Lame */ + + } else if (ret & LM_OUT_CANCELED) { + spin_lock(&gl->gl_spin); + list_del_init(&gh->gh_list); + gh->gh_error = GLR_CANCELED; + if (test_bit(HIF_RECURSE, &gh->gh_iflags)) + do_unrecurse(gh); + spin_unlock(&gl->gl_spin); + + } else if (relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) { + spin_lock(&gl->gl_spin); + list_move_tail(&gh->gh_list, &gl->gl_holders); + gh->gh_error = 0; + set_bit(HIF_HOLDER, &gh->gh_iflags); + spin_unlock(&gl->gl_spin); + + set_bit(HIF_FIRST, &gh->gh_iflags); + + op_done = 0; + + } else if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) { + spin_lock(&gl->gl_spin); + list_del_init(&gh->gh_list); + gh->gh_error = GLR_TRYFAILED; + if (test_bit(HIF_RECURSE, &gh->gh_iflags)) + do_unrecurse(gh); + spin_unlock(&gl->gl_spin); + + } else { + if (gfs2_assert_withdraw(sdp, 0) == -1) + fs_err(sdp, "ret = 0x%.8X\n", ret); + } + + if (glops->go_xmote_bh) + glops->go_xmote_bh(gl); + + if (op_done) { + spin_lock(&gl->gl_spin); + gl->gl_req_gh = NULL; + gl->gl_req_bh = NULL; + clear_bit(GLF_LOCK, &gl->gl_flags); + run_queue(gl); + spin_unlock(&gl->gl_spin); + } + + gfs2_glock_put(gl); + + if (gh) { + if (test_bit(HIF_DEALLOC, &gh->gh_iflags)) + gfs2_holder_put(gh); + else + complete(&gh->gh_wait); + } +} + +/** + * gfs2_glock_xmote_th - Call into the lock module to acquire or change a glock + * @gl: The glock in question + * @state: the requested state + * @flags: modifier flags to the lock call + * + */ + +void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_glock_operations *glops = gl->gl_ops; + int lck_flags = flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB | + LM_FLAG_NOEXP | LM_FLAG_ANY | + LM_FLAG_PRIORITY); + unsigned int lck_ret; + + gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags)); + gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders)); + gfs2_assert_warn(sdp, state != LM_ST_UNLOCKED); + gfs2_assert_warn(sdp, state != gl->gl_state); + + if (gl->gl_state == LM_ST_EXCLUSIVE) { + if (glops->go_sync) + glops->go_sync(gl, + DIO_METADATA | DIO_DATA | DIO_RELEASE); + } + + gfs2_glock_hold(gl); + gl->gl_req_bh = xmote_bh; + + atomic_inc(&sdp->sd_lm_lock_calls); + + lck_ret = gfs2_lm_lock(sdp, gl->gl_lock, gl->gl_state, state, + lck_flags); + + if (gfs2_assert_withdraw(sdp, !(lck_ret & LM_OUT_ERROR))) + return; + + if (lck_ret & LM_OUT_ASYNC) + gfs2_assert_warn(sdp, lck_ret == LM_OUT_ASYNC); + else + xmote_bh(gl, lck_ret); +} + +/** + * drop_bh - Called after a lock module unlock completes + * @gl: the glock + * @ret: the return status + * + * Doesn't wake up the process waiting on the struct gfs2_holder (if any) + * Doesn't drop the reference on the glock the top half took out + * + */ + +static void drop_bh(struct gfs2_glock *gl, unsigned int ret) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_glock_operations *glops = gl->gl_ops; + struct gfs2_holder *gh = gl->gl_req_gh; + + clear_bit(GLF_PREFETCH, &gl->gl_flags); + + gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags)); + gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders)); + gfs2_assert_warn(sdp, !ret); + + state_change(gl, LM_ST_UNLOCKED); + + if (glops->go_inval) + glops->go_inval(gl, DIO_METADATA | DIO_DATA); + + if (gh) { + spin_lock(&gl->gl_spin); + list_del_init(&gh->gh_list); + gh->gh_error = 0; + spin_unlock(&gl->gl_spin); + } + + if (glops->go_drop_bh) + glops->go_drop_bh(gl); + + spin_lock(&gl->gl_spin); + gl->gl_req_gh = NULL; + gl->gl_req_bh = NULL; + clear_bit(GLF_LOCK, &gl->gl_flags); + run_queue(gl); + spin_unlock(&gl->gl_spin); + + gfs2_glock_put(gl); + + if (gh) { + if (test_bit(HIF_DEALLOC, &gh->gh_iflags)) + gfs2_holder_put(gh); + else + complete(&gh->gh_wait); + } +} + +/** + * gfs2_glock_drop_th - call into the lock module to unlock a lock + * @gl: the glock + * + */ + +void gfs2_glock_drop_th(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_glock_operations *glops = gl->gl_ops; + unsigned int ret; + + gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags)); + gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders)); + gfs2_assert_warn(sdp, gl->gl_state != LM_ST_UNLOCKED); + + if (gl->gl_state == LM_ST_EXCLUSIVE) { + if (glops->go_sync) + glops->go_sync(gl, + DIO_METADATA | DIO_DATA | DIO_RELEASE); + } + + gfs2_glock_hold(gl); + gl->gl_req_bh = drop_bh; + + atomic_inc(&sdp->sd_lm_unlock_calls); + + ret = gfs2_lm_unlock(sdp, gl->gl_lock, gl->gl_state); + + if (gfs2_assert_withdraw(sdp, !(ret & LM_OUT_ERROR))) + return; + + if (!ret) + drop_bh(gl, ret); + else + gfs2_assert_warn(sdp, ret == LM_OUT_ASYNC); +} + +/** + * do_cancels - cancel requests for locks stuck waiting on an expire flag + * @gh: the LM_FLAG_PRIORITY holder waiting to acquire the lock + * + * Don't cancel GL_NOCANCEL requests. + */ + +static void do_cancels(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + + spin_lock(&gl->gl_spin); + + while (gl->gl_req_gh != gh && + !test_bit(HIF_HOLDER, &gh->gh_iflags) && + !list_empty(&gh->gh_list)) { + if (gl->gl_req_bh && + !(gl->gl_req_gh && + (gl->gl_req_gh->gh_flags & GL_NOCANCEL))) { + spin_unlock(&gl->gl_spin); + gfs2_lm_cancel(gl->gl_sbd, gl->gl_lock); + msleep(100); + spin_lock(&gl->gl_spin); + } else { + spin_unlock(&gl->gl_spin); + msleep(100); + spin_lock(&gl->gl_spin); + } + } + + spin_unlock(&gl->gl_spin); +} + +/** + * glock_wait_internal - wait on a glock acquisition + * @gh: the glock holder + * + * Returns: 0 on success + */ + +static int glock_wait_internal(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_glock_operations *glops = gl->gl_ops; + + if (test_bit(HIF_ABORTED, &gh->gh_iflags)) + return -EIO; + + if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) { + spin_lock(&gl->gl_spin); + if (gl->gl_req_gh != gh && + !test_bit(HIF_HOLDER, &gh->gh_iflags) && + !list_empty(&gh->gh_list)) { + list_del_init(&gh->gh_list); + gh->gh_error = GLR_TRYFAILED; + if (test_bit(HIF_RECURSE, &gh->gh_iflags)) + do_unrecurse(gh); + run_queue(gl); + spin_unlock(&gl->gl_spin); + return gh->gh_error; + } + spin_unlock(&gl->gl_spin); + } + + if (gh->gh_flags & LM_FLAG_PRIORITY) + do_cancels(gh); + + wait_for_completion(&gh->gh_wait); + + if (gh->gh_error) + return gh->gh_error; + + gfs2_assert_withdraw(sdp, test_bit(HIF_HOLDER, &gh->gh_iflags)); + gfs2_assert_withdraw(sdp, relaxed_state_ok(gl->gl_state, + gh->gh_state, + gh->gh_flags)); + + if (test_bit(HIF_FIRST, &gh->gh_iflags)) { + gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags)); + + if (glops->go_lock) { + gh->gh_error = glops->go_lock(gh); + if (gh->gh_error) { + spin_lock(&gl->gl_spin); + list_del_init(&gh->gh_list); + if (test_and_clear_bit(HIF_RECURSE, + &gh->gh_iflags)) + do_unrecurse(gh); + spin_unlock(&gl->gl_spin); + } + } + + spin_lock(&gl->gl_spin); + gl->gl_req_gh = NULL; + gl->gl_req_bh = NULL; + clear_bit(GLF_LOCK, &gl->gl_flags); + if (test_bit(HIF_RECURSE, &gh->gh_iflags)) + handle_recurse(gh); + run_queue(gl); + spin_unlock(&gl->gl_spin); + } + + return gh->gh_error; +} + +static inline struct gfs2_holder * +find_holder_by_owner(struct list_head *head, struct task_struct *owner) +{ + struct gfs2_holder *gh; + + list_for_each_entry(gh, head, gh_list) { + if (gh->gh_owner == owner) + return gh; + } + + return NULL; +} + +/** + * recurse_check - + * + * Make sure the new holder is compatible with the pre-existing one. + * + */ + +static int recurse_check(struct gfs2_holder *existing, struct gfs2_holder *new, + unsigned int state) +{ + struct gfs2_sbd *sdp = existing->gh_gl->gl_sbd; + + if (gfs2_assert_warn(sdp, (new->gh_flags & LM_FLAG_ANY) || + !(existing->gh_flags & LM_FLAG_ANY))) + goto fail; + + if (gfs2_assert_warn(sdp, (existing->gh_flags & GL_LOCAL_EXCL) || + !(new->gh_flags & GL_LOCAL_EXCL))) + goto fail; + + if (gfs2_assert_warn(sdp, relaxed_state_ok(state, new->gh_state, + new->gh_flags))) + goto fail; + + return 0; + + fail: + set_bit(HIF_ABORTED, &new->gh_iflags); + return -EINVAL; +} + +/** + * add_to_queue - Add a holder to the wait queue (but look for recursion) + * @gh: the holder structure to add + * + */ + +static void add_to_queue(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_holder *existing; + + if (!gh->gh_owner) + goto out; + + existing = find_holder_by_owner(&gl->gl_holders, gh->gh_owner); + if (existing) { + if (recurse_check(existing, gh, gl->gl_state)) + return; + + list_add_tail(&gh->gh_list, &gl->gl_holders); + set_bit(HIF_HOLDER, &gh->gh_iflags); + + gh->gh_error = 0; + complete(&gh->gh_wait); + + return; + } + + existing = find_holder_by_owner(&gl->gl_waiters3, gh->gh_owner); + if (existing) { + if (recurse_check(existing, gh, existing->gh_state)) + return; + + set_bit(HIF_RECURSE, &gh->gh_iflags); + set_bit(HIF_RECURSE, &existing->gh_iflags); + + list_add_tail(&gh->gh_list, &gl->gl_waiters3); + + return; + } + + out: + if (gh->gh_flags & LM_FLAG_PRIORITY) + list_add(&gh->gh_list, &gl->gl_waiters3); + else + list_add_tail(&gh->gh_list, &gl->gl_waiters3); +} + +/** + * gfs2_glock_nq - enqueue a struct gfs2_holder onto a glock (acquire a glock) + * @gh: the holder structure + * + * if (gh->gh_flags & GL_ASYNC), this never returns an error + * + * Returns: 0, GLR_TRYFAILED, or errno on failure + */ + +int gfs2_glock_nq(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_sbd *sdp = gl->gl_sbd; + int error = 0; + + atomic_inc(&sdp->sd_glock_nq_calls); + + restart: + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) { + set_bit(HIF_ABORTED, &gh->gh_iflags); + return -EIO; + } + + set_bit(HIF_PROMOTE, &gh->gh_iflags); + + spin_lock(&gl->gl_spin); + add_to_queue(gh); + run_queue(gl); + spin_unlock(&gl->gl_spin); + + if (!(gh->gh_flags & GL_ASYNC)) { + error = glock_wait_internal(gh); + if (error == GLR_CANCELED) { + msleep(1000); + goto restart; + } + } + + clear_bit(GLF_PREFETCH, &gl->gl_flags); + + return error; +} + +/** + * gfs2_glock_poll - poll to see if an async request has been completed + * @gh: the holder + * + * Returns: 1 if the request is ready to be gfs2_glock_wait()ed on + */ + +int gfs2_glock_poll(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + int ready = 0; + + spin_lock(&gl->gl_spin); + + if (test_bit(HIF_HOLDER, &gh->gh_iflags)) + ready = 1; + else if (list_empty(&gh->gh_list)) { + if (gh->gh_error == GLR_CANCELED) { + spin_unlock(&gl->gl_spin); + msleep(1000); + if (gfs2_glock_nq(gh)) + return 1; + return 0; + } else + ready = 1; + } + + spin_unlock(&gl->gl_spin); + + return ready; +} + +/** + * gfs2_glock_wait - wait for a lock acquisition that ended in a GLR_ASYNC + * @gh: the holder structure + * + * Returns: 0, GLR_TRYFAILED, or errno on failure + */ + +int gfs2_glock_wait(struct gfs2_holder *gh) +{ + int error; + + error = glock_wait_internal(gh); + if (error == GLR_CANCELED) { + msleep(1000); + gh->gh_flags &= ~GL_ASYNC; + error = gfs2_glock_nq(gh); + } + + return error; +} + +/** + * gfs2_glock_dq - dequeue a struct gfs2_holder from a glock (release a glock) + * @gh: the glock holder + * + */ + +void gfs2_glock_dq(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_glock_operations *glops = gl->gl_ops; + + atomic_inc(&sdp->sd_glock_dq_calls); + + if (gh->gh_flags & GL_SYNC) + set_bit(GLF_SYNC, &gl->gl_flags); + + if (gh->gh_flags & GL_NOCACHE) + handle_callback(gl, LM_ST_UNLOCKED); + + gfs2_glmutex_lock(gl); + + spin_lock(&gl->gl_spin); + list_del_init(&gh->gh_list); + + if (list_empty(&gl->gl_holders)) { + spin_unlock(&gl->gl_spin); + + if (glops->go_unlock) + glops->go_unlock(gh); + + if (test_bit(GLF_SYNC, &gl->gl_flags)) { + if (glops->go_sync) + glops->go_sync(gl, DIO_METADATA | DIO_DATA); + } + + gl->gl_stamp = jiffies; + + spin_lock(&gl->gl_spin); + } + + clear_bit(GLF_LOCK, &gl->gl_flags); + run_queue(gl); + spin_unlock(&gl->gl_spin); +} + +/** + * gfs2_glock_prefetch - Try to prefetch a glock + * @gl: the glock + * @state: the state to prefetch in + * @flags: flags passed to go_xmote_th() + * + */ + +void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, int flags) +{ + struct gfs2_glock_operations *glops = gl->gl_ops; + + spin_lock(&gl->gl_spin); + + if (test_bit(GLF_LOCK, &gl->gl_flags) || + !list_empty(&gl->gl_holders) || + !list_empty(&gl->gl_waiters1) || + !list_empty(&gl->gl_waiters2) || + !list_empty(&gl->gl_waiters3) || + relaxed_state_ok(gl->gl_state, state, flags)) { + spin_unlock(&gl->gl_spin); + return; + } + + set_bit(GLF_PREFETCH, &gl->gl_flags); + set_bit(GLF_LOCK, &gl->gl_flags); + spin_unlock(&gl->gl_spin); + + glops->go_xmote_th(gl, state, flags); + + atomic_inc(&gl->gl_sbd->sd_glock_prefetch_calls); +} + +/** + * gfs2_glock_force_drop - Force a glock to be uncached + * @gl: the glock + * + */ + +void gfs2_glock_force_drop(struct gfs2_glock *gl) +{ + struct gfs2_holder gh; + + gfs2_holder_init(gl, LM_ST_UNLOCKED, GL_NEVER_RECURSE, &gh); + set_bit(HIF_DEMOTE, &gh.gh_iflags); + + spin_lock(&gl->gl_spin); + list_add_tail(&gh.gh_list, &gl->gl_waiters2); + run_queue(gl); + spin_unlock(&gl->gl_spin); + + wait_for_completion(&gh.gh_wait); + gfs2_holder_uninit(&gh); +} + +static void greedy_work(void *data) +{ + struct greedy *gr = (struct greedy *)data; + struct gfs2_holder *gh = &gr->gr_gh; + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_glock_operations *glops = gl->gl_ops; + + clear_bit(GLF_SKIP_WAITERS2, &gl->gl_flags); + + if (glops->go_greedy) + glops->go_greedy(gl); + + spin_lock(&gl->gl_spin); + + if (list_empty(&gl->gl_waiters2)) { + clear_bit(GLF_GREEDY, &gl->gl_flags); + spin_unlock(&gl->gl_spin); + gfs2_holder_uninit(gh); + kfree(gr); + } else { + gfs2_glock_hold(gl); + list_add_tail(&gh->gh_list, &gl->gl_waiters2); + run_queue(gl); + spin_unlock(&gl->gl_spin); + gfs2_glock_put(gl); + } +} + +/** + * gfs2_glock_be_greedy - + * @gl: + * @time: + * + * Returns: 0 if go_greedy will be called, 1 otherwise + */ + +int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time) +{ + struct greedy *gr; + struct gfs2_holder *gh; + + if (!time || + gl->gl_sbd->sd_args.ar_localcaching || + test_and_set_bit(GLF_GREEDY, &gl->gl_flags)) + return 1; + + gr = kmalloc(sizeof(struct greedy), GFP_KERNEL); + if (!gr) { + clear_bit(GLF_GREEDY, &gl->gl_flags); + return 1; + } + gh = &gr->gr_gh; + + gfs2_holder_init(gl, 0, GL_NEVER_RECURSE, gh); + set_bit(HIF_GREEDY, &gh->gh_iflags); + INIT_WORK(&gr->gr_work, greedy_work, gr); + + set_bit(GLF_SKIP_WAITERS2, &gl->gl_flags); + schedule_delayed_work(&gr->gr_work, time); + + return 0; +} + +/** + * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock + * @gl: the glock + * @state: the state we're requesting + * @flags: the modifier flags + * @gh: the holder structure + * + * Returns: 0, GLR_*, or errno + */ + +int gfs2_glock_nq_init(struct gfs2_glock *gl, unsigned int state, int flags, + struct gfs2_holder *gh) +{ + int error; + + gfs2_holder_init(gl, state, flags, gh); + + error = gfs2_glock_nq(gh); + if (error) + gfs2_holder_uninit(gh); + + return error; +} + +/** + * gfs2_glock_dq_uninit - dequeue a holder from a glock and initialize it + * @gh: the holder structure + * + */ + +void gfs2_glock_dq_uninit(struct gfs2_holder *gh) +{ + gfs2_glock_dq(gh); + gfs2_holder_uninit(gh); +} + +/** + * gfs2_glock_nq_num - acquire a glock based on lock number + * @sdp: the filesystem + * @number: the lock number + * @glops: the glock operations for the type of glock + * @state: the state to acquire the glock in + * @flags: modifier flags for the aquisition + * @gh: the struct gfs2_holder + * + * Returns: errno + */ + +int gfs2_glock_nq_num(struct gfs2_sbd *sdp, uint64_t number, + struct gfs2_glock_operations *glops, unsigned int state, + int flags, struct gfs2_holder *gh) +{ + struct gfs2_glock *gl; + int error; + + error = gfs2_glock_get(sdp, number, glops, CREATE, &gl); + if (!error) { + error = gfs2_glock_nq_init(gl, state, flags, gh); + gfs2_glock_put(gl); + } + + return error; +} + +/** + * glock_compare - Compare two struct gfs2_glock structures for sorting + * @arg_a: the first structure + * @arg_b: the second structure + * + */ + +static int glock_compare(const void *arg_a, const void *arg_b) +{ + struct gfs2_holder *gh_a = *(struct gfs2_holder **)arg_a; + struct gfs2_holder *gh_b = *(struct gfs2_holder **)arg_b; + struct lm_lockname *a = &gh_a->gh_gl->gl_name; + struct lm_lockname *b = &gh_b->gh_gl->gl_name; + int ret = 0; + + if (a->ln_number > b->ln_number) + ret = 1; + else if (a->ln_number < b->ln_number) + ret = -1; + else { + if (gh_a->gh_state == LM_ST_SHARED && + gh_b->gh_state == LM_ST_EXCLUSIVE) + ret = 1; + else if (!(gh_a->gh_flags & GL_LOCAL_EXCL) && + (gh_b->gh_flags & GL_LOCAL_EXCL)) + ret = 1; + } + + return ret; +} + +/** + * nq_m_sync - synchonously acquire more than one glock in deadlock free order + * @num_gh: the number of structures + * @ghs: an array of struct gfs2_holder structures + * + * Returns: 0 on success (all glocks acquired), + * errno on failure (no glocks acquired) + */ + +static int nq_m_sync(unsigned int num_gh, struct gfs2_holder *ghs, + struct gfs2_holder **p) +{ + unsigned int x; + int error = 0; + + for (x = 0; x < num_gh; x++) + p[x] = &ghs[x]; + + sort(p, num_gh, sizeof(struct gfs2_holder *), glock_compare, NULL); + + for (x = 0; x < num_gh; x++) { + p[x]->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC); + + error = gfs2_glock_nq(p[x]); + if (error) { + while (x--) + gfs2_glock_dq(p[x]); + break; + } + } + + return error; +} + +/** + * gfs2_glock_nq_m - acquire multiple glocks + * @num_gh: the number of structures + * @ghs: an array of struct gfs2_holder structures + * + * Figure out how big an impact this function has. Either: + * 1) Replace this code with code that calls gfs2_glock_prefetch() + * 2) Forget async stuff and just call nq_m_sync() + * 3) Leave it like it is + * + * Returns: 0 on success (all glocks acquired), + * errno on failure (no glocks acquired) + */ + +int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs) +{ + int *e; + unsigned int x; + int borked = 0, serious = 0; + int error = 0; + + if (!num_gh) + return 0; + + if (num_gh == 1) { + ghs->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC); + return gfs2_glock_nq(ghs); + } + + e = kcalloc(num_gh, sizeof(struct gfs2_holder *), GFP_KERNEL); + if (!e) + return -ENOMEM; + + for (x = 0; x < num_gh; x++) { + ghs[x].gh_flags |= LM_FLAG_TRY | GL_ASYNC; + error = gfs2_glock_nq(&ghs[x]); + if (error) { + borked = 1; + serious = error; + num_gh = x; + break; + } + } + + for (x = 0; x < num_gh; x++) { + error = e[x] = glock_wait_internal(&ghs[x]); + if (error) { + borked = 1; + if (error != GLR_TRYFAILED && error != GLR_CANCELED) + serious = error; + } + } + + if (!borked) { + kfree(e); + return 0; + } + + for (x = 0; x < num_gh; x++) + if (!e[x]) + gfs2_glock_dq(&ghs[x]); + + if (serious) + error = serious; + else { + for (x = 0; x < num_gh; x++) + gfs2_holder_reinit(ghs[x].gh_state, ghs[x].gh_flags, + &ghs[x]); + error = nq_m_sync(num_gh, ghs, (struct gfs2_holder **)e); + } + + kfree(e); + + return error; +} + +/** + * gfs2_glock_dq_m - release multiple glocks + * @num_gh: the number of structures + * @ghs: an array of struct gfs2_holder structures + * + */ + +void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs) +{ + unsigned int x; + + for (x = 0; x < num_gh; x++) + gfs2_glock_dq(&ghs[x]); +} + +/** + * gfs2_glock_dq_uninit_m - release multiple glocks + * @num_gh: the number of structures + * @ghs: an array of struct gfs2_holder structures + * + */ + +void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs) +{ + unsigned int x; + + for (x = 0; x < num_gh; x++) + gfs2_glock_dq_uninit(&ghs[x]); +} + +/** + * gfs2_glock_prefetch_num - prefetch a glock based on lock number + * @sdp: the filesystem + * @number: the lock number + * @glops: the glock operations for the type of glock + * @state: the state to acquire the glock in + * @flags: modifier flags for the aquisition + * + * Returns: errno + */ + +void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number, + struct gfs2_glock_operations *glops, + unsigned int state, int flags) +{ + struct gfs2_glock *gl; + int error; + + if (atomic_read(&sdp->sd_reclaim_count) < + gfs2_tune_get(sdp, gt_reclaim_limit)) { + error = gfs2_glock_get(sdp, number, glops, CREATE, &gl); + if (!error) { + gfs2_glock_prefetch(gl, state, flags); + gfs2_glock_put(gl); + } + } +} + +/** + * gfs2_lvb_hold - attach a LVB from a glock + * @gl: The glock in question + * + */ + +int gfs2_lvb_hold(struct gfs2_glock *gl) +{ + int error; + + gfs2_glmutex_lock(gl); + + if (!atomic_read(&gl->gl_lvb_count)) { + error = gfs2_lm_hold_lvb(gl->gl_sbd, gl->gl_lock, &gl->gl_lvb); + if (error) { + gfs2_glmutex_unlock(gl); + return error; + } + gfs2_glock_hold(gl); + } + atomic_inc(&gl->gl_lvb_count); + + gfs2_glmutex_unlock(gl); + + return 0; +} + +/** + * gfs2_lvb_unhold - detach a LVB from a glock + * @gl: The glock in question + * + */ + +void gfs2_lvb_unhold(struct gfs2_glock *gl) +{ + gfs2_glock_hold(gl); + gfs2_glmutex_lock(gl); + + gfs2_assert(gl->gl_sbd, atomic_read(&gl->gl_lvb_count) > 0); + if (atomic_dec_and_test(&gl->gl_lvb_count)) { + gfs2_lm_unhold_lvb(gl->gl_sbd, gl->gl_lock, gl->gl_lvb); + gl->gl_lvb = NULL; + gfs2_glock_put(gl); + } + + gfs2_glmutex_unlock(gl); + gfs2_glock_put(gl); +} + +void gfs2_lvb_sync(struct gfs2_glock *gl) +{ + gfs2_glmutex_lock(gl); + + gfs2_assert(gl->gl_sbd, atomic_read(&gl->gl_lvb_count)); + if (!gfs2_assert_warn(gl->gl_sbd, gfs2_glock_is_held_excl(gl))) + gfs2_lm_sync_lvb(gl->gl_sbd, gl->gl_lock, gl->gl_lvb); + + gfs2_glmutex_unlock(gl); +} + +static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name, + unsigned int state) +{ + struct gfs2_glock *gl; + + gl = gfs2_glock_find(sdp, name); + if (!gl) + return; + + if (gl->gl_ops->go_callback) + gl->gl_ops->go_callback(gl, state); + handle_callback(gl, state); + + spin_lock(&gl->gl_spin); + run_queue(gl); + spin_unlock(&gl->gl_spin); + + gfs2_glock_put(gl); +} + +/** + * gfs2_glock_cb - Callback used by locking module + * @fsdata: Pointer to the superblock + * @type: Type of callback + * @data: Type dependent data pointer + * + * Called by the locking module when it wants to tell us something. + * Either we need to drop a lock, one of our ASYNC requests completed, or + * a journal from another client needs to be recovered. + */ + +void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data) +{ + struct gfs2_sbd *sdp = (struct gfs2_sbd *)fsdata; + + atomic_inc(&sdp->sd_lm_callbacks); + + switch (type) { + case LM_CB_NEED_E: + blocking_cb(sdp, (struct lm_lockname *)data, LM_ST_UNLOCKED); + return; + + case LM_CB_NEED_D: + blocking_cb(sdp, (struct lm_lockname *)data, LM_ST_DEFERRED); + return; + + case LM_CB_NEED_S: + blocking_cb(sdp, (struct lm_lockname *)data, LM_ST_SHARED); + return; + + case LM_CB_ASYNC: { + struct lm_async_cb *async = (struct lm_async_cb *)data; + struct gfs2_glock *gl; + + gl = gfs2_glock_find(sdp, &async->lc_name); + if (gfs2_assert_warn(sdp, gl)) + return; + if (!gfs2_assert_warn(sdp, gl->gl_req_bh)) + gl->gl_req_bh(gl, async->lc_ret); + gfs2_glock_put(gl); + + return; + } + + case LM_CB_NEED_RECOVERY: + gfs2_jdesc_make_dirty(sdp, *(unsigned int *)data); + if (sdp->sd_recoverd_process) + wake_up_process(sdp->sd_recoverd_process); + return; + + case LM_CB_DROPLOCKS: + gfs2_gl_hash_clear(sdp, NO_WAIT); + gfs2_quota_scan(sdp); + return; + + default: + gfs2_assert_warn(sdp, 0); + return; + } +} + +/** + * gfs2_try_toss_inode - try to remove a particular inode struct from cache + * sdp: the filesystem + * inum: the inode number + * + */ + +void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum) +{ + struct gfs2_glock *gl; + struct gfs2_inode *ip; + int error; + + error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops, + NO_CREATE, &gl); + if (error || !gl) + return; + + if (!gfs2_glmutex_trylock(gl)) + goto out; + + ip = get_gl2ip(gl); + if (!ip) + goto out_unlock; + + if (atomic_read(&ip->i_count)) + goto out_unlock; + + gfs2_inode_destroy(ip); + + out_unlock: + gfs2_glmutex_unlock(gl); + + out: + gfs2_glock_put(gl); +} + +/** + * gfs2_iopen_go_callback - Try to kick the inode/vnode associated with an + * iopen glock from memory + * @io_gl: the iopen glock + * @state: the state into which the glock should be put + * + */ + +void gfs2_iopen_go_callback(struct gfs2_glock *io_gl, unsigned int state) +{ + struct gfs2_glock *i_gl; + + if (state != LM_ST_UNLOCKED) + return; + + spin_lock(&io_gl->gl_spin); + i_gl = get_gl2gl(io_gl); + if (i_gl) { + gfs2_glock_hold(i_gl); + spin_unlock(&io_gl->gl_spin); + } else { + spin_unlock(&io_gl->gl_spin); + return; + } + + if (gfs2_glmutex_trylock(i_gl)) { + struct gfs2_inode *ip = get_gl2ip(i_gl); + if (ip) { + gfs2_try_toss_vnode(ip); + gfs2_glmutex_unlock(i_gl); + gfs2_glock_schedule_for_reclaim(i_gl); + goto out; + } + gfs2_glmutex_unlock(i_gl); + } + + out: + gfs2_glock_put(i_gl); +} + +/** + * demote_ok - Check to see if it's ok to unlock a glock + * @gl: the glock + * + * Returns: 1 if it's ok + */ + +static int demote_ok(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_glock_operations *glops = gl->gl_ops; + int demote = 1; + + if (test_bit(GLF_STICKY, &gl->gl_flags)) + demote = 0; + else if (test_bit(GLF_PREFETCH, &gl->gl_flags)) + demote = time_after_eq(jiffies, + gl->gl_stamp + + gfs2_tune_get(sdp, gt_prefetch_secs) * HZ); + else if (glops->go_demote_ok) + demote = glops->go_demote_ok(gl); + + return demote; +} + +/** + * gfs2_glock_schedule_for_reclaim - Add a glock to the reclaim list + * @gl: the glock + * + */ + +void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + + spin_lock(&sdp->sd_reclaim_lock); + if (list_empty(&gl->gl_reclaim)) { + gfs2_glock_hold(gl); + list_add(&gl->gl_reclaim, &sdp->sd_reclaim_list); + atomic_inc(&sdp->sd_reclaim_count); + } + spin_unlock(&sdp->sd_reclaim_lock); + + wake_up(&sdp->sd_reclaim_wq); +} + +/** + * gfs2_reclaim_glock - process the next glock on the filesystem's reclaim list + * @sdp: the filesystem + * + * Called from gfs2_glockd() glock reclaim daemon, or when promoting a + * different glock and we notice that there are a lot of glocks in the + * reclaim list. + * + */ + +void gfs2_reclaim_glock(struct gfs2_sbd *sdp) +{ + struct gfs2_glock *gl; + + spin_lock(&sdp->sd_reclaim_lock); + if (list_empty(&sdp->sd_reclaim_list)) { + spin_unlock(&sdp->sd_reclaim_lock); + return; + } + gl = list_entry(sdp->sd_reclaim_list.next, + struct gfs2_glock, gl_reclaim); + list_del_init(&gl->gl_reclaim); + spin_unlock(&sdp->sd_reclaim_lock); + + atomic_dec(&sdp->sd_reclaim_count); + atomic_inc(&sdp->sd_reclaimed); + + if (gfs2_glmutex_trylock(gl)) { + if (gl->gl_ops == &gfs2_inode_glops) { + struct gfs2_inode *ip = get_gl2ip(gl); + if (ip && !atomic_read(&ip->i_count)) + gfs2_inode_destroy(ip); + } + if (queue_empty(gl, &gl->gl_holders) && + gl->gl_state != LM_ST_UNLOCKED && + demote_ok(gl)) + handle_callback(gl, LM_ST_UNLOCKED); + gfs2_glmutex_unlock(gl); + } + + gfs2_glock_put(gl); +} + +/** + * examine_bucket - Call a function for glock in a hash bucket + * @examiner: the function + * @sdp: the filesystem + * @bucket: the bucket + * + * Returns: 1 if the bucket has entries + */ + +static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, + struct gfs2_gl_hash_bucket *bucket) +{ + struct glock_plug plug; + struct list_head *tmp; + struct gfs2_glock *gl; + int entries; + + /* Add "plug" to end of bucket list, work back up list from there */ + memset(&plug.gl_flags, 0, sizeof(unsigned long)); + set_bit(GLF_PLUG, &plug.gl_flags); + + write_lock(&bucket->hb_lock); + list_add(&plug.gl_list, &bucket->hb_list); + write_unlock(&bucket->hb_lock); + + for (;;) { + write_lock(&bucket->hb_lock); + + for (;;) { + tmp = plug.gl_list.next; + + if (tmp == &bucket->hb_list) { + list_del(&plug.gl_list); + entries = !list_empty(&bucket->hb_list); + write_unlock(&bucket->hb_lock); + return entries; + } + gl = list_entry(tmp, struct gfs2_glock, gl_list); + + /* Move plug up list */ + list_move(&plug.gl_list, &gl->gl_list); + + if (test_bit(GLF_PLUG, &gl->gl_flags)) + continue; + + /* examiner() must glock_put() */ + gfs2_glock_hold(gl); + + break; + } + + write_unlock(&bucket->hb_lock); + + examiner(gl); + } +} + +/** + * scan_glock - look at a glock and see if we can reclaim it + * @gl: the glock to look at + * + */ + +static void scan_glock(struct gfs2_glock *gl) +{ + if (gfs2_glmutex_trylock(gl)) { + if (gl->gl_ops == &gfs2_inode_glops) { + struct gfs2_inode *ip = get_gl2ip(gl); + if (ip && !atomic_read(&ip->i_count)) + goto out_schedule; + } + if (queue_empty(gl, &gl->gl_holders) && + gl->gl_state != LM_ST_UNLOCKED && + demote_ok(gl)) + goto out_schedule; + + gfs2_glmutex_unlock(gl); + } + + gfs2_glock_put(gl); + + return; + + out_schedule: + gfs2_glmutex_unlock(gl); + gfs2_glock_schedule_for_reclaim(gl); + gfs2_glock_put(gl); +} + +/** + * gfs2_scand_internal - Look for glocks and inodes to toss from memory + * @sdp: the filesystem + * + */ + +void gfs2_scand_internal(struct gfs2_sbd *sdp) +{ + unsigned int x; + + for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { + examine_bucket(scan_glock, sdp, &sdp->sd_gl_hash[x]); + cond_resched(); + } +} + +/** + * clear_glock - look at a glock and see if we can free it from glock cache + * @gl: the glock to look at + * + */ + +static void clear_glock(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + int released; + + spin_lock(&sdp->sd_reclaim_lock); + if (!list_empty(&gl->gl_reclaim)) { + list_del_init(&gl->gl_reclaim); + atomic_dec(&sdp->sd_reclaim_count); + released = gfs2_glock_put(gl); + gfs2_assert(sdp, !released); + } + spin_unlock(&sdp->sd_reclaim_lock); + + if (gfs2_glmutex_trylock(gl)) { + if (gl->gl_ops == &gfs2_inode_glops) { + struct gfs2_inode *ip = get_gl2ip(gl); + if (ip && !atomic_read(&ip->i_count)) + gfs2_inode_destroy(ip); + } + if (queue_empty(gl, &gl->gl_holders) && + gl->gl_state != LM_ST_UNLOCKED) + handle_callback(gl, LM_ST_UNLOCKED); + + gfs2_glmutex_unlock(gl); + } + + gfs2_glock_put(gl); +} + +/** + * gfs2_gl_hash_clear - Empty out the glock hash table + * @sdp: the filesystem + * @wait: wait until it's all gone + * + * Called when unmounting the filesystem, or when inter-node lock manager + * requests DROPLOCKS because it is running out of capacity. + */ + +void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait) +{ + unsigned long t; + unsigned int x; + int cont; + + t = jiffies; + + for (;;) { + cont = 0; + + for (x = 0; x < GFS2_GL_HASH_SIZE; x++) + if (examine_bucket(clear_glock, sdp, + &sdp->sd_gl_hash[x])) + cont = 1; + + if (!wait || !cont) + break; + + if (time_after_eq(jiffies, + t + gfs2_tune_get(sdp, gt_stall_secs) * HZ)) { + fs_warn(sdp, "Unmount seems to be stalled. " + "Dumping lock state...\n"); + gfs2_dump_lockstate(sdp); + t = jiffies; + } + + /* invalidate_inodes() requires that the sb inodes list + not change, but an async completion callback for an + unlock can occur which does glock_put() which + can call iput() which will change the sb inodes list. + invalidate_inodes_mutex prevents glock_put()'s during + an invalidate_inodes() */ + + down(&sdp->sd_invalidate_inodes_mutex); + invalidate_inodes(sdp->sd_vfs); + up(&sdp->sd_invalidate_inodes_mutex); + yield(); + } +} + +/* + * Diagnostic routines to help debug distributed deadlock + */ + +/** + * dump_holder - print information about a glock holder + * @str: a string naming the type of holder + * @gh: the glock holder + * + * Returns: 0 on success, -ENOBUFS when we run out of space + */ + +static int dump_holder(char *str, struct gfs2_holder *gh) +{ + unsigned int x; + int error = -ENOBUFS; + + printk(" %s\n", str); + printk(" owner = %ld\n", + (gh->gh_owner) ? (long)gh->gh_owner->pid : -1); + printk(" gh_state = %u\n", gh->gh_state); + printk(" gh_flags ="); + for (x = 0; x < 32; x++) + if (gh->gh_flags & (1 << x)) + printk(" %u", x); + printk(" \n"); + printk(" error = %d\n", gh->gh_error); + printk(" gh_iflags ="); + for (x = 0; x < 32; x++) + if (test_bit(x, &gh->gh_iflags)) + printk(" %u", x); + printk(" \n"); + + error = 0; + + return error; +} + +/** + * dump_inode - print information about an inode + * @ip: the inode + * + * Returns: 0 on success, -ENOBUFS when we run out of space + */ + +static int dump_inode(struct gfs2_inode *ip) +{ + unsigned int x; + int error = -ENOBUFS; + + printk(" Inode:\n"); + printk(" num = %llu %llu\n", + ip->i_num.no_formal_ino, ip->i_num.no_addr); + printk(" type = %u\n", IF2DT(ip->i_di.di_mode)); + printk(" i_count = %d\n", atomic_read(&ip->i_count)); + printk(" i_flags ="); + for (x = 0; x < 32; x++) + if (test_bit(x, &ip->i_flags)) + printk(" %u", x); + printk(" \n"); + printk(" vnode = %s\n", (ip->i_vnode) ? "yes" : "no"); + + error = 0; + + return error; +} + +/** + * dump_glock - print information about a glock + * @gl: the glock + * @count: where we are in the buffer + * + * Returns: 0 on success, -ENOBUFS when we run out of space + */ + +static int dump_glock(struct gfs2_glock *gl) +{ + struct gfs2_holder *gh; + unsigned int x; + int error = -ENOBUFS; + + spin_lock(&gl->gl_spin); + + printk("Glock (%u, %llu)\n", + gl->gl_name.ln_type, + gl->gl_name.ln_number); + printk(" gl_flags ="); + for (x = 0; x < 32; x++) + if (test_bit(x, &gl->gl_flags)) + printk(" %u", x); + printk(" \n"); + printk(" gl_ref = %d\n", atomic_read(&gl->gl_ref.refcount)); + printk(" gl_state = %u\n", gl->gl_state); + printk(" req_gh = %s\n", (gl->gl_req_gh) ? "yes" : "no"); + printk(" req_bh = %s\n", (gl->gl_req_bh) ? "yes" : "no"); + printk(" lvb_count = %d\n", atomic_read(&gl->gl_lvb_count)); + printk(" object = %s\n", (gl->gl_object) ? "yes" : "no"); + printk(" le = %s\n", + (list_empty(&gl->gl_le.le_list)) ? "no" : "yes"); + printk(" reclaim = %s\n", + (list_empty(&gl->gl_reclaim)) ? "no" : "yes"); + if (gl->gl_aspace) + printk(" aspace = %lu\n", + gl->gl_aspace->i_mapping->nrpages); + else + printk(" aspace = no\n"); + printk(" ail = %d\n", atomic_read(&gl->gl_ail_count)); + if (gl->gl_req_gh) { + error = dump_holder("Request", gl->gl_req_gh); + if (error) + goto out; + } + list_for_each_entry(gh, &gl->gl_holders, gh_list) { + error = dump_holder("Holder", gh); + if (error) + goto out; + } + list_for_each_entry(gh, &gl->gl_waiters1, gh_list) { + error = dump_holder("Waiter1", gh); + if (error) + goto out; + } + list_for_each_entry(gh, &gl->gl_waiters2, gh_list) { + error = dump_holder("Waiter2", gh); + if (error) + goto out; + } + list_for_each_entry(gh, &gl->gl_waiters3, gh_list) { + error = dump_holder("Waiter3", gh); + if (error) + goto out; + } + if (gl->gl_ops == &gfs2_inode_glops && get_gl2ip(gl)) { + if (!test_bit(GLF_LOCK, &gl->gl_flags) && + list_empty(&gl->gl_holders)) { + error = dump_inode(get_gl2ip(gl)); + if (error) + goto out; + } else { + error = -ENOBUFS; + printk(" Inode: busy\n"); + } + } + + error = 0; + + out: + spin_unlock(&gl->gl_spin); + + return error; +} + +/** + * gfs2_dump_lockstate - print out the current lockstate + * @sdp: the filesystem + * @ub: the buffer to copy the information into + * + * If @ub is NULL, dump the lockstate to the console. + * + */ + +int gfs2_dump_lockstate(struct gfs2_sbd *sdp) +{ + struct gfs2_gl_hash_bucket *bucket; + struct gfs2_glock *gl; + unsigned int x; + int error = 0; + + for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { + bucket = &sdp->sd_gl_hash[x]; + + read_lock(&bucket->hb_lock); + + list_for_each_entry(gl, &bucket->hb_list, gl_list) { + if (test_bit(GLF_PLUG, &gl->gl_flags)) + continue; + + error = dump_glock(gl); + if (error) + break; + } + + read_unlock(&bucket->hb_lock); + + if (error) + break; + } + + + return error; +} + diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h new file mode 100644 index 000000000000..06847ebebdee --- /dev/null +++ b/fs/gfs2/glock.h @@ -0,0 +1,143 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __GLOCK_DOT_H__ +#define __GLOCK_DOT_H__ + +/* Flags for lock requests; used in gfs2_holder gh_flag field. + From lm_interface.h: +#define LM_FLAG_TRY 0x00000001 +#define LM_FLAG_TRY_1CB 0x00000002 +#define LM_FLAG_NOEXP 0x00000004 +#define LM_FLAG_ANY 0x00000008 +#define LM_FLAG_PRIORITY 0x00000010 */ + +#define GL_LOCAL_EXCL 0x00000020 +#define GL_ASYNC 0x00000040 +#define GL_EXACT 0x00000080 +#define GL_SKIP 0x00000100 +#define GL_ATIME 0x00000200 +#define GL_NOCACHE 0x00000400 +#define GL_SYNC 0x00000800 +#define GL_NOCANCEL 0x00001000 +#define GL_NEVER_RECURSE 0x00002000 + +#define GLR_TRYFAILED 13 +#define GLR_CANCELED 14 + +static inline int gfs2_glock_is_locked_by_me(struct gfs2_glock *gl) +{ + struct gfs2_holder *gh; + int locked = 0; + + /* Look in glock's list of holders for one with current task as owner */ + spin_lock(&gl->gl_spin); + list_for_each_entry(gh, &gl->gl_holders, gh_list) { + if (gh->gh_owner == current) { + locked = 1; + break; + } + } + spin_unlock(&gl->gl_spin); + + return locked; +} + +static inline int gfs2_glock_is_held_excl(struct gfs2_glock *gl) +{ + return (gl->gl_state == LM_ST_EXCLUSIVE); +} + +static inline int gfs2_glock_is_held_dfrd(struct gfs2_glock *gl) +{ + return (gl->gl_state == LM_ST_DEFERRED); +} + +static inline int gfs2_glock_is_held_shrd(struct gfs2_glock *gl) +{ + return (gl->gl_state == LM_ST_SHARED); +} + +static inline int gfs2_glock_is_blocking(struct gfs2_glock *gl) +{ + int ret; + spin_lock(&gl->gl_spin); + ret = !list_empty(&gl->gl_waiters2) || !list_empty(&gl->gl_waiters3); + spin_unlock(&gl->gl_spin); + return ret; +} + +struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, + struct lm_lockname *name); +int gfs2_glock_get(struct gfs2_sbd *sdp, + uint64_t number, struct gfs2_glock_operations *glops, + int create, struct gfs2_glock **glp); +void gfs2_glock_hold(struct gfs2_glock *gl); +int gfs2_glock_put(struct gfs2_glock *gl); + +void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, int flags, + struct gfs2_holder *gh); +void gfs2_holder_reinit(unsigned int state, int flags, struct gfs2_holder *gh); +void gfs2_holder_uninit(struct gfs2_holder *gh); +struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl, unsigned int state, + int flags, gfp_t gfp_flags); +void gfs2_holder_put(struct gfs2_holder *gh); + +void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags); +void gfs2_glock_drop_th(struct gfs2_glock *gl); + +void gfs2_glmutex_lock(struct gfs2_glock *gl); +int gfs2_glmutex_trylock(struct gfs2_glock *gl); +void gfs2_glmutex_unlock(struct gfs2_glock *gl); + +int gfs2_glock_nq(struct gfs2_holder *gh); +int gfs2_glock_poll(struct gfs2_holder *gh); +int gfs2_glock_wait(struct gfs2_holder *gh); +void gfs2_glock_dq(struct gfs2_holder *gh); + +void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, int flags); +void gfs2_glock_force_drop(struct gfs2_glock *gl); + +int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time); + +int gfs2_glock_nq_init(struct gfs2_glock *gl, unsigned int state, int flags, + struct gfs2_holder *gh); +void gfs2_glock_dq_uninit(struct gfs2_holder *gh); +int gfs2_glock_nq_num(struct gfs2_sbd *sdp, + uint64_t number, struct gfs2_glock_operations *glops, + unsigned int state, int flags, struct gfs2_holder *gh); + +int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs); +void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs); +void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs); + +void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number, + struct gfs2_glock_operations *glops, + unsigned int state, int flags); + +/* Lock Value Block functions */ + +int gfs2_lvb_hold(struct gfs2_glock *gl); +void gfs2_lvb_unhold(struct gfs2_glock *gl); +void gfs2_lvb_sync(struct gfs2_glock *gl); + +void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data); + +void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum); +void gfs2_iopen_go_callback(struct gfs2_glock *gl, unsigned int state); + +void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl); +void gfs2_reclaim_glock(struct gfs2_sbd *sdp); + +void gfs2_scand_internal(struct gfs2_sbd *sdp); +void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait); + +int gfs2_dump_lockstate(struct gfs2_sbd *sdp); + +#endif /* __GLOCK_DOT_H__ */ diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c new file mode 100644 index 000000000000..127008146a57 --- /dev/null +++ b/fs/gfs2/glops.c @@ -0,0 +1,487 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "glock.h" +#include "glops.h" +#include "inode.h" +#include "log.h" +#include "meta_io.h" +#include "page.h" +#include "recovery.h" +#include "rgrp.h" + +/** + * meta_go_sync - sync out the metadata for this glock + * @gl: the glock + * @flags: DIO_* + * + * Called when demoting or unlocking an EX glock. We must flush + * to disk all dirty buffers/pages relating to this glock, and must not + * not return to caller to demote/unlock the glock until I/O is complete. + */ + +static void meta_go_sync(struct gfs2_glock *gl, int flags) +{ + if (!(flags & DIO_METADATA)) + return; + + if (test_and_clear_bit(GLF_DIRTY, &gl->gl_flags)) { + gfs2_log_flush_glock(gl); + gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); + if (flags & DIO_RELEASE) + gfs2_ail_empty_gl(gl); + } + + clear_bit(GLF_SYNC, &gl->gl_flags); +} + +/** + * meta_go_inval - invalidate the metadata for this glock + * @gl: the glock + * @flags: + * + */ + +static void meta_go_inval(struct gfs2_glock *gl, int flags) +{ + if (!(flags & DIO_METADATA)) + return; + + gfs2_meta_inval(gl); + gl->gl_vn++; +} + +/** + * meta_go_demote_ok - Check to see if it's ok to unlock a glock + * @gl: the glock + * + * Returns: 1 if we have no cached data; ok to demote meta glock + */ + +static int meta_go_demote_ok(struct gfs2_glock *gl) +{ + return !gl->gl_aspace->i_mapping->nrpages; +} + +/** + * inode_go_xmote_th - promote/demote a glock + * @gl: the glock + * @state: the requested state + * @flags: + * + */ + +static void inode_go_xmote_th(struct gfs2_glock *gl, unsigned int state, + int flags) +{ + if (gl->gl_state != LM_ST_UNLOCKED) + gfs2_pte_inval(gl); + gfs2_glock_xmote_th(gl, state, flags); +} + +/** + * inode_go_xmote_bh - After promoting/demoting a glock + * @gl: the glock + * + */ + +static void inode_go_xmote_bh(struct gfs2_glock *gl) +{ + struct gfs2_holder *gh = gl->gl_req_gh; + struct buffer_head *bh; + int error; + + if (gl->gl_state != LM_ST_UNLOCKED && + (!gh || !(gh->gh_flags & GL_SKIP))) { + error = gfs2_meta_read(gl, gl->gl_name.ln_number, DIO_START, + &bh); + if (!error) + brelse(bh); + } +} + +/** + * inode_go_drop_th - unlock a glock + * @gl: the glock + * + * Invoked from rq_demote(). + * Another node needs the lock in EXCLUSIVE mode, or lock (unused for too long) + * is being purged from our node's glock cache; we're dropping lock. + */ + +static void inode_go_drop_th(struct gfs2_glock *gl) +{ + gfs2_pte_inval(gl); + gfs2_glock_drop_th(gl); +} + +/** + * inode_go_sync - Sync the dirty data and/or metadata for an inode glock + * @gl: the glock protecting the inode + * @flags: + * + */ + +static void inode_go_sync(struct gfs2_glock *gl, int flags) +{ + int meta = (flags & DIO_METADATA); + int data = (flags & DIO_DATA); + + if (test_bit(GLF_DIRTY, &gl->gl_flags)) { + if (meta && data) { + gfs2_page_sync(gl, flags | DIO_START); + gfs2_log_flush_glock(gl); + gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); + gfs2_page_sync(gl, flags | DIO_WAIT); + clear_bit(GLF_DIRTY, &gl->gl_flags); + } else if (meta) { + gfs2_log_flush_glock(gl); + gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); + } else if (data) + gfs2_page_sync(gl, flags | DIO_START | DIO_WAIT); + if (flags & DIO_RELEASE) + gfs2_ail_empty_gl(gl); + } + + clear_bit(GLF_SYNC, &gl->gl_flags); +} + +/** + * inode_go_inval - prepare a inode glock to be released + * @gl: the glock + * @flags: + * + */ + +static void inode_go_inval(struct gfs2_glock *gl, int flags) +{ + int meta = (flags & DIO_METADATA); + int data = (flags & DIO_DATA); + + if (meta) { + gfs2_meta_inval(gl); + gl->gl_vn++; + } + if (data) + gfs2_page_inval(gl); +} + +/** + * inode_go_demote_ok - Check to see if it's ok to unlock an inode glock + * @gl: the glock + * + * Returns: 1 if it's ok + */ + +static int inode_go_demote_ok(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + int demote = 0; + + if (!get_gl2ip(gl) && !gl->gl_aspace->i_mapping->nrpages) + demote = 1; + else if (!sdp->sd_args.ar_localcaching && + time_after_eq(jiffies, gl->gl_stamp + + gfs2_tune_get(sdp, gt_demote_secs) * HZ)) + demote = 1; + + return demote; +} + +/** + * inode_go_lock - operation done after an inode lock is locked by a process + * @gl: the glock + * @flags: + * + * Returns: errno + */ + +static int inode_go_lock(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_inode *ip = get_gl2ip(gl); + int error = 0; + + if (!ip) + return 0; + + if (ip->i_vn != gl->gl_vn) { + error = gfs2_inode_refresh(ip); + if (error) + return error; + gfs2_inode_attr_in(ip); + } + + if ((ip->i_di.di_flags & GFS2_DIF_TRUNC_IN_PROG) && + (gl->gl_state == LM_ST_EXCLUSIVE) && + (gh->gh_flags & GL_LOCAL_EXCL)) + error = gfs2_truncatei_resume(ip); + + return error; +} + +/** + * inode_go_unlock - operation done before an inode lock is unlocked by a + * process + * @gl: the glock + * @flags: + * + */ + +static void inode_go_unlock(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_inode *ip = get_gl2ip(gl); + + if (ip && test_bit(GLF_DIRTY, &gl->gl_flags)) + gfs2_inode_attr_in(ip); + + if (ip) + gfs2_meta_cache_flush(ip); +} + +/** + * inode_greedy - + * @gl: the glock + * + */ + +static void inode_greedy(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_inode *ip = get_gl2ip(gl); + unsigned int quantum = gfs2_tune_get(sdp, gt_greedy_quantum); + unsigned int max = gfs2_tune_get(sdp, gt_greedy_max); + unsigned int new_time; + + spin_lock(&ip->i_spin); + + if (time_after(ip->i_last_pfault + quantum, jiffies)) { + new_time = ip->i_greedy + quantum; + if (new_time > max) + new_time = max; + } else { + new_time = ip->i_greedy - quantum; + if (!new_time || new_time > max) + new_time = 1; + } + + ip->i_greedy = new_time; + + spin_unlock(&ip->i_spin); + + gfs2_inode_put(ip); +} + +/** + * rgrp_go_demote_ok - Check to see if it's ok to unlock a RG's glock + * @gl: the glock + * + * Returns: 1 if it's ok + */ + +static int rgrp_go_demote_ok(struct gfs2_glock *gl) +{ + return !gl->gl_aspace->i_mapping->nrpages; +} + +/** + * rgrp_go_lock - operation done after an rgrp lock is locked by + * a first holder on this node. + * @gl: the glock + * @flags: + * + * Returns: errno + */ + +static int rgrp_go_lock(struct gfs2_holder *gh) +{ + return gfs2_rgrp_bh_get(get_gl2rgd(gh->gh_gl)); +} + +/** + * rgrp_go_unlock - operation done before an rgrp lock is unlocked by + * a last holder on this node. + * @gl: the glock + * @flags: + * + */ + +static void rgrp_go_unlock(struct gfs2_holder *gh) +{ + gfs2_rgrp_bh_put(get_gl2rgd(gh->gh_gl)); +} + +/** + * trans_go_xmote_th - promote/demote the transaction glock + * @gl: the glock + * @state: the requested state + * @flags: + * + */ + +static void trans_go_xmote_th(struct gfs2_glock *gl, unsigned int state, + int flags) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + + if (gl->gl_state != LM_ST_UNLOCKED && + test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { + gfs2_meta_syncfs(sdp); + gfs2_log_shutdown(sdp); + } + + gfs2_glock_xmote_th(gl, state, flags); +} + +/** + * trans_go_xmote_bh - After promoting/demoting the transaction glock + * @gl: the glock + * + */ + +static void trans_go_xmote_bh(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_glock *j_gl = sdp->sd_jdesc->jd_inode->i_gl; + struct gfs2_log_header head; + int error; + + if (gl->gl_state != LM_ST_UNLOCKED && + test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { + gfs2_meta_cache_flush(sdp->sd_jdesc->jd_inode); + j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA); + + error = gfs2_find_jhead(sdp->sd_jdesc, &head); + if (error) + gfs2_consist(sdp); + if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) + gfs2_consist(sdp); + + /* Initialize some head of the log stuff */ + if (!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) { + sdp->sd_log_sequence = head.lh_sequence + 1; + gfs2_log_pointers_init(sdp, head.lh_blkno); + } + } +} + +/** + * trans_go_drop_th - unlock the transaction glock + * @gl: the glock + * + * We want to sync the device even with localcaching. Remember + * that localcaching journal replay only marks buffers dirty. + */ + +static void trans_go_drop_th(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + + if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { + gfs2_meta_syncfs(sdp); + gfs2_log_shutdown(sdp); + } + + gfs2_glock_drop_th(gl); +} + +/** + * quota_go_demote_ok - Check to see if it's ok to unlock a quota glock + * @gl: the glock + * + * Returns: 1 if it's ok + */ + +static int quota_go_demote_ok(struct gfs2_glock *gl) +{ + return !atomic_read(&gl->gl_lvb_count); +} + +struct gfs2_glock_operations gfs2_meta_glops = { + .go_xmote_th = gfs2_glock_xmote_th, + .go_drop_th = gfs2_glock_drop_th, + .go_sync = meta_go_sync, + .go_inval = meta_go_inval, + .go_demote_ok = meta_go_demote_ok, + .go_type = LM_TYPE_META +}; + +struct gfs2_glock_operations gfs2_inode_glops = { + .go_xmote_th = inode_go_xmote_th, + .go_xmote_bh = inode_go_xmote_bh, + .go_drop_th = inode_go_drop_th, + .go_sync = inode_go_sync, + .go_inval = inode_go_inval, + .go_demote_ok = inode_go_demote_ok, + .go_lock = inode_go_lock, + .go_unlock = inode_go_unlock, + .go_greedy = inode_greedy, + .go_type = LM_TYPE_INODE +}; + +struct gfs2_glock_operations gfs2_rgrp_glops = { + .go_xmote_th = gfs2_glock_xmote_th, + .go_drop_th = gfs2_glock_drop_th, + .go_sync = meta_go_sync, + .go_inval = meta_go_inval, + .go_demote_ok = rgrp_go_demote_ok, + .go_lock = rgrp_go_lock, + .go_unlock = rgrp_go_unlock, + .go_type = LM_TYPE_RGRP +}; + +struct gfs2_glock_operations gfs2_trans_glops = { + .go_xmote_th = trans_go_xmote_th, + .go_xmote_bh = trans_go_xmote_bh, + .go_drop_th = trans_go_drop_th, + .go_type = LM_TYPE_NONDISK +}; + +struct gfs2_glock_operations gfs2_iopen_glops = { + .go_xmote_th = gfs2_glock_xmote_th, + .go_drop_th = gfs2_glock_drop_th, + .go_callback = gfs2_iopen_go_callback, + .go_type = LM_TYPE_IOPEN +}; + +struct gfs2_glock_operations gfs2_flock_glops = { + .go_xmote_th = gfs2_glock_xmote_th, + .go_drop_th = gfs2_glock_drop_th, + .go_type = LM_TYPE_FLOCK +}; + +struct gfs2_glock_operations gfs2_nondisk_glops = { + .go_xmote_th = gfs2_glock_xmote_th, + .go_drop_th = gfs2_glock_drop_th, + .go_type = LM_TYPE_NONDISK +}; + +struct gfs2_glock_operations gfs2_quota_glops = { + .go_xmote_th = gfs2_glock_xmote_th, + .go_drop_th = gfs2_glock_drop_th, + .go_demote_ok = quota_go_demote_ok, + .go_type = LM_TYPE_QUOTA +}; + +struct gfs2_glock_operations gfs2_journal_glops = { + .go_xmote_th = gfs2_glock_xmote_th, + .go_drop_th = gfs2_glock_drop_th, + .go_type = LM_TYPE_JOURNAL +}; + diff --git a/fs/gfs2/glops.h b/fs/gfs2/glops.h new file mode 100644 index 000000000000..94f2d264aa64 --- /dev/null +++ b/fs/gfs2/glops.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __GLOPS_DOT_H__ +#define __GLOPS_DOT_H__ + +extern struct gfs2_glock_operations gfs2_meta_glops; +extern struct gfs2_glock_operations gfs2_inode_glops; +extern struct gfs2_glock_operations gfs2_rgrp_glops; +extern struct gfs2_glock_operations gfs2_trans_glops; +extern struct gfs2_glock_operations gfs2_iopen_glops; +extern struct gfs2_glock_operations gfs2_flock_glops; +extern struct gfs2_glock_operations gfs2_nondisk_glops; +extern struct gfs2_glock_operations gfs2_quota_glops; +extern struct gfs2_glock_operations gfs2_journal_glops; + +#endif /* __GLOPS_DOT_H__ */ diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h new file mode 100644 index 000000000000..3ed0a7f26e45 --- /dev/null +++ b/fs/gfs2/incore.h @@ -0,0 +1,703 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __INCORE_DOT_H__ +#define __INCORE_DOT_H__ + +#define DIO_FORCE 0x00000001 +#define DIO_CLEAN 0x00000002 +#define DIO_DIRTY 0x00000004 +#define DIO_START 0x00000008 +#define DIO_WAIT 0x00000010 +#define DIO_METADATA 0x00000020 +#define DIO_DATA 0x00000040 +#define DIO_RELEASE 0x00000080 +#define DIO_ALL 0x00000100 + +struct gfs2_log_operations; +struct gfs2_log_element; +struct gfs2_bitmap; +struct gfs2_rgrpd; +struct gfs2_bufdata; +struct gfs2_databuf; +struct gfs2_glock_operations; +struct gfs2_holder; +struct gfs2_glock; +struct gfs2_alloc; +struct gfs2_inode; +struct gfs2_file; +struct gfs2_revoke; +struct gfs2_revoke_replay; +struct gfs2_unlinked; +struct gfs2_quota_data; +struct gfs2_log_buf; +struct gfs2_trans; +struct gfs2_ail; +struct gfs2_jdesc; +struct gfs2_args; +struct gfs2_tune; +struct gfs2_gl_hash_bucket; +struct gfs2_sbd; + +typedef void (*gfs2_glop_bh_t) (struct gfs2_glock *gl, unsigned int ret); + +/* + * Structure of operations that are associated with each + * type of element in the log. + */ + +struct gfs2_log_operations { + void (*lo_add) (struct gfs2_sbd *sdp, struct gfs2_log_element *le); + void (*lo_incore_commit) (struct gfs2_sbd *sdp, struct gfs2_trans *tr); + void (*lo_before_commit) (struct gfs2_sbd *sdp); + void (*lo_after_commit) (struct gfs2_sbd *sdp, struct gfs2_ail *ai); + void (*lo_before_scan) (struct gfs2_jdesc *jd, + struct gfs2_log_header *head, int pass); + int (*lo_scan_elements) (struct gfs2_jdesc *jd, unsigned int start, + struct gfs2_log_descriptor *ld, __be64 *ptr, + int pass); + void (*lo_after_scan) (struct gfs2_jdesc *jd, int error, int pass); + char *lo_name; +}; + +struct gfs2_log_element { + struct list_head le_list; + struct gfs2_log_operations *le_ops; +}; + +struct gfs2_bitmap { + struct buffer_head *bi_bh; + char *bi_clone; + uint32_t bi_offset; + uint32_t bi_start; + uint32_t bi_len; +}; + +struct gfs2_rgrpd { + struct list_head rd_list; /* Link with superblock */ + struct list_head rd_list_mru; + struct list_head rd_recent; /* Recently used rgrps */ + struct gfs2_glock *rd_gl; /* Glock for this rgrp */ + struct gfs2_rindex rd_ri; + struct gfs2_rgrp rd_rg; + uint64_t rd_rg_vn; + struct gfs2_bitmap *rd_bits; + unsigned int rd_bh_count; + struct semaphore rd_mutex; + uint32_t rd_free_clone; + struct gfs2_log_element rd_le; + uint32_t rd_last_alloc_data; + uint32_t rd_last_alloc_meta; + struct gfs2_sbd *rd_sbd; +}; + +enum gfs2_state_bits { + BH_Pinned = BH_PrivateStart, +}; + +BUFFER_FNS(Pinned, pinned) +TAS_BUFFER_FNS(Pinned, pinned) + +struct gfs2_bufdata { + struct buffer_head *bd_bh; + struct gfs2_glock *bd_gl; + + struct list_head bd_list_tr; + struct gfs2_log_element bd_le; + + struct gfs2_ail *bd_ail; + struct list_head bd_ail_st_list; + struct list_head bd_ail_gl_list; +}; + +struct gfs2_databuf { + struct gfs2_log_element db_le; + struct buffer_head *db_bh; +}; + +struct gfs2_glock_operations { + void (*go_xmote_th) (struct gfs2_glock * gl, unsigned int state, + int flags); + void (*go_xmote_bh) (struct gfs2_glock * gl); + void (*go_drop_th) (struct gfs2_glock * gl); + void (*go_drop_bh) (struct gfs2_glock * gl); + void (*go_sync) (struct gfs2_glock * gl, int flags); + void (*go_inval) (struct gfs2_glock * gl, int flags); + int (*go_demote_ok) (struct gfs2_glock * gl); + int (*go_lock) (struct gfs2_holder * gh); + void (*go_unlock) (struct gfs2_holder * gh); + void (*go_callback) (struct gfs2_glock * gl, unsigned int state); + void (*go_greedy) (struct gfs2_glock * gl); + int go_type; +}; + +enum { + /* Actions */ + HIF_MUTEX = 0, + HIF_PROMOTE = 1, + HIF_DEMOTE = 2, + HIF_GREEDY = 3, + + /* States */ + HIF_ALLOCED = 4, + HIF_DEALLOC = 5, + HIF_HOLDER = 6, + HIF_FIRST = 7, + HIF_RECURSE = 8, + HIF_ABORTED = 9, +}; + +struct gfs2_holder { + struct list_head gh_list; + + struct gfs2_glock *gh_gl; + struct task_struct *gh_owner; + unsigned int gh_state; + int gh_flags; + + int gh_error; + unsigned long gh_iflags; + struct completion gh_wait; +}; + +enum { + GLF_PLUG = 0, + GLF_LOCK = 1, + GLF_STICKY = 2, + GLF_PREFETCH = 3, + GLF_SYNC = 4, + GLF_DIRTY = 5, + GLF_SKIP_WAITERS2 = 6, + GLF_GREEDY = 7, +}; + +struct gfs2_glock { + struct list_head gl_list; + unsigned long gl_flags; /* GLF_... */ + struct lm_lockname gl_name; + struct kref gl_ref; + + spinlock_t gl_spin; + + unsigned int gl_state; + struct list_head gl_holders; + struct list_head gl_waiters1; /* HIF_MUTEX */ + struct list_head gl_waiters2; /* HIF_DEMOTE, HIF_GREEDY */ + struct list_head gl_waiters3; /* HIF_PROMOTE */ + + struct gfs2_glock_operations *gl_ops; + + struct gfs2_holder *gl_req_gh; + gfs2_glop_bh_t gl_req_bh; + + lm_lock_t *gl_lock; + char *gl_lvb; + atomic_t gl_lvb_count; + + uint64_t gl_vn; + unsigned long gl_stamp; + void *gl_object; + + struct gfs2_gl_hash_bucket *gl_bucket; + struct list_head gl_reclaim; + + struct gfs2_sbd *gl_sbd; + + struct inode *gl_aspace; + struct gfs2_log_element gl_le; + struct list_head gl_ail_list; + atomic_t gl_ail_count; +}; + +struct gfs2_alloc { + /* Quota stuff */ + + unsigned int al_qd_num; + struct gfs2_quota_data *al_qd[4]; + struct gfs2_holder al_qd_ghs[4]; + + /* Filled in by the caller to gfs2_inplace_reserve() */ + + uint32_t al_requested; + + /* Filled in by gfs2_inplace_reserve() */ + + char *al_file; + unsigned int al_line; + struct gfs2_holder al_ri_gh; + struct gfs2_holder al_rgd_gh; + struct gfs2_rgrpd *al_rgd; + + /* Filled in by gfs2_alloc_*() */ + + uint32_t al_alloced; +}; + +enum { + GIF_MIN_INIT = 0, + GIF_QD_LOCKED = 1, + GIF_PAGED = 2, + GIF_SW_PAGED = 3, +}; + +struct gfs2_inode { + struct gfs2_inum i_num; + + atomic_t i_count; + unsigned long i_flags; /* GIF_... */ + + uint64_t i_vn; + struct gfs2_dinode i_di; + + struct gfs2_glock *i_gl; + struct gfs2_sbd *i_sbd; + struct inode *i_vnode; + + struct gfs2_holder i_iopen_gh; + + struct gfs2_alloc i_alloc; + uint64_t i_last_rg_alloc; + + spinlock_t i_spin; + struct rw_semaphore i_rw_mutex; + + unsigned int i_greedy; + unsigned long i_last_pfault; + + struct buffer_head *i_cache[GFS2_MAX_META_HEIGHT]; +}; + +enum { + GFF_DID_DIRECT_ALLOC = 0, +}; + +struct gfs2_file { + unsigned long f_flags; /* GFF_... */ + + struct semaphore f_fl_mutex; + struct gfs2_holder f_fl_gh; + + struct gfs2_inode *f_inode; + struct file *f_vfile; +}; + +struct gfs2_revoke { + struct gfs2_log_element rv_le; + uint64_t rv_blkno; +}; + +struct gfs2_revoke_replay { + struct list_head rr_list; + uint64_t rr_blkno; + unsigned int rr_where; +}; + +enum { + ULF_LOCKED = 0, +}; + +struct gfs2_unlinked { + struct list_head ul_list; + unsigned int ul_count; + struct gfs2_unlinked_tag ul_ut; + unsigned long ul_flags; /* ULF_... */ + unsigned int ul_slot; +}; + +enum { + QDF_USER = 0, + QDF_CHANGE = 1, + QDF_LOCKED = 2, +}; + +struct gfs2_quota_data { + struct list_head qd_list; + unsigned int qd_count; + + uint32_t qd_id; + unsigned long qd_flags; /* QDF_... */ + + int64_t qd_change; + int64_t qd_change_sync; + + unsigned int qd_slot; + unsigned int qd_slot_count; + + struct buffer_head *qd_bh; + struct gfs2_quota_change *qd_bh_qc; + unsigned int qd_bh_count; + + struct gfs2_glock *qd_gl; + struct gfs2_quota_lvb qd_qb; + + uint64_t qd_sync_gen; + unsigned long qd_last_warn; + unsigned long qd_last_touched; +}; + +struct gfs2_log_buf { + struct list_head lb_list; + struct buffer_head *lb_bh; + struct buffer_head *lb_real; +}; + +struct gfs2_trans { + char *tr_file; + unsigned int tr_line; + + unsigned int tr_blocks; + unsigned int tr_revokes; + unsigned int tr_reserved; + + struct gfs2_holder *tr_t_gh; + + int tr_touched; + + unsigned int tr_num_buf; + unsigned int tr_num_buf_new; + unsigned int tr_num_buf_rm; + struct list_head tr_list_buf; + + unsigned int tr_num_revoke; + unsigned int tr_num_revoke_rm; +}; + +struct gfs2_ail { + struct list_head ai_list; + + unsigned int ai_first; + struct list_head ai_ail1_list; + struct list_head ai_ail2_list; + + uint64_t ai_sync_gen; +}; + +struct gfs2_jdesc { + struct list_head jd_list; + + struct gfs2_inode *jd_inode; + unsigned int jd_jid; + int jd_dirty; + + unsigned int jd_blocks; +}; + +#define GFS2_GLOCKD_DEFAULT 1 +#define GFS2_GLOCKD_MAX 16 + +#define GFS2_QUOTA_DEFAULT GFS2_QUOTA_OFF +#define GFS2_QUOTA_OFF 0 +#define GFS2_QUOTA_ACCOUNT 1 +#define GFS2_QUOTA_ON 2 + +#define GFS2_DATA_DEFAULT GFS2_DATA_ORDERED +#define GFS2_DATA_WRITEBACK 1 +#define GFS2_DATA_ORDERED 2 + +struct gfs2_args { + char ar_lockproto[GFS2_LOCKNAME_LEN]; /* Name of the Lock Protocol */ + char ar_locktable[GFS2_LOCKNAME_LEN]; /* Name of the Lock Table */ + char ar_hostdata[GFS2_LOCKNAME_LEN]; /* Host specific data */ + int ar_spectator; /* Don't get a journal because we're always RO */ + int ar_ignore_local_fs; /* Don't optimize even if local_fs is 1 */ + int ar_localflocks; /* Let the VFS do flock|fcntl locks for us */ + int ar_localcaching; /* Local-style caching (dangerous on multihost) */ + int ar_debug; /* Oops on errors instead of trying to be graceful */ + int ar_upgrade; /* Upgrade ondisk/multihost format */ + unsigned int ar_num_glockd; /* Number of glockd threads */ + int ar_posix_acl; /* Enable posix acls */ + int ar_quota; /* off/account/on */ + int ar_suiddir; /* suiddir support */ + int ar_data; /* ordered/writeback */ +}; + +struct gfs2_tune { + spinlock_t gt_spin; + + unsigned int gt_ilimit; + unsigned int gt_ilimit_tries; + unsigned int gt_ilimit_min; + unsigned int gt_demote_secs; /* Cache retention for unheld glock */ + unsigned int gt_incore_log_blocks; + unsigned int gt_log_flush_secs; + unsigned int gt_jindex_refresh_secs; /* Check for new journal index */ + + unsigned int gt_scand_secs; + unsigned int gt_recoverd_secs; + unsigned int gt_logd_secs; + unsigned int gt_quotad_secs; + unsigned int gt_inoded_secs; + + unsigned int gt_quota_simul_sync; /* Max quotavals to sync at once */ + unsigned int gt_quota_warn_period; /* Secs between quota warn msgs */ + unsigned int gt_quota_scale_num; /* Numerator */ + unsigned int gt_quota_scale_den; /* Denominator */ + unsigned int gt_quota_cache_secs; + unsigned int gt_quota_quantum; /* Secs between syncs to quota file */ + unsigned int gt_atime_quantum; /* Min secs between atime updates */ + unsigned int gt_new_files_jdata; + unsigned int gt_new_files_directio; + unsigned int gt_max_atomic_write; /* Split big writes into this size */ + unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */ + unsigned int gt_lockdump_size; + unsigned int gt_stall_secs; /* Detects trouble! */ + unsigned int gt_complain_secs; + unsigned int gt_reclaim_limit; /* Max num of glocks in reclaim list */ + unsigned int gt_entries_per_readdir; + unsigned int gt_prefetch_secs; /* Usage window for prefetched glocks */ + unsigned int gt_greedy_default; + unsigned int gt_greedy_quantum; + unsigned int gt_greedy_max; + unsigned int gt_statfs_quantum; + unsigned int gt_statfs_slow; +}; + +struct gfs2_gl_hash_bucket { + rwlock_t hb_lock; + struct list_head hb_list; +}; + +enum { + SDF_JOURNAL_CHECKED = 0, + SDF_JOURNAL_LIVE = 1, + SDF_SHUTDOWN = 2, + SDF_NOATIME = 3, +}; + +#define GFS2_GL_HASH_SHIFT 13 +#define GFS2_GL_HASH_SIZE (1 << GFS2_GL_HASH_SHIFT) +#define GFS2_GL_HASH_MASK (GFS2_GL_HASH_SIZE - 1) +#define GFS2_FSNAME_LEN 256 + +struct gfs2_sbd { + struct super_block *sd_vfs; + struct kobject sd_kobj; + unsigned long sd_flags; /* SDF_... */ + struct gfs2_sb sd_sb; + + /* Constants computed on mount */ + + uint32_t sd_fsb2bb; + uint32_t sd_fsb2bb_shift; + uint32_t sd_diptrs; /* Number of pointers in a dinode */ + uint32_t sd_inptrs; /* Number of pointers in a indirect block */ + uint32_t sd_jbsize; /* Size of a journaled data block */ + uint32_t sd_hash_bsize; /* sizeof(exhash block) */ + uint32_t sd_hash_bsize_shift; + uint32_t sd_hash_ptrs; /* Number of pointers in a hash block */ + uint32_t sd_ut_per_block; + uint32_t sd_qc_per_block; + uint32_t sd_max_dirres; /* Max blocks needed to add a directory entry */ + uint32_t sd_max_height; /* Max height of a file's metadata tree */ + uint64_t sd_heightsize[GFS2_MAX_META_HEIGHT]; + uint32_t sd_max_jheight; /* Max height of journaled file's meta tree */ + uint64_t sd_jheightsize[GFS2_MAX_META_HEIGHT]; + + struct gfs2_args sd_args; /* Mount arguments */ + struct gfs2_tune sd_tune; /* Filesystem tuning structure */ + + /* Lock Stuff */ + + struct lm_lockstruct sd_lockstruct; + struct gfs2_gl_hash_bucket sd_gl_hash[GFS2_GL_HASH_SIZE]; + struct list_head sd_reclaim_list; + spinlock_t sd_reclaim_lock; + wait_queue_head_t sd_reclaim_wq; + atomic_t sd_reclaim_count; + struct gfs2_holder sd_live_gh; + struct gfs2_glock *sd_rename_gl; + struct gfs2_glock *sd_trans_gl; + struct semaphore sd_invalidate_inodes_mutex; + + /* Inode Stuff */ + + struct gfs2_inode *sd_master_dir; + struct gfs2_inode *sd_jindex; + struct gfs2_inode *sd_inum_inode; + struct gfs2_inode *sd_statfs_inode; + struct gfs2_inode *sd_ir_inode; + struct gfs2_inode *sd_sc_inode; + struct gfs2_inode *sd_ut_inode; + struct gfs2_inode *sd_qc_inode; + struct gfs2_inode *sd_rindex; + struct gfs2_inode *sd_quota_inode; + struct gfs2_inode *sd_root_dir; + + /* Inum stuff */ + + struct semaphore sd_inum_mutex; + + /* StatFS stuff */ + + spinlock_t sd_statfs_spin; + struct semaphore sd_statfs_mutex; + struct gfs2_statfs_change sd_statfs_master; + struct gfs2_statfs_change sd_statfs_local; + unsigned long sd_statfs_sync_time; + + /* Resource group stuff */ + + uint64_t sd_rindex_vn; + spinlock_t sd_rindex_spin; + struct semaphore sd_rindex_mutex; + struct list_head sd_rindex_list; + struct list_head sd_rindex_mru_list; + struct list_head sd_rindex_recent_list; + struct gfs2_rgrpd *sd_rindex_forward; + unsigned int sd_rgrps; + + /* Journal index stuff */ + + struct list_head sd_jindex_list; + spinlock_t sd_jindex_spin; + struct semaphore sd_jindex_mutex; + unsigned int sd_journals; + unsigned long sd_jindex_refresh_time; + + struct gfs2_jdesc *sd_jdesc; + struct gfs2_holder sd_journal_gh; + struct gfs2_holder sd_jinode_gh; + + struct gfs2_holder sd_ir_gh; + struct gfs2_holder sd_sc_gh; + struct gfs2_holder sd_ut_gh; + struct gfs2_holder sd_qc_gh; + + /* Daemon stuff */ + + struct task_struct *sd_scand_process; + struct task_struct *sd_recoverd_process; + struct task_struct *sd_logd_process; + struct task_struct *sd_quotad_process; + struct task_struct *sd_inoded_process; + struct task_struct *sd_glockd_process[GFS2_GLOCKD_MAX]; + unsigned int sd_glockd_num; + + /* Unlinked inode stuff */ + + struct list_head sd_unlinked_list; + atomic_t sd_unlinked_count; + spinlock_t sd_unlinked_spin; + struct semaphore sd_unlinked_mutex; + + unsigned int sd_unlinked_slots; + unsigned int sd_unlinked_chunks; + unsigned char **sd_unlinked_bitmap; + + /* Quota stuff */ + + struct list_head sd_quota_list; + atomic_t sd_quota_count; + spinlock_t sd_quota_spin; + struct semaphore sd_quota_mutex; + + unsigned int sd_quota_slots; + unsigned int sd_quota_chunks; + unsigned char **sd_quota_bitmap; + + uint64_t sd_quota_sync_gen; + unsigned long sd_quota_sync_time; + + /* Log stuff */ + + spinlock_t sd_log_lock; + atomic_t sd_log_trans_count; + wait_queue_head_t sd_log_trans_wq; + atomic_t sd_log_flush_count; + wait_queue_head_t sd_log_flush_wq; + + unsigned int sd_log_blks_reserved; + unsigned int sd_log_commited_buf; + unsigned int sd_log_commited_revoke; + + unsigned int sd_log_num_gl; + unsigned int sd_log_num_buf; + unsigned int sd_log_num_revoke; + unsigned int sd_log_num_rg; + unsigned int sd_log_num_databuf; + struct list_head sd_log_le_gl; + struct list_head sd_log_le_buf; + struct list_head sd_log_le_revoke; + struct list_head sd_log_le_rg; + struct list_head sd_log_le_databuf; + + unsigned int sd_log_blks_free; + struct list_head sd_log_blks_list; + wait_queue_head_t sd_log_blks_wait; + + uint64_t sd_log_sequence; + unsigned int sd_log_head; + unsigned int sd_log_tail; + uint64_t sd_log_wraps; + int sd_log_idle; + + unsigned long sd_log_flush_time; + struct semaphore sd_log_flush_lock; + struct list_head sd_log_flush_list; + + unsigned int sd_log_flush_head; + uint64_t sd_log_flush_wrapped; + + struct list_head sd_ail1_list; + struct list_head sd_ail2_list; + uint64_t sd_ail_sync_gen; + + /* Replay stuff */ + + struct list_head sd_revoke_list; + unsigned int sd_replay_tail; + + unsigned int sd_found_blocks; + unsigned int sd_found_revokes; + unsigned int sd_replayed_blocks; + + /* For quiescing the filesystem */ + + struct gfs2_holder sd_freeze_gh; + struct semaphore sd_freeze_lock; + unsigned int sd_freeze_count; + + /* Counters */ + + atomic_t sd_glock_count; + atomic_t sd_glock_held_count; + atomic_t sd_inode_count; + atomic_t sd_bufdata_count; + + atomic_t sd_fh2dentry_misses; + atomic_t sd_reclaimed; + atomic_t sd_log_flush_incore; + atomic_t sd_log_flush_ondisk; + + atomic_t sd_glock_nq_calls; + atomic_t sd_glock_dq_calls; + atomic_t sd_glock_prefetch_calls; + atomic_t sd_lm_lock_calls; + atomic_t sd_lm_unlock_calls; + atomic_t sd_lm_callbacks; + + atomic_t sd_ops_address; + atomic_t sd_ops_dentry; + atomic_t sd_ops_export; + atomic_t sd_ops_file; + atomic_t sd_ops_inode; + atomic_t sd_ops_super; + atomic_t sd_ops_vm; + + char sd_fsname[GFS2_FSNAME_LEN]; + char sd_table_name[GFS2_FSNAME_LEN]; + char sd_proto_name[GFS2_FSNAME_LEN]; + + /* Debugging crud */ + + unsigned long sd_last_warning; +}; + +#endif /* __INCORE_DOT_H__ */ + diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c new file mode 100644 index 000000000000..73922dba5398 --- /dev/null +++ b/fs/gfs2/inode.c @@ -0,0 +1,1805 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "acl.h" +#include "bmap.h" +#include "dir.h" +#include "eattr.h" +#include "glock.h" +#include "glops.h" +#include "inode.h" +#include "log.h" +#include "meta_io.h" +#include "ops_address.h" +#include "ops_file.h" +#include "ops_inode.h" +#include "quota.h" +#include "rgrp.h" +#include "trans.h" +#include "unlinked.h" + +/** + * inode_attr_in - Copy attributes from the dinode into the VFS inode + * @ip: The GFS2 inode (with embedded disk inode data) + * @inode: The Linux VFS inode + * + */ + +static void inode_attr_in(struct gfs2_inode *ip, struct inode *inode) +{ + inode->i_ino = ip->i_num.no_formal_ino; + + switch (ip->i_di.di_mode & S_IFMT) { + case S_IFBLK: + case S_IFCHR: + inode->i_rdev = MKDEV(ip->i_di.di_major, ip->i_di.di_minor); + break; + default: + inode->i_rdev = 0; + break; + }; + + inode->i_mode = ip->i_di.di_mode; + inode->i_nlink = ip->i_di.di_nlink; + inode->i_uid = ip->i_di.di_uid; + inode->i_gid = ip->i_di.di_gid; + i_size_write(inode, ip->i_di.di_size); + inode->i_atime.tv_sec = ip->i_di.di_atime; + inode->i_mtime.tv_sec = ip->i_di.di_mtime; + inode->i_ctime.tv_sec = ip->i_di.di_ctime; + inode->i_atime.tv_nsec = 0; + inode->i_mtime.tv_nsec = 0; + inode->i_ctime.tv_nsec = 0; + inode->i_blksize = PAGE_SIZE; + inode->i_blocks = ip->i_di.di_blocks << + (ip->i_sbd->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT); + + if (ip->i_di.di_flags & GFS2_DIF_IMMUTABLE) + inode->i_flags |= S_IMMUTABLE; + else + inode->i_flags &= ~S_IMMUTABLE; + + if (ip->i_di.di_flags & GFS2_DIF_APPENDONLY) + inode->i_flags |= S_APPEND; + else + inode->i_flags &= ~S_APPEND; +} + +/** + * gfs2_inode_attr_in - Copy attributes from the dinode into the VFS inode + * @ip: The GFS2 inode (with embedded disk inode data) + * + */ + +void gfs2_inode_attr_in(struct gfs2_inode *ip) +{ + struct inode *inode; + + inode = gfs2_ip2v_lookup(ip); + if (inode) { + inode_attr_in(ip, inode); + iput(inode); + } +} + +/** + * gfs2_inode_attr_out - Copy attributes from VFS inode into the dinode + * @ip: The GFS2 inode + * + * Only copy out the attributes that we want the VFS layer + * to be able to modify. + */ + +void gfs2_inode_attr_out(struct gfs2_inode *ip) +{ + struct inode *inode = ip->i_vnode; + + gfs2_assert_withdraw(ip->i_sbd, + (ip->i_di.di_mode & S_IFMT) == (inode->i_mode & S_IFMT)); + ip->i_di.di_mode = inode->i_mode; + ip->i_di.di_uid = inode->i_uid; + ip->i_di.di_gid = inode->i_gid; + ip->i_di.di_atime = inode->i_atime.tv_sec; + ip->i_di.di_mtime = inode->i_mtime.tv_sec; + ip->i_di.di_ctime = inode->i_ctime.tv_sec; +} + +/** + * gfs2_ip2v_lookup - Get the struct inode for a struct gfs2_inode + * @ip: the struct gfs2_inode to get the struct inode for + * + * Returns: A VFS inode, or NULL if none + */ + +struct inode *gfs2_ip2v_lookup(struct gfs2_inode *ip) +{ + struct inode *inode = NULL; + + gfs2_assert_warn(ip->i_sbd, test_bit(GIF_MIN_INIT, &ip->i_flags)); + + spin_lock(&ip->i_spin); + if (ip->i_vnode) + inode = igrab(ip->i_vnode); + spin_unlock(&ip->i_spin); + + return inode; +} + +/** + * gfs2_ip2v - Get/Create a struct inode for a struct gfs2_inode + * @ip: the struct gfs2_inode to get the struct inode for + * + * Returns: A VFS inode, or NULL if no mem + */ + +struct inode *gfs2_ip2v(struct gfs2_inode *ip) +{ + struct inode *inode, *tmp; + + inode = gfs2_ip2v_lookup(ip); + if (inode) + return inode; + + tmp = new_inode(ip->i_sbd->sd_vfs); + if (!tmp) + return NULL; + + inode_attr_in(ip, tmp); + + if (S_ISREG(ip->i_di.di_mode)) { + tmp->i_op = &gfs2_file_iops; + tmp->i_fop = &gfs2_file_fops; + tmp->i_mapping->a_ops = &gfs2_file_aops; + } else if (S_ISDIR(ip->i_di.di_mode)) { + tmp->i_op = &gfs2_dir_iops; + tmp->i_fop = &gfs2_dir_fops; + } else if (S_ISLNK(ip->i_di.di_mode)) { + tmp->i_op = &gfs2_symlink_iops; + } else { + tmp->i_op = &gfs2_dev_iops; + init_special_inode(tmp, tmp->i_mode, tmp->i_rdev); + } + + set_v2ip(tmp, NULL); + + for (;;) { + spin_lock(&ip->i_spin); + if (!ip->i_vnode) + break; + inode = igrab(ip->i_vnode); + spin_unlock(&ip->i_spin); + + if (inode) { + iput(tmp); + return inode; + } + yield(); + } + + inode = tmp; + + gfs2_inode_hold(ip); + ip->i_vnode = inode; + set_v2ip(inode, ip); + + spin_unlock(&ip->i_spin); + + insert_inode_hash(inode); + + return inode; +} + +static int iget_test(struct inode *inode, void *opaque) +{ + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inum *inum = (struct gfs2_inum *)opaque; + + if (ip && ip->i_num.no_addr == inum->no_addr) + return 1; + + return 0; +} + +struct inode *gfs2_iget(struct super_block *sb, struct gfs2_inum *inum) +{ + return ilookup5(sb, (unsigned long)inum->no_formal_ino, + iget_test, inum); +} + +void gfs2_inode_min_init(struct gfs2_inode *ip, unsigned int type) +{ + spin_lock(&ip->i_spin); + if (!test_and_set_bit(GIF_MIN_INIT, &ip->i_flags)) { + ip->i_di.di_nlink = 1; + ip->i_di.di_mode = DT2IF(type); + } + spin_unlock(&ip->i_spin); +} + +/** + * gfs2_inode_refresh - Refresh the incore copy of the dinode + * @ip: The GFS2 inode + * + * Returns: errno + */ + +int gfs2_inode_refresh(struct gfs2_inode *ip) +{ + struct buffer_head *dibh; + int error; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + return error; + + if (gfs2_metatype_check(ip->i_sbd, dibh, GFS2_METATYPE_DI)) { + brelse(dibh); + return -EIO; + } + + spin_lock(&ip->i_spin); + gfs2_dinode_in(&ip->i_di, dibh->b_data); + set_bit(GIF_MIN_INIT, &ip->i_flags); + spin_unlock(&ip->i_spin); + + brelse(dibh); + + if (ip->i_num.no_addr != ip->i_di.di_num.no_addr) { + if (gfs2_consist_inode(ip)) + gfs2_dinode_print(&ip->i_di); + return -EIO; + } + if (ip->i_num.no_formal_ino != ip->i_di.di_num.no_formal_ino) + return -ESTALE; + + ip->i_vn = ip->i_gl->gl_vn; + + return 0; +} + +/** + * inode_create - create a struct gfs2_inode + * @i_gl: The glock covering the inode + * @inum: The inode number + * @io_gl: the iopen glock to acquire/hold (using holder in new gfs2_inode) + * @io_state: the state the iopen glock should be acquired in + * @ipp: pointer to put the returned inode in + * + * Returns: errno + */ + +static int inode_create(struct gfs2_glock *i_gl, struct gfs2_inum *inum, + struct gfs2_glock *io_gl, unsigned int io_state, + struct gfs2_inode **ipp) +{ + struct gfs2_sbd *sdp = i_gl->gl_sbd; + struct gfs2_inode *ip; + int error = 0; + + ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL); + if (!ip) + return -ENOMEM; + memset(ip, 0, sizeof(struct gfs2_inode)); + + ip->i_num = *inum; + + atomic_set(&ip->i_count, 1); + + ip->i_vn = i_gl->gl_vn - 1; + + ip->i_gl = i_gl; + ip->i_sbd = sdp; + + spin_lock_init(&ip->i_spin); + init_rwsem(&ip->i_rw_mutex); + + ip->i_greedy = gfs2_tune_get(sdp, gt_greedy_default); + + error = gfs2_glock_nq_init(io_gl, + io_state, GL_LOCAL_EXCL | GL_EXACT, + &ip->i_iopen_gh); + if (error) + goto fail; + ip->i_iopen_gh.gh_owner = NULL; + + spin_lock(&io_gl->gl_spin); + gfs2_glock_hold(i_gl); + set_gl2gl(io_gl, i_gl); + spin_unlock(&io_gl->gl_spin); + + gfs2_glock_hold(i_gl); + set_gl2ip(i_gl, ip); + + atomic_inc(&sdp->sd_inode_count); + + *ipp = ip; + + return 0; + + fail: + gfs2_meta_cache_flush(ip); + kmem_cache_free(gfs2_inode_cachep, ip); + *ipp = NULL; + + return error; +} + +/** + * gfs2_inode_get - Create or get a reference on an inode + * @i_gl: The glock covering the inode + * @inum: The inode number + * @create: + * @ipp: pointer to put the returned inode in + * + * Returns: errno + */ + +int gfs2_inode_get(struct gfs2_glock *i_gl, struct gfs2_inum *inum, int create, + struct gfs2_inode **ipp) +{ + struct gfs2_sbd *sdp = i_gl->gl_sbd; + struct gfs2_glock *io_gl; + int error = 0; + + gfs2_glmutex_lock(i_gl); + + *ipp = get_gl2ip(i_gl); + if (*ipp) { + error = -ESTALE; + if ((*ipp)->i_num.no_formal_ino != inum->no_formal_ino) + goto out; + atomic_inc(&(*ipp)->i_count); + error = 0; + goto out; + } + + if (!create) + goto out; + + error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_iopen_glops, + CREATE, &io_gl); + if (!error) { + error = inode_create(i_gl, inum, io_gl, LM_ST_SHARED, ipp); + gfs2_glock_put(io_gl); + } + + out: + gfs2_glmutex_unlock(i_gl); + + return error; +} + +void gfs2_inode_hold(struct gfs2_inode *ip) +{ + gfs2_assert(ip->i_sbd, atomic_read(&ip->i_count) > 0); + atomic_inc(&ip->i_count); +} + +void gfs2_inode_put(struct gfs2_inode *ip) +{ + gfs2_assert(ip->i_sbd, atomic_read(&ip->i_count) > 0); + atomic_dec(&ip->i_count); +} + +void gfs2_inode_destroy(struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_glock *io_gl = ip->i_iopen_gh.gh_gl; + struct gfs2_glock *i_gl = ip->i_gl; + + gfs2_assert_warn(sdp, !atomic_read(&ip->i_count)); + gfs2_assert(sdp, get_gl2gl(io_gl) == i_gl); + + spin_lock(&io_gl->gl_spin); + set_gl2gl(io_gl, NULL); + gfs2_glock_put(i_gl); + spin_unlock(&io_gl->gl_spin); + + gfs2_glock_dq_uninit(&ip->i_iopen_gh); + + gfs2_meta_cache_flush(ip); + kmem_cache_free(gfs2_inode_cachep, ip); + + set_gl2ip(i_gl, NULL); + gfs2_glock_put(i_gl); + + atomic_dec(&sdp->sd_inode_count); +} + +static int dinode_dealloc(struct gfs2_inode *ip, struct gfs2_unlinked *ul) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al; + struct gfs2_rgrpd *rgd; + int error; + + if (ip->i_di.di_blocks != 1) { + if (gfs2_consist_inode(ip)) + gfs2_dinode_print(&ip->i_di); + return -EIO; + } + + al = gfs2_alloc_get(ip); + + error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out; + + error = gfs2_rindex_hold(sdp, &al->al_ri_gh); + if (error) + goto out_qs; + + rgd = gfs2_blk2rgrpd(sdp, ip->i_num.no_addr); + if (!rgd) { + gfs2_consist_inode(ip); + error = -EIO; + goto out_rindex_relse; + } + + error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, + &al->al_rgd_gh); + if (error) + goto out_rindex_relse; + + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_UNLINKED + + RES_STATFS + RES_QUOTA, 1); + if (error) + goto out_rg_gunlock; + + gfs2_trans_add_gl(ip->i_gl); + + gfs2_free_di(rgd, ip); + + error = gfs2_unlinked_ondisk_rm(sdp, ul); + + gfs2_trans_end(sdp); + clear_bit(GLF_STICKY, &ip->i_gl->gl_flags); + + out_rg_gunlock: + gfs2_glock_dq_uninit(&al->al_rgd_gh); + + out_rindex_relse: + gfs2_glock_dq_uninit(&al->al_ri_gh); + + out_qs: + gfs2_quota_unhold(ip); + + out: + gfs2_alloc_put(ip); + + return error; +} + +/** + * inode_dealloc - Deallocate all on-disk blocks for an inode (dinode) + * @sdp: the filesystem + * @inum: the inode number to deallocate + * @io_gh: a holder for the iopen glock for this inode + * + * Returns: errno + */ + +static int inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul, + struct gfs2_holder *io_gh) +{ + struct gfs2_inode *ip; + struct gfs2_holder i_gh; + int error; + + error = gfs2_glock_nq_num(sdp, + ul->ul_ut.ut_inum.no_addr, &gfs2_inode_glops, + LM_ST_EXCLUSIVE, 0, &i_gh); + if (error) + return error; + + /* We reacquire the iopen lock here to avoid a race with the NFS server + calling gfs2_read_inode() with the inode number of a inode we're in + the process of deallocating. And we can't keep our hold on the lock + from inode_dealloc_init() for deadlock reasons. */ + + gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY, io_gh); + error = gfs2_glock_nq(io_gh); + switch (error) { + case 0: + break; + case GLR_TRYFAILED: + error = 1; + default: + goto out; + } + + gfs2_assert_warn(sdp, !get_gl2ip(i_gh.gh_gl)); + error = inode_create(i_gh.gh_gl, &ul->ul_ut.ut_inum, io_gh->gh_gl, + LM_ST_EXCLUSIVE, &ip); + + gfs2_glock_dq(io_gh); + + if (error) + goto out; + + error = gfs2_inode_refresh(ip); + if (error) + goto out_iput; + + if (ip->i_di.di_nlink) { + if (gfs2_consist_inode(ip)) + gfs2_dinode_print(&ip->i_di); + error = -EIO; + goto out_iput; + } + + if (S_ISDIR(ip->i_di.di_mode) && + (ip->i_di.di_flags & GFS2_DIF_EXHASH)) { + error = gfs2_dir_exhash_dealloc(ip); + if (error) + goto out_iput; + } + + if (ip->i_di.di_eattr) { + error = gfs2_ea_dealloc(ip); + if (error) + goto out_iput; + } + + if (!gfs2_is_stuffed(ip)) { + error = gfs2_file_dealloc(ip); + if (error) + goto out_iput; + } + + error = dinode_dealloc(ip, ul); + if (error) + goto out_iput; + + out_iput: + gfs2_glmutex_lock(i_gh.gh_gl); + gfs2_inode_put(ip); + gfs2_inode_destroy(ip); + gfs2_glmutex_unlock(i_gh.gh_gl); + + out: + gfs2_glock_dq_uninit(&i_gh); + + return error; +} + +/** + * try_inode_dealloc - Try to deallocate an inode and all its blocks + * @sdp: the filesystem + * + * Returns: 0 on success, -errno on error, 1 on busy (inode open) + */ + +static int try_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) +{ + struct gfs2_holder io_gh; + int error = 0; + + gfs2_try_toss_inode(sdp, &ul->ul_ut.ut_inum); + + error = gfs2_glock_nq_num(sdp, + ul->ul_ut.ut_inum.no_addr, &gfs2_iopen_glops, + LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB, &io_gh); + switch (error) { + case 0: + break; + case GLR_TRYFAILED: + return 1; + default: + return error; + } + + gfs2_glock_dq(&io_gh); + error = inode_dealloc(sdp, ul, &io_gh); + gfs2_holder_uninit(&io_gh); + + return error; +} + +static int inode_dealloc_uninit(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) +{ + struct gfs2_rgrpd *rgd; + struct gfs2_holder ri_gh, rgd_gh; + int error; + + error = gfs2_rindex_hold(sdp, &ri_gh); + if (error) + return error; + + rgd = gfs2_blk2rgrpd(sdp, ul->ul_ut.ut_inum.no_addr); + if (!rgd) { + gfs2_consist(sdp); + error = -EIO; + goto out; + } + + error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &rgd_gh); + if (error) + goto out; + + error = gfs2_trans_begin(sdp, + RES_RG_BIT + RES_UNLINKED + RES_STATFS, + 0); + if (error) + goto out_gunlock; + + gfs2_free_uninit_di(rgd, ul->ul_ut.ut_inum.no_addr); + gfs2_unlinked_ondisk_rm(sdp, ul); + + gfs2_trans_end(sdp); + + out_gunlock: + gfs2_glock_dq_uninit(&rgd_gh); + out: + gfs2_glock_dq_uninit(&ri_gh); + + return error; +} + +int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) +{ + if (ul->ul_ut.ut_flags & GFS2_UTF_UNINIT) + return inode_dealloc_uninit(sdp, ul); + else + return try_inode_dealloc(sdp, ul); +} + +/** + * gfs2_change_nlink - Change nlink count on inode + * @ip: The GFS2 inode + * @diff: The change in the nlink count required + * + * Returns: errno + */ + +int gfs2_change_nlink(struct gfs2_inode *ip, int diff) +{ + struct buffer_head *dibh; + uint32_t nlink; + int error; + + nlink = ip->i_di.di_nlink + diff; + + /* If we are reducing the nlink count, but the new value ends up being + bigger than the old one, we must have underflowed. */ + if (diff < 0 && nlink > ip->i_di.di_nlink) { + if (gfs2_consist_inode(ip)) + gfs2_dinode_print(&ip->i_di); + return -EIO; + } + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + return error; + + ip->i_di.di_nlink = nlink; + ip->i_di.di_ctime = get_seconds(); + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + + return 0; +} + +/** + * gfs2_lookupi - Look up a filename in a directory and return its inode + * @d_gh: An initialized holder for the directory glock + * @name: The name of the inode to look for + * @is_root: If 1, ignore the caller's permissions + * @i_gh: An uninitialized holder for the new inode glock + * + * There will always be a vnode (Linux VFS inode) for the d_gh inode unless + * @is_root is true. + * + * Returns: errno + */ + +int gfs2_lookupi(struct gfs2_inode *dip, struct qstr *name, int is_root, + struct gfs2_inode **ipp) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_holder d_gh; + struct gfs2_inum inum; + unsigned int type; + struct gfs2_glock *gl; + int error; + + if (!name->len || name->len > GFS2_FNAMESIZE) + return -ENAMETOOLONG; + + if (gfs2_filecmp(name, ".", 1) || + (gfs2_filecmp(name, "..", 2) && dip == sdp->sd_root_dir)) { + gfs2_inode_hold(dip); + *ipp = dip; + return 0; + } + + error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); + if (error) + return error; + + if (!is_root) { + error = gfs2_repermission(dip->i_vnode, MAY_EXEC, NULL); + if (error) + goto out; + } + + error = gfs2_dir_search(dip, name, &inum, &type); + if (error) + goto out; + + error = gfs2_glock_get(sdp, inum.no_addr, &gfs2_inode_glops, + CREATE, &gl); + if (error) + goto out; + + error = gfs2_inode_get(gl, &inum, CREATE, ipp); + if (!error) + gfs2_inode_min_init(*ipp, type); + + gfs2_glock_put(gl); + + out: + gfs2_glock_dq_uninit(&d_gh); + + return error; +} + +static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) +{ + struct gfs2_inode *ip = sdp->sd_ir_inode; + struct buffer_head *bh; + struct gfs2_inum_range ir; + int error; + + error = gfs2_trans_begin(sdp, RES_DINODE, 0); + if (error) + return error; + down(&sdp->sd_inum_mutex); + + error = gfs2_meta_inode_buffer(ip, &bh); + if (error) { + up(&sdp->sd_inum_mutex); + gfs2_trans_end(sdp); + return error; + } + + gfs2_inum_range_in(&ir, bh->b_data + sizeof(struct gfs2_dinode)); + + if (ir.ir_length) { + *formal_ino = ir.ir_start++; + ir.ir_length--; + gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_inum_range_out(&ir, + bh->b_data + sizeof(struct gfs2_dinode)); + brelse(bh); + up(&sdp->sd_inum_mutex); + gfs2_trans_end(sdp); + return 0; + } + + brelse(bh); + + up(&sdp->sd_inum_mutex); + gfs2_trans_end(sdp); + + return 1; +} + +static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) +{ + struct gfs2_inode *ip = sdp->sd_ir_inode; + struct gfs2_inode *m_ip = sdp->sd_inum_inode; + struct gfs2_holder gh; + struct buffer_head *bh; + struct gfs2_inum_range ir; + int error; + + error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); + if (error) + return error; + + error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0); + if (error) + goto out; + down(&sdp->sd_inum_mutex); + + error = gfs2_meta_inode_buffer(ip, &bh); + if (error) + goto out_end_trans; + + gfs2_inum_range_in(&ir, bh->b_data + sizeof(struct gfs2_dinode)); + + if (!ir.ir_length) { + struct buffer_head *m_bh; + uint64_t x, y; + + error = gfs2_meta_inode_buffer(m_ip, &m_bh); + if (error) + goto out_brelse; + + x = *(uint64_t *)(m_bh->b_data + sizeof(struct gfs2_dinode)); + x = y = be64_to_cpu(x); + ir.ir_start = x; + ir.ir_length = GFS2_INUM_QUANTUM; + x += GFS2_INUM_QUANTUM; + if (x < y) + gfs2_consist_inode(m_ip); + x = cpu_to_be64(x); + gfs2_trans_add_bh(m_ip->i_gl, m_bh); + *(uint64_t *)(m_bh->b_data + sizeof(struct gfs2_dinode)) = x; + + brelse(m_bh); + } + + *formal_ino = ir.ir_start++; + ir.ir_length--; + + gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_inum_range_out(&ir, bh->b_data + sizeof(struct gfs2_dinode)); + + out_brelse: + brelse(bh); + + out_end_trans: + up(&sdp->sd_inum_mutex); + gfs2_trans_end(sdp); + + out: + gfs2_glock_dq_uninit(&gh); + + return error; +} + +static int pick_formal_ino(struct gfs2_sbd *sdp, uint64_t *inum) +{ + int error; + + error = pick_formal_ino_1(sdp, inum); + if (error <= 0) + return error; + + error = pick_formal_ino_2(sdp, inum); + + return error; +} + +/** + * create_ok - OK to create a new on-disk inode here? + * @dip: Directory in which dinode is to be created + * @name: Name of new dinode + * @mode: + * + * Returns: errno + */ + +static int create_ok(struct gfs2_inode *dip, struct qstr *name, + unsigned int mode) +{ + int error; + + error = gfs2_repermission(dip->i_vnode, MAY_WRITE | MAY_EXEC, NULL); + if (error) + return error; + + /* Don't create entries in an unlinked directory */ + if (!dip->i_di.di_nlink) + return -EPERM; + + error = gfs2_dir_search(dip, name, NULL, NULL); + switch (error) { + case -ENOENT: + error = 0; + break; + case 0: + return -EEXIST; + default: + return error; + } + + if (dip->i_di.di_entries == (uint32_t)-1) + return -EFBIG; + if (S_ISDIR(mode) && dip->i_di.di_nlink == (uint32_t)-1) + return -EMLINK; + + return 0; +} + +static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, + unsigned int *uid, unsigned int *gid) +{ + if (dip->i_sbd->sd_args.ar_suiddir && + (dip->i_di.di_mode & S_ISUID) && + dip->i_di.di_uid) { + if (S_ISDIR(*mode)) + *mode |= S_ISUID; + else if (dip->i_di.di_uid != current->fsuid) + *mode &= ~07111; + *uid = dip->i_di.di_uid; + } else + *uid = current->fsuid; + + if (dip->i_di.di_mode & S_ISGID) { + if (S_ISDIR(*mode)) + *mode |= S_ISGID; + *gid = dip->i_di.di_gid; + } else + *gid = current->fsgid; +} + +static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_unlinked *ul) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + int error; + + gfs2_alloc_get(dip); + + dip->i_alloc.al_requested = RES_DINODE; + error = gfs2_inplace_reserve(dip); + if (error) + goto out; + + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_UNLINKED + + RES_STATFS, 0); + if (error) + goto out_ipreserv; + + ul->ul_ut.ut_inum.no_addr = gfs2_alloc_di(dip); + + ul->ul_ut.ut_flags = GFS2_UTF_UNINIT; + error = gfs2_unlinked_ondisk_add(sdp, ul); + + gfs2_trans_end(sdp); + + out_ipreserv: + gfs2_inplace_release(dip); + + out: + gfs2_alloc_put(dip); + + return error; +} + +/** + * init_dinode - Fill in a new dinode structure + * @dip: the directory this inode is being created in + * @gl: The glock covering the new inode + * @inum: the inode number + * @mode: the file permissions + * @uid: + * @gid: + * + */ + +static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, + struct gfs2_inum *inum, unsigned int mode, + unsigned int uid, unsigned int gid) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_dinode di; + struct buffer_head *dibh; + + dibh = gfs2_meta_new(gl, inum->no_addr); + gfs2_trans_add_bh(gl, dibh); + gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI); + gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); + + memset(&di, 0, sizeof(struct gfs2_dinode)); + gfs2_meta_header_in(&di.di_header, dibh->b_data); + di.di_num = *inum; + di.di_mode = mode; + di.di_uid = uid; + di.di_gid = gid; + di.di_blocks = 1; + di.di_atime = di.di_mtime = di.di_ctime = get_seconds(); + di.di_goal_meta = di.di_goal_data = inum->no_addr; + + if (S_ISREG(mode)) { + if ((dip->i_di.di_flags & GFS2_DIF_INHERIT_JDATA) || + gfs2_tune_get(sdp, gt_new_files_jdata)) + di.di_flags |= GFS2_DIF_JDATA; + if ((dip->i_di.di_flags & GFS2_DIF_INHERIT_DIRECTIO) || + gfs2_tune_get(sdp, gt_new_files_directio)) + di.di_flags |= GFS2_DIF_DIRECTIO; + } else if (S_ISDIR(mode)) { + di.di_flags |= (dip->i_di.di_flags & GFS2_DIF_INHERIT_DIRECTIO); + di.di_flags |= (dip->i_di.di_flags & GFS2_DIF_INHERIT_JDATA); + } + + gfs2_dinode_out(&di, dibh->b_data); + brelse(dibh); +} + +static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, + unsigned int mode, struct gfs2_unlinked *ul) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + unsigned int uid, gid; + int error; + + munge_mode_uid_gid(dip, &mode, &uid, &gid); + + gfs2_alloc_get(dip); + + error = gfs2_quota_lock(dip, uid, gid); + if (error) + goto out; + + error = gfs2_quota_check(dip, uid, gid); + if (error) + goto out_quota; + + error = gfs2_trans_begin(sdp, RES_DINODE + RES_UNLINKED + + RES_QUOTA, 0); + if (error) + goto out_quota; + + ul->ul_ut.ut_flags = 0; + error = gfs2_unlinked_ondisk_munge(sdp, ul); + + init_dinode(dip, gl, &ul->ul_ut.ut_inum, + mode, uid, gid); + + gfs2_quota_change(dip, +1, uid, gid); + + gfs2_trans_end(sdp); + + out_quota: + gfs2_quota_unlock(dip); + + out: + gfs2_alloc_put(dip); + + return error; +} + +static int link_dinode(struct gfs2_inode *dip, struct qstr *name, + struct gfs2_inode *ip, struct gfs2_unlinked *ul) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_alloc *al; + int alloc_required; + struct buffer_head *dibh; + int error; + + al = gfs2_alloc_get(dip); + + error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto fail; + + error = gfs2_diradd_alloc_required(dip, name, &alloc_required); + if (alloc_required) { + error = gfs2_quota_check(dip, dip->i_di.di_uid, + dip->i_di.di_gid); + if (error) + goto fail_quota_locks; + + al->al_requested = sdp->sd_max_dirres; + + error = gfs2_inplace_reserve(dip); + if (error) + goto fail_quota_locks; + + error = gfs2_trans_begin(sdp, + sdp->sd_max_dirres + + al->al_rgd->rd_ri.ri_length + + 2 * RES_DINODE + RES_UNLINKED + + RES_STATFS + RES_QUOTA, 0); + if (error) + goto fail_ipreserv; + } else { + error = gfs2_trans_begin(sdp, + RES_LEAF + + 2 * RES_DINODE + + RES_UNLINKED, 0); + if (error) + goto fail_quota_locks; + } + + error = gfs2_dir_add(dip, name, &ip->i_num, IF2DT(ip->i_di.di_mode)); + if (error) + goto fail_end_trans; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto fail_end_trans; + ip->i_di.di_nlink = 1; + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + + error = gfs2_unlinked_ondisk_rm(sdp, ul); + if (error) + goto fail_end_trans; + + return 0; + + fail_end_trans: + gfs2_trans_end(sdp); + + fail_ipreserv: + if (dip->i_alloc.al_rgd) + gfs2_inplace_release(dip); + + fail_quota_locks: + gfs2_quota_unlock(dip); + + fail: + gfs2_alloc_put(dip); + + return error; +} + +/** + * gfs2_createi - Create a new inode + * @ghs: An array of two holders + * @name: The name of the new file + * @mode: the permissions on the new inode + * + * @ghs[0] is an initialized holder for the directory + * @ghs[1] is the holder for the inode lock + * + * If the return value is 0, the glocks on both the directory and the new + * file are held. A transaction has been started and an inplace reservation + * is held, as well. + * + * Returns: errno + */ + +int gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode) +{ + struct gfs2_inode *dip = get_gl2ip(ghs->gh_gl); + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_unlinked *ul; + struct gfs2_inode *ip; + int error; + + if (!name->len || name->len > GFS2_FNAMESIZE) + return -ENAMETOOLONG; + + error = gfs2_unlinked_get(sdp, &ul); + if (error) + return error; + + gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs); + error = gfs2_glock_nq(ghs); + if (error) + goto fail; + + error = create_ok(dip, name, mode); + if (error) + goto fail_gunlock; + + error = pick_formal_ino(sdp, &ul->ul_ut.ut_inum.no_formal_ino); + if (error) + goto fail_gunlock; + + error = alloc_dinode(dip, ul); + if (error) + goto fail_gunlock; + + if (ul->ul_ut.ut_inum.no_addr < dip->i_num.no_addr) { + gfs2_glock_dq(ghs); + + error = gfs2_glock_nq_num(sdp, + ul->ul_ut.ut_inum.no_addr, + &gfs2_inode_glops, + LM_ST_EXCLUSIVE, GL_SKIP, + ghs + 1); + if (error) { + gfs2_unlinked_put(sdp, ul); + return error; + } + + gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs); + error = gfs2_glock_nq(ghs); + if (error) { + gfs2_glock_dq_uninit(ghs + 1); + gfs2_unlinked_put(sdp, ul); + return error; + } + + error = create_ok(dip, name, mode); + if (error) + goto fail_gunlock2; + } else { + error = gfs2_glock_nq_num(sdp, + ul->ul_ut.ut_inum.no_addr, + &gfs2_inode_glops, + LM_ST_EXCLUSIVE, GL_SKIP, + ghs + 1); + if (error) + goto fail_gunlock; + } + + error = make_dinode(dip, ghs[1].gh_gl, mode, ul); + if (error) + goto fail_gunlock2; + + error = gfs2_inode_get(ghs[1].gh_gl, &ul->ul_ut.ut_inum, CREATE, &ip); + if (error) + goto fail_gunlock2; + + error = gfs2_inode_refresh(ip); + if (error) + goto fail_iput; + + error = gfs2_acl_create(dip, ip); + if (error) + goto fail_iput; + + error = link_dinode(dip, name, ip, ul); + if (error) + goto fail_iput; + + gfs2_unlinked_put(sdp, ul); + + return 0; + + fail_iput: + gfs2_inode_put(ip); + + fail_gunlock2: + gfs2_glock_dq_uninit(ghs + 1); + + fail_gunlock: + gfs2_glock_dq(ghs); + + fail: + gfs2_unlinked_put(sdp, ul); + + return error; +} + +/** + * gfs2_unlinki - Unlink a file + * @dip: The inode of the directory + * @name: The name of the file to be unlinked + * @ip: The inode of the file to be removed + * + * Assumes Glocks on both dip and ip are held. + * + * Returns: errno + */ + +int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name, + struct gfs2_inode *ip, struct gfs2_unlinked *ul) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + int error; + + error = gfs2_dir_del(dip, name); + if (error) + return error; + + error = gfs2_change_nlink(ip, -1); + if (error) + return error; + + /* If this inode is being unlinked from the directory structure, + we need to mark that in the log so that it isn't lost during + a crash. */ + + if (!ip->i_di.di_nlink) { + ul->ul_ut.ut_inum = ip->i_num; + error = gfs2_unlinked_ondisk_add(sdp, ul); + if (!error) + set_bit(GLF_STICKY, &ip->i_gl->gl_flags); + } + + return error; +} + +/** + * gfs2_rmdiri - Remove a directory + * @dip: The parent directory of the directory to be removed + * @name: The name of the directory to be removed + * @ip: The GFS2 inode of the directory to be removed + * + * Assumes Glocks on dip and ip are held + * + * Returns: errno + */ + +int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, + struct gfs2_inode *ip, struct gfs2_unlinked *ul) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct qstr dotname; + int error; + + if (ip->i_di.di_entries != 2) { + if (gfs2_consist_inode(ip)) + gfs2_dinode_print(&ip->i_di); + return -EIO; + } + + error = gfs2_dir_del(dip, name); + if (error) + return error; + + error = gfs2_change_nlink(dip, -1); + if (error) + return error; + + dotname.len = 1; + dotname.name = "."; + error = gfs2_dir_del(ip, &dotname); + if (error) + return error; + + dotname.len = 2; + dotname.name = ".."; + error = gfs2_dir_del(ip, &dotname); + if (error) + return error; + + error = gfs2_change_nlink(ip, -2); + if (error) + return error; + + /* This inode is being unlinked from the directory structure and + we need to mark that in the log so that it isn't lost during + a crash. */ + + ul->ul_ut.ut_inum = ip->i_num; + error = gfs2_unlinked_ondisk_add(sdp, ul); + if (!error) + set_bit(GLF_STICKY, &ip->i_gl->gl_flags); + + return error; +} + +/* + * gfs2_unlink_ok - check to see that a inode is still in a directory + * @dip: the directory + * @name: the name of the file + * @ip: the inode + * + * Assumes that the lock on (at least) @dip is held. + * + * Returns: 0 if the parent/child relationship is correct, errno if it isn't + */ + +int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name, + struct gfs2_inode *ip) +{ + struct gfs2_inum inum; + unsigned int type; + int error; + + if (IS_IMMUTABLE(ip->i_vnode) || IS_APPEND(ip->i_vnode)) + return -EPERM; + + if ((dip->i_di.di_mode & S_ISVTX) && + dip->i_di.di_uid != current->fsuid && + ip->i_di.di_uid != current->fsuid && + !capable(CAP_FOWNER)) + return -EPERM; + + if (IS_APPEND(dip->i_vnode)) + return -EPERM; + + error = gfs2_repermission(dip->i_vnode, MAY_WRITE | MAY_EXEC, NULL); + if (error) + return error; + + error = gfs2_dir_search(dip, name, &inum, &type); + if (error) + return error; + + if (!gfs2_inum_equal(&inum, &ip->i_num)) + return -ENOENT; + + if (IF2DT(ip->i_di.di_mode) != type) { + gfs2_consist_inode(dip); + return -EIO; + } + + return 0; +} + +/* + * gfs2_ok_to_move - check if it's ok to move a directory to another directory + * @this: move this + * @to: to here + * + * Follow @to back to the root and make sure we don't encounter @this + * Assumes we already hold the rename lock. + * + * Returns: errno + */ + +int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) +{ + struct gfs2_sbd *sdp = this->i_sbd; + struct gfs2_inode *tmp; + struct qstr dotdot; + int error = 0; + + memset(&dotdot, 0, sizeof(struct qstr)); + dotdot.name = ".."; + dotdot.len = 2; + + gfs2_inode_hold(to); + + for (;;) { + if (to == this) { + error = -EINVAL; + break; + } + if (to == sdp->sd_root_dir) { + error = 0; + break; + } + + error = gfs2_lookupi(to, &dotdot, 1, &tmp); + if (error) + break; + + gfs2_inode_put(to); + to = tmp; + } + + gfs2_inode_put(to); + + return error; +} + +/** + * gfs2_readlinki - return the contents of a symlink + * @ip: the symlink's inode + * @buf: a pointer to the buffer to be filled + * @len: a pointer to the length of @buf + * + * If @buf is too small, a piece of memory is kmalloc()ed and needs + * to be freed by the caller. + * + * Returns: errno + */ + +int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len) +{ + struct gfs2_holder i_gh; + struct buffer_head *dibh; + unsigned int x; + int error; + + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &i_gh); + error = gfs2_glock_nq_atime(&i_gh); + if (error) { + gfs2_holder_uninit(&i_gh); + return error; + } + + if (!ip->i_di.di_size) { + gfs2_consist_inode(ip); + error = -EIO; + goto out; + } + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto out; + + x = ip->i_di.di_size + 1; + if (x > *len) { + *buf = kmalloc(x, GFP_KERNEL); + if (!*buf) { + error = -ENOMEM; + goto out_brelse; + } + } + + memcpy(*buf, dibh->b_data + sizeof(struct gfs2_dinode), x); + *len = x; + + out_brelse: + brelse(dibh); + + out: + gfs2_glock_dq_uninit(&i_gh); + + return error; +} + +/** + * gfs2_glock_nq_atime - Acquire a hold on an inode's glock, and + * conditionally update the inode's atime + * @gh: the holder to acquire + * + * Tests atime (access time) for gfs2_read, gfs2_readdir and gfs2_mmap + * Update if the difference between the current time and the inode's current + * atime is greater than an interval specified at mount. + * + * Returns: errno + */ + +int gfs2_glock_nq_atime(struct gfs2_holder *gh) +{ + struct gfs2_glock *gl = gh->gh_gl; + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_inode *ip = get_gl2ip(gl); + int64_t curtime, quantum = gfs2_tune_get(sdp, gt_atime_quantum); + unsigned int state; + int flags; + int error; + + if (gfs2_assert_warn(sdp, gh->gh_flags & GL_ATIME) || + gfs2_assert_warn(sdp, !(gh->gh_flags & GL_ASYNC)) || + gfs2_assert_warn(sdp, gl->gl_ops == &gfs2_inode_glops)) + return -EINVAL; + + state = gh->gh_state; + flags = gh->gh_flags; + + error = gfs2_glock_nq(gh); + if (error) + return error; + + if (test_bit(SDF_NOATIME, &sdp->sd_flags) || + (sdp->sd_vfs->s_flags & MS_RDONLY)) + return 0; + + curtime = get_seconds(); + if (curtime - ip->i_di.di_atime >= quantum) { + gfs2_glock_dq(gh); + gfs2_holder_reinit(LM_ST_EXCLUSIVE, + gh->gh_flags & ~LM_FLAG_ANY, + gh); + error = gfs2_glock_nq(gh); + if (error) + return error; + + /* Verify that atime hasn't been updated while we were + trying to get exclusive lock. */ + + curtime = get_seconds(); + if (curtime - ip->i_di.di_atime >= quantum) { + struct buffer_head *dibh; + + error = gfs2_trans_begin(sdp, RES_DINODE, 0); + if (error == -EROFS) + return 0; + if (error) + goto fail; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto fail_end_trans; + + ip->i_di.di_atime = curtime; + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + + gfs2_trans_end(sdp); + } + + /* If someone else has asked for the glock, + unlock and let them have it. Then reacquire + in the original state. */ + if (gfs2_glock_is_blocking(gl)) { + gfs2_glock_dq(gh); + gfs2_holder_reinit(state, flags, gh); + return gfs2_glock_nq(gh); + } + } + + return 0; + + fail_end_trans: + gfs2_trans_end(sdp); + + fail: + gfs2_glock_dq(gh); + + return error; +} + +/** + * glock_compare_atime - Compare two struct gfs2_glock structures for sort + * @arg_a: the first structure + * @arg_b: the second structure + * + * Returns: 1 if A > B + * -1 if A < B + * 0 if A = B + */ + +static int glock_compare_atime(const void *arg_a, const void *arg_b) +{ + struct gfs2_holder *gh_a = *(struct gfs2_holder **)arg_a; + struct gfs2_holder *gh_b = *(struct gfs2_holder **)arg_b; + struct lm_lockname *a = &gh_a->gh_gl->gl_name; + struct lm_lockname *b = &gh_b->gh_gl->gl_name; + int ret = 0; + + if (a->ln_number > b->ln_number) + ret = 1; + else if (a->ln_number < b->ln_number) + ret = -1; + else { + if (gh_a->gh_state == LM_ST_SHARED && + gh_b->gh_state == LM_ST_EXCLUSIVE) + ret = 1; + else if (gh_a->gh_state == LM_ST_SHARED && + (gh_b->gh_flags & GL_ATIME)) + ret = 1; + } + + return ret; +} + +/** + * gfs2_glock_nq_m_atime - acquire multiple glocks where one may need an + * atime update + * @num_gh: the number of structures + * @ghs: an array of struct gfs2_holder structures + * + * Returns: 0 on success (all glocks acquired), + * errno on failure (no glocks acquired) + */ + +int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs) +{ + struct gfs2_holder **p; + unsigned int x; + int error = 0; + + if (!num_gh) + return 0; + + if (num_gh == 1) { + ghs->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC); + if (ghs->gh_flags & GL_ATIME) + error = gfs2_glock_nq_atime(ghs); + else + error = gfs2_glock_nq(ghs); + return error; + } + + p = kcalloc(num_gh, sizeof(struct gfs2_holder *), GFP_KERNEL); + if (!p) + return -ENOMEM; + + for (x = 0; x < num_gh; x++) + p[x] = &ghs[x]; + + sort(p, num_gh, sizeof(struct gfs2_holder *), glock_compare_atime,NULL); + + for (x = 0; x < num_gh; x++) { + p[x]->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC); + + if (p[x]->gh_flags & GL_ATIME) + error = gfs2_glock_nq_atime(p[x]); + else + error = gfs2_glock_nq(p[x]); + + if (error) { + while (x--) + gfs2_glock_dq(p[x]); + break; + } + } + + kfree(p); + + return error; +} + +/** + * gfs2_try_toss_vnode - See if we can toss a vnode from memory + * @ip: the inode + * + * Returns: 1 if the vnode was tossed + */ + +void gfs2_try_toss_vnode(struct gfs2_inode *ip) +{ + struct inode *inode; + + inode = gfs2_ip2v_lookup(ip); + if (!inode) + return; + + d_prune_aliases(inode); + + if (S_ISDIR(ip->i_di.di_mode)) { + struct list_head *head = &inode->i_dentry; + struct dentry *d = NULL; + + spin_lock(&dcache_lock); + if (list_empty(head)) + spin_unlock(&dcache_lock); + else { + d = list_entry(head->next, struct dentry, d_alias); + dget_locked(d); + spin_unlock(&dcache_lock); + + if (have_submounts(d)) + dput(d); + else { + shrink_dcache_parent(d); + dput(d); + d_prune_aliases(inode); + } + } + } + + inode->i_nlink = 0; + iput(inode); +} + + +static int +__gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) +{ + struct buffer_head *dibh; + int error; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + error = inode_setattr(ip->i_vnode, attr); + gfs2_assert_warn(ip->i_sbd, !error); + gfs2_inode_attr_out(ip); + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + return error; +} + +/** + * gfs2_setattr_simple - + * @ip: + * @attr: + * + * Called with a reference on the vnode. + * + * Returns: errno + */ + +int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) +{ + int error; + + if (get_transaction) + return __gfs2_setattr_simple(ip, attr); + + error = gfs2_trans_begin(ip->i_sbd, RES_DINODE, 0); + if (error) + return error; + + error = __gfs2_setattr_simple(ip, attr); + + gfs2_trans_end(ip->i_sbd); + + return error; +} + +int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd) +{ + return permission(inode, mask, nd); +} + diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h new file mode 100644 index 000000000000..4df7da51f715 --- /dev/null +++ b/fs/gfs2/inode.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __INODE_DOT_H__ +#define __INODE_DOT_H__ + +static inline int gfs2_is_stuffed(struct gfs2_inode *ip) +{ + return !ip->i_di.di_height; +} + +static inline int gfs2_is_jdata(struct gfs2_inode *ip) +{ + return ip->i_di.di_flags & GFS2_DIF_JDATA; +} + +void gfs2_inode_attr_in(struct gfs2_inode *ip); +void gfs2_inode_attr_out(struct gfs2_inode *ip); +struct inode *gfs2_ip2v_lookup(struct gfs2_inode *ip); +struct inode *gfs2_ip2v(struct gfs2_inode *ip); +struct inode *gfs2_iget(struct super_block *sb, struct gfs2_inum *inum); + +void gfs2_inode_min_init(struct gfs2_inode *ip, unsigned int type); +int gfs2_inode_refresh(struct gfs2_inode *ip); + +int gfs2_inode_get(struct gfs2_glock *i_gl, + struct gfs2_inum *inum, int create, + struct gfs2_inode **ipp); +void gfs2_inode_hold(struct gfs2_inode *ip); +void gfs2_inode_put(struct gfs2_inode *ip); +void gfs2_inode_destroy(struct gfs2_inode *ip); + +int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); + +int gfs2_change_nlink(struct gfs2_inode *ip, int diff); +int gfs2_lookupi(struct gfs2_inode *dip, struct qstr *name, int is_root, + struct gfs2_inode **ipp); +int gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode); +int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name, + struct gfs2_inode *ip, struct gfs2_unlinked *ul); +int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, + struct gfs2_inode *ip, struct gfs2_unlinked *ul); +int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name, + struct gfs2_inode *ip); +int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to); +int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len); + +int gfs2_glock_nq_atime(struct gfs2_holder *gh); +int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs); + +void gfs2_try_toss_vnode(struct gfs2_inode *ip); + +int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr); + +int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd); + +static inline int gfs2_lookup_simple(struct gfs2_inode *dip, char *name, + struct gfs2_inode **ipp) +{ + struct qstr qstr; + memset(&qstr, 0, sizeof(struct qstr)); + qstr.name = name; + qstr.len = strlen(name); + return gfs2_lookupi(dip, &qstr, 1, ipp); +} + +#endif /* __INODE_DOT_H__ */ + diff --git a/fs/gfs2/jdata.c b/fs/gfs2/jdata.c new file mode 100644 index 000000000000..d4adbf171ed3 --- /dev/null +++ b/fs/gfs2/jdata.c @@ -0,0 +1,382 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "inode.h" +#include "jdata.h" +#include "meta_io.h" +#include "trans.h" + +int gfs2_jdata_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, + struct buffer_head **bhp) +{ + struct buffer_head *bh; + int error = 0; + + if (new) { + bh = gfs2_meta_new(ip->i_gl, block); + gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_metatype_set(bh, GFS2_METATYPE_JD, GFS2_FORMAT_JD); + gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); + } else { + error = gfs2_meta_read(ip->i_gl, block, + DIO_START | DIO_WAIT, &bh); + if (error) + return error; + if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_JD)) { + brelse(bh); + return -EIO; + } + } + + *bhp = bh; + + return 0; +} + +/** + * gfs2_copy2mem - Trivial copy function for gfs2_jdata_read() + * @bh: The buffer to copy from, or NULL meaning zero the buffer + * @buf: The buffer to copy/zero + * @offset: The offset in the buffer to copy from + * @size: The amount of data to copy/zero + * + * Returns: errno + */ + +int gfs2_copy2mem(struct buffer_head *bh, char **buf, unsigned int offset, + unsigned int size) +{ + if (bh) + memcpy(*buf, bh->b_data + offset, size); + else + memset(*buf, 0, size); + *buf += size; + return 0; +} + +/** + * gfs2_copy2user - Copy bytes to user space for gfs2_jdata_read() + * @bh: The buffer + * @buf: The destination of the data + * @offset: The offset into the buffer + * @size: The amount of data to copy + * + * Returns: errno + */ + +int gfs2_copy2user(struct buffer_head *bh, char **buf, unsigned int offset, + unsigned int size) +{ + int error; + + if (bh) + error = copy_to_user(*buf, bh->b_data + offset, size); + else + error = clear_user(*buf, size); + + if (error) + error = -EFAULT; + else + *buf += size; + + return error; +} + +static int jdata_read_stuffed(struct gfs2_inode *ip, char *buf, + unsigned int offset, unsigned int size, + read_copy_fn_t copy_fn) +{ + struct buffer_head *dibh; + int error; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + error = copy_fn(dibh, &buf, + offset + sizeof(struct gfs2_dinode), size); + brelse(dibh); + } + + return (error) ? error : size; +} + +/** + * gfs2_jdata_read - Read a jdata file + * @ip: The GFS2 Inode + * @buf: The buffer to place result into + * @offset: File offset to begin jdata_readng from + * @size: Amount of data to transfer + * @copy_fn: Function to actually perform the copy + * + * The @copy_fn only copies a maximum of a single block at once so + * we are safe calling it with int arguments. It is done so that + * we don't needlessly put 64bit arguments on the stack and it + * also makes the code in the @copy_fn nicer too. + * + * Returns: The amount of data actually copied or the error + */ + +int gfs2_jdata_read(struct gfs2_inode *ip, char __user *buf, uint64_t offset, + unsigned int size, read_copy_fn_t copy_fn) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + uint64_t lblock, dblock; + uint32_t extlen = 0; + unsigned int o; + int copied = 0; + int error = 0; + + if (offset >= ip->i_di.di_size) + return 0; + + if ((offset + size) > ip->i_di.di_size) + size = ip->i_di.di_size - offset; + + if (!size) + return 0; + + if (gfs2_is_stuffed(ip)) + return jdata_read_stuffed(ip, buf, (unsigned int)offset, size, + copy_fn); + + if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) + return -EINVAL; + + lblock = offset; + o = do_div(lblock, sdp->sd_jbsize) + + sizeof(struct gfs2_meta_header); + + while (copied < size) { + unsigned int amount; + struct buffer_head *bh; + int new; + + amount = size - copied; + if (amount > sdp->sd_sb.sb_bsize - o) + amount = sdp->sd_sb.sb_bsize - o; + + if (!extlen) { + new = 0; + error = gfs2_block_map(ip, lblock, &new, + &dblock, &extlen); + if (error) + goto fail; + } + + if (extlen > 1) + gfs2_meta_ra(ip->i_gl, dblock, extlen); + + if (dblock) { + error = gfs2_jdata_get_buffer(ip, dblock, new, &bh); + if (error) + goto fail; + dblock++; + extlen--; + } else + bh = NULL; + + error = copy_fn(bh, &buf, o, amount); + brelse(bh); + if (error) + goto fail; + + copied += amount; + lblock++; + + o = sizeof(struct gfs2_meta_header); + } + + return copied; + + fail: + return (copied) ? copied : error; +} + +/** + * gfs2_copy_from_mem - Trivial copy function for gfs2_jdata_write() + * @bh: The buffer to copy to or clear + * @buf: The buffer to copy from + * @offset: The offset in the buffer to write to + * @size: The amount of data to write + * + * Returns: errno + */ + +int gfs2_copy_from_mem(struct gfs2_inode *ip, struct buffer_head *bh, + const char **buf, unsigned int offset, unsigned int size) +{ + gfs2_trans_add_bh(ip->i_gl, bh); + memcpy(bh->b_data + offset, *buf, size); + + *buf += size; + + return 0; +} + +/** + * gfs2_copy_from_user - Copy bytes from user space for gfs2_jdata_write() + * @bh: The buffer to copy to or clear + * @buf: The buffer to copy from + * @offset: The offset in the buffer to write to + * @size: The amount of data to write + * + * Returns: errno + */ + +int gfs2_copy_from_user(struct gfs2_inode *ip, struct buffer_head *bh, + const char __user **buf, unsigned int offset, unsigned int size) +{ + int error = 0; + + gfs2_trans_add_bh(ip->i_gl, bh); + if (copy_from_user(bh->b_data + offset, *buf, size)) + error = -EFAULT; + else + *buf += size; + + return error; +} + +static int jdata_write_stuffed(struct gfs2_inode *ip, char *buf, + unsigned int offset, unsigned int size, + write_copy_fn_t copy_fn) +{ + struct buffer_head *dibh; + int error; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + return error; + + error = copy_fn(ip, + dibh, &buf, + offset + sizeof(struct gfs2_dinode), size); + if (!error) { + if (ip->i_di.di_size < offset + size) + ip->i_di.di_size = offset + size; + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + } + + brelse(dibh); + + return (error) ? error : size; +} + +/** + * gfs2_jdata_write - Write bytes to a file + * @ip: The GFS2 inode + * @buf: The buffer containing information to be written + * @offset: The file offset to start writing at + * @size: The amount of data to write + * @copy_fn: Function to do the actual copying + * + * Returns: The number of bytes correctly written or error code + */ + +int gfs2_jdata_write(struct gfs2_inode *ip, const char __user *buf, uint64_t offset, + unsigned int size, write_copy_fn_t copy_fn) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head *dibh; + uint64_t lblock, dblock; + uint32_t extlen = 0; + unsigned int o; + int copied = 0; + int error = 0; + + if (!size) + return 0; + + if (gfs2_is_stuffed(ip) && + offset + size <= sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) + return jdata_write_stuffed(ip, buf, (unsigned int)offset, size, + copy_fn); + + if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) + return -EINVAL; + + if (gfs2_is_stuffed(ip)) { + error = gfs2_unstuff_dinode(ip, NULL, NULL); + if (error) + return error; + } + + lblock = offset; + o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header); + + while (copied < size) { + unsigned int amount; + struct buffer_head *bh; + int new; + + amount = size - copied; + if (amount > sdp->sd_sb.sb_bsize - o) + amount = sdp->sd_sb.sb_bsize - o; + + if (!extlen) { + new = 1; + error = gfs2_block_map(ip, lblock, &new, + &dblock, &extlen); + if (error) + goto fail; + error = -EIO; + if (gfs2_assert_withdraw(sdp, dblock)) + goto fail; + } + + error = gfs2_jdata_get_buffer(ip, dblock, + (amount == sdp->sd_jbsize) ? 1 : new, + &bh); + if (error) + goto fail; + + error = copy_fn(ip, bh, &buf, o, amount); + brelse(bh); + if (error) + goto fail; + + copied += amount; + lblock++; + dblock++; + extlen--; + + o = sizeof(struct gfs2_meta_header); + } + + out: + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + return error; + + if (ip->i_di.di_size < offset + copied) + ip->i_di.di_size = offset + copied; + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + + return copied; + + fail: + if (copied) + goto out; + return error; +} + diff --git a/fs/gfs2/jdata.h b/fs/gfs2/jdata.h new file mode 100644 index 000000000000..95e18fcb8f82 --- /dev/null +++ b/fs/gfs2/jdata.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __FILE_DOT_H__ +#define __FILE_DOT_H__ + +int gfs2_jdata_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, + struct buffer_head **bhp); + +typedef int (*read_copy_fn_t) (struct buffer_head *bh, char **buf, + unsigned int offset, unsigned int size); +typedef int (*write_copy_fn_t) (struct gfs2_inode *ip, + struct buffer_head *bh, const char **buf, + unsigned int offset, unsigned int size); + +int gfs2_copy2mem(struct buffer_head *bh, char **buf, + unsigned int offset, unsigned int size); +int gfs2_copy2user(struct buffer_head *bh, char __user **buf, + unsigned int offset, unsigned int size); +int gfs2_jdata_read(struct gfs2_inode *ip, char __user *buf, + uint64_t offset, unsigned int size, + read_copy_fn_t copy_fn); + +int gfs2_copy_from_mem(struct gfs2_inode *ip, + struct buffer_head *bh, const char **buf, + unsigned int offset, unsigned int size); +int gfs2_copy_from_user(struct gfs2_inode *ip, + struct buffer_head *bh, const char __user **buf, + unsigned int offset, unsigned int size); +int gfs2_jdata_write(struct gfs2_inode *ip, const char __user *buf, + uint64_t offset, unsigned int size, + write_copy_fn_t copy_fn); + +static inline int gfs2_jdata_read_mem(struct gfs2_inode *ip, char *buf, + uint64_t offset, unsigned int size) +{ + return gfs2_jdata_read(ip, (__force char __user *)buf, offset, size, gfs2_copy2mem); +} + +static inline int gfs2_jdata_write_mem(struct gfs2_inode *ip, const char *buf, + uint64_t offset, unsigned int size) +{ + return gfs2_jdata_write(ip, (__force const char __user *)buf, offset, size, gfs2_copy_from_mem); +} + +#endif /* __FILE_DOT_H__ */ diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c new file mode 100644 index 000000000000..cc7442261b2e --- /dev/null +++ b/fs/gfs2/lm.c @@ -0,0 +1,235 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "glock.h" +#include "lm.h" +#include "super.h" + +/** + * gfs2_lm_mount - mount a locking protocol + * @sdp: the filesystem + * @args: mount arguements + * @silent: if 1, don't complain if the FS isn't a GFS2 fs + * + * Returns: errno + */ + +int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent) +{ + char *proto = sdp->sd_proto_name; + char *table = sdp->sd_table_name; + int flags = 0; + int error; + + if (sdp->sd_args.ar_spectator) + flags |= LM_MFLAG_SPECTATOR; + + fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table); + + error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata, + gfs2_glock_cb, sdp, + GFS2_MIN_LVB_SIZE, flags, + &sdp->sd_lockstruct, &sdp->sd_kobj); + if (error) { + fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n", + proto, table, sdp->sd_args.ar_hostdata); + goto out; + } + + if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lockspace) || + gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) || + gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >= + GFS2_MIN_LVB_SIZE)) { + gfs2_unmount_lockproto(&sdp->sd_lockstruct); + goto out; + } + + if (sdp->sd_args.ar_spectator) + snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table); + else + snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table, + sdp->sd_lockstruct.ls_jid); + + fs_info(sdp, "Joined cluster. Now mounting FS...\n"); + + if ((sdp->sd_lockstruct.ls_flags & LM_LSFLAG_LOCAL) && + !sdp->sd_args.ar_ignore_local_fs) { + sdp->sd_args.ar_localflocks = 1; + sdp->sd_args.ar_localcaching = 1; + } + + out: + return error; +} + +void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp) +{ + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + sdp->sd_lockstruct.ls_ops->lm_others_may_mount(sdp->sd_lockstruct.ls_lockspace); +} + +void gfs2_lm_unmount(struct gfs2_sbd *sdp) +{ + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + gfs2_unmount_lockproto(&sdp->sd_lockstruct); +} + +int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) +{ + va_list args; + + if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags)) + return 0; + + va_start(args, fmt); + vprintk(fmt, args); + va_end(args); + + fs_err(sdp, "about to withdraw from the cluster\n"); + if (sdp->sd_args.ar_debug) + BUG(); + + fs_err(sdp, "waiting for outstanding I/O\n"); + + /* FIXME: suspend dm device so oustanding bio's complete + and all further io requests fail */ + + fs_err(sdp, "telling LM to withdraw\n"); + gfs2_withdraw_lockproto(&sdp->sd_lockstruct); + fs_err(sdp, "withdrawn\n"); + dump_stack(); + + return -1; +} + +int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, + lm_lock_t **lockp) +{ + int error; + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + error = -EIO; + else + error = sdp->sd_lockstruct.ls_ops->lm_get_lock(sdp->sd_lockstruct.ls_lockspace, name, lockp); + return error; +} + +void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock) +{ + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + sdp->sd_lockstruct.ls_ops->lm_put_lock(lock); +} + +unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, + unsigned int cur_state, unsigned int req_state, + unsigned int flags) +{ + int ret; + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + ret = 0; + else + ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, + cur_state, + req_state, flags); + return ret; +} + +unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, + unsigned int cur_state) +{ + int ret; + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + ret = 0; + else + ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state); + return ret; +} + +void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock) +{ + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + sdp->sd_lockstruct.ls_ops->lm_cancel(lock); +} + +int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp) +{ + int error; + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + error = -EIO; + else + error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp); + return error; +} + +void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) +{ + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb); +} + +void gfs2_lm_sync_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) +{ + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + sdp->sd_lockstruct.ls_ops->lm_sync_lvb(lock, lvb); +} + +int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, + struct file *file, struct file_lock *fl) +{ + int error; + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + error = -EIO; + else + error = sdp->sd_lockstruct.ls_ops->lm_plock_get( + sdp->sd_lockstruct.ls_lockspace, + name, file, fl); + return error; +} + +int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name, + struct file *file, int cmd, struct file_lock *fl) +{ + int error; + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + error = -EIO; + else + error = sdp->sd_lockstruct.ls_ops->lm_plock( + sdp->sd_lockstruct.ls_lockspace, + name, file, cmd, fl); + return error; +} + +int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name, + struct file *file, struct file_lock *fl) +{ + int error; + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + error = -EIO; + else + error = sdp->sd_lockstruct.ls_ops->lm_punlock( + sdp->sd_lockstruct.ls_lockspace, + name, file, fl); + return error; +} + +void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid, + unsigned int message) +{ + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + sdp->sd_lockstruct.ls_ops->lm_recovery_done(sdp->sd_lockstruct.ls_lockspace, jid, message); +} + diff --git a/fs/gfs2/lm.h b/fs/gfs2/lm.h new file mode 100644 index 000000000000..ec812424fdec --- /dev/null +++ b/fs/gfs2/lm.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __LM_DOT_H__ +#define __LM_DOT_H__ + +int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent); +void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp); +void gfs2_lm_unmount(struct gfs2_sbd *sdp); +int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) +__attribute__ ((format(printf, 2, 3))); +int gfs2_lm_get_lock(struct gfs2_sbd *sdp, + struct lm_lockname *name, lm_lock_t **lockp); +void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock); +unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, + unsigned int cur_state, unsigned int req_state, + unsigned int flags); +unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, + unsigned int cur_state); +void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock); +int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp); +void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb); +void gfs2_lm_sync_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb); +int gfs2_lm_plock_get(struct gfs2_sbd *sdp, + struct lm_lockname *name, + struct file *file, struct file_lock *fl); +int gfs2_lm_plock(struct gfs2_sbd *sdp, + struct lm_lockname *name, + struct file *file, int cmd, struct file_lock *fl); +int gfs2_lm_punlock(struct gfs2_sbd *sdp, + struct lm_lockname *name, + struct file *file, struct file_lock *fl); +void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, + unsigned int jid, unsigned int message); + +#endif /* __LM_DOT_H__ */ diff --git a/fs/gfs2/lm_interface.h b/fs/gfs2/lm_interface.h new file mode 100644 index 000000000000..378432f17f27 --- /dev/null +++ b/fs/gfs2/lm_interface.h @@ -0,0 +1,295 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __LM_INTERFACE_DOT_H__ +#define __LM_INTERFACE_DOT_H__ + +/* + * Opaque handles represent the lock module's lockspace structure, the lock + * module's lock structures, and GFS's file system (superblock) structure. + */ + +typedef void lm_lockspace_t; +typedef void lm_lock_t; +typedef void lm_fsdata_t; + +typedef void (*lm_callback_t) (lm_fsdata_t *fsdata, unsigned int type, + void *data); + +/* + * lm_mount() flags + * + * LM_MFLAG_SPECTATOR + * GFS is asking to join the filesystem's lockspace, but it doesn't want to + * modify the filesystem. The lock module shouldn't assign a journal to the FS + * mount. It shouldn't send recovery callbacks to the FS mount. If the node + * dies or withdraws, all locks can be wiped immediately. + */ + +#define LM_MFLAG_SPECTATOR 0x00000001 + +/* + * lm_lockstruct flags + * + * LM_LSFLAG_LOCAL + * The lock_nolock module returns LM_LSFLAG_LOCAL to GFS, indicating that GFS + * can make single-node optimizations. + */ + +#define LM_LSFLAG_LOCAL 0x00000001 + +/* + * lm_lockname types + */ + +#define LM_TYPE_RESERVED 0x00 +#define LM_TYPE_NONDISK 0x01 +#define LM_TYPE_INODE 0x02 +#define LM_TYPE_RGRP 0x03 +#define LM_TYPE_META 0x04 +#define LM_TYPE_IOPEN 0x05 +#define LM_TYPE_FLOCK 0x06 +#define LM_TYPE_PLOCK 0x07 +#define LM_TYPE_QUOTA 0x08 +#define LM_TYPE_JOURNAL 0x09 + +/* + * lm_lock() states + * + * SHARED is compatible with SHARED, not with DEFERRED or EX. + * DEFERRED is compatible with DEFERRED, not with SHARED or EX. + */ + +#define LM_ST_UNLOCKED 0 +#define LM_ST_EXCLUSIVE 1 +#define LM_ST_DEFERRED 2 +#define LM_ST_SHARED 3 + +/* + * lm_lock() flags + * + * LM_FLAG_TRY + * Don't wait to acquire the lock if it can't be granted immediately. + * + * LM_FLAG_TRY_1CB + * Send one blocking callback if TRY is set and the lock is not granted. + * + * LM_FLAG_NOEXP + * GFS sets this flag on lock requests it makes while doing journal recovery. + * These special requests should not be blocked due to the recovery like + * ordinary locks would be. + * + * LM_FLAG_ANY + * A SHARED request may also be granted in DEFERRED, or a DEFERRED request may + * also be granted in SHARED. The preferred state is whichever is compatible + * with other granted locks, or the specified state if no other locks exist. + * + * LM_FLAG_PRIORITY + * Override fairness considerations. Suppose a lock is held in a shared state + * and there is a pending request for the deferred state. A shared lock + * request with the priority flag would be allowed to bypass the deferred + * request and directly join the other shared lock. A shared lock request + * without the priority flag might be forced to wait until the deferred + * requested had acquired and released the lock. + */ + +#define LM_FLAG_TRY 0x00000001 +#define LM_FLAG_TRY_1CB 0x00000002 +#define LM_FLAG_NOEXP 0x00000004 +#define LM_FLAG_ANY 0x00000008 +#define LM_FLAG_PRIORITY 0x00000010 + +/* + * lm_lock() and lm_async_cb return flags + * + * LM_OUT_ST_MASK + * Masks the lower two bits of lock state in the returned value. + * + * LM_OUT_CACHEABLE + * The lock hasn't been released so GFS can continue to cache data for it. + * + * LM_OUT_CANCELED + * The lock request was canceled. + * + * LM_OUT_ASYNC + * The result of the request will be returned in an LM_CB_ASYNC callback. + */ + +#define LM_OUT_ST_MASK 0x00000003 +#define LM_OUT_CACHEABLE 0x00000004 +#define LM_OUT_CANCELED 0x00000008 +#define LM_OUT_ASYNC 0x00000080 +#define LM_OUT_ERROR 0x00000100 + +/* + * lm_callback_t types + * + * LM_CB_NEED_E LM_CB_NEED_D LM_CB_NEED_S + * Blocking callback, a remote node is requesting the given lock in + * EXCLUSIVE, DEFERRED, or SHARED. + * + * LM_CB_NEED_RECOVERY + * The given journal needs to be recovered. + * + * LM_CB_DROPLOCKS + * Reduce the number of cached locks. + * + * LM_CB_ASYNC + * The given lock has been granted. + */ + +#define LM_CB_NEED_E 257 +#define LM_CB_NEED_D 258 +#define LM_CB_NEED_S 259 +#define LM_CB_NEED_RECOVERY 260 +#define LM_CB_DROPLOCKS 261 +#define LM_CB_ASYNC 262 + +/* + * lm_recovery_done() messages + */ + +#define LM_RD_GAVEUP 308 +#define LM_RD_SUCCESS 309 + + +struct lm_lockname { + uint64_t ln_number; + unsigned int ln_type; +}; + +#define lm_name_equal(name1, name2) \ + (((name1)->ln_number == (name2)->ln_number) && \ + ((name1)->ln_type == (name2)->ln_type)) \ + +struct lm_async_cb { + struct lm_lockname lc_name; + int lc_ret; +}; + +struct lm_lockstruct; + +struct lm_lockops { + char lm_proto_name[256]; + + /* + * Mount/Unmount + */ + + int (*lm_mount) (char *table_name, char *host_data, + lm_callback_t cb, lm_fsdata_t *fsdata, + unsigned int min_lvb_size, int flags, + struct lm_lockstruct *lockstruct, + struct kobject *fskobj); + + void (*lm_others_may_mount) (lm_lockspace_t *lockspace); + + void (*lm_unmount) (lm_lockspace_t *lockspace); + + void (*lm_withdraw) (lm_lockspace_t *lockspace); + + /* + * Lock oriented operations + */ + + int (*lm_get_lock) (lm_lockspace_t *lockspace, + struct lm_lockname *name, lm_lock_t **lockp); + + void (*lm_put_lock) (lm_lock_t *lock); + + unsigned int (*lm_lock) (lm_lock_t *lock, unsigned int cur_state, + unsigned int req_state, unsigned int flags); + + unsigned int (*lm_unlock) (lm_lock_t *lock, unsigned int cur_state); + + void (*lm_cancel) (lm_lock_t *lock); + + int (*lm_hold_lvb) (lm_lock_t *lock, char **lvbp); + void (*lm_unhold_lvb) (lm_lock_t *lock, char *lvb); + void (*lm_sync_lvb) (lm_lock_t *lock, char *lvb); + + /* + * Posix Lock oriented operations + */ + + int (*lm_plock_get) (lm_lockspace_t *lockspace, + struct lm_lockname *name, + struct file *file, struct file_lock *fl); + + int (*lm_plock) (lm_lockspace_t *lockspace, + struct lm_lockname *name, + struct file *file, int cmd, struct file_lock *fl); + + int (*lm_punlock) (lm_lockspace_t *lockspace, + struct lm_lockname *name, + struct file *file, struct file_lock *fl); + + /* + * Client oriented operations + */ + + void (*lm_recovery_done) (lm_lockspace_t *lockspace, unsigned int jid, + unsigned int message); + + struct module *lm_owner; +}; + +/* + * lm_mount() return values + * + * ls_jid - the journal ID this node should use + * ls_first - this node is the first to mount the file system + * ls_lvb_size - size in bytes of lock value blocks + * ls_lockspace - lock module's context for this file system + * ls_ops - lock module's functions + * ls_flags - lock module features + */ + +struct lm_lockstruct { + unsigned int ls_jid; + unsigned int ls_first; + unsigned int ls_lvb_size; + lm_lockspace_t *ls_lockspace; + struct lm_lockops *ls_ops; + int ls_flags; +}; + +void __init gfs2_init_lmh(void); + +/* + * Lock module bottom interface. A lock module makes itself available to GFS + * with these functions. + * + * For the time being, we copy the gfs1 lock module bottom interface so the + * same lock modules can be used with both gfs1 and gfs2 (it won't be possible + * to load both gfs1 and gfs2 at once.) Eventually the lock modules will fork + * for gfs1/gfs2 and this API can change to the gfs2_ prefix. + */ + +int gfs_register_lockproto(struct lm_lockops *proto); + +void gfs_unregister_lockproto(struct lm_lockops *proto); + +/* + * Lock module top interface. GFS calls these functions when mounting or + * unmounting a file system. + */ + +int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, + lm_callback_t cb, lm_fsdata_t *fsdata, + unsigned int min_lvb_size, int flags, + struct lm_lockstruct *lockstruct, + struct kobject *fskobj); + +void gfs2_unmount_lockproto(struct lm_lockstruct *lockstruct); + +void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct); + +#endif /* __LM_INTERFACE_DOT_H__ */ + diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c new file mode 100644 index 000000000000..2d2f8fe53999 --- /dev/null +++ b/fs/gfs2/locking.c @@ -0,0 +1,192 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "lm_interface.h" + +struct lmh_wrapper { + struct list_head lw_list; + struct lm_lockops *lw_ops; +}; + +/* List of registered low-level locking protocols. A file system selects one + of them by name at mount time, e.g. lock_nolock, lock_dlm. */ + +static struct list_head lmh_list; +static struct semaphore lmh_lock; + +/** + * gfs_register_lockproto - Register a low-level locking protocol + * @proto: the protocol definition + * + * Returns: 0 on success, -EXXX on failure + */ + +int gfs_register_lockproto(struct lm_lockops *proto) +{ + struct lmh_wrapper *lw; + + down(&lmh_lock); + + list_for_each_entry(lw, &lmh_list, lw_list) { + if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) { + up(&lmh_lock); + printk("GFS2: protocol %s already exists\n", + proto->lm_proto_name); + return -EEXIST; + } + } + + lw = kmalloc(sizeof(struct lmh_wrapper), GFP_KERNEL); + if (!lw) { + up(&lmh_lock); + return -ENOMEM; + } + memset(lw, 0, sizeof(struct lmh_wrapper)); + + lw->lw_ops = proto; + list_add(&lw->lw_list, &lmh_list); + + up(&lmh_lock); + + return 0; +} + +/** + * gfs_unregister_lockproto - Unregister a low-level locking protocol + * @proto: the protocol definition + * + */ + +void gfs_unregister_lockproto(struct lm_lockops *proto) +{ + struct lmh_wrapper *lw; + + down(&lmh_lock); + + list_for_each_entry(lw, &lmh_list, lw_list) { + if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) { + list_del(&lw->lw_list); + up(&lmh_lock); + kfree(lw); + return; + } + } + + up(&lmh_lock); + + printk("GFS2: can't unregister lock protocol %s\n", + proto->lm_proto_name); +} + +/** + * gfs2_mount_lockproto - Mount a lock protocol + * @proto_name - the name of the protocol + * @table_name - the name of the lock space + * @host_data - data specific to this host + * @cb - the callback to the code using the lock module + * @fsdata - data to pass back with the callback + * @min_lvb_size - the mininum LVB size that the caller can deal with + * @flags - LM_MFLAG_* + * @lockstruct - a structure returned describing the mount + * + * Returns: 0 on success, -EXXX on failure + */ + +int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, + lm_callback_t cb, lm_fsdata_t *fsdata, + unsigned int min_lvb_size, int flags, + struct lm_lockstruct *lockstruct, + struct kobject *fskobj) +{ + struct lmh_wrapper *lw = NULL; + int try = 0; + int error, found; + + retry: + down(&lmh_lock); + + found = 0; + list_for_each_entry(lw, &lmh_list, lw_list) { + if (!strcmp(lw->lw_ops->lm_proto_name, proto_name)) { + found = 1; + break; + } + } + + if (!found) { + if (!try && capable(CAP_SYS_MODULE)) { + try = 1; + up(&lmh_lock); + request_module(proto_name); + goto retry; + } + printk("GFS2: can't find protocol %s\n", proto_name); + error = -ENOENT; + goto out; + } + + if (!try_module_get(lw->lw_ops->lm_owner)) { + try = 0; + up(&lmh_lock); + msleep(1000); + goto retry; + } + + error = lw->lw_ops->lm_mount(table_name, host_data, cb, fsdata, + min_lvb_size, flags, lockstruct, fskobj); + if (error) + module_put(lw->lw_ops->lm_owner); + out: + up(&lmh_lock); + return error; +} + +void gfs2_unmount_lockproto(struct lm_lockstruct *lockstruct) +{ + down(&lmh_lock); + lockstruct->ls_ops->lm_unmount(lockstruct->ls_lockspace); + if (lockstruct->ls_ops->lm_owner) + module_put(lockstruct->ls_ops->lm_owner); + up(&lmh_lock); +} + +/** + * gfs2_withdraw_lockproto - abnormally unmount a lock module + * @lockstruct: the lockstruct passed into mount + * + */ + +void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct) +{ + down(&lmh_lock); + lockstruct->ls_ops->lm_withdraw(lockstruct->ls_lockspace); + if (lockstruct->ls_ops->lm_owner) + module_put(lockstruct->ls_ops->lm_owner); + up(&lmh_lock); +} + +void __init gfs2_init_lmh(void) +{ + init_MUTEX(&lmh_lock); + INIT_LIST_HEAD(&lmh_list); +} + +EXPORT_SYMBOL_GPL(gfs_register_lockproto); +EXPORT_SYMBOL_GPL(gfs_unregister_lockproto); + diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c new file mode 100644 index 000000000000..736d0d33dd1b --- /dev/null +++ b/fs/gfs2/log.c @@ -0,0 +1,659 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "glock.h" +#include "log.h" +#include "lops.h" +#include "meta_io.h" + +#define PULL 1 + +static inline int is_done(struct gfs2_sbd *sdp, atomic_t *a) +{ + int done; + gfs2_log_lock(sdp); + done = atomic_read(a) ? 0 : 1; + gfs2_log_unlock(sdp); + return done; +} + +static void do_lock_wait(struct gfs2_sbd *sdp, wait_queue_head_t *wq, + atomic_t *a) +{ + gfs2_log_unlock(sdp); + wait_event(*wq, is_done(sdp, a)); + gfs2_log_lock(sdp); +} + +static void lock_for_trans(struct gfs2_sbd *sdp) +{ + gfs2_log_lock(sdp); + do_lock_wait(sdp, &sdp->sd_log_trans_wq, &sdp->sd_log_flush_count); + atomic_inc(&sdp->sd_log_trans_count); + gfs2_log_unlock(sdp); +} + +static void unlock_from_trans(struct gfs2_sbd *sdp) +{ + gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_trans_count)); + if (atomic_dec_and_test(&sdp->sd_log_trans_count)) + wake_up(&sdp->sd_log_flush_wq); +} + +void gfs2_lock_for_flush(struct gfs2_sbd *sdp) +{ + gfs2_log_lock(sdp); + atomic_inc(&sdp->sd_log_flush_count); + do_lock_wait(sdp, &sdp->sd_log_flush_wq, &sdp->sd_log_trans_count); + gfs2_log_unlock(sdp); +} + +void gfs2_unlock_from_flush(struct gfs2_sbd *sdp) +{ + gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_flush_count)); + if (atomic_dec_and_test(&sdp->sd_log_flush_count)) + wake_up(&sdp->sd_log_trans_wq); +} + +/** + * gfs2_struct2blk - compute stuff + * @sdp: the filesystem + * @nstruct: the number of structures + * @ssize: the size of the structures + * + * Compute the number of log descriptor blocks needed to hold a certain number + * of structures of a certain size. + * + * Returns: the number of blocks needed (minimum is always 1) + */ + +unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, + unsigned int ssize) +{ + unsigned int blks; + unsigned int first, second; + + blks = 1; + first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / ssize; + + if (nstruct > first) { + second = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header)) / ssize; + blks += DIV_RU(nstruct - first, second); + } + + return blks; +} + +void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags) +{ + struct list_head *head = &sdp->sd_ail1_list; + uint64_t sync_gen; + struct list_head *first, *tmp; + struct gfs2_ail *first_ai, *ai; + + gfs2_log_lock(sdp); + if (list_empty(head)) { + gfs2_log_unlock(sdp); + return; + } + sync_gen = sdp->sd_ail_sync_gen++; + + first = head->prev; + first_ai = list_entry(first, struct gfs2_ail, ai_list); + first_ai->ai_sync_gen = sync_gen; + gfs2_ail1_start_one(sdp, first_ai); + + if (flags & DIO_ALL) + first = NULL; + + for (;;) { + if (first && + (head->prev != first || + gfs2_ail1_empty_one(sdp, first_ai, 0))) + break; + + for (tmp = head->prev; tmp != head; tmp = tmp->prev) { + ai = list_entry(tmp, struct gfs2_ail, ai_list); + if (ai->ai_sync_gen >= sync_gen) + continue; + ai->ai_sync_gen = sync_gen; + gfs2_ail1_start_one(sdp, ai); + break; + } + + if (tmp == head) + break; + } + + gfs2_log_unlock(sdp); +} + +int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags) +{ + struct gfs2_ail *ai, *s; + int ret; + + gfs2_log_lock(sdp); + + list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) { + if (gfs2_ail1_empty_one(sdp, ai, flags)) + list_move(&ai->ai_list, &sdp->sd_ail2_list); + else if (!(flags & DIO_ALL)) + break; + } + + ret = list_empty(&sdp->sd_ail1_list); + + gfs2_log_unlock(sdp); + + return ret; +} + +static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) +{ + struct gfs2_ail *ai, *safe; + unsigned int old_tail = sdp->sd_log_tail; + int wrap = (new_tail < old_tail); + int a, b, rm; + + gfs2_log_lock(sdp); + + list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) { + a = (old_tail <= ai->ai_first); + b = (ai->ai_first < new_tail); + rm = (wrap) ? (a || b) : (a && b); + if (!rm) + continue; + + gfs2_ail2_empty_one(sdp, ai); + list_del(&ai->ai_list); + gfs2_assert_warn(sdp, list_empty(&ai->ai_ail1_list)); + gfs2_assert_warn(sdp, list_empty(&ai->ai_ail2_list)); + kfree(ai); + } + + gfs2_log_unlock(sdp); +} + +/** + * gfs2_log_reserve - Make a log reservation + * @sdp: The GFS2 superblock + * @blks: The number of blocks to reserve + * + * Returns: errno + */ + +int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) +{ + LIST_HEAD(list); + unsigned int try = 0; + + if (gfs2_assert_warn(sdp, blks) || + gfs2_assert_warn(sdp, blks <= sdp->sd_jdesc->jd_blocks)) + return -EINVAL; + + for (;;) { + gfs2_log_lock(sdp); + + if (list_empty(&list)) { + list_add_tail(&list, &sdp->sd_log_blks_list); + while (sdp->sd_log_blks_list.next != &list) { + DECLARE_WAITQUEUE(__wait_chan, current); + set_current_state(TASK_UNINTERRUPTIBLE); + add_wait_queue(&sdp->sd_log_blks_wait, + &__wait_chan); + gfs2_log_unlock(sdp); + schedule(); + gfs2_log_lock(sdp); + remove_wait_queue(&sdp->sd_log_blks_wait, + &__wait_chan); + set_current_state(TASK_RUNNING); + } + } + + /* Never give away the last block so we can + always pull the tail if we need to. */ + if (sdp->sd_log_blks_free > blks) { + sdp->sd_log_blks_free -= blks; + list_del(&list); + gfs2_log_unlock(sdp); + wake_up(&sdp->sd_log_blks_wait); + break; + } + + gfs2_log_unlock(sdp); + + gfs2_ail1_empty(sdp, 0); + gfs2_log_flush(sdp); + + if (try++) + gfs2_ail1_start(sdp, 0); + } + + lock_for_trans(sdp); + + return 0; +} + +/** + * gfs2_log_release - Release a given number of log blocks + * @sdp: The GFS2 superblock + * @blks: The number of blocks + * + */ + +void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) +{ + unlock_from_trans(sdp); + + gfs2_log_lock(sdp); + sdp->sd_log_blks_free += blks; + gfs2_assert_withdraw(sdp, + sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); + gfs2_log_unlock(sdp); +} + +static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) +{ + int new = 0; + uint64_t dbn; + int error; + + error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, &new, &dbn, NULL); + gfs2_assert_withdraw(sdp, !error && dbn); + + return dbn; +} + +/** + * log_distance - Compute distance between two journal blocks + * @sdp: The GFS2 superblock + * @newer: The most recent journal block of the pair + * @older: The older journal block of the pair + * + * Compute the distance (in the journal direction) between two + * blocks in the journal + * + * Returns: the distance in blocks + */ + +static inline unsigned int log_distance(struct gfs2_sbd *sdp, + unsigned int newer, + unsigned int older) +{ + int dist; + + dist = newer - older; + if (dist < 0) + dist += sdp->sd_jdesc->jd_blocks; + + return dist; +} + +static unsigned int current_tail(struct gfs2_sbd *sdp) +{ + struct gfs2_ail *ai; + unsigned int tail; + + gfs2_log_lock(sdp); + + if (list_empty(&sdp->sd_ail1_list)) + tail = sdp->sd_log_head; + else { + ai = list_entry(sdp->sd_ail1_list.prev, + struct gfs2_ail, ai_list); + tail = ai->ai_first; + } + + gfs2_log_unlock(sdp); + + return tail; +} + +static inline void log_incr_head(struct gfs2_sbd *sdp) +{ + if (sdp->sd_log_flush_head == sdp->sd_log_tail) + gfs2_assert_withdraw(sdp, + sdp->sd_log_flush_head == sdp->sd_log_head); + + if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) { + sdp->sd_log_flush_head = 0; + sdp->sd_log_flush_wrapped = 1; + } +} + +/** + * gfs2_log_get_buf - Get and initialize a buffer to use for log control data + * @sdp: The GFS2 superblock + * + * Returns: the buffer_head + */ + +struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp) +{ + uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head); + struct gfs2_log_buf *lb; + struct buffer_head *bh; + + lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_KERNEL | __GFP_NOFAIL); + list_add(&lb->lb_list, &sdp->sd_log_flush_list); + + bh = lb->lb_bh = sb_getblk(sdp->sd_vfs, blkno); + lock_buffer(bh); + memset(bh->b_data, 0, bh->b_size); + set_buffer_uptodate(bh); + clear_buffer_dirty(bh); + unlock_buffer(bh); + + log_incr_head(sdp); + + return bh; +} + +/** + * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log + * @sdp: the filesystem + * @data: the data the buffer_head should point to + * + * Returns: the log buffer descriptor + */ + +struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, + struct buffer_head *real) +{ + uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head); + struct gfs2_log_buf *lb; + struct buffer_head *bh; + + lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_KERNEL | __GFP_NOFAIL); + list_add(&lb->lb_list, &sdp->sd_log_flush_list); + lb->lb_real = real; + + bh = lb->lb_bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL); + atomic_set(&bh->b_count, 1); + bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate); + set_bh_page(bh, virt_to_page(real->b_data), + ((unsigned long)real->b_data) & (PAGE_SIZE - 1)); + bh->b_blocknr = blkno; + bh->b_size = sdp->sd_sb.sb_bsize; + bh->b_bdev = sdp->sd_vfs->s_bdev; + + log_incr_head(sdp); + + return bh; +} + +static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail, int pull) +{ + unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail); + + ail2_empty(sdp, new_tail); + + gfs2_log_lock(sdp); + sdp->sd_log_blks_free += dist - ((pull) ? 1 : 0); + gfs2_assert_withdraw(sdp, + sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); + gfs2_log_unlock(sdp); + + sdp->sd_log_tail = new_tail; +} + +/** + * log_write_header - Get and initialize a journal header buffer + * @sdp: The GFS2 superblock + * + * Returns: the initialized log buffer descriptor + */ + +static void log_write_header(struct gfs2_sbd *sdp, uint32_t flags, int pull) +{ + uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head); + struct buffer_head *bh; + struct gfs2_log_header *lh; + unsigned int tail; + uint32_t hash; + + atomic_inc(&sdp->sd_log_flush_ondisk); + + bh = sb_getblk(sdp->sd_vfs, blkno); + lock_buffer(bh); + memset(bh->b_data, 0, bh->b_size); + set_buffer_uptodate(bh); + clear_buffer_dirty(bh); + unlock_buffer(bh); + + gfs2_ail1_empty(sdp, 0); + tail = current_tail(sdp); + + lh = (struct gfs2_log_header *)bh->b_data; + memset(lh, 0, sizeof(struct gfs2_log_header)); + lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); + lh->lh_header.mh_type = cpu_to_be16(GFS2_METATYPE_LH); + lh->lh_header.mh_format = cpu_to_be16(GFS2_FORMAT_LH); + lh->lh_sequence = be64_to_cpu(sdp->sd_log_sequence++); + lh->lh_flags = be32_to_cpu(flags); + lh->lh_tail = be32_to_cpu(tail); + lh->lh_blkno = be32_to_cpu(sdp->sd_log_flush_head); + hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header)); + lh->lh_hash = cpu_to_be32(hash); + + set_buffer_dirty(bh); + if (sync_dirty_buffer(bh)) + gfs2_io_error_bh(sdp, bh); + brelse(bh); + + if (sdp->sd_log_tail != tail) + log_pull_tail(sdp, tail, pull); + else + gfs2_assert_withdraw(sdp, !pull); + + sdp->sd_log_idle = (tail == sdp->sd_log_flush_head); + log_incr_head(sdp); +} + +static void log_flush_commit(struct gfs2_sbd *sdp) +{ + struct list_head *head = &sdp->sd_log_flush_list; + struct gfs2_log_buf *lb; + struct buffer_head *bh; + unsigned int d; + + d = log_distance(sdp, sdp->sd_log_flush_head, sdp->sd_log_head); + + gfs2_assert_withdraw(sdp, d + 1 == sdp->sd_log_blks_reserved); + + while (!list_empty(head)) { + lb = list_entry(head->next, struct gfs2_log_buf, lb_list); + list_del(&lb->lb_list); + bh = lb->lb_bh; + + wait_on_buffer(bh); + if (!buffer_uptodate(bh)) + gfs2_io_error_bh(sdp, bh); + if (lb->lb_real) { + while (atomic_read(&bh->b_count) != 1) /* Grrrr... */ + schedule(); + free_buffer_head(bh); + } else + brelse(bh); + kfree(lb); + } + + log_write_header(sdp, 0, 0); +} + +/** + * gfs2_log_flush_i - flush incore transaction(s) + * @sdp: the filesystem + * @gl: The glock structure to flush. If NULL, flush the whole incore log + * + */ + +void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) +{ + struct gfs2_ail *ai; + + atomic_inc(&sdp->sd_log_flush_incore); + + ai = kzalloc(sizeof(struct gfs2_ail), GFP_KERNEL | __GFP_NOFAIL); + INIT_LIST_HEAD(&ai->ai_ail1_list); + INIT_LIST_HEAD(&ai->ai_ail2_list); + + gfs2_lock_for_flush(sdp); + down(&sdp->sd_log_flush_lock); + + gfs2_assert_withdraw(sdp, + sdp->sd_log_num_buf == sdp->sd_log_commited_buf); + gfs2_assert_withdraw(sdp, + sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke); + + if (gl && list_empty(&gl->gl_le.le_list)) { + up(&sdp->sd_log_flush_lock); + gfs2_unlock_from_flush(sdp); + kfree(ai); + return; + } + + sdp->sd_log_flush_head = sdp->sd_log_head; + sdp->sd_log_flush_wrapped = 0; + ai->ai_first = sdp->sd_log_flush_head; + + lops_before_commit(sdp); + if (!list_empty(&sdp->sd_log_flush_list)) + log_flush_commit(sdp); + else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle) + log_write_header(sdp, 0, PULL); + lops_after_commit(sdp, ai); + + sdp->sd_log_head = sdp->sd_log_flush_head; + if (sdp->sd_log_flush_wrapped) + sdp->sd_log_wraps++; + + sdp->sd_log_blks_reserved = + sdp->sd_log_commited_buf = + sdp->sd_log_commited_revoke = 0; + + gfs2_log_lock(sdp); + if (!list_empty(&ai->ai_ail1_list)) { + list_add(&ai->ai_list, &sdp->sd_ail1_list); + ai = NULL; + } + gfs2_log_unlock(sdp); + + up(&sdp->sd_log_flush_lock); + sdp->sd_vfs->s_dirt = 0; + gfs2_unlock_from_flush(sdp); + + kfree(ai); +} + +static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) +{ + unsigned int reserved = 1; + unsigned int old; + + gfs2_log_lock(sdp); + + sdp->sd_log_commited_buf += tr->tr_num_buf_new - tr->tr_num_buf_rm; + gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_buf) >= 0); + sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm; + gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0); + + if (sdp->sd_log_commited_buf) + reserved += 1 + sdp->sd_log_commited_buf + sdp->sd_log_commited_buf/503; + if (sdp->sd_log_commited_revoke) + reserved += gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke, + sizeof(uint64_t)); + + old = sdp->sd_log_blks_free; + sdp->sd_log_blks_free += tr->tr_reserved - + (reserved - sdp->sd_log_blks_reserved); + + gfs2_assert_withdraw(sdp, + sdp->sd_log_blks_free >= old); + gfs2_assert_withdraw(sdp, + sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); + + sdp->sd_log_blks_reserved = reserved; + + gfs2_log_unlock(sdp); +} + +/** + * gfs2_log_commit - Commit a transaction to the log + * @sdp: the filesystem + * @tr: the transaction + * + * Returns: errno + */ + +void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) +{ + log_refund(sdp, tr); + lops_incore_commit(sdp, tr); + + sdp->sd_vfs->s_dirt = 1; + unlock_from_trans(sdp); + + kfree(tr); + + gfs2_log_lock(sdp); + if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks)) { + gfs2_log_unlock(sdp); + gfs2_log_flush(sdp); + } else + gfs2_log_unlock(sdp); +} + +/** + * gfs2_log_shutdown - write a shutdown header into a journal + * @sdp: the filesystem + * + */ + +void gfs2_log_shutdown(struct gfs2_sbd *sdp) +{ + down(&sdp->sd_log_flush_lock); + + gfs2_assert_withdraw(sdp, !atomic_read(&sdp->sd_log_trans_count)); + gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); + gfs2_assert_withdraw(sdp, !sdp->sd_log_num_gl); + gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf); + gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); + gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg); + gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf); + gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list)); + + sdp->sd_log_flush_head = sdp->sd_log_head; + sdp->sd_log_flush_wrapped = 0; + + log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT, 0); + + gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free == + sdp->sd_jdesc->jd_blocks); + gfs2_assert_withdraw(sdp, sdp->sd_log_head == sdp->sd_log_tail); + gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail2_list)); + + sdp->sd_log_head = sdp->sd_log_flush_head; + if (sdp->sd_log_flush_wrapped) + sdp->sd_log_wraps++; + sdp->sd_log_tail = sdp->sd_log_head; + + up(&sdp->sd_log_flush_lock); +} + diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h new file mode 100644 index 000000000000..4413cda81154 --- /dev/null +++ b/fs/gfs2/log.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __LOG_DOT_H__ +#define __LOG_DOT_H__ + +/** + * gfs2_log_lock - acquire the right to mess with the log manager + * @sdp: the filesystem + * + */ + +static inline void gfs2_log_lock(struct gfs2_sbd *sdp) +{ + spin_lock(&sdp->sd_log_lock); +} + +/** + * gfs2_log_unlock - release the right to mess with the log manager + * @sdp: the filesystem + * + */ + +static inline void gfs2_log_unlock(struct gfs2_sbd *sdp) +{ + spin_unlock(&sdp->sd_log_lock); +} + +static inline void gfs2_log_pointers_init(struct gfs2_sbd *sdp, + unsigned int value) +{ + if (++value == sdp->sd_jdesc->jd_blocks) { + value = 0; + sdp->sd_log_wraps++; + } + sdp->sd_log_head = sdp->sd_log_tail = value; +} + +void gfs2_lock_for_flush(struct gfs2_sbd *sdp); +void gfs2_unlock_from_flush(struct gfs2_sbd *sdp); + +unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, + unsigned int ssize); + +void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags); +int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags); + +int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks); +void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks); + +struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp); +struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, + struct buffer_head *real); + +#define gfs2_log_flush(sdp) gfs2_log_flush_i((sdp), NULL) +#define gfs2_log_flush_glock(gl) gfs2_log_flush_i((gl)->gl_sbd, (gl)) +void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl); +void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans); + +void gfs2_log_shutdown(struct gfs2_sbd *sdp); + +#endif /* __LOG_DOT_H__ */ diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c new file mode 100644 index 000000000000..d501e8224ed0 --- /dev/null +++ b/fs/gfs2/lops.c @@ -0,0 +1,534 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "glock.h" +#include "log.h" +#include "lops.h" +#include "meta_io.h" +#include "recovery.h" +#include "rgrp.h" +#include "trans.h" + +static void glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) +{ + struct gfs2_glock *gl; + + get_transaction->tr_touched = 1; + + if (!list_empty(&le->le_list)) + return; + + gl = container_of(le, struct gfs2_glock, gl_le); + if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(gl))) + return; + gfs2_glock_hold(gl); + set_bit(GLF_DIRTY, &gl->gl_flags); + + gfs2_log_lock(sdp); + sdp->sd_log_num_gl++; + list_add(&le->le_list, &sdp->sd_log_le_gl); + gfs2_log_unlock(sdp); +} + +static void glock_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) +{ + struct list_head *head = &sdp->sd_log_le_gl; + struct gfs2_glock *gl; + + while (!list_empty(head)) { + gl = list_entry(head->next, struct gfs2_glock, gl_le.le_list); + list_del_init(&gl->gl_le.le_list); + sdp->sd_log_num_gl--; + + gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(gl)); + gfs2_glock_put(gl); + } + gfs2_assert_warn(sdp, !sdp->sd_log_num_gl); +} + +static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) +{ + struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le); + struct gfs2_trans *tr; + + if (!list_empty(&bd->bd_list_tr)) + return; + + tr = get_transaction; + tr->tr_touched = 1; + tr->tr_num_buf++; + list_add(&bd->bd_list_tr, &tr->tr_list_buf); + + if (!list_empty(&le->le_list)) + return; + + gfs2_trans_add_gl(bd->bd_gl); + + gfs2_meta_check(sdp, bd->bd_bh); + gfs2_meta_pin(sdp, bd->bd_bh); + + gfs2_log_lock(sdp); + sdp->sd_log_num_buf++; + list_add(&le->le_list, &sdp->sd_log_le_buf); + gfs2_log_unlock(sdp); + + tr->tr_num_buf_new++; +} + +static void buf_lo_incore_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) +{ + struct list_head *head = &tr->tr_list_buf; + struct gfs2_bufdata *bd; + + while (!list_empty(head)) { + bd = list_entry(head->next, struct gfs2_bufdata, bd_list_tr); + list_del_init(&bd->bd_list_tr); + tr->tr_num_buf--; + } + gfs2_assert_warn(sdp, !tr->tr_num_buf); +} + +static void buf_lo_before_commit(struct gfs2_sbd *sdp) +{ + struct buffer_head *bh; + struct gfs2_log_descriptor *ld; + struct gfs2_bufdata *bd1 = NULL, *bd2; + unsigned int total = sdp->sd_log_num_buf; + unsigned int offset = sizeof(struct gfs2_log_descriptor); + unsigned int limit; + unsigned int num; + unsigned n; + __be64 *ptr; + + offset += (sizeof(__be64) - 1); + offset &= ~(sizeof(__be64) - 1); + limit = (sdp->sd_sb.sb_bsize - offset)/sizeof(__be64); + /* for 4k blocks, limit = 503 */ + + bd1 = bd2 = list_prepare_entry(bd1, &sdp->sd_log_le_buf, bd_le.le_list); + while(total) { + num = total; + if (total > limit) + num = limit; + bh = gfs2_log_get_buf(sdp); + ld = (struct gfs2_log_descriptor *)bh->b_data; + ptr = (__be64 *)(bh->b_data + offset); + ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC); + ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD); + ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD); + ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_METADATA); + ld->ld_length = cpu_to_be32(num + 1); + ld->ld_data1 = cpu_to_be32(num); + ld->ld_data2 = cpu_to_be32(0); + memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved)); + + n = 0; + list_for_each_entry_continue(bd1, &sdp->sd_log_le_buf, bd_le.le_list) { + *ptr++ = cpu_to_be64(bd1->bd_bh->b_blocknr); + if (++n >= num) + break; + } + + set_buffer_dirty(bh); + ll_rw_block(WRITE, 1, &bh); + + n = 0; + list_for_each_entry_continue(bd2, &sdp->sd_log_le_buf, bd_le.le_list) { + bh = gfs2_log_fake_buf(sdp, bd2->bd_bh); + set_buffer_dirty(bh); + ll_rw_block(WRITE, 1, &bh); + if (++n >= num) + break; + } + + total -= num; + } +} + +static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) +{ + struct list_head *head = &sdp->sd_log_le_buf; + struct gfs2_bufdata *bd; + + while (!list_empty(head)) { + bd = list_entry(head->next, struct gfs2_bufdata, bd_le.le_list); + list_del_init(&bd->bd_le.le_list); + sdp->sd_log_num_buf--; + + gfs2_meta_unpin(sdp, bd->bd_bh, ai); + } + gfs2_assert_warn(sdp, !sdp->sd_log_num_buf); +} + +static void buf_lo_before_scan(struct gfs2_jdesc *jd, + struct gfs2_log_header *head, int pass) +{ + struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + + if (pass != 0) + return; + + sdp->sd_found_blocks = 0; + sdp->sd_replayed_blocks = 0; +} + +static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, + struct gfs2_log_descriptor *ld, __be64 *ptr, + int pass) +{ + struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_glock *gl = jd->jd_inode->i_gl; + unsigned int blks = be32_to_cpu(ld->ld_data1); + struct buffer_head *bh_log, *bh_ip; + uint64_t blkno; + int error = 0; + + if (pass != 1 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_METADATA) + return 0; + + gfs2_replay_incr_blk(sdp, &start); + + for (; blks; gfs2_replay_incr_blk(sdp, &start), blks--) { + blkno = be64_to_cpu(*ptr++); + + sdp->sd_found_blocks++; + + if (gfs2_revoke_check(sdp, blkno, start)) + continue; + + error = gfs2_replay_read_block(jd, start, &bh_log); + if (error) + return error; + + bh_ip = gfs2_meta_new(gl, blkno); + memcpy(bh_ip->b_data, bh_log->b_data, bh_log->b_size); + + if (gfs2_meta_check(sdp, bh_ip)) + error = -EIO; + else + mark_buffer_dirty(bh_ip); + + brelse(bh_log); + brelse(bh_ip); + + if (error) + break; + + sdp->sd_replayed_blocks++; + } + + return error; +} + +static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) +{ + struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + + if (error) { + gfs2_meta_sync(jd->jd_inode->i_gl, DIO_START | DIO_WAIT); + return; + } + if (pass != 1) + return; + + gfs2_meta_sync(jd->jd_inode->i_gl, DIO_START | DIO_WAIT); + + fs_info(sdp, "jid=%u: Replayed %u of %u blocks\n", + jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); +} + +static void revoke_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) +{ + struct gfs2_trans *tr; + + tr = get_transaction; + tr->tr_touched = 1; + tr->tr_num_revoke++; + + gfs2_log_lock(sdp); + sdp->sd_log_num_revoke++; + list_add(&le->le_list, &sdp->sd_log_le_revoke); + gfs2_log_unlock(sdp); +} + +static void revoke_lo_before_commit(struct gfs2_sbd *sdp) +{ + struct gfs2_log_descriptor *ld; + struct gfs2_meta_header *mh; + struct buffer_head *bh; + unsigned int offset; + struct list_head *head = &sdp->sd_log_le_revoke; + struct gfs2_revoke *rv; + + if (!sdp->sd_log_num_revoke) + return; + + bh = gfs2_log_get_buf(sdp); + ld = (struct gfs2_log_descriptor *)bh->b_data; + ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC); + ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD); + ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD); + ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_REVOKE); + ld->ld_length = cpu_to_be32(gfs2_struct2blk(sdp, sdp->sd_log_num_revoke, sizeof(uint64_t))); + ld->ld_data1 = cpu_to_be32(sdp->sd_log_num_revoke); + ld->ld_data2 = cpu_to_be32(0); + memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved)); + offset = sizeof(struct gfs2_log_descriptor); + + while (!list_empty(head)) { + rv = list_entry(head->next, struct gfs2_revoke, rv_le.le_list); + list_del(&rv->rv_le.le_list); + sdp->sd_log_num_revoke--; + + if (offset + sizeof(uint64_t) > sdp->sd_sb.sb_bsize) { + set_buffer_dirty(bh); + ll_rw_block(WRITE, 1, &bh); + + bh = gfs2_log_get_buf(sdp); + mh = (struct gfs2_meta_header *)bh->b_data; + mh->mh_magic = cpu_to_be32(GFS2_MAGIC); + mh->mh_type = cpu_to_be16(GFS2_METATYPE_LB); + mh->mh_format = cpu_to_be16(GFS2_FORMAT_LB); + offset = sizeof(struct gfs2_meta_header); + } + + *(__be64 *)(bh->b_data + offset) = cpu_to_be64(rv->rv_blkno); + kfree(rv); + + offset += sizeof(uint64_t); + } + gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); + + set_buffer_dirty(bh); + ll_rw_block(WRITE, 1, &bh); +} + +static void revoke_lo_before_scan(struct gfs2_jdesc *jd, + struct gfs2_log_header *head, int pass) +{ + struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + + if (pass != 0) + return; + + sdp->sd_found_revokes = 0; + sdp->sd_replay_tail = head->lh_tail; +} + +static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, + struct gfs2_log_descriptor *ld, __be64 *ptr, + int pass) +{ + struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + unsigned int blks = be32_to_cpu(ld->ld_length); + unsigned int revokes = be32_to_cpu(ld->ld_data1); + struct buffer_head *bh; + unsigned int offset; + uint64_t blkno; + int first = 1; + int error; + + if (pass != 0 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_REVOKE) + return 0; + + offset = sizeof(struct gfs2_log_descriptor); + + for (; blks; gfs2_replay_incr_blk(sdp, &start), blks--) { + error = gfs2_replay_read_block(jd, start, &bh); + if (error) + return error; + + if (!first) + gfs2_metatype_check(sdp, bh, GFS2_METATYPE_LB); + + while (offset + sizeof(uint64_t) <= sdp->sd_sb.sb_bsize) { + blkno = be64_to_cpu(*(__be64 *)(bh->b_data + offset)); + + error = gfs2_revoke_add(sdp, blkno, start); + if (error < 0) + return error; + else if (error) + sdp->sd_found_revokes++; + + if (!--revokes) + break; + offset += sizeof(uint64_t); + } + + brelse(bh); + offset = sizeof(struct gfs2_meta_header); + first = 0; + } + + return 0; +} + +static void revoke_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) +{ + struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + + if (error) { + gfs2_revoke_clean(sdp); + return; + } + if (pass != 1) + return; + + fs_info(sdp, "jid=%u: Found %u revoke tags\n", + jd->jd_jid, sdp->sd_found_revokes); + + gfs2_revoke_clean(sdp); +} + +static void rg_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) +{ + struct gfs2_rgrpd *rgd; + + get_transaction->tr_touched = 1; + + if (!list_empty(&le->le_list)) + return; + + rgd = container_of(le, struct gfs2_rgrpd, rd_le); + gfs2_rgrp_bh_hold(rgd); + + gfs2_log_lock(sdp); + sdp->sd_log_num_rg++; + list_add(&le->le_list, &sdp->sd_log_le_rg); + gfs2_log_unlock(sdp); +} + +static void rg_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) +{ + struct list_head *head = &sdp->sd_log_le_rg; + struct gfs2_rgrpd *rgd; + + while (!list_empty(head)) { + rgd = list_entry(head->next, struct gfs2_rgrpd, rd_le.le_list); + list_del_init(&rgd->rd_le.le_list); + sdp->sd_log_num_rg--; + + gfs2_rgrp_repolish_clones(rgd); + gfs2_rgrp_bh_put(rgd); + } + gfs2_assert_warn(sdp, !sdp->sd_log_num_rg); +} + +static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) +{ + get_transaction->tr_touched = 1; + + gfs2_log_lock(sdp); + sdp->sd_log_num_databuf++; + list_add(&le->le_list, &sdp->sd_log_le_databuf); + gfs2_log_unlock(sdp); +} + +static void databuf_lo_before_commit(struct gfs2_sbd *sdp) +{ + struct list_head *head = &sdp->sd_log_le_databuf; + LIST_HEAD(started); + struct gfs2_databuf *db; + struct buffer_head *bh; + + while (!list_empty(head)) { + db = list_entry(head->prev, struct gfs2_databuf, db_le.le_list); + list_move(&db->db_le.le_list, &started); + + gfs2_log_lock(sdp); + bh = db->db_bh; + if (bh) { + get_bh(bh); + gfs2_log_unlock(sdp); + if (buffer_dirty(bh)) { + wait_on_buffer(bh); + ll_rw_block(WRITE, 1, &bh); + } + brelse(bh); + } else + gfs2_log_unlock(sdp); + } + + while (!list_empty(&started)) { + db = list_entry(started.next, struct gfs2_databuf, + db_le.le_list); + list_del(&db->db_le.le_list); + sdp->sd_log_num_databuf--; + + gfs2_log_lock(sdp); + bh = db->db_bh; + if (bh) { + set_v2db(bh, NULL); + gfs2_log_unlock(sdp); + wait_on_buffer(bh); + brelse(bh); + } else + gfs2_log_unlock(sdp); + + kfree(db); + } + + gfs2_assert_warn(sdp, !sdp->sd_log_num_databuf); +} + +struct gfs2_log_operations gfs2_glock_lops = { + .lo_add = glock_lo_add, + .lo_after_commit = glock_lo_after_commit, + .lo_name = "glock" +}; + +struct gfs2_log_operations gfs2_buf_lops = { + .lo_add = buf_lo_add, + .lo_incore_commit = buf_lo_incore_commit, + .lo_before_commit = buf_lo_before_commit, + .lo_after_commit = buf_lo_after_commit, + .lo_before_scan = buf_lo_before_scan, + .lo_scan_elements = buf_lo_scan_elements, + .lo_after_scan = buf_lo_after_scan, + .lo_name = "buf" +}; + +struct gfs2_log_operations gfs2_revoke_lops = { + .lo_add = revoke_lo_add, + .lo_before_commit = revoke_lo_before_commit, + .lo_before_scan = revoke_lo_before_scan, + .lo_scan_elements = revoke_lo_scan_elements, + .lo_after_scan = revoke_lo_after_scan, + .lo_name = "revoke" +}; + +struct gfs2_log_operations gfs2_rg_lops = { + .lo_add = rg_lo_add, + .lo_after_commit = rg_lo_after_commit, + .lo_name = "rg" +}; + +struct gfs2_log_operations gfs2_databuf_lops = { + .lo_add = databuf_lo_add, + .lo_before_commit = databuf_lo_before_commit, + .lo_name = "databuf" +}; + +struct gfs2_log_operations *gfs2_log_ops[] = { + &gfs2_glock_lops, + &gfs2_buf_lops, + &gfs2_revoke_lops, + &gfs2_rg_lops, + &gfs2_databuf_lops, + NULL +}; + diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h new file mode 100644 index 000000000000..417f5aade4b1 --- /dev/null +++ b/fs/gfs2/lops.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __LOPS_DOT_H__ +#define __LOPS_DOT_H__ + +extern struct gfs2_log_operations gfs2_glock_lops; +extern struct gfs2_log_operations gfs2_buf_lops; +extern struct gfs2_log_operations gfs2_revoke_lops; +extern struct gfs2_log_operations gfs2_rg_lops; +extern struct gfs2_log_operations gfs2_databuf_lops; + +extern struct gfs2_log_operations *gfs2_log_ops[]; + +static inline void lops_init_le(struct gfs2_log_element *le, + struct gfs2_log_operations *lops) +{ + INIT_LIST_HEAD(&le->le_list); + le->le_ops = lops; +} + +static inline void lops_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) +{ + if (le->le_ops->lo_add) + le->le_ops->lo_add(sdp, le); +} + +static inline void lops_incore_commit(struct gfs2_sbd *sdp, + struct gfs2_trans *tr) +{ + int x; + for (x = 0; gfs2_log_ops[x]; x++) + if (gfs2_log_ops[x]->lo_incore_commit) + gfs2_log_ops[x]->lo_incore_commit(sdp, tr); +} + +static inline void lops_before_commit(struct gfs2_sbd *sdp) +{ + int x; + for (x = 0; gfs2_log_ops[x]; x++) + if (gfs2_log_ops[x]->lo_before_commit) + gfs2_log_ops[x]->lo_before_commit(sdp); +} + +static inline void lops_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) +{ + int x; + for (x = 0; gfs2_log_ops[x]; x++) + if (gfs2_log_ops[x]->lo_after_commit) + gfs2_log_ops[x]->lo_after_commit(sdp, ai); +} + +static inline void lops_before_scan(struct gfs2_jdesc *jd, + struct gfs2_log_header *head, + unsigned int pass) +{ + int x; + for (x = 0; gfs2_log_ops[x]; x++) + if (gfs2_log_ops[x]->lo_before_scan) + gfs2_log_ops[x]->lo_before_scan(jd, head, pass); +} + +static inline int lops_scan_elements(struct gfs2_jdesc *jd, unsigned int start, + struct gfs2_log_descriptor *ld, + __be64 *ptr, + unsigned int pass) +{ + int x, error; + for (x = 0; gfs2_log_ops[x]; x++) + if (gfs2_log_ops[x]->lo_scan_elements) { + error = gfs2_log_ops[x]->lo_scan_elements(jd, start, + ld, ptr, pass); + if (error) + return error; + } + + return 0; +} + +static inline void lops_after_scan(struct gfs2_jdesc *jd, int error, + unsigned int pass) +{ + int x; + for (x = 0; gfs2_log_ops[x]; x++) + if (gfs2_log_ops[x]->lo_before_scan) + gfs2_log_ops[x]->lo_after_scan(jd, error, pass); +} + +#endif /* __LOPS_DOT_H__ */ + diff --git a/fs/gfs2/lvb.c b/fs/gfs2/lvb.c new file mode 100644 index 000000000000..8af62568a3f4 --- /dev/null +++ b/fs/gfs2/lvb.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" + +#define pv(struct, member, fmt) printk(" "#member" = "fmt"\n", struct->member); + +void gfs2_quota_lvb_in(struct gfs2_quota_lvb *qb, char *lvb) +{ + struct gfs2_quota_lvb *str = (struct gfs2_quota_lvb *)lvb; + + qb->qb_magic = be32_to_cpu(str->qb_magic); + qb->qb_limit = be64_to_cpu(str->qb_limit); + qb->qb_warn = be64_to_cpu(str->qb_warn); + qb->qb_value = be64_to_cpu(str->qb_value); +} + +void gfs2_quota_lvb_out(struct gfs2_quota_lvb *qb, char *lvb) +{ + struct gfs2_quota_lvb *str = (struct gfs2_quota_lvb *)lvb; + + str->qb_magic = cpu_to_be32(qb->qb_magic); + str->qb_limit = cpu_to_be64(qb->qb_limit); + str->qb_warn = cpu_to_be64(qb->qb_warn); + str->qb_value = cpu_to_be64(qb->qb_value); +} + +void gfs2_quota_lvb_print(struct gfs2_quota_lvb *qb) +{ + pv(qb, qb_magic, "%u"); + pv(qb, qb_limit, "%llu"); + pv(qb, qb_warn, "%llu"); + pv(qb, qb_value, "%lld"); +} + diff --git a/fs/gfs2/lvb.h b/fs/gfs2/lvb.h new file mode 100644 index 000000000000..ca9732b2d9f4 --- /dev/null +++ b/fs/gfs2/lvb.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __LVB_DOT_H__ +#define __LVB_DOT_H__ + +#define GFS2_MIN_LVB_SIZE 32 + +struct gfs2_quota_lvb { + uint32_t qb_magic; + uint32_t __pad; + uint64_t qb_limit; /* Hard limit of # blocks to alloc */ + uint64_t qb_warn; /* Warn user when alloc is above this # */ + int64_t qb_value; /* Current # blocks allocated */ +}; + +void gfs2_quota_lvb_in(struct gfs2_quota_lvb *qb, char *lvb); +void gfs2_quota_lvb_out(struct gfs2_quota_lvb *qb, char *lvb); +void gfs2_quota_lvb_print(struct gfs2_quota_lvb *qb); + +#endif /* __LVB_DOT_H__ */ + diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c new file mode 100644 index 000000000000..0c60f2b10fdd --- /dev/null +++ b/fs/gfs2/main.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "ops_fstype.h" +#include "sys.h" + +/** + * init_gfs2_fs - Register GFS2 as a filesystem + * + * Returns: 0 on success, error code on failure + */ + +static int __init init_gfs2_fs(void) +{ + int error; + + gfs2_init_lmh(); + + error = gfs2_sys_init(); + if (error) + return error; + + error = -ENOMEM; + + gfs2_glock_cachep = kmem_cache_create("gfs2_glock", + sizeof(struct gfs2_glock), + 0, 0, NULL, NULL); + if (!gfs2_glock_cachep) + goto fail; + + gfs2_inode_cachep = kmem_cache_create("gfs2_inode", + sizeof(struct gfs2_inode), + 0, 0, NULL, NULL); + if (!gfs2_inode_cachep) + goto fail; + + gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata", + sizeof(struct gfs2_bufdata), + 0, 0, NULL, NULL); + if (!gfs2_bufdata_cachep) + goto fail; + + error = register_filesystem(&gfs2_fs_type); + if (error) + goto fail; + + printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__); + + return 0; + + fail: + if (gfs2_bufdata_cachep) + kmem_cache_destroy(gfs2_bufdata_cachep); + + if (gfs2_inode_cachep) + kmem_cache_destroy(gfs2_inode_cachep); + + if (gfs2_glock_cachep) + kmem_cache_destroy(gfs2_glock_cachep); + + gfs2_sys_uninit(); + return error; +} + +/** + * exit_gfs2_fs - Unregister the file system + * + */ + +static void __exit exit_gfs2_fs(void) +{ + unregister_filesystem(&gfs2_fs_type); + + kmem_cache_destroy(gfs2_bufdata_cachep); + kmem_cache_destroy(gfs2_inode_cachep); + kmem_cache_destroy(gfs2_glock_cachep); + + gfs2_sys_uninit(); +} + +MODULE_DESCRIPTION("Global File System"); +MODULE_AUTHOR("Red Hat, Inc."); +MODULE_LICENSE("GPL"); + +module_init(init_gfs2_fs); +module_exit(exit_gfs2_fs); + diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c new file mode 100644 index 000000000000..177b0246d194 --- /dev/null +++ b/fs/gfs2/meta_io.c @@ -0,0 +1,876 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "glock.h" +#include "glops.h" +#include "inode.h" +#include "log.h" +#include "lops.h" +#include "meta_io.h" +#include "rgrp.h" +#include "trans.h" + +#define buffer_busy(bh) \ +((bh)->b_state & ((1ul << BH_Dirty) | (1ul << BH_Lock) | (1ul << BH_Pinned))) +#define buffer_in_io(bh) \ +((bh)->b_state & ((1ul << BH_Dirty) | (1ul << BH_Lock))) + +static int aspace_get_block(struct inode *inode, sector_t lblock, + struct buffer_head *bh_result, int create) +{ + gfs2_assert_warn(get_v2sdp(inode->i_sb), 0); + return -EOPNOTSUPP; +} + +static int gfs2_aspace_writepage(struct page *page, + struct writeback_control *wbc) +{ + return block_write_full_page(page, aspace_get_block, wbc); +} + +/** + * stuck_releasepage - We're stuck in gfs2_releasepage(). Print stuff out. + * @bh: the buffer we're stuck on + * + */ + +static void stuck_releasepage(struct buffer_head *bh) +{ + struct gfs2_sbd *sdp = get_v2sdp(bh->b_page->mapping->host->i_sb); + struct gfs2_bufdata *bd = get_v2bd(bh); + struct gfs2_glock *gl; + + fs_warn(sdp, "stuck in gfs2_releasepage()\n"); + fs_warn(sdp, "blkno = %llu, bh->b_count = %d\n", + (uint64_t)bh->b_blocknr, atomic_read(&bh->b_count)); + fs_warn(sdp, "pinned = %u\n", buffer_pinned(bh)); + fs_warn(sdp, "get_v2bd(bh) = %s\n", (bd) ? "!NULL" : "NULL"); + + if (!bd) + return; + + gl = bd->bd_gl; + + fs_warn(sdp, "gl = (%u, %llu)\n", + gl->gl_name.ln_type, gl->gl_name.ln_number); + + fs_warn(sdp, "bd_list_tr = %s, bd_le.le_list = %s\n", + (list_empty(&bd->bd_list_tr)) ? "no" : "yes", + (list_empty(&bd->bd_le.le_list)) ? "no" : "yes"); + + if (gl->gl_ops == &gfs2_inode_glops) { + struct gfs2_inode *ip = get_gl2ip(gl); + unsigned int x; + + if (!ip) + return; + + fs_warn(sdp, "ip = %llu %llu\n", + ip->i_num.no_formal_ino, ip->i_num.no_addr); + fs_warn(sdp, "ip->i_count = %d, ip->i_vnode = %s\n", + atomic_read(&ip->i_count), + (ip->i_vnode) ? "!NULL" : "NULL"); + + for (x = 0; x < GFS2_MAX_META_HEIGHT; x++) + fs_warn(sdp, "ip->i_cache[%u] = %s\n", + x, (ip->i_cache[x]) ? "!NULL" : "NULL"); + } +} + +/** + * gfs2_aspace_releasepage - free the metadata associated with a page + * @page: the page that's being released + * @gfp_mask: passed from Linux VFS, ignored by us + * + * Call try_to_free_buffers() if the buffers in this page can be + * released. + * + * Returns: 0 + */ + +static int gfs2_aspace_releasepage(struct page *page, gfp_t gfp_mask) +{ + struct inode *aspace = page->mapping->host; + struct gfs2_sbd *sdp = get_v2sdp(aspace->i_sb); + struct buffer_head *bh, *head; + struct gfs2_bufdata *bd; + unsigned long t; + + if (!page_has_buffers(page)) + goto out; + + head = bh = page_buffers(page); + do { + t = jiffies; + + while (atomic_read(&bh->b_count)) { + if (atomic_read(&aspace->i_writecount)) { + if (time_after_eq(jiffies, t + + gfs2_tune_get(sdp, gt_stall_secs) * HZ)) { + stuck_releasepage(bh); + t = jiffies; + } + + yield(); + continue; + } + + return 0; + } + + gfs2_assert_warn(sdp, !buffer_pinned(bh)); + + bd = get_v2bd(bh); + if (bd) { + gfs2_assert_warn(sdp, bd->bd_bh == bh); + gfs2_assert_warn(sdp, list_empty(&bd->bd_list_tr)); + gfs2_assert_warn(sdp, list_empty(&bd->bd_le.le_list)); + gfs2_assert_warn(sdp, !bd->bd_ail); + kmem_cache_free(gfs2_bufdata_cachep, bd); + atomic_dec(&sdp->sd_bufdata_count); + set_v2bd(bh, NULL); + } + + bh = bh->b_this_page; + } + while (bh != head); + + out: + return try_to_free_buffers(page); +} + +static struct address_space_operations aspace_aops = { + .writepage = gfs2_aspace_writepage, + .releasepage = gfs2_aspace_releasepage, +}; + +/** + * gfs2_aspace_get - Create and initialize a struct inode structure + * @sdp: the filesystem the aspace is in + * + * Right now a struct inode is just a struct inode. Maybe Linux + * will supply a more lightweight address space construct (that works) + * in the future. + * + * Make sure pages/buffers in this aspace aren't in high memory. + * + * Returns: the aspace + */ + +struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp) +{ + struct inode *aspace; + + aspace = new_inode(sdp->sd_vfs); + if (aspace) { + mapping_set_gfp_mask(aspace->i_mapping, GFP_KERNEL); + aspace->i_mapping->a_ops = &aspace_aops; + aspace->i_size = ~0ULL; + set_v2ip(aspace, NULL); + insert_inode_hash(aspace); + } + + return aspace; +} + +void gfs2_aspace_put(struct inode *aspace) +{ + remove_inode_hash(aspace); + iput(aspace); +} + +/** + * gfs2_ail1_start_one - Start I/O on a part of the AIL + * @sdp: the filesystem + * @tr: the part of the AIL + * + */ + +void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) +{ + struct gfs2_bufdata *bd, *s; + struct buffer_head *bh; + int retry; + + do { + retry = 0; + + list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, + bd_ail_st_list) { + bh = bd->bd_bh; + + gfs2_assert(sdp, bd->bd_ail == ai); + + if (!buffer_busy(bh)) { + if (!buffer_uptodate(bh)) + gfs2_io_error_bh(sdp, bh); + list_move(&bd->bd_ail_st_list, + &ai->ai_ail2_list); + continue; + } + + if (!buffer_dirty(bh)) + continue; + + list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list); + + gfs2_log_unlock(sdp); + wait_on_buffer(bh); + ll_rw_block(WRITE, 1, &bh); + gfs2_log_lock(sdp); + + retry = 1; + break; + } + } while (retry); +} + +/** + * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced + * @sdp: the filesystem + * @ai: the AIL entry + * + */ + +int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags) +{ + struct gfs2_bufdata *bd, *s; + struct buffer_head *bh; + + list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, + bd_ail_st_list) { + bh = bd->bd_bh; + + gfs2_assert(sdp, bd->bd_ail == ai); + + if (buffer_busy(bh)) { + if (flags & DIO_ALL) + continue; + else + break; + } + + if (!buffer_uptodate(bh)) + gfs2_io_error_bh(sdp, bh); + + list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); + } + + return list_empty(&ai->ai_ail1_list); +} + +/** + * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced + * @sdp: the filesystem + * @ai: the AIL entry + * + */ + +void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) +{ + struct list_head *head = &ai->ai_ail2_list; + struct gfs2_bufdata *bd; + + while (!list_empty(head)) { + bd = list_entry(head->prev, struct gfs2_bufdata, + bd_ail_st_list); + gfs2_assert(sdp, bd->bd_ail == ai); + bd->bd_ail = NULL; + list_del(&bd->bd_ail_st_list); + list_del(&bd->bd_ail_gl_list); + atomic_dec(&bd->bd_gl->gl_ail_count); + brelse(bd->bd_bh); + } +} + +/** + * ail_empty_gl - remove all buffers for a given lock from the AIL + * @gl: the glock + * + * None of the buffers should be dirty, locked, or pinned. + */ + +void gfs2_ail_empty_gl(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + unsigned int blocks; + struct list_head *head = &gl->gl_ail_list; + struct gfs2_bufdata *bd; + struct buffer_head *bh; + uint64_t blkno; + int error; + + blocks = atomic_read(&gl->gl_ail_count); + if (!blocks) + return; + + error = gfs2_trans_begin(sdp, 0, blocks); + if (gfs2_assert_withdraw(sdp, !error)) + return; + + gfs2_log_lock(sdp); + while (!list_empty(head)) { + bd = list_entry(head->next, struct gfs2_bufdata, + bd_ail_gl_list); + bh = bd->bd_bh; + blkno = bh->b_blocknr; + gfs2_assert_withdraw(sdp, !buffer_busy(bh)); + + bd->bd_ail = NULL; + list_del(&bd->bd_ail_st_list); + list_del(&bd->bd_ail_gl_list); + atomic_dec(&gl->gl_ail_count); + brelse(bh); + gfs2_log_unlock(sdp); + + gfs2_trans_add_revoke(sdp, blkno); + + gfs2_log_lock(sdp); + } + gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count)); + gfs2_log_unlock(sdp); + + gfs2_trans_end(sdp); + gfs2_log_flush(sdp); +} + +/** + * gfs2_meta_inval - Invalidate all buffers associated with a glock + * @gl: the glock + * + */ + +void gfs2_meta_inval(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct inode *aspace = gl->gl_aspace; + struct address_space *mapping = gl->gl_aspace->i_mapping; + + gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count)); + + atomic_inc(&aspace->i_writecount); + truncate_inode_pages(mapping, 0); + atomic_dec(&aspace->i_writecount); + + gfs2_assert_withdraw(sdp, !mapping->nrpages); +} + +/** + * gfs2_meta_sync - Sync all buffers associated with a glock + * @gl: The glock + * @flags: DIO_START | DIO_WAIT + * + */ + +void gfs2_meta_sync(struct gfs2_glock *gl, int flags) +{ + struct address_space *mapping = gl->gl_aspace->i_mapping; + int error = 0; + + if (flags & DIO_START) + filemap_fdatawrite(mapping); + if (!error && (flags & DIO_WAIT)) + error = filemap_fdatawait(mapping); + + if (error) + gfs2_io_error(gl->gl_sbd); +} + +/** + * getbuf - Get a buffer with a given address space + * @sdp: the filesystem + * @aspace: the address space + * @blkno: the block number (filesystem scope) + * @create: 1 if the buffer should be created + * + * Returns: the buffer + */ + +static struct buffer_head *getbuf(struct gfs2_sbd *sdp, struct inode *aspace, + uint64_t blkno, int create) +{ + struct page *page; + struct buffer_head *bh; + unsigned int shift; + unsigned long index; + unsigned int bufnum; + + shift = PAGE_CACHE_SHIFT - sdp->sd_sb.sb_bsize_shift; + index = blkno >> shift; /* convert block to page */ + bufnum = blkno - (index << shift); /* block buf index within page */ + + if (create) { + for (;;) { + page = grab_cache_page(aspace->i_mapping, index); + if (page) + break; + yield(); + } + } else { + page = find_lock_page(aspace->i_mapping, index); + if (!page) + return NULL; + } + + if (!page_has_buffers(page)) + create_empty_buffers(page, sdp->sd_sb.sb_bsize, 0); + + /* Locate header for our buffer within our page */ + for (bh = page_buffers(page); bufnum--; bh = bh->b_this_page) + /* Do nothing */; + get_bh(bh); + + if (!buffer_mapped(bh)) + map_bh(bh, sdp->sd_vfs, blkno); + + unlock_page(page); + mark_page_accessed(page); + page_cache_release(page); + + return bh; +} + +static void meta_prep_new(struct buffer_head *bh) +{ + struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; + + lock_buffer(bh); + clear_buffer_dirty(bh); + set_buffer_uptodate(bh); + unlock_buffer(bh); + + mh->mh_magic = cpu_to_be32(GFS2_MAGIC); +} + +/** + * gfs2_meta_new - Get a block + * @gl: The glock associated with this block + * @blkno: The block number + * + * Returns: The buffer + */ + +struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, uint64_t blkno) +{ + struct buffer_head *bh; + bh = getbuf(gl->gl_sbd, gl->gl_aspace, blkno, CREATE); + meta_prep_new(bh); + return bh; +} + +/** + * gfs2_meta_read - Read a block from disk + * @gl: The glock covering the block + * @blkno: The block number + * @flags: flags to gfs2_dreread() + * @bhp: the place where the buffer is returned (NULL on failure) + * + * Returns: errno + */ + +int gfs2_meta_read(struct gfs2_glock *gl, uint64_t blkno, int flags, + struct buffer_head **bhp) +{ + int error; + + *bhp = getbuf(gl->gl_sbd, gl->gl_aspace, blkno, CREATE); + error = gfs2_meta_reread(gl->gl_sbd, *bhp, flags); + if (error) + brelse(*bhp); + + return error; +} + +/** + * gfs2_meta_reread - Reread a block from disk + * @sdp: the filesystem + * @bh: The block to read + * @flags: Flags that control the read + * + * Returns: errno + */ + +int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags) +{ + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + return -EIO; + + if (flags & DIO_FORCE) + clear_buffer_uptodate(bh); + + if ((flags & DIO_START) && !buffer_uptodate(bh)) + ll_rw_block(READ, 1, &bh); + + if (flags & DIO_WAIT) { + wait_on_buffer(bh); + + if (!buffer_uptodate(bh)) { + struct gfs2_trans *tr = get_transaction; + if (tr && tr->tr_touched) + gfs2_io_error_bh(sdp, bh); + return -EIO; + } + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + return -EIO; + } + + return 0; +} + +/** + * gfs2_meta_attach_bufdata - attach a struct gfs2_bufdata structure to a buffer + * @gl: the glock the buffer belongs to + * @bh: The buffer to be attached to + * + */ + +void gfs2_meta_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh) +{ + struct gfs2_bufdata *bd; + + lock_page(bh->b_page); + + if (get_v2bd(bh)) { + unlock_page(bh->b_page); + return; + } + + bd = kmem_cache_alloc(gfs2_bufdata_cachep, GFP_KERNEL | __GFP_NOFAIL), + atomic_inc(&gl->gl_sbd->sd_bufdata_count); + + memset(bd, 0, sizeof(struct gfs2_bufdata)); + + bd->bd_bh = bh; + bd->bd_gl = gl; + + INIT_LIST_HEAD(&bd->bd_list_tr); + lops_init_le(&bd->bd_le, &gfs2_buf_lops); + + set_v2bd(bh, bd); + + unlock_page(bh->b_page); +} + +/** + * gfs2_meta_pin - Pin a metadata buffer in memory + * @sdp: the filesystem the buffer belongs to + * @bh: The buffer to be pinned + * + */ + +void gfs2_meta_pin(struct gfs2_sbd *sdp, struct buffer_head *bh) +{ + struct gfs2_bufdata *bd = get_v2bd(bh); + + gfs2_assert_withdraw(sdp, test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)); + + if (test_set_buffer_pinned(bh)) + gfs2_assert_withdraw(sdp, 0); + + wait_on_buffer(bh); + + /* If this buffer is in the AIL and it has already been written + to in-place disk block, remove it from the AIL. */ + + gfs2_log_lock(sdp); + if (bd->bd_ail && !buffer_in_io(bh)) + list_move(&bd->bd_ail_st_list, &bd->bd_ail->ai_ail2_list); + gfs2_log_unlock(sdp); + + clear_buffer_dirty(bh); + wait_on_buffer(bh); + + if (!buffer_uptodate(bh)) + gfs2_io_error_bh(sdp, bh); + + get_bh(bh); +} + +/** + * gfs2_meta_unpin - Unpin a buffer + * @sdp: the filesystem the buffer belongs to + * @bh: The buffer to unpin + * @ai: + * + */ + +void gfs2_meta_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, + struct gfs2_ail *ai) +{ + struct gfs2_bufdata *bd = get_v2bd(bh); + + gfs2_assert_withdraw(sdp, buffer_uptodate(bh)); + + if (!buffer_pinned(bh)) + gfs2_assert_withdraw(sdp, 0); + + mark_buffer_dirty(bh); + clear_buffer_pinned(bh); + + gfs2_log_lock(sdp); + if (bd->bd_ail) { + list_del(&bd->bd_ail_st_list); + brelse(bh); + } else { + struct gfs2_glock *gl = bd->bd_gl; + list_add(&bd->bd_ail_gl_list, &gl->gl_ail_list); + atomic_inc(&gl->gl_ail_count); + } + bd->bd_ail = ai; + list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list); + gfs2_log_unlock(sdp); +} + +/** + * gfs2_meta_wipe - make inode's buffers so they aren't dirty/pinned anymore + * @ip: the inode who owns the buffers + * @bstart: the first buffer in the run + * @blen: the number of buffers in the run + * + */ + +void gfs2_meta_wipe(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct inode *aspace = ip->i_gl->gl_aspace; + struct buffer_head *bh; + + while (blen) { + bh = getbuf(sdp, aspace, bstart, NO_CREATE); + if (bh) { + struct gfs2_bufdata *bd = get_v2bd(bh); + + if (test_clear_buffer_pinned(bh)) { + gfs2_log_lock(sdp); + list_del_init(&bd->bd_le.le_list); + gfs2_assert_warn(sdp, sdp->sd_log_num_buf); + sdp->sd_log_num_buf--; + gfs2_log_unlock(sdp); + get_transaction->tr_num_buf_rm++; + brelse(bh); + } + if (bd) { + gfs2_log_lock(sdp); + if (bd->bd_ail) { + uint64_t blkno = bh->b_blocknr; + bd->bd_ail = NULL; + list_del(&bd->bd_ail_st_list); + list_del(&bd->bd_ail_gl_list); + atomic_dec(&bd->bd_gl->gl_ail_count); + brelse(bh); + gfs2_log_unlock(sdp); + gfs2_trans_add_revoke(sdp, blkno); + } else + gfs2_log_unlock(sdp); + } + + lock_buffer(bh); + clear_buffer_dirty(bh); + clear_buffer_uptodate(bh); + unlock_buffer(bh); + + brelse(bh); + } + + bstart++; + blen--; + } +} + +/** + * gfs2_meta_cache_flush - get rid of any references on buffers for this inode + * @ip: The GFS2 inode + * + * This releases buffers that are in the most-recently-used array of + * blocks used for indirect block addressing for this inode. + */ + +void gfs2_meta_cache_flush(struct gfs2_inode *ip) +{ + struct buffer_head **bh_slot; + unsigned int x; + + spin_lock(&ip->i_spin); + + for (x = 0; x < GFS2_MAX_META_HEIGHT; x++) { + bh_slot = &ip->i_cache[x]; + if (!*bh_slot) + break; + brelse(*bh_slot); + *bh_slot = NULL; + } + + spin_unlock(&ip->i_spin); +} + +/** + * gfs2_meta_indirect_buffer - Get a metadata buffer + * @ip: The GFS2 inode + * @height: The level of this buf in the metadata (indir addr) tree (if any) + * @num: The block number (device relative) of the buffer + * @new: Non-zero if we may create a new buffer + * @bhp: the buffer is returned here + * + * Try to use the gfs2_inode's MRU metadata tree cache. + * + * Returns: errno + */ + +int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num, + int new, struct buffer_head **bhp) +{ + struct buffer_head *bh, **bh_slot = ip->i_cache + height; + int error; + + spin_lock(&ip->i_spin); + bh = *bh_slot; + if (bh) { + if (bh->b_blocknr == num) + get_bh(bh); + else + bh = NULL; + } + spin_unlock(&ip->i_spin); + + if (bh) { + if (new) + meta_prep_new(bh); + else { + error = gfs2_meta_reread(ip->i_sbd, bh, + DIO_START | DIO_WAIT); + if (error) { + brelse(bh); + return error; + } + } + } else { + if (new) + bh = gfs2_meta_new(ip->i_gl, num); + else { + error = gfs2_meta_read(ip->i_gl, num, + DIO_START | DIO_WAIT, &bh); + if (error) + return error; + } + + spin_lock(&ip->i_spin); + if (*bh_slot != bh) { + brelse(*bh_slot); + *bh_slot = bh; + get_bh(bh); + } + spin_unlock(&ip->i_spin); + } + + if (new) { + if (gfs2_assert_warn(ip->i_sbd, height)) { + brelse(bh); + return -EIO; + } + gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); + gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); + + } else if (gfs2_metatype_check(ip->i_sbd, bh, + (height) ? GFS2_METATYPE_IN : GFS2_METATYPE_DI)) { + brelse(bh); + return -EIO; + } + + *bhp = bh; + + return 0; +} + +/** + * gfs2_meta_ra - start readahead on an extent of a file + * @gl: the glock the blocks belong to + * @dblock: the starting disk block + * @extlen: the number of blocks in the extent + * + */ + +void gfs2_meta_ra(struct gfs2_glock *gl, uint64_t dblock, uint32_t extlen) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct inode *aspace = gl->gl_aspace; + struct buffer_head *first_bh, *bh; + uint32_t max_ra = gfs2_tune_get(sdp, gt_max_readahead) >> sdp->sd_sb.sb_bsize_shift; + int error; + + if (!extlen || !max_ra) + return; + if (extlen > max_ra) + extlen = max_ra; + + first_bh = getbuf(sdp, aspace, dblock, CREATE); + + if (buffer_uptodate(first_bh)) + goto out; + if (!buffer_locked(first_bh)) { + error = gfs2_meta_reread(sdp, first_bh, DIO_START); + if (error) + goto out; + } + + dblock++; + extlen--; + + while (extlen) { + bh = getbuf(sdp, aspace, dblock, CREATE); + + if (!buffer_uptodate(bh) && !buffer_locked(bh)) { + error = gfs2_meta_reread(sdp, bh, DIO_START); + brelse(bh); + if (error) + goto out; + } else + brelse(bh); + + dblock++; + extlen--; + + if (buffer_uptodate(first_bh)) + break; + } + + out: + brelse(first_bh); +} + +/** + * gfs2_meta_syncfs - sync all the buffers in a filesystem + * @sdp: the filesystem + * + */ + +void gfs2_meta_syncfs(struct gfs2_sbd *sdp) +{ + gfs2_log_flush(sdp); + for (;;) { + gfs2_ail1_start(sdp, DIO_ALL); + if (gfs2_ail1_empty(sdp, DIO_ALL)) + break; + msleep(100); + } +} + diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h new file mode 100644 index 000000000000..5556df8cc6c9 --- /dev/null +++ b/fs/gfs2/meta_io.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __DIO_DOT_H__ +#define __DIO_DOT_H__ + +static inline void gfs2_buffer_clear(struct buffer_head *bh) +{ + memset(bh->b_data, 0, bh->b_size); +} + +static inline void gfs2_buffer_clear_tail(struct buffer_head *bh, int head) +{ + memset(bh->b_data + head, 0, bh->b_size - head); +} + +static inline void gfs2_buffer_clear_ends(struct buffer_head *bh, int offset, + int amount, int journaled) +{ + int z_off1 = (journaled) ? sizeof(struct gfs2_meta_header) : 0; + int z_len1 = offset - z_off1; + int z_off2 = offset + amount; + int z_len2 = (bh)->b_size - z_off2; + + if (z_len1) + memset(bh->b_data + z_off1, 0, z_len1); + + if (z_len2) + memset(bh->b_data + z_off2, 0, z_len2); +} + +static inline void gfs2_buffer_copy_tail(struct buffer_head *to_bh, + int to_head, + struct buffer_head *from_bh, + int from_head) +{ + memcpy(to_bh->b_data + to_head, + from_bh->b_data + from_head, + from_bh->b_size - from_head); + memset(to_bh->b_data + to_bh->b_size + to_head - from_head, + 0, + from_head - to_head); +} + +struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp); +void gfs2_aspace_put(struct inode *aspace); + +void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai); +int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags); +void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai); +void gfs2_ail_empty_gl(struct gfs2_glock *gl); + +void gfs2_meta_inval(struct gfs2_glock *gl); +void gfs2_meta_sync(struct gfs2_glock *gl, int flags); + +struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, uint64_t blkno); +int gfs2_meta_read(struct gfs2_glock *gl, uint64_t blkno, + int flags, struct buffer_head **bhp); +int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags); + +void gfs2_meta_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh); +void gfs2_meta_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); +void gfs2_meta_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, + struct gfs2_ail *ai); + +void gfs2_meta_wipe(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); + +void gfs2_meta_cache_flush(struct gfs2_inode *ip); +int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num, + int new, struct buffer_head **bhp); + +static inline int gfs2_meta_inode_buffer(struct gfs2_inode *ip, + struct buffer_head **bhp) +{ + return gfs2_meta_indirect_buffer(ip, 0, ip->i_num.no_addr, 0, bhp); +} + +void gfs2_meta_ra(struct gfs2_glock *gl, uint64_t dblock, uint32_t extlen); +void gfs2_meta_syncfs(struct gfs2_sbd *sdp); + +#endif /* __DIO_DOT_H__ */ + diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c new file mode 100644 index 000000000000..3e42697aafc7 --- /dev/null +++ b/fs/gfs2/mount.c @@ -0,0 +1,211 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "mount.h" +#include "sys.h" + +/** + * gfs2_mount_args - Parse mount options + * @sdp: + * @data: + * + * Return: errno + */ + +int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount) +{ + struct gfs2_args *args = &sdp->sd_args; + char *data = data_arg; + char *options, *o, *v; + int error = 0; + + if (!remount) { + /* If someone preloaded options, use those instead */ + spin_lock(&gfs2_sys_margs_lock); + if (gfs2_sys_margs) { + data = gfs2_sys_margs; + gfs2_sys_margs = NULL; + } + spin_unlock(&gfs2_sys_margs_lock); + + /* Set some defaults */ + args->ar_num_glockd = GFS2_GLOCKD_DEFAULT; + args->ar_quota = GFS2_QUOTA_DEFAULT; + args->ar_data = GFS2_DATA_DEFAULT; + } + + /* Split the options into tokens with the "," character and + process them */ + + for (options = data; (o = strsep(&options, ",")); ) { + if (!*o) + continue; + + v = strchr(o, '='); + if (v) + *v++ = 0; + + if (!strcmp(o, "lockproto")) { + if (!v) + goto need_value; + if (remount && strcmp(v, args->ar_lockproto)) + goto cant_remount; + strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN); + args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0; + } + + else if (!strcmp(o, "locktable")) { + if (!v) + goto need_value; + if (remount && strcmp(v, args->ar_locktable)) + goto cant_remount; + strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN); + args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0; + } + + else if (!strcmp(o, "hostdata")) { + if (!v) + goto need_value; + if (remount && strcmp(v, args->ar_hostdata)) + goto cant_remount; + strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN); + args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0; + } + + else if (!strcmp(o, "spectator")) { + if (remount && !args->ar_spectator) + goto cant_remount; + args->ar_spectator = 1; + sdp->sd_vfs->s_flags |= MS_RDONLY; + } + + else if (!strcmp(o, "ignore_local_fs")) { + if (remount && !args->ar_ignore_local_fs) + goto cant_remount; + args->ar_ignore_local_fs = 1; + } + + else if (!strcmp(o, "localflocks")) { + if (remount && !args->ar_localflocks) + goto cant_remount; + args->ar_localflocks = 1; + } + + else if (!strcmp(o, "localcaching")) { + if (remount && !args->ar_localcaching) + goto cant_remount; + args->ar_localcaching = 1; + } + + else if (!strcmp(o, "debug")) + args->ar_debug = 1; + + else if (!strcmp(o, "nodebug")) + args->ar_debug = 0; + + else if (!strcmp(o, "upgrade")) { + if (remount && !args->ar_upgrade) + goto cant_remount; + args->ar_upgrade = 1; + } + + else if (!strcmp(o, "num_glockd")) { + unsigned int x; + if (!v) + goto need_value; + sscanf(v, "%u", &x); + if (remount && x != args->ar_num_glockd) + goto cant_remount; + if (!x || x > GFS2_GLOCKD_MAX) { + fs_info(sdp, "0 < num_glockd <= %u (not %u)\n", + GFS2_GLOCKD_MAX, x); + error = -EINVAL; + break; + } + args->ar_num_glockd = x; + } + + else if (!strcmp(o, "acl")) { + args->ar_posix_acl = 1; + sdp->sd_vfs->s_flags |= MS_POSIXACL; + } + + else if (!strcmp(o, "noacl")) { + args->ar_posix_acl = 0; + sdp->sd_vfs->s_flags &= ~MS_POSIXACL; + } + + else if (!strcmp(o, "quota")) { + if (!v) + goto need_value; + if (!strcmp(v, "off")) + args->ar_quota = GFS2_QUOTA_OFF; + else if (!strcmp(v, "account")) + args->ar_quota = GFS2_QUOTA_ACCOUNT; + else if (!strcmp(v, "on")) + args->ar_quota = GFS2_QUOTA_ON; + else { + fs_info(sdp, "invalid value for quota\n"); + error = -EINVAL; + break; + } + } + + else if (!strcmp(o, "suiddir")) + args->ar_suiddir = 1; + + else if (!strcmp(o, "nosuiddir")) + args->ar_suiddir = 0; + + else if (!strcmp(o, "data")) { + if (!v) + goto need_value; + if (!strcmp(v, "writeback")) + args->ar_data = GFS2_DATA_WRITEBACK; + else if (!strcmp(v, "ordered")) + args->ar_data = GFS2_DATA_ORDERED; + else { + fs_info(sdp, "invalid value for data\n"); + error = -EINVAL; + break; + } + } + + else { + fs_info(sdp, "unknown option: %s\n", o); + error = -EINVAL; + break; + } + } + + if (error) + fs_info(sdp, "invalid mount option(s)\n"); + + if (data != data_arg) + kfree(data); + + return error; + + need_value: + fs_info(sdp, "need value for option %s\n", o); + return -EINVAL; + + cant_remount: + fs_info(sdp, "can't remount with option %s\n", o); + return -EINVAL; +} + diff --git a/fs/gfs2/mount.h b/fs/gfs2/mount.h new file mode 100644 index 000000000000..bc8331cd7b2c --- /dev/null +++ b/fs/gfs2/mount.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __MOUNT_DOT_H__ +#define __MOUNT_DOT_H__ + +int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount); + +#endif /* __MOUNT_DOT_H__ */ diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c new file mode 100644 index 000000000000..2a1ef5aa7f0c --- /dev/null +++ b/fs/gfs2/ondisk.c @@ -0,0 +1,590 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include + +#define pv(struct, member, fmt) printk(" "#member" = "fmt"\n", struct->member); +#define pa(struct, member, count) print_array(#member, struct->member, count); + +/** + * print_array - Print out an array of bytes + * @title: what to print before the array + * @buf: the array + * @count: the number of bytes + * + */ + +static void print_array(char *title, char *buf, int count) +{ + int x; + + printk(" %s =\n", title); + for (x = 0; x < count; x++) { + printk("%.2X ", (unsigned char)buf[x]); + if (x % 16 == 15) + printk("\n"); + } + if (x % 16) + printk("\n"); +} + +/* + * gfs2_xxx_in - read in an xxx struct + * first arg: the cpu-order structure + * buf: the disk-order buffer + * + * gfs2_xxx_out - write out an xxx struct + * first arg: the cpu-order structure + * buf: the disk-order buffer + * + * gfs2_xxx_print - print out an xxx struct + * first arg: the cpu-order structure + */ + +void gfs2_inum_in(struct gfs2_inum *no, char *buf) +{ + struct gfs2_inum *str = (struct gfs2_inum *)buf; + + no->no_formal_ino = be64_to_cpu(str->no_formal_ino); + no->no_addr = be64_to_cpu(str->no_addr); +} + +void gfs2_inum_out(struct gfs2_inum *no, char *buf) +{ + struct gfs2_inum *str = (struct gfs2_inum *)buf; + + str->no_formal_ino = cpu_to_be64(no->no_formal_ino); + str->no_addr = cpu_to_be64(no->no_addr); +} + +void gfs2_inum_print(struct gfs2_inum *no) +{ + pv(no, no_formal_ino, "%llu"); + pv(no, no_addr, "%llu"); +} + +void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf) +{ + struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf; + + mh->mh_magic = be32_to_cpu(str->mh_magic); + mh->mh_type = be16_to_cpu(str->mh_type); + mh->mh_format = be16_to_cpu(str->mh_format); +} + +void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf) +{ + struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf; + + str->mh_magic = cpu_to_be32(mh->mh_magic); + str->mh_type = cpu_to_be16(mh->mh_type); + str->mh_format = cpu_to_be16(mh->mh_format); +} + +void gfs2_meta_header_print(struct gfs2_meta_header *mh) +{ + pv(mh, mh_magic, "0x%.8X"); + pv(mh, mh_type, "%u"); + pv(mh, mh_format, "%u"); +} + +void gfs2_sb_in(struct gfs2_sb *sb, char *buf) +{ + struct gfs2_sb *str = (struct gfs2_sb *)buf; + + gfs2_meta_header_in(&sb->sb_header, buf); + + sb->sb_fs_format = be32_to_cpu(str->sb_fs_format); + sb->sb_multihost_format = be32_to_cpu(str->sb_multihost_format); + sb->sb_bsize = be32_to_cpu(str->sb_bsize); + sb->sb_bsize_shift = be32_to_cpu(str->sb_bsize_shift); + + gfs2_inum_in(&sb->sb_master_dir, (char *)&str->sb_master_dir); + gfs2_inum_in(&sb->sb_root_dir, (char *)&str->sb_root_dir); + + memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN); + memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN); +} + +void gfs2_sb_out(struct gfs2_sb *sb, char *buf) +{ + struct gfs2_sb *str = (struct gfs2_sb *)buf; + + gfs2_meta_header_out(&sb->sb_header, buf); + + str->sb_fs_format = cpu_to_be32(sb->sb_fs_format); + str->sb_multihost_format = cpu_to_be32(sb->sb_multihost_format); + str->sb_bsize = cpu_to_be32(sb->sb_bsize); + str->sb_bsize_shift = cpu_to_be32(sb->sb_bsize_shift); + + gfs2_inum_out(&sb->sb_master_dir, (char *)&str->sb_master_dir); + gfs2_inum_out(&sb->sb_root_dir, (char *)&str->sb_root_dir); + + memcpy(str->sb_lockproto, sb->sb_lockproto, GFS2_LOCKNAME_LEN); + memcpy(str->sb_locktable, sb->sb_locktable, GFS2_LOCKNAME_LEN); +} + +void gfs2_sb_print(struct gfs2_sb *sb) +{ + gfs2_meta_header_print(&sb->sb_header); + + pv(sb, sb_fs_format, "%u"); + pv(sb, sb_multihost_format, "%u"); + + pv(sb, sb_bsize, "%u"); + pv(sb, sb_bsize_shift, "%u"); + + gfs2_inum_print(&sb->sb_master_dir); + + pv(sb, sb_lockproto, "%s"); + pv(sb, sb_locktable, "%s"); +} + +void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf) +{ + struct gfs2_rindex *str = (struct gfs2_rindex *)buf; + + ri->ri_addr = be64_to_cpu(str->ri_addr); + ri->ri_length = be32_to_cpu(str->ri_length); + ri->ri_data0 = be64_to_cpu(str->ri_data0); + ri->ri_data = be32_to_cpu(str->ri_data); + ri->ri_bitbytes = be32_to_cpu(str->ri_bitbytes); + +} + +void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf) +{ + struct gfs2_rindex *str = (struct gfs2_rindex *)buf; + + str->ri_addr = cpu_to_be64(ri->ri_addr); + str->ri_length = cpu_to_be32(ri->ri_length); + str->__pad = 0; + + str->ri_data0 = cpu_to_be64(ri->ri_data0); + str->ri_data = cpu_to_be32(ri->ri_data); + str->ri_bitbytes = cpu_to_be32(ri->ri_bitbytes); + memset(str->ri_reserved, 0, sizeof(str->ri_reserved)); +} + +void gfs2_rindex_print(struct gfs2_rindex *ri) +{ + pv(ri, ri_addr, "%llu"); + pv(ri, ri_length, "%u"); + + pv(ri, ri_data0, "%llu"); + pv(ri, ri_data, "%u"); + + pv(ri, ri_bitbytes, "%u"); +} + +void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf) +{ + struct gfs2_rgrp *str = (struct gfs2_rgrp *)buf; + + gfs2_meta_header_in(&rg->rg_header, buf); + rg->rg_flags = be32_to_cpu(str->rg_flags); + rg->rg_free = be32_to_cpu(str->rg_free); + rg->rg_dinodes = be32_to_cpu(str->rg_dinodes); +} + +void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf) +{ + struct gfs2_rgrp *str = (struct gfs2_rgrp *)buf; + + gfs2_meta_header_out(&rg->rg_header, buf); + str->rg_flags = cpu_to_be32(rg->rg_flags); + str->rg_free = cpu_to_be32(rg->rg_free); + str->rg_dinodes = cpu_to_be32(rg->rg_dinodes); + + memset(&str->rg_reserved, 0, sizeof(str->rg_reserved)); +} + +void gfs2_rgrp_print(struct gfs2_rgrp *rg) +{ + gfs2_meta_header_print(&rg->rg_header); + pv(rg, rg_flags, "%u"); + pv(rg, rg_free, "%u"); + pv(rg, rg_dinodes, "%u"); + + pa(rg, rg_reserved, 36); +} + +void gfs2_quota_in(struct gfs2_quota *qu, char *buf) +{ + struct gfs2_quota *str = (struct gfs2_quota *)buf; + + qu->qu_limit = be64_to_cpu(str->qu_limit); + qu->qu_warn = be64_to_cpu(str->qu_warn); + qu->qu_value = be64_to_cpu(str->qu_value); +} + +void gfs2_quota_out(struct gfs2_quota *qu, char *buf) +{ + struct gfs2_quota *str = (struct gfs2_quota *)buf; + + str->qu_limit = cpu_to_be64(qu->qu_limit); + str->qu_warn = cpu_to_be64(qu->qu_warn); + str->qu_value = cpu_to_be64(qu->qu_value); +} + +void gfs2_quota_print(struct gfs2_quota *qu) +{ + pv(qu, qu_limit, "%llu"); + pv(qu, qu_warn, "%llu"); + pv(qu, qu_value, "%lld"); +} + +void gfs2_dinode_in(struct gfs2_dinode *di, char *buf) +{ + struct gfs2_dinode *str = (struct gfs2_dinode *)buf; + + gfs2_meta_header_in(&di->di_header, buf); + gfs2_inum_in(&di->di_num, (char *)&str->di_num); + + di->di_mode = be32_to_cpu(str->di_mode); + di->di_uid = be32_to_cpu(str->di_uid); + di->di_gid = be32_to_cpu(str->di_gid); + di->di_nlink = be32_to_cpu(str->di_nlink); + di->di_size = be64_to_cpu(str->di_size); + di->di_blocks = be64_to_cpu(str->di_blocks); + di->di_atime = be64_to_cpu(str->di_atime); + di->di_mtime = be64_to_cpu(str->di_mtime); + di->di_ctime = be64_to_cpu(str->di_ctime); + di->di_major = be32_to_cpu(str->di_major); + di->di_minor = be32_to_cpu(str->di_minor); + + di->di_goal_meta = be64_to_cpu(str->di_goal_meta); + di->di_goal_data = be64_to_cpu(str->di_goal_data); + + di->di_flags = be32_to_cpu(str->di_flags); + di->di_payload_format = be32_to_cpu(str->di_payload_format); + di->di_height = be16_to_cpu(str->di_height); + + di->di_depth = be16_to_cpu(str->di_depth); + di->di_entries = be32_to_cpu(str->di_entries); + + di->di_eattr = be64_to_cpu(str->di_eattr); + +} + +void gfs2_dinode_out(struct gfs2_dinode *di, char *buf) +{ + struct gfs2_dinode *str = (struct gfs2_dinode *)buf; + + gfs2_meta_header_out(&di->di_header, buf); + gfs2_inum_out(&di->di_num, (char *)&str->di_num); + + str->di_mode = cpu_to_be32(di->di_mode); + str->di_uid = cpu_to_be32(di->di_uid); + str->di_gid = cpu_to_be32(di->di_gid); + str->di_nlink = cpu_to_be32(di->di_nlink); + str->di_size = cpu_to_be64(di->di_size); + str->di_blocks = cpu_to_be64(di->di_blocks); + str->di_atime = cpu_to_be64(di->di_atime); + str->di_mtime = cpu_to_be64(di->di_mtime); + str->di_ctime = cpu_to_be64(di->di_ctime); + str->di_major = cpu_to_be32(di->di_major); + str->di_minor = cpu_to_be32(di->di_minor); + + str->di_goal_meta = cpu_to_be64(di->di_goal_meta); + str->di_goal_data = cpu_to_be64(di->di_goal_data); + + str->di_flags = cpu_to_be32(di->di_flags); + str->di_payload_format = cpu_to_be32(di->di_payload_format); + str->di_height = cpu_to_be16(di->di_height); + + str->di_depth = cpu_to_be16(di->di_depth); + str->di_entries = cpu_to_be32(di->di_entries); + + str->di_eattr = cpu_to_be64(di->di_eattr); + +} + +void gfs2_dinode_print(struct gfs2_dinode *di) +{ + gfs2_meta_header_print(&di->di_header); + gfs2_inum_print(&di->di_num); + + pv(di, di_mode, "0%o"); + pv(di, di_uid, "%u"); + pv(di, di_gid, "%u"); + pv(di, di_nlink, "%u"); + pv(di, di_size, "%llu"); + pv(di, di_blocks, "%llu"); + pv(di, di_atime, "%lld"); + pv(di, di_mtime, "%lld"); + pv(di, di_ctime, "%lld"); + pv(di, di_major, "%u"); + pv(di, di_minor, "%u"); + + pv(di, di_goal_meta, "%llu"); + pv(di, di_goal_data, "%llu"); + + pv(di, di_flags, "0x%.8X"); + pv(di, di_payload_format, "%u"); + pv(di, di_height, "%u"); + + pv(di, di_depth, "%u"); + pv(di, di_entries, "%u"); + + pv(di, di_eattr, "%llu"); +} + +void gfs2_dirent_in(struct gfs2_dirent *de, char *buf) +{ + struct gfs2_dirent *str = (struct gfs2_dirent *)buf; + + gfs2_inum_in(&de->de_inum, buf); + de->de_hash = be32_to_cpu(str->de_hash); + de->de_rec_len = be32_to_cpu(str->de_rec_len); + de->de_name_len = str->de_name_len; + de->de_type = str->de_type; +} + +void gfs2_dirent_out(struct gfs2_dirent *de, char *buf) +{ + struct gfs2_dirent *str = (struct gfs2_dirent *)buf; + + gfs2_inum_out(&de->de_inum, buf); + str->de_hash = cpu_to_be32(de->de_hash); + str->de_rec_len = cpu_to_be32(de->de_rec_len); + str->de_name_len = de->de_name_len; + str->de_type = de->de_type; + str->__pad1 = 0; + str->__pad2 = 0; +} + +void gfs2_dirent_print(struct gfs2_dirent *de, char *name) +{ + char buf[GFS2_FNAMESIZE + 1]; + + gfs2_inum_print(&de->de_inum); + pv(de, de_hash, "0x%.8X"); + pv(de, de_rec_len, "%u"); + pv(de, de_name_len, "%u"); + pv(de, de_type, "%u"); + + memset(buf, 0, GFS2_FNAMESIZE + 1); + memcpy(buf, name, de->de_name_len); + printk(" name = %s\n", buf); +} + +void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf) +{ + struct gfs2_leaf *str = (struct gfs2_leaf *)buf; + + gfs2_meta_header_in(&lf->lf_header, buf); + lf->lf_depth = be16_to_cpu(str->lf_depth); + lf->lf_entries = be16_to_cpu(str->lf_entries); + lf->lf_dirent_format = be32_to_cpu(str->lf_dirent_format); + lf->lf_next = be64_to_cpu(str->lf_next); +} + +void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf) +{ + struct gfs2_leaf *str = (struct gfs2_leaf *)buf; + + gfs2_meta_header_out(&lf->lf_header, buf); + str->lf_depth = cpu_to_be16(lf->lf_depth); + str->lf_entries = cpu_to_be16(lf->lf_entries); + str->lf_dirent_format = cpu_to_be32(lf->lf_dirent_format); + str->lf_next = cpu_to_be64(lf->lf_next); + memset(&str->lf_reserved, 0, sizeof(str->lf_reserved)); +} + +void gfs2_leaf_print(struct gfs2_leaf *lf) +{ + gfs2_meta_header_print(&lf->lf_header); + pv(lf, lf_depth, "%u"); + pv(lf, lf_entries, "%u"); + pv(lf, lf_dirent_format, "%u"); + pv(lf, lf_next, "%llu"); + + pa(lf, lf_reserved, 32); +} + +void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf) +{ + struct gfs2_ea_header *str = (struct gfs2_ea_header *)buf; + + ea->ea_rec_len = be32_to_cpu(str->ea_rec_len); + ea->ea_data_len = be32_to_cpu(str->ea_data_len); + ea->ea_name_len = str->ea_name_len; + ea->ea_type = str->ea_type; + ea->ea_flags = str->ea_flags; + ea->ea_num_ptrs = str->ea_num_ptrs; +} + +void gfs2_ea_header_out(struct gfs2_ea_header *ea, char *buf) +{ + struct gfs2_ea_header *str = (struct gfs2_ea_header *)buf; + + str->ea_rec_len = cpu_to_be32(ea->ea_rec_len); + str->ea_data_len = cpu_to_be32(ea->ea_data_len); + str->ea_name_len = ea->ea_name_len; + str->ea_type = ea->ea_type; + str->ea_flags = ea->ea_flags; + str->ea_num_ptrs = ea->ea_num_ptrs; + str->__pad = 0; +} + +void gfs2_ea_header_print(struct gfs2_ea_header *ea, char *name) +{ + char buf[GFS2_EA_MAX_NAME_LEN + 1]; + + pv(ea, ea_rec_len, "%u"); + pv(ea, ea_data_len, "%u"); + pv(ea, ea_name_len, "%u"); + pv(ea, ea_type, "%u"); + pv(ea, ea_flags, "%u"); + pv(ea, ea_num_ptrs, "%u"); + + memset(buf, 0, GFS2_EA_MAX_NAME_LEN + 1); + memcpy(buf, name, ea->ea_name_len); + printk(" name = %s\n", buf); +} + +void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf) +{ + struct gfs2_log_header *str = (struct gfs2_log_header *)buf; + + gfs2_meta_header_in(&lh->lh_header, buf); + lh->lh_sequence = be64_to_cpu(str->lh_sequence); + lh->lh_flags = be32_to_cpu(str->lh_flags); + lh->lh_tail = be32_to_cpu(str->lh_tail); + lh->lh_blkno = be32_to_cpu(str->lh_blkno); + lh->lh_hash = be32_to_cpu(str->lh_hash); +} + +void gfs2_log_header_print(struct gfs2_log_header *lh) +{ + gfs2_meta_header_print(&lh->lh_header); + pv(lh, lh_sequence, "%llu"); + pv(lh, lh_flags, "0x%.8X"); + pv(lh, lh_tail, "%u"); + pv(lh, lh_blkno, "%u"); + pv(lh, lh_hash, "0x%.8X"); +} + +void gfs2_log_descriptor_print(struct gfs2_log_descriptor *ld) +{ + gfs2_meta_header_print(&ld->ld_header); + pv(ld, ld_type, "%u"); + pv(ld, ld_length, "%u"); + pv(ld, ld_data1, "%u"); + pv(ld, ld_data2, "%u"); + + pa(ld, ld_reserved, 32); +} + +void gfs2_inum_range_in(struct gfs2_inum_range *ir, char *buf) +{ + struct gfs2_inum_range *str = (struct gfs2_inum_range *)buf; + + ir->ir_start = be64_to_cpu(str->ir_start); + ir->ir_length = be64_to_cpu(str->ir_length); +} + +void gfs2_inum_range_out(struct gfs2_inum_range *ir, char *buf) +{ + struct gfs2_inum_range *str = (struct gfs2_inum_range *)buf; + + str->ir_start = cpu_to_be64(ir->ir_start); + str->ir_length = cpu_to_be64(ir->ir_length); +} + +void gfs2_inum_range_print(struct gfs2_inum_range *ir) +{ + pv(ir, ir_start, "%llu"); + pv(ir, ir_length, "%llu"); +} + +void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, char *buf) +{ + struct gfs2_statfs_change *str = (struct gfs2_statfs_change *)buf; + + sc->sc_total = be64_to_cpu(str->sc_total); + sc->sc_free = be64_to_cpu(str->sc_free); + sc->sc_dinodes = be64_to_cpu(str->sc_dinodes); +} + +void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf) +{ + struct gfs2_statfs_change *str = (struct gfs2_statfs_change *)buf; + + str->sc_total = cpu_to_be64(sc->sc_total); + str->sc_free = cpu_to_be64(sc->sc_free); + str->sc_dinodes = cpu_to_be64(sc->sc_dinodes); +} + +void gfs2_statfs_change_print(struct gfs2_statfs_change *sc) +{ + pv(sc, sc_total, "%lld"); + pv(sc, sc_free, "%lld"); + pv(sc, sc_dinodes, "%lld"); +} + +void gfs2_unlinked_tag_in(struct gfs2_unlinked_tag *ut, char *buf) +{ + struct gfs2_unlinked_tag *str = (struct gfs2_unlinked_tag *)buf; + + gfs2_inum_in(&ut->ut_inum, buf); + ut->ut_flags = be32_to_cpu(str->ut_flags); +} + +void gfs2_unlinked_tag_out(struct gfs2_unlinked_tag *ut, char *buf) +{ + struct gfs2_unlinked_tag *str = (struct gfs2_unlinked_tag *)buf; + + gfs2_inum_out(&ut->ut_inum, buf); + str->ut_flags = cpu_to_be32(ut->ut_flags); + str->__pad = 0; +} + +void gfs2_unlinked_tag_print(struct gfs2_unlinked_tag *ut) +{ + gfs2_inum_print(&ut->ut_inum); + pv(ut, ut_flags, "%u"); +} + +void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf) +{ + struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf; + + qc->qc_change = be64_to_cpu(str->qc_change); + qc->qc_flags = be32_to_cpu(str->qc_flags); + qc->qc_id = be32_to_cpu(str->qc_id); +} + +void gfs2_quota_change_out(struct gfs2_quota_change *qc, char *buf) +{ + struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf; + + str->qc_change = cpu_to_be64(qc->qc_change); + str->qc_flags = cpu_to_be32(qc->qc_flags); + str->qc_id = cpu_to_be32(qc->qc_id); +} + +void gfs2_quota_change_print(struct gfs2_quota_change *qc) +{ + pv(qc, qc_change, "%lld"); + pv(qc, qc_flags, "0x%.8X"); + pv(qc, qc_id, "%u"); +} + + + diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c new file mode 100644 index 000000000000..0aa5f140ddb1 --- /dev/null +++ b/fs/gfs2/ops_address.c @@ -0,0 +1,515 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "glock.h" +#include "inode.h" +#include "jdata.h" +#include "log.h" +#include "meta_io.h" +#include "ops_address.h" +#include "page.h" +#include "quota.h" +#include "trans.h" + +/** + * get_block - Fills in a buffer head with details about a block + * @inode: The inode + * @lblock: The block number to look up + * @bh_result: The buffer head to return the result in + * @create: Non-zero if we may add block to the file + * + * Returns: errno + */ + +static int get_block(struct inode *inode, sector_t lblock, + struct buffer_head *bh_result, int create) +{ + struct gfs2_inode *ip = get_v2ip(inode); + int new = create; + uint64_t dblock; + int error; + + error = gfs2_block_map(ip, lblock, &new, &dblock, NULL); + if (error) + return error; + + if (!dblock) + return 0; + + map_bh(bh_result, inode->i_sb, dblock); + if (new) + set_buffer_new(bh_result); + + return 0; +} + +/** + * get_block_noalloc - Fills in a buffer head with details about a block + * @inode: The inode + * @lblock: The block number to look up + * @bh_result: The buffer head to return the result in + * @create: Non-zero if we may add block to the file + * + * Returns: errno + */ + +static int get_block_noalloc(struct inode *inode, sector_t lblock, + struct buffer_head *bh_result, int create) +{ + struct gfs2_inode *ip = get_v2ip(inode); + int new = 0; + uint64_t dblock; + int error; + + error = gfs2_block_map(ip, lblock, &new, &dblock, NULL); + if (error) + return error; + + if (dblock) + map_bh(bh_result, inode->i_sb, dblock); + else if (gfs2_assert_withdraw(ip->i_sbd, !create)) + error = -EIO; + + return error; +} + +static int get_blocks(struct inode *inode, sector_t lblock, + unsigned long max_blocks, struct buffer_head *bh_result, + int create) +{ + struct gfs2_inode *ip = get_v2ip(inode); + int new = create; + uint64_t dblock; + uint32_t extlen; + int error; + + error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); + if (error) + return error; + + if (!dblock) + return 0; + + map_bh(bh_result, inode->i_sb, dblock); + if (new) + set_buffer_new(bh_result); + + if (extlen > max_blocks) + extlen = max_blocks; + bh_result->b_size = extlen << inode->i_blkbits; + + return 0; +} + +static int get_blocks_noalloc(struct inode *inode, sector_t lblock, + unsigned long max_blocks, + struct buffer_head *bh_result, int create) +{ + struct gfs2_inode *ip = get_v2ip(inode); + int new = 0; + uint64_t dblock; + uint32_t extlen; + int error; + + error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); + if (error) + return error; + + if (dblock) { + map_bh(bh_result, inode->i_sb, dblock); + if (extlen > max_blocks) + extlen = max_blocks; + bh_result->b_size = extlen << inode->i_blkbits; + } else if (gfs2_assert_withdraw(ip->i_sbd, !create)) + error = -EIO; + + return error; +} + +/** + * gfs2_writepage - Write complete page + * @page: Page to write + * + * Returns: errno + * + * Use Linux VFS block_write_full_page() to write one page, + * using GFS2's get_block_noalloc to find which blocks to write. + */ + +static int gfs2_writepage(struct page *page, struct writeback_control *wbc) +{ + struct gfs2_inode *ip = get_v2ip(page->mapping->host); + struct gfs2_sbd *sdp = ip->i_sbd; + int error; + + atomic_inc(&sdp->sd_ops_address); + + if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(ip->i_gl))) { + unlock_page(page); + return -EIO; + } + if (get_transaction) { + redirty_page_for_writepage(wbc, page); + unlock_page(page); + return 0; + } + + error = block_write_full_page(page, get_block_noalloc, wbc); + + gfs2_meta_cache_flush(ip); + + return error; +} + +/** + * stuffed_readpage - Fill in a Linux page with stuffed file data + * @ip: the inode + * @page: the page + * + * Returns: errno + */ + +static int stuffed_readpage(struct gfs2_inode *ip, struct page *page) +{ + struct buffer_head *dibh; + void *kaddr; + int error; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + return error; + + kaddr = kmap(page); + memcpy((char *)kaddr, + dibh->b_data + sizeof(struct gfs2_dinode), + ip->i_di.di_size); + memset((char *)kaddr + ip->i_di.di_size, + 0, + PAGE_CACHE_SIZE - ip->i_di.di_size); + kunmap(page); + + brelse(dibh); + + SetPageUptodate(page); + + return 0; +} + +static int zero_readpage(struct page *page) +{ + void *kaddr; + + kaddr = kmap(page); + memset(kaddr, 0, PAGE_CACHE_SIZE); + kunmap(page); + + SetPageUptodate(page); + unlock_page(page); + + return 0; +} + +/** + * jdata_readpage - readpage that goes through gfs2_jdata_read_mem() + * @ip: + * @page: The page to read + * + * Returns: errno + */ + +static int jdata_readpage(struct gfs2_inode *ip, struct page *page) +{ + void *kaddr; + int ret; + + kaddr = kmap(page); + + ret = gfs2_jdata_read_mem(ip, kaddr, + (uint64_t)page->index << PAGE_CACHE_SHIFT, + PAGE_CACHE_SIZE); + if (ret >= 0) { + if (ret < PAGE_CACHE_SIZE) + memset(kaddr + ret, 0, PAGE_CACHE_SIZE - ret); + SetPageUptodate(page); + ret = 0; + } + + kunmap(page); + + unlock_page(page); + + return ret; +} + +/** + * gfs2_readpage - readpage with locking + * @file: The file to read a page for + * @page: The page to read + * + * Returns: errno + */ + +static int gfs2_readpage(struct file *file, struct page *page) +{ + struct gfs2_inode *ip = get_v2ip(page->mapping->host); + struct gfs2_sbd *sdp = ip->i_sbd; + int error; + + atomic_inc(&sdp->sd_ops_address); + + if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl))) { + unlock_page(page); + return -EOPNOTSUPP; + } + + if (!gfs2_is_jdata(ip)) { + if (gfs2_is_stuffed(ip)) { + if (!page->index) { + error = stuffed_readpage(ip, page); + unlock_page(page); + } else + error = zero_readpage(page); + } else + error = block_read_full_page(page, get_block); + } else + error = jdata_readpage(ip, page); + + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + error = -EIO; + + return error; +} + +/** + * gfs2_prepare_write - Prepare to write a page to a file + * @file: The file to write to + * @page: The page which is to be prepared for writing + * @from: From (byte range within page) + * @to: To (byte range within page) + * + * Returns: errno + */ + +static int gfs2_prepare_write(struct file *file, struct page *page, + unsigned from, unsigned to) +{ + struct gfs2_inode *ip = get_v2ip(page->mapping->host); + struct gfs2_sbd *sdp = ip->i_sbd; + int error = 0; + + atomic_inc(&sdp->sd_ops_address); + + if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl))) + return -EOPNOTSUPP; + + if (gfs2_is_stuffed(ip)) { + uint64_t file_size; + file_size = ((uint64_t)page->index << PAGE_CACHE_SHIFT) + to; + + if (file_size > sdp->sd_sb.sb_bsize - + sizeof(struct gfs2_dinode)) { + error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, + page); + if (!error) + error = block_prepare_write(page, from, to, + get_block); + } else if (!PageUptodate(page)) + error = stuffed_readpage(ip, page); + } else + error = block_prepare_write(page, from, to, get_block); + + return error; +} + +/** + * gfs2_commit_write - Commit write to a file + * @file: The file to write to + * @page: The page containing the data + * @from: From (byte range within page) + * @to: To (byte range within page) + * + * Returns: errno + */ + +static int gfs2_commit_write(struct file *file, struct page *page, + unsigned from, unsigned to) +{ + struct inode *inode = page->mapping->host; + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_sbd *sdp = ip->i_sbd; + int error; + + atomic_inc(&sdp->sd_ops_address); + + if (gfs2_is_stuffed(ip)) { + struct buffer_head *dibh; + uint64_t file_size; + void *kaddr; + + file_size = ((uint64_t)page->index << PAGE_CACHE_SHIFT) + to; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto fail; + + gfs2_trans_add_bh(ip->i_gl, dibh); + + kaddr = kmap(page); + memcpy(dibh->b_data + sizeof(struct gfs2_dinode) + from, + (char *)kaddr + from, + to - from); + kunmap(page); + + brelse(dibh); + + SetPageUptodate(page); + + if (inode->i_size < file_size) + i_size_write(inode, file_size); + } else { + if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) + gfs2_page_add_databufs(sdp, page, from, to); + error = generic_commit_write(file, page, from, to); + if (error) + goto fail; + } + + return 0; + + fail: + ClearPageUptodate(page); + + return error; +} + +/** + * gfs2_bmap - Block map function + * @mapping: Address space info + * @lblock: The block to map + * + * Returns: The disk address for the block or 0 on hole or error + */ + +static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock) +{ + struct gfs2_inode *ip = get_v2ip(mapping->host); + struct gfs2_holder i_gh; + sector_t dblock = 0; + int error; + + atomic_inc(&ip->i_sbd->sd_ops_address); + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); + if (error) + return 0; + + if (!gfs2_is_stuffed(ip)) + dblock = generic_block_bmap(mapping, lblock, get_block); + + gfs2_glock_dq_uninit(&i_gh); + + return dblock; +} + +static void discard_buffer(struct gfs2_sbd *sdp, struct buffer_head *bh) +{ + struct gfs2_databuf *db; + + gfs2_log_lock(sdp); + db = get_v2db(bh); + if (db) { + db->db_bh = NULL; + set_v2db(bh, NULL); + gfs2_log_unlock(sdp); + brelse(bh); + } else + gfs2_log_unlock(sdp); + + lock_buffer(bh); + clear_buffer_dirty(bh); + bh->b_bdev = NULL; + clear_buffer_mapped(bh); + clear_buffer_req(bh); + clear_buffer_new(bh); + clear_buffer_delay(bh); + unlock_buffer(bh); +} + +static int gfs2_invalidatepage(struct page *page, unsigned long offset) +{ + struct gfs2_sbd *sdp = get_v2sdp(page->mapping->host->i_sb); + struct buffer_head *head, *bh, *next; + unsigned int curr_off = 0; + int ret = 1; + + BUG_ON(!PageLocked(page)); + if (!page_has_buffers(page)) + return 1; + + bh = head = page_buffers(page); + do { + unsigned int next_off = curr_off + bh->b_size; + next = bh->b_this_page; + + if (offset <= curr_off) + discard_buffer(sdp, bh); + + curr_off = next_off; + bh = next; + } while (bh != head); + + if (!offset) + ret = try_to_release_page(page, 0); + + return ret; +} + +static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, + loff_t offset, unsigned long nr_segs) +{ + struct file *file = iocb->ki_filp; + struct inode *inode = file->f_mapping->host; + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_sbd *sdp = ip->i_sbd; + get_blocks_t *gb = get_blocks; + + atomic_inc(&sdp->sd_ops_address); + + if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl)) || + gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) + return -EINVAL; + + if (rw == WRITE && !get_transaction) + gb = get_blocks_noalloc; + + return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, + offset, nr_segs, gb, NULL); +} + +struct address_space_operations gfs2_file_aops = { + .writepage = gfs2_writepage, + .readpage = gfs2_readpage, + .sync_page = block_sync_page, + .prepare_write = gfs2_prepare_write, + .commit_write = gfs2_commit_write, + .bmap = gfs2_bmap, + .invalidatepage = gfs2_invalidatepage, + .direct_IO = gfs2_direct_IO, +}; + diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h new file mode 100644 index 000000000000..ced9ea0fdd31 --- /dev/null +++ b/fs/gfs2/ops_address.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __OPS_ADDRESS_DOT_H__ +#define __OPS_ADDRESS_DOT_H__ + +extern struct address_space_operations gfs2_file_aops; + +#endif /* __OPS_ADDRESS_DOT_H__ */ diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c new file mode 100644 index 000000000000..5c618611c11b --- /dev/null +++ b/fs/gfs2/ops_dentry.c @@ -0,0 +1,117 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "dir.h" +#include "glock.h" +#include "ops_dentry.h" + +/** + * gfs2_drevalidate - Check directory lookup consistency + * @dentry: the mapping to check + * @nd: + * + * Check to make sure the lookup necessary to arrive at this inode from its + * parent is still good. + * + * Returns: 1 if the dentry is ok, 0 if it isn't + */ + +static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) +{ + struct dentry *parent = dget_parent(dentry); + struct gfs2_inode *dip = get_v2ip(parent->d_inode); + struct gfs2_sbd *sdp = dip->i_sbd; + struct inode *inode; + struct gfs2_holder d_gh; + struct gfs2_inode *ip; + struct gfs2_inum inum; + unsigned int type; + int error; + + lock_kernel(); + + atomic_inc(&sdp->sd_ops_dentry); + + inode = dentry->d_inode; + if (inode && is_bad_inode(inode)) + goto invalid; + + error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); + if (error) + goto fail; + + error = gfs2_dir_search(dip, &dentry->d_name, &inum, &type); + switch (error) { + case 0: + if (!inode) + goto invalid_gunlock; + break; + case -ENOENT: + if (!inode) + goto valid_gunlock; + goto invalid_gunlock; + default: + goto fail_gunlock; + } + + ip = get_v2ip(inode); + + if (!gfs2_inum_equal(&ip->i_num, &inum)) + goto invalid_gunlock; + + if (IF2DT(ip->i_di.di_mode) != type) { + gfs2_consist_inode(dip); + goto fail_gunlock; + } + + valid_gunlock: + gfs2_glock_dq_uninit(&d_gh); + + valid: + unlock_kernel(); + dput(parent); + return 1; + + invalid_gunlock: + gfs2_glock_dq_uninit(&d_gh); + + invalid: + if (inode && S_ISDIR(inode->i_mode)) { + if (have_submounts(dentry)) + goto valid; + shrink_dcache_parent(dentry); + } + d_drop(dentry); + + unlock_kernel(); + dput(parent); + return 0; + + fail_gunlock: + gfs2_glock_dq_uninit(&d_gh); + + fail: + unlock_kernel(); + dput(parent); + return 0; +} + +struct dentry_operations gfs2_dops = { + .d_revalidate = gfs2_drevalidate, +}; + diff --git a/fs/gfs2/ops_dentry.h b/fs/gfs2/ops_dentry.h new file mode 100644 index 000000000000..94e3ee170165 --- /dev/null +++ b/fs/gfs2/ops_dentry.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __OPS_DENTRY_DOT_H__ +#define __OPS_DENTRY_DOT_H__ + +extern struct dentry_operations gfs2_dops; + +#endif /* __OPS_DENTRY_DOT_H__ */ diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c new file mode 100644 index 000000000000..0ae3a0af192d --- /dev/null +++ b/fs/gfs2/ops_export.c @@ -0,0 +1,310 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "dir.h" +#include "glock.h" +#include "glops.h" +#include "inode.h" +#include "ops_export.h" +#include "rgrp.h" + +static struct dentry *gfs2_decode_fh(struct super_block *sb, + __u32 *fh, + int fh_len, + int fh_type, + int (*acceptable)(void *context, + struct dentry *dentry), + void *context) +{ + struct gfs2_inum this, parent; + + atomic_inc(&get_v2sdp(sb)->sd_ops_export); + + if (fh_type != fh_len) + return NULL; + + memset(&parent, 0, sizeof(struct gfs2_inum)); + + switch (fh_type) { + case 8: + parent.no_formal_ino = ((uint64_t)be32_to_cpu(fh[4])) << 32; + parent.no_formal_ino |= be32_to_cpu(fh[5]); + parent.no_addr = ((uint64_t)be32_to_cpu(fh[6])) << 32; + parent.no_addr |= be32_to_cpu(fh[7]); + case 4: + this.no_formal_ino = ((uint64_t)be32_to_cpu(fh[0])) << 32; + this.no_formal_ino |= be32_to_cpu(fh[1]); + this.no_addr = ((uint64_t)be32_to_cpu(fh[2])) << 32; + this.no_addr |= be32_to_cpu(fh[3]); + break; + default: + return NULL; + } + + return gfs2_export_ops.find_exported_dentry(sb, &this, &parent, + acceptable, context); +} + +static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, + int connectable) +{ + struct inode *inode = dentry->d_inode; + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_sbd *sdp = ip->i_sbd; + + atomic_inc(&sdp->sd_ops_export); + + if (*len < 4 || (connectable && *len < 8)) + return 255; + + fh[0] = ip->i_num.no_formal_ino >> 32; + fh[0] = cpu_to_be32(fh[0]); + fh[1] = ip->i_num.no_formal_ino & 0xFFFFFFFF; + fh[1] = cpu_to_be32(fh[1]); + fh[2] = ip->i_num.no_addr >> 32; + fh[2] = cpu_to_be32(fh[2]); + fh[3] = ip->i_num.no_addr & 0xFFFFFFFF; + fh[3] = cpu_to_be32(fh[3]); + *len = 4; + + if (!connectable || ip == sdp->sd_root_dir) + return *len; + + spin_lock(&dentry->d_lock); + inode = dentry->d_parent->d_inode; + ip = get_v2ip(inode); + gfs2_inode_hold(ip); + spin_unlock(&dentry->d_lock); + + fh[4] = ip->i_num.no_formal_ino >> 32; + fh[4] = cpu_to_be32(fh[4]); + fh[5] = ip->i_num.no_formal_ino & 0xFFFFFFFF; + fh[5] = cpu_to_be32(fh[5]); + fh[6] = ip->i_num.no_addr >> 32; + fh[6] = cpu_to_be32(fh[6]); + fh[7] = ip->i_num.no_addr & 0xFFFFFFFF; + fh[7] = cpu_to_be32(fh[7]); + *len = 8; + + gfs2_inode_put(ip); + + return *len; +} + +struct get_name_filldir { + struct gfs2_inum inum; + char *name; +}; + +static int get_name_filldir(void *opaque, const char *name, unsigned int length, + uint64_t offset, struct gfs2_inum *inum, + unsigned int type) +{ + struct get_name_filldir *gnfd = (struct get_name_filldir *)opaque; + + if (!gfs2_inum_equal(inum, &gnfd->inum)) + return 0; + + memcpy(gnfd->name, name, length); + gnfd->name[length] = 0; + + return 1; +} + +static int gfs2_get_name(struct dentry *parent, char *name, + struct dentry *child) +{ + struct inode *dir = parent->d_inode; + struct inode *inode = child->d_inode; + struct gfs2_inode *dip, *ip; + struct get_name_filldir gnfd; + struct gfs2_holder gh; + uint64_t offset = 0; + int error; + + if (!dir) + return -EINVAL; + + atomic_inc(&get_v2sdp(dir->i_sb)->sd_ops_export); + + if (!S_ISDIR(dir->i_mode) || !inode) + return -EINVAL; + + dip = get_v2ip(dir); + ip = get_v2ip(inode); + + *name = 0; + gnfd.inum = ip->i_num; + gnfd.name = name; + + error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &gh); + if (error) + return error; + + error = gfs2_dir_read(dip, &offset, &gnfd, get_name_filldir); + + gfs2_glock_dq_uninit(&gh); + + if (!error && !*name) + error = -ENOENT; + + return error; +} + +static struct dentry *gfs2_get_parent(struct dentry *child) +{ + struct gfs2_inode *dip = get_v2ip(child->d_inode); + struct qstr dotdot = { .name = "..", .len = 2 }; + struct gfs2_inode *ip; + struct inode *inode; + struct dentry *dentry; + int error; + + atomic_inc(&dip->i_sbd->sd_ops_export); + + error = gfs2_lookupi(dip, &dotdot, 1, &ip); + if (error) + return ERR_PTR(error); + + inode = gfs2_ip2v(ip); + gfs2_inode_put(ip); + + if (!inode) + return ERR_PTR(-ENOMEM); + + dentry = d_alloc_anon(inode); + if (!dentry) { + iput(inode); + return ERR_PTR(-ENOMEM); + } + + return dentry; +} + +static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) +{ + struct gfs2_sbd *sdp = get_v2sdp(sb); + struct gfs2_inum *inum = (struct gfs2_inum *)inum_p; + struct gfs2_holder i_gh, ri_gh, rgd_gh; + struct gfs2_rgrpd *rgd; + struct gfs2_inode *ip; + struct inode *inode; + struct dentry *dentry; + int error; + + atomic_inc(&sdp->sd_ops_export); + + /* System files? */ + + inode = gfs2_iget(sb, inum); + if (inode) { + ip = get_v2ip(inode); + if (ip->i_num.no_formal_ino != inum->no_formal_ino) { + iput(inode); + return ERR_PTR(-ESTALE); + } + goto out_inode; + } + + error = gfs2_glock_nq_num(sdp, + inum->no_addr, &gfs2_inode_glops, + LM_ST_SHARED, LM_FLAG_ANY | GL_LOCAL_EXCL, + &i_gh); + if (error) + return ERR_PTR(error); + + error = gfs2_inode_get(i_gh.gh_gl, inum, NO_CREATE, &ip); + if (error) + goto fail; + if (ip) + goto out_ip; + + error = gfs2_rindex_hold(sdp, &ri_gh); + if (error) + goto fail; + + error = -EINVAL; + rgd = gfs2_blk2rgrpd(sdp, inum->no_addr); + if (!rgd) + goto fail_rindex; + + error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_SHARED, 0, &rgd_gh); + if (error) + goto fail_rindex; + + error = -ESTALE; + if (gfs2_get_block_type(rgd, inum->no_addr) != GFS2_BLKST_DINODE) + goto fail_rgd; + + gfs2_glock_dq_uninit(&rgd_gh); + gfs2_glock_dq_uninit(&ri_gh); + + error = gfs2_inode_get(i_gh.gh_gl, inum, CREATE, &ip); + if (error) + goto fail; + + error = gfs2_inode_refresh(ip); + if (error) { + gfs2_inode_put(ip); + goto fail; + } + + atomic_inc(&sdp->sd_fh2dentry_misses); + + out_ip: + error = -EIO; + if (ip->i_di.di_flags & GFS2_DIF_SYSTEM) { + gfs2_inode_put(ip); + goto fail; + } + + gfs2_glock_dq_uninit(&i_gh); + + inode = gfs2_ip2v(ip); + gfs2_inode_put(ip); + + if (!inode) + return ERR_PTR(-ENOMEM); + + out_inode: + dentry = d_alloc_anon(inode); + if (!dentry) { + iput(inode); + return ERR_PTR(-ENOMEM); + } + + return dentry; + + fail_rgd: + gfs2_glock_dq_uninit(&rgd_gh); + + fail_rindex: + gfs2_glock_dq_uninit(&ri_gh); + + fail: + gfs2_glock_dq_uninit(&i_gh); + return ERR_PTR(error); +} + +struct export_operations gfs2_export_ops = { + .decode_fh = gfs2_decode_fh, + .encode_fh = gfs2_encode_fh, + .get_name = gfs2_get_name, + .get_parent = gfs2_get_parent, + .get_dentry = gfs2_get_dentry, +}; + diff --git a/fs/gfs2/ops_export.h b/fs/gfs2/ops_export.h new file mode 100644 index 000000000000..2f342f3d8755 --- /dev/null +++ b/fs/gfs2/ops_export.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __OPS_EXPORT_DOT_H__ +#define __OPS_EXPORT_DOT_H__ + +extern struct export_operations gfs2_export_ops; + +#endif /* __OPS_EXPORT_DOT_H__ */ diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c new file mode 100644 index 000000000000..1e6f51b74f44 --- /dev/null +++ b/fs/gfs2/ops_file.c @@ -0,0 +1,1597 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "dir.h" +#include "glock.h" +#include "glops.h" +#include "inode.h" +#include "jdata.h" +#include "lm.h" +#include "log.h" +#include "meta_io.h" +#include "ops_file.h" +#include "ops_vm.h" +#include "quota.h" +#include "rgrp.h" +#include "trans.h" + +/* "bad" is for NFS support */ +struct filldir_bad_entry { + char *fbe_name; + unsigned int fbe_length; + uint64_t fbe_offset; + struct gfs2_inum fbe_inum; + unsigned int fbe_type; +}; + +struct filldir_bad { + struct gfs2_sbd *fdb_sbd; + + struct filldir_bad_entry *fdb_entry; + unsigned int fdb_entry_num; + unsigned int fdb_entry_off; + + char *fdb_name; + unsigned int fdb_name_size; + unsigned int fdb_name_off; +}; + +/* For regular, non-NFS */ +struct filldir_reg { + struct gfs2_sbd *fdr_sbd; + int fdr_prefetch; + + filldir_t fdr_filldir; + void *fdr_opaque; +}; + +typedef ssize_t(*do_rw_t) (struct file *file, + char __user *buf, + size_t size, loff_t *offset, + unsigned int num_gh, struct gfs2_holder *ghs); + +/** + * gfs2_llseek - seek to a location in a file + * @file: the file + * @offset: the offset + * @origin: Where to seek from (SEEK_SET, SEEK_CUR, or SEEK_END) + * + * SEEK_END requires the glock for the file because it references the + * file's size. + * + * Returns: The new offset, or errno + */ + +static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) +{ + struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + struct gfs2_holder i_gh; + loff_t error; + + atomic_inc(&ip->i_sbd->sd_ops_file); + + if (origin == 2) { + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, + &i_gh); + if (!error) { + error = remote_llseek(file, offset, origin); + gfs2_glock_dq_uninit(&i_gh); + } + } else + error = remote_llseek(file, offset, origin); + + return error; +} + +static inline unsigned int vma2state(struct vm_area_struct *vma) +{ + if ((vma->vm_flags & (VM_MAYWRITE | VM_MAYSHARE)) == + (VM_MAYWRITE | VM_MAYSHARE)) + return LM_ST_EXCLUSIVE; + return LM_ST_SHARED; +} + +static ssize_t walk_vm_hard(struct file *file, const char __user *buf, size_t size, + loff_t *offset, do_rw_t operation) +{ + struct gfs2_holder *ghs; + unsigned int num_gh = 0; + ssize_t count; + struct super_block *sb = file->f_dentry->d_inode->i_sb; + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma; + unsigned long start = (unsigned long)buf; + unsigned long end = start + size; + int dumping = (current->flags & PF_DUMPCORE); + unsigned int x = 0; + + for (vma = find_vma(mm, start); vma; vma = vma->vm_next) { + if (end <= vma->vm_start) + break; + if (vma->vm_file && + vma->vm_file->f_dentry->d_inode->i_sb == sb) { + num_gh++; + } + } + + ghs = kcalloc((num_gh + 1), sizeof(struct gfs2_holder), GFP_KERNEL); + if (!ghs) { + if (!dumping) + up_read(&mm->mmap_sem); + return -ENOMEM; + } + + for (vma = find_vma(mm, start); vma; vma = vma->vm_next) { + if (end <= vma->vm_start) + break; + if (vma->vm_file) { + struct inode *inode = vma->vm_file->f_dentry->d_inode; + if (inode->i_sb == sb) + gfs2_holder_init(get_v2ip(inode)->i_gl, + vma2state(vma), 0, &ghs[x++]); + } + } + + if (!dumping) + up_read(&mm->mmap_sem); + + gfs2_assert(get_v2sdp(sb), x == num_gh); + + count = operation(file, buf, size, offset, num_gh, ghs); + + while (num_gh--) + gfs2_holder_uninit(&ghs[num_gh]); + kfree(ghs); + + return count; +} + +/** + * walk_vm - Walk the vmas associated with a buffer for read or write. + * If any of them are gfs2, pass the gfs2 inode down to the read/write + * worker function so that locks can be acquired in the correct order. + * @file: The file to read/write from/to + * @buf: The buffer to copy to/from + * @size: The amount of data requested + * @offset: The current file offset + * @operation: The read or write worker function + * + * Outputs: Offset - updated according to number of bytes written + * + * Returns: The number of bytes written, errno on failure + */ + +static ssize_t walk_vm(struct file *file, const char __user *buf, size_t size, + loff_t *offset, do_rw_t operation) +{ + struct gfs2_holder gh; + + if (current->mm) { + struct super_block *sb = file->f_dentry->d_inode->i_sb; + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma; + unsigned long start = (unsigned long)buf; + unsigned long end = start + size; + int dumping = (current->flags & PF_DUMPCORE); + + if (!dumping) + down_read(&mm->mmap_sem); + + for (vma = find_vma(mm, start); vma; vma = vma->vm_next) { + if (end <= vma->vm_start) + break; + if (vma->vm_file && + vma->vm_file->f_dentry->d_inode->i_sb == sb) + goto do_locks; + } + + if (!dumping) + up_read(&mm->mmap_sem); + } + + return operation(file, buf, size, offset, 0, &gh); + +do_locks: + return walk_vm_hard(file, buf, size, offset, operation); +} + +static ssize_t do_jdata_read(struct file *file, char __user *buf, size_t size, + loff_t *offset) +{ + struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + ssize_t count = 0; + + if (*offset < 0) + return -EINVAL; + if (!access_ok(VERIFY_WRITE, buf, size)) + return -EFAULT; + + if (!(file->f_flags & O_LARGEFILE)) { + if (*offset >= MAX_NON_LFS) + return -EFBIG; + if (*offset + size > MAX_NON_LFS) + size = MAX_NON_LFS - *offset; + } + + count = gfs2_jdata_read(ip, buf, *offset, size, gfs2_copy2user); + + if (count > 0) + *offset += count; + + return count; +} + +/** + * do_read_direct - Read bytes from a file + * @file: The file to read from + * @buf: The buffer to copy into + * @size: The amount of data requested + * @offset: The current file offset + * @num_gh: The number of other locks we need to do the read + * @ghs: the locks we need plus one for our lock + * + * Outputs: Offset - updated according to number of bytes read + * + * Returns: The number of bytes read, errno on failure + */ + +static ssize_t do_read_direct(struct file *file, char __user *buf, size_t size, + loff_t *offset, unsigned int num_gh, + struct gfs2_holder *ghs) +{ + struct inode *inode = file->f_mapping->host; + struct gfs2_inode *ip = get_v2ip(inode); + unsigned int state = LM_ST_DEFERRED; + int flags = 0; + unsigned int x; + ssize_t count = 0; + int error; + + for (x = 0; x < num_gh; x++) + if (ghs[x].gh_gl == ip->i_gl) { + state = LM_ST_SHARED; + flags |= GL_LOCAL_EXCL; + break; + } + + gfs2_holder_init(ip->i_gl, state, flags, &ghs[num_gh]); + + error = gfs2_glock_nq_m(num_gh + 1, ghs); + if (error) + goto out; + + error = -EINVAL; + if (gfs2_is_jdata(ip)) + goto out_gunlock; + + if (gfs2_is_stuffed(ip)) { + size_t mask = bdev_hardsect_size(inode->i_sb->s_bdev) - 1; + + if (((*offset) & mask) || (((unsigned long)buf) & mask)) + goto out_gunlock; + + count = do_jdata_read(file, buf, size & ~mask, offset); + } else + count = generic_file_read(file, buf, size, offset); + + error = 0; + + out_gunlock: + gfs2_glock_dq_m(num_gh + 1, ghs); + + out: + gfs2_holder_uninit(&ghs[num_gh]); + + return (count) ? count : error; +} + +/** + * do_read_buf - Read bytes from a file + * @file: The file to read from + * @buf: The buffer to copy into + * @size: The amount of data requested + * @offset: The current file offset + * @num_gh: The number of other locks we need to do the read + * @ghs: the locks we need plus one for our lock + * + * Outputs: Offset - updated according to number of bytes read + * + * Returns: The number of bytes read, errno on failure + */ + +static ssize_t do_read_buf(struct file *file, char __user *buf, size_t size, + loff_t *offset, unsigned int num_gh, + struct gfs2_holder *ghs) +{ + struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + ssize_t count = 0; + int error; + + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &ghs[num_gh]); + + error = gfs2_glock_nq_m_atime(num_gh + 1, ghs); + if (error) + goto out; + + if (gfs2_is_jdata(ip)) + count = do_jdata_read(file, buf, size, offset); + else + count = generic_file_read(file, buf, size, offset); + + gfs2_glock_dq_m(num_gh + 1, ghs); + + out: + gfs2_holder_uninit(&ghs[num_gh]); + + return (count) ? count : error; +} + +/** + * gfs2_read - Read bytes from a file + * @file: The file to read from + * @buf: The buffer to copy into + * @size: The amount of data requested + * @offset: The current file offset + * + * Outputs: Offset - updated according to number of bytes read + * + * Returns: The number of bytes read, errno on failure + */ + +static ssize_t gfs2_read(struct file *file, char __user *buf, size_t size, + loff_t *offset) +{ + atomic_inc(&get_v2sdp(file->f_mapping->host->i_sb)->sd_ops_file); + + if (file->f_flags & O_DIRECT) + return walk_vm(file, buf, size, offset, do_read_direct); + else + return walk_vm(file, buf, size, offset, do_read_buf); +} + +/** + * grope_mapping - feel up a mapping that needs to be written + * @buf: the start of the memory to be written + * @size: the size of the memory to be written + * + * We do this after acquiring the locks on the mapping, + * but before starting the write transaction. We need to make + * sure that we don't cause recursive transactions if blocks + * need to be allocated to the file backing the mapping. + * + * Returns: errno + */ + +static int grope_mapping(const char __user *buf, size_t size) +{ + const char __user *stop = buf + size; + char c; + + while (buf < stop) { + if (copy_from_user(&c, buf, 1)) + return -EFAULT; + buf += PAGE_CACHE_SIZE; + buf = (const char __user *)PAGE_ALIGN((unsigned long)buf); + } + + return 0; +} + +/** + * do_write_direct_alloc - Write bytes to a file + * @file: The file to write to + * @buf: The buffer to copy from + * @size: The amount of data requested + * @offset: The current file offset + * + * Outputs: Offset - updated according to number of bytes written + * + * Returns: The number of bytes written, errno on failure + */ + +static ssize_t do_write_direct_alloc(struct file *file, const char __user *buf, size_t size, + loff_t *offset) +{ + struct inode *inode = file->f_mapping->host; + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = NULL; + struct iovec local_iov = { .iov_base = buf, .iov_len = size }; + struct buffer_head *dibh; + unsigned int data_blocks, ind_blocks; + ssize_t count; + int error; + + gfs2_write_calc_reserv(ip, size, &data_blocks, &ind_blocks); + + al = gfs2_alloc_get(ip); + + error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto fail; + + error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid); + if (error) + goto fail_gunlock_q; + + al->al_requested = data_blocks + ind_blocks; + + error = gfs2_inplace_reserve(ip); + if (error) + goto fail_gunlock_q; + + error = gfs2_trans_begin(sdp, + al->al_rgd->rd_ri.ri_length + ind_blocks + + RES_DINODE + RES_STATFS + RES_QUOTA, 0); + if (error) + goto fail_ipres; + + if ((ip->i_di.di_mode & (S_ISUID | S_ISGID)) && !capable(CAP_FSETID)) { + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto fail_end_trans; + + ip->i_di.di_mode &= (ip->i_di.di_mode & S_IXGRP) ? + (~(S_ISUID | S_ISGID)) : (~S_ISUID); + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + if (gfs2_is_stuffed(ip)) { + error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_sync, NULL); + if (error) + goto fail_end_trans; + } + + count = generic_file_write_nolock(file, &local_iov, 1, offset); + if (count < 0) { + error = count; + goto fail_end_trans; + } + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto fail_end_trans; + + if (ip->i_di.di_size < inode->i_size) + ip->i_di.di_size = inode->i_size; + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + + gfs2_trans_end(sdp); + + if (file->f_flags & O_SYNC) + gfs2_log_flush_glock(ip->i_gl); + + gfs2_inplace_release(ip); + gfs2_quota_unlock(ip); + gfs2_alloc_put(ip); + + if (file->f_mapping->nrpages) { + error = filemap_fdatawrite(file->f_mapping); + if (!error) + error = filemap_fdatawait(file->f_mapping); + } + if (error) + return error; + + return count; + + fail_end_trans: + gfs2_trans_end(sdp); + + fail_ipres: + gfs2_inplace_release(ip); + + fail_gunlock_q: + gfs2_quota_unlock(ip); + + fail: + gfs2_alloc_put(ip); + + return error; +} + +/** + * do_write_direct - Write bytes to a file + * @file: The file to write to + * @buf: The buffer to copy from + * @size: The amount of data requested + * @offset: The current file offset + * @num_gh: The number of other locks we need to do the read + * @gh: the locks we need plus one for our lock + * + * Outputs: Offset - updated according to number of bytes written + * + * Returns: The number of bytes written, errno on failure + */ + +static ssize_t do_write_direct(struct file *file, const char __user *buf, size_t size, + loff_t *offset, unsigned int num_gh, + struct gfs2_holder *ghs) +{ + struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_file *fp = get_v2fp(file); + unsigned int state = LM_ST_DEFERRED; + int alloc_required; + unsigned int x; + size_t s; + ssize_t count = 0; + int error; + + if (test_bit(GFF_DID_DIRECT_ALLOC, &fp->f_flags)) + state = LM_ST_EXCLUSIVE; + else + for (x = 0; x < num_gh; x++) + if (ghs[x].gh_gl == ip->i_gl) { + state = LM_ST_EXCLUSIVE; + break; + } + + restart: + gfs2_holder_init(ip->i_gl, state, 0, &ghs[num_gh]); + + error = gfs2_glock_nq_m(num_gh + 1, ghs); + if (error) + goto out; + + error = -EINVAL; + if (gfs2_is_jdata(ip)) + goto out_gunlock; + + if (num_gh) { + error = grope_mapping(buf, size); + if (error) + goto out_gunlock; + } + + if (file->f_flags & O_APPEND) + *offset = ip->i_di.di_size; + + if (!(file->f_flags & O_LARGEFILE)) { + error = -EFBIG; + if (*offset >= MAX_NON_LFS) + goto out_gunlock; + if (*offset + size > MAX_NON_LFS) + size = MAX_NON_LFS - *offset; + } + + if (gfs2_is_stuffed(ip) || + *offset + size > ip->i_di.di_size || + ((ip->i_di.di_mode & (S_ISUID | S_ISGID)) && !capable(CAP_FSETID))) + alloc_required = 1; + else { + error = gfs2_write_alloc_required(ip, *offset, size, + &alloc_required); + if (error) + goto out_gunlock; + } + + if (alloc_required && state != LM_ST_EXCLUSIVE) { + gfs2_glock_dq_m(num_gh + 1, ghs); + gfs2_holder_uninit(&ghs[num_gh]); + state = LM_ST_EXCLUSIVE; + goto restart; + } + + if (alloc_required) { + set_bit(GFF_DID_DIRECT_ALLOC, &fp->f_flags); + + /* split large writes into smaller atomic transactions */ + while (size) { + s = gfs2_tune_get(sdp, gt_max_atomic_write); + if (s > size) + s = size; + + error = do_write_direct_alloc(file, buf, s, offset); + if (error < 0) + goto out_gunlock; + + buf += error; + size -= error; + count += error; + } + } else { + struct iovec local_iov = { .iov_base = buf, .iov_len = size }; + struct gfs2_holder t_gh; + + clear_bit(GFF_DID_DIRECT_ALLOC, &fp->f_flags); + + error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, + GL_NEVER_RECURSE, &t_gh); + if (error) + goto out_gunlock; + + count = generic_file_write_nolock(file, &local_iov, 1, offset); + + gfs2_glock_dq_uninit(&t_gh); + } + + error = 0; + + out_gunlock: + gfs2_glock_dq_m(num_gh + 1, ghs); + + out: + gfs2_holder_uninit(&ghs[num_gh]); + + return (count) ? count : error; +} + +/** + * do_do_write_buf - Write bytes to a file + * @file: The file to write to + * @buf: The buffer to copy from + * @size: The amount of data requested + * @offset: The current file offset + * + * Outputs: Offset - updated according to number of bytes written + * + * Returns: The number of bytes written, errno on failure + */ + +static ssize_t do_do_write_buf(struct file *file, const char __user *buf, size_t size, + loff_t *offset) +{ + struct inode *inode = file->f_mapping->host; + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = NULL; + struct buffer_head *dibh; + unsigned int data_blocks, ind_blocks; + int alloc_required, journaled; + ssize_t count; + int error; + + journaled = gfs2_is_jdata(ip); + + gfs2_write_calc_reserv(ip, size, &data_blocks, &ind_blocks); + + error = gfs2_write_alloc_required(ip, *offset, size, &alloc_required); + if (error) + return error; + + if (alloc_required) { + al = gfs2_alloc_get(ip); + + error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto fail; + + error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid); + if (error) + goto fail_gunlock_q; + + al->al_requested = data_blocks + ind_blocks; + + error = gfs2_inplace_reserve(ip); + if (error) + goto fail_gunlock_q; + + error = gfs2_trans_begin(sdp, + al->al_rgd->rd_ri.ri_length + + ind_blocks + + ((journaled) ? data_blocks : 0) + + RES_DINODE + RES_STATFS + RES_QUOTA, + 0); + if (error) + goto fail_ipres; + } else { + error = gfs2_trans_begin(sdp, + ((journaled) ? data_blocks : 0) + + RES_DINODE, + 0); + if (error) + goto fail_ipres; + } + + if ((ip->i_di.di_mode & (S_ISUID | S_ISGID)) && !capable(CAP_FSETID)) { + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto fail_end_trans; + + ip->i_di.di_mode &= (ip->i_di.di_mode & S_IXGRP) ? + (~(S_ISUID | S_ISGID)) : (~S_ISUID); + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + if (journaled) { + count = gfs2_jdata_write(ip, buf, *offset, size, + gfs2_copy_from_user); + if (count < 0) { + error = count; + goto fail_end_trans; + } + + *offset += count; + } else { + struct iovec local_iov = { .iov_base = buf, .iov_len = size }; + + count = generic_file_write_nolock(file, &local_iov, 1, offset); + if (count < 0) { + error = count; + goto fail_end_trans; + } + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto fail_end_trans; + + if (ip->i_di.di_size < inode->i_size) + ip->i_di.di_size = inode->i_size; + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + gfs2_trans_end(sdp); + + if (file->f_flags & O_SYNC || IS_SYNC(inode)) { + gfs2_log_flush_glock(ip->i_gl); + error = filemap_fdatawrite(file->f_mapping); + if (error == 0) + error = filemap_fdatawait(file->f_mapping); + if (error) + goto fail_ipres; + } + + if (alloc_required) { + gfs2_assert_warn(sdp, count != size || + al->al_alloced); + gfs2_inplace_release(ip); + gfs2_quota_unlock(ip); + gfs2_alloc_put(ip); + } + + return count; + + fail_end_trans: + gfs2_trans_end(sdp); + + fail_ipres: + if (alloc_required) + gfs2_inplace_release(ip); + + fail_gunlock_q: + if (alloc_required) + gfs2_quota_unlock(ip); + + fail: + if (alloc_required) + gfs2_alloc_put(ip); + + return error; +} + +/** + * do_write_buf - Write bytes to a file + * @file: The file to write to + * @buf: The buffer to copy from + * @size: The amount of data requested + * @offset: The current file offset + * @num_gh: The number of other locks we need to do the read + * @gh: the locks we need plus one for our lock + * + * Outputs: Offset - updated according to number of bytes written + * + * Returns: The number of bytes written, errno on failure + */ + +static ssize_t do_write_buf(struct file *file, const char __user *buf, size_t size, + loff_t *offset, unsigned int num_gh, + struct gfs2_holder *ghs) +{ + struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + struct gfs2_sbd *sdp = ip->i_sbd; + size_t s; + ssize_t count = 0; + int error; + + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &ghs[num_gh]); + + error = gfs2_glock_nq_m(num_gh + 1, ghs); + if (error) + goto out; + + if (num_gh) { + error = grope_mapping(buf, size); + if (error) + goto out_gunlock; + } + + if (file->f_flags & O_APPEND) + *offset = ip->i_di.di_size; + + if (!(file->f_flags & O_LARGEFILE)) { + error = -EFBIG; + if (*offset >= MAX_NON_LFS) + goto out_gunlock; + if (*offset + size > MAX_NON_LFS) + size = MAX_NON_LFS - *offset; + } + + /* split large writes into smaller atomic transactions */ + while (size) { + s = gfs2_tune_get(sdp, gt_max_atomic_write); + if (s > size) + s = size; + + error = do_do_write_buf(file, buf, s, offset); + if (error < 0) + goto out_gunlock; + + buf += error; + size -= error; + count += error; + } + + error = 0; + + out_gunlock: + gfs2_glock_dq_m(num_gh + 1, ghs); + + out: + gfs2_holder_uninit(&ghs[num_gh]); + + return (count) ? count : error; +} + +/** + * gfs2_write - Write bytes to a file + * @file: The file to write to + * @buf: The buffer to copy from + * @size: The amount of data requested + * @offset: The current file offset + * + * Outputs: Offset - updated according to number of bytes written + * + * Returns: The number of bytes written, errno on failure + */ + +static ssize_t gfs2_write(struct file *file, const char __user *buf, + size_t size, loff_t *offset) +{ + struct inode *inode = file->f_mapping->host; + ssize_t count; + + atomic_inc(&get_v2sdp(inode->i_sb)->sd_ops_file); + + if (*offset < 0) + return -EINVAL; + if (!access_ok(VERIFY_READ, buf, size)) + return -EFAULT; + + mutex_lock(&inode->i_mutex); + if (file->f_flags & O_DIRECT) + count = walk_vm(file, buf, size, offset, + do_write_direct); + else + count = walk_vm(file, buf, size, offset, do_write_buf); + mutex_unlock(&inode->i_mutex); + + return count; +} + +/** + * filldir_reg_func - Report a directory entry to the caller of gfs2_dir_read() + * @opaque: opaque data used by the function + * @name: the name of the directory entry + * @length: the length of the name + * @offset: the entry's offset in the directory + * @inum: the inode number the entry points to + * @type: the type of inode the entry points to + * + * Returns: 0 on success, 1 if buffer full + */ + +static int filldir_reg_func(void *opaque, const char *name, unsigned int length, + uint64_t offset, struct gfs2_inum *inum, + unsigned int type) +{ + struct filldir_reg *fdr = (struct filldir_reg *)opaque; + struct gfs2_sbd *sdp = fdr->fdr_sbd; + int error; + + error = fdr->fdr_filldir(fdr->fdr_opaque, name, length, offset, + inum->no_formal_ino, type); + if (error) + return 1; + + if (fdr->fdr_prefetch && !(length == 1 && *name == '.')) { + gfs2_glock_prefetch_num(sdp, + inum->no_addr, &gfs2_inode_glops, + LM_ST_SHARED, LM_FLAG_TRY | LM_FLAG_ANY); + gfs2_glock_prefetch_num(sdp, + inum->no_addr, &gfs2_iopen_glops, + LM_ST_SHARED, LM_FLAG_TRY); + } + + return 0; +} + +/** + * readdir_reg - Read directory entries from a directory + * @file: The directory to read from + * @dirent: Buffer for dirents + * @filldir: Function used to do the copying + * + * Returns: errno + */ + +static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) +{ + struct gfs2_inode *dip = get_v2ip(file->f_mapping->host); + struct filldir_reg fdr; + struct gfs2_holder d_gh; + uint64_t offset = file->f_pos; + int error; + + fdr.fdr_sbd = dip->i_sbd; + fdr.fdr_prefetch = 1; + fdr.fdr_filldir = filldir; + fdr.fdr_opaque = dirent; + + gfs2_holder_init(dip->i_gl, LM_ST_SHARED, GL_ATIME, &d_gh); + error = gfs2_glock_nq_atime(&d_gh); + if (error) { + gfs2_holder_uninit(&d_gh); + return error; + } + + error = gfs2_dir_read(dip, &offset, &fdr, filldir_reg_func); + + gfs2_glock_dq_uninit(&d_gh); + + file->f_pos = offset; + + return error; +} + +/** + * filldir_bad_func - Report a directory entry to the caller of gfs2_dir_read() + * @opaque: opaque data used by the function + * @name: the name of the directory entry + * @length: the length of the name + * @offset: the entry's offset in the directory + * @inum: the inode number the entry points to + * @type: the type of inode the entry points to + * + * For supporting NFS. + * + * Returns: 0 on success, 1 if buffer full + */ + +static int filldir_bad_func(void *opaque, const char *name, unsigned int length, + uint64_t offset, struct gfs2_inum *inum, + unsigned int type) +{ + struct filldir_bad *fdb = (struct filldir_bad *)opaque; + struct gfs2_sbd *sdp = fdb->fdb_sbd; + struct filldir_bad_entry *fbe; + + if (fdb->fdb_entry_off == fdb->fdb_entry_num || + fdb->fdb_name_off + length > fdb->fdb_name_size) + return 1; + + fbe = &fdb->fdb_entry[fdb->fdb_entry_off]; + fbe->fbe_name = fdb->fdb_name + fdb->fdb_name_off; + memcpy(fbe->fbe_name, name, length); + fbe->fbe_length = length; + fbe->fbe_offset = offset; + fbe->fbe_inum = *inum; + fbe->fbe_type = type; + + fdb->fdb_entry_off++; + fdb->fdb_name_off += length; + + if (!(length == 1 && *name == '.')) { + gfs2_glock_prefetch_num(sdp, + inum->no_addr, &gfs2_inode_glops, + LM_ST_SHARED, LM_FLAG_TRY | LM_FLAG_ANY); + gfs2_glock_prefetch_num(sdp, + inum->no_addr, &gfs2_iopen_glops, + LM_ST_SHARED, LM_FLAG_TRY); + } + + return 0; +} + +/** + * readdir_bad - Read directory entries from a directory + * @file: The directory to read from + * @dirent: Buffer for dirents + * @filldir: Function used to do the copying + * + * For supporting NFS. + * + * Returns: errno + */ + +static int readdir_bad(struct file *file, void *dirent, filldir_t filldir) +{ + struct gfs2_inode *dip = get_v2ip(file->f_mapping->host); + struct gfs2_sbd *sdp = dip->i_sbd; + struct filldir_reg fdr; + unsigned int entries, size; + struct filldir_bad *fdb; + struct gfs2_holder d_gh; + uint64_t offset = file->f_pos; + unsigned int x; + struct filldir_bad_entry *fbe; + int error; + + entries = gfs2_tune_get(sdp, gt_entries_per_readdir); + size = sizeof(struct filldir_bad) + + entries * (sizeof(struct filldir_bad_entry) + GFS2_FAST_NAME_SIZE); + + fdb = kzalloc(size, GFP_KERNEL); + if (!fdb) + return -ENOMEM; + + fdb->fdb_sbd = sdp; + fdb->fdb_entry = (struct filldir_bad_entry *)(fdb + 1); + fdb->fdb_entry_num = entries; + fdb->fdb_name = ((char *)fdb) + sizeof(struct filldir_bad) + + entries * sizeof(struct filldir_bad_entry); + fdb->fdb_name_size = entries * GFS2_FAST_NAME_SIZE; + + gfs2_holder_init(dip->i_gl, LM_ST_SHARED, GL_ATIME, &d_gh); + error = gfs2_glock_nq_atime(&d_gh); + if (error) { + gfs2_holder_uninit(&d_gh); + goto out; + } + + error = gfs2_dir_read(dip, &offset, fdb, filldir_bad_func); + + gfs2_glock_dq_uninit(&d_gh); + + fdr.fdr_sbd = sdp; + fdr.fdr_prefetch = 0; + fdr.fdr_filldir = filldir; + fdr.fdr_opaque = dirent; + + for (x = 0; x < fdb->fdb_entry_off; x++) { + fbe = &fdb->fdb_entry[x]; + + error = filldir_reg_func(&fdr, + fbe->fbe_name, fbe->fbe_length, + fbe->fbe_offset, + &fbe->fbe_inum, fbe->fbe_type); + if (error) { + file->f_pos = fbe->fbe_offset; + error = 0; + goto out; + } + } + + file->f_pos = offset; + + out: + kfree(fdb); + + return error; +} + +/** + * gfs2_readdir - Read directory entries from a directory + * @file: The directory to read from + * @dirent: Buffer for dirents + * @filldir: Function used to do the copying + * + * Returns: errno + */ + +static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) +{ + int error; + + atomic_inc(&get_v2sdp(file->f_mapping->host->i_sb)->sd_ops_file); + + if (strcmp(current->comm, "nfsd") != 0) + error = readdir_reg(file, dirent, filldir); + else + error = readdir_bad(file, dirent, filldir); + + return error; +} + +static int gfs2_ioctl_flags(struct gfs2_inode *ip, unsigned int cmd, unsigned long arg) +{ + unsigned int lmode = (cmd == GFS2_IOCTL_SETFLAGS) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; + struct buffer_head *dibh; + struct gfs2_holder i_gh; + int error; + __u32 flags = 0, change; + + if (cmd == GFS2_IOCTL_SETFLAGS) { + error = get_user(flags, (__u32 __user *)arg); + if (error) + return -EFAULT; + } + + error = gfs2_glock_nq_init(ip->i_gl, lmode, 0, &i_gh); + if (error) + return error; + + if (cmd == GFS2_IOCTL_SETFLAGS) { + change = flags ^ ip->i_di.di_flags; + error = -EPERM; + if (change & (GFS2_DIF_IMMUTABLE|GFS2_DIF_APPENDONLY)) { + if (!capable(CAP_LINUX_IMMUTABLE)) + goto out; + } + error = -EINVAL; + if (flags & (GFS2_DIF_JDATA|GFS2_DIF_DIRECTIO)) { + if (!S_ISREG(ip->i_di.di_mode)) + goto out; + /* FIXME: Would be nice not to require the following test */ + if ((flags & GFS2_DIF_JDATA) && ip->i_di.di_size) + goto out; + } + if (flags & (GFS2_DIF_INHERIT_JDATA|GFS2_DIF_INHERIT_DIRECTIO)) { + if (!S_ISDIR(ip->i_di.di_mode)) + goto out; + } + + error = gfs2_trans_begin(ip->i_sbd, RES_DINODE, 0); + if (error) + goto out; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto out_trans_end; + + ip->i_di.di_flags = flags; + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + + brelse(dibh); + +out_trans_end: + gfs2_trans_end(ip->i_sbd); + } else { + flags = ip->i_di.di_flags; + } +out: + gfs2_glock_dq_uninit(&i_gh); + if (cmd == GFS2_IOCTL_GETFLAGS) { + if (put_user(flags, (__u32 __user *)arg)) + return -EFAULT; + } + return error; +} + +/** + * gfs2_ioctl - do an ioctl on a file + * @inode: the inode + * @file: the file pointer + * @cmd: the ioctl command + * @arg: the argument + * + * Returns: errno + */ + +static int gfs2_ioctl(struct inode *inode, struct file *file, unsigned int cmd, + unsigned long arg) +{ + struct gfs2_inode *ip = get_v2ip(inode); + + atomic_inc(&ip->i_sbd->sd_ops_file); + + switch (cmd) { + case GFS2_IOCTL_IDENTIFY: { + unsigned int x = GFS2_MAGIC; + if (copy_to_user((unsigned int __user *)arg, &x, sizeof(unsigned int))) + return -EFAULT; + return 0; + + case GFS2_IOCTL_SETFLAGS: + case GFS2_IOCTL_GETFLAGS: + return gfs2_ioctl_flags(ip, cmd, arg); + } + + default: + return -ENOTTY; + } +} + +/** + * gfs2_mmap - + * @file: The file to map + * @vma: The VMA which described the mapping + * + * Returns: 0 or error code + */ + +static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + struct gfs2_holder i_gh; + int error; + + atomic_inc(&ip->i_sbd->sd_ops_file); + + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &i_gh); + error = gfs2_glock_nq_atime(&i_gh); + if (error) { + gfs2_holder_uninit(&i_gh); + return error; + } + + if (gfs2_is_jdata(ip)) { + if (vma->vm_flags & VM_MAYSHARE) + error = -EOPNOTSUPP; + else + vma->vm_ops = &gfs2_vm_ops_private; + } else { + /* This is VM_MAYWRITE instead of VM_WRITE because a call + to mprotect() can turn on VM_WRITE later. */ + + if ((vma->vm_flags & (VM_MAYSHARE | VM_MAYWRITE)) == + (VM_MAYSHARE | VM_MAYWRITE)) + vma->vm_ops = &gfs2_vm_ops_sharewrite; + else + vma->vm_ops = &gfs2_vm_ops_private; + } + + gfs2_glock_dq_uninit(&i_gh); + + return error; +} + +/** + * gfs2_open - open a file + * @inode: the inode to open + * @file: the struct file for this opening + * + * Returns: errno + */ + +static int gfs2_open(struct inode *inode, struct file *file) +{ + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_holder i_gh; + struct gfs2_file *fp; + int error; + + atomic_inc(&ip->i_sbd->sd_ops_file); + + fp = kzalloc(sizeof(struct gfs2_file), GFP_KERNEL); + if (!fp) + return -ENOMEM; + + init_MUTEX(&fp->f_fl_mutex); + + fp->f_inode = ip; + fp->f_vfile = file; + + gfs2_assert_warn(ip->i_sbd, !get_v2fp(file)); + set_v2fp(file, fp); + + if (S_ISREG(ip->i_di.di_mode)) { + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, + &i_gh); + if (error) + goto fail; + + if (!(file->f_flags & O_LARGEFILE) && + ip->i_di.di_size > MAX_NON_LFS) { + error = -EFBIG; + goto fail_gunlock; + } + + /* Listen to the Direct I/O flag */ + + if (ip->i_di.di_flags & GFS2_DIF_DIRECTIO) + file->f_flags |= O_DIRECT; + + /* Don't let the user open O_DIRECT on a jdata file */ + + if ((file->f_flags & O_DIRECT) && gfs2_is_jdata(ip)) { + error = -EINVAL; + goto fail_gunlock; + } + + gfs2_glock_dq_uninit(&i_gh); + } + + return 0; + + fail_gunlock: + gfs2_glock_dq_uninit(&i_gh); + + fail: + set_v2fp(file, NULL); + kfree(fp); + + return error; +} + +/** + * gfs2_close - called to close a struct file + * @inode: the inode the struct file belongs to + * @file: the struct file being closed + * + * Returns: errno + */ + +static int gfs2_close(struct inode *inode, struct file *file) +{ + struct gfs2_sbd *sdp = get_v2sdp(inode->i_sb); + struct gfs2_file *fp; + + atomic_inc(&sdp->sd_ops_file); + + fp = get_v2fp(file); + set_v2fp(file, NULL); + + if (gfs2_assert_warn(sdp, fp)) + return -EIO; + + kfree(fp); + + return 0; +} + +/** + * gfs2_fsync - sync the dirty data for a file (across the cluster) + * @file: the file that points to the dentry (we ignore this) + * @dentry: the dentry that points to the inode to sync + * + * Returns: errno + */ + +static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) +{ + struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + + atomic_inc(&ip->i_sbd->sd_ops_file); + gfs2_log_flush_glock(ip->i_gl); + + return 0; +} + +/** + * gfs2_lock - acquire/release a posix lock on a file + * @file: the file pointer + * @cmd: either modify or retrieve lock state, possibly wait + * @fl: type and range of lock + * + * Returns: errno + */ + +static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) +{ + struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + struct gfs2_sbd *sdp = ip->i_sbd; + struct lm_lockname name = + { .ln_number = ip->i_num.no_addr, + .ln_type = LM_TYPE_PLOCK }; + + atomic_inc(&sdp->sd_ops_file); + + if (!(fl->fl_flags & FL_POSIX)) + return -ENOLCK; + if ((ip->i_di.di_mode & (S_ISGID | S_IXGRP)) == S_ISGID) + return -ENOLCK; + + if (sdp->sd_args.ar_localflocks) { + if (IS_GETLK(cmd)) { + struct file_lock *tmp; + lock_kernel(); + tmp = posix_test_lock(file, fl); + fl->fl_type = F_UNLCK; + if (tmp) + memcpy(fl, tmp, sizeof(struct file_lock)); + unlock_kernel(); + return 0; + } else { + int error; + lock_kernel(); + error = posix_lock_file_wait(file, fl); + unlock_kernel(); + return error; + } + } + + if (IS_GETLK(cmd)) + return gfs2_lm_plock_get(sdp, &name, file, fl); + else if (fl->fl_type == F_UNLCK) + return gfs2_lm_punlock(sdp, &name, file, fl); + else + return gfs2_lm_plock(sdp, &name, file, cmd, fl); +} + +/** + * gfs2_sendfile - Send bytes to a file or socket + * @in_file: The file to read from + * @out_file: The file to write to + * @count: The amount of data + * @offset: The beginning file offset + * + * Outputs: offset - updated according to number of bytes read + * + * Returns: The number of bytes sent, errno on failure + */ + +static ssize_t gfs2_sendfile(struct file *in_file, loff_t *offset, size_t count, + read_actor_t actor, void *target) +{ + struct gfs2_inode *ip = get_v2ip(in_file->f_mapping->host); + struct gfs2_holder gh; + ssize_t retval; + + atomic_inc(&ip->i_sbd->sd_ops_file); + + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); + + retval = gfs2_glock_nq_atime(&gh); + if (retval) + goto out; + + if (gfs2_is_jdata(ip)) + retval = -EOPNOTSUPP; + else + retval = generic_file_sendfile(in_file, offset, count, actor, + target); + + gfs2_glock_dq(&gh); + + out: + gfs2_holder_uninit(&gh); + + return retval; +} + +static int do_flock(struct file *file, int cmd, struct file_lock *fl) +{ + struct gfs2_file *fp = get_v2fp(file); + struct gfs2_holder *fl_gh = &fp->f_fl_gh; + struct gfs2_inode *ip = fp->f_inode; + struct gfs2_glock *gl; + unsigned int state; + int flags; + int error = 0; + + state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; + flags = ((IS_SETLKW(cmd)) ? 0 : LM_FLAG_TRY) | GL_EXACT | GL_NOCACHE; + + down(&fp->f_fl_mutex); + + gl = fl_gh->gh_gl; + if (gl) { + if (fl_gh->gh_state == state) + goto out; + gfs2_glock_hold(gl); + flock_lock_file_wait(file, + &(struct file_lock){.fl_type = F_UNLCK}); + gfs2_glock_dq_uninit(fl_gh); + } else { + error = gfs2_glock_get(ip->i_sbd, + ip->i_num.no_addr, &gfs2_flock_glops, + CREATE, &gl); + if (error) + goto out; + } + + gfs2_holder_init(gl, state, flags, fl_gh); + gfs2_glock_put(gl); + + error = gfs2_glock_nq(fl_gh); + if (error) { + gfs2_holder_uninit(fl_gh); + if (error == GLR_TRYFAILED) + error = -EAGAIN; + } else { + error = flock_lock_file_wait(file, fl); + gfs2_assert_warn(ip->i_sbd, !error); + } + + out: + up(&fp->f_fl_mutex); + + return error; +} + +static void do_unflock(struct file *file, struct file_lock *fl) +{ + struct gfs2_file *fp = get_v2fp(file); + struct gfs2_holder *fl_gh = &fp->f_fl_gh; + + down(&fp->f_fl_mutex); + flock_lock_file_wait(file, fl); + if (fl_gh->gh_gl) + gfs2_glock_dq_uninit(fl_gh); + up(&fp->f_fl_mutex); +} + +/** + * gfs2_flock - acquire/release a flock lock on a file + * @file: the file pointer + * @cmd: either modify or retrieve lock state, possibly wait + * @fl: type and range of lock + * + * Returns: errno + */ + +static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) +{ + struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + struct gfs2_sbd *sdp = ip->i_sbd; + + atomic_inc(&ip->i_sbd->sd_ops_file); + + if (!(fl->fl_flags & FL_FLOCK)) + return -ENOLCK; + if ((ip->i_di.di_mode & (S_ISGID | S_IXGRP)) == S_ISGID) + return -ENOLCK; + + if (sdp->sd_args.ar_localflocks) + return flock_lock_file_wait(file, fl); + + if (fl->fl_type == F_UNLCK) { + do_unflock(file, fl); + return 0; + } else + return do_flock(file, cmd, fl); +} + +struct file_operations gfs2_file_fops = { + .llseek = gfs2_llseek, + .read = gfs2_read, + .write = gfs2_write, + .ioctl = gfs2_ioctl, + .mmap = gfs2_mmap, + .open = gfs2_open, + .release = gfs2_close, + .fsync = gfs2_fsync, + .lock = gfs2_lock, + .sendfile = gfs2_sendfile, + .flock = gfs2_flock, +}; + +struct file_operations gfs2_dir_fops = { + .readdir = gfs2_readdir, + .ioctl = gfs2_ioctl, + .open = gfs2_open, + .release = gfs2_close, + .fsync = gfs2_fsync, + .lock = gfs2_lock, + .flock = gfs2_flock, +}; + diff --git a/fs/gfs2/ops_file.h b/fs/gfs2/ops_file.h new file mode 100644 index 000000000000..95123d7bbcdf --- /dev/null +++ b/fs/gfs2/ops_file.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __OPS_FILE_DOT_H__ +#define __OPS_FILE_DOT_H__ + +extern struct file_operations gfs2_file_fops; +extern struct file_operations gfs2_dir_fops; + +#endif /* __OPS_FILE_DOT_H__ */ diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c new file mode 100644 index 000000000000..c61a80c439a6 --- /dev/null +++ b/fs/gfs2/ops_fstype.c @@ -0,0 +1,879 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "daemon.h" +#include "glock.h" +#include "glops.h" +#include "inode.h" +#include "lm.h" +#include "mount.h" +#include "ops_export.h" +#include "ops_fstype.h" +#include "ops_super.h" +#include "recovery.h" +#include "rgrp.h" +#include "super.h" +#include "unlinked.h" +#include "sys.h" + +#define DO 0 +#define UNDO 1 + +static struct gfs2_sbd *init_sbd(struct super_block *sb) +{ + struct gfs2_sbd *sdp; + unsigned int x; + + sdp = vmalloc(sizeof(struct gfs2_sbd)); + if (!sdp) + return NULL; + + memset(sdp, 0, sizeof(struct gfs2_sbd)); + + set_v2sdp(sb, sdp); + sdp->sd_vfs = sb; + + gfs2_tune_init(&sdp->sd_tune); + + for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { + sdp->sd_gl_hash[x].hb_lock = RW_LOCK_UNLOCKED; + INIT_LIST_HEAD(&sdp->sd_gl_hash[x].hb_list); + } + INIT_LIST_HEAD(&sdp->sd_reclaim_list); + spin_lock_init(&sdp->sd_reclaim_lock); + init_waitqueue_head(&sdp->sd_reclaim_wq); + init_MUTEX(&sdp->sd_invalidate_inodes_mutex); + + init_MUTEX(&sdp->sd_inum_mutex); + spin_lock_init(&sdp->sd_statfs_spin); + init_MUTEX(&sdp->sd_statfs_mutex); + + spin_lock_init(&sdp->sd_rindex_spin); + init_MUTEX(&sdp->sd_rindex_mutex); + INIT_LIST_HEAD(&sdp->sd_rindex_list); + INIT_LIST_HEAD(&sdp->sd_rindex_mru_list); + INIT_LIST_HEAD(&sdp->sd_rindex_recent_list); + + INIT_LIST_HEAD(&sdp->sd_jindex_list); + spin_lock_init(&sdp->sd_jindex_spin); + init_MUTEX(&sdp->sd_jindex_mutex); + + INIT_LIST_HEAD(&sdp->sd_unlinked_list); + spin_lock_init(&sdp->sd_unlinked_spin); + init_MUTEX(&sdp->sd_unlinked_mutex); + + INIT_LIST_HEAD(&sdp->sd_quota_list); + spin_lock_init(&sdp->sd_quota_spin); + init_MUTEX(&sdp->sd_quota_mutex); + + spin_lock_init(&sdp->sd_log_lock); + init_waitqueue_head(&sdp->sd_log_trans_wq); + init_waitqueue_head(&sdp->sd_log_flush_wq); + + INIT_LIST_HEAD(&sdp->sd_log_le_gl); + INIT_LIST_HEAD(&sdp->sd_log_le_buf); + INIT_LIST_HEAD(&sdp->sd_log_le_revoke); + INIT_LIST_HEAD(&sdp->sd_log_le_rg); + INIT_LIST_HEAD(&sdp->sd_log_le_databuf); + + INIT_LIST_HEAD(&sdp->sd_log_blks_list); + init_waitqueue_head(&sdp->sd_log_blks_wait); + + INIT_LIST_HEAD(&sdp->sd_ail1_list); + INIT_LIST_HEAD(&sdp->sd_ail2_list); + + init_MUTEX(&sdp->sd_log_flush_lock); + INIT_LIST_HEAD(&sdp->sd_log_flush_list); + + INIT_LIST_HEAD(&sdp->sd_revoke_list); + + init_MUTEX(&sdp->sd_freeze_lock); + + return sdp; +} + +static void init_vfs(struct gfs2_sbd *sdp) +{ + struct super_block *sb = sdp->sd_vfs; + + sb->s_magic = GFS2_MAGIC; + sb->s_op = &gfs2_super_ops; + sb->s_export_op = &gfs2_export_ops; + sb->s_maxbytes = MAX_LFS_FILESIZE; + + if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME)) + set_bit(SDF_NOATIME, &sdp->sd_flags); + + /* Don't let the VFS update atimes. GFS2 handles this itself. */ + sb->s_flags |= MS_NOATIME | MS_NODIRATIME; + + /* Set up the buffer cache and fill in some fake block size values + to allow us to read-in the on-disk superblock. */ + sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK); + sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; + sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT; + sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; +} + +static int init_names(struct gfs2_sbd *sdp, int silent) +{ + struct gfs2_sb *sb = NULL; + char *proto, *table; + int error = 0; + + proto = sdp->sd_args.ar_lockproto; + table = sdp->sd_args.ar_locktable; + + /* Try to autodetect */ + + if (!proto[0] || !table[0]) { + struct buffer_head *bh; + bh = sb_getblk(sdp->sd_vfs, + GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); + lock_buffer(bh); + clear_buffer_uptodate(bh); + clear_buffer_dirty(bh); + unlock_buffer(bh); + ll_rw_block(READ, 1, &bh); + wait_on_buffer(bh); + + if (!buffer_uptodate(bh)) { + brelse(bh); + return -EIO; + } + + sb = kmalloc(sizeof(struct gfs2_sb), GFP_KERNEL); + if (!sb) { + brelse(bh); + return -ENOMEM; + } + gfs2_sb_in(sb, bh->b_data); + brelse(bh); + + error = gfs2_check_sb(sdp, sb, silent); + if (error) + goto out; + + if (!proto[0]) + proto = sb->sb_lockproto; + if (!table[0]) + table = sb->sb_locktable; + } + + if (!table[0]) + table = sdp->sd_vfs->s_id; + + snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto); + snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table); + + out: + kfree(sb); + + return error; +} + +static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, + int undo) +{ + struct task_struct *p; + int error = 0; + + if (undo) + goto fail_trans; + + p = kthread_run(gfs2_scand, sdp, "gfs2_scand"); + error = IS_ERR(p); + if (error) { + fs_err(sdp, "can't start scand thread: %d\n", error); + return error; + } + sdp->sd_scand_process = p; + + for (sdp->sd_glockd_num = 0; + sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd; + sdp->sd_glockd_num++) { + p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd"); + error = IS_ERR(p); + if (error) { + fs_err(sdp, "can't start glockd thread: %d\n", error); + goto fail; + } + sdp->sd_glockd_process[sdp->sd_glockd_num] = p; + } + + error = gfs2_glock_nq_num(sdp, + GFS2_MOUNT_LOCK, &gfs2_nondisk_glops, + LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE, + mount_gh); + if (error) { + fs_err(sdp, "can't acquire mount glock: %d\n", error); + goto fail; + } + + error = gfs2_glock_nq_num(sdp, + GFS2_LIVE_LOCK, &gfs2_nondisk_glops, + LM_ST_SHARED, + LM_FLAG_NOEXP | GL_EXACT | GL_NEVER_RECURSE, + &sdp->sd_live_gh); + if (error) { + fs_err(sdp, "can't acquire live glock: %d\n", error); + goto fail_mount; + } + + error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops, + CREATE, &sdp->sd_rename_gl); + if (error) { + fs_err(sdp, "can't create rename glock: %d\n", error); + goto fail_live; + } + + error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops, + CREATE, &sdp->sd_trans_gl); + if (error) { + fs_err(sdp, "can't create transaction glock: %d\n", error); + goto fail_rename; + } + set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags); + + return 0; + + fail_trans: + gfs2_glock_put(sdp->sd_trans_gl); + + fail_rename: + gfs2_glock_put(sdp->sd_rename_gl); + + fail_live: + gfs2_glock_dq_uninit(&sdp->sd_live_gh); + + fail_mount: + gfs2_glock_dq_uninit(mount_gh); + + fail: + while (sdp->sd_glockd_num--) + kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); + + kthread_stop(sdp->sd_scand_process); + + return error; +} + +static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) +{ + struct super_block *sb = sdp->sd_vfs; + struct gfs2_holder sb_gh; + int error = 0; + + if (undo) { + gfs2_inode_put(sdp->sd_master_dir); + return 0; + } + + error = gfs2_glock_nq_num(sdp, + GFS2_SB_LOCK, &gfs2_meta_glops, + LM_ST_SHARED, 0, &sb_gh); + if (error) { + fs_err(sdp, "can't acquire superblock glock: %d\n", error); + return error; + } + + error = gfs2_read_sb(sdp, sb_gh.gh_gl, silent); + if (error) { + fs_err(sdp, "can't read superblock: %d\n", error); + goto out; + } + + /* Set up the buffer cache and SB for real */ + error = -EINVAL; + if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) { + fs_err(sdp, "FS block size (%u) is too small for device " + "block size (%u)\n", + sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev)); + goto out; + } + if (sdp->sd_sb.sb_bsize > PAGE_SIZE) { + fs_err(sdp, "FS block size (%u) is too big for machine " + "page size (%u)\n", + sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE); + goto out; + } + + /* Get rid of buffers from the original block size */ + sb_gh.gh_gl->gl_ops->go_inval(sb_gh.gh_gl, DIO_METADATA | DIO_DATA); + sb_gh.gh_gl->gl_aspace->i_blkbits = sdp->sd_sb.sb_bsize_shift; + + sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); + + error = gfs2_lookup_master_dir(sdp); + if (error) + fs_err(sdp, "can't read in master directory: %d\n", error); + + out: + gfs2_glock_dq_uninit(&sb_gh); + + return error; +} + +static int init_journal(struct gfs2_sbd *sdp, int undo) +{ + struct gfs2_holder ji_gh; + struct task_struct *p; + int jindex = 1; + int error = 0; + + if (undo) { + jindex = 0; + goto fail_recoverd; + } + + error = gfs2_lookup_simple(sdp->sd_master_dir, "jindex", + &sdp->sd_jindex); + if (error) { + fs_err(sdp, "can't lookup journal index: %d\n", error); + return error; + } + set_bit(GLF_STICKY, &sdp->sd_jindex->i_gl->gl_flags); + + /* Load in the journal index special file */ + + error = gfs2_jindex_hold(sdp, &ji_gh); + if (error) { + fs_err(sdp, "can't read journal index: %d\n", error); + goto fail; + } + + error = -EINVAL; + if (!gfs2_jindex_size(sdp)) { + fs_err(sdp, "no journals!\n"); + goto fail_jindex; + } + + if (sdp->sd_args.ar_spectator) { + sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0); + sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks; + } else { + if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) { + fs_err(sdp, "can't mount journal #%u\n", + sdp->sd_lockstruct.ls_jid); + fs_err(sdp, "there are only %u journals (0 - %u)\n", + gfs2_jindex_size(sdp), + gfs2_jindex_size(sdp) - 1); + goto fail_jindex; + } + sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid); + + error = gfs2_glock_nq_num(sdp, + sdp->sd_lockstruct.ls_jid, + &gfs2_journal_glops, + LM_ST_EXCLUSIVE, LM_FLAG_NOEXP, + &sdp->sd_journal_gh); + if (error) { + fs_err(sdp, "can't acquire journal glock: %d\n", error); + goto fail_jindex; + } + + error = gfs2_glock_nq_init(sdp->sd_jdesc->jd_inode->i_gl, + LM_ST_SHARED, + LM_FLAG_NOEXP | GL_EXACT, + &sdp->sd_jinode_gh); + if (error) { + fs_err(sdp, "can't acquire journal inode glock: %d\n", + error); + goto fail_journal_gh; + } + + error = gfs2_jdesc_check(sdp->sd_jdesc); + if (error) { + fs_err(sdp, "my journal (%u) is bad: %d\n", + sdp->sd_jdesc->jd_jid, error); + goto fail_jinode_gh; + } + sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks; + } + + if (sdp->sd_lockstruct.ls_first) { + unsigned int x; + for (x = 0; x < sdp->sd_journals; x++) { + error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x), + WAIT); + if (error) { + fs_err(sdp, "error recovering journal %u: %d\n", + x, error); + goto fail_jinode_gh; + } + } + + gfs2_lm_others_may_mount(sdp); + } else if (!sdp->sd_args.ar_spectator) { + error = gfs2_recover_journal(sdp->sd_jdesc, WAIT); + if (error) { + fs_err(sdp, "error recovering my journal: %d\n", error); + goto fail_jinode_gh; + } + } + + set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags); + gfs2_glock_dq_uninit(&ji_gh); + jindex = 0; + + /* Disown my Journal glock */ + + sdp->sd_journal_gh.gh_owner = NULL; + sdp->sd_jinode_gh.gh_owner = NULL; + + p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd"); + error = IS_ERR(p); + if (error) { + fs_err(sdp, "can't start recoverd thread: %d\n", error); + goto fail_jinode_gh; + } + sdp->sd_recoverd_process = p; + + return 0; + + fail_recoverd: + kthread_stop(sdp->sd_recoverd_process); + + fail_jinode_gh: + if (!sdp->sd_args.ar_spectator) + gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); + + fail_journal_gh: + if (!sdp->sd_args.ar_spectator) + gfs2_glock_dq_uninit(&sdp->sd_journal_gh); + + fail_jindex: + gfs2_jindex_free(sdp); + if (jindex) + gfs2_glock_dq_uninit(&ji_gh); + + fail: + gfs2_inode_put(sdp->sd_jindex); + + return error; +} + +int gfs2_lookup_root(struct gfs2_sbd *sdp) +{ + int error; + struct gfs2_glock *gl; + + error = gfs2_glock_get(sdp, sdp->sd_sb.sb_root_dir.no_addr, + &gfs2_inode_glops, CREATE, &gl); + if (!error) { + error = gfs2_inode_get(gl, &sdp->sd_sb.sb_root_dir, + CREATE, &sdp->sd_root_dir); + if (!error) + gfs2_inode_min_init(sdp->sd_root_dir, DT_DIR); + gfs2_glock_put(gl); + } + + return error; +} + + +static int init_inodes(struct gfs2_sbd *sdp, int undo) +{ + struct inode *inode; + struct dentry **dentry = &sdp->sd_vfs->s_root; + int error = 0; + + if (undo) + goto fail_dput; + + /* Read in the master inode number inode */ + error = gfs2_lookup_simple(sdp->sd_master_dir, "inum", + &sdp->sd_inum_inode); + if (error) { + fs_err(sdp, "can't read in inum inode: %d\n", error); + return error; + } + + /* Read in the master statfs inode */ + error = gfs2_lookup_simple(sdp->sd_master_dir, "statfs", + &sdp->sd_statfs_inode); + if (error) { + fs_err(sdp, "can't read in statfs inode: %d\n", error); + goto fail; + } + + /* Read in the resource index inode */ + error = gfs2_lookup_simple(sdp->sd_master_dir, "rindex", + &sdp->sd_rindex); + if (error) { + fs_err(sdp, "can't get resource index inode: %d\n", error); + goto fail_statfs; + } + set_bit(GLF_STICKY, &sdp->sd_rindex->i_gl->gl_flags); + sdp->sd_rindex_vn = sdp->sd_rindex->i_gl->gl_vn - 1; + + /* Read in the quota inode */ + error = gfs2_lookup_simple(sdp->sd_master_dir, "quota", + &sdp->sd_quota_inode); + if (error) { + fs_err(sdp, "can't get quota file inode: %d\n", error); + goto fail_rindex; + } + + /* Get the root inode */ + error = gfs2_lookup_root(sdp); + if (error) { + fs_err(sdp, "can't read in root inode: %d\n", error); + goto fail_qinode; + } + + /* Get the root inode/dentry */ + inode = gfs2_ip2v(sdp->sd_root_dir); + if (!inode) { + fs_err(sdp, "can't get root inode\n"); + error = -ENOMEM; + goto fail_rooti; + } + + *dentry = d_alloc_root(inode); + if (!*dentry) { + iput(inode); + fs_err(sdp, "can't get root dentry\n"); + error = -ENOMEM; + goto fail_rooti; + } + + return 0; + + fail_dput: + dput(*dentry); + *dentry = NULL; + + fail_rooti: + gfs2_inode_put(sdp->sd_root_dir); + + fail_qinode: + gfs2_inode_put(sdp->sd_quota_inode); + + fail_rindex: + gfs2_clear_rgrpd(sdp); + gfs2_inode_put(sdp->sd_rindex); + + fail_statfs: + gfs2_inode_put(sdp->sd_statfs_inode); + + fail: + gfs2_inode_put(sdp->sd_inum_inode); + + return error; +} + +static int init_per_node(struct gfs2_sbd *sdp, int undo) +{ + struct gfs2_inode *pn = NULL; + char buf[30]; + int error = 0; + + if (sdp->sd_args.ar_spectator) + return 0; + + if (undo) + goto fail_qc_gh; + + error = gfs2_lookup_simple(sdp->sd_master_dir, "per_node", &pn); + if (error) { + fs_err(sdp, "can't find per_node directory: %d\n", error); + return error; + } + + sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid); + error = gfs2_lookup_simple(pn, buf, &sdp->sd_ir_inode); + if (error) { + fs_err(sdp, "can't find local \"ir\" file: %d\n", error); + goto fail; + } + + sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid); + error = gfs2_lookup_simple(pn, buf, &sdp->sd_sc_inode); + if (error) { + fs_err(sdp, "can't find local \"sc\" file: %d\n", error); + goto fail_ir_i; + } + + sprintf(buf, "unlinked_tag%u", sdp->sd_jdesc->jd_jid); + error = gfs2_lookup_simple(pn, buf, &sdp->sd_ut_inode); + if (error) { + fs_err(sdp, "can't find local \"ut\" file: %d\n", error); + goto fail_sc_i; + } + + sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid); + error = gfs2_lookup_simple(pn, buf, &sdp->sd_qc_inode); + if (error) { + fs_err(sdp, "can't find local \"qc\" file: %d\n", error); + goto fail_ut_i; + } + + gfs2_inode_put(pn); + pn = NULL; + + error = gfs2_glock_nq_init(sdp->sd_ir_inode->i_gl, + LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, + &sdp->sd_ir_gh); + if (error) { + fs_err(sdp, "can't lock local \"ir\" file: %d\n", error); + goto fail_qc_i; + } + + error = gfs2_glock_nq_init(sdp->sd_sc_inode->i_gl, + LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, + &sdp->sd_sc_gh); + if (error) { + fs_err(sdp, "can't lock local \"sc\" file: %d\n", error); + goto fail_ir_gh; + } + + error = gfs2_glock_nq_init(sdp->sd_ut_inode->i_gl, + LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, + &sdp->sd_ut_gh); + if (error) { + fs_err(sdp, "can't lock local \"ut\" file: %d\n", error); + goto fail_sc_gh; + } + + error = gfs2_glock_nq_init(sdp->sd_qc_inode->i_gl, + LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, + &sdp->sd_qc_gh); + if (error) { + fs_err(sdp, "can't lock local \"qc\" file: %d\n", error); + goto fail_ut_gh; + } + + return 0; + + fail_qc_gh: + gfs2_glock_dq_uninit(&sdp->sd_qc_gh); + + fail_ut_gh: + gfs2_glock_dq_uninit(&sdp->sd_ut_gh); + + fail_sc_gh: + gfs2_glock_dq_uninit(&sdp->sd_sc_gh); + + fail_ir_gh: + gfs2_glock_dq_uninit(&sdp->sd_ir_gh); + + fail_qc_i: + gfs2_inode_put(sdp->sd_qc_inode); + + fail_ut_i: + gfs2_inode_put(sdp->sd_ut_inode); + + fail_sc_i: + gfs2_inode_put(sdp->sd_sc_inode); + + fail_ir_i: + gfs2_inode_put(sdp->sd_ir_inode); + + fail: + if (pn) + gfs2_inode_put(pn); + return error; +} + +static int init_threads(struct gfs2_sbd *sdp, int undo) +{ + struct task_struct *p; + int error = 0; + + if (undo) + goto fail_inoded; + + sdp->sd_log_flush_time = jiffies; + sdp->sd_jindex_refresh_time = jiffies; + + p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); + error = IS_ERR(p); + if (error) { + fs_err(sdp, "can't start logd thread: %d\n", error); + return error; + } + sdp->sd_logd_process = p; + + sdp->sd_statfs_sync_time = jiffies; + sdp->sd_quota_sync_time = jiffies; + + p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad"); + error = IS_ERR(p); + if (error) { + fs_err(sdp, "can't start quotad thread: %d\n", error); + goto fail; + } + sdp->sd_quotad_process = p; + + p = kthread_run(gfs2_inoded, sdp, "gfs2_inoded"); + error = IS_ERR(p); + if (error) { + fs_err(sdp, "can't start inoded thread: %d\n", error); + goto fail_quotad; + } + sdp->sd_inoded_process = p; + + return 0; + + fail_inoded: + kthread_stop(sdp->sd_inoded_process); + + fail_quotad: + kthread_stop(sdp->sd_quotad_process); + + fail: + kthread_stop(sdp->sd_logd_process); + + return error; +} + +/** + * fill_super - Read in superblock + * @sb: The VFS superblock + * @data: Mount options + * @silent: Don't complain if it's not a GFS2 filesystem + * + * Returns: errno + */ + +static int fill_super(struct super_block *sb, void *data, int silent) +{ + struct gfs2_sbd *sdp; + struct gfs2_holder mount_gh; + int error; + + sdp = init_sbd(sb); + if (!sdp) { + printk("GFS2: can't alloc struct gfs2_sbd\n"); + return -ENOMEM; + } + + error = gfs2_mount_args(sdp, (char *)data, 0); + if (error) { + printk("GFS2: can't parse mount arguments\n"); + goto fail; + } + + init_vfs(sdp); + + error = init_names(sdp, silent); + if (error) + goto fail; + + error = gfs2_sys_fs_add(sdp); + if (error) + goto fail; + + error = gfs2_lm_mount(sdp, silent); + if (error) + goto fail_sys; + + error = init_locking(sdp, &mount_gh, DO); + if (error) + goto fail_lm; + + error = init_sb(sdp, silent, DO); + if (error) + goto fail_locking; + + error = init_journal(sdp, DO); + if (error) + goto fail_sb; + + error = init_inodes(sdp, DO); + if (error) + goto fail_journals; + + error = init_per_node(sdp, DO); + if (error) + goto fail_inodes; + + error = gfs2_statfs_init(sdp); + if (error) { + fs_err(sdp, "can't initialize statfs subsystem: %d\n", error); + goto fail_per_node; + } + + error = init_threads(sdp, DO); + if (error) + goto fail_per_node; + + if (!(sb->s_flags & MS_RDONLY)) { + error = gfs2_make_fs_rw(sdp); + if (error) { + fs_err(sdp, "can't make FS RW: %d\n", error); + goto fail_threads; + } + } + + gfs2_glock_dq_uninit(&mount_gh); + + return 0; + + fail_threads: + init_threads(sdp, UNDO); + + fail_per_node: + init_per_node(sdp, UNDO); + + fail_inodes: + init_inodes(sdp, UNDO); + + fail_journals: + init_journal(sdp, UNDO); + + fail_sb: + init_sb(sdp, 0, UNDO); + + fail_locking: + init_locking(sdp, &mount_gh, UNDO); + + fail_lm: + gfs2_gl_hash_clear(sdp, WAIT); + gfs2_lm_unmount(sdp); + while (invalidate_inodes(sb)) + yield(); + + fail_sys: + gfs2_sys_fs_del(sdp); + + fail: + vfree(sdp); + set_v2sdp(sb, NULL); + + return error; +} + +static struct super_block *gfs2_get_sb(struct file_system_type *fs_type, + int flags, const char *dev_name, + void *data) +{ + return get_sb_bdev(fs_type, flags, dev_name, data, fill_super); +} + +struct file_system_type gfs2_fs_type = { + .name = "gfs2", + .fs_flags = FS_REQUIRES_DEV, + .get_sb = gfs2_get_sb, + .kill_sb = kill_block_super, + .owner = THIS_MODULE, +}; + diff --git a/fs/gfs2/ops_fstype.h b/fs/gfs2/ops_fstype.h new file mode 100644 index 000000000000..7008364e76ea --- /dev/null +++ b/fs/gfs2/ops_fstype.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __OPS_FSTYPE_DOT_H__ +#define __OPS_FSTYPE_DOT_H__ + +extern struct file_system_type gfs2_fs_type; + +#endif /* __OPS_FSTYPE_DOT_H__ */ diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c new file mode 100644 index 000000000000..d0f90b88380c --- /dev/null +++ b/fs/gfs2/ops_inode.c @@ -0,0 +1,1265 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "acl.h" +#include "bmap.h" +#include "dir.h" +#include "eaops.h" +#include "eattr.h" +#include "glock.h" +#include "inode.h" +#include "meta_io.h" +#include "ops_dentry.h" +#include "ops_inode.h" +#include "page.h" +#include "quota.h" +#include "rgrp.h" +#include "trans.h" +#include "unlinked.h" + +/** + * gfs2_create - Create a file + * @dir: The directory in which to create the file + * @dentry: The dentry of the new file + * @mode: The mode of the new file + * + * Returns: errno + */ + +static int gfs2_create(struct inode *dir, struct dentry *dentry, + int mode, struct nameidata *nd) +{ + struct gfs2_inode *dip = get_v2ip(dir), *ip; + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_holder ghs[2]; + struct inode *inode; + int new = 1; + int error; + + atomic_inc(&sdp->sd_ops_inode); + + gfs2_holder_init(dip->i_gl, 0, 0, ghs); + + for (;;) { + error = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode); + if (!error) { + ip = get_gl2ip(ghs[1].gh_gl); + gfs2_trans_end(sdp); + if (dip->i_alloc.al_rgd) + gfs2_inplace_release(dip); + gfs2_quota_unlock(dip); + gfs2_alloc_put(dip); + gfs2_glock_dq_uninit_m(2, ghs); + break; + } else if (error != -EEXIST || + (nd->intent.open.flags & O_EXCL)) { + gfs2_holder_uninit(ghs); + return error; + } + + error = gfs2_lookupi(dip, &dentry->d_name, 0, &ip); + if (!error) { + new = 0; + gfs2_holder_uninit(ghs); + break; + } else if (error != -ENOENT) { + gfs2_holder_uninit(ghs); + return error; + } + } + + inode = gfs2_ip2v(ip); + gfs2_inode_put(ip); + + if (!inode) + return -ENOMEM; + + d_instantiate(dentry, inode); + if (new) + mark_inode_dirty(inode); + + return 0; +} + +/** + * gfs2_lookup - Look up a filename in a directory and return its inode + * @dir: The directory inode + * @dentry: The dentry of the new inode + * @nd: passed from Linux VFS, ignored by us + * + * Called by the VFS layer. Lock dir and call gfs2_lookupi() + * + * Returns: errno + */ + +static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, + struct nameidata *nd) +{ + struct gfs2_inode *dip = get_v2ip(dir), *ip; + struct gfs2_sbd *sdp = dip->i_sbd; + struct inode *inode = NULL; + int error; + + atomic_inc(&sdp->sd_ops_inode); + + if (!sdp->sd_args.ar_localcaching) + dentry->d_op = &gfs2_dops; + + error = gfs2_lookupi(dip, &dentry->d_name, 0, &ip); + if (!error) { + inode = gfs2_ip2v(ip); + gfs2_inode_put(ip); + if (!inode) + return ERR_PTR(-ENOMEM); + + } else if (error != -ENOENT) + return ERR_PTR(error); + + if (inode) + return d_splice_alias(inode, dentry); + d_add(dentry, inode); + + return NULL; +} + +/** + * gfs2_link - Link to a file + * @old_dentry: The inode to link + * @dir: Add link to this directory + * @dentry: The name of the link + * + * Link the inode in "old_dentry" into the directory "dir" with the + * name in "dentry". + * + * Returns: errno + */ + +static int gfs2_link(struct dentry *old_dentry, struct inode *dir, + struct dentry *dentry) +{ + struct gfs2_inode *dip = get_v2ip(dir); + struct gfs2_sbd *sdp = dip->i_sbd; + struct inode *inode = old_dentry->d_inode; + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_holder ghs[2]; + int alloc_required; + int error; + + atomic_inc(&sdp->sd_ops_inode); + + if (S_ISDIR(ip->i_di.di_mode)) + return -EPERM; + + gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); + + error = gfs2_glock_nq_m(2, ghs); + if (error) + goto out; + + error = gfs2_repermission(dir, MAY_WRITE | MAY_EXEC, NULL); + if (error) + goto out_gunlock; + + error = gfs2_dir_search(dip, &dentry->d_name, NULL, NULL); + switch (error) { + case -ENOENT: + break; + case 0: + error = -EEXIST; + default: + goto out_gunlock; + } + + error = -EINVAL; + if (!dip->i_di.di_nlink) + goto out_gunlock; + error = -EFBIG; + if (dip->i_di.di_entries == (uint32_t)-1) + goto out_gunlock; + error = -EPERM; + if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) + goto out_gunlock; + error = -EINVAL; + if (!ip->i_di.di_nlink) + goto out_gunlock; + error = -EMLINK; + if (ip->i_di.di_nlink == (uint32_t)-1) + goto out_gunlock; + + error = gfs2_diradd_alloc_required(dip, &dentry->d_name, + &alloc_required); + if (error) + goto out_gunlock; + + if (alloc_required) { + struct gfs2_alloc *al = gfs2_alloc_get(dip); + + error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out_alloc; + + error = gfs2_quota_check(dip, dip->i_di.di_uid, + dip->i_di.di_gid); + if (error) + goto out_gunlock_q; + + al->al_requested = sdp->sd_max_dirres; + + error = gfs2_inplace_reserve(dip); + if (error) + goto out_gunlock_q; + + error = gfs2_trans_begin(sdp, + sdp->sd_max_dirres + + al->al_rgd->rd_ri.ri_length + + 2 * RES_DINODE + RES_STATFS + + RES_QUOTA, 0); + if (error) + goto out_ipres; + } else { + error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0); + if (error) + goto out_ipres; + } + + error = gfs2_dir_add(dip, &dentry->d_name, &ip->i_num, + IF2DT(ip->i_di.di_mode)); + if (error) + goto out_end_trans; + + error = gfs2_change_nlink(ip, +1); + + out_end_trans: + gfs2_trans_end(sdp); + + out_ipres: + if (alloc_required) + gfs2_inplace_release(dip); + + out_gunlock_q: + if (alloc_required) + gfs2_quota_unlock(dip); + + out_alloc: + if (alloc_required) + gfs2_alloc_put(dip); + + out_gunlock: + gfs2_glock_dq_m(2, ghs); + + out: + gfs2_holder_uninit(ghs); + gfs2_holder_uninit(ghs + 1); + + if (!error) { + atomic_inc(&inode->i_count); + d_instantiate(dentry, inode); + mark_inode_dirty(inode); + } + + return error; +} + +/** + * gfs2_unlink - Unlink a file + * @dir: The inode of the directory containing the file to unlink + * @dentry: The file itself + * + * Unlink a file. Call gfs2_unlinki() + * + * Returns: errno + */ + +static int gfs2_unlink(struct inode *dir, struct dentry *dentry) +{ + struct gfs2_inode *dip = get_v2ip(dir); + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + struct gfs2_unlinked *ul; + struct gfs2_holder ghs[2]; + int error; + + atomic_inc(&sdp->sd_ops_inode); + + error = gfs2_unlinked_get(sdp, &ul); + if (error) + return error; + + gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); + + error = gfs2_glock_nq_m(2, ghs); + if (error) + goto out; + + error = gfs2_unlink_ok(dip, &dentry->d_name, ip); + if (error) + goto out_gunlock; + + error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF + + RES_UNLINKED, 0); + if (error) + goto out_gunlock; + + error = gfs2_unlinki(dip, &dentry->d_name, ip,ul); + + gfs2_trans_end(sdp); + + out_gunlock: + gfs2_glock_dq_m(2, ghs); + + out: + gfs2_holder_uninit(ghs); + gfs2_holder_uninit(ghs + 1); + + gfs2_unlinked_put(sdp, ul); + + return error; +} + +/** + * gfs2_symlink - Create a symlink + * @dir: The directory to create the symlink in + * @dentry: The dentry to put the symlink in + * @symname: The thing which the link points to + * + * Returns: errno + */ + +static int gfs2_symlink(struct inode *dir, struct dentry *dentry, + const char *symname) +{ + struct gfs2_inode *dip = get_v2ip(dir), *ip; + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_holder ghs[2]; + struct inode *inode; + struct buffer_head *dibh; + int size; + int error; + + atomic_inc(&sdp->sd_ops_inode); + + /* Must be stuffed with a null terminator for gfs2_follow_link() */ + size = strlen(symname); + if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1) + return -ENAMETOOLONG; + + gfs2_holder_init(dip->i_gl, 0, 0, ghs); + + error = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO); + if (error) { + gfs2_holder_uninit(ghs); + return error; + } + + ip = get_gl2ip(ghs[1].gh_gl); + + ip->i_di.di_size = size; + + error = gfs2_meta_inode_buffer(ip, &dibh); + + if (!gfs2_assert_withdraw(sdp, !error)) { + gfs2_dinode_out(&ip->i_di, dibh->b_data); + memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname, + size); + brelse(dibh); + } + + gfs2_trans_end(sdp); + if (dip->i_alloc.al_rgd) + gfs2_inplace_release(dip); + gfs2_quota_unlock(dip); + gfs2_alloc_put(dip); + + gfs2_glock_dq_uninit_m(2, ghs); + + inode = gfs2_ip2v(ip); + gfs2_inode_put(ip); + + if (!inode) + return -ENOMEM; + + d_instantiate(dentry, inode); + mark_inode_dirty(inode); + + return 0; +} + +/** + * gfs2_mkdir - Make a directory + * @dir: The parent directory of the new one + * @dentry: The dentry of the new directory + * @mode: The mode of the new directory + * + * Returns: errno + */ + +static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) +{ + struct gfs2_inode *dip = get_v2ip(dir), *ip; + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_holder ghs[2]; + struct inode *inode; + struct buffer_head *dibh; + int error; + + atomic_inc(&sdp->sd_ops_inode); + + gfs2_holder_init(dip->i_gl, 0, 0, ghs); + + error = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode); + if (error) { + gfs2_holder_uninit(ghs); + return error; + } + + ip = get_gl2ip(ghs[1].gh_gl); + + ip->i_di.di_nlink = 2; + ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode); + ip->i_di.di_flags |= GFS2_DIF_JDATA; + ip->i_di.di_payload_format = GFS2_FORMAT_DE; + ip->i_di.di_entries = 2; + + error = gfs2_meta_inode_buffer(ip, &dibh); + + if (!gfs2_assert_withdraw(sdp, !error)) { + struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data; + struct gfs2_dirent *dent; + + gfs2_dirent_alloc(ip, dibh, 1, &dent); + + dent->de_inum = di->di_num; /* already GFS2 endian */ + dent->de_hash = gfs2_disk_hash(".", 1); + dent->de_hash = cpu_to_be32(dent->de_hash); + dent->de_type = DT_DIR; + memcpy((char *) (dent + 1), ".", 1); + di->di_entries = cpu_to_be32(1); + + gfs2_dirent_alloc(ip, dibh, 2, &dent); + + gfs2_inum_out(&dip->i_num, (char *) &dent->de_inum); + dent->de_hash = gfs2_disk_hash("..", 2); + dent->de_hash = cpu_to_be32(dent->de_hash); + dent->de_type = DT_DIR; + memcpy((char *) (dent + 1), "..", 2); + + gfs2_dinode_out(&ip->i_di, (char *)di); + + brelse(dibh); + } + + error = gfs2_change_nlink(dip, +1); + gfs2_assert_withdraw(sdp, !error); /* dip already pinned */ + + gfs2_trans_end(sdp); + if (dip->i_alloc.al_rgd) + gfs2_inplace_release(dip); + gfs2_quota_unlock(dip); + gfs2_alloc_put(dip); + + gfs2_glock_dq_uninit_m(2, ghs); + + inode = gfs2_ip2v(ip); + gfs2_inode_put(ip); + + if (!inode) + return -ENOMEM; + + d_instantiate(dentry, inode); + mark_inode_dirty(inode); + + return 0; +} + +/** + * gfs2_rmdir - Remove a directory + * @dir: The parent directory of the directory to be removed + * @dentry: The dentry of the directory to remove + * + * Remove a directory. Call gfs2_rmdiri() + * + * Returns: errno + */ + +static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) +{ + struct gfs2_inode *dip = get_v2ip(dir); + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + struct gfs2_unlinked *ul; + struct gfs2_holder ghs[2]; + int error; + + atomic_inc(&sdp->sd_ops_inode); + + error = gfs2_unlinked_get(sdp, &ul); + if (error) + return error; + + gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); + + error = gfs2_glock_nq_m(2, ghs); + if (error) + goto out; + + error = gfs2_unlink_ok(dip, &dentry->d_name, ip); + if (error) + goto out_gunlock; + + if (ip->i_di.di_entries < 2) { + if (gfs2_consist_inode(ip)) + gfs2_dinode_print(&ip->i_di); + error = -EIO; + goto out_gunlock; + } + if (ip->i_di.di_entries > 2) { + error = -ENOTEMPTY; + goto out_gunlock; + } + + error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + + RES_UNLINKED, 0); + if (error) + goto out_gunlock; + + error = gfs2_rmdiri(dip, &dentry->d_name, ip, ul); + + gfs2_trans_end(sdp); + + out_gunlock: + gfs2_glock_dq_m(2, ghs); + + out: + gfs2_holder_uninit(ghs); + gfs2_holder_uninit(ghs + 1); + + gfs2_unlinked_put(sdp, ul); + + return error; +} + +/** + * gfs2_mknod - Make a special file + * @dir: The directory in which the special file will reside + * @dentry: The dentry of the special file + * @mode: The mode of the special file + * @rdev: The device specification of the special file + * + */ + +static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, + dev_t dev) +{ + struct gfs2_inode *dip = get_v2ip(dir), *ip; + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_holder ghs[2]; + struct inode *inode; + struct buffer_head *dibh; + uint32_t major = 0, minor = 0; + int error; + + atomic_inc(&sdp->sd_ops_inode); + + switch (mode & S_IFMT) { + case S_IFBLK: + case S_IFCHR: + major = MAJOR(dev); + minor = MINOR(dev); + break; + case S_IFIFO: + case S_IFSOCK: + break; + default: + return -EOPNOTSUPP; + }; + + gfs2_holder_init(dip->i_gl, 0, 0, ghs); + + error = gfs2_createi(ghs, &dentry->d_name, mode); + if (error) { + gfs2_holder_uninit(ghs); + return error; + } + + ip = get_gl2ip(ghs[1].gh_gl); + + ip->i_di.di_major = major; + ip->i_di.di_minor = minor; + + error = gfs2_meta_inode_buffer(ip, &dibh); + + if (!gfs2_assert_withdraw(sdp, !error)) { + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + gfs2_trans_end(sdp); + if (dip->i_alloc.al_rgd) + gfs2_inplace_release(dip); + gfs2_quota_unlock(dip); + gfs2_alloc_put(dip); + + gfs2_glock_dq_uninit_m(2, ghs); + + inode = gfs2_ip2v(ip); + gfs2_inode_put(ip); + + if (!inode) + return -ENOMEM; + + d_instantiate(dentry, inode); + mark_inode_dirty(inode); + + return 0; +} + +/** + * gfs2_rename - Rename a file + * @odir: Parent directory of old file name + * @odentry: The old dentry of the file + * @ndir: Parent directory of new file name + * @ndentry: The new dentry of the file + * + * Returns: errno + */ + +static int gfs2_rename(struct inode *odir, struct dentry *odentry, + struct inode *ndir, struct dentry *ndentry) +{ + struct gfs2_inode *odip = get_v2ip(odir); + struct gfs2_inode *ndip = get_v2ip(ndir); + struct gfs2_inode *ip = get_v2ip(odentry->d_inode); + struct gfs2_inode *nip = NULL; + struct gfs2_sbd *sdp = odip->i_sbd; + struct gfs2_unlinked *ul; + struct gfs2_holder ghs[4], r_gh; + unsigned int num_gh; + int dir_rename = 0; + int alloc_required; + unsigned int x; + int error; + + atomic_inc(&sdp->sd_ops_inode); + + if (ndentry->d_inode) { + nip = get_v2ip(ndentry->d_inode); + if (ip == nip) + return 0; + } + + error = gfs2_unlinked_get(sdp, &ul); + if (error) + return error; + + /* Make sure we aren't trying to move a dirctory into it's subdir */ + + if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) { + dir_rename = 1; + + error = gfs2_glock_nq_init(sdp->sd_rename_gl, + LM_ST_EXCLUSIVE, 0, + &r_gh); + if (error) + goto out; + + error = gfs2_ok_to_move(ip, ndip); + if (error) + goto out_gunlock_r; + } + + gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); + gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 2); + num_gh = 3; + + if (nip) + gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++); + + error = gfs2_glock_nq_m(num_gh, ghs); + if (error) + goto out_uninit; + + /* Check out the old directory */ + + error = gfs2_unlink_ok(odip, &odentry->d_name, ip); + if (error) + goto out_gunlock; + + /* Check out the new directory */ + + if (nip) { + error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip); + if (error) + goto out_gunlock; + + if (S_ISDIR(nip->i_di.di_mode)) { + if (nip->i_di.di_entries < 2) { + if (gfs2_consist_inode(nip)) + gfs2_dinode_print(&nip->i_di); + error = -EIO; + goto out_gunlock; + } + if (nip->i_di.di_entries > 2) { + error = -ENOTEMPTY; + goto out_gunlock; + } + } + } else { + error = gfs2_repermission(ndir, MAY_WRITE | MAY_EXEC, NULL); + if (error) + goto out_gunlock; + + error = gfs2_dir_search(ndip, &ndentry->d_name, NULL, NULL); + switch (error) { + case -ENOENT: + error = 0; + break; + case 0: + error = -EEXIST; + default: + goto out_gunlock; + }; + + if (odip != ndip) { + if (!ndip->i_di.di_nlink) { + error = -EINVAL; + goto out_gunlock; + } + if (ndip->i_di.di_entries == (uint32_t)-1) { + error = -EFBIG; + goto out_gunlock; + } + if (S_ISDIR(ip->i_di.di_mode) && + ndip->i_di.di_nlink == (uint32_t)-1) { + error = -EMLINK; + goto out_gunlock; + } + } + } + + /* Check out the dir to be renamed */ + + if (dir_rename) { + error = gfs2_repermission(odentry->d_inode, MAY_WRITE, NULL); + if (error) + goto out_gunlock; + } + + error = gfs2_diradd_alloc_required(ndip, &ndentry->d_name, + &alloc_required); + if (error) + goto out_gunlock; + + if (alloc_required) { + struct gfs2_alloc *al = gfs2_alloc_get(ndip); + + error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out_alloc; + + error = gfs2_quota_check(ndip, ndip->i_di.di_uid, + ndip->i_di.di_gid); + if (error) + goto out_gunlock_q; + + al->al_requested = sdp->sd_max_dirres; + + error = gfs2_inplace_reserve(ndip); + if (error) + goto out_gunlock_q; + + error = gfs2_trans_begin(sdp, + sdp->sd_max_dirres + + al->al_rgd->rd_ri.ri_length + + 4 * RES_DINODE + 4 * RES_LEAF + + RES_UNLINKED + RES_STATFS + + RES_QUOTA, 0); + if (error) + goto out_ipreserv; + } else { + error = gfs2_trans_begin(sdp, 4 * RES_DINODE + + 5 * RES_LEAF + + RES_UNLINKED, 0); + if (error) + goto out_gunlock; + } + + /* Remove the target file, if it exists */ + + if (nip) { + if (S_ISDIR(nip->i_di.di_mode)) + error = gfs2_rmdiri(ndip, &ndentry->d_name, nip, ul); + else + error = gfs2_unlinki(ndip, &ndentry->d_name, nip, ul); + if (error) + goto out_end_trans; + } + + if (dir_rename) { + struct qstr name; + name.len = 2; + name.name = ".."; + + error = gfs2_change_nlink(ndip, +1); + if (error) + goto out_end_trans; + error = gfs2_change_nlink(odip, -1); + if (error) + goto out_end_trans; + + error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR); + if (error) + goto out_end_trans; + } else { + struct buffer_head *dibh; + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto out_end_trans; + ip->i_di.di_ctime = get_seconds(); + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + + error = gfs2_dir_del(odip, &odentry->d_name); + if (error) + goto out_end_trans; + + error = gfs2_dir_add(ndip, &ndentry->d_name, &ip->i_num, + IF2DT(ip->i_di.di_mode)); + if (error) + goto out_end_trans; + + out_end_trans: + gfs2_trans_end(sdp); + + out_ipreserv: + if (alloc_required) + gfs2_inplace_release(ndip); + + out_gunlock_q: + if (alloc_required) + gfs2_quota_unlock(ndip); + + out_alloc: + if (alloc_required) + gfs2_alloc_put(ndip); + + out_gunlock: + gfs2_glock_dq_m(num_gh, ghs); + + out_uninit: + for (x = 0; x < num_gh; x++) + gfs2_holder_uninit(ghs + x); + + out_gunlock_r: + if (dir_rename) + gfs2_glock_dq_uninit(&r_gh); + + out: + gfs2_unlinked_put(sdp, ul); + + return error; +} + +/** + * gfs2_readlink - Read the value of a symlink + * @dentry: the symlink + * @buf: the buffer to read the symlink data into + * @size: the size of the buffer + * + * Returns: errno + */ + +static int gfs2_readlink(struct dentry *dentry, char __user *user_buf, + int user_size) +{ + struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + char array[GFS2_FAST_NAME_SIZE], *buf = array; + unsigned int len = GFS2_FAST_NAME_SIZE; + int error; + + atomic_inc(&ip->i_sbd->sd_ops_inode); + + error = gfs2_readlinki(ip, &buf, &len); + if (error) + return error; + + if (user_size > len - 1) + user_size = len - 1; + + if (copy_to_user(user_buf, buf, user_size)) + error = -EFAULT; + else + error = user_size; + + if (buf != array) + kfree(buf); + + return error; +} + +/** + * gfs2_follow_link - Follow a symbolic link + * @dentry: The dentry of the link + * @nd: Data that we pass to vfs_follow_link() + * + * This can handle symlinks of any size. It is optimised for symlinks + * under GFS2_FAST_NAME_SIZE. + * + * Returns: 0 on success or error code + */ + +static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) +{ + struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + char array[GFS2_FAST_NAME_SIZE], *buf = array; + unsigned int len = GFS2_FAST_NAME_SIZE; + int error; + + atomic_inc(&ip->i_sbd->sd_ops_inode); + + error = gfs2_readlinki(ip, &buf, &len); + if (!error) { + error = vfs_follow_link(nd, buf); + if (buf != array) + kfree(buf); + } + + return ERR_PTR(error); +} + +/** + * gfs2_permission - + * @inode: + * @mask: + * @nd: passed from Linux VFS, ignored by us + * + * Returns: errno + */ + +static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd) +{ + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_holder i_gh; + int error; + + atomic_inc(&ip->i_sbd->sd_ops_inode); + + if (ip->i_vn == ip->i_gl->gl_vn) + return generic_permission(inode, mask, gfs2_check_acl); + + error = gfs2_glock_nq_init(ip->i_gl, + LM_ST_SHARED, LM_FLAG_ANY, + &i_gh); + if (!error) { + error = generic_permission(inode, mask, gfs2_check_acl_locked); + gfs2_glock_dq_uninit(&i_gh); + } + + return error; +} + +static int setattr_size(struct inode *inode, struct iattr *attr) +{ + struct gfs2_inode *ip = get_v2ip(inode); + int error; + + if (attr->ia_size != ip->i_di.di_size) { + error = vmtruncate(inode, attr->ia_size); + if (error) + return error; + } + + error = gfs2_truncatei(ip, attr->ia_size, gfs2_truncator_page); + if (error) + return error; + + return error; +} + +static int setattr_chown(struct inode *inode, struct iattr *attr) +{ + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head *dibh; + uint32_t ouid, ogid, nuid, ngid; + int error; + + ouid = ip->i_di.di_uid; + ogid = ip->i_di.di_gid; + nuid = attr->ia_uid; + ngid = attr->ia_gid; + + if (!(attr->ia_valid & ATTR_UID) || ouid == nuid) + ouid = nuid = NO_QUOTA_CHANGE; + if (!(attr->ia_valid & ATTR_GID) || ogid == ngid) + ogid = ngid = NO_QUOTA_CHANGE; + + gfs2_alloc_get(ip); + + error = gfs2_quota_lock(ip, nuid, ngid); + if (error) + goto out_alloc; + + if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { + error = gfs2_quota_check(ip, nuid, ngid); + if (error) + goto out_gunlock_q; + } + + error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0); + if (error) + goto out_gunlock_q; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto out_end_trans; + + error = inode_setattr(inode, attr); + gfs2_assert_warn(sdp, !error); + gfs2_inode_attr_out(ip); + + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + + if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { + gfs2_quota_change(ip, -ip->i_di.di_blocks, + ouid, ogid); + gfs2_quota_change(ip, ip->i_di.di_blocks, + nuid, ngid); + } + + out_end_trans: + gfs2_trans_end(sdp); + + out_gunlock_q: + gfs2_quota_unlock(ip); + + out_alloc: + gfs2_alloc_put(ip); + + return error; +} + +/** + * gfs2_setattr - Change attributes on an inode + * @dentry: The dentry which is changing + * @attr: The structure describing the change + * + * The VFS layer wants to change one or more of an inodes attributes. Write + * that change out to disk. + * + * Returns: errno + */ + +static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) +{ + struct inode *inode = dentry->d_inode; + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_holder i_gh; + int error; + + atomic_inc(&ip->i_sbd->sd_ops_inode); + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); + if (error) + return error; + + error = -EPERM; + if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) + goto out; + + error = inode_change_ok(inode, attr); + if (error) + goto out; + + if (attr->ia_valid & ATTR_SIZE) + error = setattr_size(inode, attr); + else if (attr->ia_valid & (ATTR_UID | ATTR_GID)) + error = setattr_chown(inode, attr); + else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode)) + error = gfs2_acl_chmod(ip, attr); + else + error = gfs2_setattr_simple(ip, attr); + + out: + gfs2_glock_dq_uninit(&i_gh); + + if (!error) + mark_inode_dirty(inode); + + return error; +} + +/** + * gfs2_getattr - Read out an inode's attributes + * @mnt: ? + * @dentry: The dentry to stat + * @stat: The inode's stats + * + * Returns: errno + */ + +static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, + struct kstat *stat) +{ + struct inode *inode = dentry->d_inode; + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_holder gh; + int error; + + atomic_inc(&ip->i_sbd->sd_ops_inode); + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); + if (!error) { + generic_fillattr(inode, stat); + gfs2_glock_dq_uninit(&gh); + } + + return error; +} + +static int gfs2_setxattr(struct dentry *dentry, const char *name, + const void *data, size_t size, int flags) +{ + struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + struct gfs2_ea_request er; + + atomic_inc(&ip->i_sbd->sd_ops_inode); + + memset(&er, 0, sizeof(struct gfs2_ea_request)); + er.er_type = gfs2_ea_name2type(name, &er.er_name); + if (er.er_type == GFS2_EATYPE_UNUSED) + return -EOPNOTSUPP; + er.er_data = (char *)data; + er.er_name_len = strlen(er.er_name); + er.er_data_len = size; + er.er_flags = flags; + + gfs2_assert_warn(ip->i_sbd, !(er.er_flags & GFS2_ERF_MODE)); + + return gfs2_ea_set(ip, &er); +} + +static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, + void *data, size_t size) +{ + struct gfs2_ea_request er; + + atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode); + + memset(&er, 0, sizeof(struct gfs2_ea_request)); + er.er_type = gfs2_ea_name2type(name, &er.er_name); + if (er.er_type == GFS2_EATYPE_UNUSED) + return -EOPNOTSUPP; + er.er_data = data; + er.er_name_len = strlen(er.er_name); + er.er_data_len = size; + + return gfs2_ea_get(get_v2ip(dentry->d_inode), &er); +} + +static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) +{ + struct gfs2_ea_request er; + + atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode); + + memset(&er, 0, sizeof(struct gfs2_ea_request)); + er.er_data = (size) ? buffer : NULL; + er.er_data_len = size; + + return gfs2_ea_list(get_v2ip(dentry->d_inode), &er); +} + +static int gfs2_removexattr(struct dentry *dentry, const char *name) +{ + struct gfs2_ea_request er; + + atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode); + + memset(&er, 0, sizeof(struct gfs2_ea_request)); + er.er_type = gfs2_ea_name2type(name, &er.er_name); + if (er.er_type == GFS2_EATYPE_UNUSED) + return -EOPNOTSUPP; + er.er_name_len = strlen(er.er_name); + + return gfs2_ea_remove(get_v2ip(dentry->d_inode), &er); +} + +struct inode_operations gfs2_file_iops = { + .permission = gfs2_permission, + .setattr = gfs2_setattr, + .getattr = gfs2_getattr, + .setxattr = gfs2_setxattr, + .getxattr = gfs2_getxattr, + .listxattr = gfs2_listxattr, + .removexattr = gfs2_removexattr, +}; + +struct inode_operations gfs2_dev_iops = { + .permission = gfs2_permission, + .setattr = gfs2_setattr, + .getattr = gfs2_getattr, + .setxattr = gfs2_setxattr, + .getxattr = gfs2_getxattr, + .listxattr = gfs2_listxattr, + .removexattr = gfs2_removexattr, +}; + +struct inode_operations gfs2_dir_iops = { + .create = gfs2_create, + .lookup = gfs2_lookup, + .link = gfs2_link, + .unlink = gfs2_unlink, + .symlink = gfs2_symlink, + .mkdir = gfs2_mkdir, + .rmdir = gfs2_rmdir, + .mknod = gfs2_mknod, + .rename = gfs2_rename, + .permission = gfs2_permission, + .setattr = gfs2_setattr, + .getattr = gfs2_getattr, + .setxattr = gfs2_setxattr, + .getxattr = gfs2_getxattr, + .listxattr = gfs2_listxattr, + .removexattr = gfs2_removexattr, +}; + +struct inode_operations gfs2_symlink_iops = { + .readlink = gfs2_readlink, + .follow_link = gfs2_follow_link, + .permission = gfs2_permission, + .setattr = gfs2_setattr, + .getattr = gfs2_getattr, + .setxattr = gfs2_setxattr, + .getxattr = gfs2_getxattr, + .listxattr = gfs2_listxattr, + .removexattr = gfs2_removexattr, +}; + diff --git a/fs/gfs2/ops_inode.h b/fs/gfs2/ops_inode.h new file mode 100644 index 000000000000..5fafd87c8d7b --- /dev/null +++ b/fs/gfs2/ops_inode.h @@ -0,0 +1,18 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __OPS_INODE_DOT_H__ +#define __OPS_INODE_DOT_H__ + +extern struct inode_operations gfs2_file_iops; +extern struct inode_operations gfs2_dir_iops; +extern struct inode_operations gfs2_symlink_iops; +extern struct inode_operations gfs2_dev_iops; + +#endif /* __OPS_INODE_DOT_H__ */ diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c new file mode 100644 index 000000000000..ca6a4d81bc26 --- /dev/null +++ b/fs/gfs2/ops_super.c @@ -0,0 +1,401 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "glock.h" +#include "inode.h" +#include "lm.h" +#include "log.h" +#include "mount.h" +#include "ops_super.h" +#include "page.h" +#include "quota.h" +#include "recovery.h" +#include "rgrp.h" +#include "super.h" +#include "sys.h" + +/** + * gfs2_write_inode - Make sure the inode is stable on the disk + * @inode: The inode + * @sync: synchronous write flag + * + * Returns: errno + */ + +static int gfs2_write_inode(struct inode *inode, int sync) +{ + struct gfs2_inode *ip = get_v2ip(inode); + + atomic_inc(&ip->i_sbd->sd_ops_super); + + if (current->flags & PF_MEMALLOC) + return 0; + if (ip && sync) + gfs2_log_flush_glock(ip->i_gl); + + return 0; +} + +/** + * gfs2_put_super - Unmount the filesystem + * @sb: The VFS superblock + * + */ + +static void gfs2_put_super(struct super_block *sb) +{ + struct gfs2_sbd *sdp = get_v2sdp(sb); + int error; + + if (!sdp) + return; + + atomic_inc(&sdp->sd_ops_super); + + /* Unfreeze the filesystem, if we need to */ + + down(&sdp->sd_freeze_lock); + if (sdp->sd_freeze_count) + gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); + up(&sdp->sd_freeze_lock); + + kthread_stop(sdp->sd_inoded_process); + kthread_stop(sdp->sd_quotad_process); + kthread_stop(sdp->sd_logd_process); + kthread_stop(sdp->sd_recoverd_process); + while (sdp->sd_glockd_num--) + kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); + kthread_stop(sdp->sd_scand_process); + + if (!(sb->s_flags & MS_RDONLY)) { + error = gfs2_make_fs_ro(sdp); + if (error) + gfs2_io_error(sdp); + } + + /* At this point, we're through modifying the disk */ + + /* Release stuff */ + + gfs2_inode_put(sdp->sd_master_dir); + gfs2_inode_put(sdp->sd_jindex); + gfs2_inode_put(sdp->sd_inum_inode); + gfs2_inode_put(sdp->sd_statfs_inode); + gfs2_inode_put(sdp->sd_rindex); + gfs2_inode_put(sdp->sd_quota_inode); + gfs2_inode_put(sdp->sd_root_dir); + + gfs2_glock_put(sdp->sd_rename_gl); + gfs2_glock_put(sdp->sd_trans_gl); + + if (!sdp->sd_args.ar_spectator) { + gfs2_glock_dq_uninit(&sdp->sd_journal_gh); + gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); + gfs2_glock_dq_uninit(&sdp->sd_ir_gh); + gfs2_glock_dq_uninit(&sdp->sd_sc_gh); + gfs2_glock_dq_uninit(&sdp->sd_ut_gh); + gfs2_glock_dq_uninit(&sdp->sd_qc_gh); + gfs2_inode_put(sdp->sd_ir_inode); + gfs2_inode_put(sdp->sd_sc_inode); + gfs2_inode_put(sdp->sd_ut_inode); + gfs2_inode_put(sdp->sd_qc_inode); + } + + gfs2_glock_dq_uninit(&sdp->sd_live_gh); + + gfs2_clear_rgrpd(sdp); + gfs2_jindex_free(sdp); + + /* Take apart glock structures and buffer lists */ + gfs2_gl_hash_clear(sdp, WAIT); + + /* Unmount the locking protocol */ + gfs2_lm_unmount(sdp); + + /* At this point, we're through participating in the lockspace */ + + gfs2_sys_fs_del(sdp); + + /* Get rid of any extra inodes */ + while (invalidate_inodes(sb)) + yield(); + + vfree(sdp); + + set_v2sdp(sb, NULL); +} + +/** + * gfs2_write_super - disk commit all incore transactions + * @sb: the filesystem + * + * This function is called every time sync(2) is called. + * After this exits, all dirty buffers and synced. + */ + +static void gfs2_write_super(struct super_block *sb) +{ + struct gfs2_sbd *sdp = get_v2sdp(sb); + atomic_inc(&sdp->sd_ops_super); + gfs2_log_flush(sdp); +} + +/** + * gfs2_write_super_lockfs - prevent further writes to the filesystem + * @sb: the VFS structure for the filesystem + * + */ + +static void gfs2_write_super_lockfs(struct super_block *sb) +{ + struct gfs2_sbd *sdp = get_v2sdp(sb); + int error; + + atomic_inc(&sdp->sd_ops_super); + + for (;;) { + error = gfs2_freeze_fs(sdp); + if (!error) + break; + + switch (error) { + case -EBUSY: + fs_err(sdp, "waiting for recovery before freeze\n"); + break; + + default: + fs_err(sdp, "error freezing FS: %d\n", error); + break; + } + + fs_err(sdp, "retrying...\n"); + msleep(1000); + } +} + +/** + * gfs2_unlockfs - reallow writes to the filesystem + * @sb: the VFS structure for the filesystem + * + */ + +static void gfs2_unlockfs(struct super_block *sb) +{ + struct gfs2_sbd *sdp = get_v2sdp(sb); + + atomic_inc(&sdp->sd_ops_super); + gfs2_unfreeze_fs(sdp); +} + +/** + * gfs2_statfs - Gather and return stats about the filesystem + * @sb: The superblock + * @statfsbuf: The buffer + * + * Returns: 0 on success or error code + */ + +static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf) +{ + struct gfs2_sbd *sdp = get_v2sdp(sb); + struct gfs2_statfs_change sc; + int error; + + atomic_inc(&sdp->sd_ops_super); + + if (gfs2_tune_get(sdp, gt_statfs_slow)) + error = gfs2_statfs_slow(sdp, &sc); + else + error = gfs2_statfs_i(sdp, &sc); + + if (error) + return error; + + memset(buf, 0, sizeof(struct kstatfs)); + + buf->f_type = GFS2_MAGIC; + buf->f_bsize = sdp->sd_sb.sb_bsize; + buf->f_blocks = sc.sc_total; + buf->f_bfree = sc.sc_free; + buf->f_bavail = sc.sc_free; + buf->f_files = sc.sc_dinodes + sc.sc_free; + buf->f_ffree = sc.sc_free; + buf->f_namelen = GFS2_FNAMESIZE; + + return 0; +} + +/** + * gfs2_remount_fs - called when the FS is remounted + * @sb: the filesystem + * @flags: the remount flags + * @data: extra data passed in (not used right now) + * + * Returns: errno + */ + +static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) +{ + struct gfs2_sbd *sdp = get_v2sdp(sb); + int error; + + atomic_inc(&sdp->sd_ops_super); + + error = gfs2_mount_args(sdp, data, 1); + if (error) + return error; + + if (sdp->sd_args.ar_spectator) + *flags |= MS_RDONLY; + else { + if (*flags & MS_RDONLY) { + if (!(sb->s_flags & MS_RDONLY)) + error = gfs2_make_fs_ro(sdp); + } else if (!(*flags & MS_RDONLY) && + (sb->s_flags & MS_RDONLY)) { + error = gfs2_make_fs_rw(sdp); + } + } + + if (*flags & (MS_NOATIME | MS_NODIRATIME)) + set_bit(SDF_NOATIME, &sdp->sd_flags); + else + clear_bit(SDF_NOATIME, &sdp->sd_flags); + + /* Don't let the VFS update atimes. GFS2 handles this itself. */ + *flags |= MS_NOATIME | MS_NODIRATIME; + + return error; +} + +/** + * gfs2_clear_inode - Deallocate an inode when VFS is done with it + * @inode: The VFS inode + * + */ + +static void gfs2_clear_inode(struct inode *inode) +{ + struct gfs2_inode *ip = get_v2ip(inode); + + atomic_inc(&get_v2sdp(inode->i_sb)->sd_ops_super); + + if (ip) { + spin_lock(&ip->i_spin); + ip->i_vnode = NULL; + set_v2ip(inode, NULL); + spin_unlock(&ip->i_spin); + + gfs2_glock_schedule_for_reclaim(ip->i_gl); + gfs2_inode_put(ip); + } +} + +/** + * gfs2_show_options - Show mount options for /proc/mounts + * @s: seq_file structure + * @mnt: vfsmount + * + * Returns: 0 on success or error code + */ + +static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) +{ + struct gfs2_sbd *sdp = get_v2sdp(mnt->mnt_sb); + struct gfs2_args *args = &sdp->sd_args; + + atomic_inc(&sdp->sd_ops_super); + + if (args->ar_lockproto[0]) + seq_printf(s, ",lockproto=%s", args->ar_lockproto); + if (args->ar_locktable[0]) + seq_printf(s, ",locktable=%s", args->ar_locktable); + if (args->ar_hostdata[0]) + seq_printf(s, ",hostdata=%s", args->ar_hostdata); + if (args->ar_spectator) + seq_printf(s, ",spectator"); + if (args->ar_ignore_local_fs) + seq_printf(s, ",ignore_local_fs"); + if (args->ar_localflocks) + seq_printf(s, ",localflocks"); + if (args->ar_localcaching) + seq_printf(s, ",localcaching"); + if (args->ar_debug) + seq_printf(s, ",debug"); + if (args->ar_upgrade) + seq_printf(s, ",upgrade"); + if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT) + seq_printf(s, ",num_glockd=%u", args->ar_num_glockd); + if (args->ar_posix_acl) + seq_printf(s, ",acl"); + if (args->ar_quota != GFS2_QUOTA_DEFAULT) { + char *state; + switch (args->ar_quota) { + case GFS2_QUOTA_OFF: + state = "off"; + break; + case GFS2_QUOTA_ACCOUNT: + state = "account"; + break; + case GFS2_QUOTA_ON: + state = "on"; + break; + default: + state = "unknown"; + break; + } + seq_printf(s, ",quota=%s", state); + } + if (args->ar_suiddir) + seq_printf(s, ",suiddir"); + if (args->ar_data != GFS2_DATA_DEFAULT) { + char *state; + switch (args->ar_data) { + case GFS2_DATA_WRITEBACK: + state = "writeback"; + break; + case GFS2_DATA_ORDERED: + state = "ordered"; + break; + default: + state = "unknown"; + break; + } + seq_printf(s, ",data=%s", state); + } + + return 0; +} + +struct super_operations gfs2_super_ops = { + .write_inode = gfs2_write_inode, + .put_super = gfs2_put_super, + .write_super = gfs2_write_super, + .write_super_lockfs = gfs2_write_super_lockfs, + .unlockfs = gfs2_unlockfs, + .statfs = gfs2_statfs, + .remount_fs = gfs2_remount_fs, + .clear_inode = gfs2_clear_inode, + .show_options = gfs2_show_options, +}; + diff --git a/fs/gfs2/ops_super.h b/fs/gfs2/ops_super.h new file mode 100644 index 000000000000..a41d208dc558 --- /dev/null +++ b/fs/gfs2/ops_super.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __OPS_SUPER_DOT_H__ +#define __OPS_SUPER_DOT_H__ + +extern struct super_operations gfs2_super_ops; + +#endif /* __OPS_SUPER_DOT_H__ */ diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c new file mode 100644 index 000000000000..a1b409ce75e1 --- /dev/null +++ b/fs/gfs2/ops_vm.c @@ -0,0 +1,199 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "glock.h" +#include "inode.h" +#include "ops_vm.h" +#include "page.h" +#include "quota.h" +#include "rgrp.h" +#include "trans.h" + +static void pfault_be_greedy(struct gfs2_inode *ip) +{ + unsigned int time; + + spin_lock(&ip->i_spin); + time = ip->i_greedy; + ip->i_last_pfault = jiffies; + spin_unlock(&ip->i_spin); + + gfs2_inode_hold(ip); + if (gfs2_glock_be_greedy(ip->i_gl, time)) + gfs2_inode_put(ip); +} + +static struct page *gfs2_private_nopage(struct vm_area_struct *area, + unsigned long address, int *type) +{ + struct gfs2_inode *ip = get_v2ip(area->vm_file->f_mapping->host); + struct gfs2_holder i_gh; + struct page *result; + int error; + + atomic_inc(&ip->i_sbd->sd_ops_vm); + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); + if (error) + return NULL; + + set_bit(GIF_PAGED, &ip->i_flags); + + result = filemap_nopage(area, address, type); + + if (result && result != NOPAGE_OOM) + pfault_be_greedy(ip); + + gfs2_glock_dq_uninit(&i_gh); + + return result; +} + +static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + unsigned long index = page->index; + uint64_t lblock = index << (PAGE_CACHE_SHIFT - sdp->sd_sb.sb_bsize_shift); + unsigned int blocks = PAGE_CACHE_SIZE >> sdp->sd_sb.sb_bsize_shift; + struct gfs2_alloc *al; + unsigned int data_blocks, ind_blocks; + unsigned int x; + int error; + + al = gfs2_alloc_get(ip); + + error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out; + + error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid); + if (error) + goto out_gunlock_q; + + gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, + &data_blocks, &ind_blocks); + + al->al_requested = data_blocks + ind_blocks; + + error = gfs2_inplace_reserve(ip); + if (error) + goto out_gunlock_q; + + error = gfs2_trans_begin(sdp, + al->al_rgd->rd_ri.ri_length + + ind_blocks + RES_DINODE + + RES_STATFS + RES_QUOTA, 0); + if (error) + goto out_ipres; + + if (gfs2_is_stuffed(ip)) { + error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, NULL); + if (error) + goto out_trans; + } + + for (x = 0; x < blocks; ) { + uint64_t dblock; + unsigned int extlen; + int new = 1; + + error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); + if (error) + goto out_trans; + + lblock += extlen; + x += extlen; + } + + gfs2_assert_warn(sdp, al->al_alloced); + + out_trans: + gfs2_trans_end(sdp); + + out_ipres: + gfs2_inplace_release(ip); + + out_gunlock_q: + gfs2_quota_unlock(ip); + + out: + gfs2_alloc_put(ip); + + return error; +} + +static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, + unsigned long address, int *type) +{ + struct gfs2_inode *ip = get_v2ip(area->vm_file->f_mapping->host); + struct gfs2_holder i_gh; + struct page *result = NULL; + unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) + area->vm_pgoff; + int alloc_required; + int error; + + atomic_inc(&ip->i_sbd->sd_ops_vm); + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); + if (error) + return NULL; + + if (gfs2_is_jdata(ip)) + goto out; + + set_bit(GIF_PAGED, &ip->i_flags); + set_bit(GIF_SW_PAGED, &ip->i_flags); + + error = gfs2_write_alloc_required(ip, + (uint64_t)index << PAGE_CACHE_SHIFT, + PAGE_CACHE_SIZE, &alloc_required); + if (error) + goto out; + + result = filemap_nopage(area, address, type); + if (!result || result == NOPAGE_OOM) + goto out; + + if (alloc_required) { + error = alloc_page_backing(ip, result); + if (error) { + page_cache_release(result); + result = NULL; + goto out; + } + set_page_dirty(result); + } + + pfault_be_greedy(ip); + + out: + gfs2_glock_dq_uninit(&i_gh); + + return result; +} + +struct vm_operations_struct gfs2_vm_ops_private = { + .nopage = gfs2_private_nopage, +}; + +struct vm_operations_struct gfs2_vm_ops_sharewrite = { + .nopage = gfs2_sharewrite_nopage, +}; + diff --git a/fs/gfs2/ops_vm.h b/fs/gfs2/ops_vm.h new file mode 100644 index 000000000000..54e3a8769cbb --- /dev/null +++ b/fs/gfs2/ops_vm.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __OPS_VM_DOT_H__ +#define __OPS_VM_DOT_H__ + +extern struct vm_operations_struct gfs2_vm_ops_private; +extern struct vm_operations_struct gfs2_vm_ops_sharewrite; + +#endif /* __OPS_VM_DOT_H__ */ diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c new file mode 100644 index 000000000000..05453c5a06f0 --- /dev/null +++ b/fs/gfs2/page.c @@ -0,0 +1,273 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "inode.h" +#include "page.h" +#include "trans.h" + +/** + * gfs2_pte_inval - Sync and invalidate all PTEs associated with a glock + * @gl: the glock + * + */ + +void gfs2_pte_inval(struct gfs2_glock *gl) +{ + struct gfs2_inode *ip; + struct inode *inode; + + ip = get_gl2ip(gl); + if (!ip || !S_ISREG(ip->i_di.di_mode)) + return; + + if (!test_bit(GIF_PAGED, &ip->i_flags)) + return; + + inode = gfs2_ip2v_lookup(ip); + if (inode) { + unmap_shared_mapping_range(inode->i_mapping, 0, 0); + iput(inode); + + if (test_bit(GIF_SW_PAGED, &ip->i_flags)) + set_bit(GLF_DIRTY, &gl->gl_flags); + } + + clear_bit(GIF_SW_PAGED, &ip->i_flags); +} + +/** + * gfs2_page_inval - Invalidate all pages associated with a glock + * @gl: the glock + * + */ + +void gfs2_page_inval(struct gfs2_glock *gl) +{ + struct gfs2_inode *ip; + struct inode *inode; + + ip = get_gl2ip(gl); + if (!ip || !S_ISREG(ip->i_di.di_mode)) + return; + + inode = gfs2_ip2v_lookup(ip); + if (inode) { + struct address_space *mapping = inode->i_mapping; + + truncate_inode_pages(mapping, 0); + gfs2_assert_withdraw(ip->i_sbd, !mapping->nrpages); + + iput(inode); + } + + clear_bit(GIF_PAGED, &ip->i_flags); +} + +/** + * gfs2_page_sync - Sync the data pages (not metadata) associated with a glock + * @gl: the glock + * @flags: DIO_START | DIO_WAIT + * + * Syncs data (not metadata) for a regular file. + * No-op for all other types. + */ + +void gfs2_page_sync(struct gfs2_glock *gl, int flags) +{ + struct gfs2_inode *ip; + struct inode *inode; + + ip = get_gl2ip(gl); + if (!ip || !S_ISREG(ip->i_di.di_mode)) + return; + + inode = gfs2_ip2v_lookup(ip); + if (inode) { + struct address_space *mapping = inode->i_mapping; + int error = 0; + + if (flags & DIO_START) + filemap_fdatawrite(mapping); + if (!error && (flags & DIO_WAIT)) + error = filemap_fdatawait(mapping); + + /* Put back any errors cleared by filemap_fdatawait() + so they can be caught by someone who can pass them + up to user space. */ + + if (error == -ENOSPC) + set_bit(AS_ENOSPC, &mapping->flags); + else if (error) + set_bit(AS_EIO, &mapping->flags); + + iput(inode); + } +} + +/** + * gfs2_unstuffer_page - unstuff a stuffed inode into a block cached by a page + * @ip: the inode + * @dibh: the dinode buffer + * @block: the block number that was allocated + * @private: any locked page held by the caller process + * + * Returns: errno + */ + +int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, + uint64_t block, void *private) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct inode *inode = ip->i_vnode; + struct page *page = (struct page *)private; + struct buffer_head *bh; + int release = 0; + + if (!page || page->index) { + page = grab_cache_page(inode->i_mapping, 0); + if (!page) + return -ENOMEM; + release = 1; + } + + if (!PageUptodate(page)) { + void *kaddr = kmap(page); + + memcpy(kaddr, + dibh->b_data + sizeof(struct gfs2_dinode), + ip->i_di.di_size); + memset(kaddr + ip->i_di.di_size, + 0, + PAGE_CACHE_SIZE - ip->i_di.di_size); + kunmap(page); + + SetPageUptodate(page); + } + + if (!page_has_buffers(page)) + create_empty_buffers(page, 1 << inode->i_blkbits, + (1 << BH_Uptodate)); + + bh = page_buffers(page); + + if (!buffer_mapped(bh)) + map_bh(bh, inode->i_sb, block); + + set_buffer_uptodate(bh); + if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) + gfs2_trans_add_databuf(sdp, bh); + mark_buffer_dirty(bh); + + if (release) { + unlock_page(page); + page_cache_release(page); + } + + return 0; +} + +/** + * gfs2_truncator_page - truncate a partial data block in the page cache + * @ip: the inode + * @size: the size the file should be + * + * Returns: errno + */ + +int gfs2_truncator_page(struct gfs2_inode *ip, uint64_t size) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct inode *inode = ip->i_vnode; + struct page *page; + struct buffer_head *bh; + void *kaddr; + uint64_t lbn, dbn; + unsigned long index; + unsigned int offset; + unsigned int bufnum; + int new = 0; + int error; + + lbn = size >> inode->i_blkbits; + error = gfs2_block_map(ip, lbn, &new, &dbn, NULL); + if (error || !dbn) + return error; + + index = size >> PAGE_CACHE_SHIFT; + offset = size & (PAGE_CACHE_SIZE - 1); + bufnum = lbn - (index << (PAGE_CACHE_SHIFT - inode->i_blkbits)); + + page = read_cache_page(inode->i_mapping, index, + (filler_t *)inode->i_mapping->a_ops->readpage, + NULL); + if (IS_ERR(page)) + return PTR_ERR(page); + + lock_page(page); + + if (!PageUptodate(page) || PageError(page)) { + error = -EIO; + goto out; + } + + kaddr = kmap(page); + memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset); + kunmap(page); + + if (!page_has_buffers(page)) + create_empty_buffers(page, 1 << inode->i_blkbits, + (1 << BH_Uptodate)); + + for (bh = page_buffers(page); bufnum--; bh = bh->b_this_page) + /* Do nothing */; + + if (!buffer_mapped(bh)) + map_bh(bh, inode->i_sb, dbn); + + set_buffer_uptodate(bh); + if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) + gfs2_trans_add_databuf(sdp, bh); + mark_buffer_dirty(bh); + + out: + unlock_page(page); + page_cache_release(page); + + return error; +} + +void gfs2_page_add_databufs(struct gfs2_sbd *sdp, struct page *page, + unsigned int from, unsigned int to) +{ + struct buffer_head *head = page_buffers(page); + unsigned int bsize = head->b_size; + struct buffer_head *bh; + unsigned int start, end; + + for (bh = head, start = 0; + bh != head || !start; + bh = bh->b_this_page, start = end) { + end = start + bsize; + if (end <= from || start >= to) + continue; + gfs2_trans_add_databuf(sdp, bh); + } +} + diff --git a/fs/gfs2/page.h b/fs/gfs2/page.h new file mode 100644 index 000000000000..7ad8c99ee0ef --- /dev/null +++ b/fs/gfs2/page.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __PAGE_DOT_H__ +#define __PAGE_DOT_H__ + +void gfs2_pte_inval(struct gfs2_glock *gl); +void gfs2_page_inval(struct gfs2_glock *gl); +void gfs2_page_sync(struct gfs2_glock *gl, int flags); + +int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, + uint64_t block, void *private); +int gfs2_truncator_page(struct gfs2_inode *ip, uint64_t size); +void gfs2_page_add_databufs(struct gfs2_sbd *sdp, struct page *page, + unsigned int from, unsigned int to); + +#endif /* __PAGE_DOT_H__ */ diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c new file mode 100644 index 000000000000..a0320f22b57b --- /dev/null +++ b/fs/gfs2/quota.c @@ -0,0 +1,1238 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +/* + * Quota change tags are associated with each transaction that allocates or + * deallocates space. Those changes are accumulated locally to each node (in a + * per-node file) and then are periodically synced to the quota file. This + * avoids the bottleneck of constantly touching the quota file, but introduces + * fuzziness in the current usage value of IDs that are being used on different + * nodes in the cluster simultaneously. So, it is possible for a user on + * multiple nodes to overrun their quota, but that overrun is controlable. + * Since quota tags are part of transactions, there is no need to a quota check + * program to be run on node crashes or anything like that. + * + * There are couple of knobs that let the administrator manage the quota + * fuzziness. "quota_quantum" sets the maximum time a quota change can be + * sitting on one node before being synced to the quota file. (The default is + * 60 seconds.) Another knob, "quota_scale" controls how quickly the frequency + * of quota file syncs increases as the user moves closer to their limit. The + * more frequent the syncs, the more accurate the quota enforcement, but that + * means that there is more contention between the nodes for the quota file. + * The default value is one. This sets the maximum theoretical quota overrun + * (with infinite node with infinite bandwidth) to twice the user's limit. (In + * practice, the maximum overrun you see should be much less.) A "quota_scale" + * number greater than one makes quota syncs more frequent and reduces the + * maximum overrun. Numbers less than one (but greater than zero) make quota + * syncs less frequent. + * + * GFS quotas also use per-ID Lock Value Blocks (LVBs) to cache the contents of + * the quota file, so it is not being constantly read. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "glock.h" +#include "glops.h" +#include "jdata.h" +#include "log.h" +#include "meta_io.h" +#include "quota.h" +#include "rgrp.h" +#include "super.h" +#include "trans.h" + +#define QUOTA_USER 1 +#define QUOTA_GROUP 0 + +static uint64_t qd2offset(struct gfs2_quota_data *qd) +{ + uint64_t offset; + + offset = 2 * (uint64_t)qd->qd_id + !test_bit(QDF_USER, &qd->qd_flags); + offset *= sizeof(struct gfs2_quota); + + return offset; +} + +static int qd_alloc(struct gfs2_sbd *sdp, int user, uint32_t id, + struct gfs2_quota_data **qdp) +{ + struct gfs2_quota_data *qd; + int error; + + qd = kzalloc(sizeof(struct gfs2_quota_data), GFP_KERNEL); + if (!qd) + return -ENOMEM; + + qd->qd_count = 1; + qd->qd_id = id; + if (user) + set_bit(QDF_USER, &qd->qd_flags); + qd->qd_slot = -1; + + error = gfs2_glock_get(sdp, 2 * (uint64_t)id + !user, + &gfs2_quota_glops, CREATE, &qd->qd_gl); + if (error) + goto fail; + + error = gfs2_lvb_hold(qd->qd_gl); + gfs2_glock_put(qd->qd_gl); + if (error) + goto fail; + + *qdp = qd; + + return 0; + + fail: + kfree(qd); + return error; +} + +static int qd_get(struct gfs2_sbd *sdp, int user, uint32_t id, int create, + struct gfs2_quota_data **qdp) +{ + struct gfs2_quota_data *qd = NULL, *new_qd = NULL; + int error, found; + + *qdp = NULL; + + for (;;) { + found = 0; + spin_lock(&sdp->sd_quota_spin); + list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) { + if (qd->qd_id == id && + !test_bit(QDF_USER, &qd->qd_flags) == !user) { + qd->qd_count++; + found = 1; + break; + } + } + + if (!found) + qd = NULL; + + if (!qd && new_qd) { + qd = new_qd; + list_add(&qd->qd_list, &sdp->sd_quota_list); + atomic_inc(&sdp->sd_quota_count); + new_qd = NULL; + } + + spin_unlock(&sdp->sd_quota_spin); + + if (qd || !create) { + if (new_qd) { + gfs2_lvb_unhold(new_qd->qd_gl); + kfree(new_qd); + } + *qdp = qd; + return 0; + } + + error = qd_alloc(sdp, user, id, &new_qd); + if (error) + return error; + } +} + +static void qd_hold(struct gfs2_quota_data *qd) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + + spin_lock(&sdp->sd_quota_spin); + gfs2_assert(sdp, qd->qd_count); + qd->qd_count++; + spin_unlock(&sdp->sd_quota_spin); +} + +static void qd_put(struct gfs2_quota_data *qd) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + spin_lock(&sdp->sd_quota_spin); + gfs2_assert(sdp, qd->qd_count); + if (!--qd->qd_count) + qd->qd_last_touched = jiffies; + spin_unlock(&sdp->sd_quota_spin); +} + +static int slot_get(struct gfs2_quota_data *qd) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + unsigned int c, o = 0, b; + unsigned char byte = 0; + + spin_lock(&sdp->sd_quota_spin); + + if (qd->qd_slot_count++) { + spin_unlock(&sdp->sd_quota_spin); + return 0; + } + + for (c = 0; c < sdp->sd_quota_chunks; c++) + for (o = 0; o < PAGE_SIZE; o++) { + byte = sdp->sd_quota_bitmap[c][o]; + if (byte != 0xFF) + goto found; + } + + goto fail; + + found: + for (b = 0; b < 8; b++) + if (!(byte & (1 << b))) + break; + qd->qd_slot = c * (8 * PAGE_SIZE) + o * 8 + b; + + if (qd->qd_slot >= sdp->sd_quota_slots) + goto fail; + + sdp->sd_quota_bitmap[c][o] |= 1 << b; + + spin_unlock(&sdp->sd_quota_spin); + + return 0; + + fail: + qd->qd_slot_count--; + spin_unlock(&sdp->sd_quota_spin); + return -ENOSPC; +} + +static void slot_hold(struct gfs2_quota_data *qd) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + + spin_lock(&sdp->sd_quota_spin); + gfs2_assert(sdp, qd->qd_slot_count); + qd->qd_slot_count++; + spin_unlock(&sdp->sd_quota_spin); +} + +static void slot_put(struct gfs2_quota_data *qd) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + + spin_lock(&sdp->sd_quota_spin); + gfs2_assert(sdp, qd->qd_slot_count); + if (!--qd->qd_slot_count) { + gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, qd->qd_slot, 0); + qd->qd_slot = -1; + } + spin_unlock(&sdp->sd_quota_spin); +} + +static int bh_get(struct gfs2_quota_data *qd) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + struct gfs2_inode *ip = sdp->sd_qc_inode; + unsigned int block, offset; + uint64_t dblock; + int new = 0; + struct buffer_head *bh; + int error; + + down(&sdp->sd_quota_mutex); + + if (qd->qd_bh_count++) { + up(&sdp->sd_quota_mutex); + return 0; + } + + block = qd->qd_slot / sdp->sd_qc_per_block; + offset = qd->qd_slot % sdp->sd_qc_per_block;; + + error = gfs2_block_map(ip, block, &new, &dblock, NULL); + if (error) + goto fail; + error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh); + if (error) + goto fail; + error = -EIO; + if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) + goto fail_brelse; + + qd->qd_bh = bh; + qd->qd_bh_qc = (struct gfs2_quota_change *) + (bh->b_data + sizeof(struct gfs2_meta_header) + + offset * sizeof(struct gfs2_quota_change)); + + up(&sdp->sd_quota_mutex); + + return 0; + + fail_brelse: + brelse(bh); + + fail: + qd->qd_bh_count--; + up(&sdp->sd_quota_mutex); + return error; +} + +static void bh_put(struct gfs2_quota_data *qd) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + + down(&sdp->sd_quota_mutex); + gfs2_assert(sdp, qd->qd_bh_count); + if (!--qd->qd_bh_count) { + brelse(qd->qd_bh); + qd->qd_bh = NULL; + qd->qd_bh_qc = NULL; + } + up(&sdp->sd_quota_mutex); +} + +static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp) +{ + struct gfs2_quota_data *qd = NULL; + int error; + int found = 0; + + *qdp = NULL; + + if (sdp->sd_vfs->s_flags & MS_RDONLY) + return 0; + + spin_lock(&sdp->sd_quota_spin); + + list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) { + if (test_bit(QDF_LOCKED, &qd->qd_flags) || + !test_bit(QDF_CHANGE, &qd->qd_flags) || + qd->qd_sync_gen >= sdp->sd_quota_sync_gen) + continue; + + list_move_tail(&qd->qd_list, &sdp->sd_quota_list); + + set_bit(QDF_LOCKED, &qd->qd_flags); + gfs2_assert_warn(sdp, qd->qd_count); + qd->qd_count++; + qd->qd_change_sync = qd->qd_change; + gfs2_assert_warn(sdp, qd->qd_slot_count); + qd->qd_slot_count++; + found = 1; + + break; + } + + if (!found) + qd = NULL; + + spin_unlock(&sdp->sd_quota_spin); + + if (qd) { + gfs2_assert_warn(sdp, qd->qd_change_sync); + error = bh_get(qd); + if (error) { + clear_bit(QDF_LOCKED, &qd->qd_flags); + slot_put(qd); + qd_put(qd); + return error; + } + } + + *qdp = qd; + + return 0; +} + +static int qd_trylock(struct gfs2_quota_data *qd) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + + if (sdp->sd_vfs->s_flags & MS_RDONLY) + return 0; + + spin_lock(&sdp->sd_quota_spin); + + if (test_bit(QDF_LOCKED, &qd->qd_flags) || + !test_bit(QDF_CHANGE, &qd->qd_flags)) { + spin_unlock(&sdp->sd_quota_spin); + return 0; + } + + list_move_tail(&qd->qd_list, &sdp->sd_quota_list); + + set_bit(QDF_LOCKED, &qd->qd_flags); + gfs2_assert_warn(sdp, qd->qd_count); + qd->qd_count++; + qd->qd_change_sync = qd->qd_change; + gfs2_assert_warn(sdp, qd->qd_slot_count); + qd->qd_slot_count++; + + spin_unlock(&sdp->sd_quota_spin); + + gfs2_assert_warn(sdp, qd->qd_change_sync); + if (bh_get(qd)) { + clear_bit(QDF_LOCKED, &qd->qd_flags); + slot_put(qd); + qd_put(qd); + return 0; + } + + return 1; +} + +static void qd_unlock(struct gfs2_quota_data *qd) +{ + gfs2_assert_warn(qd->qd_gl->gl_sbd, test_bit(QDF_LOCKED, &qd->qd_flags)); + clear_bit(QDF_LOCKED, &qd->qd_flags); + bh_put(qd); + slot_put(qd); + qd_put(qd); +} + +static int qdsb_get(struct gfs2_sbd *sdp, int user, uint32_t id, int create, + struct gfs2_quota_data **qdp) +{ + int error; + + error = qd_get(sdp, user, id, create, qdp); + if (error) + return error; + + error = slot_get(*qdp); + if (error) + goto fail; + + error = bh_get(*qdp); + if (error) + goto fail_slot; + + return 0; + + fail_slot: + slot_put(*qdp); + + fail: + qd_put(*qdp); + return error; +} + +static void qdsb_put(struct gfs2_quota_data *qd) +{ + bh_put(qd); + slot_put(qd); + qd_put(qd); +} + +int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = &ip->i_alloc; + struct gfs2_quota_data **qd = al->al_qd; + int error; + + if (gfs2_assert_warn(sdp, !al->al_qd_num) || + gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags))) + return -EIO; + + if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) + return 0; + + error = qdsb_get(sdp, QUOTA_USER, ip->i_di.di_uid, CREATE, qd); + if (error) + goto out; + al->al_qd_num++; + qd++; + + error = qdsb_get(sdp, QUOTA_GROUP, ip->i_di.di_gid, CREATE, qd); + if (error) + goto out; + al->al_qd_num++; + qd++; + + if (uid != NO_QUOTA_CHANGE && uid != ip->i_di.di_uid) { + error = qdsb_get(sdp, QUOTA_USER, uid, CREATE, qd); + if (error) + goto out; + al->al_qd_num++; + qd++; + } + + if (gid != NO_QUOTA_CHANGE && gid != ip->i_di.di_gid) { + error = qdsb_get(sdp, QUOTA_GROUP, gid, CREATE, qd); + if (error) + goto out; + al->al_qd_num++; + qd++; + } + + out: + if (error) + gfs2_quota_unhold(ip); + + return error; +} + +void gfs2_quota_unhold(struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = &ip->i_alloc; + unsigned int x; + + gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)); + + for (x = 0; x < al->al_qd_num; x++) { + qdsb_put(al->al_qd[x]); + al->al_qd[x] = NULL; + } + al->al_qd_num = 0; +} + +static int sort_qd(const void *a, const void *b) +{ + struct gfs2_quota_data *qd_a = *(struct gfs2_quota_data **)a; + struct gfs2_quota_data *qd_b = *(struct gfs2_quota_data **)b; + int ret = 0; + + if (!test_bit(QDF_USER, &qd_a->qd_flags) != + !test_bit(QDF_USER, &qd_b->qd_flags)) { + if (test_bit(QDF_USER, &qd_a->qd_flags)) + ret = -1; + else + ret = 1; + } else { + if (qd_a->qd_id < qd_b->qd_id) + ret = -1; + else if (qd_a->qd_id > qd_b->qd_id) + ret = 1; + } + + return ret; +} + +static void do_qc(struct gfs2_quota_data *qd, int64_t change) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + struct gfs2_inode *ip = sdp->sd_qc_inode; + struct gfs2_quota_change *qc = qd->qd_bh_qc; + int64_t x; + + down(&sdp->sd_quota_mutex); + gfs2_trans_add_bh(ip->i_gl, qd->qd_bh); + + if (!test_bit(QDF_CHANGE, &qd->qd_flags)) { + qc->qc_change = 0; + qc->qc_flags = 0; + if (test_bit(QDF_USER, &qd->qd_flags)) + qc->qc_flags = cpu_to_be32(GFS2_QCF_USER); + qc->qc_id = cpu_to_be32(qd->qd_id); + } + + x = qc->qc_change; + x = be64_to_cpu(x) + change; + qc->qc_change = cpu_to_be64(x); + + spin_lock(&sdp->sd_quota_spin); + qd->qd_change = x; + spin_unlock(&sdp->sd_quota_spin); + + if (!x) { + gfs2_assert_warn(sdp, test_bit(QDF_CHANGE, &qd->qd_flags)); + clear_bit(QDF_CHANGE, &qd->qd_flags); + qc->qc_flags = 0; + qc->qc_id = 0; + slot_put(qd); + qd_put(qd); + } else if (!test_and_set_bit(QDF_CHANGE, &qd->qd_flags)) { + qd_hold(qd); + slot_hold(qd); + } + + up(&sdp->sd_quota_mutex); +} + +static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) +{ + struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd; + struct gfs2_inode *ip = sdp->sd_quota_inode; + unsigned int data_blocks, ind_blocks; + struct gfs2_holder *ghs, i_gh; + unsigned int qx, x; + struct gfs2_quota_data *qd; + uint64_t offset; + unsigned int nalloc = 0; + struct gfs2_alloc *al = NULL; + int error; + + gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota), + &data_blocks, &ind_blocks); + + ghs = kcalloc(num_qd, sizeof(struct gfs2_holder), GFP_KERNEL); + if (!ghs) + return -ENOMEM; + + sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL); + for (qx = 0; qx < num_qd; qx++) { + error = gfs2_glock_nq_init(qda[qx]->qd_gl, + LM_ST_EXCLUSIVE, + GL_NOCACHE, &ghs[qx]); + if (error) + goto out; + } + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); + if (error) + goto out; + + for (x = 0; x < num_qd; x++) { + int alloc_required; + + offset = qd2offset(qda[x]); + error = gfs2_write_alloc_required(ip, offset, + sizeof(struct gfs2_quota), + &alloc_required); + if (error) + goto out_gunlock; + if (alloc_required) + nalloc++; + } + + if (nalloc) { + al = gfs2_alloc_get(ip); + + al->al_requested = nalloc * (data_blocks + ind_blocks); + + error = gfs2_inplace_reserve(ip); + if (error) + goto out_alloc; + + error = gfs2_trans_begin(sdp, + al->al_rgd->rd_ri.ri_length + + num_qd * data_blocks + + nalloc * ind_blocks + + RES_DINODE + num_qd + + RES_STATFS, 0); + if (error) + goto out_ipres; + } else { + error = gfs2_trans_begin(sdp, + num_qd * data_blocks + + RES_DINODE + num_qd, 0); + if (error) + goto out_gunlock; + } + + for (x = 0; x < num_qd; x++) { + char buf[sizeof(struct gfs2_quota)]; + struct gfs2_quota q; + + qd = qda[x]; + offset = qd2offset(qd); + + /* The quota file may not be a multiple of + sizeof(struct gfs2_quota) bytes. */ + memset(buf, 0, sizeof(struct gfs2_quota)); + + error = gfs2_jdata_read_mem(ip, buf, offset, + sizeof(struct gfs2_quota)); + if (error < 0) + goto out_end_trans; + + gfs2_quota_in(&q, buf); + q.qu_value += qda[x]->qd_change_sync; + gfs2_quota_out(&q, buf); + + error = gfs2_jdata_write_mem(ip, buf, offset, + sizeof(struct gfs2_quota)); + if (error < 0) + goto out_end_trans; + else if (error != sizeof(struct gfs2_quota)) { + error = -EIO; + goto out_end_trans; + } + + do_qc(qd, -qd->qd_change_sync); + + memset(&qd->qd_qb, 0, sizeof(struct gfs2_quota_lvb)); + qd->qd_qb.qb_magic = GFS2_MAGIC; + qd->qd_qb.qb_limit = q.qu_limit; + qd->qd_qb.qb_warn = q.qu_warn; + qd->qd_qb.qb_value = q.qu_value; + + gfs2_quota_lvb_out(&qd->qd_qb, qd->qd_gl->gl_lvb); + } + + error = 0; + + out_end_trans: + gfs2_trans_end(sdp); + + out_ipres: + if (nalloc) + gfs2_inplace_release(ip); + + out_alloc: + if (nalloc) + gfs2_alloc_put(ip); + + out_gunlock: + gfs2_glock_dq_uninit(&i_gh); + + out: + while (qx--) + gfs2_glock_dq_uninit(&ghs[qx]); + kfree(ghs); + gfs2_log_flush_glock(ip->i_gl); + + return error; +} + +static int do_glock(struct gfs2_quota_data *qd, int force_refresh, + struct gfs2_holder *q_gh) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + struct gfs2_holder i_gh; + struct gfs2_quota q; + char buf[sizeof(struct gfs2_quota)]; + int error; + + restart: + error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh); + if (error) + return error; + + gfs2_quota_lvb_in(&qd->qd_qb, qd->qd_gl->gl_lvb); + + if (force_refresh || qd->qd_qb.qb_magic != GFS2_MAGIC) { + gfs2_glock_dq_uninit(q_gh); + error = gfs2_glock_nq_init(qd->qd_gl, + LM_ST_EXCLUSIVE, GL_NOCACHE, + q_gh); + if (error) + return error; + + error = gfs2_glock_nq_init(sdp->sd_quota_inode->i_gl, + LM_ST_SHARED, 0, + &i_gh); + if (error) + goto fail; + + memset(buf, 0, sizeof(struct gfs2_quota)); + + error = gfs2_jdata_read_mem(sdp->sd_quota_inode, buf, + qd2offset(qd), + sizeof(struct gfs2_quota)); + if (error < 0) + goto fail_gunlock; + + gfs2_glock_dq_uninit(&i_gh); + + gfs2_quota_in(&q, buf); + + memset(&qd->qd_qb, 0, sizeof(struct gfs2_quota_lvb)); + qd->qd_qb.qb_magic = GFS2_MAGIC; + qd->qd_qb.qb_limit = q.qu_limit; + qd->qd_qb.qb_warn = q.qu_warn; + qd->qd_qb.qb_value = q.qu_value; + + gfs2_quota_lvb_out(&qd->qd_qb, qd->qd_gl->gl_lvb); + + if (gfs2_glock_is_blocking(qd->qd_gl)) { + gfs2_glock_dq_uninit(q_gh); + force_refresh = 0; + goto restart; + } + } + + return 0; + + fail_gunlock: + gfs2_glock_dq_uninit(&i_gh); + + fail: + gfs2_glock_dq_uninit(q_gh); + + return error; +} + +int gfs2_quota_lock(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = &ip->i_alloc; + unsigned int x; + int error = 0; + + gfs2_quota_hold(ip, uid, gid); + + if (capable(CAP_SYS_RESOURCE) || + sdp->sd_args.ar_quota != GFS2_QUOTA_ON) + return 0; + + sort(al->al_qd, al->al_qd_num, sizeof(struct gfs2_quota_data *), + sort_qd, NULL); + + for (x = 0; x < al->al_qd_num; x++) { + error = do_glock(al->al_qd[x], NO_FORCE, &al->al_qd_ghs[x]); + if (error) + break; + } + + if (!error) + set_bit(GIF_QD_LOCKED, &ip->i_flags); + else { + while (x--) + gfs2_glock_dq_uninit(&al->al_qd_ghs[x]); + gfs2_quota_unhold(ip); + } + + return error; +} + +static int need_sync(struct gfs2_quota_data *qd) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + struct gfs2_tune *gt = &sdp->sd_tune; + int64_t value; + unsigned int num, den; + int do_sync = 1; + + if (!qd->qd_qb.qb_limit) + return 0; + + spin_lock(&sdp->sd_quota_spin); + value = qd->qd_change; + spin_unlock(&sdp->sd_quota_spin); + + spin_lock(>->gt_spin); + num = gt->gt_quota_scale_num; + den = gt->gt_quota_scale_den; + spin_unlock(>->gt_spin); + + if (value < 0) + do_sync = 0; + else if (qd->qd_qb.qb_value >= (int64_t)qd->qd_qb.qb_limit) + do_sync = 0; + else { + value *= gfs2_jindex_size(sdp) * num; + do_div(value, den); + value += qd->qd_qb.qb_value; + if (value < (int64_t)qd->qd_qb.qb_limit) + do_sync = 0; + } + + return do_sync; +} + +void gfs2_quota_unlock(struct gfs2_inode *ip) +{ + struct gfs2_alloc *al = &ip->i_alloc; + struct gfs2_quota_data *qda[4]; + unsigned int count = 0; + unsigned int x; + + if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags)) + goto out; + + for (x = 0; x < al->al_qd_num; x++) { + struct gfs2_quota_data *qd; + int sync; + + qd = al->al_qd[x]; + sync = need_sync(qd); + + gfs2_glock_dq_uninit(&al->al_qd_ghs[x]); + + if (sync && qd_trylock(qd)) + qda[count++] = qd; + } + + if (count) { + do_sync(count, qda); + for (x = 0; x < count; x++) + qd_unlock(qda[x]); + } + + out: + gfs2_quota_unhold(ip); +} + +#define MAX_LINE 256 + +static int print_message(struct gfs2_quota_data *qd, char *type) +{ + struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + char *line; + int len; + + line = kmalloc(MAX_LINE, GFP_KERNEL); + if (!line) + return -ENOMEM; + + len = snprintf(line, MAX_LINE-1, "GFS2: fsid=%s: quota %s for %s %u\r\n", + sdp->sd_fsname, type, + (test_bit(QDF_USER, &qd->qd_flags)) ? "user" : "group", + qd->qd_id); + line[MAX_LINE-1] = 0; + + if (current->signal) { /* Is this test still required? */ + tty_write_message(current->signal->tty, line); + } + + kfree(line); + + return 0; +} + +int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = &ip->i_alloc; + struct gfs2_quota_data *qd; + int64_t value; + unsigned int x; + int error = 0; + + if (!test_bit(GIF_QD_LOCKED, &ip->i_flags)) + return 0; + + if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON) + return 0; + + for (x = 0; x < al->al_qd_num; x++) { + qd = al->al_qd[x]; + + if (!((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) || + (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags)))) + continue; + + value = qd->qd_qb.qb_value; + spin_lock(&sdp->sd_quota_spin); + value += qd->qd_change; + spin_unlock(&sdp->sd_quota_spin); + + if (qd->qd_qb.qb_limit && (int64_t)qd->qd_qb.qb_limit < value) { + print_message(qd, "exceeded"); + error = -EDQUOT; + break; + } else if (qd->qd_qb.qb_warn && + (int64_t)qd->qd_qb.qb_warn < value && + time_after_eq(jiffies, qd->qd_last_warn + + gfs2_tune_get(sdp, gt_quota_warn_period) * HZ)) { + error = print_message(qd, "warning"); + qd->qd_last_warn = jiffies; + } + } + + return error; +} + +void gfs2_quota_change(struct gfs2_inode *ip, int64_t change, + uint32_t uid, uint32_t gid) +{ + struct gfs2_alloc *al = &ip->i_alloc; + struct gfs2_quota_data *qd; + unsigned int x; + unsigned int found = 0; + + if (gfs2_assert_warn(ip->i_sbd, change)) + return; + if (ip->i_di.di_flags & GFS2_DIF_SYSTEM) + return; + + for (x = 0; x < al->al_qd_num; x++) { + qd = al->al_qd[x]; + + if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) || + (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) { + do_qc(qd, change); + found++; + } + } +} + +int gfs2_quota_sync(struct gfs2_sbd *sdp) +{ + struct gfs2_quota_data **qda; + unsigned int max_qd = gfs2_tune_get(sdp, gt_quota_simul_sync); + unsigned int num_qd; + unsigned int x; + int error = 0; + + sdp->sd_quota_sync_gen++; + + qda = kcalloc(max_qd, sizeof(struct gfs2_quota_data *), GFP_KERNEL); + if (!qda) + return -ENOMEM; + + do { + num_qd = 0; + + for (;;) { + error = qd_fish(sdp, qda + num_qd); + if (error || !qda[num_qd]) + break; + if (++num_qd == max_qd) + break; + } + + if (num_qd) { + if (!error) + error = do_sync(num_qd, qda); + if (!error) + for (x = 0; x < num_qd; x++) + qda[x]->qd_sync_gen = + sdp->sd_quota_sync_gen; + + for (x = 0; x < num_qd; x++) + qd_unlock(qda[x]); + } + } while (!error && num_qd == max_qd); + + kfree(qda); + + return error; +} + +int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, uint32_t id) +{ + struct gfs2_quota_data *qd; + struct gfs2_holder q_gh; + int error; + + error = qd_get(sdp, user, id, CREATE, &qd); + if (error) + return error; + + error = do_glock(qd, FORCE, &q_gh); + if (!error) + gfs2_glock_dq_uninit(&q_gh); + + qd_put(qd); + + return error; +} + +int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, + struct gfs2_quota *q) +{ + struct gfs2_quota_data *qd; + struct gfs2_holder q_gh; + int error; + + if (((user) ? (id != current->fsuid) : (!in_group_p(id))) && + !capable(CAP_SYS_ADMIN)) + return -EACCES; + + error = qd_get(sdp, user, id, CREATE, &qd); + if (error) + return error; + + error = do_glock(qd, NO_FORCE, &q_gh); + if (error) + goto out; + + memset(q, 0, sizeof(struct gfs2_quota)); + q->qu_limit = qd->qd_qb.qb_limit; + q->qu_warn = qd->qd_qb.qb_warn; + q->qu_value = qd->qd_qb.qb_value; + + spin_lock(&sdp->sd_quota_spin); + q->qu_value += qd->qd_change; + spin_unlock(&sdp->sd_quota_spin); + + gfs2_glock_dq_uninit(&q_gh); + + out: + qd_put(qd); + + return error; +} + +int gfs2_quota_init(struct gfs2_sbd *sdp) +{ + struct gfs2_inode *ip = sdp->sd_qc_inode; + unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; + unsigned int x, slot = 0; + unsigned int found = 0; + uint64_t dblock; + uint32_t extlen = 0; + int error; + + if (!ip->i_di.di_size || + ip->i_di.di_size > (64 << 20) || + ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1)) { + gfs2_consist_inode(ip); + return -EIO; + } + sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block; + sdp->sd_quota_chunks = DIV_RU(sdp->sd_quota_slots, 8 * PAGE_SIZE); + + error = -ENOMEM; + + sdp->sd_quota_bitmap = kcalloc(sdp->sd_quota_chunks, + sizeof(unsigned char *), GFP_KERNEL); + if (!sdp->sd_quota_bitmap) + return error; + + for (x = 0; x < sdp->sd_quota_chunks; x++) { + sdp->sd_quota_bitmap[x] = kzalloc(PAGE_SIZE, GFP_KERNEL); + if (!sdp->sd_quota_bitmap[x]) + goto fail; + } + + for (x = 0; x < blocks; x++) { + struct buffer_head *bh; + unsigned int y; + + if (!extlen) { + int new = 0; + error = gfs2_block_map(ip, x, &new, &dblock, &extlen); + if (error) + goto fail; + } + gfs2_meta_ra(ip->i_gl, dblock, extlen); + error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, + &bh); + if (error) + goto fail; + error = -EIO; + if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) { + brelse(bh); + goto fail; + } + + for (y = 0; + y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots; + y++, slot++) { + struct gfs2_quota_change qc; + struct gfs2_quota_data *qd; + + gfs2_quota_change_in(&qc, bh->b_data + + sizeof(struct gfs2_meta_header) + + y * sizeof(struct gfs2_quota_change)); + if (!qc.qc_change) + continue; + + error = qd_alloc(sdp, (qc.qc_flags & GFS2_QCF_USER), + qc.qc_id, &qd); + if (error) { + brelse(bh); + goto fail; + } + + set_bit(QDF_CHANGE, &qd->qd_flags); + qd->qd_change = qc.qc_change; + qd->qd_slot = slot; + qd->qd_slot_count = 1; + qd->qd_last_touched = jiffies; + + spin_lock(&sdp->sd_quota_spin); + gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1); + list_add(&qd->qd_list, &sdp->sd_quota_list); + atomic_inc(&sdp->sd_quota_count); + spin_unlock(&sdp->sd_quota_spin); + + found++; + } + + brelse(bh); + dblock++; + extlen--; + } + + if (found) + fs_info(sdp, "found %u quota changes\n", found); + + return 0; + + fail: + gfs2_quota_cleanup(sdp); + return error; +} + +void gfs2_quota_scan(struct gfs2_sbd *sdp) +{ + struct gfs2_quota_data *qd, *safe; + LIST_HEAD(dead); + + spin_lock(&sdp->sd_quota_spin); + list_for_each_entry_safe(qd, safe, &sdp->sd_quota_list, qd_list) { + if (!qd->qd_count && + time_after_eq(jiffies, qd->qd_last_touched + + gfs2_tune_get(sdp, gt_quota_cache_secs) * HZ)) { + list_move(&qd->qd_list, &dead); + gfs2_assert_warn(sdp, + atomic_read(&sdp->sd_quota_count) > 0); + atomic_dec(&sdp->sd_quota_count); + } + } + spin_unlock(&sdp->sd_quota_spin); + + while (!list_empty(&dead)) { + qd = list_entry(dead.next, struct gfs2_quota_data, qd_list); + list_del(&qd->qd_list); + + gfs2_assert_warn(sdp, !qd->qd_change); + gfs2_assert_warn(sdp, !qd->qd_slot_count); + gfs2_assert_warn(sdp, !qd->qd_bh_count); + + gfs2_lvb_unhold(qd->qd_gl); + kfree(qd); + } +} + +void gfs2_quota_cleanup(struct gfs2_sbd *sdp) +{ + struct list_head *head = &sdp->sd_quota_list; + struct gfs2_quota_data *qd; + unsigned int x; + + spin_lock(&sdp->sd_quota_spin); + while (!list_empty(head)) { + qd = list_entry(head->prev, struct gfs2_quota_data, qd_list); + + if (qd->qd_count > 1 || + (qd->qd_count && !test_bit(QDF_CHANGE, &qd->qd_flags))) { + list_move(&qd->qd_list, head); + spin_unlock(&sdp->sd_quota_spin); + schedule(); + spin_lock(&sdp->sd_quota_spin); + continue; + } + + list_del(&qd->qd_list); + atomic_dec(&sdp->sd_quota_count); + spin_unlock(&sdp->sd_quota_spin); + + if (!qd->qd_count) { + gfs2_assert_warn(sdp, !qd->qd_change); + gfs2_assert_warn(sdp, !qd->qd_slot_count); + } else + gfs2_assert_warn(sdp, qd->qd_slot_count == 1); + gfs2_assert_warn(sdp, !qd->qd_bh_count); + + gfs2_lvb_unhold(qd->qd_gl); + kfree(qd); + + spin_lock(&sdp->sd_quota_spin); + } + spin_unlock(&sdp->sd_quota_spin); + + gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count)); + + if (sdp->sd_quota_bitmap) { + for (x = 0; x < sdp->sd_quota_chunks; x++) + kfree(sdp->sd_quota_bitmap[x]); + kfree(sdp->sd_quota_bitmap); + } +} + diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h new file mode 100644 index 000000000000..005529f6895d --- /dev/null +++ b/fs/gfs2/quota.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __QUOTA_DOT_H__ +#define __QUOTA_DOT_H__ + +#define NO_QUOTA_CHANGE ((uint32_t)-1) + +int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid); +void gfs2_quota_unhold(struct gfs2_inode *ip); + +int gfs2_quota_lock(struct gfs2_inode *ip, uint32_t uid, uint32_t gid); +void gfs2_quota_unlock(struct gfs2_inode *ip); + +int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid); +void gfs2_quota_change(struct gfs2_inode *ip, int64_t change, + uint32_t uid, uint32_t gid); + +int gfs2_quota_sync(struct gfs2_sbd *sdp); +int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, uint32_t id); +int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, + struct gfs2_quota *q); + +int gfs2_quota_init(struct gfs2_sbd *sdp); +void gfs2_quota_scan(struct gfs2_sbd *sdp); +void gfs2_quota_cleanup(struct gfs2_sbd *sdp); + +#endif /* __QUOTA_DOT_H__ */ diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c new file mode 100644 index 000000000000..15cd26fbcff9 --- /dev/null +++ b/fs/gfs2/recovery.c @@ -0,0 +1,570 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "glock.h" +#include "glops.h" +#include "lm.h" +#include "lops.h" +#include "meta_io.h" +#include "recovery.h" +#include "super.h" + +int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, + struct buffer_head **bh) +{ + struct gfs2_glock *gl = jd->jd_inode->i_gl; + int new = 0; + uint64_t dblock; + uint32_t extlen; + int error; + + error = gfs2_block_map(jd->jd_inode, blk, &new, &dblock, &extlen); + if (error) + return error; + if (!dblock) { + gfs2_consist_inode(jd->jd_inode); + return -EIO; + } + + gfs2_meta_ra(gl, dblock, extlen); + error = gfs2_meta_read(gl, dblock, DIO_START | DIO_WAIT, bh); + + return error; +} + +int gfs2_revoke_add(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where) +{ + struct list_head *head = &sdp->sd_revoke_list; + struct gfs2_revoke_replay *rr; + int found = 0; + + list_for_each_entry(rr, head, rr_list) { + if (rr->rr_blkno == blkno) { + found = 1; + break; + } + } + + if (found) { + rr->rr_where = where; + return 0; + } + + rr = kmalloc(sizeof(struct gfs2_revoke_replay), GFP_KERNEL); + if (!rr) + return -ENOMEM; + + rr->rr_blkno = blkno; + rr->rr_where = where; + list_add(&rr->rr_list, head); + + return 1; +} + +int gfs2_revoke_check(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where) +{ + struct gfs2_revoke_replay *rr; + int wrap, a, b, revoke; + int found = 0; + + list_for_each_entry(rr, &sdp->sd_revoke_list, rr_list) { + if (rr->rr_blkno == blkno) { + found = 1; + break; + } + } + + if (!found) + return 0; + + wrap = (rr->rr_where < sdp->sd_replay_tail); + a = (sdp->sd_replay_tail < where); + b = (where < rr->rr_where); + revoke = (wrap) ? (a || b) : (a && b); + + return revoke; +} + +void gfs2_revoke_clean(struct gfs2_sbd *sdp) +{ + struct list_head *head = &sdp->sd_revoke_list; + struct gfs2_revoke_replay *rr; + + while (!list_empty(head)) { + rr = list_entry(head->next, struct gfs2_revoke_replay, rr_list); + list_del(&rr->rr_list); + kfree(rr); + } +} + +/** + * get_log_header - read the log header for a given segment + * @jd: the journal + * @blk: the block to look at + * @lh: the log header to return + * + * Read the log header for a given segement in a given journal. Do a few + * sanity checks on it. + * + * Returns: 0 on success, + * 1 if the header was invalid or incomplete, + * errno on error + */ + +static int get_log_header(struct gfs2_jdesc *jd, unsigned int blk, + struct gfs2_log_header *head) +{ + struct buffer_head *bh; + struct gfs2_log_header lh; + uint32_t hash; + int error; + + error = gfs2_replay_read_block(jd, blk, &bh); + if (error) + return error; + + memcpy(&lh, bh->b_data, sizeof(struct gfs2_log_header)); + lh.lh_hash = 0; + hash = gfs2_disk_hash((char *)&lh, sizeof(struct gfs2_log_header)); + gfs2_log_header_in(&lh, bh->b_data); + + brelse(bh); + + if (lh.lh_header.mh_magic != GFS2_MAGIC || + lh.lh_header.mh_type != GFS2_METATYPE_LH || + lh.lh_blkno != blk || + lh.lh_hash != hash) + return 1; + + *head = lh; + + return 0; +} + +/** + * find_good_lh - find a good log header + * @jd: the journal + * @blk: the segment to start searching from + * @lh: the log header to fill in + * @forward: if true search forward in the log, else search backward + * + * Call get_log_header() to get a log header for a segment, but if the + * segment is bad, either scan forward or backward until we find a good one. + * + * Returns: errno + */ + +static int find_good_lh(struct gfs2_jdesc *jd, unsigned int *blk, + struct gfs2_log_header *head) +{ + unsigned int orig_blk = *blk; + int error; + + for (;;) { + error = get_log_header(jd, *blk, head); + if (error <= 0) + return error; + + if (++*blk == jd->jd_blocks) + *blk = 0; + + if (*blk == orig_blk) { + gfs2_consist_inode(jd->jd_inode); + return -EIO; + } + } +} + +/** + * jhead_scan - make sure we've found the head of the log + * @jd: the journal + * @head: this is filled in with the log descriptor of the head + * + * At this point, seg and lh should be either the head of the log or just + * before. Scan forward until we find the head. + * + * Returns: errno + */ + +static int jhead_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head) +{ + unsigned int blk = head->lh_blkno; + struct gfs2_log_header lh; + int error; + + for (;;) { + if (++blk == jd->jd_blocks) + blk = 0; + + error = get_log_header(jd, blk, &lh); + if (error < 0) + return error; + if (error == 1) + continue; + + if (lh.lh_sequence == head->lh_sequence) { + gfs2_consist_inode(jd->jd_inode); + return -EIO; + } + if (lh.lh_sequence < head->lh_sequence) + break; + + *head = lh; + } + + return 0; +} + +/** + * gfs2_find_jhead - find the head of a log + * @jd: the journal + * @head: the log descriptor for the head of the log is returned here + * + * Do a binary search of a journal and find the valid log entry with the + * highest sequence number. (i.e. the log head) + * + * Returns: errno + */ + +int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header *head) +{ + struct gfs2_log_header lh_1, lh_m; + uint32_t blk_1, blk_2, blk_m; + int error; + + blk_1 = 0; + blk_2 = jd->jd_blocks - 1; + + for (;;) { + blk_m = (blk_1 + blk_2) / 2; + + error = find_good_lh(jd, &blk_1, &lh_1); + if (error) + return error; + + error = find_good_lh(jd, &blk_m, &lh_m); + if (error) + return error; + + if (blk_1 == blk_m || blk_m == blk_2) + break; + + if (lh_1.lh_sequence <= lh_m.lh_sequence) + blk_1 = blk_m; + else + blk_2 = blk_m; + } + + error = jhead_scan(jd, &lh_1); + if (error) + return error; + + *head = lh_1; + + return error; +} + +/** + * foreach_descriptor - go through the active part of the log + * @jd: the journal + * @start: the first log header in the active region + * @end: the last log header (don't process the contents of this entry)) + * + * Call a given function once for every log descriptor in the active + * portion of the log. + * + * Returns: errno + */ + +static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, + unsigned int end, int pass) +{ + struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct buffer_head *bh; + struct gfs2_log_descriptor *ld; + int error = 0; + u32 length; + __be64 *ptr; + unsigned int offset = sizeof(struct gfs2_log_descriptor); + offset += (sizeof(__be64)-1); + offset &= ~(sizeof(__be64)-1); + + while (start != end) { + error = gfs2_replay_read_block(jd, start, &bh); + if (error) + return error; + if (gfs2_meta_check(sdp, bh)) { + brelse(bh); + return -EIO; + } + ld = (struct gfs2_log_descriptor *)bh->b_data; + length = be32_to_cpu(ld->ld_length); + + if (be16_to_cpu(ld->ld_header.mh_type) == GFS2_METATYPE_LH) { + struct gfs2_log_header lh; + error = get_log_header(jd, start, &lh); + if (!error) { + gfs2_replay_incr_blk(sdp, &start); + continue; + } + if (error == 1) { + gfs2_consist_inode(jd->jd_inode); + error = -EIO; + } + brelse(bh); + return error; + } else if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_LD)) { + brelse(bh); + return -EIO; + } + ptr = (__be64 *)(bh->b_data + offset); + error = lops_scan_elements(jd, start, ld, ptr, pass); + if (error) { + brelse(bh); + return error; + } + + while (length--) + gfs2_replay_incr_blk(sdp, &start); + + brelse(bh); + } + + return 0; +} + +/** + * clean_journal - mark a dirty journal as being clean + * @sdp: the filesystem + * @jd: the journal + * @gl: the journal's glock + * @head: the head journal to start from + * + * Returns: errno + */ + +static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) +{ + struct gfs2_inode *ip = jd->jd_inode; + struct gfs2_sbd *sdp = ip->i_sbd; + unsigned int lblock; + int new = 0; + uint64_t dblock; + struct gfs2_log_header *lh; + uint32_t hash; + struct buffer_head *bh; + int error; + + lblock = head->lh_blkno; + gfs2_replay_incr_blk(sdp, &lblock); + error = gfs2_block_map(ip, lblock, &new, &dblock, NULL); + if (error) + return error; + if (!dblock) { + gfs2_consist_inode(ip); + return -EIO; + } + + bh = sb_getblk(sdp->sd_vfs, dblock); + lock_buffer(bh); + memset(bh->b_data, 0, bh->b_size); + set_buffer_uptodate(bh); + clear_buffer_dirty(bh); + unlock_buffer(bh); + + lh = (struct gfs2_log_header *)bh->b_data; + memset(lh, 0, sizeof(struct gfs2_log_header)); + lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); + lh->lh_header.mh_type = cpu_to_be16(GFS2_METATYPE_LH); + lh->lh_header.mh_format = cpu_to_be16(GFS2_FORMAT_LH); + lh->lh_sequence = cpu_to_be64(head->lh_sequence + 1); + lh->lh_flags = cpu_to_be32(GFS2_LOG_HEAD_UNMOUNT); + lh->lh_blkno = cpu_to_be32(lblock); + hash = gfs2_disk_hash((const char *)lh, sizeof(struct gfs2_log_header)); + lh->lh_hash = cpu_to_be32(hash); + + set_buffer_dirty(bh); + if (sync_dirty_buffer(bh)) + gfs2_io_error_bh(sdp, bh); + brelse(bh); + + return error; +} + +/** + * gfs2_recover_journal - recovery a given journal + * @jd: the struct gfs2_jdesc describing the journal + * @wait: Don't return until the journal is clean (or an error is encountered) + * + * Acquire the journal's lock, check to see if the journal is clean, and + * do recovery if necessary. + * + * Returns: errno + */ + +int gfs2_recover_journal(struct gfs2_jdesc *jd, int wait) +{ + struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_log_header head; + struct gfs2_holder j_gh, ji_gh, t_gh; + unsigned long t; + int ro = 0; + unsigned int pass; + int error; + + fs_info(sdp, "jid=%u: Trying to acquire journal lock...\n", jd->jd_jid); + + /* Aquire the journal lock so we can do recovery */ + + error = gfs2_glock_nq_num(sdp, + jd->jd_jid, &gfs2_journal_glops, + LM_ST_EXCLUSIVE, + LM_FLAG_NOEXP | + ((wait) ? 0 : LM_FLAG_TRY) | + GL_NOCACHE, &j_gh); + switch (error) { + case 0: + break; + + case GLR_TRYFAILED: + fs_info(sdp, "jid=%u: Busy\n", jd->jd_jid); + error = 0; + + default: + goto fail; + }; + + error = gfs2_glock_nq_init(jd->jd_inode->i_gl, LM_ST_SHARED, + LM_FLAG_NOEXP, &ji_gh); + if (error) + goto fail_gunlock_j; + + fs_info(sdp, "jid=%u: Looking at journal...\n", jd->jd_jid); + + error = gfs2_jdesc_check(jd); + if (error) + goto fail_gunlock_ji; + + error = gfs2_find_jhead(jd, &head); + if (error) + goto fail_gunlock_ji; + + if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { + fs_info(sdp, "jid=%u: Acquiring the transaction lock...\n", + jd->jd_jid); + + t = jiffies; + + /* Acquire a shared hold on the transaction lock */ + + error = gfs2_glock_nq_init(sdp->sd_trans_gl, + LM_ST_SHARED, + LM_FLAG_NOEXP | + LM_FLAG_PRIORITY | + GL_NEVER_RECURSE | + GL_NOCANCEL | + GL_NOCACHE, + &t_gh); + if (error) + goto fail_gunlock_ji; + + if (test_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags)) { + if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) + ro = 1; + } else { + if (sdp->sd_vfs->s_flags & MS_RDONLY) + ro = 1; + } + + if (ro) { + fs_warn(sdp, "jid=%u: Can't replay: read-only FS\n", + jd->jd_jid); + error = -EROFS; + goto fail_gunlock_tr; + } + + fs_info(sdp, "jid=%u: Replaying journal...\n", jd->jd_jid); + + for (pass = 0; pass < 2; pass++) { + lops_before_scan(jd, &head, pass); + error = foreach_descriptor(jd, head.lh_tail, + head.lh_blkno, pass); + lops_after_scan(jd, error, pass); + if (error) + goto fail_gunlock_tr; + } + + error = clean_journal(jd, &head); + if (error) + goto fail_gunlock_tr; + + gfs2_glock_dq_uninit(&t_gh); + + t = DIV_RU(jiffies - t, HZ); + + fs_info(sdp, "jid=%u: Journal replayed in %lus\n", + jd->jd_jid, t); + } + + gfs2_glock_dq_uninit(&ji_gh); + + gfs2_lm_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS); + + gfs2_glock_dq_uninit(&j_gh); + + fs_info(sdp, "jid=%u: Done\n", jd->jd_jid); + + return 0; + + fail_gunlock_tr: + gfs2_glock_dq_uninit(&t_gh); + + fail_gunlock_ji: + gfs2_glock_dq_uninit(&ji_gh); + + fail_gunlock_j: + gfs2_glock_dq_uninit(&j_gh); + + fs_info(sdp, "jid=%u: %s\n", jd->jd_jid, (error) ? "Failed" : "Done"); + + fail: + gfs2_lm_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP); + + return error; +} + +/** + * gfs2_check_journals - Recover any dirty journals + * @sdp: the filesystem + * + */ + +void gfs2_check_journals(struct gfs2_sbd *sdp) +{ + struct gfs2_jdesc *jd; + + for (;;) { + jd = gfs2_jdesc_find_dirty(sdp); + if (!jd) + break; + + if (jd != sdp->sd_jdesc) + gfs2_recover_journal(jd, NO_WAIT); + } +} + diff --git a/fs/gfs2/recovery.h b/fs/gfs2/recovery.h new file mode 100644 index 000000000000..50d7eb57881c --- /dev/null +++ b/fs/gfs2/recovery.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __RECOVERY_DOT_H__ +#define __RECOVERY_DOT_H__ + +static inline void gfs2_replay_incr_blk(struct gfs2_sbd *sdp, unsigned int *blk) +{ + if (++*blk == sdp->sd_jdesc->jd_blocks) + *blk = 0; +} + +int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, + struct buffer_head **bh); + +int gfs2_revoke_add(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where); +int gfs2_revoke_check(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where); +void gfs2_revoke_clean(struct gfs2_sbd *sdp); + +int gfs2_find_jhead(struct gfs2_jdesc *jd, + struct gfs2_log_header *head); +int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd, int wait); +void gfs2_check_journals(struct gfs2_sbd *sdp); + +#endif /* __RECOVERY_DOT_H__ */ + diff --git a/fs/gfs2/resize.c b/fs/gfs2/resize.c new file mode 100644 index 000000000000..67d26b99a73c --- /dev/null +++ b/fs/gfs2/resize.c @@ -0,0 +1,291 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "dir.h" +#include "glock.h" +#include "inode.h" +#include "jdata.h" +#include "meta_io.h" +#include "quota.h" +#include "resize.h" +#include "rgrp.h" +#include "super.h" +#include "trans.h" + +/* A single transaction needs to add the structs to rindex and make the + statfs change. */ + +int gfs2_resize_add_rgrps(struct gfs2_sbd *sdp, char __user *buf, + unsigned int size) +{ + unsigned int num = size / sizeof(struct gfs2_rindex); + struct gfs2_inode *ip = sdp->sd_rindex; + struct gfs2_alloc *al = NULL; + struct gfs2_holder i_gh; + unsigned int data_blocks, ind_blocks; + int alloc_required; + unsigned int x; + int error; + + gfs2_write_calc_reserv(ip, size, &data_blocks, &ind_blocks); + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, + LM_FLAG_PRIORITY | GL_SYNC, &i_gh); + if (error) + return error; + + if (!gfs2_is_jdata(ip)) { + gfs2_consist_inode(ip); + error = -EIO; + goto out; + } + + error = gfs2_write_alloc_required(ip, ip->i_di.di_size, size, + &alloc_required); + if (error) + goto out; + + if (alloc_required) { + al = gfs2_alloc_get(ip); + + al->al_requested = data_blocks + ind_blocks; + + error = gfs2_inplace_reserve(ip); + if (error) + goto out_alloc; + + error = gfs2_trans_begin(sdp, + al->al_rgd->rd_ri.ri_length + + data_blocks + ind_blocks + + RES_DINODE + RES_STATFS, 0); + if (error) + goto out_relse; + } else { + error = gfs2_trans_begin(sdp, data_blocks + + RES_DINODE + RES_STATFS, 0); + if (error) + goto out; + } + + for (x = 0; x < num; x++) { + struct gfs2_rindex ri; + char ri_buf[sizeof(struct gfs2_rindex)]; + + error = copy_from_user(&ri, buf, sizeof(struct gfs2_rindex)); + if (error) { + error = -EFAULT; + goto out_trans; + } + gfs2_rindex_out(&ri, ri_buf); + + error = gfs2_jdata_write_mem(ip, ri_buf, ip->i_di.di_size, + sizeof(struct gfs2_rindex)); + if (error < 0) + goto out_trans; + gfs2_assert_withdraw(sdp, error == sizeof(struct gfs2_rindex)); + error = 0; + + gfs2_statfs_change(sdp, ri.ri_data, ri.ri_data, 0); + + buf += sizeof(struct gfs2_rindex); + } + + out_trans: + gfs2_trans_end(sdp); + + out_relse: + if (alloc_required) + gfs2_inplace_release(ip); + + out_alloc: + if (alloc_required) + gfs2_alloc_put(ip); + + out: + ip->i_gl->gl_vn++; + gfs2_glock_dq_uninit(&i_gh); + + return error; +} + +static void drop_dentries(struct gfs2_inode *ip) +{ + struct inode *inode; + struct dentry *d; + + inode = gfs2_ip2v_lookup(ip); + if (!inode) + return; + + restart: + spin_lock(&dcache_lock); + list_for_each_entry(d, &inode->i_dentry, d_alias) { + if (d_unhashed(d)) + continue; + dget_locked(d); + __d_drop(d); + spin_unlock(&dcache_lock); + dput(d); + goto restart; + } + spin_unlock(&dcache_lock); + + iput(inode); +} + +/* This is called by an ioctl to rename an ordinary file that's represented + in the vfs to a hidden system file that isn't represented in the vfs. It's + used to add journals, along with the associated system files, to a fs. */ + +int gfs2_rename2system(struct gfs2_inode *ip, + struct gfs2_inode *old_dip, char *old_name, + struct gfs2_inode *new_dip, char *new_name) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_holder ghs[3]; + struct qstr old_qstr, new_qstr; + struct gfs2_inum inum; + int alloc_required; + struct buffer_head *dibh; + int error; + + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, ghs); + gfs2_holder_init(old_dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); + gfs2_holder_init(new_dip->i_gl, LM_ST_EXCLUSIVE, GL_SYNC, ghs + 2); + + error = gfs2_glock_nq_m(3, ghs); + if (error) + goto out; + + error = -EMLINK; + if (ip->i_di.di_nlink != 1) + goto out_gunlock; + error = -EINVAL; + if (!S_ISREG(ip->i_di.di_mode)) + goto out_gunlock; + + old_qstr.name = old_name; + old_qstr.len = strlen(old_name); + error = gfs2_dir_search(old_dip, &old_qstr, &inum, NULL); + switch (error) { + case 0: + break; + default: + goto out_gunlock; + } + + error = -EINVAL; + if (!gfs2_inum_equal(&inum, &ip->i_num)) + goto out_gunlock; + + new_qstr.name = new_name; + new_qstr.len = strlen(new_name); + error = gfs2_dir_search(new_dip, &new_qstr, NULL, NULL); + switch (error) { + case -ENOENT: + break; + case 0: + error = -EEXIST; + default: + goto out_gunlock; + } + + gfs2_alloc_get(ip); + + error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out_alloc; + + error = gfs2_diradd_alloc_required(new_dip, &new_qstr, &alloc_required); + if (error) + goto out_unhold; + + if (alloc_required) { + struct gfs2_alloc *al = gfs2_alloc_get(new_dip); + + al->al_requested = sdp->sd_max_dirres; + + error = gfs2_inplace_reserve(new_dip); + if (error) + goto out_alloc2; + + error = gfs2_trans_begin(sdp, + sdp->sd_max_dirres + + al->al_rgd->rd_ri.ri_length + + 3 * RES_DINODE + RES_LEAF + + RES_STATFS + RES_QUOTA, 0); + if (error) + goto out_ipreserv; + } else { + error = gfs2_trans_begin(sdp, + 3 * RES_DINODE + 2 * RES_LEAF + + RES_QUOTA, 0); + if (error) + goto out_unhold; + } + + error = gfs2_dir_del(old_dip, &old_qstr); + if (error) + goto out_trans; + + error = gfs2_dir_add(new_dip, &new_qstr, &ip->i_num, + IF2DT(ip->i_di.di_mode)); + if (error) + goto out_trans; + + gfs2_quota_change(ip, -ip->i_di.di_blocks, ip->i_di.di_uid, + ip->i_di.di_gid); + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto out_trans; + ip->i_di.di_flags |= GFS2_DIF_SYSTEM; + gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + + drop_dentries(ip); + + out_trans: + gfs2_trans_end(sdp); + + out_ipreserv: + if (alloc_required) + gfs2_inplace_release(new_dip); + + out_alloc2: + if (alloc_required) + gfs2_alloc_put(new_dip); + + out_unhold: + gfs2_quota_unhold(ip); + + out_alloc: + gfs2_alloc_put(ip); + + out_gunlock: + gfs2_glock_dq_m(3, ghs); + + out: + gfs2_holder_uninit(ghs); + gfs2_holder_uninit(ghs + 1); + gfs2_holder_uninit(ghs + 2); + + return error; +} + diff --git a/fs/gfs2/resize.h b/fs/gfs2/resize.h new file mode 100644 index 000000000000..bb97f0501598 --- /dev/null +++ b/fs/gfs2/resize.h @@ -0,0 +1,19 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __RESIZE_DOT_H__ +#define __RESIZE_DOT_H__ + +int gfs2_resize_add_rgrps(struct gfs2_sbd *sdp, char __user *buf, + unsigned int size); +int gfs2_rename2system(struct gfs2_inode *ip, + struct gfs2_inode *old_dip, char *old_name, + struct gfs2_inode *new_dip, char *new_name); + +#endif /* __RESIZE_DOT_H__ */ diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c new file mode 100644 index 000000000000..8df6fba20fac --- /dev/null +++ b/fs/gfs2/rgrp.c @@ -0,0 +1,1361 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bits.h" +#include "glock.h" +#include "glops.h" +#include "jdata.h" +#include "lops.h" +#include "meta_io.h" +#include "quota.h" +#include "rgrp.h" +#include "super.h" +#include "trans.h" + +/** + * gfs2_rgrp_verify - Verify that a resource group is consistent + * @sdp: the filesystem + * @rgd: the rgrp + * + */ + +void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd) +{ + struct gfs2_sbd *sdp = rgd->rd_sbd; + struct gfs2_bitmap *bi = NULL; + uint32_t length = rgd->rd_ri.ri_length; + uint32_t count[4], tmp; + int buf, x; + + memset(count, 0, 4 * sizeof(uint32_t)); + + /* Count # blocks in each of 4 possible allocation states */ + for (buf = 0; buf < length; buf++) { + bi = rgd->rd_bits + buf; + for (x = 0; x < 4; x++) + count[x] += gfs2_bitcount(rgd, + bi->bi_bh->b_data + + bi->bi_offset, + bi->bi_len, x); + } + + if (count[0] != rgd->rd_rg.rg_free) { + if (gfs2_consist_rgrpd(rgd)) + fs_err(sdp, "free data mismatch: %u != %u\n", + count[0], rgd->rd_rg.rg_free); + return; + } + + tmp = rgd->rd_ri.ri_data - + rgd->rd_rg.rg_free - + rgd->rd_rg.rg_dinodes; + if (count[1] != tmp) { + if (gfs2_consist_rgrpd(rgd)) + fs_err(sdp, "used data mismatch: %u != %u\n", + count[1], tmp); + return; + } + + if (count[2]) { + if (gfs2_consist_rgrpd(rgd)) + fs_err(sdp, "free metadata mismatch: %u != 0\n", + count[2]); + return; + } + + if (count[3] != rgd->rd_rg.rg_dinodes) { + if (gfs2_consist_rgrpd(rgd)) + fs_err(sdp, "used metadata mismatch: %u != %u\n", + count[3], rgd->rd_rg.rg_dinodes); + return; + } +} + +static inline int rgrp_contains_block(struct gfs2_rindex *ri, uint64_t block) +{ + uint64_t first = ri->ri_data0; + uint64_t last = first + ri->ri_data; + return !!(first <= block && block < last); +} + +/** + * gfs2_blk2rgrpd - Find resource group for a given data/meta block number + * @sdp: The GFS2 superblock + * @n: The data block number + * + * Returns: The resource group, or NULL if not found + */ + +struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, uint64_t blk) +{ + struct gfs2_rgrpd *rgd; + + spin_lock(&sdp->sd_rindex_spin); + + list_for_each_entry(rgd, &sdp->sd_rindex_mru_list, rd_list_mru) { + if (rgrp_contains_block(&rgd->rd_ri, blk)) { + list_move(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list); + spin_unlock(&sdp->sd_rindex_spin); + return rgd; + } + } + + spin_unlock(&sdp->sd_rindex_spin); + + return NULL; +} + +/** + * gfs2_rgrpd_get_first - get the first Resource Group in the filesystem + * @sdp: The GFS2 superblock + * + * Returns: The first rgrp in the filesystem + */ + +struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp) +{ + gfs2_assert(sdp, !list_empty(&sdp->sd_rindex_list)); + return list_entry(sdp->sd_rindex_list.next, struct gfs2_rgrpd, rd_list); +} + +/** + * gfs2_rgrpd_get_next - get the next RG + * @rgd: A RG + * + * Returns: The next rgrp + */ + +struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd) +{ + if (rgd->rd_list.next == &rgd->rd_sbd->sd_rindex_list) + return NULL; + return list_entry(rgd->rd_list.next, struct gfs2_rgrpd, rd_list); +} + +static void clear_rgrpdi(struct gfs2_sbd *sdp) +{ + struct list_head *head; + struct gfs2_rgrpd *rgd; + struct gfs2_glock *gl; + + spin_lock(&sdp->sd_rindex_spin); + sdp->sd_rindex_forward = NULL; + head = &sdp->sd_rindex_recent_list; + while (!list_empty(head)) { + rgd = list_entry(head->next, struct gfs2_rgrpd, rd_recent); + list_del(&rgd->rd_recent); + } + spin_unlock(&sdp->sd_rindex_spin); + + head = &sdp->sd_rindex_list; + while (!list_empty(head)) { + rgd = list_entry(head->next, struct gfs2_rgrpd, rd_list); + gl = rgd->rd_gl; + + list_del(&rgd->rd_list); + list_del(&rgd->rd_list_mru); + + if (gl) { + set_gl2rgd(gl, NULL); + gfs2_glock_put(gl); + } + + kfree(rgd->rd_bits); + kfree(rgd); + } +} + +void gfs2_clear_rgrpd(struct gfs2_sbd *sdp) +{ + down(&sdp->sd_rindex_mutex); + clear_rgrpdi(sdp); + up(&sdp->sd_rindex_mutex); +} + +/** + * gfs2_compute_bitstructs - Compute the bitmap sizes + * @rgd: The resource group descriptor + * + * Calculates bitmap descriptors, one for each block that contains bitmap data + * + * Returns: errno + */ + +static int compute_bitstructs(struct gfs2_rgrpd *rgd) +{ + struct gfs2_sbd *sdp = rgd->rd_sbd; + struct gfs2_bitmap *bi; + uint32_t length = rgd->rd_ri.ri_length; /* # blocks in hdr & bitmap */ + uint32_t bytes_left, bytes; + int x; + + rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_KERNEL); + if (!rgd->rd_bits) + return -ENOMEM; + + bytes_left = rgd->rd_ri.ri_bitbytes; + + for (x = 0; x < length; x++) { + bi = rgd->rd_bits + x; + + /* small rgrp; bitmap stored completely in header block */ + if (length == 1) { + bytes = bytes_left; + bi->bi_offset = sizeof(struct gfs2_rgrp); + bi->bi_start = 0; + bi->bi_len = bytes; + /* header block */ + } else if (x == 0) { + bytes = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_rgrp); + bi->bi_offset = sizeof(struct gfs2_rgrp); + bi->bi_start = 0; + bi->bi_len = bytes; + /* last block */ + } else if (x + 1 == length) { + bytes = bytes_left; + bi->bi_offset = sizeof(struct gfs2_meta_header); + bi->bi_start = rgd->rd_ri.ri_bitbytes - bytes_left; + bi->bi_len = bytes; + /* other blocks */ + } else { + bytes = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header); + bi->bi_offset = sizeof(struct gfs2_meta_header); + bi->bi_start = rgd->rd_ri.ri_bitbytes - bytes_left; + bi->bi_len = bytes; + } + + bytes_left -= bytes; + } + + if (bytes_left) { + gfs2_consist_rgrpd(rgd); + return -EIO; + } + bi = rgd->rd_bits + (length - 1); + if ((bi->bi_start + bi->bi_len) * GFS2_NBBY != rgd->rd_ri.ri_data) { + if (gfs2_consist_rgrpd(rgd)) { + gfs2_rindex_print(&rgd->rd_ri); + fs_err(sdp, "start=%u len=%u offset=%u\n", + bi->bi_start, bi->bi_len, bi->bi_offset); + } + return -EIO; + } + + return 0; +} + +/** + * gfs2_ri_update - Pull in a new resource index from the disk + * @gl: The glock covering the rindex inode + * + * Returns: 0 on successful update, error code otherwise + */ + +static int gfs2_ri_update(struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_rgrpd *rgd; + char buf[sizeof(struct gfs2_rindex)]; + uint64_t junk = ip->i_di.di_size; + int error; + + if (do_div(junk, sizeof(struct gfs2_rindex))) { + gfs2_consist_inode(ip); + return -EIO; + } + + clear_rgrpdi(sdp); + + for (sdp->sd_rgrps = 0;; sdp->sd_rgrps++) { + error = gfs2_jdata_read_mem(ip, buf, + sdp->sd_rgrps * + sizeof(struct gfs2_rindex), + sizeof(struct gfs2_rindex)); + if (!error) + break; + if (error != sizeof(struct gfs2_rindex)) { + if (error > 0) + error = -EIO; + goto fail; + } + + rgd = kzalloc(sizeof(struct gfs2_rgrpd), GFP_KERNEL); + error = -ENOMEM; + if (!rgd) + goto fail; + + init_MUTEX(&rgd->rd_mutex); + lops_init_le(&rgd->rd_le, &gfs2_rg_lops); + rgd->rd_sbd = sdp; + + list_add_tail(&rgd->rd_list, &sdp->sd_rindex_list); + list_add_tail(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list); + + gfs2_rindex_in(&rgd->rd_ri, buf); + + error = compute_bitstructs(rgd); + if (error) + goto fail; + + error = gfs2_glock_get(sdp, rgd->rd_ri.ri_addr, + &gfs2_rgrp_glops, CREATE, &rgd->rd_gl); + if (error) + goto fail; + + set_gl2rgd(rgd->rd_gl, rgd); + rgd->rd_rg_vn = rgd->rd_gl->gl_vn - 1; + } + + sdp->sd_rindex_vn = ip->i_gl->gl_vn; + + return 0; + + fail: + clear_rgrpdi(sdp); + + return error; +} + +/** + * gfs2_rindex_hold - Grab a lock on the rindex + * @sdp: The GFS2 superblock + * @ri_gh: the glock holder + * + * We grab a lock on the rindex inode to make sure that it doesn't + * change whilst we are performing an operation. We keep this lock + * for quite long periods of time compared to other locks. This + * doesn't matter, since it is shared and it is very, very rarely + * accessed in the exclusive mode (i.e. only when expanding the filesystem). + * + * This makes sure that we're using the latest copy of the resource index + * special file, which might have been updated if someone expanded the + * filesystem (via gfs2_grow utility), which adds new resource groups. + * + * Returns: 0 on success, error code otherwise + */ + +int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh) +{ + struct gfs2_inode *ip = sdp->sd_rindex; + struct gfs2_glock *gl = ip->i_gl; + int error; + + error = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, ri_gh); + if (error) + return error; + + /* Read new copy from disk if we don't have the latest */ + if (sdp->sd_rindex_vn != gl->gl_vn) { + down(&sdp->sd_rindex_mutex); + if (sdp->sd_rindex_vn != gl->gl_vn) { + error = gfs2_ri_update(ip); + if (error) + gfs2_glock_dq_uninit(ri_gh); + } + up(&sdp->sd_rindex_mutex); + } + + return error; +} + +/** + * gfs2_rgrp_bh_get - Read in a RG's header and bitmaps + * @rgd: the struct gfs2_rgrpd describing the RG to read in + * + * Read in all of a Resource Group's header and bitmap blocks. + * Caller must eventually call gfs2_rgrp_relse() to free the bitmaps. + * + * Returns: errno + */ + +int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd) +{ + struct gfs2_sbd *sdp = rgd->rd_sbd; + struct gfs2_glock *gl = rgd->rd_gl; + unsigned int length = rgd->rd_ri.ri_length; + struct gfs2_bitmap *bi; + unsigned int x, y; + int error; + + down(&rgd->rd_mutex); + + spin_lock(&sdp->sd_rindex_spin); + if (rgd->rd_bh_count) { + rgd->rd_bh_count++; + spin_unlock(&sdp->sd_rindex_spin); + up(&rgd->rd_mutex); + return 0; + } + spin_unlock(&sdp->sd_rindex_spin); + + for (x = 0; x < length; x++) { + bi = rgd->rd_bits + x; + error = gfs2_meta_read(gl, rgd->rd_ri.ri_addr + x, DIO_START, + &bi->bi_bh); + if (error) + goto fail; + } + + for (y = length; y--;) { + bi = rgd->rd_bits + y; + error = gfs2_meta_reread(sdp, bi->bi_bh, DIO_WAIT); + if (error) + goto fail; + if (gfs2_metatype_check(sdp, bi->bi_bh, + (y) ? GFS2_METATYPE_RB : + GFS2_METATYPE_RG)) { + error = -EIO; + goto fail; + } + } + + if (rgd->rd_rg_vn != gl->gl_vn) { + gfs2_rgrp_in(&rgd->rd_rg, (rgd->rd_bits[0].bi_bh)->b_data); + rgd->rd_rg_vn = gl->gl_vn; + } + + spin_lock(&sdp->sd_rindex_spin); + rgd->rd_free_clone = rgd->rd_rg.rg_free; + rgd->rd_bh_count++; + spin_unlock(&sdp->sd_rindex_spin); + + up(&rgd->rd_mutex); + + return 0; + + fail: + while (x--) { + bi = rgd->rd_bits + x; + brelse(bi->bi_bh); + bi->bi_bh = NULL; + gfs2_assert_warn(sdp, !bi->bi_clone); + } + up(&rgd->rd_mutex); + + return error; +} + +void gfs2_rgrp_bh_hold(struct gfs2_rgrpd *rgd) +{ + struct gfs2_sbd *sdp = rgd->rd_sbd; + + spin_lock(&sdp->sd_rindex_spin); + gfs2_assert_warn(rgd->rd_sbd, rgd->rd_bh_count); + rgd->rd_bh_count++; + spin_unlock(&sdp->sd_rindex_spin); +} + +/** + * gfs2_rgrp_bh_put - Release RG bitmaps read in with gfs2_rgrp_bh_get() + * @rgd: the struct gfs2_rgrpd describing the RG to read in + * + */ + +void gfs2_rgrp_bh_put(struct gfs2_rgrpd *rgd) +{ + struct gfs2_sbd *sdp = rgd->rd_sbd; + int x, length = rgd->rd_ri.ri_length; + + spin_lock(&sdp->sd_rindex_spin); + gfs2_assert_warn(rgd->rd_sbd, rgd->rd_bh_count); + if (--rgd->rd_bh_count) { + spin_unlock(&sdp->sd_rindex_spin); + return; + } + + for (x = 0; x < length; x++) { + struct gfs2_bitmap *bi = rgd->rd_bits + x; + kfree(bi->bi_clone); + bi->bi_clone = NULL; + brelse(bi->bi_bh); + bi->bi_bh = NULL; + } + + spin_unlock(&sdp->sd_rindex_spin); +} + +void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd) +{ + struct gfs2_sbd *sdp = rgd->rd_sbd; + unsigned int length = rgd->rd_ri.ri_length; + unsigned int x; + + for (x = 0; x < length; x++) { + struct gfs2_bitmap *bi = rgd->rd_bits + x; + if (!bi->bi_clone) + continue; + memcpy(bi->bi_clone + bi->bi_offset, + bi->bi_bh->b_data + bi->bi_offset, + bi->bi_len); + } + + spin_lock(&sdp->sd_rindex_spin); + rgd->rd_free_clone = rgd->rd_rg.rg_free; + spin_unlock(&sdp->sd_rindex_spin); +} + +/** + * gfs2_alloc_get - get the struct gfs2_alloc structure for an inode + * @ip: the incore GFS2 inode structure + * + * Returns: the struct gfs2_alloc + */ + +struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip) +{ + struct gfs2_alloc *al = &ip->i_alloc; + + /* FIXME: Should assert that the correct locks are held here... */ + memset(al, 0, sizeof(*al)); + return al; +} + +/** + * gfs2_alloc_put - throw away the struct gfs2_alloc for an inode + * @ip: the inode + * + */ + +void gfs2_alloc_put(struct gfs2_inode *ip) +{ + return; +} + +/** + * try_rgrp_fit - See if a given reservation will fit in a given RG + * @rgd: the RG data + * @al: the struct gfs2_alloc structure describing the reservation + * + * If there's room for the requested blocks to be allocated from the RG: + * Sets the $al_reserved_data field in @al. + * Sets the $al_reserved_meta field in @al. + * Sets the $al_rgd field in @al. + * + * Returns: 1 on success (it fits), 0 on failure (it doesn't fit) + */ + +static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_alloc *al) +{ + struct gfs2_sbd *sdp = rgd->rd_sbd; + int ret = 0; + + spin_lock(&sdp->sd_rindex_spin); + if (rgd->rd_free_clone >= al->al_requested) { + al->al_rgd = rgd; + ret = 1; + } + spin_unlock(&sdp->sd_rindex_spin); + + return ret; +} + +/** + * recent_rgrp_first - get first RG from "recent" list + * @sdp: The GFS2 superblock + * @rglast: address of the rgrp used last + * + * Returns: The first rgrp in the recent list + */ + +static struct gfs2_rgrpd *recent_rgrp_first(struct gfs2_sbd *sdp, + uint64_t rglast) +{ + struct gfs2_rgrpd *rgd = NULL; + + spin_lock(&sdp->sd_rindex_spin); + + if (list_empty(&sdp->sd_rindex_recent_list)) + goto out; + + if (!rglast) + goto first; + + list_for_each_entry(rgd, &sdp->sd_rindex_recent_list, rd_recent) { + if (rgd->rd_ri.ri_addr == rglast) + goto out; + } + + first: + rgd = list_entry(sdp->sd_rindex_recent_list.next, struct gfs2_rgrpd, + rd_recent); + + out: + spin_unlock(&sdp->sd_rindex_spin); + + return rgd; +} + +/** + * recent_rgrp_next - get next RG from "recent" list + * @cur_rgd: current rgrp + * @remove: + * + * Returns: The next rgrp in the recent list + */ + +static struct gfs2_rgrpd *recent_rgrp_next(struct gfs2_rgrpd *cur_rgd, + int remove) +{ + struct gfs2_sbd *sdp = cur_rgd->rd_sbd; + struct list_head *head; + struct gfs2_rgrpd *rgd; + + spin_lock(&sdp->sd_rindex_spin); + + head = &sdp->sd_rindex_recent_list; + + list_for_each_entry(rgd, head, rd_recent) { + if (rgd == cur_rgd) { + if (cur_rgd->rd_recent.next != head) + rgd = list_entry(cur_rgd->rd_recent.next, + struct gfs2_rgrpd, rd_recent); + else + rgd = NULL; + + if (remove) + list_del(&cur_rgd->rd_recent); + + goto out; + } + } + + rgd = NULL; + if (!list_empty(head)) + rgd = list_entry(head->next, struct gfs2_rgrpd, rd_recent); + + out: + spin_unlock(&sdp->sd_rindex_spin); + + return rgd; +} + +/** + * recent_rgrp_add - add an RG to tail of "recent" list + * @new_rgd: The rgrp to add + * + */ + +static void recent_rgrp_add(struct gfs2_rgrpd *new_rgd) +{ + struct gfs2_sbd *sdp = new_rgd->rd_sbd; + struct gfs2_rgrpd *rgd; + unsigned int count = 0; + unsigned int max = sdp->sd_rgrps / gfs2_jindex_size(sdp); + + spin_lock(&sdp->sd_rindex_spin); + + list_for_each_entry(rgd, &sdp->sd_rindex_recent_list, rd_recent) { + if (rgd == new_rgd) + goto out; + + if (++count >= max) + goto out; + } + list_add_tail(&new_rgd->rd_recent, &sdp->sd_rindex_recent_list); + + out: + spin_unlock(&sdp->sd_rindex_spin); +} + +/** + * forward_rgrp_get - get an rgrp to try next from full list + * @sdp: The GFS2 superblock + * + * Returns: The rgrp to try next + */ + +static struct gfs2_rgrpd *forward_rgrp_get(struct gfs2_sbd *sdp) +{ + struct gfs2_rgrpd *rgd; + unsigned int journals = gfs2_jindex_size(sdp); + unsigned int rg = 0, x; + + spin_lock(&sdp->sd_rindex_spin); + + rgd = sdp->sd_rindex_forward; + if (!rgd) { + if (sdp->sd_rgrps >= journals) + rg = sdp->sd_rgrps * sdp->sd_jdesc->jd_jid / journals; + + for (x = 0, rgd = gfs2_rgrpd_get_first(sdp); + x < rg; + x++, rgd = gfs2_rgrpd_get_next(rgd)) + /* Do Nothing */; + + sdp->sd_rindex_forward = rgd; + } + + spin_unlock(&sdp->sd_rindex_spin); + + return rgd; +} + +/** + * forward_rgrp_set - set the forward rgrp pointer + * @sdp: the filesystem + * @rgd: The new forward rgrp + * + */ + +static void forward_rgrp_set(struct gfs2_sbd *sdp, struct gfs2_rgrpd *rgd) +{ + spin_lock(&sdp->sd_rindex_spin); + sdp->sd_rindex_forward = rgd; + spin_unlock(&sdp->sd_rindex_spin); +} + +/** + * get_local_rgrp - Choose and lock a rgrp for allocation + * @ip: the inode to reserve space for + * @rgp: the chosen and locked rgrp + * + * Try to acquire rgrp in way which avoids contending with others. + * + * Returns: errno + */ + +static int get_local_rgrp(struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_rgrpd *rgd, *begin = NULL; + struct gfs2_alloc *al = &ip->i_alloc; + int flags = LM_FLAG_TRY; + int skipped = 0; + int loops = 0; + int error; + + /* Try recently successful rgrps */ + + rgd = recent_rgrp_first(sdp, ip->i_last_rg_alloc); + + while (rgd) { + error = gfs2_glock_nq_init(rgd->rd_gl, + LM_ST_EXCLUSIVE, LM_FLAG_TRY, + &al->al_rgd_gh); + switch (error) { + case 0: + if (try_rgrp_fit(rgd, al)) + goto out; + gfs2_glock_dq_uninit(&al->al_rgd_gh); + rgd = recent_rgrp_next(rgd, 1); + break; + + case GLR_TRYFAILED: + rgd = recent_rgrp_next(rgd, 0); + break; + + default: + return error; + } + } + + /* Go through full list of rgrps */ + + begin = rgd = forward_rgrp_get(sdp); + + for (;;) { + error = gfs2_glock_nq_init(rgd->rd_gl, + LM_ST_EXCLUSIVE, flags, + &al->al_rgd_gh); + switch (error) { + case 0: + if (try_rgrp_fit(rgd, al)) + goto out; + gfs2_glock_dq_uninit(&al->al_rgd_gh); + break; + + case GLR_TRYFAILED: + skipped++; + break; + + default: + return error; + } + + rgd = gfs2_rgrpd_get_next(rgd); + if (!rgd) + rgd = gfs2_rgrpd_get_first(sdp); + + if (rgd == begin) { + if (++loops >= 2 || !skipped) + return -ENOSPC; + flags = 0; + } + } + + out: + ip->i_last_rg_alloc = rgd->rd_ri.ri_addr; + + if (begin) { + recent_rgrp_add(rgd); + rgd = gfs2_rgrpd_get_next(rgd); + if (!rgd) + rgd = gfs2_rgrpd_get_first(sdp); + forward_rgrp_set(sdp, rgd); + } + + return 0; +} + +/** + * gfs2_inplace_reserve_i - Reserve space in the filesystem + * @ip: the inode to reserve space for + * + * Returns: errno + */ + +int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = &ip->i_alloc; + int error; + + if (gfs2_assert_warn(sdp, al->al_requested)) + return -EINVAL; + + error = gfs2_rindex_hold(sdp, &al->al_ri_gh); + if (error) + return error; + + error = get_local_rgrp(ip); + if (error) { + gfs2_glock_dq_uninit(&al->al_ri_gh); + return error; + } + + al->al_file = file; + al->al_line = line; + + return 0; +} + +/** + * gfs2_inplace_release - release an inplace reservation + * @ip: the inode the reservation was taken out on + * + * Release a reservation made by gfs2_inplace_reserve(). + */ + +void gfs2_inplace_release(struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = &ip->i_alloc; + + if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1) + fs_warn(sdp, "al_alloced = %u, al_requested = %u " + "al_file = %s, al_line = %u\n", + al->al_alloced, al->al_requested, al->al_file, + al->al_line); + + al->al_rgd = NULL; + gfs2_glock_dq_uninit(&al->al_rgd_gh); + gfs2_glock_dq_uninit(&al->al_ri_gh); +} + +/** + * gfs2_get_block_type - Check a block in a RG is of given type + * @rgd: the resource group holding the block + * @block: the block number + * + * Returns: The block type (GFS2_BLKST_*) + */ + +unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, uint64_t block) +{ + struct gfs2_bitmap *bi = NULL; + uint32_t length, rgrp_block, buf_block; + unsigned int buf; + unsigned char type; + + length = rgd->rd_ri.ri_length; + rgrp_block = block - rgd->rd_ri.ri_data0; + + for (buf = 0; buf < length; buf++) { + bi = rgd->rd_bits + buf; + if (rgrp_block < (bi->bi_start + bi->bi_len) * GFS2_NBBY) + break; + } + + gfs2_assert(rgd->rd_sbd, buf < length); + buf_block = rgrp_block - bi->bi_start * GFS2_NBBY; + + type = gfs2_testbit(rgd, + bi->bi_bh->b_data + bi->bi_offset, + bi->bi_len, buf_block); + + return type; +} + +/** + * rgblk_search - find a block in @old_state, change allocation + * state to @new_state + * @rgd: the resource group descriptor + * @goal: the goal block within the RG (start here to search for avail block) + * @old_state: GFS2_BLKST_XXX the before-allocation state to find + * @new_state: GFS2_BLKST_XXX the after-allocation block state + * + * Walk rgrp's bitmap to find bits that represent a block in @old_state. + * Add the found bitmap buffer to the transaction. + * Set the found bits to @new_state to change block's allocation state. + * + * This function never fails, because we wouldn't call it unless we + * know (from reservation results, etc.) that a block is available. + * + * Scope of @goal and returned block is just within rgrp, not the whole + * filesystem. + * + * Returns: the block number allocated + */ + +static uint32_t rgblk_search(struct gfs2_rgrpd *rgd, uint32_t goal, + unsigned char old_state, unsigned char new_state) +{ + struct gfs2_bitmap *bi = NULL; + uint32_t length = rgd->rd_ri.ri_length; + uint32_t blk = 0; + unsigned int buf, x; + + /* Find bitmap block that contains bits for goal block */ + for (buf = 0; buf < length; buf++) { + bi = rgd->rd_bits + buf; + if (goal < (bi->bi_start + bi->bi_len) * GFS2_NBBY) + break; + } + + gfs2_assert(rgd->rd_sbd, buf < length); + + /* Convert scope of "goal" from rgrp-wide to within found bit block */ + goal -= bi->bi_start * GFS2_NBBY; + + /* Search (up to entire) bitmap in this rgrp for allocatable block. + "x <= length", instead of "x < length", because we typically start + the search in the middle of a bit block, but if we can't find an + allocatable block anywhere else, we want to be able wrap around and + search in the first part of our first-searched bit block. */ + for (x = 0; x <= length; x++) { + if (bi->bi_clone) + blk = gfs2_bitfit(rgd, + bi->bi_clone + bi->bi_offset, + bi->bi_len, goal, old_state); + else + blk = gfs2_bitfit(rgd, + bi->bi_bh->b_data + bi->bi_offset, + bi->bi_len, goal, old_state); + if (blk != BFITNOENT) + break; + + /* Try next bitmap block (wrap back to rgrp header if at end) */ + buf = (buf + 1) % length; + bi = rgd->rd_bits + buf; + goal = 0; + } + + if (gfs2_assert_withdraw(rgd->rd_sbd, x <= length)) + blk = 0; + + gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh); + gfs2_setbit(rgd, + bi->bi_bh->b_data + bi->bi_offset, + bi->bi_len, blk, new_state); + if (bi->bi_clone) + gfs2_setbit(rgd, + bi->bi_clone + bi->bi_offset, + bi->bi_len, blk, new_state); + + return bi->bi_start * GFS2_NBBY + blk; +} + +/** + * rgblk_free - Change alloc state of given block(s) + * @sdp: the filesystem + * @bstart: the start of a run of blocks to free + * @blen: the length of the block run (all must lie within ONE RG!) + * @new_state: GFS2_BLKST_XXX the after-allocation block state + * + * Returns: Resource group containing the block(s) + */ + +static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, uint64_t bstart, + uint32_t blen, unsigned char new_state) +{ + struct gfs2_rgrpd *rgd; + struct gfs2_bitmap *bi = NULL; + uint32_t length, rgrp_blk, buf_blk; + unsigned int buf; + + rgd = gfs2_blk2rgrpd(sdp, bstart); + if (!rgd) { + if (gfs2_consist(sdp)) + fs_err(sdp, "block = %llu\n", bstart); + return NULL; + } + + length = rgd->rd_ri.ri_length; + + rgrp_blk = bstart - rgd->rd_ri.ri_data0; + + while (blen--) { + for (buf = 0; buf < length; buf++) { + bi = rgd->rd_bits + buf; + if (rgrp_blk < (bi->bi_start + bi->bi_len) * GFS2_NBBY) + break; + } + + gfs2_assert(rgd->rd_sbd, buf < length); + + buf_blk = rgrp_blk - bi->bi_start * GFS2_NBBY; + rgrp_blk++; + + if (!bi->bi_clone) { + bi->bi_clone = kmalloc(bi->bi_bh->b_size, + GFP_KERNEL | __GFP_NOFAIL); + memcpy(bi->bi_clone + bi->bi_offset, + bi->bi_bh->b_data + bi->bi_offset, + bi->bi_len); + } + gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh); + gfs2_setbit(rgd, + bi->bi_bh->b_data + bi->bi_offset, + bi->bi_len, buf_blk, new_state); + } + + return rgd; +} + +/** + * gfs2_alloc_data - Allocate a data block + * @ip: the inode to allocate the data block for + * + * Returns: the allocated block + */ + +uint64_t gfs2_alloc_data(struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = &ip->i_alloc; + struct gfs2_rgrpd *rgd = al->al_rgd; + uint32_t goal, blk; + uint64_t block; + + if (rgrp_contains_block(&rgd->rd_ri, ip->i_di.di_goal_data)) + goal = ip->i_di.di_goal_data - rgd->rd_ri.ri_data0; + else + goal = rgd->rd_last_alloc_data; + + blk = rgblk_search(rgd, goal, + GFS2_BLKST_FREE, GFS2_BLKST_USED); + rgd->rd_last_alloc_data = blk; + + block = rgd->rd_ri.ri_data0 + blk; + ip->i_di.di_goal_data = block; + + gfs2_assert_withdraw(sdp, rgd->rd_rg.rg_free); + rgd->rd_rg.rg_free--; + + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); + + al->al_alloced++; + + gfs2_statfs_change(sdp, 0, -1, 0); + gfs2_quota_change(ip, +1, ip->i_di.di_uid, ip->i_di.di_gid); + + spin_lock(&sdp->sd_rindex_spin); + rgd->rd_free_clone--; + spin_unlock(&sdp->sd_rindex_spin); + + return block; +} + +/** + * gfs2_alloc_meta - Allocate a metadata block + * @ip: the inode to allocate the metadata block for + * + * Returns: the allocated block + */ + +uint64_t gfs2_alloc_meta(struct gfs2_inode *ip) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_alloc *al = &ip->i_alloc; + struct gfs2_rgrpd *rgd = al->al_rgd; + uint32_t goal, blk; + uint64_t block; + + if (rgrp_contains_block(&rgd->rd_ri, ip->i_di.di_goal_meta)) + goal = ip->i_di.di_goal_meta - rgd->rd_ri.ri_data0; + else + goal = rgd->rd_last_alloc_meta; + + blk = rgblk_search(rgd, goal, + GFS2_BLKST_FREE, GFS2_BLKST_USED); + rgd->rd_last_alloc_meta = blk; + + block = rgd->rd_ri.ri_data0 + blk; + ip->i_di.di_goal_meta = block; + + gfs2_assert_withdraw(sdp, rgd->rd_rg.rg_free); + rgd->rd_rg.rg_free--; + + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); + + al->al_alloced++; + + gfs2_statfs_change(sdp, 0, -1, 0); + gfs2_quota_change(ip, +1, ip->i_di.di_uid, ip->i_di.di_gid); + gfs2_trans_add_unrevoke(sdp, block); + + spin_lock(&sdp->sd_rindex_spin); + rgd->rd_free_clone--; + spin_unlock(&sdp->sd_rindex_spin); + + return block; +} + +/** + * gfs2_alloc_di - Allocate a dinode + * @dip: the directory that the inode is going in + * + * Returns: the block allocated + */ + +uint64_t gfs2_alloc_di(struct gfs2_inode *dip) +{ + struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_alloc *al = &dip->i_alloc; + struct gfs2_rgrpd *rgd = al->al_rgd; + uint32_t blk; + uint64_t block; + + blk = rgblk_search(rgd, rgd->rd_last_alloc_meta, + GFS2_BLKST_FREE, GFS2_BLKST_DINODE); + + rgd->rd_last_alloc_meta = blk; + + block = rgd->rd_ri.ri_data0 + blk; + + gfs2_assert_withdraw(sdp, rgd->rd_rg.rg_free); + rgd->rd_rg.rg_free--; + rgd->rd_rg.rg_dinodes++; + + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); + + al->al_alloced++; + + gfs2_statfs_change(sdp, 0, -1, +1); + gfs2_trans_add_unrevoke(sdp, block); + + spin_lock(&sdp->sd_rindex_spin); + rgd->rd_free_clone--; + spin_unlock(&sdp->sd_rindex_spin); + + return block; +} + +/** + * gfs2_free_data - free a contiguous run of data block(s) + * @ip: the inode these blocks are being freed from + * @bstart: first block of a run of contiguous blocks + * @blen: the length of the block run + * + */ + +void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_rgrpd *rgd; + + rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE); + if (!rgd) + return; + + rgd->rd_rg.rg_free += blen; + + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); + + gfs2_trans_add_rg(rgd); + + gfs2_statfs_change(sdp, 0, +blen, 0); + gfs2_quota_change(ip, -(int64_t)blen, + ip->i_di.di_uid, ip->i_di.di_gid); +} + +/** + * gfs2_free_meta - free a contiguous run of data block(s) + * @ip: the inode these blocks are being freed from + * @bstart: first block of a run of contiguous blocks + * @blen: the length of the block run + * + */ + +void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_rgrpd *rgd; + + rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE); + if (!rgd) + return; + + rgd->rd_rg.rg_free += blen; + + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); + + gfs2_trans_add_rg(rgd); + + gfs2_statfs_change(sdp, 0, +blen, 0); + gfs2_quota_change(ip, -(int64_t)blen, + ip->i_di.di_uid, ip->i_di.di_gid); + gfs2_meta_wipe(ip, bstart, blen); +} + +void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno) +{ + struct gfs2_sbd *sdp = rgd->rd_sbd; + struct gfs2_rgrpd *tmp_rgd; + + tmp_rgd = rgblk_free(sdp, blkno, 1, GFS2_BLKST_FREE); + if (!tmp_rgd) + return; + gfs2_assert_withdraw(sdp, rgd == tmp_rgd); + + if (!rgd->rd_rg.rg_dinodes) + gfs2_consist_rgrpd(rgd); + rgd->rd_rg.rg_dinodes--; + rgd->rd_rg.rg_free++; + + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); + + gfs2_statfs_change(sdp, 0, +1, -1); + gfs2_trans_add_rg(rgd); +} + +/** + * gfs2_free_uninit_di - free a dinode block + * @rgd: the resource group that contains the dinode + * @ip: the inode + * + */ + +void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) +{ + gfs2_free_uninit_di(rgd, ip->i_num.no_addr); + gfs2_quota_change(ip, -1, ip->i_di.di_uid, ip->i_di.di_gid); + gfs2_meta_wipe(ip, ip->i_num.no_addr, 1); +} + +/** + * gfs2_rlist_add - add a RG to a list of RGs + * @sdp: the filesystem + * @rlist: the list of resource groups + * @block: the block + * + * Figure out what RG a block belongs to and add that RG to the list + * + * FIXME: Don't use NOFAIL + * + */ + +void gfs2_rlist_add(struct gfs2_sbd *sdp, struct gfs2_rgrp_list *rlist, + uint64_t block) +{ + struct gfs2_rgrpd *rgd; + struct gfs2_rgrpd **tmp; + unsigned int new_space; + unsigned int x; + + if (gfs2_assert_warn(sdp, !rlist->rl_ghs)) + return; + + rgd = gfs2_blk2rgrpd(sdp, block); + if (!rgd) { + if (gfs2_consist(sdp)) + fs_err(sdp, "block = %llu\n", block); + return; + } + + for (x = 0; x < rlist->rl_rgrps; x++) + if (rlist->rl_rgd[x] == rgd) + return; + + if (rlist->rl_rgrps == rlist->rl_space) { + new_space = rlist->rl_space + 10; + + tmp = kcalloc(new_space, sizeof(struct gfs2_rgrpd *), + GFP_KERNEL | __GFP_NOFAIL); + + if (rlist->rl_rgd) { + memcpy(tmp, rlist->rl_rgd, + rlist->rl_space * sizeof(struct gfs2_rgrpd *)); + kfree(rlist->rl_rgd); + } + + rlist->rl_space = new_space; + rlist->rl_rgd = tmp; + } + + rlist->rl_rgd[rlist->rl_rgrps++] = rgd; +} + +/** + * gfs2_rlist_alloc - all RGs have been added to the rlist, now allocate + * and initialize an array of glock holders for them + * @rlist: the list of resource groups + * @state: the lock state to acquire the RG lock in + * @flags: the modifier flags for the holder structures + * + * FIXME: Don't use NOFAIL + * + */ + +void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state, + int flags) +{ + unsigned int x; + + rlist->rl_ghs = kcalloc(rlist->rl_rgrps, sizeof(struct gfs2_holder), + GFP_KERNEL | __GFP_NOFAIL); + for (x = 0; x < rlist->rl_rgrps; x++) + gfs2_holder_init(rlist->rl_rgd[x]->rd_gl, + state, flags, + &rlist->rl_ghs[x]); +} + +/** + * gfs2_rlist_free - free a resource group list + * @list: the list of resource groups + * + */ + +void gfs2_rlist_free(struct gfs2_rgrp_list *rlist) +{ + unsigned int x; + + kfree(rlist->rl_rgd); + + if (rlist->rl_ghs) { + for (x = 0; x < rlist->rl_rgrps; x++) + gfs2_holder_uninit(&rlist->rl_ghs[x]); + kfree(rlist->rl_ghs); + } +} + diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h new file mode 100644 index 000000000000..4c44a191b1c1 --- /dev/null +++ b/fs/gfs2/rgrp.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __RGRP_DOT_H__ +#define __RGRP_DOT_H__ + +void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd); + +struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, uint64_t blk); +struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp); +struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd); + +void gfs2_clear_rgrpd(struct gfs2_sbd *sdp); +int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh); + +int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd); +void gfs2_rgrp_bh_hold(struct gfs2_rgrpd *rgd); +void gfs2_rgrp_bh_put(struct gfs2_rgrpd *rgd); + +void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd); + +struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip); +void gfs2_alloc_put(struct gfs2_inode *ip); + +int gfs2_inplace_reserve_i(struct gfs2_inode *ip, + char *file, unsigned int line); +#define gfs2_inplace_reserve(ip) \ +gfs2_inplace_reserve_i((ip), __FILE__, __LINE__) + +void gfs2_inplace_release(struct gfs2_inode *ip); + +unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, uint64_t block); + +uint64_t gfs2_alloc_data(struct gfs2_inode *ip); +uint64_t gfs2_alloc_meta(struct gfs2_inode *ip); +uint64_t gfs2_alloc_di(struct gfs2_inode *ip); + +void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); +void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); +void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno); +void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip); + +struct gfs2_rgrp_list { + unsigned int rl_rgrps; + unsigned int rl_space; + struct gfs2_rgrpd **rl_rgd; + struct gfs2_holder *rl_ghs; +}; + +void gfs2_rlist_add(struct gfs2_sbd *sdp, struct gfs2_rgrp_list *rlist, + uint64_t block); +void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state, + int flags); +void gfs2_rlist_free(struct gfs2_rgrp_list *rlist); + +#endif /* __RGRP_DOT_H__ */ diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c new file mode 100644 index 000000000000..d37f203e133b --- /dev/null +++ b/fs/gfs2/super.c @@ -0,0 +1,944 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "dir.h" +#include "format.h" +#include "glock.h" +#include "glops.h" +#include "inode.h" +#include "log.h" +#include "meta_io.h" +#include "quota.h" +#include "recovery.h" +#include "rgrp.h" +#include "super.h" +#include "trans.h" +#include "unlinked.h" + +/** + * gfs2_tune_init - Fill a gfs2_tune structure with default values + * @gt: tune + * + */ + +void gfs2_tune_init(struct gfs2_tune *gt) +{ + spin_lock_init(>->gt_spin); + + gt->gt_ilimit = 100; + gt->gt_ilimit_tries = 3; + gt->gt_ilimit_min = 1; + gt->gt_demote_secs = 300; + gt->gt_incore_log_blocks = 1024; + gt->gt_log_flush_secs = 60; + gt->gt_jindex_refresh_secs = 60; + gt->gt_scand_secs = 15; + gt->gt_recoverd_secs = 60; + gt->gt_logd_secs = 1; + gt->gt_quotad_secs = 5; + gt->gt_inoded_secs = 15; + gt->gt_quota_simul_sync = 64; + gt->gt_quota_warn_period = 10; + gt->gt_quota_scale_num = 1; + gt->gt_quota_scale_den = 1; + gt->gt_quota_cache_secs = 300; + gt->gt_quota_quantum = 60; + gt->gt_atime_quantum = 3600; + gt->gt_new_files_jdata = 0; + gt->gt_new_files_directio = 0; + gt->gt_max_atomic_write = 4 << 20; + gt->gt_max_readahead = 1 << 18; + gt->gt_lockdump_size = 131072; + gt->gt_stall_secs = 600; + gt->gt_complain_secs = 10; + gt->gt_reclaim_limit = 5000; + gt->gt_entries_per_readdir = 32; + gt->gt_prefetch_secs = 10; + gt->gt_greedy_default = HZ / 10; + gt->gt_greedy_quantum = HZ / 40; + gt->gt_greedy_max = HZ / 4; + gt->gt_statfs_quantum = 30; + gt->gt_statfs_slow = 0; +} + +/** + * gfs2_check_sb - Check superblock + * @sdp: the filesystem + * @sb: The superblock + * @silent: Don't print a message if the check fails + * + * Checks the version code of the FS is one that we understand how to + * read and that the sizes of the various on-disk structures have not + * changed. + */ + +int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent) +{ + unsigned int x; + + if (sb->sb_header.mh_magic != GFS2_MAGIC || + sb->sb_header.mh_type != GFS2_METATYPE_SB) { + if (!silent) + printk("GFS2: not a GFS2 filesystem\n"); + return -EINVAL; + } + + /* If format numbers match exactly, we're done. */ + + if (sb->sb_fs_format == GFS2_FORMAT_FS && + sb->sb_multihost_format == GFS2_FORMAT_MULTI) + return 0; + + if (sb->sb_fs_format != GFS2_FORMAT_FS) { + for (x = 0; gfs2_old_fs_formats[x]; x++) + if (gfs2_old_fs_formats[x] == sb->sb_fs_format) + break; + + if (!gfs2_old_fs_formats[x]) { + printk("GFS2: code version (%u, %u) is incompatible " + "with ondisk format (%u, %u)\n", + GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, + sb->sb_fs_format, sb->sb_multihost_format); + printk("GFS2: I don't know how to upgrade this FS\n"); + return -EINVAL; + } + } + + if (sb->sb_multihost_format != GFS2_FORMAT_MULTI) { + for (x = 0; gfs2_old_multihost_formats[x]; x++) + if (gfs2_old_multihost_formats[x] == sb->sb_multihost_format) + break; + + if (!gfs2_old_multihost_formats[x]) { + printk("GFS2: code version (%u, %u) is incompatible " + "with ondisk format (%u, %u)\n", + GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, + sb->sb_fs_format, sb->sb_multihost_format); + printk("GFS2: I don't know how to upgrade this FS\n"); + return -EINVAL; + } + } + + if (!sdp->sd_args.ar_upgrade) { + printk("GFS2: code version (%u, %u) is incompatible " + "with ondisk format (%u, %u)\n", + GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, + sb->sb_fs_format, sb->sb_multihost_format); + printk("GFS2: Use the \"upgrade\" mount option to upgrade " + "the FS\n"); + printk("GFS2: See the manual for more details\n"); + return -EINVAL; + } + + return 0; +} + +/** + * gfs2_read_sb - Read super block + * @sdp: The GFS2 superblock + * @gl: the glock for the superblock (assumed to be held) + * @silent: Don't print message if mount fails + * + */ + +int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) +{ + struct buffer_head *bh; + uint32_t hash_blocks, ind_blocks, leaf_blocks; + uint32_t tmp_blocks; + unsigned int x; + int error; + + error = gfs2_meta_read(gl, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift, + DIO_FORCE | DIO_START | DIO_WAIT, &bh); + if (error) { + if (!silent) + fs_err(sdp, "can't read superblock\n"); + return error; + } + + gfs2_assert(sdp, sizeof(struct gfs2_sb) <= bh->b_size); + gfs2_sb_in(&sdp->sd_sb, bh->b_data); + brelse(bh); + + error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); + if (error) + return error; + + sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - + GFS2_BASIC_BLOCK_SHIFT; + sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; + sdp->sd_diptrs = (sdp->sd_sb.sb_bsize - + sizeof(struct gfs2_dinode)) / sizeof(uint64_t); + sdp->sd_inptrs = (sdp->sd_sb.sb_bsize - + sizeof(struct gfs2_meta_header)) / sizeof(uint64_t); + sdp->sd_jbsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header); + sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2; + sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1; + sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(uint64_t); + sdp->sd_ut_per_block = (sdp->sd_sb.sb_bsize - + sizeof(struct gfs2_meta_header)) / + sizeof(struct gfs2_unlinked_tag); + sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize - + sizeof(struct gfs2_meta_header)) / + sizeof(struct gfs2_quota_change); + + /* Compute maximum reservation required to add a entry to a directory */ + + hash_blocks = DIV_RU(sizeof(uint64_t) * (1 << GFS2_DIR_MAX_DEPTH), + sdp->sd_jbsize); + + ind_blocks = 0; + for (tmp_blocks = hash_blocks; tmp_blocks > sdp->sd_diptrs;) { + tmp_blocks = DIV_RU(tmp_blocks, sdp->sd_inptrs); + ind_blocks += tmp_blocks; + } + + leaf_blocks = 2 + GFS2_DIR_MAX_DEPTH; + + sdp->sd_max_dirres = hash_blocks + ind_blocks + leaf_blocks; + + sdp->sd_heightsize[0] = sdp->sd_sb.sb_bsize - + sizeof(struct gfs2_dinode); + sdp->sd_heightsize[1] = sdp->sd_sb.sb_bsize * sdp->sd_diptrs; + for (x = 2;; x++) { + uint64_t space, d; + uint32_t m; + + space = sdp->sd_heightsize[x - 1] * sdp->sd_inptrs; + d = space; + m = do_div(d, sdp->sd_inptrs); + + if (d != sdp->sd_heightsize[x - 1] || m) + break; + sdp->sd_heightsize[x] = space; + } + sdp->sd_max_height = x; + gfs2_assert(sdp, sdp->sd_max_height <= GFS2_MAX_META_HEIGHT); + + sdp->sd_jheightsize[0] = sdp->sd_sb.sb_bsize - + sizeof(struct gfs2_dinode); + sdp->sd_jheightsize[1] = sdp->sd_jbsize * sdp->sd_diptrs; + for (x = 2;; x++) { + uint64_t space, d; + uint32_t m; + + space = sdp->sd_jheightsize[x - 1] * sdp->sd_inptrs; + d = space; + m = do_div(d, sdp->sd_inptrs); + + if (d != sdp->sd_jheightsize[x - 1] || m) + break; + sdp->sd_jheightsize[x] = space; + } + sdp->sd_max_jheight = x; + gfs2_assert(sdp, sdp->sd_max_jheight <= GFS2_MAX_META_HEIGHT); + + return 0; +} + +int gfs2_do_upgrade(struct gfs2_sbd *sdp, struct gfs2_glock *sb_gl) +{ + return 0; +} + +/** + * gfs2_jindex_hold - Grab a lock on the jindex + * @sdp: The GFS2 superblock + * @ji_gh: the holder for the jindex glock + * + * This is very similar to the gfs2_rindex_hold() function, except that + * in general we hold the jindex lock for longer periods of time and + * we grab it far less frequently (in general) then the rgrp lock. + * + * Returns: errno + */ + +int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) +{ + struct gfs2_inode *dip = sdp->sd_jindex; + struct qstr name; + char buf[20]; + struct gfs2_jdesc *jd; + int error; + + name.name = buf; + + down(&sdp->sd_jindex_mutex); + + for (;;) { + error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, + GL_LOCAL_EXCL, ji_gh); + if (error) + break; + + name.len = sprintf(buf, "journal%u", sdp->sd_journals); + + error = gfs2_dir_search(sdp->sd_jindex, &name, NULL, NULL); + if (error == -ENOENT) { + error = 0; + break; + } + + gfs2_glock_dq_uninit(ji_gh); + + if (error) + break; + + error = -ENOMEM; + jd = kzalloc(sizeof(struct gfs2_jdesc), GFP_KERNEL); + if (!jd) + break; + + error = gfs2_lookupi(dip, &name, 1, &jd->jd_inode); + if (error) { + kfree(jd); + break; + } + + spin_lock(&sdp->sd_jindex_spin); + jd->jd_jid = sdp->sd_journals++; + list_add_tail(&jd->jd_list, &sdp->sd_jindex_list); + spin_unlock(&sdp->sd_jindex_spin); + } + + up(&sdp->sd_jindex_mutex); + + return error; +} + +/** + * gfs2_jindex_free - Clear all the journal index information + * @sdp: The GFS2 superblock + * + */ + +void gfs2_jindex_free(struct gfs2_sbd *sdp) +{ + struct list_head list; + struct gfs2_jdesc *jd; + + spin_lock(&sdp->sd_jindex_spin); + list_add(&list, &sdp->sd_jindex_list); + list_del_init(&sdp->sd_jindex_list); + sdp->sd_journals = 0; + spin_unlock(&sdp->sd_jindex_spin); + + while (!list_empty(&list)) { + jd = list_entry(list.next, struct gfs2_jdesc, jd_list); + list_del(&jd->jd_list); + gfs2_inode_put(jd->jd_inode); + kfree(jd); + } +} + +static struct gfs2_jdesc *jdesc_find_i(struct list_head *head, unsigned int jid) +{ + struct gfs2_jdesc *jd; + int found = 0; + + list_for_each_entry(jd, head, jd_list) { + if (jd->jd_jid == jid) { + found = 1; + break; + } + } + + if (!found) + jd = NULL; + + return jd; +} + +struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid) +{ + struct gfs2_jdesc *jd; + + spin_lock(&sdp->sd_jindex_spin); + jd = jdesc_find_i(&sdp->sd_jindex_list, jid); + spin_unlock(&sdp->sd_jindex_spin); + + return jd; +} + +void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid) +{ + struct gfs2_jdesc *jd; + + spin_lock(&sdp->sd_jindex_spin); + jd = jdesc_find_i(&sdp->sd_jindex_list, jid); + if (jd) + jd->jd_dirty = 1; + spin_unlock(&sdp->sd_jindex_spin); +} + +struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp) +{ + struct gfs2_jdesc *jd; + int found = 0; + + spin_lock(&sdp->sd_jindex_spin); + + list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { + if (jd->jd_dirty) { + jd->jd_dirty = 0; + found = 1; + break; + } + } + spin_unlock(&sdp->sd_jindex_spin); + + if (!found) + jd = NULL; + + return jd; +} + +int gfs2_jdesc_check(struct gfs2_jdesc *jd) +{ + struct gfs2_inode *ip = jd->jd_inode; + struct gfs2_sbd *sdp = ip->i_sbd; + int ar; + int error; + + if (ip->i_di.di_size < (8 << 20) || + ip->i_di.di_size > (1 << 30) || + (ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1))) { + gfs2_consist_inode(ip); + return -EIO; + } + jd->jd_blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; + + error = gfs2_write_alloc_required(ip, + 0, ip->i_di.di_size, + &ar); + if (!error && ar) { + gfs2_consist_inode(ip); + error = -EIO; + } + + return error; +} + +int gfs2_lookup_master_dir(struct gfs2_sbd *sdp) +{ + struct gfs2_glock *gl; + int error; + + error = gfs2_glock_get(sdp, + sdp->sd_sb.sb_master_dir.no_addr, + &gfs2_inode_glops, CREATE, &gl); + if (!error) { + error = gfs2_inode_get(gl, &sdp->sd_sb.sb_master_dir, CREATE, + &sdp->sd_master_dir); + gfs2_glock_put(gl); + } + + return error; +} + +/** + * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one + * @sdp: the filesystem + * + * Returns: errno + */ + +int gfs2_make_fs_rw(struct gfs2_sbd *sdp) +{ + struct gfs2_glock *j_gl = sdp->sd_jdesc->jd_inode->i_gl; + struct gfs2_holder t_gh; + struct gfs2_log_header head; + int error; + + error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, + GL_LOCAL_EXCL | GL_NEVER_RECURSE, &t_gh); + if (error) + return error; + + gfs2_meta_cache_flush(sdp->sd_jdesc->jd_inode); + j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA); + + error = gfs2_find_jhead(sdp->sd_jdesc, &head); + if (error) + goto fail; + + if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { + gfs2_consist(sdp); + error = -EIO; + goto fail; + } + + /* Initialize some head of the log stuff */ + sdp->sd_log_sequence = head.lh_sequence + 1; + gfs2_log_pointers_init(sdp, head.lh_blkno); + + error = gfs2_unlinked_init(sdp); + if (error) + goto fail; + error = gfs2_quota_init(sdp); + if (error) + goto fail_unlinked; + + set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); + + gfs2_glock_dq_uninit(&t_gh); + + return 0; + + fail_unlinked: + gfs2_unlinked_cleanup(sdp); + + fail: + t_gh.gh_flags |= GL_NOCACHE; + gfs2_glock_dq_uninit(&t_gh); + + return error; +} + +/** + * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one + * @sdp: the filesystem + * + * Returns: errno + */ + +int gfs2_make_fs_ro(struct gfs2_sbd *sdp) +{ + struct gfs2_holder t_gh; + int error; + + gfs2_unlinked_dealloc(sdp); + gfs2_quota_sync(sdp); + gfs2_statfs_sync(sdp); + + error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, + GL_LOCAL_EXCL | GL_NEVER_RECURSE | GL_NOCACHE, + &t_gh); + if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) + return error; + + gfs2_meta_syncfs(sdp); + gfs2_log_shutdown(sdp); + + clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); + + if (t_gh.gh_gl) + gfs2_glock_dq_uninit(&t_gh); + + gfs2_unlinked_cleanup(sdp); + gfs2_quota_cleanup(sdp); + + return error; +} + +int gfs2_statfs_init(struct gfs2_sbd *sdp) +{ + struct gfs2_inode *m_ip = sdp->sd_statfs_inode; + struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; + struct gfs2_inode *l_ip = sdp->sd_sc_inode; + struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; + struct buffer_head *m_bh, *l_bh; + struct gfs2_holder gh; + int error; + + error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, + &gh); + if (error) + return error; + + error = gfs2_meta_inode_buffer(m_ip, &m_bh); + if (error) + goto out; + + if (sdp->sd_args.ar_spectator) { + spin_lock(&sdp->sd_statfs_spin); + gfs2_statfs_change_in(m_sc, m_bh->b_data + + sizeof(struct gfs2_dinode)); + spin_unlock(&sdp->sd_statfs_spin); + } else { + error = gfs2_meta_inode_buffer(l_ip, &l_bh); + if (error) + goto out_m_bh; + + spin_lock(&sdp->sd_statfs_spin); + gfs2_statfs_change_in(m_sc, m_bh->b_data + + sizeof(struct gfs2_dinode)); + gfs2_statfs_change_in(l_sc, l_bh->b_data + + sizeof(struct gfs2_dinode)); + spin_unlock(&sdp->sd_statfs_spin); + + brelse(l_bh); + } + + out_m_bh: + brelse(m_bh); + + out: + gfs2_glock_dq_uninit(&gh); + + return 0; +} + +void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, + int64_t dinodes) +{ + struct gfs2_inode *l_ip = sdp->sd_sc_inode; + struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; + struct buffer_head *l_bh; + int error; + + error = gfs2_meta_inode_buffer(l_ip, &l_bh); + if (error) + return; + + down(&sdp->sd_statfs_mutex); + gfs2_trans_add_bh(l_ip->i_gl, l_bh); + up(&sdp->sd_statfs_mutex); + + spin_lock(&sdp->sd_statfs_spin); + l_sc->sc_total += total; + l_sc->sc_free += free; + l_sc->sc_dinodes += dinodes; + gfs2_statfs_change_out(l_sc, l_bh->b_data + + sizeof(struct gfs2_dinode)); + spin_unlock(&sdp->sd_statfs_spin); + + brelse(l_bh); +} + +int gfs2_statfs_sync(struct gfs2_sbd *sdp) +{ + struct gfs2_inode *m_ip = sdp->sd_statfs_inode; + struct gfs2_inode *l_ip = sdp->sd_sc_inode; + struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; + struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; + struct gfs2_holder gh; + struct buffer_head *m_bh, *l_bh; + int error; + + error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, + &gh); + if (error) + return error; + + error = gfs2_meta_inode_buffer(m_ip, &m_bh); + if (error) + goto out; + + spin_lock(&sdp->sd_statfs_spin); + gfs2_statfs_change_in(m_sc, m_bh->b_data + + sizeof(struct gfs2_dinode)); + if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) { + spin_unlock(&sdp->sd_statfs_spin); + goto out_bh; + } + spin_unlock(&sdp->sd_statfs_spin); + + error = gfs2_meta_inode_buffer(l_ip, &l_bh); + if (error) + goto out_bh; + + error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0); + if (error) + goto out_bh2; + + down(&sdp->sd_statfs_mutex); + gfs2_trans_add_bh(l_ip->i_gl, l_bh); + up(&sdp->sd_statfs_mutex); + + spin_lock(&sdp->sd_statfs_spin); + m_sc->sc_total += l_sc->sc_total; + m_sc->sc_free += l_sc->sc_free; + m_sc->sc_dinodes += l_sc->sc_dinodes; + memset(l_sc, 0, sizeof(struct gfs2_statfs_change)); + memset(l_bh->b_data + sizeof(struct gfs2_dinode), + 0, sizeof(struct gfs2_statfs_change)); + spin_unlock(&sdp->sd_statfs_spin); + + gfs2_trans_add_bh(m_ip->i_gl, m_bh); + gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode)); + + gfs2_trans_end(sdp); + + out_bh2: + brelse(l_bh); + + out_bh: + brelse(m_bh); + + out: + gfs2_glock_dq_uninit(&gh); + + return error; +} + +/** + * gfs2_statfs_i - Do a statfs + * @sdp: the filesystem + * @sg: the sg structure + * + * Returns: errno + */ + +int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc) +{ + struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; + struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; + + spin_lock(&sdp->sd_statfs_spin); + + *sc = *m_sc; + sc->sc_total += l_sc->sc_total; + sc->sc_free += l_sc->sc_free; + sc->sc_dinodes += l_sc->sc_dinodes; + + spin_unlock(&sdp->sd_statfs_spin); + + if (sc->sc_free < 0) + sc->sc_free = 0; + if (sc->sc_free > sc->sc_total) + sc->sc_free = sc->sc_total; + if (sc->sc_dinodes < 0) + sc->sc_dinodes = 0; + + return 0; +} + +/** + * statfs_fill - fill in the sg for a given RG + * @rgd: the RG + * @sc: the sc structure + * + * Returns: 0 on success, -ESTALE if the LVB is invalid + */ + +static int statfs_slow_fill(struct gfs2_rgrpd *rgd, + struct gfs2_statfs_change *sc) +{ + gfs2_rgrp_verify(rgd); + sc->sc_total += rgd->rd_ri.ri_data; + sc->sc_free += rgd->rd_rg.rg_free; + sc->sc_dinodes += rgd->rd_rg.rg_dinodes; + return 0; +} + +/** + * gfs2_statfs_slow - Stat a filesystem using asynchronous locking + * @sdp: the filesystem + * @sc: the sc info that will be returned + * + * Any error (other than a signal) will cause this routine to fall back + * to the synchronous version. + * + * FIXME: This really shouldn't busy wait like this. + * + * Returns: errno + */ + +int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc) +{ + struct gfs2_holder ri_gh; + struct gfs2_rgrpd *rgd_next; + struct gfs2_holder *gha, *gh; + unsigned int slots = 64; + unsigned int x; + int done; + int error = 0, err; + + memset(sc, 0, sizeof(struct gfs2_statfs_change)); + gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL); + if (!gha) + return -ENOMEM; + + error = gfs2_rindex_hold(sdp, &ri_gh); + if (error) + goto out; + + rgd_next = gfs2_rgrpd_get_first(sdp); + + for (;;) { + done = 1; + + for (x = 0; x < slots; x++) { + gh = gha + x; + + if (gh->gh_gl && gfs2_glock_poll(gh)) { + err = gfs2_glock_wait(gh); + if (err) { + gfs2_holder_uninit(gh); + error = err; + } else { + if (!error) + error = statfs_slow_fill(get_gl2rgd(gh->gh_gl), sc); + gfs2_glock_dq_uninit(gh); + } + } + + if (gh->gh_gl) + done = 0; + else if (rgd_next && !error) { + error = gfs2_glock_nq_init(rgd_next->rd_gl, + LM_ST_SHARED, + GL_ASYNC, + gh); + rgd_next = gfs2_rgrpd_get_next(rgd_next); + done = 0; + } + + if (signal_pending(current)) + error = -ERESTARTSYS; + } + + if (done) + break; + + yield(); + } + + gfs2_glock_dq_uninit(&ri_gh); + + out: + kfree(gha); + + return error; +} + +struct lfcc { + struct list_head list; + struct gfs2_holder gh; +}; + +/** + * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all + * journals are clean + * @sdp: the file system + * @state: the state to put the transaction lock into + * @t_gh: the hold on the transaction lock + * + * Returns: errno + */ + +int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh) +{ + struct gfs2_holder ji_gh; + struct gfs2_jdesc *jd; + struct lfcc *lfcc; + LIST_HEAD(list); + struct gfs2_log_header lh; + int error; + + error = gfs2_jindex_hold(sdp, &ji_gh); + if (error) + return error; + + list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { + lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL); + if (!lfcc) { + error = -ENOMEM; + goto out; + } + error = gfs2_glock_nq_init(jd->jd_inode->i_gl, LM_ST_SHARED, 0, + &lfcc->gh); + if (error) { + kfree(lfcc); + goto out; + } + list_add(&lfcc->list, &list); + } + + error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_DEFERRED, + LM_FLAG_PRIORITY | GL_NEVER_RECURSE | GL_NOCACHE, + t_gh); + + list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { + error = gfs2_jdesc_check(jd); + if (error) + break; + error = gfs2_find_jhead(jd, &lh); + if (error) + break; + if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { + error = -EBUSY; + break; + } + } + + if (error) + gfs2_glock_dq_uninit(t_gh); + + out: + while (!list_empty(&list)) { + lfcc = list_entry(list.next, struct lfcc, list); + list_del(&lfcc->list); + gfs2_glock_dq_uninit(&lfcc->gh); + kfree(lfcc); + } + gfs2_glock_dq_uninit(&ji_gh); + + return error; +} + +/** + * gfs2_freeze_fs - freezes the file system + * @sdp: the file system + * + * This function flushes data and meta data for all machines by + * aquiring the transaction log exclusively. All journals are + * ensured to be in a clean state as well. + * + * Returns: errno + */ + +int gfs2_freeze_fs(struct gfs2_sbd *sdp) +{ + int error = 0; + + down(&sdp->sd_freeze_lock); + + if (!sdp->sd_freeze_count++) { + error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh); + if (error) + sdp->sd_freeze_count--; + } + + up(&sdp->sd_freeze_lock); + + return error; +} + +/** + * gfs2_unfreeze_fs - unfreezes the file system + * @sdp: the file system + * + * This function allows the file system to proceed by unlocking + * the exclusively held transaction lock. Other GFS2 nodes are + * now free to acquire the lock shared and go on with their lives. + * + */ + +void gfs2_unfreeze_fs(struct gfs2_sbd *sdp) +{ + down(&sdp->sd_freeze_lock); + + if (sdp->sd_freeze_count && !--sdp->sd_freeze_count) + gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); + + up(&sdp->sd_freeze_lock); +} + diff --git a/fs/gfs2/super.h b/fs/gfs2/super.h new file mode 100644 index 000000000000..cc1a3df1949a --- /dev/null +++ b/fs/gfs2/super.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __SUPER_DOT_H__ +#define __SUPER_DOT_H__ + +void gfs2_tune_init(struct gfs2_tune *gt); + +int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent); +int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent); +int gfs2_do_upgrade(struct gfs2_sbd *sdp, struct gfs2_glock *gl_sb); + +static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp) +{ + unsigned int x; + spin_lock(&sdp->sd_jindex_spin); + x = sdp->sd_journals; + spin_unlock(&sdp->sd_jindex_spin); + return x; +} + +int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh); +void gfs2_jindex_free(struct gfs2_sbd *sdp); + +struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid); +void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid); +struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp); +int gfs2_jdesc_check(struct gfs2_jdesc *jd); + +int gfs2_lookup_master_dir(struct gfs2_sbd *sdp); +int gfs2_lookup_in_master_dir(struct gfs2_sbd *sdp, char *filename, + struct gfs2_inode **ipp); + +int gfs2_make_fs_rw(struct gfs2_sbd *sdp); +int gfs2_make_fs_ro(struct gfs2_sbd *sdp); + +int gfs2_statfs_init(struct gfs2_sbd *sdp); +void gfs2_statfs_change(struct gfs2_sbd *sdp, + int64_t total, int64_t free, int64_t dinodes); +int gfs2_statfs_sync(struct gfs2_sbd *sdp); +int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc); +int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc); + +int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh); +int gfs2_freeze_fs(struct gfs2_sbd *sdp); +void gfs2_unfreeze_fs(struct gfs2_sbd *sdp); + +#endif /* __SUPER_DOT_H__ */ + diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c new file mode 100644 index 000000000000..75e9a3231b8f --- /dev/null +++ b/fs/gfs2/sys.c @@ -0,0 +1,640 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "lm.h" +#include "sys.h" +#include "super.h" +#include "glock.h" +#include "quota.h" + +char *gfs2_sys_margs; +spinlock_t gfs2_sys_margs_lock; + +static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) +{ + return sprintf(buf, "%s\n", sdp->sd_vfs->s_id); +} + +static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) +{ + return sprintf(buf, "%s\n", sdp->sd_fsname); +} + +static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) +{ + unsigned int count; + + down(&sdp->sd_freeze_lock); + count = sdp->sd_freeze_count; + up(&sdp->sd_freeze_lock); + + return sprintf(buf, "%u\n", count); +} + +static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len) +{ + ssize_t ret = len; + int error = 0; + int n = simple_strtol(buf, NULL, 0); + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + switch (n) { + case 0: + gfs2_unfreeze_fs(sdp); + break; + case 1: + error = gfs2_freeze_fs(sdp); + break; + default: + ret = -EINVAL; + } + + if (error) + fs_warn(sdp, "freeze %d error %d", n, error); + + return ret; +} + +static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf) +{ + unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags); + return sprintf(buf, "%u\n", b); +} + +static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len) +{ + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (simple_strtol(buf, NULL, 0) != 1) + return -EINVAL; + + gfs2_lm_withdraw(sdp, + "GFS2: fsid=%s: withdrawing from cluster at user's request\n", + sdp->sd_fsname); + return len; +} + +static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf, + size_t len) +{ + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (simple_strtol(buf, NULL, 0) != 1) + return -EINVAL; + + gfs2_statfs_sync(sdp); + return len; +} + +static ssize_t shrink_store(struct gfs2_sbd *sdp, const char *buf, size_t len) +{ + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (simple_strtol(buf, NULL, 0) != 1) + return -EINVAL; + + gfs2_gl_hash_clear(sdp, NO_WAIT); + return len; +} + +static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf, + size_t len) +{ + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (simple_strtol(buf, NULL, 0) != 1) + return -EINVAL; + + gfs2_quota_sync(sdp); + return len; +} + +static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, + size_t len) +{ + uint32_t id; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + id = simple_strtoul(buf, NULL, 0); + + gfs2_quota_refresh(sdp, 1, id); + return len; +} + +static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf, + size_t len) +{ + uint32_t id; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + id = simple_strtoul(buf, NULL, 0); + + gfs2_quota_refresh(sdp, 0, id); + return len; +} + +struct gfs2_attr { + struct attribute attr; + ssize_t (*show)(struct gfs2_sbd *, char *); + ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); +}; + +#define GFS2_ATTR(name, mode, show, store) \ +static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store) + +GFS2_ATTR(id, 0444, id_show, NULL); +GFS2_ATTR(fsname, 0444, fsname_show, NULL); +GFS2_ATTR(freeze, 0644, freeze_show, freeze_store); +GFS2_ATTR(shrink, 0200, NULL, shrink_store); +GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store); +GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store); +GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store); +GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store); +GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store); + +static struct attribute *gfs2_attrs[] = { + &gfs2_attr_id.attr, + &gfs2_attr_fsname.attr, + &gfs2_attr_freeze.attr, + &gfs2_attr_shrink.attr, + &gfs2_attr_withdraw.attr, + &gfs2_attr_statfs_sync.attr, + &gfs2_attr_quota_sync.attr, + &gfs2_attr_quota_refresh_user.attr, + &gfs2_attr_quota_refresh_group.attr, + NULL, +}; + +static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); + struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); + return a->show ? a->show(sdp, buf) : 0; +} + +static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t len) +{ + struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); + struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); + return a->store ? a->store(sdp, buf, len) : len; +} + +static struct sysfs_ops gfs2_attr_ops = { + .show = gfs2_attr_show, + .store = gfs2_attr_store, +}; + +static struct kobj_type gfs2_ktype = { + .default_attrs = gfs2_attrs, + .sysfs_ops = &gfs2_attr_ops, +}; + +static struct kset gfs2_kset = { + .subsys = &fs_subsys, + .kobj = {.name = "gfs2",}, + .ktype = &gfs2_ktype, +}; + +/* + * display struct lm_lockstruct fields + */ + +struct lockstruct_attr { + struct attribute attr; + ssize_t (*show)(struct gfs2_sbd *, char *); +}; + +#define LOCKSTRUCT_ATTR(name, fmt) \ +static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ +{ \ + return sprintf(buf, fmt, sdp->sd_lockstruct.ls_##name); \ +} \ +static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name) + +LOCKSTRUCT_ATTR(jid, "%u\n"); +LOCKSTRUCT_ATTR(first, "%u\n"); +LOCKSTRUCT_ATTR(lvb_size, "%u\n"); +LOCKSTRUCT_ATTR(flags, "%d\n"); + +static struct attribute *lockstruct_attrs[] = { + &lockstruct_attr_jid.attr, + &lockstruct_attr_first.attr, + &lockstruct_attr_lvb_size.attr, + &lockstruct_attr_flags.attr, + NULL +}; + +/* + * display struct gfs2_args fields + */ + +struct args_attr { + struct attribute attr; + ssize_t (*show)(struct gfs2_sbd *, char *); +}; + +#define ARGS_ATTR(name, fmt) \ +static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ +{ \ + return sprintf(buf, fmt, sdp->sd_args.ar_##name); \ +} \ +static struct args_attr args_attr_##name = __ATTR_RO(name) + +ARGS_ATTR(lockproto, "%s\n"); +ARGS_ATTR(locktable, "%s\n"); +ARGS_ATTR(hostdata, "%s\n"); +ARGS_ATTR(spectator, "%d\n"); +ARGS_ATTR(ignore_local_fs, "%d\n"); +ARGS_ATTR(localcaching, "%d\n"); +ARGS_ATTR(localflocks, "%d\n"); +ARGS_ATTR(debug, "%d\n"); +ARGS_ATTR(upgrade, "%d\n"); +ARGS_ATTR(num_glockd, "%u\n"); +ARGS_ATTR(posix_acl, "%d\n"); +ARGS_ATTR(quota, "%u\n"); +ARGS_ATTR(suiddir, "%d\n"); +ARGS_ATTR(data, "%d\n"); + +/* one oddball doesn't fit the macro mold */ +static ssize_t noatime_show(struct gfs2_sbd *sdp, char *buf) +{ + return sprintf(buf, "%d\n", !!test_bit(SDF_NOATIME, &sdp->sd_flags)); +} +static struct args_attr args_attr_noatime = __ATTR_RO(noatime); + +static struct attribute *args_attrs[] = { + &args_attr_lockproto.attr, + &args_attr_locktable.attr, + &args_attr_hostdata.attr, + &args_attr_spectator.attr, + &args_attr_ignore_local_fs.attr, + &args_attr_localcaching.attr, + &args_attr_localflocks.attr, + &args_attr_debug.attr, + &args_attr_upgrade.attr, + &args_attr_num_glockd.attr, + &args_attr_posix_acl.attr, + &args_attr_quota.attr, + &args_attr_suiddir.attr, + &args_attr_data.attr, + &args_attr_noatime.attr, + NULL +}; + +/* + * display counters from superblock + */ + +struct counters_attr { + struct attribute attr; + ssize_t (*show)(struct gfs2_sbd *, char *); +}; + +#define COUNTERS_ATTR_GENERAL(name, fmt, val) \ +static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ +{ \ + return sprintf(buf, fmt, val); \ +} \ +static struct counters_attr counters_attr_##name = __ATTR_RO(name) + +#define COUNTERS_ATTR_SIMPLE(name, fmt) \ + COUNTERS_ATTR_GENERAL(name, fmt, sdp->sd_##name) + +#define COUNTERS_ATTR_ATOMIC(name, fmt) \ + COUNTERS_ATTR_GENERAL(name, fmt, (unsigned int)atomic_read(&sdp->sd_##name)) + +COUNTERS_ATTR_ATOMIC(glock_count, "%u\n"); +COUNTERS_ATTR_ATOMIC(glock_held_count, "%u\n"); +COUNTERS_ATTR_ATOMIC(inode_count, "%u\n"); +COUNTERS_ATTR_ATOMIC(bufdata_count, "%u\n"); +COUNTERS_ATTR_ATOMIC(unlinked_count, "%u\n"); +COUNTERS_ATTR_ATOMIC(quota_count, "%u\n"); +COUNTERS_ATTR_SIMPLE(log_num_gl, "%u\n"); +COUNTERS_ATTR_SIMPLE(log_num_buf, "%u\n"); +COUNTERS_ATTR_SIMPLE(log_num_revoke, "%u\n"); +COUNTERS_ATTR_SIMPLE(log_num_rg, "%u\n"); +COUNTERS_ATTR_SIMPLE(log_num_databuf, "%u\n"); +COUNTERS_ATTR_SIMPLE(log_blks_free, "%u\n"); +COUNTERS_ATTR_GENERAL(jd_blocks, "%u\n", sdp->sd_jdesc->jd_blocks); +COUNTERS_ATTR_ATOMIC(reclaim_count, "%u\n"); +COUNTERS_ATTR_SIMPLE(log_wraps, "%llu\n"); +COUNTERS_ATTR_ATOMIC(fh2dentry_misses, "%u\n"); +COUNTERS_ATTR_ATOMIC(reclaimed, "%u\n"); +COUNTERS_ATTR_ATOMIC(log_flush_incore, "%u\n"); +COUNTERS_ATTR_ATOMIC(log_flush_ondisk, "%u\n"); +COUNTERS_ATTR_ATOMIC(glock_nq_calls, "%u\n"); +COUNTERS_ATTR_ATOMIC(glock_dq_calls, "%u\n"); +COUNTERS_ATTR_ATOMIC(glock_prefetch_calls, "%u\n"); +COUNTERS_ATTR_ATOMIC(lm_lock_calls, "%u\n"); +COUNTERS_ATTR_ATOMIC(lm_unlock_calls, "%u\n"); +COUNTERS_ATTR_ATOMIC(lm_callbacks, "%u\n"); +COUNTERS_ATTR_ATOMIC(ops_address, "%u\n"); +COUNTERS_ATTR_ATOMIC(ops_dentry, "%u\n"); +COUNTERS_ATTR_ATOMIC(ops_export, "%u\n"); +COUNTERS_ATTR_ATOMIC(ops_file, "%u\n"); +COUNTERS_ATTR_ATOMIC(ops_inode, "%u\n"); +COUNTERS_ATTR_ATOMIC(ops_super, "%u\n"); +COUNTERS_ATTR_ATOMIC(ops_vm, "%u\n"); + +static struct attribute *counters_attrs[] = { + &counters_attr_glock_count.attr, + &counters_attr_glock_held_count.attr, + &counters_attr_inode_count.attr, + &counters_attr_bufdata_count.attr, + &counters_attr_unlinked_count.attr, + &counters_attr_quota_count.attr, + &counters_attr_log_num_gl.attr, + &counters_attr_log_num_buf.attr, + &counters_attr_log_num_revoke.attr, + &counters_attr_log_num_rg.attr, + &counters_attr_log_num_databuf.attr, + &counters_attr_log_blks_free.attr, + &counters_attr_jd_blocks.attr, + &counters_attr_reclaim_count.attr, + &counters_attr_log_wraps.attr, + &counters_attr_fh2dentry_misses.attr, + &counters_attr_reclaimed.attr, + &counters_attr_log_flush_incore.attr, + &counters_attr_log_flush_ondisk.attr, + &counters_attr_glock_nq_calls.attr, + &counters_attr_glock_dq_calls.attr, + &counters_attr_glock_prefetch_calls.attr, + &counters_attr_lm_lock_calls.attr, + &counters_attr_lm_unlock_calls.attr, + &counters_attr_lm_callbacks.attr, + &counters_attr_ops_address.attr, + &counters_attr_ops_dentry.attr, + &counters_attr_ops_export.attr, + &counters_attr_ops_file.attr, + &counters_attr_ops_inode.attr, + &counters_attr_ops_super.attr, + &counters_attr_ops_vm.attr, + NULL +}; + +/* + * get and set struct gfs2_tune fields + */ + +static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf) +{ + return sprintf(buf, "%u %u\n", sdp->sd_tune.gt_quota_scale_num, + sdp->sd_tune.gt_quota_scale_den); +} + +static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf, + size_t len) +{ + struct gfs2_tune *gt = &sdp->sd_tune; + unsigned int x, y; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (sscanf(buf, "%u %u", &x, &y) != 2 || !y) + return -EINVAL; + + spin_lock(>->gt_spin); + gt->gt_quota_scale_num = x; + gt->gt_quota_scale_den = y; + spin_unlock(>->gt_spin); + return len; +} + +static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field, + int check_zero, const char *buf, size_t len) +{ + struct gfs2_tune *gt = &sdp->sd_tune; + unsigned int x; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + x = simple_strtoul(buf, NULL, 0); + + if (check_zero && !x) + return -EINVAL; + + spin_lock(>->gt_spin); + *field = x; + spin_unlock(>->gt_spin); + return len; +} + +struct tune_attr { + struct attribute attr; + ssize_t (*show)(struct gfs2_sbd *, char *); + ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); +}; + +#define TUNE_ATTR_3(name, show, store) \ +static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store) + +#define TUNE_ATTR_2(name, store) \ +static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ +{ \ + return sprintf(buf, "%u\n", sdp->sd_tune.gt_##name); \ +} \ +TUNE_ATTR_3(name, name##_show, store) + +#define TUNE_ATTR(name, check_zero) \ +static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ +{ \ + return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \ +} \ +TUNE_ATTR_2(name, name##_store) + +#define TUNE_ATTR_DAEMON(name, process) \ +static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ +{ \ + ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \ + wake_up_process(sdp->sd_##process); \ + return r; \ +} \ +TUNE_ATTR_2(name, name##_store) + +TUNE_ATTR(ilimit, 0); +TUNE_ATTR(ilimit_tries, 0); +TUNE_ATTR(ilimit_min, 0); +TUNE_ATTR(demote_secs, 0); +TUNE_ATTR(incore_log_blocks, 0); +TUNE_ATTR(log_flush_secs, 0); +TUNE_ATTR(jindex_refresh_secs, 0); +TUNE_ATTR(quota_warn_period, 0); +TUNE_ATTR(quota_quantum, 0); +TUNE_ATTR(atime_quantum, 0); +TUNE_ATTR(max_readahead, 0); +TUNE_ATTR(complain_secs, 0); +TUNE_ATTR(reclaim_limit, 0); +TUNE_ATTR(prefetch_secs, 0); +TUNE_ATTR(statfs_slow, 0); +TUNE_ATTR(new_files_jdata, 0); +TUNE_ATTR(new_files_directio, 0); +TUNE_ATTR(quota_simul_sync, 1); +TUNE_ATTR(quota_cache_secs, 1); +TUNE_ATTR(max_atomic_write, 1); +TUNE_ATTR(stall_secs, 1); +TUNE_ATTR(entries_per_readdir, 1); +TUNE_ATTR(greedy_default, 1); +TUNE_ATTR(greedy_quantum, 1); +TUNE_ATTR(greedy_max, 1); +TUNE_ATTR(statfs_quantum, 1); +TUNE_ATTR_DAEMON(scand_secs, scand_process); +TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process); +TUNE_ATTR_DAEMON(logd_secs, logd_process); +TUNE_ATTR_DAEMON(quotad_secs, quotad_process); +TUNE_ATTR_DAEMON(inoded_secs, inoded_process); +TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); + +static struct attribute *tune_attrs[] = { + &tune_attr_ilimit.attr, + &tune_attr_ilimit_tries.attr, + &tune_attr_ilimit_min.attr, + &tune_attr_demote_secs.attr, + &tune_attr_incore_log_blocks.attr, + &tune_attr_log_flush_secs.attr, + &tune_attr_jindex_refresh_secs.attr, + &tune_attr_quota_warn_period.attr, + &tune_attr_quota_quantum.attr, + &tune_attr_atime_quantum.attr, + &tune_attr_max_readahead.attr, + &tune_attr_complain_secs.attr, + &tune_attr_reclaim_limit.attr, + &tune_attr_prefetch_secs.attr, + &tune_attr_statfs_slow.attr, + &tune_attr_quota_simul_sync.attr, + &tune_attr_quota_cache_secs.attr, + &tune_attr_max_atomic_write.attr, + &tune_attr_stall_secs.attr, + &tune_attr_entries_per_readdir.attr, + &tune_attr_greedy_default.attr, + &tune_attr_greedy_quantum.attr, + &tune_attr_greedy_max.attr, + &tune_attr_statfs_quantum.attr, + &tune_attr_scand_secs.attr, + &tune_attr_recoverd_secs.attr, + &tune_attr_logd_secs.attr, + &tune_attr_quotad_secs.attr, + &tune_attr_inoded_secs.attr, + &tune_attr_quota_scale.attr, + &tune_attr_new_files_jdata.attr, + &tune_attr_new_files_directio.attr, + NULL +}; + +static struct attribute_group lockstruct_group = { + .name = "lockstruct", + .attrs = lockstruct_attrs +}; + +static struct attribute_group counters_group = { + .name = "counters", + .attrs = counters_attrs +}; + +static struct attribute_group args_group = { + .name = "args", + .attrs = args_attrs +}; + +static struct attribute_group tune_group = { + .name = "tune", + .attrs = tune_attrs +}; + +int gfs2_sys_fs_add(struct gfs2_sbd *sdp) +{ + int error; + + sdp->sd_kobj.kset = &gfs2_kset; + sdp->sd_kobj.ktype = &gfs2_ktype; + + error = kobject_set_name(&sdp->sd_kobj, "%s", sdp->sd_table_name); + if (error) + goto fail; + + error = kobject_register(&sdp->sd_kobj); + if (error) + goto fail; + + error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group); + if (error) + goto fail_reg; + + error = sysfs_create_group(&sdp->sd_kobj, &counters_group); + if (error) + goto fail_lockstruct; + + error = sysfs_create_group(&sdp->sd_kobj, &args_group); + if (error) + goto fail_counters; + + error = sysfs_create_group(&sdp->sd_kobj, &tune_group); + if (error) + goto fail_args; + + return 0; + + fail_args: + sysfs_remove_group(&sdp->sd_kobj, &args_group); + fail_counters: + sysfs_remove_group(&sdp->sd_kobj, &counters_group); + fail_lockstruct: + sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); + fail_reg: + kobject_unregister(&sdp->sd_kobj); + fail: + return error; +} + +void gfs2_sys_fs_del(struct gfs2_sbd *sdp) +{ + sysfs_remove_group(&sdp->sd_kobj, &tune_group); + sysfs_remove_group(&sdp->sd_kobj, &args_group); + sysfs_remove_group(&sdp->sd_kobj, &counters_group); + sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); + kobject_unregister(&sdp->sd_kobj); +} + +int gfs2_sys_init(void) +{ + gfs2_sys_margs = NULL; + spin_lock_init(&gfs2_sys_margs_lock); + return kset_register(&gfs2_kset); +} + +void gfs2_sys_uninit(void) +{ + kfree(gfs2_sys_margs); + kset_unregister(&gfs2_kset); +} + diff --git a/fs/gfs2/sys.h b/fs/gfs2/sys.h new file mode 100644 index 000000000000..62c8ed89ab9c --- /dev/null +++ b/fs/gfs2/sys.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __SYS_DOT_H__ +#define __SYS_DOT_H__ + +/* Allow args to be passed to GFS2 when using an initial ram disk */ +extern char *gfs2_sys_margs; +extern spinlock_t gfs2_sys_margs_lock; + +int gfs2_sys_fs_add(struct gfs2_sbd *sdp); +void gfs2_sys_fs_del(struct gfs2_sbd *sdp); + +int gfs2_sys_init(void); +void gfs2_sys_uninit(void); + +#endif /* __SYS_DOT_H__ */ + diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c new file mode 100644 index 000000000000..afa5408c0008 --- /dev/null +++ b/fs/gfs2/trans.c @@ -0,0 +1,214 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "glock.h" +#include "log.h" +#include "lops.h" +#include "meta_io.h" +#include "trans.h" + +int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, + unsigned int revokes, char *file, unsigned int line) +{ + struct gfs2_trans *tr; + int error; + + if (gfs2_assert_warn(sdp, !get_transaction) || + gfs2_assert_warn(sdp, blocks || revokes)) { + fs_warn(sdp, "(%s, %u)\n", file, line); + return -EINVAL; + } + + tr = kzalloc(sizeof(struct gfs2_trans), GFP_KERNEL); + if (!tr) + return -ENOMEM; + + tr->tr_file = file; + tr->tr_line = line; + tr->tr_blocks = blocks; + tr->tr_revokes = revokes; + tr->tr_reserved = 1; + if (blocks) + tr->tr_reserved += 1 + blocks; + if (revokes) + tr->tr_reserved += gfs2_struct2blk(sdp, revokes, + sizeof(uint64_t)); + INIT_LIST_HEAD(&tr->tr_list_buf); + + error = -ENOMEM; + tr->tr_t_gh = gfs2_holder_get(sdp->sd_trans_gl, LM_ST_SHARED, + GL_NEVER_RECURSE, GFP_KERNEL); + if (!tr->tr_t_gh) + goto fail; + + error = gfs2_glock_nq(tr->tr_t_gh); + if (error) + goto fail_holder_put; + + if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { + tr->tr_t_gh->gh_flags |= GL_NOCACHE; + error = -EROFS; + goto fail_gunlock; + } + + error = gfs2_log_reserve(sdp, tr->tr_reserved); + if (error) + goto fail_gunlock; + + set_transaction(tr); + + return 0; + + fail_gunlock: + gfs2_glock_dq(tr->tr_t_gh); + + fail_holder_put: + gfs2_holder_put(tr->tr_t_gh); + + fail: + kfree(tr); + + return error; +} + +void gfs2_trans_end(struct gfs2_sbd *sdp) +{ + struct gfs2_trans *tr; + struct gfs2_holder *t_gh; + + tr = get_transaction; + set_transaction(NULL); + + if (gfs2_assert_warn(sdp, tr)) + return; + + t_gh = tr->tr_t_gh; + tr->tr_t_gh = NULL; + + if (!tr->tr_touched) { + gfs2_log_release(sdp, tr->tr_reserved); + kfree(tr); + + gfs2_glock_dq(t_gh); + gfs2_holder_put(t_gh); + + return; + } + + if (gfs2_assert_withdraw(sdp, tr->tr_num_buf <= tr->tr_blocks)) + fs_err(sdp, "tr_num_buf = %u, tr_blocks = %u " + "tr_file = %s, tr_line = %u\n", + tr->tr_num_buf, tr->tr_blocks, + tr->tr_file, tr->tr_line); + if (gfs2_assert_withdraw(sdp, tr->tr_num_revoke <= tr->tr_revokes)) + fs_err(sdp, "tr_num_revoke = %u, tr_revokes = %u " + "tr_file = %s, tr_line = %u\n", + tr->tr_num_revoke, tr->tr_revokes, + tr->tr_file, tr->tr_line); + + gfs2_log_commit(sdp, tr); + + gfs2_glock_dq(t_gh); + gfs2_holder_put(t_gh); + + if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS) + gfs2_log_flush(sdp); +} + +void gfs2_trans_add_gl(struct gfs2_glock *gl) +{ + lops_add(gl->gl_sbd, &gl->gl_le); +} + +/** + * gfs2_trans_add_bh - Add a to-be-modified buffer to the current transaction + * @gl: the glock the buffer belongs to + * @bh: The buffer to add + * + */ + +void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + struct gfs2_bufdata *bd; + + bd = get_v2bd(bh); + if (bd) + gfs2_assert(sdp, bd->bd_gl == gl); + else { + gfs2_meta_attach_bufdata(gl, bh); + bd = get_v2bd(bh); + } + + lops_add(sdp, &bd->bd_le); +} + +void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, uint64_t blkno) +{ + struct gfs2_revoke *rv = kmalloc(sizeof(struct gfs2_revoke), + GFP_KERNEL | __GFP_NOFAIL); + lops_init_le(&rv->rv_le, &gfs2_revoke_lops); + rv->rv_blkno = blkno; + lops_add(sdp, &rv->rv_le); +} + +void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, uint64_t blkno) +{ + struct gfs2_revoke *rv; + int found = 0; + + gfs2_log_lock(sdp); + + list_for_each_entry(rv, &sdp->sd_log_le_revoke, rv_le.le_list) { + if (rv->rv_blkno == blkno) { + list_del(&rv->rv_le.le_list); + gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke); + sdp->sd_log_num_revoke--; + found = 1; + break; + } + } + + gfs2_log_unlock(sdp); + + if (found) { + kfree(rv); + get_transaction->tr_num_revoke_rm++; + } +} + +void gfs2_trans_add_rg(struct gfs2_rgrpd *rgd) +{ + lops_add(rgd->rd_sbd, &rgd->rd_le); +} + +void gfs2_trans_add_databuf(struct gfs2_sbd *sdp, struct buffer_head *bh) +{ + struct gfs2_databuf *db; + + db = get_v2db(bh); + if (!db) { + db = kmalloc(sizeof(struct gfs2_databuf), + GFP_KERNEL | __GFP_NOFAIL); + lops_init_le(&db->db_le, &gfs2_databuf_lops); + get_bh(bh); + db->db_bh = bh; + set_v2db(bh, db); + lops_add(sdp, &db->db_le); + } +} + diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h new file mode 100644 index 000000000000..ac615e9e8521 --- /dev/null +++ b/fs/gfs2/trans.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __TRANS_DOT_H__ +#define __TRANS_DOT_H__ + +#define RES_DINODE 1 +#define RES_INDIRECT 1 +#define RES_JDATA 1 +#define RES_DATA 1 +#define RES_LEAF 1 +#define RES_RG_BIT 2 +#define RES_EATTR 1 +#define RES_UNLINKED 1 +#define RES_STATFS 1 +#define RES_QUOTA 2 + +#define gfs2_trans_begin(sdp, blocks, revokes) \ +gfs2_trans_begin_i((sdp), (blocks), (revokes), __FILE__, __LINE__) + +int gfs2_trans_begin_i(struct gfs2_sbd *sdp, + unsigned int blocks, unsigned int revokes, + char *file, unsigned int line); + +void gfs2_trans_end(struct gfs2_sbd *sdp); + +void gfs2_trans_add_gl(struct gfs2_glock *gl); +void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh); +void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, uint64_t blkno); +void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, uint64_t blkno); +void gfs2_trans_add_rg(struct gfs2_rgrpd *rgd); +void gfs2_trans_add_databuf(struct gfs2_sbd *sdp, struct buffer_head *bh); + +#endif /* __TRANS_DOT_H__ */ diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c new file mode 100644 index 000000000000..4a993af58c1a --- /dev/null +++ b/fs/gfs2/unlinked.c @@ -0,0 +1,453 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "bmap.h" +#include "inode.h" +#include "meta_io.h" +#include "trans.h" +#include "unlinked.h" + +static int munge_ondisk(struct gfs2_sbd *sdp, unsigned int slot, + struct gfs2_unlinked_tag *ut) +{ + struct gfs2_inode *ip = sdp->sd_ut_inode; + unsigned int block, offset; + uint64_t dblock; + int new = 0; + struct buffer_head *bh; + int error; + + block = slot / sdp->sd_ut_per_block; + offset = slot % sdp->sd_ut_per_block; + + error = gfs2_block_map(ip, block, &new, &dblock, NULL); + if (error) + return error; + error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh); + if (error) + return error; + if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_UT)) { + error = -EIO; + goto out; + } + + down(&sdp->sd_unlinked_mutex); + gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_unlinked_tag_out(ut, bh->b_data + + sizeof(struct gfs2_meta_header) + + offset * sizeof(struct gfs2_unlinked_tag)); + up(&sdp->sd_unlinked_mutex); + + out: + brelse(bh); + + return error; +} + +static void ul_hash(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) +{ + spin_lock(&sdp->sd_unlinked_spin); + list_add(&ul->ul_list, &sdp->sd_unlinked_list); + gfs2_assert(sdp, ul->ul_count); + ul->ul_count++; + atomic_inc(&sdp->sd_unlinked_count); + spin_unlock(&sdp->sd_unlinked_spin); +} + +static void ul_unhash(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) +{ + spin_lock(&sdp->sd_unlinked_spin); + list_del_init(&ul->ul_list); + gfs2_assert(sdp, ul->ul_count > 1); + ul->ul_count--; + gfs2_assert_warn(sdp, atomic_read(&sdp->sd_unlinked_count) > 0); + atomic_dec(&sdp->sd_unlinked_count); + spin_unlock(&sdp->sd_unlinked_spin); +} + +static struct gfs2_unlinked *ul_fish(struct gfs2_sbd *sdp) +{ + struct list_head *head; + struct gfs2_unlinked *ul; + int found = 0; + + if (sdp->sd_vfs->s_flags & MS_RDONLY) + return NULL; + + spin_lock(&sdp->sd_unlinked_spin); + + head = &sdp->sd_unlinked_list; + + list_for_each_entry(ul, head, ul_list) { + if (test_bit(ULF_LOCKED, &ul->ul_flags)) + continue; + + list_move_tail(&ul->ul_list, head); + ul->ul_count++; + set_bit(ULF_LOCKED, &ul->ul_flags); + found = 1; + + break; + } + + if (!found) + ul = NULL; + + spin_unlock(&sdp->sd_unlinked_spin); + + return ul; +} + +/** + * enforce_limit - limit the number of inodes waiting to be deallocated + * @sdp: the filesystem + * + * Returns: errno + */ + +static void enforce_limit(struct gfs2_sbd *sdp) +{ + unsigned int tries = 0, min = 0; + int error; + + if (atomic_read(&sdp->sd_unlinked_count) >= + gfs2_tune_get(sdp, gt_ilimit)) { + tries = gfs2_tune_get(sdp, gt_ilimit_tries); + min = gfs2_tune_get(sdp, gt_ilimit_min); + } + + while (tries--) { + struct gfs2_unlinked *ul = ul_fish(sdp); + if (!ul) + break; + error = gfs2_inode_dealloc(sdp, ul); + gfs2_unlinked_put(sdp, ul); + + if (!error) { + if (!--min) + break; + } else if (error != 1) + break; + } +} + +static struct gfs2_unlinked *ul_alloc(struct gfs2_sbd *sdp) +{ + struct gfs2_unlinked *ul; + + ul = kzalloc(sizeof(struct gfs2_unlinked), GFP_KERNEL); + if (ul) { + INIT_LIST_HEAD(&ul->ul_list); + ul->ul_count = 1; + set_bit(ULF_LOCKED, &ul->ul_flags); + } + + return ul; +} + +int gfs2_unlinked_get(struct gfs2_sbd *sdp, struct gfs2_unlinked **ul) +{ + unsigned int c, o = 0, b; + unsigned char byte = 0; + + enforce_limit(sdp); + + *ul = ul_alloc(sdp); + if (!*ul) + return -ENOMEM; + + spin_lock(&sdp->sd_unlinked_spin); + + for (c = 0; c < sdp->sd_unlinked_chunks; c++) + for (o = 0; o < PAGE_SIZE; o++) { + byte = sdp->sd_unlinked_bitmap[c][o]; + if (byte != 0xFF) + goto found; + } + + goto fail; + + found: + for (b = 0; b < 8; b++) + if (!(byte & (1 << b))) + break; + (*ul)->ul_slot = c * (8 * PAGE_SIZE) + o * 8 + b; + + if ((*ul)->ul_slot >= sdp->sd_unlinked_slots) + goto fail; + + sdp->sd_unlinked_bitmap[c][o] |= 1 << b; + + spin_unlock(&sdp->sd_unlinked_spin); + + return 0; + + fail: + spin_unlock(&sdp->sd_unlinked_spin); + kfree(*ul); + return -ENOSPC; +} + +void gfs2_unlinked_put(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) +{ + gfs2_assert_warn(sdp, test_and_clear_bit(ULF_LOCKED, &ul->ul_flags)); + + spin_lock(&sdp->sd_unlinked_spin); + gfs2_assert(sdp, ul->ul_count); + ul->ul_count--; + if (!ul->ul_count) { + gfs2_icbit_munge(sdp, sdp->sd_unlinked_bitmap, ul->ul_slot, 0); + spin_unlock(&sdp->sd_unlinked_spin); + kfree(ul); + } else + spin_unlock(&sdp->sd_unlinked_spin); +} + +int gfs2_unlinked_ondisk_add(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) +{ + int error; + + gfs2_assert_warn(sdp, test_bit(ULF_LOCKED, &ul->ul_flags)); + gfs2_assert_warn(sdp, list_empty(&ul->ul_list)); + + error = munge_ondisk(sdp, ul->ul_slot, &ul->ul_ut); + if (!error) + ul_hash(sdp, ul); + + return error; +} + +int gfs2_unlinked_ondisk_munge(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) +{ + int error; + + gfs2_assert_warn(sdp, test_bit(ULF_LOCKED, &ul->ul_flags)); + gfs2_assert_warn(sdp, !list_empty(&ul->ul_list)); + + error = munge_ondisk(sdp, ul->ul_slot, &ul->ul_ut); + + return error; +} + +int gfs2_unlinked_ondisk_rm(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) +{ + struct gfs2_unlinked_tag ut; + int error; + + gfs2_assert_warn(sdp, test_bit(ULF_LOCKED, &ul->ul_flags)); + gfs2_assert_warn(sdp, !list_empty(&ul->ul_list)); + + memset(&ut, 0, sizeof(struct gfs2_unlinked_tag)); + + error = munge_ondisk(sdp, ul->ul_slot, &ut); + if (error) + return error; + + ul_unhash(sdp, ul); + + return 0; +} + +/** + * gfs2_unlinked_dealloc - Go through the list of inodes to be deallocated + * @sdp: the filesystem + * + * Returns: errno + */ + +int gfs2_unlinked_dealloc(struct gfs2_sbd *sdp) +{ + unsigned int hits, strikes; + int error; + + for (;;) { + hits = 0; + strikes = 0; + + for (;;) { + struct gfs2_unlinked *ul = ul_fish(sdp); + if (!ul) + return 0; + error = gfs2_inode_dealloc(sdp, ul); + gfs2_unlinked_put(sdp, ul); + + if (!error) { + hits++; + if (strikes) + strikes--; + } else if (error == 1) { + strikes++; + if (strikes >= + atomic_read(&sdp->sd_unlinked_count)) { + error = 0; + break; + } + } else + return error; + } + + if (!hits || kthread_should_stop()) + break; + + cond_resched(); + } + + return 0; +} + +int gfs2_unlinked_init(struct gfs2_sbd *sdp) +{ + struct gfs2_inode *ip = sdp->sd_ut_inode; + unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; + unsigned int x, slot = 0; + unsigned int found = 0; + uint64_t dblock; + uint32_t extlen = 0; + int error; + + if (!ip->i_di.di_size || + ip->i_di.di_size > (64 << 20) || + ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1)) { + gfs2_consist_inode(ip); + return -EIO; + } + sdp->sd_unlinked_slots = blocks * sdp->sd_ut_per_block; + sdp->sd_unlinked_chunks = DIV_RU(sdp->sd_unlinked_slots, 8 * PAGE_SIZE); + + error = -ENOMEM; + + sdp->sd_unlinked_bitmap = kcalloc(sdp->sd_unlinked_chunks, + sizeof(unsigned char *), + GFP_KERNEL); + if (!sdp->sd_unlinked_bitmap) + return error; + + for (x = 0; x < sdp->sd_unlinked_chunks; x++) { + sdp->sd_unlinked_bitmap[x] = kzalloc(PAGE_SIZE, GFP_KERNEL); + if (!sdp->sd_unlinked_bitmap[x]) + goto fail; + } + + for (x = 0; x < blocks; x++) { + struct buffer_head *bh; + unsigned int y; + + if (!extlen) { + int new = 0; + error = gfs2_block_map(ip, x, &new, &dblock, &extlen); + if (error) + goto fail; + } + gfs2_meta_ra(ip->i_gl, dblock, extlen); + error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, + &bh); + if (error) + goto fail; + error = -EIO; + if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_UT)) { + brelse(bh); + goto fail; + } + + for (y = 0; + y < sdp->sd_ut_per_block && slot < sdp->sd_unlinked_slots; + y++, slot++) { + struct gfs2_unlinked_tag ut; + struct gfs2_unlinked *ul; + + gfs2_unlinked_tag_in(&ut, bh->b_data + + sizeof(struct gfs2_meta_header) + + y * sizeof(struct gfs2_unlinked_tag)); + if (!ut.ut_inum.no_addr) + continue; + + error = -ENOMEM; + ul = ul_alloc(sdp); + if (!ul) { + brelse(bh); + goto fail; + } + ul->ul_ut = ut; + ul->ul_slot = slot; + + spin_lock(&sdp->sd_unlinked_spin); + gfs2_icbit_munge(sdp, sdp->sd_unlinked_bitmap, slot, 1); + spin_unlock(&sdp->sd_unlinked_spin); + ul_hash(sdp, ul); + + gfs2_unlinked_put(sdp, ul); + found++; + } + + brelse(bh); + dblock++; + extlen--; + } + + if (found) + fs_info(sdp, "found %u unlinked inodes\n", found); + + return 0; + + fail: + gfs2_unlinked_cleanup(sdp); + return error; +} + +/** + * gfs2_unlinked_cleanup - get rid of any extra struct gfs2_unlinked structures + * @sdp: the filesystem + * + */ + +void gfs2_unlinked_cleanup(struct gfs2_sbd *sdp) +{ + struct list_head *head = &sdp->sd_unlinked_list; + struct gfs2_unlinked *ul; + unsigned int x; + + spin_lock(&sdp->sd_unlinked_spin); + while (!list_empty(head)) { + ul = list_entry(head->next, struct gfs2_unlinked, ul_list); + + if (ul->ul_count > 1) { + list_move_tail(&ul->ul_list, head); + spin_unlock(&sdp->sd_unlinked_spin); + schedule(); + spin_lock(&sdp->sd_unlinked_spin); + continue; + } + + list_del_init(&ul->ul_list); + atomic_dec(&sdp->sd_unlinked_count); + + gfs2_assert_warn(sdp, ul->ul_count == 1); + gfs2_assert_warn(sdp, !test_bit(ULF_LOCKED, &ul->ul_flags)); + kfree(ul); + } + spin_unlock(&sdp->sd_unlinked_spin); + + gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_unlinked_count)); + + if (sdp->sd_unlinked_bitmap) { + for (x = 0; x < sdp->sd_unlinked_chunks; x++) + kfree(sdp->sd_unlinked_bitmap[x]); + kfree(sdp->sd_unlinked_bitmap); + } +} + diff --git a/fs/gfs2/unlinked.h b/fs/gfs2/unlinked.h new file mode 100644 index 000000000000..51e77f88d74f --- /dev/null +++ b/fs/gfs2/unlinked.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __UNLINKED_DOT_H__ +#define __UNLINKED_DOT_H__ + +int gfs2_unlinked_get(struct gfs2_sbd *sdp, struct gfs2_unlinked **ul); +void gfs2_unlinked_put(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); + +int gfs2_unlinked_ondisk_add(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); +int gfs2_unlinked_ondisk_munge(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); +int gfs2_unlinked_ondisk_rm(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); + +int gfs2_unlinked_dealloc(struct gfs2_sbd *sdp); + +int gfs2_unlinked_init(struct gfs2_sbd *sdp); +void gfs2_unlinked_cleanup(struct gfs2_sbd *sdp); + +#endif /* __UNLINKED_DOT_H__ */ diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c new file mode 100644 index 000000000000..74e2c62f2370 --- /dev/null +++ b/fs/gfs2/util.c @@ -0,0 +1,273 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gfs2.h" +#include "glock.h" +#include "lm.h" + +kmem_cache_t *gfs2_glock_cachep __read_mostly; +kmem_cache_t *gfs2_inode_cachep __read_mostly; +kmem_cache_t *gfs2_bufdata_cachep __read_mostly; + +uint32_t gfs2_disk_hash(const char *data, int len) +{ + return crc32_le(0xFFFFFFFF, data, len) ^ 0xFFFFFFFF; +} + +void gfs2_assert_i(struct gfs2_sbd *sdp) +{ + printk(KERN_EMERG "GFS2: fsid=%s: fatal assertion failed\n", + sdp->sd_fsname); +} + +/** + * gfs2_assert_withdraw_i - Cause the machine to withdraw if @assertion is false + * Returns: -1 if this call withdrew the machine, + * -2 if it was already withdrawn + */ + +int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion, + const char *function, char *file, unsigned int line) +{ + int me; + me = gfs2_lm_withdraw(sdp, + "GFS2: fsid=%s: fatal: assertion \"%s\" failed\n" + "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", + sdp->sd_fsname, assertion, + sdp->sd_fsname, function, file, line); + return (me) ? -1 : -2; +} + +/** + * gfs2_assert_warn_i - Print a message to the console if @assertion is false + * Returns: -1 if we printed something + * -2 if we didn't + */ + +int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, + const char *function, char *file, unsigned int line) +{ + if (time_before(jiffies, + sdp->sd_last_warning + + gfs2_tune_get(sdp, gt_complain_secs) * HZ)) + return -2; + + printk(KERN_WARNING + "GFS2: fsid=%s: warning: assertion \"%s\" failed\n" + "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", + sdp->sd_fsname, assertion, + sdp->sd_fsname, function, file, line); + + if (sdp->sd_args.ar_debug) + BUG(); + + sdp->sd_last_warning = jiffies; + + return -1; +} + +/** + * gfs2_consist_i - Flag a filesystem consistency error and withdraw + * Returns: -1 if this call withdrew the machine, + * 0 if it was already withdrawn + */ + +int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function, + char *file, unsigned int line) +{ + int rv; + rv = gfs2_lm_withdraw(sdp, + "GFS2: fsid=%s: fatal: filesystem consistency error\n" + "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", + sdp->sd_fsname, + sdp->sd_fsname, function, file, line); + return rv; +} + +/** + * gfs2_consist_inode_i - Flag an inode consistency error and withdraw + * Returns: -1 if this call withdrew the machine, + * 0 if it was already withdrawn + */ + +int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, + const char *function, char *file, unsigned int line) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + int rv; + rv = gfs2_lm_withdraw(sdp, + "GFS2: fsid=%s: fatal: filesystem consistency error\n" + "GFS2: fsid=%s: inode = %llu %llu\n" + "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", + sdp->sd_fsname, + sdp->sd_fsname, ip->i_num.no_formal_ino, ip->i_num.no_addr, + sdp->sd_fsname, function, file, line); + return rv; +} + +/** + * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw + * Returns: -1 if this call withdrew the machine, + * 0 if it was already withdrawn + */ + +int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide, + const char *function, char *file, unsigned int line) +{ + struct gfs2_sbd *sdp = rgd->rd_sbd; + int rv; + rv = gfs2_lm_withdraw(sdp, + "GFS2: fsid=%s: fatal: filesystem consistency error\n" + "GFS2: fsid=%s: RG = %llu\n" + "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", + sdp->sd_fsname, + sdp->sd_fsname, rgd->rd_ri.ri_addr, + sdp->sd_fsname, function, file, line); + return rv; +} + +/** + * gfs2_meta_check_ii - Flag a magic number consistency error and withdraw + * Returns: -1 if this call withdrew the machine, + * -2 if it was already withdrawn + */ + +int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, + const char *type, const char *function, char *file, + unsigned int line) +{ + int me; + me = gfs2_lm_withdraw(sdp, + "GFS2: fsid=%s: fatal: invalid metadata block\n" + "GFS2: fsid=%s: bh = %llu (%s)\n" + "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", + sdp->sd_fsname, + sdp->sd_fsname, (uint64_t)bh->b_blocknr, type, + sdp->sd_fsname, function, file, line); + return (me) ? -1 : -2; +} + +/** + * gfs2_metatype_check_ii - Flag a metadata type consistency error and withdraw + * Returns: -1 if this call withdrew the machine, + * -2 if it was already withdrawn + */ + +int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, + uint16_t type, uint16_t t, const char *function, + char *file, unsigned int line) +{ + int me; + me = gfs2_lm_withdraw(sdp, + "GFS2: fsid=%s: fatal: invalid metadata block\n" + "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n" + "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", + sdp->sd_fsname, + sdp->sd_fsname, (uint64_t)bh->b_blocknr, type, t, + sdp->sd_fsname, function, file, line); + return (me) ? -1 : -2; +} + +/** + * gfs2_io_error_i - Flag an I/O error and withdraw + * Returns: -1 if this call withdrew the machine, + * 0 if it was already withdrawn + */ + +int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file, + unsigned int line) +{ + int rv; + rv = gfs2_lm_withdraw(sdp, + "GFS2: fsid=%s: fatal: I/O error\n" + "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", + sdp->sd_fsname, + sdp->sd_fsname, function, file, line); + return rv; +} + +/** + * gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw + * Returns: -1 if this call withdrew the machine, + * 0 if it was already withdrawn + */ + +int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, + const char *function, char *file, unsigned int line) +{ + int rv; + rv = gfs2_lm_withdraw(sdp, + "GFS2: fsid=%s: fatal: I/O error\n" + "GFS2: fsid=%s: block = %llu\n" + "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", + sdp->sd_fsname, + sdp->sd_fsname, (uint64_t)bh->b_blocknr, + sdp->sd_fsname, function, file, line); + return rv; +} + +/** + * gfs2_add_bh_to_ub - copy a buffer up to user space + * @ub: the structure representing where to copy + * @bh: the buffer + * + * Returns: errno + */ + +int gfs2_add_bh_to_ub(struct gfs2_user_buffer *ub, struct buffer_head *bh) +{ + uint64_t blkno = bh->b_blocknr; + + if (ub->ub_count + sizeof(uint64_t) + bh->b_size > ub->ub_size) + return -ENOMEM; + + if (copy_to_user(ub->ub_data + ub->ub_count, + &blkno, + sizeof(uint64_t))) + return -EFAULT; + ub->ub_count += sizeof(uint64_t); + + if (copy_to_user(ub->ub_data + ub->ub_count, + bh->b_data, + bh->b_size)) + return -EFAULT; + ub->ub_count += bh->b_size; + + return 0; +} + +void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap, + unsigned int bit, int new_value) +{ + unsigned int c, o, b = bit; + int old_value; + + c = b / (8 * PAGE_SIZE); + b %= 8 * PAGE_SIZE; + o = b / 8; + b %= 8; + + old_value = (bitmap[c][o] & (1 << b)); + gfs2_assert_withdraw(sdp, !old_value != !new_value); + + if (new_value) + bitmap[c][o] |= 1 << b; + else + bitmap[c][o] &= ~(1 << b); +} + diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h new file mode 100644 index 000000000000..21466fe9bf43 --- /dev/null +++ b/fs/gfs2/util.h @@ -0,0 +1,180 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __UTIL_DOT_H__ +#define __UTIL_DOT_H__ + +uint32_t gfs2_disk_hash(const char *data, int len); + + +#define fs_printk(level, fs, fmt, arg...) \ + printk(level "GFS2: fsid=%s: " fmt , (fs)->sd_fsname , ## arg) + +#define fs_info(fs, fmt, arg...) \ + fs_printk(KERN_INFO , fs , fmt , ## arg) + +#define fs_warn(fs, fmt, arg...) \ + fs_printk(KERN_WARNING , fs , fmt , ## arg) + +#define fs_err(fs, fmt, arg...) \ + fs_printk(KERN_ERR, fs , fmt , ## arg) + + +void gfs2_assert_i(struct gfs2_sbd *sdp); + +#define gfs2_assert(sdp, assertion) \ +do { \ + if (unlikely(!(assertion))) { \ + gfs2_assert_i(sdp); \ + BUG(); \ + } \ +} while (0) + + +int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion, + const char *function, char *file, unsigned int line); + +#define gfs2_assert_withdraw(sdp, assertion) \ +((likely(assertion)) ? 0 : gfs2_assert_withdraw_i((sdp), #assertion, \ + __FUNCTION__, __FILE__, __LINE__)) + + +int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, + const char *function, char *file, unsigned int line); + +#define gfs2_assert_warn(sdp, assertion) \ +((likely(assertion)) ? 0 : gfs2_assert_warn_i((sdp), #assertion, \ + __FUNCTION__, __FILE__, __LINE__)) + + +int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, + const char *function, char *file, unsigned int line); + +#define gfs2_consist(sdp) \ +gfs2_consist_i((sdp), 0, __FUNCTION__, __FILE__, __LINE__) + + +int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, + const char *function, char *file, unsigned int line); + +#define gfs2_consist_inode(ip) \ +gfs2_consist_inode_i((ip), 0, __FUNCTION__, __FILE__, __LINE__) + + +int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide, + const char *function, char *file, unsigned int line); + +#define gfs2_consist_rgrpd(rgd) \ +gfs2_consist_rgrpd_i((rgd), 0, __FUNCTION__, __FILE__, __LINE__) + + +int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, + const char *type, const char *function, + char *file, unsigned int line); + +static inline int gfs2_meta_check_i(struct gfs2_sbd *sdp, + struct buffer_head *bh, + const char *function, + char *file, unsigned int line) +{ + struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; + uint32_t magic = mh->mh_magic; + magic = be32_to_cpu(magic); + if (unlikely(magic != GFS2_MAGIC)) + return gfs2_meta_check_ii(sdp, bh, "magic number", function, + file, line); + return 0; +} + +#define gfs2_meta_check(sdp, bh) \ +gfs2_meta_check_i((sdp), (bh), __FUNCTION__, __FILE__, __LINE__) + + +int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, + uint16_t type, uint16_t t, + const char *function, + char *file, unsigned int line); + +static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp, + struct buffer_head *bh, + uint16_t type, + const char *function, + char *file, unsigned int line) +{ + struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; + uint32_t magic = mh->mh_magic; + uint16_t t = mh->mh_type; + magic = be32_to_cpu(magic); + if (unlikely(magic != GFS2_MAGIC)) + return gfs2_meta_check_ii(sdp, bh, "magic number", function, + file, line); + t = be16_to_cpu(t); + if (unlikely(t != type)) + return gfs2_metatype_check_ii(sdp, bh, type, t, function, + file, line); + return 0; +} + +#define gfs2_metatype_check(sdp, bh, type) \ +gfs2_metatype_check_i((sdp), (bh), (type), __FUNCTION__, __FILE__, __LINE__) + +static inline void gfs2_metatype_set(struct buffer_head *bh, uint16_t type, + uint16_t format) +{ + struct gfs2_meta_header *mh; + mh = (struct gfs2_meta_header *)bh->b_data; + mh->mh_type = cpu_to_be16(type); + mh->mh_format = cpu_to_be16(format); +} + + +int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, + char *file, unsigned int line); + +#define gfs2_io_error(sdp) \ +gfs2_io_error_i((sdp), __FUNCTION__, __FILE__, __LINE__); + + +int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, + const char *function, char *file, unsigned int line); + +#define gfs2_io_error_bh(sdp, bh) \ +gfs2_io_error_bh_i((sdp), (bh), __FUNCTION__, __FILE__, __LINE__); + + +extern kmem_cache_t *gfs2_glock_cachep; +extern kmem_cache_t *gfs2_inode_cachep; +extern kmem_cache_t *gfs2_bufdata_cachep; + +struct gfs2_user_buffer { + char __user *ub_data; + unsigned int ub_size; + unsigned int ub_count; +}; + +int gfs2_add_bh_to_ub(struct gfs2_user_buffer *ub, struct buffer_head *bh); + +static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt, + unsigned int *p) +{ + unsigned int x; + spin_lock(>->gt_spin); + x = *p; + spin_unlock(>->gt_spin); + return x; +} + +#define gfs2_tune_get(sdp, field) \ +gfs2_tune_get_i(&(sdp)->sd_tune, &(sdp)->sd_tune.field) + +void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap, + unsigned int bit, int new_value); + +#endif /* __UTIL_DOT_H__ */ + diff --git a/include/linux/gfs2_ioctl.h b/include/linux/gfs2_ioctl.h new file mode 100644 index 000000000000..dde9840b1c30 --- /dev/null +++ b/include/linux/gfs2_ioctl.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __GFS2_IOCTL_DOT_H__ +#define __GFS2_IOCTL_DOT_H__ + +#define _GFS2C_(x) (('G' << 16) | ('2' << 8) | (x)) + +/* Ioctls implemented */ + +#define GFS2_IOCTL_IDENTIFY _GFS2C_(1) +#define GFS2_IOCTL_SUPER _GFS2C_(2) +#define GFS2_IOCTL_SETFLAGS _GFS2C_(3) +#define GFS2_IOCTL_GETFLAGS _GFS2C_(4) + +struct gfs2_ioctl { + unsigned int gi_argc; + const char **gi_argv; + + char __user *gi_data; + unsigned int gi_size; + uint64_t gi_offset; +}; + +#endif /* ___GFS2_IOCTL_DOT_H__ */ + diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h new file mode 100644 index 000000000000..213d664d495d --- /dev/null +++ b/include/linux/gfs2_ondisk.h @@ -0,0 +1,454 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __GFS2_ONDISK_DOT_H__ +#define __GFS2_ONDISK_DOT_H__ + +#define GFS2_MAGIC 0x01161970 +#define GFS2_BASIC_BLOCK 512 +#define GFS2_BASIC_BLOCK_SHIFT 9 + +/* Lock numbers of the LM_TYPE_NONDISK type */ + +#define GFS2_MOUNT_LOCK 0 +#define GFS2_LIVE_LOCK 1 +#define GFS2_TRANS_LOCK 2 +#define GFS2_RENAME_LOCK 3 + +/* Format numbers for various metadata types */ + +#define GFS2_FORMAT_NONE 0 +#define GFS2_FORMAT_SB 100 +#define GFS2_FORMAT_RG 200 +#define GFS2_FORMAT_RB 300 +#define GFS2_FORMAT_DI 400 +#define GFS2_FORMAT_IN 500 +#define GFS2_FORMAT_LF 600 +#define GFS2_FORMAT_JD 700 +#define GFS2_FORMAT_LH 800 +#define GFS2_FORMAT_LD 900 +#define GFS2_FORMAT_LB 1000 +#define GFS2_FORMAT_EA 1100 +#define GFS2_FORMAT_ED 1200 +#define GFS2_FORMAT_UT 1300 +#define GFS2_FORMAT_QC 1400 +/* These are format numbers for entities contained in files */ +#define GFS2_FORMAT_RI 1500 +#define GFS2_FORMAT_DE 1600 +#define GFS2_FORMAT_QU 1700 +/* These are part of the superblock */ +#define GFS2_FORMAT_FS 1801 +#define GFS2_FORMAT_MULTI 1900 + +/* + * An on-disk inode number + */ + +#define gfs2_inum_equal(ino1, ino2) \ + (((ino1)->no_formal_ino == (ino2)->no_formal_ino) && \ + ((ino1)->no_addr == (ino2)->no_addr)) + +struct gfs2_inum { + __be64 no_formal_ino; + __be64 no_addr; +}; + +/* + * Generic metadata head structure + * Every inplace buffer logged in the journal must start with this. + */ + +#define GFS2_METATYPE_NONE 0 +#define GFS2_METATYPE_SB 1 +#define GFS2_METATYPE_RG 2 +#define GFS2_METATYPE_RB 3 +#define GFS2_METATYPE_DI 4 +#define GFS2_METATYPE_IN 5 +#define GFS2_METATYPE_LF 6 +#define GFS2_METATYPE_JD 7 +#define GFS2_METATYPE_LH 8 +#define GFS2_METATYPE_LD 9 +#define GFS2_METATYPE_LB 10 +#define GFS2_METATYPE_EA 11 +#define GFS2_METATYPE_ED 12 +#define GFS2_METATYPE_UT 13 +#define GFS2_METATYPE_QC 14 + +struct gfs2_meta_header { + __be32 mh_magic; + __be32 mh_type; + __be64 __pad0; /* Was generation number in gfs1 */ + __be32 mh_format; + __be32 __pad1; /* Was incarnation number in gfs1 */ +}; + +/* + * super-block structure + * + * It's probably good if SIZEOF_SB <= GFS2_BASIC_BLOCK (512 bytes) + * + * Order is important, need to be able to read old superblocks to do on-disk + * version upgrades. + */ + +/* Address of superblock in GFS2 basic blocks */ +#define GFS2_SB_ADDR 128 + +/* The lock number for the superblock (must be zero) */ +#define GFS2_SB_LOCK 0 + +/* Requirement: GFS2_LOCKNAME_LEN % 8 == 0 + Includes: the fencing zero at the end */ +#define GFS2_LOCKNAME_LEN 64 + +struct gfs2_sb { + struct gfs2_meta_header sb_header; + + __be32 sb_fs_format; + __be32 sb_multihost_format; + __u32 __pad0; /* Was superblock flags in gfs1 */ + + __be32 sb_bsize; + __be32 sb_bsize_shift; + __u32 __pad1; /* Was journal segment size in gfs1 */ + + struct gfs2_inum sb_master_dir; /* Was jindex dinode in gfs1 */ + struct gfs2_inum __pad2; /* Was rindex dinode in gfs1 */ + struct gfs2_inum sb_root_dir; + + char sb_lockproto[GFS2_LOCKNAME_LEN]; + char sb_locktable[GFS2_LOCKNAME_LEN]; + /* In gfs1, quota and license dinodes followed */ +}; + +/* + * resource index structure + */ + +struct gfs2_rindex { + __be64 ri_addr; /* grp block disk address */ + __be32 ri_length; /* length of rgrp header in fs blocks */ + __u32 __pad; + + __be64 ri_data0; /* first data location */ + __be32 ri_data; /* num of data blocks in rgrp */ + + __be32 ri_bitbytes; /* number of bytes in data bitmaps */ + + __u8 ri_reserved[64]; +}; + +/* + * resource group header structure + */ + +/* Number of blocks per byte in rgrp */ +#define GFS2_NBBY 4 +#define GFS2_BIT_SIZE 2 +#define GFS2_BIT_MASK 0x00000003 + +#define GFS2_BLKST_FREE 0 +#define GFS2_BLKST_USED 1 +#define GFS2_BLKST_INVALID 2 +#define GFS2_BLKST_DINODE 3 + +#define GFS2_RGF_JOURNAL 0x00000001 +#define GFS2_RGF_METAONLY 0x00000002 +#define GFS2_RGF_DATAONLY 0x00000004 +#define GFS2_RGF_NOALLOC 0x00000008 + +struct gfs2_rgrp { + struct gfs2_meta_header rg_header; + + __be32 rg_flags; + __be32 rg_free; + __be32 rg_dinodes; + + __u8 rg_reserved[92]; /* Several fields from gfs1 now reserved */ +}; + +/* + * quota structure + */ + +struct gfs2_quota { + __be64 qu_limit; + __be64 qu_warn; + __be64 qu_value; +}; + +/* + * dinode structure + */ + +#define GFS2_MAX_META_HEIGHT 10 +#define GFS2_DIR_MAX_DEPTH 17 + +#define DT2IF(dt) (((dt) << 12) & S_IFMT) +#define IF2DT(sif) (((sif) & S_IFMT) >> 12) + +/* Dinode flags */ +#define GFS2_DIF_JDATA 0x00000001 +#define GFS2_DIF_EXHASH 0x00000002 +#define GFS2_DIF_UNUSED 0x00000004 /* only in gfs1 */ +#define GFS2_DIF_EA_INDIRECT 0x00000008 +#define GFS2_DIF_DIRECTIO 0x00000010 +#define GFS2_DIF_IMMUTABLE 0x00000020 +#define GFS2_DIF_APPENDONLY 0x00000040 +#define GFS2_DIF_NOATIME 0x00000080 +#define GFS2_DIF_SYNC 0x00000100 +#define GFS2_DIF_SYSTEM 0x00000200 /* New in gfs2 */ +#define GFS2_DIF_TRUNC_IN_PROG 0x20000000 /* New in gfs2 */ +#define GFS2_DIF_INHERIT_DIRECTIO 0x40000000 +#define GFS2_DIF_INHERIT_JDATA 0x80000000 + +struct gfs2_dinode { + struct gfs2_meta_header di_header; + + struct gfs2_inum di_num; + + __be32 di_mode; /* mode of file */ + __be32 di_uid; /* owner's user id */ + __be32 di_gid; /* owner's group id */ + __be32 di_nlink; /* number of links to this file */ + __be64 di_size; /* number of bytes in file */ + __be64 di_blocks; /* number of blocks in file */ + __be64 di_atime; /* time last accessed */ + __be64 di_mtime; /* time last modified */ + __be64 di_ctime; /* time last changed */ + __be32 di_major; /* device major number */ + __be32 di_minor; /* device minor number */ + + /* This section varies from gfs1. Padding added to align with + * remainder of dinode + */ + __be64 di_goal_meta; /* rgrp to alloc from next */ + __be64 di_goal_data; /* data block goal */ + __u32 __pad[2]; + + __be32 di_flags; /* GFS2_DIF_... */ + __be32 di_payload_format; /* GFS2_FORMAT_... */ + __u16 __pad1; /* Was ditype in gfs1 */ + __be16 di_height; /* height of metadata */ + __u32 __pad2; /* Unused incarnation number from gfs1 */ + + /* These only apply to directories */ + __u16 __pad3; /* Padding */ + __be16 di_depth; /* Number of bits in the table */ + __be32 di_entries; /* The number of entries in the directory */ + + struct gfs2_inum __pad4; /* Unused even in current gfs1 */ + + __be64 di_eattr; /* extended attribute block number */ + + __u8 di_reserved[56]; +}; + +/* + * directory structure - many of these per directory file + */ + +#define GFS2_FNAMESIZE 255 +#define GFS2_DIRENT_SIZE(name_len) ((sizeof(struct gfs2_dirent) + (name_len) + 7) & ~7) + +struct gfs2_dirent { + struct gfs2_inum de_inum; + __be32 de_hash; + __be32 de_rec_len; + __u8 de_name_len; + __u8 de_type; + __u16 __pad1; + __u32 __pad2; +}; + +/* + * Header of leaf directory nodes + */ + +struct gfs2_leaf { + struct gfs2_meta_header lf_header; + + __be16 lf_depth; /* Depth of leaf */ + __be16 lf_entries; /* Number of dirents in leaf */ + __be32 lf_dirent_format; /* Format of the dirents */ + __be64 lf_next; /* Next leaf, if overflow */ + + __u8 lf_reserved[32]; +}; + +/* + * Extended attribute header format + */ + +#define GFS2_EA_MAX_NAME_LEN 255 +#define GFS2_EA_MAX_DATA_LEN 65536 + +#define GFS2_EATYPE_UNUSED 0 +#define GFS2_EATYPE_USR 1 +#define GFS2_EATYPE_SYS 2 + +#define GFS2_EATYPE_LAST 2 +#define GFS2_EATYPE_VALID(x) ((x) <= GFS2_EATYPE_LAST) + +#define GFS2_EAFLAG_LAST 0x01 /* last ea in block */ + +struct gfs2_ea_header { + __be32 ea_rec_len; + __be32 ea_data_len; + __u8 ea_name_len; /* no NULL pointer after the string */ + __u8 ea_type; /* GFS2_EATYPE_... */ + __u8 ea_flags; /* GFS2_EAFLAG_... */ + __u8 ea_num_ptrs; + __u32 __pad; +}; + +/* + * Log header structure + */ + +#define GFS2_LOG_HEAD_UNMOUNT 0x00000001 /* log is clean */ + +struct gfs2_log_header { + struct gfs2_meta_header lh_header; + + __be64 lh_sequence; /* Sequence number of this transaction */ + __be32 lh_flags; /* GFS2_LOG_HEAD_... */ + __be32 lh_tail; /* Block number of log tail */ + __be32 lh_blkno; + __be32 lh_hash; +}; + +/* + * Log type descriptor + */ + +#define GFS2_LOG_DESC_METADATA 300 +/* ld_data1 is the number of metadata blocks in the descriptor. + ld_data2 is unused. */ + +#define GFS2_LOG_DESC_REVOKE 301 +/* ld_data1 is the number of revoke blocks in the descriptor. + ld_data2 is unused. */ + +struct gfs2_log_descriptor { + struct gfs2_meta_header ld_header; + + __be32 ld_type; /* GFS2_LOG_DESC_... */ + __be32 ld_length; /* Number of buffers in this chunk */ + __be32 ld_data1; /* descriptor-specific field */ + __be32 ld_data2; /* descriptor-specific field */ + + __u8 ld_reserved[32]; +}; + +/* + * Inum Range + * Describe a range of formal inode numbers allocated to + * one machine to assign to inodes. + */ + +#define GFS2_INUM_QUANTUM 1048576 + +struct gfs2_inum_range { + __be64 ir_start; + __be64 ir_length; +}; + +/* + * Statfs change + * Describes an change to the pool of free and allocated + * blocks. + */ + +struct gfs2_statfs_change { + __be64 sc_total; + __be64 sc_free; + __be64 sc_dinodes; +}; + +/* + * Unlinked Tag + * Describes an allocated inode that isn't linked into + * the directory tree and might need to be deallocated. + */ + +#define GFS2_UTF_UNINIT 0x00000001 + +struct gfs2_unlinked_tag { + struct gfs2_inum ut_inum; + __be32 ut_flags; /* GFS2_UTF_... */ + __u32 __pad; +}; + +/* + * Quota change + * Describes an allocation change for a particular + * user or group. + */ + +#define GFS2_QCF_USER 0x00000001 + +struct gfs2_quota_change { + __be64 qc_change; + __be32 qc_flags; /* GFS2_QCF_... */ + __be32 qc_id; +}; + +/* Translation functions */ + +extern void gfs2_inum_in(struct gfs2_inum *no, char *buf); +extern void gfs2_inum_out(struct gfs2_inum *no, char *buf); +extern void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf); +extern void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf); +extern void gfs2_sb_in(struct gfs2_sb *sb, char *buf); +extern void gfs2_sb_out(struct gfs2_sb *sb, char *buf); +extern void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf); +extern void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf); +extern void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf); +extern void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf); +extern void gfs2_quota_in(struct gfs2_quota *qu, char *buf); +extern void gfs2_quota_out(struct gfs2_quota *qu, char *buf); +extern void gfs2_dinode_in(struct gfs2_dinode *di, char *buf); +extern void gfs2_dinode_out(struct gfs2_dinode *di, char *buf); +extern void gfs2_dirent_in(struct gfs2_dirent *de, char *buf); +extern void gfs2_dirent_out(struct gfs2_dirent *de, char *buf); +extern void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf); +extern void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf); +extern void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf); +extern void gfs2_ea_header_out(struct gfs2_ea_header *ea, char *buf); +extern void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf); +extern void gfs2_inum_range_in(struct gfs2_inum_range *ir, char *buf); +extern void gfs2_inum_range_out(struct gfs2_inum_range *ir, char *buf); +extern void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, char *buf); +extern void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf); +extern void gfs2_unlinked_tag_in(struct gfs2_unlinked_tag *ut, char *buf); +extern void gfs2_unlinked_tag_out(struct gfs2_unlinked_tag *ut, char *buf); +extern void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf); +extern void gfs2_quota_change_out(struct gfs2_quota_change *qc, char *buf); + +/* Printing functions */ + +extern void gfs2_inum_print(struct gfs2_inum *no); +extern void gfs2_meta_header_print(struct gfs2_meta_header *mh); +extern void gfs2_sb_print(struct gfs2_sb *sb); +extern void gfs2_rindex_print(struct gfs2_rindex *ri); +extern void gfs2_rgrp_print(struct gfs2_rgrp *rg); +extern void gfs2_quota_print(struct gfs2_quota *qu); +extern void gfs2_dinode_print(struct gfs2_dinode *di); +extern void gfs2_dirent_print(struct gfs2_dirent *de, char *name); +extern void gfs2_leaf_print(struct gfs2_leaf *lf); +extern void gfs2_ea_header_print(struct gfs2_ea_header *ea, char *name); +extern void gfs2_log_header_print(struct gfs2_log_header *lh); +extern void gfs2_log_descriptor_print(struct gfs2_log_descriptor *ld); +extern void gfs2_inum_range_print(struct gfs2_inum_range *ir); +extern void gfs2_statfs_change_print(struct gfs2_statfs_change *sc); +extern void gfs2_unlinked_tag_print(struct gfs2_unlinked_tag *ut); +extern void gfs2_quota_change_print(struct gfs2_quota_change *qc); + +#endif /* __GFS2_ONDISK_DOT_H__ */ From 29b7998d887529eca1ef43c8ca7b278448dc983c Mon Sep 17 00:00:00 2001 From: David Teigland Date: Mon, 16 Jan 2006 16:52:38 +0000 Subject: [PATCH 005/292] [GFS2] The lock modules for GFS2 This patch contains the pluggable locking modules for GFS2. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/Makefile | 3 + fs/gfs2/locking/dlm/lock.c | 537 +++++++++++++++++++++++ fs/gfs2/locking/dlm/main.c | 58 +++ fs/gfs2/locking/dlm/mount.c | 240 ++++++++++ fs/gfs2/locking/dlm/sysfs.c | 315 +++++++++++++ fs/gfs2/locking/dlm/thread.c | 359 +++++++++++++++ fs/gfs2/locking/nolock/Makefile | 3 + fs/gfs2/locking/nolock/lock_nolock.mod.c | 44 ++ fs/gfs2/locking/nolock/main.c | 357 +++++++++++++++ 9 files changed, 1916 insertions(+) create mode 100644 fs/gfs2/locking/dlm/Makefile create mode 100644 fs/gfs2/locking/dlm/lock.c create mode 100644 fs/gfs2/locking/dlm/main.c create mode 100644 fs/gfs2/locking/dlm/mount.c create mode 100644 fs/gfs2/locking/dlm/sysfs.c create mode 100644 fs/gfs2/locking/dlm/thread.c create mode 100644 fs/gfs2/locking/nolock/Makefile create mode 100644 fs/gfs2/locking/nolock/lock_nolock.mod.c create mode 100644 fs/gfs2/locking/nolock/main.c diff --git a/fs/gfs2/locking/dlm/Makefile b/fs/gfs2/locking/dlm/Makefile new file mode 100644 index 000000000000..d3bca02f7b3e --- /dev/null +++ b/fs/gfs2/locking/dlm/Makefile @@ -0,0 +1,3 @@ +obj-$(CONFIG_GFS2_FS) += lock_dlm.o +lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o + diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c new file mode 100644 index 000000000000..daf59d504e29 --- /dev/null +++ b/fs/gfs2/locking/dlm/lock.c @@ -0,0 +1,537 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "lock_dlm.h" + +static char junk_lvb[GDLM_LVB_SIZE]; + +static void queue_complete(struct gdlm_lock *lp) +{ + struct gdlm_ls *ls = lp->ls; + + clear_bit(LFL_ACTIVE, &lp->flags); + + spin_lock(&ls->async_lock); + list_add_tail(&lp->clist, &ls->complete); + spin_unlock(&ls->async_lock); + wake_up(&ls->thread_wait); +} + +static inline void gdlm_ast(void *astarg) +{ + queue_complete((struct gdlm_lock *) astarg); +} + +static inline void gdlm_bast(void *astarg, int mode) +{ + struct gdlm_lock *lp = astarg; + struct gdlm_ls *ls = lp->ls; + + if (!mode) { + printk("lock_dlm: bast mode zero %x,%"PRIx64"\n", + lp->lockname.ln_type, lp->lockname.ln_number); + return; + } + + spin_lock(&ls->async_lock); + if (!lp->bast_mode) { + list_add_tail(&lp->blist, &ls->blocking); + lp->bast_mode = mode; + } else if (lp->bast_mode < mode) + lp->bast_mode = mode; + spin_unlock(&ls->async_lock); + wake_up(&ls->thread_wait); +} + +void gdlm_queue_delayed(struct gdlm_lock *lp) +{ + struct gdlm_ls *ls = lp->ls; + + spin_lock(&ls->async_lock); + list_add_tail(&lp->delay_list, &ls->delayed); + spin_unlock(&ls->async_lock); +} + +/* convert gfs lock-state to dlm lock-mode */ + +static int16_t make_mode(int16_t lmstate) +{ + switch (lmstate) { + case LM_ST_UNLOCKED: + return DLM_LOCK_NL; + case LM_ST_EXCLUSIVE: + return DLM_LOCK_EX; + case LM_ST_DEFERRED: + return DLM_LOCK_CW; + case LM_ST_SHARED: + return DLM_LOCK_PR; + default: + GDLM_ASSERT(0, printk("unknown LM state %d\n", lmstate);); + } +} + +/* convert dlm lock-mode to gfs lock-state */ + +int16_t gdlm_make_lmstate(int16_t dlmmode) +{ + switch (dlmmode) { + case DLM_LOCK_IV: + case DLM_LOCK_NL: + return LM_ST_UNLOCKED; + case DLM_LOCK_EX: + return LM_ST_EXCLUSIVE; + case DLM_LOCK_CW: + return LM_ST_DEFERRED; + case DLM_LOCK_PR: + return LM_ST_SHARED; + default: + GDLM_ASSERT(0, printk("unknown DLM mode %d\n", dlmmode);); + } +} + +/* verify agreement with GFS on the current lock state, NB: DLM_LOCK_NL and + DLM_LOCK_IV are both considered LM_ST_UNLOCKED by GFS. */ + +static void check_cur_state(struct gdlm_lock *lp, unsigned int cur_state) +{ + int16_t cur = make_mode(cur_state); + if (lp->cur != DLM_LOCK_IV) + GDLM_ASSERT(lp->cur == cur, printk("%d, %d\n", lp->cur, cur);); +} + +static inline unsigned int make_flags(struct gdlm_lock *lp, + unsigned int gfs_flags, + int16_t cur, int16_t req) +{ + unsigned int lkf = 0; + + if (gfs_flags & LM_FLAG_TRY) + lkf |= DLM_LKF_NOQUEUE; + + if (gfs_flags & LM_FLAG_TRY_1CB) { + lkf |= DLM_LKF_NOQUEUE; + lkf |= DLM_LKF_NOQUEUEBAST; + } + + if (gfs_flags & LM_FLAG_PRIORITY) { + lkf |= DLM_LKF_NOORDER; + lkf |= DLM_LKF_HEADQUE; + } + + if (gfs_flags & LM_FLAG_ANY) { + if (req == DLM_LOCK_PR) + lkf |= DLM_LKF_ALTCW; + else if (req == DLM_LOCK_CW) + lkf |= DLM_LKF_ALTPR; + } + + if (lp->lksb.sb_lkid != 0) { + lkf |= DLM_LKF_CONVERT; + + /* Conversion deadlock avoidance by DLM */ + + if (!test_bit(LFL_FORCE_PROMOTE, &lp->flags) && + !(lkf & DLM_LKF_NOQUEUE) && + cur > DLM_LOCK_NL && req > DLM_LOCK_NL && cur != req) + lkf |= DLM_LKF_CONVDEADLK; + } + + if (lp->lvb) + lkf |= DLM_LKF_VALBLK; + + return lkf; +} + +/* make_strname - convert GFS lock numbers to a string */ + +static inline void make_strname(struct lm_lockname *lockname, + struct gdlm_strname *str) +{ + sprintf(str->name, "%8x%16"PRIx64, lockname->ln_type, + lockname->ln_number); + str->namelen = GDLM_STRNAME_BYTES; +} + +int gdlm_create_lp(struct gdlm_ls *ls, struct lm_lockname *name, + struct gdlm_lock **lpp) +{ + struct gdlm_lock *lp; + + lp = kmalloc(sizeof(struct gdlm_lock), GFP_KERNEL); + if (!lp) + return -ENOMEM; + + memset(lp, 0, sizeof(struct gdlm_lock)); + lp->lockname = *name; + lp->ls = ls; + lp->cur = DLM_LOCK_IV; + lp->lvb = NULL; + lp->hold_null = NULL; + init_completion(&lp->ast_wait); + INIT_LIST_HEAD(&lp->clist); + INIT_LIST_HEAD(&lp->blist); + INIT_LIST_HEAD(&lp->delay_list); + + spin_lock(&ls->async_lock); + list_add(&lp->all_list, &ls->all_locks); + ls->all_locks_count++; + spin_unlock(&ls->async_lock); + + *lpp = lp; + return 0; +} + +void gdlm_delete_lp(struct gdlm_lock *lp) +{ + struct gdlm_ls *ls = lp->ls; + + spin_lock(&ls->async_lock); + if (!list_empty(&lp->clist)) + list_del_init(&lp->clist); + if (!list_empty(&lp->blist)) + list_del_init(&lp->blist); + if (!list_empty(&lp->delay_list)) + list_del_init(&lp->delay_list); + GDLM_ASSERT(!list_empty(&lp->all_list),); + list_del_init(&lp->all_list); + ls->all_locks_count--; + spin_unlock(&ls->async_lock); + + kfree(lp); +} + +int gdlm_get_lock(lm_lockspace_t *lockspace, struct lm_lockname *name, + lm_lock_t **lockp) +{ + struct gdlm_lock *lp; + int error; + + error = gdlm_create_lp((struct gdlm_ls *) lockspace, name, &lp); + + *lockp = (lm_lock_t *) lp; + return error; +} + +void gdlm_put_lock(lm_lock_t *lock) +{ + gdlm_delete_lp((struct gdlm_lock *) lock); +} + +void gdlm_do_lock(struct gdlm_lock *lp, struct dlm_range *range) +{ + struct gdlm_ls *ls = lp->ls; + struct gdlm_strname str; + int error, bast = 1; + + /* + * When recovery is in progress, delay lock requests for submission + * once recovery is done. Requests for recovery (NOEXP) and unlocks + * can pass. + */ + + if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) && + !test_bit(LFL_NOBLOCK, &lp->flags) && lp->req != DLM_LOCK_NL) { + gdlm_queue_delayed(lp); + return; + } + + /* + * Submit the actual lock request. + */ + + if (test_bit(LFL_NOBAST, &lp->flags)) + bast = 0; + + make_strname(&lp->lockname, &str); + + set_bit(LFL_ACTIVE, &lp->flags); + + log_debug("lk %x,%"PRIx64" id %x %d,%d %x", lp->lockname.ln_type, + lp->lockname.ln_number, lp->lksb.sb_lkid, + lp->cur, lp->req, lp->lkf); + + error = dlm_lock(ls->dlm_lockspace, lp->req, &lp->lksb, lp->lkf, + str.name, str.namelen, 0, gdlm_ast, (void *) lp, + bast ? gdlm_bast : NULL, range); + + if ((error == -EAGAIN) && (lp->lkf & DLM_LKF_NOQUEUE)) { + lp->lksb.sb_status = -EAGAIN; + queue_complete(lp); + error = 0; + } + + GDLM_ASSERT(!error, + printk("%s: num=%x,%"PRIx64" err=%d cur=%d req=%d lkf=%x\n", + ls->fsname, lp->lockname.ln_type, + lp->lockname.ln_number, error, lp->cur, lp->req, + lp->lkf);); +} + +void gdlm_do_unlock(struct gdlm_lock *lp) +{ + unsigned int lkf = 0; + int error; + + set_bit(LFL_DLM_UNLOCK, &lp->flags); + set_bit(LFL_ACTIVE, &lp->flags); + + if (lp->lvb) + lkf = DLM_LKF_VALBLK; + + log_debug("un %x,%"PRIx64" %x %d %x", lp->lockname.ln_type, + lp->lockname.ln_number, lp->lksb.sb_lkid, lp->cur, lkf); + + error = dlm_unlock(lp->ls->dlm_lockspace, lp->lksb.sb_lkid, lkf, + NULL, lp); + + GDLM_ASSERT(!error, + printk("%s: error=%d num=%x,%"PRIx64" lkf=%x flags=%lx\n", + lp->ls->fsname, error, lp->lockname.ln_type, + lp->lockname.ln_number, lkf, lp->flags);); +} + +unsigned int gdlm_lock(lm_lock_t *lock, unsigned int cur_state, + unsigned int req_state, unsigned int flags) +{ + struct gdlm_lock *lp = (struct gdlm_lock *) lock; + + clear_bit(LFL_DLM_CANCEL, &lp->flags); + if (flags & LM_FLAG_NOEXP) + set_bit(LFL_NOBLOCK, &lp->flags); + + check_cur_state(lp, cur_state); + lp->req = make_mode(req_state); + lp->lkf = make_flags(lp, flags, lp->cur, lp->req); + + gdlm_do_lock(lp, NULL); + return LM_OUT_ASYNC; +} + +unsigned int gdlm_unlock(lm_lock_t *lock, unsigned int cur_state) +{ + struct gdlm_lock *lp = (struct gdlm_lock *) lock; + + clear_bit(LFL_DLM_CANCEL, &lp->flags); + if (lp->cur == DLM_LOCK_IV) + return 0; + gdlm_do_unlock(lp); + return LM_OUT_ASYNC; +} + +void gdlm_cancel(lm_lock_t *lock) +{ + struct gdlm_lock *lp = (struct gdlm_lock *) lock; + struct gdlm_ls *ls = lp->ls; + int error, delay_list = 0; + + if (test_bit(LFL_DLM_CANCEL, &lp->flags)) + return; + + log_all("gdlm_cancel %x,%"PRIx64" flags %lx", + lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); + + spin_lock(&ls->async_lock); + if (!list_empty(&lp->delay_list)) { + list_del_init(&lp->delay_list); + delay_list = 1; + } + spin_unlock(&ls->async_lock); + + if (delay_list) { + set_bit(LFL_CANCEL, &lp->flags); + set_bit(LFL_ACTIVE, &lp->flags); + queue_complete(lp); + return; + } + + if (!test_bit(LFL_ACTIVE, &lp->flags) || + test_bit(LFL_DLM_UNLOCK, &lp->flags)) { + log_all("gdlm_cancel skip %x,%"PRIx64" flags %lx", + lp->lockname.ln_type, lp->lockname.ln_number, + lp->flags); + return; + } + + /* the lock is blocked in the dlm */ + + set_bit(LFL_DLM_CANCEL, &lp->flags); + set_bit(LFL_ACTIVE, &lp->flags); + + error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, DLM_LKF_CANCEL, + NULL, lp); + + log_all("gdlm_cancel rv %d %x,%"PRIx64" flags %lx", error, + lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); + + if (error == -EBUSY) + clear_bit(LFL_DLM_CANCEL, &lp->flags); +} + +int gdlm_add_lvb(struct gdlm_lock *lp) +{ + char *lvb; + + lvb = kmalloc(GDLM_LVB_SIZE, GFP_KERNEL); + if (!lvb) + return -ENOMEM; + + memset(lvb, 0, GDLM_LVB_SIZE); + + lp->lksb.sb_lvbptr = lvb; + lp->lvb = lvb; + return 0; +} + +void gdlm_del_lvb(struct gdlm_lock *lp) +{ + kfree(lp->lvb); + lp->lvb = NULL; + lp->lksb.sb_lvbptr = NULL; +} + +/* This can do a synchronous dlm request (requiring a lock_dlm thread to get + the completion) because gfs won't call hold_lvb() during a callback (from + the context of a lock_dlm thread). */ + +static int hold_null_lock(struct gdlm_lock *lp) +{ + struct gdlm_lock *lpn = NULL; + int error; + + if (lp->hold_null) { + printk("lock_dlm: lvb already held\n"); + return 0; + } + + error = gdlm_create_lp(lp->ls, &lp->lockname, &lpn); + if (error) + goto out; + + lpn->lksb.sb_lvbptr = junk_lvb; + lpn->lvb = junk_lvb; + + lpn->req = DLM_LOCK_NL; + lpn->lkf = DLM_LKF_VALBLK | DLM_LKF_EXPEDITE; + set_bit(LFL_NOBAST, &lpn->flags); + set_bit(LFL_INLOCK, &lpn->flags); + + init_completion(&lpn->ast_wait); + gdlm_do_lock(lpn, NULL); + wait_for_completion(&lpn->ast_wait); + error = lp->lksb.sb_status; + if (error) { + printk("lock_dlm: hold_null_lock dlm error %d\n", error); + gdlm_delete_lp(lpn); + lpn = NULL; + } + out: + lp->hold_null = lpn; + return error; +} + +/* This cannot do a synchronous dlm request (requiring a lock_dlm thread to get + the completion) because gfs may call unhold_lvb() during a callback (from + the context of a lock_dlm thread) which could cause a deadlock since the + other lock_dlm thread could be engaged in recovery. */ + +static void unhold_null_lock(struct gdlm_lock *lp) +{ + struct gdlm_lock *lpn = lp->hold_null; + + GDLM_ASSERT(lpn,); + lpn->lksb.sb_lvbptr = NULL; + lpn->lvb = NULL; + set_bit(LFL_UNLOCK_DELETE, &lpn->flags); + gdlm_do_unlock(lpn); + lp->hold_null = NULL; +} + +/* Acquire a NL lock because gfs requires the value block to remain + intact on the resource while the lvb is "held" even if it's holding no locks + on the resource. */ + +int gdlm_hold_lvb(lm_lock_t *lock, char **lvbp) +{ + struct gdlm_lock *lp = (struct gdlm_lock *) lock; + int error; + + error = gdlm_add_lvb(lp); + if (error) + return error; + + *lvbp = lp->lvb; + + error = hold_null_lock(lp); + if (error) + gdlm_del_lvb(lp); + + return error; +} + +void gdlm_unhold_lvb(lm_lock_t *lock, char *lvb) +{ + struct gdlm_lock *lp = (struct gdlm_lock *) lock; + + unhold_null_lock(lp); + gdlm_del_lvb(lp); +} + +void gdlm_sync_lvb(lm_lock_t *lock, char *lvb) +{ + struct gdlm_lock *lp = (struct gdlm_lock *) lock; + + if (lp->cur != DLM_LOCK_EX) + return; + + init_completion(&lp->ast_wait); + set_bit(LFL_SYNC_LVB, &lp->flags); + + lp->req = DLM_LOCK_EX; + lp->lkf = make_flags(lp, 0, lp->cur, lp->req); + + gdlm_do_lock(lp, NULL); + wait_for_completion(&lp->ast_wait); +} + +void gdlm_submit_delayed(struct gdlm_ls *ls) +{ + struct gdlm_lock *lp, *safe; + + spin_lock(&ls->async_lock); + list_for_each_entry_safe(lp, safe, &ls->delayed, delay_list) { + list_del_init(&lp->delay_list); + list_add_tail(&lp->delay_list, &ls->submit); + } + spin_unlock(&ls->async_lock); + wake_up(&ls->thread_wait); +} + +int gdlm_release_all_locks(struct gdlm_ls *ls) +{ + struct gdlm_lock *lp, *safe; + int count = 0; + + spin_lock(&ls->async_lock); + list_for_each_entry_safe(lp, safe, &ls->all_locks, all_list) { + list_del_init(&lp->all_list); + + if (lp->lvb && lp->lvb != junk_lvb) + kfree(lp->lvb); + kfree(lp); + count++; + } + spin_unlock(&ls->async_lock); + + return count; +} + diff --git a/fs/gfs2/locking/dlm/main.c b/fs/gfs2/locking/dlm/main.c new file mode 100644 index 000000000000..3ced92ef1b19 --- /dev/null +++ b/fs/gfs2/locking/dlm/main.c @@ -0,0 +1,58 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include + +#include "lock_dlm.h" + +extern int gdlm_drop_count; +extern int gdlm_drop_period; + +extern struct lm_lockops gdlm_ops; + +int __init init_lock_dlm(void) +{ + int error; + + error = lm_register_proto(&gdlm_ops); + if (error) { + printk("lock_dlm: can't register protocol: %d\n", error); + return error; + } + + error = gdlm_sysfs_init(); + if (error) { + lm_unregister_proto(&gdlm_ops); + return error; + } + + gdlm_drop_count = GDLM_DROP_COUNT; + gdlm_drop_period = GDLM_DROP_PERIOD; + + printk("Lock_DLM (built %s %s) installed\n", __DATE__, __TIME__); + return 0; +} + +void __exit exit_lock_dlm(void) +{ + lm_unregister_proto(&gdlm_ops); + gdlm_sysfs_exit(); +} + +module_init(init_lock_dlm); +module_exit(exit_lock_dlm); + +MODULE_DESCRIPTION("GFS DLM Locking Module"); +MODULE_AUTHOR("Red Hat, Inc."); +MODULE_LICENSE("GPL"); + diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c new file mode 100644 index 000000000000..92b1789deb89 --- /dev/null +++ b/fs/gfs2/locking/dlm/mount.c @@ -0,0 +1,240 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "lock_dlm.h" + +int gdlm_drop_count; +int gdlm_drop_period; +struct lm_lockops gdlm_ops; + + +static struct gdlm_ls *init_gdlm(lm_callback_t cb, lm_fsdata_t *fsdata, + int flags, char *table_name) +{ + struct gdlm_ls *ls; + char buf[256], *p; + + ls = kmalloc(sizeof(struct gdlm_ls), GFP_KERNEL); + if (!ls) + return NULL; + + memset(ls, 0, sizeof(struct gdlm_ls)); + + ls->drop_locks_count = gdlm_drop_count; + ls->drop_locks_period = gdlm_drop_period; + + ls->fscb = cb; + ls->fsdata = fsdata; + ls->fsflags = flags; + + spin_lock_init(&ls->async_lock); + + INIT_LIST_HEAD(&ls->complete); + INIT_LIST_HEAD(&ls->blocking); + INIT_LIST_HEAD(&ls->delayed); + INIT_LIST_HEAD(&ls->submit); + INIT_LIST_HEAD(&ls->all_locks); + + init_waitqueue_head(&ls->thread_wait); + init_waitqueue_head(&ls->wait_control); + ls->thread1 = NULL; + ls->thread2 = NULL; + ls->drop_time = jiffies; + ls->jid = -1; + + strncpy(buf, table_name, 256); + buf[255] = '\0'; + + p = strstr(buf, ":"); + if (!p) { + printk("lock_dlm: invalid table_name \"%s\"\n", table_name); + kfree(ls); + return NULL; + } + *p = '\0'; + p++; + + strncpy(ls->clustername, buf, 128); + strncpy(ls->fsname, p, 128); + + return ls; +} + +static int gdlm_mount(char *table_name, char *host_data, + lm_callback_t cb, lm_fsdata_t *fsdata, + unsigned int min_lvb_size, int flags, + struct lm_lockstruct *lockstruct) +{ + struct gdlm_ls *ls; + int error = -ENOMEM; + + if (min_lvb_size > GDLM_LVB_SIZE) + goto out; + + ls = init_gdlm(cb, fsdata, flags, table_name); + if (!ls) + goto out; + + error = gdlm_init_threads(ls); + if (error) + goto out_free; + + error = dlm_new_lockspace(ls->fsname, strlen(ls->fsname), + &ls->dlm_lockspace, 0, GDLM_LVB_SIZE); + if (error) { + printk("lock_dlm: dlm_new_lockspace error %d\n", error); + goto out_thread; + } + + error = gdlm_kobject_setup(ls); + if (error) + goto out_dlm; + kobject_uevent(&ls->kobj, KOBJ_MOUNT, NULL); + + /* Now we depend on userspace to notice the new mount, + join the appropriate group, and do a write to our sysfs + "mounted" or "terminate" file. Before the start, userspace + must set "jid" and "first". */ + + error = wait_event_interruptible(ls->wait_control, + test_bit(DFL_JOIN_DONE, &ls->flags)); + if (error) + goto out_sysfs; + + if (test_bit(DFL_TERMINATE, &ls->flags)) { + error = -ERESTARTSYS; + goto out_sysfs; + } + + lockstruct->ls_jid = ls->jid; + lockstruct->ls_first = ls->first; + lockstruct->ls_lockspace = ls; + lockstruct->ls_ops = &gdlm_ops; + lockstruct->ls_flags = 0; + lockstruct->ls_lvb_size = GDLM_LVB_SIZE; + return 0; + + out_sysfs: + gdlm_kobject_release(ls); + out_dlm: + dlm_release_lockspace(ls->dlm_lockspace, 2); + out_thread: + gdlm_release_threads(ls); + out_free: + kfree(ls); + out: + return error; +} + +static void gdlm_unmount(lm_lockspace_t *lockspace) +{ + struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + int rv; + + log_debug("unmount flags %lx", ls->flags); + + if (test_bit(DFL_WITHDRAW, &ls->flags)) { + gdlm_kobject_release(ls); + goto out; + } + + kobject_uevent(&ls->kobj, KOBJ_UMOUNT, NULL); + + wait_event_interruptible(ls->wait_control, + test_bit(DFL_LEAVE_DONE, &ls->flags)); + + gdlm_kobject_release(ls); + dlm_release_lockspace(ls->dlm_lockspace, 2); + gdlm_release_threads(ls); + rv = gdlm_release_all_locks(ls); + if (rv) + log_all("lm_dlm_unmount: %d stray locks freed", rv); + out: + kfree(ls); +} + +static void gdlm_recovery_done(lm_lockspace_t *lockspace, unsigned int jid, + unsigned int message) +{ + struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + ls->recover_done = jid; + kobject_uevent(&ls->kobj, KOBJ_CHANGE, NULL); +} + +static void gdlm_others_may_mount(lm_lockspace_t *lockspace) +{ + struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + ls->first_done = 1; + kobject_uevent(&ls->kobj, KOBJ_CHANGE, NULL); +} + +static void gdlm_withdraw(lm_lockspace_t *lockspace) +{ + struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + + /* userspace suspends locking on all other members */ + + kobject_uevent(&ls->kobj, KOBJ_OFFLINE, NULL); + + wait_event_interruptible(ls->wait_control, + test_bit(DFL_WITHDRAW, &ls->flags)); + + dlm_release_lockspace(ls->dlm_lockspace, 2); + gdlm_release_threads(ls); + gdlm_release_all_locks(ls); + + kobject_uevent(&ls->kobj, KOBJ_UMOUNT, NULL); + + /* userspace leaves the mount group, we don't need to wait for + that to complete */ +} + +int gdlm_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, + struct file *file, struct file_lock *fl) +{ + return -ENOSYS; +} + +int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, + struct file *file, struct file_lock *fl) +{ + return -ENOSYS; +} + +int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, + struct file *file, int cmd, struct file_lock *fl) +{ + return -ENOSYS; +} + +struct lm_lockops gdlm_ops = { + lm_proto_name:"lock_dlm", + lm_mount:gdlm_mount, + lm_others_may_mount:gdlm_others_may_mount, + lm_unmount:gdlm_unmount, + lm_withdraw:gdlm_withdraw, + lm_get_lock:gdlm_get_lock, + lm_put_lock:gdlm_put_lock, + lm_lock:gdlm_lock, + lm_unlock:gdlm_unlock, + lm_plock:gdlm_plock, + lm_punlock:gdlm_punlock, + lm_plock_get:gdlm_plock_get, + lm_cancel:gdlm_cancel, + lm_hold_lvb:gdlm_hold_lvb, + lm_unhold_lvb:gdlm_unhold_lvb, + lm_sync_lvb:gdlm_sync_lvb, + lm_recovery_done:gdlm_recovery_done, + lm_owner:THIS_MODULE, +}; + diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c new file mode 100644 index 000000000000..8964733f55e4 --- /dev/null +++ b/fs/gfs2/locking/dlm/sysfs.c @@ -0,0 +1,315 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include +#include + +#include "lock_dlm.h" + +static ssize_t gdlm_block_show(struct gdlm_ls *ls, char *buf) +{ + ssize_t ret; + int val = 0; + + if (test_bit(DFL_BLOCK_LOCKS, &ls->flags)) + val = 1; + ret = sprintf(buf, "%d\n", val); + return ret; +} + +static ssize_t gdlm_block_store(struct gdlm_ls *ls, const char *buf, size_t len) +{ + ssize_t ret = len; + int val; + + val = simple_strtol(buf, NULL, 0); + + if (val == 1) + set_bit(DFL_BLOCK_LOCKS, &ls->flags); + else if (val == 0) { + clear_bit(DFL_BLOCK_LOCKS, &ls->flags); + gdlm_submit_delayed(ls); + } else + ret = -EINVAL; + return ret; +} + +static ssize_t gdlm_mounted_show(struct gdlm_ls *ls, char *buf) +{ + ssize_t ret; + int val = -2; + + if (test_bit(DFL_TERMINATE, &ls->flags)) + val = -1; + else if (test_bit(DFL_LEAVE_DONE, &ls->flags)) + val = 0; + else if (test_bit(DFL_JOIN_DONE, &ls->flags)) + val = 1; + ret = sprintf(buf, "%d\n", val); + return ret; +} + +static ssize_t gdlm_mounted_store(struct gdlm_ls *ls, const char *buf, size_t len) +{ + ssize_t ret = len; + int val; + + val = simple_strtol(buf, NULL, 0); + + if (val == 1) + set_bit(DFL_JOIN_DONE, &ls->flags); + else if (val == 0) + set_bit(DFL_LEAVE_DONE, &ls->flags); + else if (val == -1) { + set_bit(DFL_TERMINATE, &ls->flags); + set_bit(DFL_JOIN_DONE, &ls->flags); + set_bit(DFL_LEAVE_DONE, &ls->flags); + } else + ret = -EINVAL; + wake_up(&ls->wait_control); + return ret; +} + +static ssize_t gdlm_withdraw_show(struct gdlm_ls *ls, char *buf) +{ + ssize_t ret; + int val = 0; + + if (test_bit(DFL_WITHDRAW, &ls->flags)) + val = 1; + ret = sprintf(buf, "%d\n", val); + return ret; +} + +static ssize_t gdlm_withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len) +{ + ssize_t ret = len; + int val; + + val = simple_strtol(buf, NULL, 0); + + if (val == 1) + set_bit(DFL_WITHDRAW, &ls->flags); + else + ret = -EINVAL; + wake_up(&ls->wait_control); + return ret; +} + +static ssize_t gdlm_jid_show(struct gdlm_ls *ls, char *buf) +{ + return sprintf(buf, "%u\n", ls->jid); +} + +static ssize_t gdlm_jid_store(struct gdlm_ls *ls, const char *buf, size_t len) +{ + ls->jid = simple_strtol(buf, NULL, 0); + return len; +} + +static ssize_t gdlm_first_show(struct gdlm_ls *ls, char *buf) +{ + return sprintf(buf, "%u\n", ls->first); +} + +static ssize_t gdlm_first_store(struct gdlm_ls *ls, const char *buf, size_t len) +{ + ls->first = simple_strtol(buf, NULL, 0); + return len; +} + +static ssize_t gdlm_first_done_show(struct gdlm_ls *ls, char *buf) +{ + return sprintf(buf, "%d\n", ls->first_done); +} + +static ssize_t gdlm_recover_show(struct gdlm_ls *ls, char *buf) +{ + return sprintf(buf, "%u\n", ls->recover_jid); +} + +static ssize_t gdlm_recover_store(struct gdlm_ls *ls, const char *buf, size_t len) +{ + ls->recover_jid = simple_strtol(buf, NULL, 0); + ls->fscb(ls->fsdata, LM_CB_NEED_RECOVERY, &ls->recover_jid); + return len; +} + +static ssize_t gdlm_recover_done_show(struct gdlm_ls *ls, char *buf) +{ + ssize_t ret; + ret = sprintf(buf, "%d\n", ls->recover_done); + return ret; +} + +static ssize_t gdlm_cluster_show(struct gdlm_ls *ls, char *buf) +{ + ssize_t ret; + ret = sprintf(buf, "%s\n", ls->clustername); + return ret; +} + +static ssize_t gdlm_options_show(struct gdlm_ls *ls, char *buf) +{ + ssize_t ret = 0; + + if (ls->fsflags & LM_MFLAG_SPECTATOR) + ret += sprintf(buf, "spectator "); + + return ret; +} + +struct gdlm_attr { + struct attribute attr; + ssize_t (*show)(struct gdlm_ls *, char *); + ssize_t (*store)(struct gdlm_ls *, const char *, size_t); +}; + +static struct gdlm_attr gdlm_attr_block = { + .attr = {.name = "block", .mode = S_IRUGO | S_IWUSR}, + .show = gdlm_block_show, + .store = gdlm_block_store +}; + +static struct gdlm_attr gdlm_attr_mounted = { + .attr = {.name = "mounted", .mode = S_IRUGO | S_IWUSR}, + .show = gdlm_mounted_show, + .store = gdlm_mounted_store +}; + +static struct gdlm_attr gdlm_attr_withdraw = { + .attr = {.name = "withdraw", .mode = S_IRUGO | S_IWUSR}, + .show = gdlm_withdraw_show, + .store = gdlm_withdraw_store +}; + +static struct gdlm_attr gdlm_attr_jid = { + .attr = {.name = "jid", .mode = S_IRUGO | S_IWUSR}, + .show = gdlm_jid_show, + .store = gdlm_jid_store +}; + +static struct gdlm_attr gdlm_attr_first = { + .attr = {.name = "first", .mode = S_IRUGO | S_IWUSR}, + .show = gdlm_first_show, + .store = gdlm_first_store +}; + +static struct gdlm_attr gdlm_attr_first_done = { + .attr = {.name = "first_done", .mode = S_IRUGO}, + .show = gdlm_first_done_show, +}; + +static struct gdlm_attr gdlm_attr_recover = { + .attr = {.name = "recover", .mode = S_IRUGO | S_IWUSR}, + .show = gdlm_recover_show, + .store = gdlm_recover_store +}; + +static struct gdlm_attr gdlm_attr_recover_done = { + .attr = {.name = "recover_done", .mode = S_IRUGO | S_IWUSR}, + .show = gdlm_recover_done_show, +}; + +static struct gdlm_attr gdlm_attr_cluster = { + .attr = {.name = "cluster", .mode = S_IRUGO | S_IWUSR}, + .show = gdlm_cluster_show, +}; + +static struct gdlm_attr gdlm_attr_options = { + .attr = {.name = "options", .mode = S_IRUGO | S_IWUSR}, + .show = gdlm_options_show, +}; + +static struct attribute *gdlm_attrs[] = { + &gdlm_attr_block.attr, + &gdlm_attr_mounted.attr, + &gdlm_attr_withdraw.attr, + &gdlm_attr_jid.attr, + &gdlm_attr_first.attr, + &gdlm_attr_first_done.attr, + &gdlm_attr_recover.attr, + &gdlm_attr_recover_done.attr, + &gdlm_attr_cluster.attr, + &gdlm_attr_options.attr, + NULL, +}; + +static ssize_t gdlm_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj); + struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr); + return a->show ? a->show(ls, buf) : 0; +} + +static ssize_t gdlm_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t len) +{ + struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj); + struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr); + return a->store ? a->store(ls, buf, len) : len; +} + +static struct sysfs_ops gdlm_attr_ops = { + .show = gdlm_attr_show, + .store = gdlm_attr_store, +}; + +static struct kobj_type gdlm_ktype = { + .default_attrs = gdlm_attrs, + .sysfs_ops = &gdlm_attr_ops, +}; + +static struct kset gdlm_kset = { + .subsys = &kernel_subsys, + .kobj = {.name = "lock_dlm",}, + .ktype = &gdlm_ktype, +}; + +int gdlm_kobject_setup(struct gdlm_ls *ls) +{ + int error; + + error = kobject_set_name(&ls->kobj, "%s", ls->fsname); + if (error) + return error; + + ls->kobj.kset = &gdlm_kset; + ls->kobj.ktype = &gdlm_ktype; + + error = kobject_register(&ls->kobj); + + return 0; +} + +void gdlm_kobject_release(struct gdlm_ls *ls) +{ + kobject_unregister(&ls->kobj); +} + +int gdlm_sysfs_init(void) +{ + int error; + + error = kset_register(&gdlm_kset); + if (error) + printk("lock_dlm: cannot register kset %d\n", error); + + return error; +} + +void gdlm_sysfs_exit(void) +{ + kset_unregister(&gdlm_kset); +} + diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c new file mode 100644 index 000000000000..22bbe6d3a5ae --- /dev/null +++ b/fs/gfs2/locking/dlm/thread.c @@ -0,0 +1,359 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "lock_dlm.h" + +/* A lock placed on this queue is re-submitted to DLM as soon as the lock_dlm + thread gets to it. */ + +static void queue_submit(struct gdlm_lock *lp) +{ + struct gdlm_ls *ls = lp->ls; + + spin_lock(&ls->async_lock); + list_add_tail(&lp->delay_list, &ls->submit); + spin_unlock(&ls->async_lock); + wake_up(&ls->thread_wait); +} + +static void process_submit(struct gdlm_lock *lp) +{ + gdlm_do_lock(lp, NULL); +} + +static void process_blocking(struct gdlm_lock *lp, int bast_mode) +{ + struct gdlm_ls *ls = lp->ls; + unsigned int cb; + + switch (gdlm_make_lmstate(bast_mode)) { + case LM_ST_EXCLUSIVE: + cb = LM_CB_NEED_E; + break; + case LM_ST_DEFERRED: + cb = LM_CB_NEED_D; + break; + case LM_ST_SHARED: + cb = LM_CB_NEED_S; + break; + default: + GDLM_ASSERT(0, printk("unknown bast mode %u\n",lp->bast_mode);); + } + + ls->fscb(ls->fsdata, cb, &lp->lockname); +} + +static void process_complete(struct gdlm_lock *lp) +{ + struct gdlm_ls *ls = lp->ls; + struct lm_async_cb acb; + int16_t prev_mode = lp->cur; + + memset(&acb, 0, sizeof(acb)); + + if (lp->lksb.sb_status == -DLM_ECANCEL) { + log_all("complete dlm cancel %x,%"PRIx64" flags %lx", + lp->lockname.ln_type, lp->lockname.ln_number, + lp->flags); + + lp->req = lp->cur; + acb.lc_ret |= LM_OUT_CANCELED; + if (lp->cur == DLM_LOCK_IV) + lp->lksb.sb_lkid = 0; + goto out; + } + + if (test_and_clear_bit(LFL_DLM_UNLOCK, &lp->flags)) { + if (lp->lksb.sb_status != -DLM_EUNLOCK) { + log_all("unlock sb_status %d %x,%"PRIx64" flags %lx", + lp->lksb.sb_status, lp->lockname.ln_type, + lp->lockname.ln_number, lp->flags); + return; + } + + lp->cur = DLM_LOCK_IV; + lp->req = DLM_LOCK_IV; + lp->lksb.sb_lkid = 0; + + if (test_and_clear_bit(LFL_UNLOCK_DELETE, &lp->flags)) { + gdlm_delete_lp(lp); + return; + } + goto out; + } + + if (lp->lksb.sb_flags & DLM_SBF_VALNOTVALID) + memset(lp->lksb.sb_lvbptr, 0, GDLM_LVB_SIZE); + + if (lp->lksb.sb_flags & DLM_SBF_ALTMODE) { + if (lp->req == DLM_LOCK_PR) + lp->req = DLM_LOCK_CW; + else if (lp->req == DLM_LOCK_CW) + lp->req = DLM_LOCK_PR; + } + + /* + * A canceled lock request. The lock was just taken off the delayed + * list and was never even submitted to dlm. + */ + + if (test_and_clear_bit(LFL_CANCEL, &lp->flags)) { + log_all("complete internal cancel %x,%"PRIx64"", + lp->lockname.ln_type, lp->lockname.ln_number); + lp->req = lp->cur; + acb.lc_ret |= LM_OUT_CANCELED; + goto out; + } + + /* + * An error occured. + */ + + if (lp->lksb.sb_status) { + /* a "normal" error */ + if ((lp->lksb.sb_status == -EAGAIN) && + (lp->lkf & DLM_LKF_NOQUEUE)) { + lp->req = lp->cur; + if (lp->cur == DLM_LOCK_IV) + lp->lksb.sb_lkid = 0; + goto out; + } + + /* this could only happen with cancels I think */ + log_all("ast sb_status %d %x,%"PRIx64" flags %lx", + lp->lksb.sb_status, lp->lockname.ln_type, + lp->lockname.ln_number, lp->flags); + return; + } + + /* + * This is an AST for an EX->EX conversion for sync_lvb from GFS. + */ + + if (test_and_clear_bit(LFL_SYNC_LVB, &lp->flags)) { + complete(&lp->ast_wait); + return; + } + + /* + * A lock has been demoted to NL because it initially completed during + * BLOCK_LOCKS. Now it must be requested in the originally requested + * mode. + */ + + if (test_and_clear_bit(LFL_REREQUEST, &lp->flags)) { + GDLM_ASSERT(lp->req == DLM_LOCK_NL,); + GDLM_ASSERT(lp->prev_req > DLM_LOCK_NL,); + + lp->cur = DLM_LOCK_NL; + lp->req = lp->prev_req; + lp->prev_req = DLM_LOCK_IV; + lp->lkf &= ~DLM_LKF_CONVDEADLK; + + set_bit(LFL_NOCACHE, &lp->flags); + + if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) && + !test_bit(LFL_NOBLOCK, &lp->flags)) + gdlm_queue_delayed(lp); + else + queue_submit(lp); + return; + } + + /* + * A request is granted during dlm recovery. It may be granted + * because the locks of a failed node were cleared. In that case, + * there may be inconsistent data beneath this lock and we must wait + * for recovery to complete to use it. When gfs recovery is done this + * granted lock will be converted to NL and then reacquired in this + * granted state. + */ + + if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) && + !test_bit(LFL_NOBLOCK, &lp->flags) && + lp->req != DLM_LOCK_NL) { + + lp->cur = lp->req; + lp->prev_req = lp->req; + lp->req = DLM_LOCK_NL; + lp->lkf |= DLM_LKF_CONVERT; + lp->lkf &= ~DLM_LKF_CONVDEADLK; + + log_debug("rereq %x,%"PRIx64" id %x %d,%d", + lp->lockname.ln_type, lp->lockname.ln_number, + lp->lksb.sb_lkid, lp->cur, lp->req); + + set_bit(LFL_REREQUEST, &lp->flags); + queue_submit(lp); + return; + } + + /* + * DLM demoted the lock to NL before it was granted so GFS must be + * told it cannot cache data for this lock. + */ + + if (lp->lksb.sb_flags & DLM_SBF_DEMOTED) + set_bit(LFL_NOCACHE, &lp->flags); + + out: + /* + * This is an internal lock_dlm lock + */ + + if (test_bit(LFL_INLOCK, &lp->flags)) { + clear_bit(LFL_NOBLOCK, &lp->flags); + lp->cur = lp->req; + complete(&lp->ast_wait); + return; + } + + /* + * Normal completion of a lock request. Tell GFS it now has the lock. + */ + + clear_bit(LFL_NOBLOCK, &lp->flags); + lp->cur = lp->req; + + acb.lc_name = lp->lockname; + acb.lc_ret |= gdlm_make_lmstate(lp->cur); + + if (!test_and_clear_bit(LFL_NOCACHE, &lp->flags) && + (lp->cur > DLM_LOCK_NL) && (prev_mode > DLM_LOCK_NL)) + acb.lc_ret |= LM_OUT_CACHEABLE; + + ls->fscb(ls->fsdata, LM_CB_ASYNC, &acb); +} + +static inline int no_work(struct gdlm_ls *ls, int blocking) +{ + int ret; + + spin_lock(&ls->async_lock); + ret = list_empty(&ls->complete) && list_empty(&ls->submit); + if (ret && blocking) + ret = list_empty(&ls->blocking); + spin_unlock(&ls->async_lock); + + return ret; +} + +static inline int check_drop(struct gdlm_ls *ls) +{ + if (!ls->drop_locks_count) + return 0; + + if (time_after(jiffies, ls->drop_time + ls->drop_locks_period * HZ)) { + ls->drop_time = jiffies; + if (ls->all_locks_count >= ls->drop_locks_count) + return 1; + } + return 0; +} + +static int gdlm_thread(void *data) +{ + struct gdlm_ls *ls = (struct gdlm_ls *) data; + struct gdlm_lock *lp = NULL; + int blist = 0; + uint8_t complete, blocking, submit, drop; + DECLARE_WAITQUEUE(wait, current); + + /* Only thread1 is allowed to do blocking callbacks since gfs + may wait for a completion callback within a blocking cb. */ + + if (current == ls->thread1) + blist = 1; + + while (!kthread_should_stop()) { + set_current_state(TASK_INTERRUPTIBLE); + add_wait_queue(&ls->thread_wait, &wait); + if (no_work(ls, blist)) + schedule(); + remove_wait_queue(&ls->thread_wait, &wait); + set_current_state(TASK_RUNNING); + + complete = blocking = submit = drop = 0; + + spin_lock(&ls->async_lock); + + if (blist && !list_empty(&ls->blocking)) { + lp = list_entry(ls->blocking.next, struct gdlm_lock, + blist); + list_del_init(&lp->blist); + blocking = lp->bast_mode; + lp->bast_mode = 0; + } else if (!list_empty(&ls->complete)) { + lp = list_entry(ls->complete.next, struct gdlm_lock, + clist); + list_del_init(&lp->clist); + complete = 1; + } else if (!list_empty(&ls->submit)) { + lp = list_entry(ls->submit.next, struct gdlm_lock, + delay_list); + list_del_init(&lp->delay_list); + submit = 1; + } + + drop = check_drop(ls); + spin_unlock(&ls->async_lock); + + if (complete) + process_complete(lp); + + else if (blocking) + process_blocking(lp, blocking); + + else if (submit) + process_submit(lp); + + if (drop) + ls->fscb(ls->fsdata, LM_CB_DROPLOCKS, NULL); + + schedule(); + } + + return 0; +} + +int gdlm_init_threads(struct gdlm_ls *ls) +{ + struct task_struct *p; + int error; + + p = kthread_run(gdlm_thread, ls, "lock_dlm1"); + error = IS_ERR(p); + if (error) { + log_all("can't start lock_dlm1 thread %d", error); + return error; + } + ls->thread1 = p; + + p = kthread_run(gdlm_thread, ls, "lock_dlm2"); + error = IS_ERR(p); + if (error) { + log_all("can't start lock_dlm2 thread %d", error); + kthread_stop(ls->thread1); + return error; + } + ls->thread2 = p; + + return 0; +} + +void gdlm_release_threads(struct gdlm_ls *ls) +{ + kthread_stop(ls->thread1); + kthread_stop(ls->thread2); +} + diff --git a/fs/gfs2/locking/nolock/Makefile b/fs/gfs2/locking/nolock/Makefile new file mode 100644 index 000000000000..cdadf956c831 --- /dev/null +++ b/fs/gfs2/locking/nolock/Makefile @@ -0,0 +1,3 @@ +obj-$(CONFIG_GFS2_FS) += lock_nolock.o +lock_nolock-y := main.o + diff --git a/fs/gfs2/locking/nolock/lock_nolock.mod.c b/fs/gfs2/locking/nolock/lock_nolock.mod.c new file mode 100644 index 000000000000..ae92522b2182 --- /dev/null +++ b/fs/gfs2/locking/nolock/lock_nolock.mod.c @@ -0,0 +1,44 @@ +#include +#include +#include + +MODULE_INFO(vermagic, VERMAGIC_STRING); + +#undef unix +struct module __this_module +__attribute__((section(".gnu.linkonce.this_module"))) = { + .name = __stringify(KBUILD_MODNAME), + .init = init_module, +#ifdef CONFIG_MODULE_UNLOAD + .exit = cleanup_module, +#endif +}; + +static const struct modversion_info ____versions[] +__attribute_used__ +__attribute__((section("__versions"))) = { + { 0x316962fc, "struct_module" }, + { 0x5a34a45c, "__kmalloc" }, + { 0x724beef2, "malloc_sizes" }, + { 0x3fa03a97, "memset" }, + { 0xc16fe12d, "__memcpy" }, + { 0xdd132261, "printk" }, + { 0x859204af, "sscanf" }, + { 0x3656bf5a, "lock_kernel" }, + { 0x1e6d26a8, "strstr" }, + { 0x41ede9df, "lm_register_proto" }, + { 0xb1f975aa, "unlock_kernel" }, + { 0x87b0b01f, "posix_lock_file_wait" }, + { 0x75f29cfd, "kmem_cache_alloc" }, + { 0x69384280, "lm_unregister_proto" }, + { 0x37a0cba, "kfree" }, + { 0x5d16bfe6, "posix_test_lock" }, +}; + +static const char __module_depends[] +__attribute_used__ +__attribute__((section(".modinfo"))) = +"depends=gfs2"; + + +MODULE_INFO(srcversion, "123E446F965A386A0C017C4"); diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c new file mode 100644 index 000000000000..d3919e471163 --- /dev/null +++ b/fs/gfs2/locking/nolock/main.c @@ -0,0 +1,357 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include "../../lm_interface.h" + +struct nolock_lockspace { + unsigned int nl_lvb_size; +}; + +struct lm_lockops nolock_ops; + +/** + * nolock_mount - mount a nolock lockspace + * @table_name: the name of the space to mount + * @host_data: host specific data + * @cb: the callback + * @fsdata: + * @min_lvb_size: + * @flags: + * @lockstruct: the structure of crap to fill in + * + * Returns: 0 on success, -EXXX on failure + */ + +static int nolock_mount(char *table_name, char *host_data, + lm_callback_t cb, lm_fsdata_t *fsdata, + unsigned int min_lvb_size, int flags, + struct lm_lockstruct *lockstruct) +{ + char *c; + unsigned int jid; + struct nolock_lockspace *nl; + + /* If there is a "jid=" in the hostdata, return that jid. + Otherwise, return zero. */ + + c = strstr(host_data, "jid="); + if (!c) + jid = 0; + else { + c += 4; + sscanf(c, "%u", &jid); + } + + nl = kmalloc(sizeof(struct nolock_lockspace), GFP_KERNEL); + if (!nl) + return -ENOMEM; + + memset(nl, 0, sizeof(struct nolock_lockspace)); + nl->nl_lvb_size = min_lvb_size; + + lockstruct->ls_jid = jid; + lockstruct->ls_first = 1; + lockstruct->ls_lvb_size = min_lvb_size; + lockstruct->ls_lockspace = (lm_lockspace_t *)nl; + lockstruct->ls_ops = &nolock_ops; + lockstruct->ls_flags = LM_LSFLAG_LOCAL; + + return 0; +} + +/** + * nolock_others_may_mount - unmount a lock space + * @lockspace: the lockspace to unmount + * + */ + +static void nolock_others_may_mount(lm_lockspace_t *lockspace) +{ +} + +/** + * nolock_unmount - unmount a lock space + * @lockspace: the lockspace to unmount + * + */ + +static void nolock_unmount(lm_lockspace_t *lockspace) +{ + struct nolock_lockspace *nl = (struct nolock_lockspace *)lockspace; + kfree(nl); +} + +/** + * nolock_withdraw - withdraw from a lock space + * @lockspace: the lockspace + * + */ + +static void nolock_withdraw(lm_lockspace_t *lockspace) +{ +} + +/** + * nolock_get_lock - get a lm_lock_t given a descripton of the lock + * @lockspace: the lockspace the lock lives in + * @name: the name of the lock + * @lockp: return the lm_lock_t here + * + * Returns: 0 on success, -EXXX on failure + */ + +static int nolock_get_lock(lm_lockspace_t *lockspace, struct lm_lockname *name, + lm_lock_t **lockp) +{ + *lockp = (lm_lock_t *)lockspace; + return 0; +} + +/** + * nolock_put_lock - get rid of a lock structure + * @lock: the lock to throw away + * + */ + +static void nolock_put_lock(lm_lock_t *lock) +{ +} + +/** + * nolock_lock - acquire a lock + * @lock: the lock to manipulate + * @cur_state: the current state + * @req_state: the requested state + * @flags: modifier flags + * + * Returns: A bitmap of LM_OUT_* + */ + +static unsigned int nolock_lock(lm_lock_t *lock, unsigned int cur_state, + unsigned int req_state, unsigned int flags) +{ + return req_state | LM_OUT_CACHEABLE; +} + +/** + * nolock_unlock - unlock a lock + * @lock: the lock to manipulate + * @cur_state: the current state + * + * Returns: 0 + */ + +static unsigned int nolock_unlock(lm_lock_t *lock, unsigned int cur_state) +{ + return 0; +} + +/** + * nolock_cancel - cancel a request on a lock + * @lock: the lock to cancel request for + * + */ + +static void nolock_cancel(lm_lock_t *lock) +{ +} + +/** + * nolock_hold_lvb - hold on to a lock value block + * @lock: the lock the LVB is associated with + * @lvbp: return the lm_lvb_t here + * + * Returns: 0 on success, -EXXX on failure + */ + +static int nolock_hold_lvb(lm_lock_t *lock, char **lvbp) +{ + struct nolock_lockspace *nl = (struct nolock_lockspace *)lock; + int error = 0; + + *lvbp = kmalloc(nl->nl_lvb_size, GFP_KERNEL); + if (*lvbp) + memset(*lvbp, 0, nl->nl_lvb_size); + else + error = -ENOMEM; + + return error; +} + +/** + * nolock_unhold_lvb - release a LVB + * @lock: the lock the LVB is associated with + * @lvb: the lock value block + * + */ + +static void nolock_unhold_lvb(lm_lock_t *lock, char *lvb) +{ + kfree(lvb); +} + +/** + * nolock_sync_lvb - sync out the value of a lvb + * @lock: the lock the LVB is associated with + * @lvb: the lock value block + * + */ + +static void nolock_sync_lvb(lm_lock_t *lock, char *lvb) +{ +} + +/** + * nolock_plock_get - + * @lockspace: the lockspace + * @name: + * @file: + * @fl: + * + * Returns: errno + */ + +static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, + struct file *file, struct file_lock *fl) +{ + struct file_lock *tmp; + + lock_kernel(); + tmp = posix_test_lock(file, fl); + fl->fl_type = F_UNLCK; + if (tmp) + memcpy(fl, tmp, sizeof(struct file_lock)); + unlock_kernel(); + + return 0; +} + +/** + * nolock_plock - + * @lockspace: the lockspace + * @name: + * @file: + * @cmd: + * @fl: + * + * Returns: errno + */ + +static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, + struct file *file, int cmd, struct file_lock *fl) +{ + int error; + lock_kernel(); + error = posix_lock_file_wait(file, fl); + unlock_kernel(); + return error; +} + +/** + * nolock_punlock - + * @lockspace: the lockspace + * @name: + * @file: + * @fl: + * + * Returns: errno + */ + +static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, + struct file *file, struct file_lock *fl) +{ + int error; + lock_kernel(); + error = posix_lock_file_wait(file, fl); + unlock_kernel(); + return error; +} + +/** + * nolock_recovery_done - reset the expired locks for a given jid + * @lockspace: the lockspace + * @jid: the jid + * + */ + +static void nolock_recovery_done(lm_lockspace_t *lockspace, unsigned int jid, + unsigned int message) +{ +} + +struct lm_lockops nolock_ops = { + .lm_proto_name = "lock_nolock", + .lm_mount = nolock_mount, + .lm_others_may_mount = nolock_others_may_mount, + .lm_unmount = nolock_unmount, + .lm_withdraw = nolock_withdraw, + .lm_get_lock = nolock_get_lock, + .lm_put_lock = nolock_put_lock, + .lm_lock = nolock_lock, + .lm_unlock = nolock_unlock, + .lm_cancel = nolock_cancel, + .lm_hold_lvb = nolock_hold_lvb, + .lm_unhold_lvb = nolock_unhold_lvb, + .lm_sync_lvb = nolock_sync_lvb, + .lm_plock_get = nolock_plock_get, + .lm_plock = nolock_plock, + .lm_punlock = nolock_punlock, + .lm_recovery_done = nolock_recovery_done, + .lm_owner = THIS_MODULE, +}; + +/** + * init_nolock - Initialize the nolock module + * + * Returns: 0 on success, -EXXX on failure + */ + +int __init init_nolock(void) +{ + int error; + + error = lm_register_proto(&nolock_ops); + if (error) { + printk("lock_nolock: can't register protocol: %d\n", error); + return error; + } + + printk("Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__); + return 0; +} + +/** + * exit_nolock - cleanup the nolock module + * + */ + +void __exit exit_nolock(void) +{ + lm_unregister_proto(&nolock_ops); +} + +module_init(init_nolock); +module_exit(exit_nolock); + +MODULE_DESCRIPTION("GFS Nolock Locking Module"); +MODULE_AUTHOR("Red Hat, Inc."); +MODULE_LICENSE("GPL"); + From a8f2d64728d8b706392fc1cb0f2fd6852a5e27ae Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 17 Jan 2006 08:36:49 +0000 Subject: [PATCH 006/292] [GFS2] Fix typo in GFS2 Makefile A two line fix to the GFS2 Makefile. Signed-off-by: David Teigland Signed-off-by: Steve Whitehouse --- fs/gfs2/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile index b1bac4f199db..974c76d0c6fc 100644 --- a/fs/gfs2/Makefile +++ b/fs/gfs2/Makefile @@ -39,6 +39,6 @@ gfs2-y := \ unlinked.o \ util.o -obj-$(CONFIG_GFS2_LOCKING_NOLOCK) += locking/nolock/ -obj-$(CONFIG_GFS2_LOCKING_DLM) += locking/dlm/ +obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += locking/nolock/ +obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += locking/dlm/ From 869d81df53ad28ce78fc92504b3365b8196a2fa1 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 17 Jan 2006 08:47:12 +0000 Subject: [PATCH 007/292] [GFS2] An update of the GFS2 lock modules This brings the lock modules uptodate and removes the stray .mod.c file which accidently got included in the last check in. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/Makefile | 2 +- fs/gfs2/locking/dlm/lock.c | 104 ++++---- fs/gfs2/locking/dlm/lock_dlm.h | 191 +++++++++++++++ fs/gfs2/locking/dlm/main.c | 34 +-- fs/gfs2/locking/dlm/mount.c | 189 ++++++++------- fs/gfs2/locking/dlm/plock.c | 297 +++++++++++++++++++++++ fs/gfs2/locking/dlm/sysfs.c | 203 ++++------------ fs/gfs2/locking/dlm/thread.c | 65 +++-- fs/gfs2/locking/nolock/lock_nolock.mod.c | 44 ---- fs/gfs2/locking/nolock/main.c | 113 +-------- include/linux/lock_dlm_plock.h | 40 +++ 11 files changed, 792 insertions(+), 490 deletions(-) create mode 100644 fs/gfs2/locking/dlm/lock_dlm.h create mode 100644 fs/gfs2/locking/dlm/plock.c delete mode 100644 fs/gfs2/locking/nolock/lock_nolock.mod.c create mode 100644 include/linux/lock_dlm_plock.h diff --git a/fs/gfs2/locking/dlm/Makefile b/fs/gfs2/locking/dlm/Makefile index d3bca02f7b3e..a9733ff80371 100644 --- a/fs/gfs2/locking/dlm/Makefile +++ b/fs/gfs2/locking/dlm/Makefile @@ -1,3 +1,3 @@ obj-$(CONFIG_GFS2_FS) += lock_dlm.o -lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o +lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o plock.o diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index daf59d504e29..d799865b64a4 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -1,15 +1,11 @@ -/****************************************************************************** -******************************************************************************* -** -** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. -** -** This copyrighted material is made available to anyone wishing to use, -** modify, copy, or redistribute it subject to the terms and conditions -** of the GNU General Public License v.2. -** -******************************************************************************* -******************************************************************************/ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ #include "lock_dlm.h" @@ -38,7 +34,7 @@ static inline void gdlm_bast(void *astarg, int mode) struct gdlm_ls *ls = lp->ls; if (!mode) { - printk("lock_dlm: bast mode zero %x,%"PRIx64"\n", + printk("lock_dlm: bast mode zero %x,%llx\n", lp->lockname.ln_type, lp->lockname.ln_number); return; } @@ -75,9 +71,9 @@ static int16_t make_mode(int16_t lmstate) return DLM_LOCK_CW; case LM_ST_SHARED: return DLM_LOCK_PR; - default: - GDLM_ASSERT(0, printk("unknown LM state %d\n", lmstate);); } + gdlm_assert(0, "unknown LM state %d", lmstate); + return -1; } /* convert dlm lock-mode to gfs lock-state */ @@ -94,9 +90,9 @@ int16_t gdlm_make_lmstate(int16_t dlmmode) return LM_ST_DEFERRED; case DLM_LOCK_PR: return LM_ST_SHARED; - default: - GDLM_ASSERT(0, printk("unknown DLM mode %d\n", dlmmode);); } + gdlm_assert(0, "unknown DLM mode %d", dlmmode); + return -1; } /* verify agreement with GFS on the current lock state, NB: DLM_LOCK_NL and @@ -106,7 +102,7 @@ static void check_cur_state(struct gdlm_lock *lp, unsigned int cur_state) { int16_t cur = make_mode(cur_state); if (lp->cur != DLM_LOCK_IV) - GDLM_ASSERT(lp->cur == cur, printk("%d, %d\n", lp->cur, cur);); + gdlm_assert(lp->cur == cur, "%d, %d", lp->cur, cur); } static inline unsigned int make_flags(struct gdlm_lock *lp, @@ -157,7 +153,7 @@ static inline unsigned int make_flags(struct gdlm_lock *lp, static inline void make_strname(struct lm_lockname *lockname, struct gdlm_strname *str) { - sprintf(str->name, "%8x%16"PRIx64, lockname->ln_type, + sprintf(str->name, "%8x%16llx", lockname->ln_type, lockname->ln_number); str->namelen = GDLM_STRNAME_BYTES; } @@ -167,11 +163,10 @@ int gdlm_create_lp(struct gdlm_ls *ls, struct lm_lockname *name, { struct gdlm_lock *lp; - lp = kmalloc(sizeof(struct gdlm_lock), GFP_KERNEL); + lp = kzalloc(sizeof(struct gdlm_lock), GFP_KERNEL); if (!lp) return -ENOMEM; - memset(lp, 0, sizeof(struct gdlm_lock)); lp->lockname = *name; lp->ls = ls; lp->cur = DLM_LOCK_IV; @@ -202,7 +197,8 @@ void gdlm_delete_lp(struct gdlm_lock *lp) list_del_init(&lp->blist); if (!list_empty(&lp->delay_list)) list_del_init(&lp->delay_list); - GDLM_ASSERT(!list_empty(&lp->all_list),); + gdlm_assert(!list_empty(&lp->all_list), + "%x,%llx", lp->lockname.ln_type, lp->lockname.ln_number); list_del_init(&lp->all_list); ls->all_locks_count--; spin_unlock(&ls->async_lock); @@ -227,7 +223,7 @@ void gdlm_put_lock(lm_lock_t *lock) gdlm_delete_lp((struct gdlm_lock *) lock); } -void gdlm_do_lock(struct gdlm_lock *lp, struct dlm_range *range) +unsigned int gdlm_do_lock(struct gdlm_lock *lp, struct dlm_range *range) { struct gdlm_ls *ls = lp->ls; struct gdlm_strname str; @@ -242,7 +238,7 @@ void gdlm_do_lock(struct gdlm_lock *lp, struct dlm_range *range) if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) && !test_bit(LFL_NOBLOCK, &lp->flags) && lp->req != DLM_LOCK_NL) { gdlm_queue_delayed(lp); - return; + return LM_OUT_ASYNC; } /* @@ -256,7 +252,7 @@ void gdlm_do_lock(struct gdlm_lock *lp, struct dlm_range *range) set_bit(LFL_ACTIVE, &lp->flags); - log_debug("lk %x,%"PRIx64" id %x %d,%d %x", lp->lockname.ln_type, + log_debug("lk %x,%llx id %x %d,%d %x", lp->lockname.ln_type, lp->lockname.ln_number, lp->lksb.sb_lkid, lp->cur, lp->req, lp->lkf); @@ -270,15 +266,19 @@ void gdlm_do_lock(struct gdlm_lock *lp, struct dlm_range *range) error = 0; } - GDLM_ASSERT(!error, - printk("%s: num=%x,%"PRIx64" err=%d cur=%d req=%d lkf=%x\n", - ls->fsname, lp->lockname.ln_type, + if (error) { + log_debug("%s: gdlm_lock %x,%llx err=%d cur=%d req=%d lkf=%x " + "flags=%lx", ls->fsname, lp->lockname.ln_type, lp->lockname.ln_number, error, lp->cur, lp->req, - lp->lkf);); + lp->lkf, lp->flags); + return LM_OUT_ERROR; + } + return LM_OUT_ASYNC; } -void gdlm_do_unlock(struct gdlm_lock *lp) +unsigned int gdlm_do_unlock(struct gdlm_lock *lp) { + struct gdlm_ls *ls = lp->ls; unsigned int lkf = 0; int error; @@ -288,16 +288,19 @@ void gdlm_do_unlock(struct gdlm_lock *lp) if (lp->lvb) lkf = DLM_LKF_VALBLK; - log_debug("un %x,%"PRIx64" %x %d %x", lp->lockname.ln_type, + log_debug("un %x,%llx %x %d %x", lp->lockname.ln_type, lp->lockname.ln_number, lp->lksb.sb_lkid, lp->cur, lkf); - error = dlm_unlock(lp->ls->dlm_lockspace, lp->lksb.sb_lkid, lkf, - NULL, lp); + error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, lkf, NULL, lp); - GDLM_ASSERT(!error, - printk("%s: error=%d num=%x,%"PRIx64" lkf=%x flags=%lx\n", - lp->ls->fsname, error, lp->lockname.ln_type, - lp->lockname.ln_number, lkf, lp->flags);); + if (error) { + log_debug("%s: gdlm_unlock %x,%llx err=%d cur=%d req=%d lkf=%x " + "flags=%lx", ls->fsname, lp->lockname.ln_type, + lp->lockname.ln_number, error, lp->cur, lp->req, + lp->lkf, lp->flags); + return LM_OUT_ERROR; + } + return LM_OUT_ASYNC; } unsigned int gdlm_lock(lm_lock_t *lock, unsigned int cur_state, @@ -313,8 +316,7 @@ unsigned int gdlm_lock(lm_lock_t *lock, unsigned int cur_state, lp->req = make_mode(req_state); lp->lkf = make_flags(lp, flags, lp->cur, lp->req); - gdlm_do_lock(lp, NULL); - return LM_OUT_ASYNC; + return gdlm_do_lock(lp, NULL); } unsigned int gdlm_unlock(lm_lock_t *lock, unsigned int cur_state) @@ -324,8 +326,7 @@ unsigned int gdlm_unlock(lm_lock_t *lock, unsigned int cur_state) clear_bit(LFL_DLM_CANCEL, &lp->flags); if (lp->cur == DLM_LOCK_IV) return 0; - gdlm_do_unlock(lp); - return LM_OUT_ASYNC; + return gdlm_do_unlock(lp); } void gdlm_cancel(lm_lock_t *lock) @@ -337,8 +338,8 @@ void gdlm_cancel(lm_lock_t *lock) if (test_bit(LFL_DLM_CANCEL, &lp->flags)) return; - log_all("gdlm_cancel %x,%"PRIx64" flags %lx", - lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); + log_info("gdlm_cancel %x,%llx flags %lx", + lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); spin_lock(&ls->async_lock); if (!list_empty(&lp->delay_list)) { @@ -356,9 +357,9 @@ void gdlm_cancel(lm_lock_t *lock) if (!test_bit(LFL_ACTIVE, &lp->flags) || test_bit(LFL_DLM_UNLOCK, &lp->flags)) { - log_all("gdlm_cancel skip %x,%"PRIx64" flags %lx", - lp->lockname.ln_type, lp->lockname.ln_number, - lp->flags); + log_info("gdlm_cancel skip %x,%llx flags %lx", + lp->lockname.ln_type, lp->lockname.ln_number, + lp->flags); return; } @@ -370,8 +371,8 @@ void gdlm_cancel(lm_lock_t *lock) error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, DLM_LKF_CANCEL, NULL, lp); - log_all("gdlm_cancel rv %d %x,%"PRIx64" flags %lx", error, - lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); + log_info("gdlm_cancel rv %d %x,%llx flags %lx", error, + lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); if (error == -EBUSY) clear_bit(LFL_DLM_CANCEL, &lp->flags); @@ -381,12 +382,10 @@ int gdlm_add_lvb(struct gdlm_lock *lp) { char *lvb; - lvb = kmalloc(GDLM_LVB_SIZE, GFP_KERNEL); + lvb = kzalloc(GDLM_LVB_SIZE, GFP_KERNEL); if (!lvb) return -ENOMEM; - memset(lvb, 0, GDLM_LVB_SIZE); - lp->lksb.sb_lvbptr = lvb; lp->lvb = lvb; return 0; @@ -448,7 +447,8 @@ static void unhold_null_lock(struct gdlm_lock *lp) { struct gdlm_lock *lpn = lp->hold_null; - GDLM_ASSERT(lpn,); + gdlm_assert(lpn, "%x,%llx", + lp->lockname.ln_type, lp->lockname.ln_number); lpn->lksb.sb_lvbptr = NULL; lpn->lvb = NULL; set_bit(LFL_UNLOCK_DELETE, &lpn->flags); diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h new file mode 100644 index 000000000000..fa545f7872e8 --- /dev/null +++ b/fs/gfs2/locking/dlm/lock_dlm.h @@ -0,0 +1,191 @@ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef LOCK_DLM_DOT_H +#define LOCK_DLM_DOT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "../../lm_interface.h" + +/* + * Internally, we prefix things with gdlm_ and GDLM_ (for gfs-dlm) since a + * prefix of lock_dlm_ gets awkward. Externally, GFS refers to this module + * as "lock_dlm". + */ + +#define GDLM_STRNAME_BYTES 24 +#define GDLM_LVB_SIZE 32 +#define GDLM_DROP_COUNT 50000 +#define GDLM_DROP_PERIOD 60 +#define GDLM_NAME_LEN 128 + +/* GFS uses 12 bytes to identify a resource (32 bit type + 64 bit number). + We sprintf these numbers into a 24 byte string of hex values to make them + human-readable (to make debugging simpler.) */ + +struct gdlm_strname { + unsigned char name[GDLM_STRNAME_BYTES]; + unsigned short namelen; +}; + +enum { + DFL_BLOCK_LOCKS = 0, + DFL_SPECTATOR = 1, + DFL_WITHDRAW = 2, +}; + +struct gdlm_ls { + uint32_t id; + int jid; + int first; + int first_done; + unsigned long flags; + struct kobject kobj; + char clustername[GDLM_NAME_LEN]; + char fsname[GDLM_NAME_LEN]; + int fsflags; + dlm_lockspace_t *dlm_lockspace; + lm_callback_t fscb; + lm_fsdata_t *fsdata; + int recover_jid; + int recover_jid_done; + spinlock_t async_lock; + struct list_head complete; + struct list_head blocking; + struct list_head delayed; + struct list_head submit; + struct list_head all_locks; + uint32_t all_locks_count; + wait_queue_head_t wait_control; + struct task_struct *thread1; + struct task_struct *thread2; + wait_queue_head_t thread_wait; + unsigned long drop_time; + int drop_locks_count; + int drop_locks_period; +}; + +enum { + LFL_NOBLOCK = 0, + LFL_NOCACHE = 1, + LFL_DLM_UNLOCK = 2, + LFL_DLM_CANCEL = 3, + LFL_SYNC_LVB = 4, + LFL_FORCE_PROMOTE = 5, + LFL_REREQUEST = 6, + LFL_ACTIVE = 7, + LFL_INLOCK = 8, + LFL_CANCEL = 9, + LFL_NOBAST = 10, + LFL_HEADQUE = 11, + LFL_UNLOCK_DELETE = 12, +}; + +struct gdlm_lock { + struct gdlm_ls *ls; + struct lm_lockname lockname; + char *lvb; + struct dlm_lksb lksb; + + int16_t cur; + int16_t req; + int16_t prev_req; + uint32_t lkf; /* dlm flags DLM_LKF_ */ + unsigned long flags; /* lock_dlm flags LFL_ */ + + int bast_mode; /* protected by async_lock */ + struct completion ast_wait; + + struct list_head clist; /* complete */ + struct list_head blist; /* blocking */ + struct list_head delay_list; /* delayed */ + struct list_head all_list; /* all locks for the fs */ + struct gdlm_lock *hold_null; /* NL lock for hold_lvb */ +}; + +#define gdlm_assert(assertion, fmt, args...) \ +do { \ + if (unlikely(!(assertion))) { \ + printk(KERN_EMERG "lock_dlm: fatal assertion failed \"%s\"\n" \ + "lock_dlm: " fmt "\n", \ + #assertion, ##args); \ + BUG(); \ + } \ +} while (0) + +#define log_print(lev, fmt, arg...) printk(lev "lock_dlm: " fmt "\n" , ## arg) +#define log_info(fmt, arg...) log_print(KERN_INFO , fmt , ## arg) +#define log_error(fmt, arg...) log_print(KERN_ERR , fmt , ## arg) +#ifdef LOCK_DLM_LOG_DEBUG +#define log_debug(fmt, arg...) log_print(KERN_DEBUG , fmt , ## arg) +#else +#define log_debug(fmt, arg...) +#endif + +/* sysfs.c */ + +int gdlm_sysfs_init(void); +void gdlm_sysfs_exit(void); +int gdlm_kobject_setup(struct gdlm_ls *, struct kobject *); +void gdlm_kobject_release(struct gdlm_ls *); + +/* thread.c */ + +int gdlm_init_threads(struct gdlm_ls *); +void gdlm_release_threads(struct gdlm_ls *); + +/* lock.c */ + +int16_t gdlm_make_lmstate(int16_t); +void gdlm_queue_delayed(struct gdlm_lock *); +void gdlm_submit_delayed(struct gdlm_ls *); +int gdlm_release_all_locks(struct gdlm_ls *); +int gdlm_create_lp(struct gdlm_ls *, struct lm_lockname *, struct gdlm_lock **); +void gdlm_delete_lp(struct gdlm_lock *); +int gdlm_add_lvb(struct gdlm_lock *); +void gdlm_del_lvb(struct gdlm_lock *); +unsigned int gdlm_do_lock(struct gdlm_lock *, struct dlm_range *); +unsigned int gdlm_do_unlock(struct gdlm_lock *); + +int gdlm_get_lock(lm_lockspace_t *, struct lm_lockname *, lm_lock_t **); +void gdlm_put_lock(lm_lock_t *); +unsigned int gdlm_lock(lm_lock_t *, unsigned int, unsigned int, unsigned int); +unsigned int gdlm_unlock(lm_lock_t *, unsigned int); +void gdlm_cancel(lm_lock_t *); +int gdlm_hold_lvb(lm_lock_t *, char **); +void gdlm_unhold_lvb(lm_lock_t *, char *); +void gdlm_sync_lvb(lm_lock_t *, char *); + +/* plock.c */ + +int gdlm_plock_init(void); +void gdlm_plock_exit(void); +int gdlm_plock(lm_lockspace_t *, struct lm_lockname *, struct file *, int, + struct file_lock *); +int gdlm_plock_get(lm_lockspace_t *, struct lm_lockname *, struct file *, + struct file_lock *); +int gdlm_punlock(lm_lockspace_t *, struct lm_lockname *, struct file *, + struct file_lock *); +#endif + diff --git a/fs/gfs2/locking/dlm/main.c b/fs/gfs2/locking/dlm/main.c index 3ced92ef1b19..2c13c916a352 100644 --- a/fs/gfs2/locking/dlm/main.c +++ b/fs/gfs2/locking/dlm/main.c @@ -1,15 +1,11 @@ -/****************************************************************************** -******************************************************************************* -** -** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. -** -** This copyrighted material is made available to anyone wishing to use, -** modify, copy, or redistribute it subject to the terms and conditions -** of the GNU General Public License v.2. -** -******************************************************************************* -******************************************************************************/ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ #include @@ -24,7 +20,7 @@ int __init init_lock_dlm(void) { int error; - error = lm_register_proto(&gdlm_ops); + error = gfs_register_lockproto(&gdlm_ops); if (error) { printk("lock_dlm: can't register protocol: %d\n", error); return error; @@ -32,7 +28,14 @@ int __init init_lock_dlm(void) error = gdlm_sysfs_init(); if (error) { - lm_unregister_proto(&gdlm_ops); + gfs_unregister_lockproto(&gdlm_ops); + return error; + } + + error = gdlm_plock_init(); + if (error) { + gdlm_sysfs_exit(); + gfs_unregister_lockproto(&gdlm_ops); return error; } @@ -45,8 +48,9 @@ int __init init_lock_dlm(void) void __exit exit_lock_dlm(void) { - lm_unregister_proto(&gdlm_ops); + gdlm_plock_exit(); gdlm_sysfs_exit(); + gfs_unregister_lockproto(&gdlm_ops); } module_init(init_lock_dlm); diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c index 92b1789deb89..bfb224638f2d 100644 --- a/fs/gfs2/locking/dlm/mount.c +++ b/fs/gfs2/locking/dlm/mount.c @@ -1,15 +1,11 @@ -/****************************************************************************** -******************************************************************************* -** -** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. -** -** This copyrighted material is made available to anyone wishing to use, -** modify, copy, or redistribute it subject to the terms and conditions -** of the GNU General Public License v.2. -** -******************************************************************************* -******************************************************************************/ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ #include "lock_dlm.h" @@ -24,27 +20,21 @@ static struct gdlm_ls *init_gdlm(lm_callback_t cb, lm_fsdata_t *fsdata, struct gdlm_ls *ls; char buf[256], *p; - ls = kmalloc(sizeof(struct gdlm_ls), GFP_KERNEL); + ls = kzalloc(sizeof(struct gdlm_ls), GFP_KERNEL); if (!ls) return NULL; - memset(ls, 0, sizeof(struct gdlm_ls)); - ls->drop_locks_count = gdlm_drop_count; ls->drop_locks_period = gdlm_drop_period; - ls->fscb = cb; ls->fsdata = fsdata; ls->fsflags = flags; - spin_lock_init(&ls->async_lock); - INIT_LIST_HEAD(&ls->complete); INIT_LIST_HEAD(&ls->blocking); INIT_LIST_HEAD(&ls->delayed); INIT_LIST_HEAD(&ls->submit); INIT_LIST_HEAD(&ls->all_locks); - init_waitqueue_head(&ls->thread_wait); init_waitqueue_head(&ls->wait_control); ls->thread1 = NULL; @@ -57,23 +47,75 @@ static struct gdlm_ls *init_gdlm(lm_callback_t cb, lm_fsdata_t *fsdata, p = strstr(buf, ":"); if (!p) { - printk("lock_dlm: invalid table_name \"%s\"\n", table_name); + log_info("invalid table_name \"%s\"", table_name); kfree(ls); return NULL; } *p = '\0'; p++; - strncpy(ls->clustername, buf, 128); - strncpy(ls->fsname, p, 128); + strncpy(ls->clustername, buf, GDLM_NAME_LEN); + strncpy(ls->fsname, p, GDLM_NAME_LEN); return ls; } +static int make_args(struct gdlm_ls *ls, char *data_arg) +{ + char data[256]; + char *options, *x, *y; + int error = 0; + + memset(data, 0, 256); + strncpy(data, data_arg, 255); + + for (options = data; (x = strsep(&options, ":")); ) { + if (!*x) + continue; + + y = strchr(x, '='); + if (y) + *y++ = 0; + + if (!strcmp(x, "jid")) { + if (!y) { + log_error("need argument to jid"); + error = -EINVAL; + break; + } + sscanf(y, "%u", &ls->jid); + + } else if (!strcmp(x, "first")) { + if (!y) { + log_error("need argument to first"); + error = -EINVAL; + break; + } + sscanf(y, "%u", &ls->first); + + } else if (!strcmp(x, "id")) { + if (!y) { + log_error("need argument to id"); + error = -EINVAL; + break; + } + sscanf(y, "%u", &ls->id); + + } else { + log_error("unkonwn option: %s", x); + error = -EINVAL; + break; + } + } + + return error; +} + static int gdlm_mount(char *table_name, char *host_data, lm_callback_t cb, lm_fsdata_t *fsdata, unsigned int min_lvb_size, int flags, - struct lm_lockstruct *lockstruct) + struct lm_lockstruct *lockstruct, + struct kobject *fskobj) { struct gdlm_ls *ls; int error = -ENOMEM; @@ -92,30 +134,18 @@ static int gdlm_mount(char *table_name, char *host_data, error = dlm_new_lockspace(ls->fsname, strlen(ls->fsname), &ls->dlm_lockspace, 0, GDLM_LVB_SIZE); if (error) { - printk("lock_dlm: dlm_new_lockspace error %d\n", error); + log_error("dlm_new_lockspace error %d", error); goto out_thread; } - error = gdlm_kobject_setup(ls); + error = gdlm_kobject_setup(ls, fskobj); if (error) goto out_dlm; - kobject_uevent(&ls->kobj, KOBJ_MOUNT, NULL); - /* Now we depend on userspace to notice the new mount, - join the appropriate group, and do a write to our sysfs - "mounted" or "terminate" file. Before the start, userspace - must set "jid" and "first". */ - - error = wait_event_interruptible(ls->wait_control, - test_bit(DFL_JOIN_DONE, &ls->flags)); + error = make_args(ls, host_data); if (error) goto out_sysfs; - if (test_bit(DFL_TERMINATE, &ls->flags)) { - error = -ERESTARTSYS; - goto out_sysfs; - } - lockstruct->ls_jid = ls->jid; lockstruct->ls_first = ls->first; lockstruct->ls_lockspace = ls; @@ -143,22 +173,19 @@ static void gdlm_unmount(lm_lockspace_t *lockspace) log_debug("unmount flags %lx", ls->flags); - if (test_bit(DFL_WITHDRAW, &ls->flags)) { - gdlm_kobject_release(ls); + /* FIXME: serialize unmount and withdraw in case they + happen at once. Also, if unmount follows withdraw, + wait for withdraw to finish. */ + + if (test_bit(DFL_WITHDRAW, &ls->flags)) goto out; - } - - kobject_uevent(&ls->kobj, KOBJ_UMOUNT, NULL); - - wait_event_interruptible(ls->wait_control, - test_bit(DFL_LEAVE_DONE, &ls->flags)); gdlm_kobject_release(ls); dlm_release_lockspace(ls->dlm_lockspace, 2); gdlm_release_threads(ls); rv = gdlm_release_all_locks(ls); if (rv) - log_all("lm_dlm_unmount: %d stray locks freed", rv); + log_info("gdlm_unmount: %d stray locks freed", rv); out: kfree(ls); } @@ -167,7 +194,7 @@ static void gdlm_recovery_done(lm_lockspace_t *lockspace, unsigned int jid, unsigned int message) { struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; - ls->recover_done = jid; + ls->recover_jid_done = jid; kobject_uevent(&ls->kobj, KOBJ_CHANGE, NULL); } @@ -178,12 +205,14 @@ static void gdlm_others_may_mount(lm_lockspace_t *lockspace) kobject_uevent(&ls->kobj, KOBJ_CHANGE, NULL); } +/* Userspace gets the offline uevent, blocks new gfs locks on + other mounters, and lets us know (sets WITHDRAW flag). Then, + userspace leaves the mount group while we leave the lockspace. */ + static void gdlm_withdraw(lm_lockspace_t *lockspace) { struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; - /* userspace suspends locking on all other members */ - kobject_uevent(&ls->kobj, KOBJ_OFFLINE, NULL); wait_event_interruptible(ls->wait_control, @@ -192,49 +221,27 @@ static void gdlm_withdraw(lm_lockspace_t *lockspace) dlm_release_lockspace(ls->dlm_lockspace, 2); gdlm_release_threads(ls); gdlm_release_all_locks(ls); - - kobject_uevent(&ls->kobj, KOBJ_UMOUNT, NULL); - - /* userspace leaves the mount group, we don't need to wait for - that to complete */ -} - -int gdlm_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, - struct file *file, struct file_lock *fl) -{ - return -ENOSYS; -} - -int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, - struct file *file, struct file_lock *fl) -{ - return -ENOSYS; -} - -int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, - struct file *file, int cmd, struct file_lock *fl) -{ - return -ENOSYS; + gdlm_kobject_release(ls); } struct lm_lockops gdlm_ops = { - lm_proto_name:"lock_dlm", - lm_mount:gdlm_mount, - lm_others_may_mount:gdlm_others_may_mount, - lm_unmount:gdlm_unmount, - lm_withdraw:gdlm_withdraw, - lm_get_lock:gdlm_get_lock, - lm_put_lock:gdlm_put_lock, - lm_lock:gdlm_lock, - lm_unlock:gdlm_unlock, - lm_plock:gdlm_plock, - lm_punlock:gdlm_punlock, - lm_plock_get:gdlm_plock_get, - lm_cancel:gdlm_cancel, - lm_hold_lvb:gdlm_hold_lvb, - lm_unhold_lvb:gdlm_unhold_lvb, - lm_sync_lvb:gdlm_sync_lvb, - lm_recovery_done:gdlm_recovery_done, - lm_owner:THIS_MODULE, + .lm_proto_name = "lock_dlm", + .lm_mount = gdlm_mount, + .lm_others_may_mount = gdlm_others_may_mount, + .lm_unmount = gdlm_unmount, + .lm_withdraw = gdlm_withdraw, + .lm_get_lock = gdlm_get_lock, + .lm_put_lock = gdlm_put_lock, + .lm_lock = gdlm_lock, + .lm_unlock = gdlm_unlock, + .lm_plock = gdlm_plock, + .lm_punlock = gdlm_punlock, + .lm_plock_get = gdlm_plock_get, + .lm_cancel = gdlm_cancel, + .lm_hold_lvb = gdlm_hold_lvb, + .lm_unhold_lvb = gdlm_unhold_lvb, + .lm_sync_lvb = gdlm_sync_lvb, + .lm_recovery_done = gdlm_recovery_done, + .lm_owner = THIS_MODULE, }; diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c new file mode 100644 index 000000000000..382847205bc1 --- /dev/null +++ b/fs/gfs2/locking/dlm/plock.c @@ -0,0 +1,297 @@ +/* + * Copyright (C) 2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include + +#include "lock_dlm.h" + + +static spinlock_t ops_lock; +static struct list_head send_list; +static struct list_head recv_list; +static wait_queue_head_t send_wq; +static wait_queue_head_t recv_wq; + +struct plock_op { + struct list_head list; + int done; + struct gdlm_plock_info info; +}; + +static inline void set_version(struct gdlm_plock_info *info) +{ + info->version[0] = GDLM_PLOCK_VERSION_MAJOR; + info->version[1] = GDLM_PLOCK_VERSION_MINOR; + info->version[2] = GDLM_PLOCK_VERSION_PATCH; +} + +static int check_version(struct gdlm_plock_info *info) +{ + if ((GDLM_PLOCK_VERSION_MAJOR != info->version[0]) || + (GDLM_PLOCK_VERSION_MINOR < info->version[1])) { + log_error("plock device version mismatch: " + "kernel (%u.%u.%u), user (%u.%u.%u)", + GDLM_PLOCK_VERSION_MAJOR, + GDLM_PLOCK_VERSION_MINOR, + GDLM_PLOCK_VERSION_PATCH, + info->version[0], + info->version[1], + info->version[2]); + return -EINVAL; + } + return 0; +} + +static void send_op(struct plock_op *op) +{ + set_version(&op->info); + INIT_LIST_HEAD(&op->list); + spin_lock(&ops_lock); + list_add_tail(&op->list, &send_list); + spin_unlock(&ops_lock); + wake_up(&send_wq); +} + +int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, + struct file *file, int cmd, struct file_lock *fl) +{ + struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + struct plock_op *op; + int rv; + + op = kzalloc(sizeof(*op), GFP_KERNEL); + if (!op) + return -ENOMEM; + + op->info.optype = GDLM_PLOCK_OP_LOCK; + op->info.pid = (uint32_t) fl->fl_owner; + op->info.ex = (fl->fl_type == F_WRLCK); + op->info.wait = IS_SETLKW(cmd); + op->info.fsid = ls->id; + op->info.number = name->ln_number; + op->info.start = fl->fl_start; + op->info.end = fl->fl_end; + + send_op(op); + wait_event(recv_wq, (op->done != 0)); + + spin_lock(&ops_lock); + if (!list_empty(&op->list)) { + printk("plock op on list\n"); + list_del(&op->list); + } + spin_unlock(&ops_lock); + + rv = op->info.rv; + + if (!rv) { + if (posix_lock_file_wait(file, fl) < 0) + log_error("gdlm_plock: vfs lock error %x,%llx", + name->ln_type, name->ln_number); + } + + kfree(op); + return rv; +} + +int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, + struct file *file, struct file_lock *fl) +{ + struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + struct plock_op *op; + int rv; + + op = kzalloc(sizeof(*op), GFP_KERNEL); + if (!op) + return -ENOMEM; + + if (posix_lock_file_wait(file, fl) < 0) + log_error("gdlm_punlock: vfs unlock error %x,%llx", + name->ln_type, name->ln_number); + + op->info.optype = GDLM_PLOCK_OP_UNLOCK; + op->info.pid = (uint32_t) fl->fl_owner; + op->info.fsid = ls->id; + op->info.number = name->ln_number; + op->info.start = fl->fl_start; + op->info.end = fl->fl_end; + + send_op(op); + wait_event(recv_wq, (op->done != 0)); + + spin_lock(&ops_lock); + if (!list_empty(&op->list)) { + printk("punlock op on list\n"); + list_del(&op->list); + } + spin_unlock(&ops_lock); + + rv = op->info.rv; + + kfree(op); + return rv; +} + +int gdlm_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, + struct file *file, struct file_lock *fl) +{ + struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + struct plock_op *op; + int rv; + + op = kzalloc(sizeof(*op), GFP_KERNEL); + if (!op) + return -ENOMEM; + + op->info.optype = GDLM_PLOCK_OP_GET; + op->info.pid = (uint32_t) fl->fl_owner; + op->info.ex = (fl->fl_type == F_WRLCK); + op->info.fsid = ls->id; + op->info.number = name->ln_number; + op->info.start = fl->fl_start; + op->info.end = fl->fl_end; + + send_op(op); + wait_event(recv_wq, (op->done != 0)); + + spin_lock(&ops_lock); + if (!list_empty(&op->list)) { + printk("plock_get op on list\n"); + list_del(&op->list); + } + spin_unlock(&ops_lock); + + rv = op->info.rv; + + if (rv == 0) + fl->fl_type = F_UNLCK; + else if (rv > 0) { + fl->fl_type = (op->info.ex) ? F_WRLCK : F_RDLCK; + fl->fl_pid = op->info.pid; + fl->fl_start = op->info.start; + fl->fl_end = op->info.end; + } + + kfree(op); + return rv; +} + +/* a read copies out one plock request from the send list */ +static ssize_t dev_read(struct file *file, char __user *u, size_t count, + loff_t *ppos) +{ + struct gdlm_plock_info info; + struct plock_op *op = NULL; + + if (count < sizeof(info)) + return -EINVAL; + + spin_lock(&ops_lock); + if (!list_empty(&send_list)) { + op = list_entry(send_list.next, struct plock_op, list); + list_move(&op->list, &recv_list); + memcpy(&info, &op->info, sizeof(info)); + } + spin_unlock(&ops_lock); + + if (!op) + return -EAGAIN; + + if (copy_to_user(u, &info, sizeof(info))) + return -EFAULT; + return sizeof(info); +} + +/* a write copies in one plock result that should match a plock_op + on the recv list */ +static ssize_t dev_write(struct file *file, const char __user *u, size_t count, + loff_t *ppos) +{ + struct gdlm_plock_info info; + struct plock_op *op; + int found = 0; + + if (count != sizeof(info)) + return -EINVAL; + + if (copy_from_user(&info, u, sizeof(info))) + return -EFAULT; + + if (check_version(&info)) + return -EINVAL; + + spin_lock(&ops_lock); + list_for_each_entry(op, &recv_list, list) { + if (op->info.fsid == info.fsid && + op->info.number == info.number) { + list_del_init(&op->list); + found = 1; + op->done = 1; + memcpy(&op->info, &info, sizeof(info)); + break; + } + } + spin_unlock(&ops_lock); + + if (found) + wake_up(&recv_wq); + else + printk("gdlm dev_write no op %x %llx\n", info.fsid, + info.number); + return count; +} + +static unsigned int dev_poll(struct file *file, poll_table *wait) +{ + poll_wait(file, &send_wq, wait); + + spin_lock(&ops_lock); + if (!list_empty(&send_list)) { + spin_unlock(&ops_lock); + return POLLIN | POLLRDNORM; + } + spin_unlock(&ops_lock); + return 0; +} + +static struct file_operations dev_fops = { + .read = dev_read, + .write = dev_write, + .poll = dev_poll, + .owner = THIS_MODULE +}; + +static struct miscdevice plock_dev_misc = { + .minor = MISC_DYNAMIC_MINOR, + .name = GDLM_PLOCK_MISC_NAME, + .fops = &dev_fops +}; + +int gdlm_plock_init(void) +{ + int rv; + + spin_lock_init(&ops_lock); + INIT_LIST_HEAD(&send_list); + INIT_LIST_HEAD(&recv_list); + init_waitqueue_head(&send_wq); + init_waitqueue_head(&recv_wq); + + rv = misc_register(&plock_dev_misc); + if (rv) + printk("gdlm_plock_init: misc_register failed %d", rv); + return rv; +} + +void gdlm_plock_exit(void) +{ + if (misc_deregister(&plock_dev_misc) < 0) + printk("gdlm_plock_exit: misc_deregister failed"); +} + diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c index 8964733f55e4..e1e5186c97c9 100644 --- a/fs/gfs2/locking/dlm/sysfs.c +++ b/fs/gfs2/locking/dlm/sysfs.c @@ -1,21 +1,25 @@ -/****************************************************************************** -******************************************************************************* -** -** Copyright (C) 2005 Red Hat, Inc. All rights reserved. -** -** This copyrighted material is made available to anyone wishing to use, -** modify, copy, or redistribute it subject to the terms and conditions -** of the GNU General Public License v.2. -** -******************************************************************************* -******************************************************************************/ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ #include #include #include "lock_dlm.h" -static ssize_t gdlm_block_show(struct gdlm_ls *ls, char *buf) +extern struct lm_lockops gdlm_ops; + +static ssize_t proto_name_show(struct gdlm_ls *ls, char *buf) +{ + return sprintf(buf, "%s\n", gdlm_ops.lm_proto_name); +} + +static ssize_t block_show(struct gdlm_ls *ls, char *buf) { ssize_t ret; int val = 0; @@ -26,7 +30,7 @@ static ssize_t gdlm_block_show(struct gdlm_ls *ls, char *buf) return ret; } -static ssize_t gdlm_block_store(struct gdlm_ls *ls, const char *buf, size_t len) +static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len) { ssize_t ret = len; int val; @@ -43,43 +47,7 @@ static ssize_t gdlm_block_store(struct gdlm_ls *ls, const char *buf, size_t len) return ret; } -static ssize_t gdlm_mounted_show(struct gdlm_ls *ls, char *buf) -{ - ssize_t ret; - int val = -2; - - if (test_bit(DFL_TERMINATE, &ls->flags)) - val = -1; - else if (test_bit(DFL_LEAVE_DONE, &ls->flags)) - val = 0; - else if (test_bit(DFL_JOIN_DONE, &ls->flags)) - val = 1; - ret = sprintf(buf, "%d\n", val); - return ret; -} - -static ssize_t gdlm_mounted_store(struct gdlm_ls *ls, const char *buf, size_t len) -{ - ssize_t ret = len; - int val; - - val = simple_strtol(buf, NULL, 0); - - if (val == 1) - set_bit(DFL_JOIN_DONE, &ls->flags); - else if (val == 0) - set_bit(DFL_LEAVE_DONE, &ls->flags); - else if (val == -1) { - set_bit(DFL_TERMINATE, &ls->flags); - set_bit(DFL_JOIN_DONE, &ls->flags); - set_bit(DFL_LEAVE_DONE, &ls->flags); - } else - ret = -EINVAL; - wake_up(&ls->wait_control); - return ret; -} - -static ssize_t gdlm_withdraw_show(struct gdlm_ls *ls, char *buf) +static ssize_t withdraw_show(struct gdlm_ls *ls, char *buf) { ssize_t ret; int val = 0; @@ -90,7 +58,7 @@ static ssize_t gdlm_withdraw_show(struct gdlm_ls *ls, char *buf) return ret; } -static ssize_t gdlm_withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len) +static ssize_t withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len) { ssize_t ret = len; int val; @@ -105,67 +73,41 @@ static ssize_t gdlm_withdraw_store(struct gdlm_ls *ls, const char *buf, size_t l return ret; } -static ssize_t gdlm_jid_show(struct gdlm_ls *ls, char *buf) +static ssize_t id_show(struct gdlm_ls *ls, char *buf) { - return sprintf(buf, "%u\n", ls->jid); + return sprintf(buf, "%u\n", ls->id); } -static ssize_t gdlm_jid_store(struct gdlm_ls *ls, const char *buf, size_t len) +static ssize_t jid_show(struct gdlm_ls *ls, char *buf) { - ls->jid = simple_strtol(buf, NULL, 0); - return len; + return sprintf(buf, "%d\n", ls->jid); } -static ssize_t gdlm_first_show(struct gdlm_ls *ls, char *buf) +static ssize_t first_show(struct gdlm_ls *ls, char *buf) { - return sprintf(buf, "%u\n", ls->first); + return sprintf(buf, "%d\n", ls->first); } -static ssize_t gdlm_first_store(struct gdlm_ls *ls, const char *buf, size_t len) -{ - ls->first = simple_strtol(buf, NULL, 0); - return len; -} - -static ssize_t gdlm_first_done_show(struct gdlm_ls *ls, char *buf) +static ssize_t first_done_show(struct gdlm_ls *ls, char *buf) { return sprintf(buf, "%d\n", ls->first_done); } -static ssize_t gdlm_recover_show(struct gdlm_ls *ls, char *buf) +static ssize_t recover_show(struct gdlm_ls *ls, char *buf) { - return sprintf(buf, "%u\n", ls->recover_jid); + return sprintf(buf, "%d\n", ls->recover_jid); } -static ssize_t gdlm_recover_store(struct gdlm_ls *ls, const char *buf, size_t len) +static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len) { ls->recover_jid = simple_strtol(buf, NULL, 0); ls->fscb(ls->fsdata, LM_CB_NEED_RECOVERY, &ls->recover_jid); return len; } -static ssize_t gdlm_recover_done_show(struct gdlm_ls *ls, char *buf) +static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf) { - ssize_t ret; - ret = sprintf(buf, "%d\n", ls->recover_done); - return ret; -} - -static ssize_t gdlm_cluster_show(struct gdlm_ls *ls, char *buf) -{ - ssize_t ret; - ret = sprintf(buf, "%s\n", ls->clustername); - return ret; -} - -static ssize_t gdlm_options_show(struct gdlm_ls *ls, char *buf) -{ - ssize_t ret = 0; - - if (ls->fsflags & LM_MFLAG_SPECTATOR) - ret += sprintf(buf, "spectator "); - - return ret; + return sprintf(buf, "%d\n", ls->recover_jid_done); } struct gdlm_attr { @@ -174,73 +116,29 @@ struct gdlm_attr { ssize_t (*store)(struct gdlm_ls *, const char *, size_t); }; -static struct gdlm_attr gdlm_attr_block = { - .attr = {.name = "block", .mode = S_IRUGO | S_IWUSR}, - .show = gdlm_block_show, - .store = gdlm_block_store -}; +#define GDLM_ATTR(_name,_mode,_show,_store) \ +static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store) -static struct gdlm_attr gdlm_attr_mounted = { - .attr = {.name = "mounted", .mode = S_IRUGO | S_IWUSR}, - .show = gdlm_mounted_show, - .store = gdlm_mounted_store -}; - -static struct gdlm_attr gdlm_attr_withdraw = { - .attr = {.name = "withdraw", .mode = S_IRUGO | S_IWUSR}, - .show = gdlm_withdraw_show, - .store = gdlm_withdraw_store -}; - -static struct gdlm_attr gdlm_attr_jid = { - .attr = {.name = "jid", .mode = S_IRUGO | S_IWUSR}, - .show = gdlm_jid_show, - .store = gdlm_jid_store -}; - -static struct gdlm_attr gdlm_attr_first = { - .attr = {.name = "first", .mode = S_IRUGO | S_IWUSR}, - .show = gdlm_first_show, - .store = gdlm_first_store -}; - -static struct gdlm_attr gdlm_attr_first_done = { - .attr = {.name = "first_done", .mode = S_IRUGO}, - .show = gdlm_first_done_show, -}; - -static struct gdlm_attr gdlm_attr_recover = { - .attr = {.name = "recover", .mode = S_IRUGO | S_IWUSR}, - .show = gdlm_recover_show, - .store = gdlm_recover_store -}; - -static struct gdlm_attr gdlm_attr_recover_done = { - .attr = {.name = "recover_done", .mode = S_IRUGO | S_IWUSR}, - .show = gdlm_recover_done_show, -}; - -static struct gdlm_attr gdlm_attr_cluster = { - .attr = {.name = "cluster", .mode = S_IRUGO | S_IWUSR}, - .show = gdlm_cluster_show, -}; - -static struct gdlm_attr gdlm_attr_options = { - .attr = {.name = "options", .mode = S_IRUGO | S_IWUSR}, - .show = gdlm_options_show, -}; +GDLM_ATTR(proto_name, 0444, proto_name_show, NULL); +GDLM_ATTR(block, 0644, block_show, block_store); +GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store); +GDLM_ATTR(id, 0444, id_show, NULL); +GDLM_ATTR(jid, 0444, jid_show, NULL); +GDLM_ATTR(first, 0444, first_show, NULL); +GDLM_ATTR(first_done, 0444, first_done_show, NULL); +GDLM_ATTR(recover, 0644, recover_show, recover_store); +GDLM_ATTR(recover_done, 0444, recover_done_show, NULL); static struct attribute *gdlm_attrs[] = { + &gdlm_attr_proto_name.attr, &gdlm_attr_block.attr, - &gdlm_attr_mounted.attr, &gdlm_attr_withdraw.attr, + &gdlm_attr_id.attr, &gdlm_attr_jid.attr, &gdlm_attr_first.attr, &gdlm_attr_first_done.attr, &gdlm_attr_recover.attr, &gdlm_attr_recover_done.attr, - &gdlm_attr_cluster.attr, - &gdlm_attr_options.attr, NULL, }; @@ -276,20 +174,25 @@ static struct kset gdlm_kset = { .ktype = &gdlm_ktype, }; -int gdlm_kobject_setup(struct gdlm_ls *ls) +int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj) { int error; - error = kobject_set_name(&ls->kobj, "%s", ls->fsname); - if (error) + error = kobject_set_name(&ls->kobj, "%s", "lock_module"); + if (error) { + log_error("can't set kobj name %d", error); return error; + } ls->kobj.kset = &gdlm_kset; ls->kobj.ktype = &gdlm_ktype; + ls->kobj.parent = fskobj; error = kobject_register(&ls->kobj); + if (error) + log_error("can't register kobj %d", error); - return 0; + return error; } void gdlm_kobject_release(struct gdlm_ls *ls) diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c index 22bbe6d3a5ae..6fe669cd334b 100644 --- a/fs/gfs2/locking/dlm/thread.c +++ b/fs/gfs2/locking/dlm/thread.c @@ -1,15 +1,11 @@ -/****************************************************************************** -******************************************************************************* -** -** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. -** -** This copyrighted material is made available to anyone wishing to use, -** modify, copy, or redistribute it subject to the terms and conditions -** of the GNU General Public License v.2. -** -******************************************************************************* -******************************************************************************/ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ #include "lock_dlm.h" @@ -26,15 +22,10 @@ static void queue_submit(struct gdlm_lock *lp) wake_up(&ls->thread_wait); } -static void process_submit(struct gdlm_lock *lp) -{ - gdlm_do_lock(lp, NULL); -} - static void process_blocking(struct gdlm_lock *lp, int bast_mode) { struct gdlm_ls *ls = lp->ls; - unsigned int cb; + unsigned int cb = 0; switch (gdlm_make_lmstate(bast_mode)) { case LM_ST_EXCLUSIVE: @@ -47,7 +38,7 @@ static void process_blocking(struct gdlm_lock *lp, int bast_mode) cb = LM_CB_NEED_S; break; default: - GDLM_ASSERT(0, printk("unknown bast mode %u\n",lp->bast_mode);); + gdlm_assert(0, "unknown bast mode %u", lp->bast_mode); } ls->fscb(ls->fsdata, cb, &lp->lockname); @@ -62,9 +53,9 @@ static void process_complete(struct gdlm_lock *lp) memset(&acb, 0, sizeof(acb)); if (lp->lksb.sb_status == -DLM_ECANCEL) { - log_all("complete dlm cancel %x,%"PRIx64" flags %lx", - lp->lockname.ln_type, lp->lockname.ln_number, - lp->flags); + log_info("complete dlm cancel %x,%llx flags %lx", + lp->lockname.ln_type, lp->lockname.ln_number, + lp->flags); lp->req = lp->cur; acb.lc_ret |= LM_OUT_CANCELED; @@ -75,9 +66,9 @@ static void process_complete(struct gdlm_lock *lp) if (test_and_clear_bit(LFL_DLM_UNLOCK, &lp->flags)) { if (lp->lksb.sb_status != -DLM_EUNLOCK) { - log_all("unlock sb_status %d %x,%"PRIx64" flags %lx", - lp->lksb.sb_status, lp->lockname.ln_type, - lp->lockname.ln_number, lp->flags); + log_info("unlock sb_status %d %x,%llx flags %lx", + lp->lksb.sb_status, lp->lockname.ln_type, + lp->lockname.ln_number, lp->flags); return; } @@ -108,8 +99,8 @@ static void process_complete(struct gdlm_lock *lp) */ if (test_and_clear_bit(LFL_CANCEL, &lp->flags)) { - log_all("complete internal cancel %x,%"PRIx64"", - lp->lockname.ln_type, lp->lockname.ln_number); + log_info("complete internal cancel %x,%llx", + lp->lockname.ln_type, lp->lockname.ln_number); lp->req = lp->cur; acb.lc_ret |= LM_OUT_CANCELED; goto out; @@ -130,9 +121,9 @@ static void process_complete(struct gdlm_lock *lp) } /* this could only happen with cancels I think */ - log_all("ast sb_status %d %x,%"PRIx64" flags %lx", - lp->lksb.sb_status, lp->lockname.ln_type, - lp->lockname.ln_number, lp->flags); + log_info("ast sb_status %d %x,%llx flags %lx", + lp->lksb.sb_status, lp->lockname.ln_type, + lp->lockname.ln_number, lp->flags); return; } @@ -152,8 +143,10 @@ static void process_complete(struct gdlm_lock *lp) */ if (test_and_clear_bit(LFL_REREQUEST, &lp->flags)) { - GDLM_ASSERT(lp->req == DLM_LOCK_NL,); - GDLM_ASSERT(lp->prev_req > DLM_LOCK_NL,); + gdlm_assert(lp->req == DLM_LOCK_NL, "%x,%llx", + lp->lockname.ln_type, lp->lockname.ln_number); + gdlm_assert(lp->prev_req > DLM_LOCK_NL, "%x,%llx", + lp->lockname.ln_type, lp->lockname.ln_number); lp->cur = DLM_LOCK_NL; lp->req = lp->prev_req; @@ -189,7 +182,7 @@ static void process_complete(struct gdlm_lock *lp) lp->lkf |= DLM_LKF_CONVERT; lp->lkf &= ~DLM_LKF_CONVDEADLK; - log_debug("rereq %x,%"PRIx64" id %x %d,%d", + log_debug("rereq %x,%llx id %x %d,%d", lp->lockname.ln_type, lp->lockname.ln_number, lp->lksb.sb_lkid, lp->cur, lp->req); @@ -315,7 +308,7 @@ static int gdlm_thread(void *data) process_blocking(lp, blocking); else if (submit) - process_submit(lp); + gdlm_do_lock(lp, NULL); if (drop) ls->fscb(ls->fsdata, LM_CB_DROPLOCKS, NULL); @@ -334,7 +327,7 @@ int gdlm_init_threads(struct gdlm_ls *ls) p = kthread_run(gdlm_thread, ls, "lock_dlm1"); error = IS_ERR(p); if (error) { - log_all("can't start lock_dlm1 thread %d", error); + log_error("can't start lock_dlm1 thread %d", error); return error; } ls->thread1 = p; @@ -342,7 +335,7 @@ int gdlm_init_threads(struct gdlm_ls *ls) p = kthread_run(gdlm_thread, ls, "lock_dlm2"); error = IS_ERR(p); if (error) { - log_all("can't start lock_dlm2 thread %d", error); + log_error("can't start lock_dlm2 thread %d", error); kthread_stop(ls->thread1); return error; } diff --git a/fs/gfs2/locking/nolock/lock_nolock.mod.c b/fs/gfs2/locking/nolock/lock_nolock.mod.c deleted file mode 100644 index ae92522b2182..000000000000 --- a/fs/gfs2/locking/nolock/lock_nolock.mod.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include - -MODULE_INFO(vermagic, VERMAGIC_STRING); - -#undef unix -struct module __this_module -__attribute__((section(".gnu.linkonce.this_module"))) = { - .name = __stringify(KBUILD_MODNAME), - .init = init_module, -#ifdef CONFIG_MODULE_UNLOAD - .exit = cleanup_module, -#endif -}; - -static const struct modversion_info ____versions[] -__attribute_used__ -__attribute__((section("__versions"))) = { - { 0x316962fc, "struct_module" }, - { 0x5a34a45c, "__kmalloc" }, - { 0x724beef2, "malloc_sizes" }, - { 0x3fa03a97, "memset" }, - { 0xc16fe12d, "__memcpy" }, - { 0xdd132261, "printk" }, - { 0x859204af, "sscanf" }, - { 0x3656bf5a, "lock_kernel" }, - { 0x1e6d26a8, "strstr" }, - { 0x41ede9df, "lm_register_proto" }, - { 0xb1f975aa, "unlock_kernel" }, - { 0x87b0b01f, "posix_lock_file_wait" }, - { 0x75f29cfd, "kmem_cache_alloc" }, - { 0x69384280, "lm_unregister_proto" }, - { 0x37a0cba, "kfree" }, - { 0x5d16bfe6, "posix_test_lock" }, -}; - -static const char __module_depends[] -__attribute_used__ -__attribute__((section(".modinfo"))) = -"depends=gfs2"; - - -MODULE_INFO(srcversion, "123E446F965A386A0C017C4"); diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index d3919e471163..b716e336c073 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -1,15 +1,11 @@ -/****************************************************************************** -******************************************************************************* -** -** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. -** -** This copyrighted material is made available to anyone wishing to use, -** modify, copy, or redistribute it subject to the terms and conditions -** of the GNU General Public License v.2. -** -******************************************************************************* -******************************************************************************/ +/* + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ #include #include @@ -27,23 +23,11 @@ struct nolock_lockspace { struct lm_lockops nolock_ops; -/** - * nolock_mount - mount a nolock lockspace - * @table_name: the name of the space to mount - * @host_data: host specific data - * @cb: the callback - * @fsdata: - * @min_lvb_size: - * @flags: - * @lockstruct: the structure of crap to fill in - * - * Returns: 0 on success, -EXXX on failure - */ - static int nolock_mount(char *table_name, char *host_data, lm_callback_t cb, lm_fsdata_t *fsdata, unsigned int min_lvb_size, int flags, - struct lm_lockstruct *lockstruct) + struct lm_lockstruct *lockstruct, + struct kobject *fskobj) { char *c; unsigned int jid; @@ -77,34 +61,16 @@ static int nolock_mount(char *table_name, char *host_data, return 0; } -/** - * nolock_others_may_mount - unmount a lock space - * @lockspace: the lockspace to unmount - * - */ - static void nolock_others_may_mount(lm_lockspace_t *lockspace) { } -/** - * nolock_unmount - unmount a lock space - * @lockspace: the lockspace to unmount - * - */ - static void nolock_unmount(lm_lockspace_t *lockspace) { struct nolock_lockspace *nl = (struct nolock_lockspace *)lockspace; kfree(nl); } -/** - * nolock_withdraw - withdraw from a lock space - * @lockspace: the lockspace - * - */ - static void nolock_withdraw(lm_lockspace_t *lockspace) { } @@ -164,12 +130,6 @@ static unsigned int nolock_unlock(lm_lock_t *lock, unsigned int cur_state) return 0; } -/** - * nolock_cancel - cancel a request on a lock - * @lock: the lock to cancel request for - * - */ - static void nolock_cancel(lm_lock_t *lock) { } @@ -219,16 +179,6 @@ static void nolock_sync_lvb(lm_lock_t *lock, char *lvb) { } -/** - * nolock_plock_get - - * @lockspace: the lockspace - * @name: - * @file: - * @fl: - * - * Returns: errno - */ - static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl) { @@ -244,17 +194,6 @@ static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, return 0; } -/** - * nolock_plock - - * @lockspace: the lockspace - * @name: - * @file: - * @cmd: - * @fl: - * - * Returns: errno - */ - static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, struct file *file, int cmd, struct file_lock *fl) { @@ -265,16 +204,6 @@ static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, return error; } -/** - * nolock_punlock - - * @lockspace: the lockspace - * @name: - * @file: - * @fl: - * - * Returns: errno - */ - static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl) { @@ -285,13 +214,6 @@ static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, return error; } -/** - * nolock_recovery_done - reset the expired locks for a given jid - * @lockspace: the lockspace - * @jid: the jid - * - */ - static void nolock_recovery_done(lm_lockspace_t *lockspace, unsigned int jid, unsigned int message) { @@ -318,17 +240,11 @@ struct lm_lockops nolock_ops = { .lm_owner = THIS_MODULE, }; -/** - * init_nolock - Initialize the nolock module - * - * Returns: 0 on success, -EXXX on failure - */ - int __init init_nolock(void) { int error; - error = lm_register_proto(&nolock_ops); + error = gfs_register_lockproto(&nolock_ops); if (error) { printk("lock_nolock: can't register protocol: %d\n", error); return error; @@ -338,14 +254,9 @@ int __init init_nolock(void) return 0; } -/** - * exit_nolock - cleanup the nolock module - * - */ - void __exit exit_nolock(void) { - lm_unregister_proto(&nolock_ops); + gfs_unregister_lockproto(&nolock_ops); } module_init(init_nolock); diff --git a/include/linux/lock_dlm_plock.h b/include/linux/lock_dlm_plock.h new file mode 100644 index 000000000000..007b07a178ab --- /dev/null +++ b/include/linux/lock_dlm_plock.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2005 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __LOCK_DLM_PLOCK_DOT_H__ +#define __LOCK_DLM_PLOCK_DOT_H__ + +#define GDLM_PLOCK_MISC_NAME "lock_dlm_plock" + +#define GDLM_PLOCK_VERSION_MAJOR 1 +#define GDLM_PLOCK_VERSION_MINOR 0 +#define GDLM_PLOCK_VERSION_PATCH 0 + +enum { + GDLM_PLOCK_OP_LOCK = 1, + GDLM_PLOCK_OP_UNLOCK, + GDLM_PLOCK_OP_GET, +}; + +struct gdlm_plock_info { + __u32 version[3]; + __u8 optype; + __u8 ex; + __u8 wait; + __u8 pad; + __u32 pid; + __s32 nodeid; + __s32 rv; + __u32 fsid; + __u64 number; + __u64 start; + __u64 end; +}; + +#endif + From cd1344fe322cd9d95b2c0f011d6766677cfcb29b Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 18 Jan 2006 08:53:38 +0000 Subject: [PATCH 008/292] [GFS2] Remove unused ioctls and unused structure Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- include/linux/gfs2_ioctl.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/include/linux/gfs2_ioctl.h b/include/linux/gfs2_ioctl.h index dde9840b1c30..ca9632862833 100644 --- a/include/linux/gfs2_ioctl.h +++ b/include/linux/gfs2_ioctl.h @@ -14,19 +14,8 @@ /* Ioctls implemented */ -#define GFS2_IOCTL_IDENTIFY _GFS2C_(1) -#define GFS2_IOCTL_SUPER _GFS2C_(2) #define GFS2_IOCTL_SETFLAGS _GFS2C_(3) #define GFS2_IOCTL_GETFLAGS _GFS2C_(4) -struct gfs2_ioctl { - unsigned int gi_argc; - const char **gi_argv; - - char __user *gi_data; - unsigned int gi_size; - uint64_t gi_offset; -}; - #endif /* ___GFS2_IOCTL_DOT_H__ */ From e47314207032cfd1157b8c377df162839b32ea6f Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 18 Jan 2006 09:21:38 +0000 Subject: [PATCH 009/292] [GFS2] Add documentation for GFS2 Signed-off-by: David Teigland Signed-off-by: Steve Whitehouse --- Documentation/filesystems/gfs2.txt | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Documentation/filesystems/gfs2.txt diff --git a/Documentation/filesystems/gfs2.txt b/Documentation/filesystems/gfs2.txt new file mode 100644 index 000000000000..4a060d38bed8 --- /dev/null +++ b/Documentation/filesystems/gfs2.txt @@ -0,0 +1,44 @@ +Global File System +------------------ + +http://sources.redhat.com/cluster/ + +GFS is a cluster file system. It allows a cluster of computers to +simultaneously use a block device that is shared between them (with FC, +iSCSI, NBD, etc). GFS reads and writes to the block device like a local +file system, but also uses a lock module to allow the computers coordinate +their I/O so file system consistency is maintained. One of the nifty +features of GFS is perfect consistency -- changes made to the file system +on one machine show up immediately on all other machines in the cluster. + +GFS uses interchangable inter-node locking mechanisms. Different lock +modules can plug into GFS and each file system selects the appropriate +lock module at mount time. Lock modules include: + + lock_nolock -- allows gfs to be used as a local file system + + lock_dlm -- uses a distributed lock manager (dlm) for inter-node locking + The dlm is found at linux/fs/dlm/ + +In addition to interfacing with an external locking manager, a gfs lock +module is responsible for interacting with external cluster management +systems. Lock_dlm depends on user space cluster management systems found +at the URL above. + +To use gfs as a local file system, no external clustering systems are +needed, simply: + + $ gfs2_mkfs -p lock_nolock -j 1 /dev/block_device + $ mount -t gfs2 /dev/block_device /dir + +GFS2 is not on-disk compatible with previous versions of GFS. + +The following man pages can be found at the URL above: + gfs2_mkfs to make a filesystem + gfs2_fsck to repair a filesystem + gfs2_grow to expand a filesystem online + gfs2_jadd to add journals to a filesystem online + gfs2_tool to manipulate, examine and tune a filesystem + gfs2_quota to examine and change quota values in a filesystem + mount.gfs2 to find mount options + From e7fd41792fc0ee52a05fcaac87511f118328d147 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 18 Jan 2006 09:30:29 +0000 Subject: [PATCH 010/292] [DLM] The core of the DLM for GFS2/CLVM This is the core of the distributed lock manager which is required to use GFS2 as a cluster filesystem. It is also used by CLVM and can be used as a standalone lock manager independantly of either of these two projects. It implements VAX-style locking modes. Signed-off-by: David Teigland Signed-off-by: Steve Whitehouse --- fs/Kconfig | 1 + fs/Makefile | 1 + fs/dlm/Kconfig | 30 + fs/dlm/Makefile | 21 + fs/dlm/ast.c | 167 ++ fs/dlm/ast.h | 26 + fs/dlm/config.c | 787 ++++++++ fs/dlm/config.h | 42 + fs/dlm/debug_fs.c | 310 ++++ fs/dlm/device.c | 1084 +++++++++++ fs/dlm/dir.c | 423 +++++ fs/dlm/dir.h | 30 + fs/dlm/dlm_internal.h | 518 ++++++ fs/dlm/lock.c | 3610 ++++++++++++++++++++++++++++++++++++ fs/dlm/lock.h | 50 + fs/dlm/lockspace.c | 666 +++++++ fs/dlm/lockspace.h | 24 + fs/dlm/lowcomms.c | 1218 ++++++++++++ fs/dlm/lowcomms.h | 25 + fs/dlm/lvb_table.h | 18 + fs/dlm/main.c | 89 + fs/dlm/member.c | 314 ++++ fs/dlm/member.h | 24 + fs/dlm/memory.c | 122 ++ fs/dlm/memory.h | 31 + fs/dlm/midcomms.c | 140 ++ fs/dlm/midcomms.h | 21 + fs/dlm/rcom.c | 460 +++++ fs/dlm/rcom.h | 24 + fs/dlm/recover.c | 762 ++++++++ fs/dlm/recover.h | 34 + fs/dlm/recoverd.c | 285 +++ fs/dlm/recoverd.h | 24 + fs/dlm/requestqueue.c | 184 ++ fs/dlm/requestqueue.h | 22 + fs/dlm/util.c | 173 ++ fs/dlm/util.h | 22 + include/linux/dlm.h | 312 ++++ include/linux/dlm_device.h | 84 + 39 files changed, 12178 insertions(+) create mode 100644 fs/dlm/Kconfig create mode 100644 fs/dlm/Makefile create mode 100644 fs/dlm/ast.c create mode 100644 fs/dlm/ast.h create mode 100644 fs/dlm/config.c create mode 100644 fs/dlm/config.h create mode 100644 fs/dlm/debug_fs.c create mode 100644 fs/dlm/device.c create mode 100644 fs/dlm/dir.c create mode 100644 fs/dlm/dir.h create mode 100644 fs/dlm/dlm_internal.h create mode 100644 fs/dlm/lock.c create mode 100644 fs/dlm/lock.h create mode 100644 fs/dlm/lockspace.c create mode 100644 fs/dlm/lockspace.h create mode 100644 fs/dlm/lowcomms.c create mode 100644 fs/dlm/lowcomms.h create mode 100644 fs/dlm/lvb_table.h create mode 100644 fs/dlm/main.c create mode 100644 fs/dlm/member.c create mode 100644 fs/dlm/member.h create mode 100644 fs/dlm/memory.c create mode 100644 fs/dlm/memory.h create mode 100644 fs/dlm/midcomms.c create mode 100644 fs/dlm/midcomms.h create mode 100644 fs/dlm/rcom.c create mode 100644 fs/dlm/rcom.h create mode 100644 fs/dlm/recover.c create mode 100644 fs/dlm/recover.h create mode 100644 fs/dlm/recoverd.c create mode 100644 fs/dlm/recoverd.h create mode 100644 fs/dlm/requestqueue.c create mode 100644 fs/dlm/requestqueue.h create mode 100644 fs/dlm/util.c create mode 100644 fs/dlm/util.h create mode 100644 include/linux/dlm.h create mode 100644 include/linux/dlm_device.h diff --git a/fs/Kconfig b/fs/Kconfig index bec8afa5704d..3a32f3f97e9b 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -1831,6 +1831,7 @@ source "fs/partitions/Kconfig" endmenu source "fs/nls/Kconfig" +source "fs/dlm/Kconfig" endmenu diff --git a/fs/Makefile b/fs/Makefile index 0922727732c5..b298f4fdc6f2 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -48,6 +48,7 @@ obj-$(CONFIG_SYSFS) += sysfs/ obj-y += devpts/ obj-$(CONFIG_PROFILING) += dcookies.o +obj-$(CONFIG_DLM) += dlm/ # Do not add any filesystems before this line obj-$(CONFIG_REISERFS_FS) += reiserfs/ diff --git a/fs/dlm/Kconfig b/fs/dlm/Kconfig new file mode 100644 index 000000000000..d01f735e6e06 --- /dev/null +++ b/fs/dlm/Kconfig @@ -0,0 +1,30 @@ +menu "Distributed Lock Manager" + depends on INET && EXPERIMENTAL + +config DLM + tristate "Distributed Lock Manager (DLM)" + depends on SYSFS + depends on IPV6 || IPV6=n + select IP_SCTP + select CONFIGFS_FS + help + A general purpose distributed lock manager for kernel or userspace + applications. + +config DLM_DEVICE + tristate "DLM device for userspace access" + depends on DLM + help + This module creates a misc device through which the dlm lockspace + and locking functions become available to userspace applications + (usually through the libdlm library). + +config DLM_DEBUG + bool "DLM debugging" + depends on DLM + help + Under the debugfs mount point, the name of each lockspace will + appear as a file in the "dlm" directory. The output is the + list of resource and locks the local node knows about. + +endmenu diff --git a/fs/dlm/Makefile b/fs/dlm/Makefile new file mode 100644 index 000000000000..1e6232e7d8e5 --- /dev/null +++ b/fs/dlm/Makefile @@ -0,0 +1,21 @@ +obj-$(CONFIG_DLM) += dlm.o +obj-$(CONFIG_DLM_DEVICE) += dlm_device.o + +dlm-y := ast.o \ + config.o \ + dir.o \ + lock.o \ + lockspace.o \ + lowcomms.o \ + main.o \ + member.o \ + memory.o \ + midcomms.o \ + rcom.o \ + recover.o \ + recoverd.o \ + requestqueue.o \ + util.o +dlm-$(CONFIG_DLM_DEBUG) += debug_fs.o + +dlm_device-y := device.o diff --git a/fs/dlm/ast.c b/fs/dlm/ast.c new file mode 100644 index 000000000000..2bd1c5e1a72c --- /dev/null +++ b/fs/dlm/ast.c @@ -0,0 +1,167 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "lock.h" +#include "ast.h" + +#define WAKE_ASTS 0 + +static struct list_head ast_queue; +static spinlock_t ast_queue_lock; +static struct task_struct * astd_task; +static unsigned long astd_wakeflags; +static struct semaphore astd_running; + + +void dlm_del_ast(struct dlm_lkb *lkb) +{ + spin_lock(&ast_queue_lock); + if (lkb->lkb_ast_type & (AST_COMP | AST_BAST)) + list_del(&lkb->lkb_astqueue); + spin_unlock(&ast_queue_lock); +} + +void dlm_add_ast(struct dlm_lkb *lkb, int type) +{ + spin_lock(&ast_queue_lock); + if (!(lkb->lkb_ast_type & (AST_COMP | AST_BAST))) { + kref_get(&lkb->lkb_ref); + list_add_tail(&lkb->lkb_astqueue, &ast_queue); + } + lkb->lkb_ast_type |= type; + spin_unlock(&ast_queue_lock); + + set_bit(WAKE_ASTS, &astd_wakeflags); + wake_up_process(astd_task); +} + +static void process_asts(void) +{ + struct dlm_ls *ls = NULL; + struct dlm_rsb *r = NULL; + struct dlm_lkb *lkb; + void (*cast) (long param); + void (*bast) (long param, int mode); + int type = 0, found, bmode; + + for (;;) { + found = FALSE; + spin_lock(&ast_queue_lock); + list_for_each_entry(lkb, &ast_queue, lkb_astqueue) { + r = lkb->lkb_resource; + ls = r->res_ls; + + if (dlm_locking_stopped(ls)) + continue; + + list_del(&lkb->lkb_astqueue); + type = lkb->lkb_ast_type; + lkb->lkb_ast_type = 0; + found = TRUE; + break; + } + spin_unlock(&ast_queue_lock); + + if (!found) + break; + + cast = lkb->lkb_astaddr; + bast = lkb->lkb_bastaddr; + bmode = lkb->lkb_bastmode; + + if ((type & AST_COMP) && cast) + cast(lkb->lkb_astparam); + + /* FIXME: Is it safe to look at lkb_grmode here + without doing a lock_rsb() ? + Look at other checks in v1 to avoid basts. */ + + if ((type & AST_BAST) && bast) + if (!dlm_modes_compat(lkb->lkb_grmode, bmode)) + bast(lkb->lkb_astparam, bmode); + + /* this removes the reference added by dlm_add_ast + and may result in the lkb being freed */ + dlm_put_lkb(lkb); + + schedule(); + } +} + +static inline int no_asts(void) +{ + int ret; + + spin_lock(&ast_queue_lock); + ret = list_empty(&ast_queue); + spin_unlock(&ast_queue_lock); + return ret; +} + +static int dlm_astd(void *data) +{ + while (!kthread_should_stop()) { + set_current_state(TASK_INTERRUPTIBLE); + if (!test_bit(WAKE_ASTS, &astd_wakeflags)) + schedule(); + set_current_state(TASK_RUNNING); + + down(&astd_running); + if (test_and_clear_bit(WAKE_ASTS, &astd_wakeflags)) + process_asts(); + up(&astd_running); + } + return 0; +} + +void dlm_astd_wake(void) +{ + if (!no_asts()) { + set_bit(WAKE_ASTS, &astd_wakeflags); + wake_up_process(astd_task); + } +} + +int dlm_astd_start(void) +{ + struct task_struct *p; + int error = 0; + + INIT_LIST_HEAD(&ast_queue); + spin_lock_init(&ast_queue_lock); + init_MUTEX(&astd_running); + + p = kthread_run(dlm_astd, NULL, "dlm_astd"); + if (IS_ERR(p)) + error = PTR_ERR(p); + else + astd_task = p; + return error; +} + +void dlm_astd_stop(void) +{ + kthread_stop(astd_task); +} + +void dlm_astd_suspend(void) +{ + down(&astd_running); +} + +void dlm_astd_resume(void) +{ + up(&astd_running); +} + diff --git a/fs/dlm/ast.h b/fs/dlm/ast.h new file mode 100644 index 000000000000..6ee276c74c52 --- /dev/null +++ b/fs/dlm/ast.h @@ -0,0 +1,26 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __ASTD_DOT_H__ +#define __ASTD_DOT_H__ + +void dlm_add_ast(struct dlm_lkb *lkb, int type); +void dlm_del_ast(struct dlm_lkb *lkb); + +void dlm_astd_wake(void); +int dlm_astd_start(void); +void dlm_astd_stop(void); +void dlm_astd_suspend(void); +void dlm_astd_resume(void); + +#endif + diff --git a/fs/dlm/config.c b/fs/dlm/config.c new file mode 100644 index 000000000000..024ace9973a8 --- /dev/null +++ b/fs/dlm/config.c @@ -0,0 +1,787 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include +#include +#include +#include + +#include "config.h" + +/* + * /config/dlm//spaces//nodes//nodeid + * /config/dlm//spaces//nodes//weight + * /config/dlm//comms//nodeid + * /config/dlm//comms//local + * /config/dlm//comms//addr + * The level is useless, but I haven't figured out how to avoid it. + */ + +static struct config_group *space_list; +static struct config_group *comm_list; +static struct comm *local_comm; + +struct clusters; +struct cluster; +struct spaces; +struct space; +struct comms; +struct comm; +struct nodes; +struct node; + +static struct config_group *make_cluster(struct config_group *, const char *); +static void drop_cluster(struct config_group *, struct config_item *); +static void release_cluster(struct config_item *); +static struct config_group *make_space(struct config_group *, const char *); +static void drop_space(struct config_group *, struct config_item *); +static void release_space(struct config_item *); +static struct config_item *make_comm(struct config_group *, const char *); +static void drop_comm(struct config_group *, struct config_item *); +static void release_comm(struct config_item *); +static struct config_item *make_node(struct config_group *, const char *); +static void drop_node(struct config_group *, struct config_item *); +static void release_node(struct config_item *); + +static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a, + char *buf); +static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a, + const char *buf, size_t len); +static ssize_t show_node(struct config_item *i, struct configfs_attribute *a, + char *buf); +static ssize_t store_node(struct config_item *i, struct configfs_attribute *a, + const char *buf, size_t len); + +static ssize_t comm_nodeid_read(struct comm *cm, char *buf); +static ssize_t comm_nodeid_write(struct comm *cm, const char *buf, size_t len); +static ssize_t comm_local_read(struct comm *cm, char *buf); +static ssize_t comm_local_write(struct comm *cm, const char *buf, size_t len); +static ssize_t comm_addr_write(struct comm *cm, const char *buf, size_t len); +static ssize_t node_nodeid_read(struct node *nd, char *buf); +static ssize_t node_nodeid_write(struct node *nd, const char *buf, size_t len); +static ssize_t node_weight_read(struct node *nd, char *buf); +static ssize_t node_weight_write(struct node *nd, const char *buf, size_t len); + +enum { + COMM_ATTR_NODEID = 0, + COMM_ATTR_LOCAL, + COMM_ATTR_ADDR, +}; + +struct comm_attribute { + struct configfs_attribute attr; + ssize_t (*show)(struct comm *, char *); + ssize_t (*store)(struct comm *, const char *, size_t); +}; + +static struct comm_attribute comm_attr_nodeid = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "nodeid", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = comm_nodeid_read, + .store = comm_nodeid_write, +}; + +static struct comm_attribute comm_attr_local = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "local", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = comm_local_read, + .store = comm_local_write, +}; + +static struct comm_attribute comm_attr_addr = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "addr", + .ca_mode = S_IRUGO | S_IWUSR }, + .store = comm_addr_write, +}; + +static struct configfs_attribute *comm_attrs[] = { + [COMM_ATTR_NODEID] = &comm_attr_nodeid.attr, + [COMM_ATTR_LOCAL] = &comm_attr_local.attr, + [COMM_ATTR_ADDR] = &comm_attr_addr.attr, + NULL, +}; + +enum { + NODE_ATTR_NODEID = 0, + NODE_ATTR_WEIGHT, +}; + +struct node_attribute { + struct configfs_attribute attr; + ssize_t (*show)(struct node *, char *); + ssize_t (*store)(struct node *, const char *, size_t); +}; + +static struct node_attribute node_attr_nodeid = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "nodeid", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = node_nodeid_read, + .store = node_nodeid_write, +}; + +static struct node_attribute node_attr_weight = { + .attr = { .ca_owner = THIS_MODULE, + .ca_name = "weight", + .ca_mode = S_IRUGO | S_IWUSR }, + .show = node_weight_read, + .store = node_weight_write, +}; + +static struct configfs_attribute *node_attrs[] = { + [NODE_ATTR_NODEID] = &node_attr_nodeid.attr, + [NODE_ATTR_WEIGHT] = &node_attr_weight.attr, + NULL, +}; + +struct clusters { + struct configfs_subsystem subsys; +}; + +struct cluster { + struct config_group group; +}; + +struct spaces { + struct config_group ss_group; +}; + +struct space { + struct config_group group; + struct list_head members; + struct semaphore members_lock; + int members_count; +}; + +struct comms { + struct config_group cs_group; +}; + +struct comm { + struct config_item item; + int nodeid; + int local; + int addr_count; + struct sockaddr_storage *addr[DLM_MAX_ADDR_COUNT]; +}; + +struct nodes { + struct config_group ns_group; +}; + +struct node { + struct config_item item; + struct list_head list; /* space->members */ + int nodeid; + int weight; +}; + +static struct configfs_group_operations clusters_ops = { + .make_group = make_cluster, + .drop_item = drop_cluster, +}; + +static struct configfs_item_operations cluster_ops = { + .release = release_cluster, +}; + +static struct configfs_group_operations spaces_ops = { + .make_group = make_space, + .drop_item = drop_space, +}; + +static struct configfs_item_operations space_ops = { + .release = release_space, +}; + +static struct configfs_group_operations comms_ops = { + .make_item = make_comm, + .drop_item = drop_comm, +}; + +static struct configfs_item_operations comm_ops = { + .release = release_comm, + .show_attribute = show_comm, + .store_attribute = store_comm, +}; + +static struct configfs_group_operations nodes_ops = { + .make_item = make_node, + .drop_item = drop_node, +}; + +static struct configfs_item_operations node_ops = { + .release = release_node, + .show_attribute = show_node, + .store_attribute = store_node, +}; + +static struct config_item_type clusters_type = { + .ct_group_ops = &clusters_ops, + .ct_owner = THIS_MODULE, +}; + +static struct config_item_type cluster_type = { + .ct_item_ops = &cluster_ops, + .ct_owner = THIS_MODULE, +}; + +static struct config_item_type spaces_type = { + .ct_group_ops = &spaces_ops, + .ct_owner = THIS_MODULE, +}; + +static struct config_item_type space_type = { + .ct_item_ops = &space_ops, + .ct_owner = THIS_MODULE, +}; + +static struct config_item_type comms_type = { + .ct_group_ops = &comms_ops, + .ct_owner = THIS_MODULE, +}; + +static struct config_item_type comm_type = { + .ct_item_ops = &comm_ops, + .ct_attrs = comm_attrs, + .ct_owner = THIS_MODULE, +}; + +static struct config_item_type nodes_type = { + .ct_group_ops = &nodes_ops, + .ct_owner = THIS_MODULE, +}; + +static struct config_item_type node_type = { + .ct_item_ops = &node_ops, + .ct_attrs = node_attrs, + .ct_owner = THIS_MODULE, +}; + +static struct cluster *to_cluster(struct config_item *i) +{ + return i ? container_of(to_config_group(i), struct cluster, group):NULL; +} + +static struct space *to_space(struct config_item *i) +{ + return i ? container_of(to_config_group(i), struct space, group) : NULL; +} + +static struct comm *to_comm(struct config_item *i) +{ + return i ? container_of(i, struct comm, item) : NULL; +} + +static struct node *to_node(struct config_item *i) +{ + return i ? container_of(i, struct node, item) : NULL; +} + +static struct config_group *make_cluster(struct config_group *g, + const char *name) +{ + struct cluster *cl = NULL; + struct spaces *sps = NULL; + struct comms *cms = NULL; + void *gps = NULL; + + cl = kzalloc(sizeof(struct cluster), GFP_KERNEL); + gps = kcalloc(3, sizeof(struct config_group *), GFP_KERNEL); + sps = kzalloc(sizeof(struct spaces), GFP_KERNEL); + cms = kzalloc(sizeof(struct comms), GFP_KERNEL); + + if (!cl || !gps || !sps || !cms) + goto fail; + + config_group_init_type_name(&cl->group, name, &cluster_type); + config_group_init_type_name(&sps->ss_group, "spaces", &spaces_type); + config_group_init_type_name(&cms->cs_group, "comms", &comms_type); + + cl->group.default_groups = gps; + cl->group.default_groups[0] = &sps->ss_group; + cl->group.default_groups[1] = &cms->cs_group; + cl->group.default_groups[2] = NULL; + + space_list = &sps->ss_group; + comm_list = &cms->cs_group; + return &cl->group; + + fail: + kfree(cl); + kfree(gps); + kfree(sps); + kfree(cms); + return NULL; +} + +static void drop_cluster(struct config_group *g, struct config_item *i) +{ + struct cluster *cl = to_cluster(i); + struct config_item *tmp; + int j; + + for (j = 0; cl->group.default_groups[j]; j++) { + tmp = &cl->group.default_groups[j]->cg_item; + cl->group.default_groups[j] = NULL; + config_item_put(tmp); + } + + space_list = NULL; + comm_list = NULL; + + config_item_put(i); +} + +static void release_cluster(struct config_item *i) +{ + struct cluster *cl = to_cluster(i); + kfree(cl->group.default_groups); + kfree(cl); +} + +static struct config_group *make_space(struct config_group *g, const char *name) +{ + struct space *sp = NULL; + struct nodes *nds = NULL; + void *gps = NULL; + + sp = kzalloc(sizeof(struct space), GFP_KERNEL); + gps = kcalloc(2, sizeof(struct config_group *), GFP_KERNEL); + nds = kzalloc(sizeof(struct nodes), GFP_KERNEL); + + if (!sp || !gps || !nds) + goto fail; + + config_group_init_type_name(&sp->group, name, &space_type); + config_group_init_type_name(&nds->ns_group, "nodes", &nodes_type); + + sp->group.default_groups = gps; + sp->group.default_groups[0] = &nds->ns_group; + sp->group.default_groups[1] = NULL; + + INIT_LIST_HEAD(&sp->members); + init_MUTEX(&sp->members_lock); + sp->members_count = 0; + return &sp->group; + + fail: + kfree(sp); + kfree(gps); + kfree(nds); + return NULL; +} + +static void drop_space(struct config_group *g, struct config_item *i) +{ + struct space *sp = to_space(i); + struct config_item *tmp; + int j; + + /* assert list_empty(&sp->members) */ + + for (j = 0; sp->group.default_groups[j]; j++) { + tmp = &sp->group.default_groups[j]->cg_item; + sp->group.default_groups[j] = NULL; + config_item_put(tmp); + } + + config_item_put(i); +} + +static void release_space(struct config_item *i) +{ + struct space *sp = to_space(i); + kfree(sp->group.default_groups); + kfree(sp); +} + +static struct config_item *make_comm(struct config_group *g, const char *name) +{ + struct comm *cm; + + cm = kzalloc(sizeof(struct comm), GFP_KERNEL); + if (!cm) + return NULL; + + config_item_init_type_name(&cm->item, name, &comm_type); + cm->nodeid = -1; + cm->local = 0; + cm->addr_count = 0; + return &cm->item; +} + +static void drop_comm(struct config_group *g, struct config_item *i) +{ + struct comm *cm = to_comm(i); + if (local_comm == cm) + local_comm = NULL; + while (cm->addr_count--) + kfree(cm->addr[cm->addr_count]); + config_item_put(i); +} + +static void release_comm(struct config_item *i) +{ + struct comm *cm = to_comm(i); + kfree(cm); +} + +static struct config_item *make_node(struct config_group *g, const char *name) +{ + struct space *sp = to_space(g->cg_item.ci_parent); + struct node *nd; + + nd = kzalloc(sizeof(struct node), GFP_KERNEL); + if (!nd) + return NULL; + + config_item_init_type_name(&nd->item, name, &node_type); + nd->nodeid = -1; + nd->weight = 1; /* default weight of 1 if none is set */ + + down(&sp->members_lock); + list_add(&nd->list, &sp->members); + sp->members_count++; + up(&sp->members_lock); + + return &nd->item; +} + +static void drop_node(struct config_group *g, struct config_item *i) +{ + struct space *sp = to_space(g->cg_item.ci_parent); + struct node *nd = to_node(i); + + down(&sp->members_lock); + list_del(&nd->list); + sp->members_count--; + up(&sp->members_lock); + + config_item_put(i); +} + +static void release_node(struct config_item *i) +{ + struct node *nd = to_node(i); + kfree(nd); +} + +static struct clusters clusters_root = { + .subsys = { + .su_group = { + .cg_item = { + .ci_namebuf = "dlm", + .ci_type = &clusters_type, + }, + }, + }, +}; + +int dlm_config_init(void) +{ + config_group_init(&clusters_root.subsys.su_group); + init_MUTEX(&clusters_root.subsys.su_sem); + return configfs_register_subsystem(&clusters_root.subsys); +} + +void dlm_config_exit(void) +{ + configfs_unregister_subsystem(&clusters_root.subsys); +} + +/* + * Functions for user space to read/write attributes + */ + +static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a, + char *buf) +{ + struct comm *cm = to_comm(i); + struct comm_attribute *cma = + container_of(a, struct comm_attribute, attr); + return cma->show ? cma->show(cm, buf) : 0; +} + +static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a, + const char *buf, size_t len) +{ + struct comm *cm = to_comm(i); + struct comm_attribute *cma = + container_of(a, struct comm_attribute, attr); + return cma->store ? cma->store(cm, buf, len) : -EINVAL; +} + +static ssize_t comm_nodeid_read(struct comm *cm, char *buf) +{ + return sprintf(buf, "%d\n", cm->nodeid); +} + +static ssize_t comm_nodeid_write(struct comm *cm, const char *buf, size_t len) +{ + cm->nodeid = simple_strtol(buf, NULL, 0); + return len; +} + +static ssize_t comm_local_read(struct comm *cm, char *buf) +{ + return sprintf(buf, "%d\n", cm->local); +} + +static ssize_t comm_local_write(struct comm *cm, const char *buf, size_t len) +{ + cm->local= simple_strtol(buf, NULL, 0); + if (cm->local && !local_comm) + local_comm = cm; + return len; +} + +static ssize_t comm_addr_write(struct comm *cm, const char *buf, size_t len) +{ + struct sockaddr_storage *addr; + + if (len != sizeof(struct sockaddr_storage)) + return -EINVAL; + + if (cm->addr_count >= DLM_MAX_ADDR_COUNT) + return -ENOSPC; + + addr = kzalloc(sizeof(*addr), GFP_KERNEL); + if (!addr) + return -ENOMEM; + + memcpy(addr, buf, len); + cm->addr[cm->addr_count++] = addr; + return len; +} + +static ssize_t show_node(struct config_item *i, struct configfs_attribute *a, + char *buf) +{ + struct node *nd = to_node(i); + struct node_attribute *nda = + container_of(a, struct node_attribute, attr); + return nda->show ? nda->show(nd, buf) : 0; +} + +static ssize_t store_node(struct config_item *i, struct configfs_attribute *a, + const char *buf, size_t len) +{ + struct node *nd = to_node(i); + struct node_attribute *nda = + container_of(a, struct node_attribute, attr); + return nda->store ? nda->store(nd, buf, len) : -EINVAL; +} + +static ssize_t node_nodeid_read(struct node *nd, char *buf) +{ + return sprintf(buf, "%d\n", nd->nodeid); +} + +static ssize_t node_nodeid_write(struct node *nd, const char *buf, size_t len) +{ + nd->nodeid = simple_strtol(buf, NULL, 0); + return len; +} + +static ssize_t node_weight_read(struct node *nd, char *buf) +{ + return sprintf(buf, "%d\n", nd->weight); +} + +static ssize_t node_weight_write(struct node *nd, const char *buf, size_t len) +{ + nd->weight = simple_strtol(buf, NULL, 0); + return len; +} + +/* + * Functions for the dlm to get the info that's been configured + */ + +static struct space *get_space(char *name) +{ + if (!space_list) + return NULL; + return to_space(config_group_find_obj(space_list, name)); +} + +static void put_space(struct space *sp) +{ + config_item_put(&sp->group.cg_item); +} + +static struct comm *get_comm(int nodeid, struct sockaddr_storage *addr) +{ + struct config_item *i; + struct comm *cm = NULL; + int found = 0; + + if (!comm_list) + return NULL; + + down(&clusters_root.subsys.su_sem); + + list_for_each_entry(i, &comm_list->cg_children, ci_entry) { + cm = to_comm(i); + + if (nodeid) { + if (cm->nodeid != nodeid) + continue; + found = 1; + break; + } else { + if (!cm->addr_count || + memcmp(cm->addr[0], addr, sizeof(*addr))) + continue; + found = 1; + break; + } + } + up(&clusters_root.subsys.su_sem); + + if (found) + config_item_get(i); + else + cm = NULL; + return cm; +} + +static void put_comm(struct comm *cm) +{ + config_item_put(&cm->item); +} + +/* caller must free mem */ +int dlm_nodeid_list(char *lsname, int **ids_out) +{ + struct space *sp; + struct node *nd; + int i = 0, rv = 0; + int *ids; + + sp = get_space(lsname); + if (!sp) + return -EEXIST; + + down(&sp->members_lock); + if (!sp->members_count) { + rv = 0; + goto out; + } + + ids = kcalloc(sp->members_count, sizeof(int), GFP_KERNEL); + if (!ids) { + rv = -ENOMEM; + goto out; + } + + rv = sp->members_count; + list_for_each_entry(nd, &sp->members, list) + ids[i++] = nd->nodeid; + + if (rv != i) + printk("bad nodeid count %d %d\n", rv, i); + + *ids_out = ids; + out: + up(&sp->members_lock); + put_space(sp); + return rv; +} + +int dlm_node_weight(char *lsname, int nodeid) +{ + struct space *sp; + struct node *nd; + int w = -EEXIST; + + sp = get_space(lsname); + if (!sp) + goto out; + + down(&sp->members_lock); + list_for_each_entry(nd, &sp->members, list) { + if (nd->nodeid != nodeid) + continue; + w = nd->weight; + break; + } + up(&sp->members_lock); + put_space(sp); + out: + return w; +} + +int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr) +{ + struct comm *cm = get_comm(nodeid, NULL); + if (!cm) + return -EEXIST; + if (!cm->addr_count) + return -ENOENT; + memcpy(addr, cm->addr[0], sizeof(*addr)); + put_comm(cm); + return 0; +} + +int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid) +{ + struct comm *cm = get_comm(0, addr); + if (!cm) + return -EEXIST; + *nodeid = cm->nodeid; + put_comm(cm); + return 0; +} + +int dlm_our_nodeid(void) +{ + return local_comm ? local_comm->nodeid : 0; +} + +/* num 0 is first addr, num 1 is second addr */ +int dlm_our_addr(struct sockaddr_storage *addr, int num) +{ + if (!local_comm) + return -1; + if (num + 1 > local_comm->addr_count) + return -1; + memcpy(addr, local_comm->addr[num], sizeof(*addr)); + return 0; +} + +/* Config file defaults */ +#define DEFAULT_TCP_PORT 21064 +#define DEFAULT_BUFFER_SIZE 4096 +#define DEFAULT_RSBTBL_SIZE 256 +#define DEFAULT_LKBTBL_SIZE 1024 +#define DEFAULT_DIRTBL_SIZE 512 +#define DEFAULT_RECOVER_TIMER 5 +#define DEFAULT_TOSS_SECS 10 +#define DEFAULT_SCAN_SECS 5 + +struct dlm_config_info dlm_config = { + .tcp_port = DEFAULT_TCP_PORT, + .buffer_size = DEFAULT_BUFFER_SIZE, + .rsbtbl_size = DEFAULT_RSBTBL_SIZE, + .lkbtbl_size = DEFAULT_LKBTBL_SIZE, + .dirtbl_size = DEFAULT_DIRTBL_SIZE, + .recover_timer = DEFAULT_RECOVER_TIMER, + .toss_secs = DEFAULT_TOSS_SECS, + .scan_secs = DEFAULT_SCAN_SECS +}; + diff --git a/fs/dlm/config.h b/fs/dlm/config.h new file mode 100644 index 000000000000..9da7839958a9 --- /dev/null +++ b/fs/dlm/config.h @@ -0,0 +1,42 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __CONFIG_DOT_H__ +#define __CONFIG_DOT_H__ + +#define DLM_MAX_ADDR_COUNT 3 + +struct dlm_config_info { + int tcp_port; + int buffer_size; + int rsbtbl_size; + int lkbtbl_size; + int dirtbl_size; + int recover_timer; + int toss_secs; + int scan_secs; +}; + +extern struct dlm_config_info dlm_config; + +int dlm_config_init(void); +void dlm_config_exit(void); +int dlm_node_weight(char *lsname, int nodeid); +int dlm_nodeid_list(char *lsname, int **ids_out); +int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr); +int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid); +int dlm_our_nodeid(void); +int dlm_our_addr(struct sockaddr_storage *addr, int num); + +#endif /* __CONFIG_DOT_H__ */ + diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c new file mode 100644 index 000000000000..98b49a1ece47 --- /dev/null +++ b/fs/dlm/debug_fs.c @@ -0,0 +1,310 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include +#include +#include +#include +#include + +#include "dlm_internal.h" + + +static struct dentry *dlm_root; + +struct rsb_iter { + int entry; + struct dlm_ls *ls; + struct list_head *next; + struct dlm_rsb *rsb; +}; + +static char *print_lockmode(int mode) +{ + switch (mode) { + case DLM_LOCK_IV: + return "--"; + case DLM_LOCK_NL: + return "NL"; + case DLM_LOCK_CR: + return "CR"; + case DLM_LOCK_CW: + return "CW"; + case DLM_LOCK_PR: + return "PR"; + case DLM_LOCK_PW: + return "PW"; + case DLM_LOCK_EX: + return "EX"; + default: + return "??"; + } +} + +static void print_lock(struct seq_file *s, struct dlm_lkb *lkb, + struct dlm_rsb *res) +{ + seq_printf(s, "%08x %s", lkb->lkb_id, print_lockmode(lkb->lkb_grmode)); + + if (lkb->lkb_status == DLM_LKSTS_CONVERT + || lkb->lkb_status == DLM_LKSTS_WAITING) + seq_printf(s, " (%s)", print_lockmode(lkb->lkb_rqmode)); + + if (lkb->lkb_range) { + /* FIXME: this warns on Alpha */ + if (lkb->lkb_status == DLM_LKSTS_CONVERT + || lkb->lkb_status == DLM_LKSTS_GRANTED) + seq_printf(s, " %" PRIx64 "-%" PRIx64, + lkb->lkb_range[GR_RANGE_START], + lkb->lkb_range[GR_RANGE_END]); + if (lkb->lkb_status == DLM_LKSTS_CONVERT + || lkb->lkb_status == DLM_LKSTS_WAITING) + seq_printf(s, " (%" PRIx64 "-%" PRIx64 ")", + lkb->lkb_range[RQ_RANGE_START], + lkb->lkb_range[RQ_RANGE_END]); + } + + if (lkb->lkb_nodeid) { + if (lkb->lkb_nodeid != res->res_nodeid) + seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid, + lkb->lkb_remid); + else + seq_printf(s, " Master: %08x", lkb->lkb_remid); + } + + if (lkb->lkb_wait_type) + seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); + + seq_printf(s, "\n"); +} + +static int print_resource(struct dlm_rsb *res, struct seq_file *s) +{ + struct dlm_lkb *lkb; + int i, lvblen = res->res_ls->ls_lvblen; + + seq_printf(s, "\nResource %p Name (len=%d) \"", res, res->res_length); + for (i = 0; i < res->res_length; i++) { + if (isprint(res->res_name[i])) + seq_printf(s, "%c", res->res_name[i]); + else + seq_printf(s, "%c", '.'); + } + if (res->res_nodeid > 0) + seq_printf(s, "\" \nLocal Copy, Master is node %d\n", + res->res_nodeid); + else if (res->res_nodeid == 0) + seq_printf(s, "\" \nMaster Copy\n"); + else if (res->res_nodeid == -1) + seq_printf(s, "\" \nLooking up master (lkid %x)\n", + res->res_first_lkid); + else + seq_printf(s, "\" \nInvalid master %d\n", res->res_nodeid); + + /* Print the LVB: */ + if (res->res_lvbptr) { + seq_printf(s, "LVB: "); + for (i = 0; i < lvblen; i++) { + if (i == lvblen / 2) + seq_printf(s, "\n "); + seq_printf(s, "%02x ", + (unsigned char) res->res_lvbptr[i]); + } + if (rsb_flag(res, RSB_VALNOTVALID)) + seq_printf(s, " (INVALID)"); + seq_printf(s, "\n"); + } + + /* Print the locks attached to this resource */ + seq_printf(s, "Granted Queue\n"); + list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue) + print_lock(s, lkb, res); + + seq_printf(s, "Conversion Queue\n"); + list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue) + print_lock(s, lkb, res); + + seq_printf(s, "Waiting Queue\n"); + list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue) + print_lock(s, lkb, res); + + return 0; +} + +static int rsb_iter_next(struct rsb_iter *ri) +{ + struct dlm_ls *ls = ri->ls; + int i; + + if (!ri->next) { + top: + /* Find the next non-empty hash bucket */ + for (i = ri->entry; i < ls->ls_rsbtbl_size; i++) { + read_lock(&ls->ls_rsbtbl[i].lock); + if (!list_empty(&ls->ls_rsbtbl[i].list)) { + ri->next = ls->ls_rsbtbl[i].list.next; + read_unlock(&ls->ls_rsbtbl[i].lock); + break; + } + read_unlock(&ls->ls_rsbtbl[i].lock); + } + ri->entry = i; + + if (ri->entry >= ls->ls_rsbtbl_size) + return 1; + } else { + i = ri->entry; + read_lock(&ls->ls_rsbtbl[i].lock); + ri->next = ri->next->next; + if (ri->next->next == ls->ls_rsbtbl[i].list.next) { + /* End of list - move to next bucket */ + ri->next = NULL; + ri->entry++; + read_unlock(&ls->ls_rsbtbl[i].lock); + goto top; + } + read_unlock(&ls->ls_rsbtbl[i].lock); + } + ri->rsb = list_entry(ri->next, struct dlm_rsb, res_hashchain); + + return 0; +} + +static void rsb_iter_free(struct rsb_iter *ri) +{ + kfree(ri); +} + +static struct rsb_iter *rsb_iter_init(struct dlm_ls *ls) +{ + struct rsb_iter *ri; + + ri = kmalloc(sizeof *ri, GFP_KERNEL); + if (!ri) + return NULL; + + ri->ls = ls; + ri->entry = 0; + ri->next = NULL; + + if (rsb_iter_next(ri)) { + rsb_iter_free(ri); + return NULL; + } + + return ri; +} + +static void *seq_start(struct seq_file *file, loff_t *pos) +{ + struct rsb_iter *ri; + loff_t n = *pos; + + ri = rsb_iter_init(file->private); + if (!ri) + return NULL; + + while (n--) { + if (rsb_iter_next(ri)) { + rsb_iter_free(ri); + return NULL; + } + } + + return ri; +} + +static void *seq_next(struct seq_file *file, void *iter_ptr, loff_t *pos) +{ + struct rsb_iter *ri = iter_ptr; + + (*pos)++; + + if (rsb_iter_next(ri)) { + rsb_iter_free(ri); + return NULL; + } + + return ri; +} + +static void seq_stop(struct seq_file *file, void *iter_ptr) +{ + /* nothing for now */ +} + +static int seq_show(struct seq_file *file, void *iter_ptr) +{ + struct rsb_iter *ri = iter_ptr; + + print_resource(ri->rsb, file); + + return 0; +} + +static struct seq_operations dlm_seq_ops = { + .start = seq_start, + .next = seq_next, + .stop = seq_stop, + .show = seq_show, +}; + +static int do_open(struct inode *inode, struct file *file) +{ + struct seq_file *seq; + int ret; + + ret = seq_open(file, &dlm_seq_ops); + if (ret) + return ret; + + seq = file->private_data; + seq->private = inode->u.generic_ip; + + return 0; +} + +static struct file_operations dlm_fops = { + .owner = THIS_MODULE, + .open = do_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release +}; + +int dlm_create_debug_file(struct dlm_ls *ls) +{ + ls->ls_debug_dentry = debugfs_create_file(ls->ls_name, + S_IFREG | S_IRUGO, + dlm_root, + ls, + &dlm_fops); + return ls->ls_debug_dentry ? 0 : -ENOMEM; +} + +void dlm_delete_debug_file(struct dlm_ls *ls) +{ + if (ls->ls_debug_dentry) + debugfs_remove(ls->ls_debug_dentry); +} + +int dlm_register_debugfs(void) +{ + dlm_root = debugfs_create_dir("dlm", NULL); + return dlm_root ? 0 : -ENOMEM; +} + +void dlm_unregister_debugfs(void) +{ + debugfs_remove(dlm_root); +} + diff --git a/fs/dlm/device.c b/fs/dlm/device.c new file mode 100644 index 000000000000..a8bf600ed13d --- /dev/null +++ b/fs/dlm/device.c @@ -0,0 +1,1084 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +/* + * device.c + * + * This is the userland interface to the DLM. + * + * The locking is done via a misc char device (find the + * registered minor number in /proc/misc). + * + * User code should not use this interface directly but + * call the library routines in libdlm.a instead. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "lvb_table.h" + +static struct file_operations _dlm_fops; +static const char *name_prefix="dlm"; +static struct list_head user_ls_list; +static struct semaphore user_ls_lock; + +/* Lock infos are stored in here indexed by lock ID */ +static DEFINE_IDR(lockinfo_idr); +static rwlock_t lockinfo_lock; + +/* Flags in li_flags */ +#define LI_FLAG_COMPLETE 1 +#define LI_FLAG_FIRSTLOCK 2 +#define LI_FLAG_PERSISTENT 3 + +/* flags in ls_flags*/ +#define LS_FLAG_DELETED 1 +#define LS_FLAG_AUTOFREE 2 + + +#define LOCKINFO_MAGIC 0x53595324 + +struct lock_info { + uint32_t li_magic; + uint8_t li_cmd; + int8_t li_grmode; + int8_t li_rqmode; + struct dlm_lksb li_lksb; + wait_queue_head_t li_waitq; + unsigned long li_flags; + void __user *li_castparam; + void __user *li_castaddr; + void __user *li_bastparam; + void __user *li_bastaddr; + void __user *li_pend_bastparam; + void __user *li_pend_bastaddr; + struct list_head li_ownerqueue; + struct file_info *li_file; + struct dlm_lksb __user *li_user_lksb; + struct semaphore li_firstlock; +}; + +/* A queued AST no less */ +struct ast_info { + struct dlm_lock_result result; + struct list_head list; + uint32_t lvb_updated; + uint32_t progress; /* How much has been read */ +}; + +/* One of these per userland lockspace */ +struct user_ls { + void *ls_lockspace; + atomic_t ls_refcnt; + long ls_flags; + + /* Passed into misc_register() */ + struct miscdevice ls_miscinfo; + struct list_head ls_list; +}; + +/* misc_device info for the control device */ +static struct miscdevice ctl_device; + +/* + * Stuff we hang off the file struct. + * The first two are to cope with unlocking all the + * locks help by a process when it dies. + */ +struct file_info { + struct list_head fi_li_list; /* List of active lock_infos */ + spinlock_t fi_li_lock; + struct list_head fi_ast_list; /* Queue of ASTs to be delivered */ + spinlock_t fi_ast_lock; + wait_queue_head_t fi_wait; + struct user_ls *fi_ls; + atomic_t fi_refcnt; /* Number of users */ + unsigned long fi_flags; /* Bit 1 means the device is open */ +}; + + +/* get and put ops for file_info. + Actually I don't really like "get" and "put", but everyone + else seems to use them and I can't think of anything + nicer at the moment */ +static void get_file_info(struct file_info *f) +{ + atomic_inc(&f->fi_refcnt); +} + +static void put_file_info(struct file_info *f) +{ + if (atomic_dec_and_test(&f->fi_refcnt)) + kfree(f); +} + +static void release_lockinfo(struct lock_info *li) +{ + put_file_info(li->li_file); + + write_lock(&lockinfo_lock); + idr_remove(&lockinfo_idr, li->li_lksb.sb_lkid); + write_unlock(&lockinfo_lock); + + if (li->li_lksb.sb_lvbptr) + kfree(li->li_lksb.sb_lvbptr); + kfree(li); + + module_put(THIS_MODULE); +} + +static struct lock_info *get_lockinfo(uint32_t lockid) +{ + struct lock_info *li; + + read_lock(&lockinfo_lock); + li = idr_find(&lockinfo_idr, lockid); + read_unlock(&lockinfo_lock); + + return li; +} + +static int add_lockinfo(struct lock_info *li) +{ + int n; + int r; + int ret = -EINVAL; + + write_lock(&lockinfo_lock); + + if (idr_find(&lockinfo_idr, li->li_lksb.sb_lkid)) + goto out_up; + + ret = -ENOMEM; + r = idr_pre_get(&lockinfo_idr, GFP_KERNEL); + if (!r) + goto out_up; + + r = idr_get_new_above(&lockinfo_idr, li, li->li_lksb.sb_lkid, &n); + if (r) + goto out_up; + + if (n != li->li_lksb.sb_lkid) { + idr_remove(&lockinfo_idr, n); + goto out_up; + } + + ret = 0; + + out_up: + write_unlock(&lockinfo_lock); + + return ret; +} + + +static struct user_ls *__find_lockspace(int minor) +{ + struct user_ls *lsinfo; + + list_for_each_entry(lsinfo, &user_ls_list, ls_list) { + if (lsinfo->ls_miscinfo.minor == minor) + return lsinfo; + } + return NULL; +} + +/* Find a lockspace struct given the device minor number */ +static struct user_ls *find_lockspace(int minor) +{ + struct user_ls *lsinfo; + + down(&user_ls_lock); + lsinfo = __find_lockspace(minor); + up(&user_ls_lock); + + return lsinfo; +} + +static void add_lockspace_to_list(struct user_ls *lsinfo) +{ + down(&user_ls_lock); + list_add(&lsinfo->ls_list, &user_ls_list); + up(&user_ls_lock); +} + +/* Register a lockspace with the DLM and create a misc + device for userland to access it */ +static int register_lockspace(char *name, struct user_ls **ls, int flags) +{ + struct user_ls *newls; + int status; + int namelen; + + namelen = strlen(name)+strlen(name_prefix)+2; + + newls = kmalloc(sizeof(struct user_ls), GFP_KERNEL); + if (!newls) + return -ENOMEM; + memset(newls, 0, sizeof(struct user_ls)); + + newls->ls_miscinfo.name = kmalloc(namelen, GFP_KERNEL); + if (!newls->ls_miscinfo.name) { + kfree(newls); + return -ENOMEM; + } + + status = dlm_new_lockspace(name, strlen(name), &newls->ls_lockspace, 0, + DLM_USER_LVB_LEN); + if (status != 0) { + kfree(newls->ls_miscinfo.name); + kfree(newls); + return status; + } + + snprintf((char*)newls->ls_miscinfo.name, namelen, "%s_%s", + name_prefix, name); + + newls->ls_miscinfo.fops = &_dlm_fops; + newls->ls_miscinfo.minor = MISC_DYNAMIC_MINOR; + + status = misc_register(&newls->ls_miscinfo); + if (status) { + printk(KERN_ERR "dlm: misc register failed for %s\n", name); + dlm_release_lockspace(newls->ls_lockspace, 0); + kfree(newls->ls_miscinfo.name); + kfree(newls); + return status; + } + + if (flags & DLM_USER_LSFLG_AUTOFREE) + set_bit(LS_FLAG_AUTOFREE, &newls->ls_flags); + + add_lockspace_to_list(newls); + *ls = newls; + return 0; +} + +/* Called with the user_ls_lock semaphore held */ +static int unregister_lockspace(struct user_ls *lsinfo, int force) +{ + int status; + + status = dlm_release_lockspace(lsinfo->ls_lockspace, force); + if (status) + return status; + + status = misc_deregister(&lsinfo->ls_miscinfo); + if (status) + return status; + + list_del(&lsinfo->ls_list); + set_bit(LS_FLAG_DELETED, &lsinfo->ls_flags); + lsinfo->ls_lockspace = NULL; + if (atomic_read(&lsinfo->ls_refcnt) == 0) { + kfree(lsinfo->ls_miscinfo.name); + kfree(lsinfo); + } + + return 0; +} + +/* Add it to userland's AST queue */ +static void add_to_astqueue(struct lock_info *li, void *astaddr, void *astparam, + int lvb_updated) +{ + struct ast_info *ast = kmalloc(sizeof(struct ast_info), GFP_KERNEL); + if (!ast) + return; + + memset(ast, 0, sizeof(*ast)); + ast->result.user_astparam = astparam; + ast->result.user_astaddr = astaddr; + ast->result.user_lksb = li->li_user_lksb; + memcpy(&ast->result.lksb, &li->li_lksb, sizeof(struct dlm_lksb)); + ast->lvb_updated = lvb_updated; + + spin_lock(&li->li_file->fi_ast_lock); + list_add_tail(&ast->list, &li->li_file->fi_ast_list); + spin_unlock(&li->li_file->fi_ast_lock); + wake_up_interruptible(&li->li_file->fi_wait); +} + +static void bast_routine(void *param, int mode) +{ + struct lock_info *li = param; + + if (li && li->li_bastaddr) + add_to_astqueue(li, li->li_bastaddr, li->li_bastparam, 0); +} + +/* + * This is the kernel's AST routine. + * All lock, unlock & query operations complete here. + * The only syncronous ops are those done during device close. + */ +static void ast_routine(void *param) +{ + struct lock_info *li = param; + + /* Param may be NULL if a persistent lock is unlocked by someone else */ + if (!li) + return; + + /* If this is a succesful conversion then activate the blocking ast + * args from the conversion request */ + if (!test_bit(LI_FLAG_FIRSTLOCK, &li->li_flags) && + li->li_lksb.sb_status == 0) { + + li->li_bastparam = li->li_pend_bastparam; + li->li_bastaddr = li->li_pend_bastaddr; + li->li_pend_bastaddr = NULL; + } + + /* If it's an async request then post data to the user's AST queue. */ + if (li->li_castaddr) { + int lvb_updated = 0; + + /* See if the lvb has been updated */ + if (dlm_lvb_operations[li->li_grmode+1][li->li_rqmode+1] == 1) + lvb_updated = 1; + + if (li->li_lksb.sb_status == 0) + li->li_grmode = li->li_rqmode; + + /* Only queue AST if the device is still open */ + if (test_bit(1, &li->li_file->fi_flags)) + add_to_astqueue(li, li->li_castaddr, li->li_castparam, + lvb_updated); + + /* If it's a new lock operation that failed, then + * remove it from the owner queue and free the + * lock_info. + */ + if (test_and_clear_bit(LI_FLAG_FIRSTLOCK, &li->li_flags) && + li->li_lksb.sb_status != 0) { + + /* Wait till dlm_lock() has finished */ + down(&li->li_firstlock); + up(&li->li_firstlock); + + spin_lock(&li->li_file->fi_li_lock); + list_del(&li->li_ownerqueue); + spin_unlock(&li->li_file->fi_li_lock); + release_lockinfo(li); + return; + } + /* Free unlocks & queries */ + if (li->li_lksb.sb_status == -DLM_EUNLOCK || + li->li_cmd == DLM_USER_QUERY) { + release_lockinfo(li); + } + } else { + /* Synchronous request, just wake up the caller */ + set_bit(LI_FLAG_COMPLETE, &li->li_flags); + wake_up_interruptible(&li->li_waitq); + } +} + +/* + * Wait for the lock op to complete and return the status. + */ +static int wait_for_ast(struct lock_info *li) +{ + /* Wait for the AST routine to complete */ + set_task_state(current, TASK_INTERRUPTIBLE); + while (!test_bit(LI_FLAG_COMPLETE, &li->li_flags)) + schedule(); + + set_task_state(current, TASK_RUNNING); + + return li->li_lksb.sb_status; +} + + +/* Open on control device */ +static int dlm_ctl_open(struct inode *inode, struct file *file) +{ + file->private_data = NULL; + return 0; +} + +/* Close on control device */ +static int dlm_ctl_close(struct inode *inode, struct file *file) +{ + return 0; +} + +/* Open on lockspace device */ +static int dlm_open(struct inode *inode, struct file *file) +{ + struct file_info *f; + struct user_ls *lsinfo; + + lsinfo = find_lockspace(iminor(inode)); + if (!lsinfo) + return -ENOENT; + + f = kmalloc(sizeof(struct file_info), GFP_KERNEL); + if (!f) + return -ENOMEM; + + atomic_inc(&lsinfo->ls_refcnt); + INIT_LIST_HEAD(&f->fi_li_list); + INIT_LIST_HEAD(&f->fi_ast_list); + spin_lock_init(&f->fi_li_lock); + spin_lock_init(&f->fi_ast_lock); + init_waitqueue_head(&f->fi_wait); + f->fi_ls = lsinfo; + f->fi_flags = 0; + get_file_info(f); + set_bit(1, &f->fi_flags); + + file->private_data = f; + + return 0; +} + +/* Check the user's version matches ours */ +static int check_version(struct dlm_write_request *req) +{ + if (req->version[0] != DLM_DEVICE_VERSION_MAJOR || + (req->version[0] == DLM_DEVICE_VERSION_MAJOR && + req->version[1] > DLM_DEVICE_VERSION_MINOR)) { + + printk(KERN_DEBUG "dlm: process %s (%d) version mismatch " + "user (%d.%d.%d) kernel (%d.%d.%d)\n", + current->comm, + current->pid, + req->version[0], + req->version[1], + req->version[2], + DLM_DEVICE_VERSION_MAJOR, + DLM_DEVICE_VERSION_MINOR, + DLM_DEVICE_VERSION_PATCH); + return -EINVAL; + } + return 0; +} + +/* Close on lockspace device */ +static int dlm_close(struct inode *inode, struct file *file) +{ + struct file_info *f = file->private_data; + struct lock_info li; + struct lock_info *old_li, *safe; + sigset_t tmpsig; + sigset_t allsigs; + struct user_ls *lsinfo; + DECLARE_WAITQUEUE(wq, current); + + lsinfo = find_lockspace(iminor(inode)); + if (!lsinfo) + return -ENOENT; + + /* Mark this closed so that ASTs will not be delivered any more */ + clear_bit(1, &f->fi_flags); + + /* Block signals while we are doing this */ + sigfillset(&allsigs); + sigprocmask(SIG_BLOCK, &allsigs, &tmpsig); + + /* We use our own lock_info struct here, so that any + * outstanding "real" ASTs will be delivered with the + * corresponding "real" params, thus freeing the lock_info + * that belongs the lock. This catches the corner case where + * a lock is BUSY when we try to unlock it here + */ + memset(&li, 0, sizeof(li)); + clear_bit(LI_FLAG_COMPLETE, &li.li_flags); + init_waitqueue_head(&li.li_waitq); + add_wait_queue(&li.li_waitq, &wq); + + /* + * Free any outstanding locks, they are on the + * list in LIFO order so there should be no problems + * about unlocking parents before children. + */ + list_for_each_entry_safe(old_li, safe, &f->fi_li_list, li_ownerqueue) { + int status; + int flags = 0; + + /* Don't unlock persistent locks, just mark them orphaned */ + if (test_bit(LI_FLAG_PERSISTENT, &old_li->li_flags)) { + list_del(&old_li->li_ownerqueue); + + /* Update master copy */ + /* TODO: Check locking core updates the local and + remote ORPHAN flags */ + li.li_lksb.sb_lkid = old_li->li_lksb.sb_lkid; + status = dlm_lock(f->fi_ls->ls_lockspace, + old_li->li_grmode, &li.li_lksb, + DLM_LKF_CONVERT|DLM_LKF_ORPHAN, + NULL, 0, 0, ast_routine, NULL, + NULL, NULL); + if (status != 0) + printk("dlm: Error orphaning lock %x: %d\n", + old_li->li_lksb.sb_lkid, status); + + /* But tidy our references in it */ + release_lockinfo(old_li); + continue; + } + + clear_bit(LI_FLAG_COMPLETE, &li.li_flags); + + flags = DLM_LKF_FORCEUNLOCK; + if (old_li->li_grmode >= DLM_LOCK_PW) + flags |= DLM_LKF_IVVALBLK; + + status = dlm_unlock(f->fi_ls->ls_lockspace, + old_li->li_lksb.sb_lkid, flags, + &li.li_lksb, &li); + + /* Must wait for it to complete as the next lock could be its + * parent */ + if (status == 0) + wait_for_ast(&li); + + /* Unlock suceeded, free the lock_info struct. */ + if (status == 0) + release_lockinfo(old_li); + } + + remove_wait_queue(&li.li_waitq, &wq); + + /* + * If this is the last reference to the lockspace + * then free the struct. If it's an AUTOFREE lockspace + * then free the whole thing. + */ + down(&user_ls_lock); + if (atomic_dec_and_test(&lsinfo->ls_refcnt)) { + + if (lsinfo->ls_lockspace) { + if (test_bit(LS_FLAG_AUTOFREE, &lsinfo->ls_flags)) { + unregister_lockspace(lsinfo, 1); + } + } else { + kfree(lsinfo->ls_miscinfo.name); + kfree(lsinfo); + } + } + up(&user_ls_lock); + put_file_info(f); + + /* Restore signals */ + sigprocmask(SIG_SETMASK, &tmpsig, NULL); + recalc_sigpending(); + + return 0; +} + +static int do_user_create_lockspace(struct file_info *fi, uint8_t cmd, + struct dlm_lspace_params *kparams) +{ + int status; + struct user_ls *lsinfo; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + status = register_lockspace(kparams->name, &lsinfo, kparams->flags); + + /* If it succeeded then return the minor number */ + if (status == 0) + status = lsinfo->ls_miscinfo.minor; + + return status; +} + +static int do_user_remove_lockspace(struct file_info *fi, uint8_t cmd, + struct dlm_lspace_params *kparams) +{ + int status; + int force = 1; + struct user_ls *lsinfo; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + down(&user_ls_lock); + lsinfo = __find_lockspace(kparams->minor); + if (!lsinfo) { + up(&user_ls_lock); + return -EINVAL; + } + + if (kparams->flags & DLM_USER_LSFLG_FORCEFREE) + force = 2; + + status = unregister_lockspace(lsinfo, force); + up(&user_ls_lock); + + return status; +} + +/* Read call, might block if no ASTs are waiting. + * It will only ever return one message at a time, regardless + * of how many are pending. + */ +static ssize_t dlm_read(struct file *file, char __user *buffer, size_t count, + loff_t *ppos) +{ + struct file_info *fi = file->private_data; + struct ast_info *ast; + int data_size; + int offset; + DECLARE_WAITQUEUE(wait, current); + + if (count < sizeof(struct dlm_lock_result)) + return -EINVAL; + + spin_lock(&fi->fi_ast_lock); + if (list_empty(&fi->fi_ast_list)) { + + /* No waiting ASTs. + * Return EOF if the lockspace been deleted. + */ + if (test_bit(LS_FLAG_DELETED, &fi->fi_ls->ls_flags)) + return 0; + + if (file->f_flags & O_NONBLOCK) { + spin_unlock(&fi->fi_ast_lock); + return -EAGAIN; + } + + add_wait_queue(&fi->fi_wait, &wait); + + repeat: + set_current_state(TASK_INTERRUPTIBLE); + if (list_empty(&fi->fi_ast_list) && + !signal_pending(current)) { + + spin_unlock(&fi->fi_ast_lock); + schedule(); + spin_lock(&fi->fi_ast_lock); + goto repeat; + } + + current->state = TASK_RUNNING; + remove_wait_queue(&fi->fi_wait, &wait); + + if (signal_pending(current)) { + spin_unlock(&fi->fi_ast_lock); + return -ERESTARTSYS; + } + } + + ast = list_entry(fi->fi_ast_list.next, struct ast_info, list); + list_del(&ast->list); + spin_unlock(&fi->fi_ast_lock); + + /* Work out the size of the returned data */ + data_size = sizeof(struct dlm_lock_result); + if (ast->lvb_updated && ast->result.lksb.sb_lvbptr) + data_size += DLM_USER_LVB_LEN; + + offset = sizeof(struct dlm_lock_result); + + /* Room for the extended data ? */ + if (count >= data_size) { + + if (ast->lvb_updated && ast->result.lksb.sb_lvbptr) { + if (copy_to_user(buffer+offset, + ast->result.lksb.sb_lvbptr, + DLM_USER_LVB_LEN)) + return -EFAULT; + ast->result.lvb_offset = offset; + offset += DLM_USER_LVB_LEN; + } + } + + ast->result.length = data_size; + /* Copy the header now it has all the offsets in it */ + if (copy_to_user(buffer, &ast->result, sizeof(struct dlm_lock_result))) + offset = -EFAULT; + + /* If we only returned a header and there's more to come then put it + back on the list */ + if (count < data_size) { + spin_lock(&fi->fi_ast_lock); + list_add(&ast->list, &fi->fi_ast_list); + spin_unlock(&fi->fi_ast_lock); + } else + kfree(ast); + return offset; +} + +static unsigned int dlm_poll(struct file *file, poll_table *wait) +{ + struct file_info *fi = file->private_data; + + poll_wait(file, &fi->fi_wait, wait); + + spin_lock(&fi->fi_ast_lock); + if (!list_empty(&fi->fi_ast_list)) { + spin_unlock(&fi->fi_ast_lock); + return POLLIN | POLLRDNORM; + } + + spin_unlock(&fi->fi_ast_lock); + return 0; +} + +static struct lock_info *allocate_lockinfo(struct file_info *fi, uint8_t cmd, + struct dlm_lock_params *kparams) +{ + struct lock_info *li; + + if (!try_module_get(THIS_MODULE)) + return NULL; + + li = kmalloc(sizeof(struct lock_info), GFP_KERNEL); + if (li) { + li->li_magic = LOCKINFO_MAGIC; + li->li_file = fi; + li->li_cmd = cmd; + li->li_flags = 0; + li->li_grmode = -1; + li->li_rqmode = -1; + li->li_pend_bastparam = NULL; + li->li_pend_bastaddr = NULL; + li->li_castaddr = NULL; + li->li_castparam = NULL; + li->li_lksb.sb_lvbptr = NULL; + li->li_bastaddr = kparams->bastaddr; + li->li_bastparam = kparams->bastparam; + + get_file_info(fi); + } + return li; +} + +static int do_user_lock(struct file_info *fi, uint8_t cmd, + struct dlm_lock_params *kparams) +{ + struct lock_info *li; + int status; + + /* + * Validate things that we need to have correct. + */ + if (!kparams->castaddr) + return -EINVAL; + + if (!kparams->lksb) + return -EINVAL; + + /* Persistent child locks are not available yet */ + if ((kparams->flags & DLM_LKF_PERSISTENT) && kparams->parent) + return -EINVAL; + + /* For conversions, there should already be a lockinfo struct, + unless we are adopting an orphaned persistent lock */ + if (kparams->flags & DLM_LKF_CONVERT) { + + li = get_lockinfo(kparams->lkid); + + /* If this is a persistent lock we will have to create a + lockinfo again */ + if (!li && DLM_LKF_PERSISTENT) { + li = allocate_lockinfo(fi, cmd, kparams); + + li->li_lksb.sb_lkid = kparams->lkid; + li->li_castaddr = kparams->castaddr; + li->li_castparam = kparams->castparam; + + /* OK, this isn;t exactly a FIRSTLOCK but it is the + first time we've used this lockinfo, and if things + fail we want rid of it */ + init_MUTEX_LOCKED(&li->li_firstlock); + set_bit(LI_FLAG_FIRSTLOCK, &li->li_flags); + add_lockinfo(li); + + /* TODO: do a query to get the current state ?? */ + } + if (!li) + return -EINVAL; + + if (li->li_magic != LOCKINFO_MAGIC) + return -EINVAL; + + /* For conversions don't overwrite the current blocking AST + info so that: + a) if a blocking AST fires before the conversion is queued + it runs the current handler + b) if the conversion is cancelled, the original blocking AST + declaration is active + The pend_ info is made active when the conversion + completes. + */ + li->li_pend_bastaddr = kparams->bastaddr; + li->li_pend_bastparam = kparams->bastparam; + } else { + li = allocate_lockinfo(fi, cmd, kparams); + if (!li) + return -ENOMEM; + + /* semaphore to allow us to complete our work before + the AST routine runs. In fact we only need (and use) this + when the initial lock fails */ + init_MUTEX_LOCKED(&li->li_firstlock); + set_bit(LI_FLAG_FIRSTLOCK, &li->li_flags); + } + + li->li_user_lksb = kparams->lksb; + li->li_castaddr = kparams->castaddr; + li->li_castparam = kparams->castparam; + li->li_lksb.sb_lkid = kparams->lkid; + li->li_rqmode = kparams->mode; + if (kparams->flags & DLM_LKF_PERSISTENT) + set_bit(LI_FLAG_PERSISTENT, &li->li_flags); + + /* Copy in the value block */ + if (kparams->flags & DLM_LKF_VALBLK) { + if (!li->li_lksb.sb_lvbptr) { + li->li_lksb.sb_lvbptr = kmalloc(DLM_USER_LVB_LEN, + GFP_KERNEL); + if (!li->li_lksb.sb_lvbptr) { + status = -ENOMEM; + goto out_err; + } + } + + memcpy(li->li_lksb.sb_lvbptr, kparams->lvb, DLM_USER_LVB_LEN); + } + + /* Lock it ... */ + status = dlm_lock(fi->fi_ls->ls_lockspace, + kparams->mode, &li->li_lksb, + kparams->flags, + kparams->name, kparams->namelen, + kparams->parent, + ast_routine, + li, + (li->li_pend_bastaddr || li->li_bastaddr) ? + bast_routine : NULL, + kparams->range.ra_end ? &kparams->range : NULL); + if (status) + goto out_err; + + /* If it succeeded (this far) with a new lock then keep track of + it on the file's lockinfo list */ + if (!status && test_bit(LI_FLAG_FIRSTLOCK, &li->li_flags)) { + + spin_lock(&fi->fi_li_lock); + list_add(&li->li_ownerqueue, &fi->fi_li_list); + spin_unlock(&fi->fi_li_lock); + if (add_lockinfo(li)) + printk(KERN_WARNING "Add lockinfo failed\n"); + + up(&li->li_firstlock); + } + + /* Return the lockid as the user needs it /now/ */ + return li->li_lksb.sb_lkid; + + out_err: + if (test_bit(LI_FLAG_FIRSTLOCK, &li->li_flags)) + release_lockinfo(li); + return status; + +} + +static int do_user_unlock(struct file_info *fi, uint8_t cmd, + struct dlm_lock_params *kparams) +{ + struct lock_info *li; + int status; + int convert_cancel = 0; + + li = get_lockinfo(kparams->lkid); + if (!li) { + li = allocate_lockinfo(fi, cmd, kparams); + spin_lock(&fi->fi_li_lock); + list_add(&li->li_ownerqueue, &fi->fi_li_list); + spin_unlock(&fi->fi_li_lock); + } + if (!li) + return -ENOMEM; + + if (li->li_magic != LOCKINFO_MAGIC) + return -EINVAL; + + li->li_user_lksb = kparams->lksb; + li->li_castparam = kparams->castparam; + li->li_cmd = cmd; + + /* Cancelling a conversion doesn't remove the lock...*/ + if (kparams->flags & DLM_LKF_CANCEL && li->li_grmode != -1) + convert_cancel = 1; + + /* dlm_unlock() passes a 0 for castaddr which means don't overwrite + the existing li_castaddr as that's the completion routine for + unlocks. dlm_unlock_wait() specifies a new AST routine to be + executed when the unlock completes. */ + if (kparams->castaddr) + li->li_castaddr = kparams->castaddr; + + /* Use existing lksb & astparams */ + status = dlm_unlock(fi->fi_ls->ls_lockspace, + kparams->lkid, + kparams->flags, &li->li_lksb, li); + + if (!status && !convert_cancel) { + spin_lock(&fi->fi_li_lock); + list_del(&li->li_ownerqueue); + spin_unlock(&fi->fi_li_lock); + } + + return status; +} + +/* Write call, submit a locking request */ +static ssize_t dlm_write(struct file *file, const char __user *buffer, + size_t count, loff_t *ppos) +{ + struct file_info *fi = file->private_data; + struct dlm_write_request *kparams; + sigset_t tmpsig; + sigset_t allsigs; + int status; + + /* -1 because lock name is optional */ + if (count < sizeof(struct dlm_write_request)-1) + return -EINVAL; + + /* Has the lockspace been deleted */ + if (fi && test_bit(LS_FLAG_DELETED, &fi->fi_ls->ls_flags)) + return -ENOENT; + + kparams = kmalloc(count, GFP_KERNEL); + if (!kparams) + return -ENOMEM; + + status = -EFAULT; + /* Get the command info */ + if (copy_from_user(kparams, buffer, count)) + goto out_free; + + status = -EBADE; + if (check_version(kparams)) + goto out_free; + + /* Block signals while we are doing this */ + sigfillset(&allsigs); + sigprocmask(SIG_BLOCK, &allsigs, &tmpsig); + + status = -EINVAL; + switch (kparams->cmd) + { + case DLM_USER_LOCK: + if (!fi) goto out_sig; + status = do_user_lock(fi, kparams->cmd, &kparams->i.lock); + break; + + case DLM_USER_UNLOCK: + if (!fi) goto out_sig; + status = do_user_unlock(fi, kparams->cmd, &kparams->i.lock); + break; + + case DLM_USER_CREATE_LOCKSPACE: + if (fi) goto out_sig; + status = do_user_create_lockspace(fi, kparams->cmd, + &kparams->i.lspace); + break; + + case DLM_USER_REMOVE_LOCKSPACE: + if (fi) goto out_sig; + status = do_user_remove_lockspace(fi, kparams->cmd, + &kparams->i.lspace); + break; + default: + printk("Unknown command passed to DLM device : %d\n", + kparams->cmd); + break; + } + + out_sig: + /* Restore signals */ + sigprocmask(SIG_SETMASK, &tmpsig, NULL); + recalc_sigpending(); + + out_free: + kfree(kparams); + if (status == 0) + return count; + else + return status; +} + +static struct file_operations _dlm_fops = { + .open = dlm_open, + .release = dlm_close, + .read = dlm_read, + .write = dlm_write, + .poll = dlm_poll, + .owner = THIS_MODULE, +}; + +static struct file_operations _dlm_ctl_fops = { + .open = dlm_ctl_open, + .release = dlm_ctl_close, + .write = dlm_write, + .owner = THIS_MODULE, +}; + +/* + * Create control device + */ +static int __init dlm_device_init(void) +{ + int r; + + INIT_LIST_HEAD(&user_ls_list); + init_MUTEX(&user_ls_lock); + rwlock_init(&lockinfo_lock); + + ctl_device.name = "dlm-control"; + ctl_device.fops = &_dlm_ctl_fops; + ctl_device.minor = MISC_DYNAMIC_MINOR; + + r = misc_register(&ctl_device); + if (r) { + printk(KERN_ERR "dlm: misc_register failed for control dev\n"); + return r; + } + + return 0; +} + +static void __exit dlm_device_exit(void) +{ + misc_deregister(&ctl_device); +} + +MODULE_DESCRIPTION("Distributed Lock Manager device interface"); +MODULE_AUTHOR("Red Hat, Inc."); +MODULE_LICENSE("GPL"); + +module_init(dlm_device_init); +module_exit(dlm_device_exit); diff --git a/fs/dlm/dir.c b/fs/dlm/dir.c new file mode 100644 index 000000000000..0f1dde54bcd2 --- /dev/null +++ b/fs/dlm/dir.c @@ -0,0 +1,423 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "lockspace.h" +#include "member.h" +#include "lowcomms.h" +#include "rcom.h" +#include "config.h" +#include "memory.h" +#include "recover.h" +#include "util.h" +#include "lock.h" +#include "dir.h" + + +static void put_free_de(struct dlm_ls *ls, struct dlm_direntry *de) +{ + spin_lock(&ls->ls_recover_list_lock); + list_add(&de->list, &ls->ls_recover_list); + spin_unlock(&ls->ls_recover_list_lock); +} + +static struct dlm_direntry *get_free_de(struct dlm_ls *ls, int len) +{ + int found = FALSE; + struct dlm_direntry *de; + + spin_lock(&ls->ls_recover_list_lock); + list_for_each_entry(de, &ls->ls_recover_list, list) { + if (de->length == len) { + list_del(&de->list); + de->master_nodeid = 0; + memset(de->name, 0, len); + found = TRUE; + break; + } + } + spin_unlock(&ls->ls_recover_list_lock); + + if (!found) + de = allocate_direntry(ls, len); + return de; +} + +void dlm_clear_free_entries(struct dlm_ls *ls) +{ + struct dlm_direntry *de; + + spin_lock(&ls->ls_recover_list_lock); + while (!list_empty(&ls->ls_recover_list)) { + de = list_entry(ls->ls_recover_list.next, struct dlm_direntry, + list); + list_del(&de->list); + free_direntry(de); + } + spin_unlock(&ls->ls_recover_list_lock); +} + +/* + * We use the upper 16 bits of the hash value to select the directory node. + * Low bits are used for distribution of rsb's among hash buckets on each node. + * + * To give the exact range wanted (0 to num_nodes-1), we apply a modulus of + * num_nodes to the hash value. This value in the desired range is used as an + * offset into the sorted list of nodeid's to give the particular nodeid. + */ + +int dlm_hash2nodeid(struct dlm_ls *ls, uint32_t hash) +{ + struct list_head *tmp; + struct dlm_member *memb = NULL; + uint32_t node, n = 0; + int nodeid; + + if (ls->ls_num_nodes == 1) { + nodeid = dlm_our_nodeid(); + goto out; + } + + if (ls->ls_node_array) { + node = (hash >> 16) % ls->ls_total_weight; + nodeid = ls->ls_node_array[node]; + goto out; + } + + /* make_member_array() failed to kmalloc ls_node_array... */ + + node = (hash >> 16) % ls->ls_num_nodes; + + list_for_each(tmp, &ls->ls_nodes) { + if (n++ != node) + continue; + memb = list_entry(tmp, struct dlm_member, list); + break; + } + + DLM_ASSERT(memb , printk("num_nodes=%u n=%u node=%u\n", + ls->ls_num_nodes, n, node);); + nodeid = memb->nodeid; + out: + return nodeid; +} + +int dlm_dir_nodeid(struct dlm_rsb *r) +{ + return dlm_hash2nodeid(r->res_ls, r->res_hash); +} + +static inline uint32_t dir_hash(struct dlm_ls *ls, char *name, int len) +{ + uint32_t val; + + val = jhash(name, len, 0); + val &= (ls->ls_dirtbl_size - 1); + + return val; +} + +static void add_entry_to_hash(struct dlm_ls *ls, struct dlm_direntry *de) +{ + uint32_t bucket; + + bucket = dir_hash(ls, de->name, de->length); + list_add_tail(&de->list, &ls->ls_dirtbl[bucket].list); +} + +static struct dlm_direntry *search_bucket(struct dlm_ls *ls, char *name, + int namelen, uint32_t bucket) +{ + struct dlm_direntry *de; + + list_for_each_entry(de, &ls->ls_dirtbl[bucket].list, list) { + if (de->length == namelen && !memcmp(name, de->name, namelen)) + goto out; + } + de = NULL; + out: + return de; +} + +void dlm_dir_remove_entry(struct dlm_ls *ls, int nodeid, char *name, int namelen) +{ + struct dlm_direntry *de; + uint32_t bucket; + + bucket = dir_hash(ls, name, namelen); + + write_lock(&ls->ls_dirtbl[bucket].lock); + + de = search_bucket(ls, name, namelen, bucket); + + if (!de) { + log_error(ls, "remove fr %u none", nodeid); + goto out; + } + + if (de->master_nodeid != nodeid) { + log_error(ls, "remove fr %u ID %u", nodeid, de->master_nodeid); + goto out; + } + + list_del(&de->list); + free_direntry(de); + out: + write_unlock(&ls->ls_dirtbl[bucket].lock); +} + +void dlm_dir_clear(struct dlm_ls *ls) +{ + struct list_head *head; + struct dlm_direntry *de; + int i; + + DLM_ASSERT(list_empty(&ls->ls_recover_list), ); + + for (i = 0; i < ls->ls_dirtbl_size; i++) { + write_lock(&ls->ls_dirtbl[i].lock); + head = &ls->ls_dirtbl[i].list; + while (!list_empty(head)) { + de = list_entry(head->next, struct dlm_direntry, list); + list_del(&de->list); + put_free_de(ls, de); + } + write_unlock(&ls->ls_dirtbl[i].lock); + } +} + +int dlm_recover_directory(struct dlm_ls *ls) +{ + struct dlm_member *memb; + struct dlm_direntry *de; + char *b, *last_name = NULL; + int error = -ENOMEM, last_len, count = 0; + uint16_t namelen; + + log_debug(ls, "dlm_recover_directory"); + + if (dlm_no_directory(ls)) + goto out_status; + + dlm_dir_clear(ls); + + last_name = kmalloc(DLM_RESNAME_MAXLEN, GFP_KERNEL); + if (!last_name) + goto out; + + list_for_each_entry(memb, &ls->ls_nodes, list) { + memset(last_name, 0, DLM_RESNAME_MAXLEN); + last_len = 0; + + for (;;) { + error = dlm_recovery_stopped(ls); + if (error) + goto out_free; + + error = dlm_rcom_names(ls, memb->nodeid, + last_name, last_len); + if (error) + goto out_free; + + schedule(); + + /* + * pick namelen/name pairs out of received buffer + */ + + b = ls->ls_recover_buf + sizeof(struct dlm_rcom); + + for (;;) { + memcpy(&namelen, b, sizeof(uint16_t)); + namelen = be16_to_cpu(namelen); + b += sizeof(uint16_t); + + /* namelen of 0xFFFFF marks end of names for + this node; namelen of 0 marks end of the + buffer */ + + if (namelen == 0xFFFF) + goto done; + if (!namelen) + break; + + error = -ENOMEM; + de = get_free_de(ls, namelen); + if (!de) + goto out_free; + + de->master_nodeid = memb->nodeid; + de->length = namelen; + last_len = namelen; + memcpy(de->name, b, namelen); + memcpy(last_name, b, namelen); + b += namelen; + + add_entry_to_hash(ls, de); + count++; + } + } + done: + ; + } + + out_status: + error = 0; + dlm_set_recover_status(ls, DLM_RS_DIR); + log_debug(ls, "dlm_recover_directory %d entries", count); + out_free: + kfree(last_name); + out: + dlm_clear_free_entries(ls); + return error; +} + +static int get_entry(struct dlm_ls *ls, int nodeid, char *name, + int namelen, int *r_nodeid) +{ + struct dlm_direntry *de, *tmp; + uint32_t bucket; + + bucket = dir_hash(ls, name, namelen); + + write_lock(&ls->ls_dirtbl[bucket].lock); + de = search_bucket(ls, name, namelen, bucket); + if (de) { + *r_nodeid = de->master_nodeid; + write_unlock(&ls->ls_dirtbl[bucket].lock); + if (*r_nodeid == nodeid) + return -EEXIST; + return 0; + } + + write_unlock(&ls->ls_dirtbl[bucket].lock); + + de = allocate_direntry(ls, namelen); + if (!de) + return -ENOMEM; + + de->master_nodeid = nodeid; + de->length = namelen; + memcpy(de->name, name, namelen); + + write_lock(&ls->ls_dirtbl[bucket].lock); + tmp = search_bucket(ls, name, namelen, bucket); + if (tmp) { + free_direntry(de); + de = tmp; + } else { + list_add_tail(&de->list, &ls->ls_dirtbl[bucket].list); + } + *r_nodeid = de->master_nodeid; + write_unlock(&ls->ls_dirtbl[bucket].lock); + return 0; +} + +int dlm_dir_lookup(struct dlm_ls *ls, int nodeid, char *name, int namelen, + int *r_nodeid) +{ + return get_entry(ls, nodeid, name, namelen, r_nodeid); +} + +/* Copy the names of master rsb's into the buffer provided. + Only select names whose dir node is the given nodeid. */ + +void dlm_copy_master_names(struct dlm_ls *ls, char *inbuf, int inlen, + char *outbuf, int outlen, int nodeid) +{ + struct list_head *list; + struct dlm_rsb *start_r = NULL, *r = NULL; + int offset = 0, start_namelen, error, dir_nodeid; + char *start_name; + uint16_t be_namelen; + + /* + * Find the rsb where we left off (or start again) + */ + + start_namelen = inlen; + start_name = inbuf; + + if (start_namelen > 1) { + /* + * We could also use a find_rsb_root() function here that + * searched the ls_root_list. + */ + error = dlm_find_rsb(ls, start_name, start_namelen, R_MASTER, + &start_r); + DLM_ASSERT(!error && start_r, + printk("error %d\n", error);); + DLM_ASSERT(!list_empty(&start_r->res_root_list), + dlm_print_rsb(start_r);); + dlm_put_rsb(start_r); + } + + /* + * Send rsb names for rsb's we're master of and whose directory node + * matches the requesting node. + */ + + down_read(&ls->ls_root_sem); + if (start_r) + list = start_r->res_root_list.next; + else + list = ls->ls_root_list.next; + + for (offset = 0; list != &ls->ls_root_list; list = list->next) { + r = list_entry(list, struct dlm_rsb, res_root_list); + if (r->res_nodeid) + continue; + + dir_nodeid = dlm_dir_nodeid(r); + if (dir_nodeid != nodeid) + continue; + + /* + * The block ends when we can't fit the following in the + * remaining buffer space: + * namelen (uint16_t) + + * name (r->res_length) + + * end-of-block record 0x0000 (uint16_t) + */ + + if (offset + sizeof(uint16_t)*2 + r->res_length > outlen) { + /* Write end-of-block record */ + be_namelen = 0; + memcpy(outbuf + offset, &be_namelen, sizeof(uint16_t)); + offset += sizeof(uint16_t); + goto out; + } + + be_namelen = cpu_to_be16(r->res_length); + memcpy(outbuf + offset, &be_namelen, sizeof(uint16_t)); + offset += sizeof(uint16_t); + memcpy(outbuf + offset, r->res_name, r->res_length); + offset += r->res_length; + } + + /* + * If we've reached the end of the list (and there's room) write a + * terminating record. + */ + + if ((list == &ls->ls_root_list) && + (offset + sizeof(uint16_t) <= outlen)) { + be_namelen = 0xFFFF; + memcpy(outbuf + offset, &be_namelen, sizeof(uint16_t)); + offset += sizeof(uint16_t); + } + + out: + up_read(&ls->ls_root_sem); +} + diff --git a/fs/dlm/dir.h b/fs/dlm/dir.h new file mode 100644 index 000000000000..0b0eb1267b6e --- /dev/null +++ b/fs/dlm/dir.h @@ -0,0 +1,30 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __DIR_DOT_H__ +#define __DIR_DOT_H__ + + +int dlm_dir_nodeid(struct dlm_rsb *rsb); +int dlm_hash2nodeid(struct dlm_ls *ls, uint32_t hash); +void dlm_dir_remove_entry(struct dlm_ls *ls, int nodeid, char *name, int len); +void dlm_dir_clear(struct dlm_ls *ls); +void dlm_clear_free_entries(struct dlm_ls *ls); +int dlm_recover_directory(struct dlm_ls *ls); +int dlm_dir_lookup(struct dlm_ls *ls, int nodeid, char *name, int namelen, + int *r_nodeid); +void dlm_copy_master_names(struct dlm_ls *ls, char *inbuf, int inlen, + char *outbuf, int outlen, int nodeid); + +#endif /* __DIR_DOT_H__ */ + diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h new file mode 100644 index 000000000000..0020cd07baf7 --- /dev/null +++ b/fs/dlm/dlm_internal.h @@ -0,0 +1,518 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __DLM_INTERNAL_DOT_H__ +#define __DLM_INTERNAL_DOT_H__ + +/* + * This is the main header file to be included in each DLM source file. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define DLM_LOCKSPACE_LEN 64 + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#if (BITS_PER_LONG == 64) +#define PRIx64 "lx" +#else +#define PRIx64 "Lx" +#endif + +/* Size of the temp buffer midcomms allocates on the stack. + We try to make this large enough so most messages fit. + FIXME: should sctp make this unnecessary? */ + +#define DLM_INBUF_LEN 148 + +struct dlm_ls; +struct dlm_lkb; +struct dlm_rsb; +struct dlm_member; +struct dlm_lkbtable; +struct dlm_rsbtable; +struct dlm_dirtable; +struct dlm_direntry; +struct dlm_recover; +struct dlm_header; +struct dlm_message; +struct dlm_rcom; +struct dlm_mhandle; + +#define log_print(fmt, args...) \ + printk(KERN_ERR "dlm: "fmt"\n" , ##args) +#define log_error(ls, fmt, args...) \ + printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args) + +#ifdef DLM_LOG_DEBUG +#define log_debug(ls, fmt, args...) log_error(ls, fmt, ##args) +#else +#define log_debug(ls, fmt, args...) +#endif + +#define DLM_ASSERT(x, do) \ +{ \ + if (!(x)) \ + { \ + printk(KERN_ERR "\nDLM: Assertion failed on line %d of file %s\n" \ + "DLM: assertion: \"%s\"\n" \ + "DLM: time = %lu\n", \ + __LINE__, __FILE__, #x, jiffies); \ + {do} \ + printk("\n"); \ + BUG(); \ + panic("DLM: Record message above and reboot.\n"); \ + } \ +} + + +struct dlm_direntry { + struct list_head list; + uint32_t master_nodeid; + uint16_t length; + char name[1]; +}; + +struct dlm_dirtable { + struct list_head list; + rwlock_t lock; +}; + +struct dlm_rsbtable { + struct list_head list; + struct list_head toss; + rwlock_t lock; +}; + +struct dlm_lkbtable { + struct list_head list; + rwlock_t lock; + uint16_t counter; +}; + +/* + * Lockspace member (per node in a ls) + */ + +struct dlm_member { + struct list_head list; + int nodeid; + int weight; +}; + +/* + * Save and manage recovery state for a lockspace. + */ + +struct dlm_recover { + struct list_head list; + int *nodeids; + int node_count; + uint64_t seq; +}; + +/* + * Pass input args to second stage locking function. + */ + +struct dlm_args { + uint32_t flags; + void *astaddr; + long astparam; + void *bastaddr; + int mode; + struct dlm_lksb *lksb; + struct dlm_range *range; +}; + + +/* + * Lock block + * + * A lock can be one of three types: + * + * local copy lock is mastered locally + * (lkb_nodeid is zero and DLM_LKF_MSTCPY is not set) + * process copy lock is mastered on a remote node + * (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is not set) + * master copy master node's copy of a lock owned by remote node + * (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is set) + * + * lkb_exflags: a copy of the most recent flags arg provided to dlm_lock or + * dlm_unlock. The dlm does not modify these or use any private flags in + * this field; it only contains DLM_LKF_ flags from dlm.h. These flags + * are sent as-is to the remote master when the lock is remote. + * + * lkb_flags: internal dlm flags (DLM_IFL_ prefix) from dlm_internal.h. + * Some internal flags are shared between the master and process nodes; + * these shared flags are kept in the lower two bytes. One of these + * flags set on the master copy will be propagated to the process copy + * and v.v. Other internal flags are private to the master or process + * node (e.g. DLM_IFL_MSTCPY). These are kept in the high two bytes. + * + * lkb_sbflags: status block flags. These flags are copied directly into + * the caller's lksb.sb_flags prior to the dlm_lock/dlm_unlock completion + * ast. All defined in dlm.h with DLM_SBF_ prefix. + * + * lkb_status: the lock status indicates which rsb queue the lock is + * on, grant, convert, or wait. DLM_LKSTS_ WAITING/GRANTED/CONVERT + * + * lkb_wait_type: the dlm message type (DLM_MSG_ prefix) for which a + * reply is needed. Only set when the lkb is on the lockspace waiters + * list awaiting a reply from a remote node. + * + * lkb_nodeid: when the lkb is a local copy, nodeid is 0; when the lkb + * is a master copy, nodeid specifies the remote lock holder, when the + * lkb is a process copy, the nodeid specifies the lock master. + */ + +/* lkb_ast_type */ + +#define AST_COMP 1 +#define AST_BAST 2 + +/* lkb_range[] */ + +#define GR_RANGE_START 0 +#define GR_RANGE_END 1 +#define RQ_RANGE_START 2 +#define RQ_RANGE_END 3 + +/* lkb_status */ + +#define DLM_LKSTS_WAITING 1 +#define DLM_LKSTS_GRANTED 2 +#define DLM_LKSTS_CONVERT 3 + +/* lkb_flags */ + +#define DLM_IFL_MSTCPY 0x00010000 +#define DLM_IFL_RESEND 0x00020000 +#define DLM_IFL_RANGE 0x00000001 + +struct dlm_lkb { + struct dlm_rsb *lkb_resource; /* the rsb */ + struct kref lkb_ref; + int lkb_nodeid; /* copied from rsb */ + int lkb_ownpid; /* pid of lock owner */ + uint32_t lkb_id; /* our lock ID */ + uint32_t lkb_remid; /* lock ID on remote partner */ + uint32_t lkb_exflags; /* external flags from caller */ + uint32_t lkb_sbflags; /* lksb flags */ + uint32_t lkb_flags; /* internal flags */ + uint32_t lkb_lvbseq; /* lvb sequence number */ + + int8_t lkb_status; /* granted, waiting, convert */ + int8_t lkb_rqmode; /* requested lock mode */ + int8_t lkb_grmode; /* granted lock mode */ + int8_t lkb_bastmode; /* requested mode */ + int8_t lkb_highbast; /* highest mode bast sent for */ + + int8_t lkb_wait_type; /* type of reply waiting for */ + int8_t lkb_ast_type; /* type of ast queued for */ + + struct list_head lkb_idtbl_list; /* lockspace lkbtbl */ + struct list_head lkb_statequeue; /* rsb g/c/w list */ + struct list_head lkb_rsb_lookup; /* waiting for rsb lookup */ + struct list_head lkb_wait_reply; /* waiting for remote reply */ + struct list_head lkb_astqueue; /* need ast to be sent */ + + uint64_t *lkb_range; /* array of gr/rq ranges */ + char *lkb_lvbptr; + struct dlm_lksb *lkb_lksb; /* caller's status block */ + void *lkb_astaddr; /* caller's ast function */ + void *lkb_bastaddr; /* caller's bast function */ + long lkb_astparam; /* caller's ast arg */ +}; + + +struct dlm_rsb { + struct dlm_ls *res_ls; /* the lockspace */ + struct kref res_ref; + struct semaphore res_sem; + unsigned long res_flags; + int res_length; /* length of rsb name */ + int res_nodeid; + uint32_t res_lvbseq; + uint32_t res_hash; + uint32_t res_bucket; /* rsbtbl */ + unsigned long res_toss_time; + uint32_t res_first_lkid; + struct list_head res_lookup; /* lkbs waiting on first */ + struct list_head res_hashchain; /* rsbtbl */ + struct list_head res_grantqueue; + struct list_head res_convertqueue; + struct list_head res_waitqueue; + + struct list_head res_root_list; /* used for recovery */ + struct list_head res_recover_list; /* used for recovery */ + int res_recover_locks_count; + + char *res_lvbptr; + char res_name[1]; +}; + +/* find_rsb() flags */ + +#define R_MASTER 1 /* only return rsb if it's a master */ +#define R_CREATE 2 /* create/add rsb if not found */ + +/* rsb_flags */ + +enum rsb_flags { + RSB_MASTER_UNCERTAIN, + RSB_VALNOTVALID, + RSB_VALNOTVALID_PREV, + RSB_NEW_MASTER, + RSB_NEW_MASTER2, + RSB_RECOVER_CONVERT, +}; + +static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag) +{ + __set_bit(flag, &r->res_flags); +} + +static inline void rsb_clear_flag(struct dlm_rsb *r, enum rsb_flags flag) +{ + __clear_bit(flag, &r->res_flags); +} + +static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag) +{ + return test_bit(flag, &r->res_flags); +} + + +/* dlm_header is first element of all structs sent between nodes */ + +#define DLM_HEADER_MAJOR 0x00020000 +#define DLM_HEADER_MINOR 0x00000001 + +#define DLM_MSG 1 +#define DLM_RCOM 2 + +struct dlm_header { + uint32_t h_version; + uint32_t h_lockspace; + uint32_t h_nodeid; /* nodeid of sender */ + uint16_t h_length; + uint8_t h_cmd; /* DLM_MSG, DLM_RCOM */ + uint8_t h_pad; +}; + + +#define DLM_MSG_REQUEST 1 +#define DLM_MSG_CONVERT 2 +#define DLM_MSG_UNLOCK 3 +#define DLM_MSG_CANCEL 4 +#define DLM_MSG_REQUEST_REPLY 5 +#define DLM_MSG_CONVERT_REPLY 6 +#define DLM_MSG_UNLOCK_REPLY 7 +#define DLM_MSG_CANCEL_REPLY 8 +#define DLM_MSG_GRANT 9 +#define DLM_MSG_BAST 10 +#define DLM_MSG_LOOKUP 11 +#define DLM_MSG_REMOVE 12 +#define DLM_MSG_LOOKUP_REPLY 13 + +struct dlm_message { + struct dlm_header m_header; + uint32_t m_type; /* DLM_MSG_ */ + uint32_t m_nodeid; + uint32_t m_pid; + uint32_t m_lkid; /* lkid on sender */ + uint32_t m_remid; /* lkid on receiver */ + uint32_t m_parent_lkid; + uint32_t m_parent_remid; + uint32_t m_exflags; + uint32_t m_sbflags; + uint32_t m_flags; + uint32_t m_lvbseq; + uint32_t m_hash; + int m_status; + int m_grmode; + int m_rqmode; + int m_bastmode; + int m_asts; + int m_result; /* 0 or -EXXX */ + uint64_t m_range[2]; + char m_extra[0]; /* name or lvb */ +}; + + +#define DLM_RS_NODES 0x00000001 +#define DLM_RS_NODES_ALL 0x00000002 +#define DLM_RS_DIR 0x00000004 +#define DLM_RS_DIR_ALL 0x00000008 +#define DLM_RS_LOCKS 0x00000010 +#define DLM_RS_LOCKS_ALL 0x00000020 +#define DLM_RS_DONE 0x00000040 +#define DLM_RS_DONE_ALL 0x00000080 + +#define DLM_RCOM_STATUS 1 +#define DLM_RCOM_NAMES 2 +#define DLM_RCOM_LOOKUP 3 +#define DLM_RCOM_LOCK 4 +#define DLM_RCOM_STATUS_REPLY 5 +#define DLM_RCOM_NAMES_REPLY 6 +#define DLM_RCOM_LOOKUP_REPLY 7 +#define DLM_RCOM_LOCK_REPLY 8 + +struct dlm_rcom { + struct dlm_header rc_header; + uint32_t rc_type; /* DLM_RCOM_ */ + int rc_result; /* multi-purpose */ + uint64_t rc_id; /* match reply with request */ + char rc_buf[0]; +}; + +struct rcom_config { + uint32_t rf_lvblen; + uint32_t rf_lsflags; + uint64_t rf_unused; +}; + +struct rcom_lock { + uint32_t rl_ownpid; + uint32_t rl_lkid; + uint32_t rl_remid; + uint32_t rl_parent_lkid; + uint32_t rl_parent_remid; + uint32_t rl_exflags; + uint32_t rl_flags; + uint32_t rl_lvbseq; + int rl_result; + int8_t rl_rqmode; + int8_t rl_grmode; + int8_t rl_status; + int8_t rl_asts; + uint16_t rl_wait_type; + uint16_t rl_namelen; + uint64_t rl_range[4]; + char rl_name[DLM_RESNAME_MAXLEN]; + char rl_lvb[0]; +}; + +struct dlm_ls { + struct list_head ls_list; /* list of lockspaces */ + uint32_t ls_global_id; /* global unique lockspace ID */ + uint32_t ls_exflags; + int ls_lvblen; + int ls_count; /* reference count */ + unsigned long ls_flags; /* LSFL_ */ + struct kobject ls_kobj; + + struct dlm_rsbtable *ls_rsbtbl; + uint32_t ls_rsbtbl_size; + + struct dlm_lkbtable *ls_lkbtbl; + uint32_t ls_lkbtbl_size; + + struct dlm_dirtable *ls_dirtbl; + uint32_t ls_dirtbl_size; + + struct semaphore ls_waiters_sem; + struct list_head ls_waiters; /* lkbs needing a reply */ + + struct list_head ls_nodes; /* current nodes in ls */ + struct list_head ls_nodes_gone; /* dead node list, recovery */ + int ls_num_nodes; /* number of nodes in ls */ + int ls_low_nodeid; + int ls_total_weight; + int *ls_node_array; + + struct dlm_rsb ls_stub_rsb; /* for returning errors */ + struct dlm_lkb ls_stub_lkb; /* for returning errors */ + struct dlm_message ls_stub_ms; /* for faking a reply */ + + struct dentry *ls_debug_dentry; /* debugfs */ + + wait_queue_head_t ls_uevent_wait; /* user part of join/leave */ + int ls_uevent_result; + + /* recovery related */ + + struct timer_list ls_timer; + struct task_struct *ls_recoverd_task; + struct semaphore ls_recoverd_active; + spinlock_t ls_recover_lock; + uint32_t ls_recover_status; /* DLM_RS_ */ + uint64_t ls_recover_seq; + struct dlm_recover *ls_recover_args; + struct rw_semaphore ls_in_recovery; /* block local requests */ + struct list_head ls_requestqueue;/* queue remote requests */ + struct semaphore ls_requestqueue_lock; + char *ls_recover_buf; + struct list_head ls_recover_list; + spinlock_t ls_recover_list_lock; + int ls_recover_list_count; + wait_queue_head_t ls_wait_general; + + struct list_head ls_root_list; /* root resources */ + struct rw_semaphore ls_root_sem; /* protect root_list */ + + int ls_namelen; + char ls_name[1]; +}; + +#define LSFL_WORK 0 +#define LSFL_RUNNING 1 +#define LSFL_RECOVERY_STOP 2 +#define LSFL_RCOM_READY 3 +#define LSFL_UEVENT_WAIT 4 + +static inline int dlm_locking_stopped(struct dlm_ls *ls) +{ + return !test_bit(LSFL_RUNNING, &ls->ls_flags); +} + +static inline int dlm_recovery_stopped(struct dlm_ls *ls) +{ + return test_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); +} + +static inline int dlm_no_directory(struct dlm_ls *ls) +{ + return (ls->ls_exflags & DLM_LSFL_NODIR) ? 1 : 0; +} + +#endif /* __DLM_INTERNAL_DOT_H__ */ + diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c new file mode 100644 index 000000000000..81efb361f95d --- /dev/null +++ b/fs/dlm/lock.c @@ -0,0 +1,3610 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +/* Central locking logic has four stages: + + dlm_lock() + dlm_unlock() + + request_lock(ls, lkb) + convert_lock(ls, lkb) + unlock_lock(ls, lkb) + cancel_lock(ls, lkb) + + _request_lock(r, lkb) + _convert_lock(r, lkb) + _unlock_lock(r, lkb) + _cancel_lock(r, lkb) + + do_request(r, lkb) + do_convert(r, lkb) + do_unlock(r, lkb) + do_cancel(r, lkb) + + Stage 1 (lock, unlock) is mainly about checking input args and + splitting into one of the four main operations: + + dlm_lock = request_lock + dlm_lock+CONVERT = convert_lock + dlm_unlock = unlock_lock + dlm_unlock+CANCEL = cancel_lock + + Stage 2, xxxx_lock(), just finds and locks the relevant rsb which is + provided to the next stage. + + Stage 3, _xxxx_lock(), determines if the operation is local or remote. + When remote, it calls send_xxxx(), when local it calls do_xxxx(). + + Stage 4, do_xxxx(), is the guts of the operation. It manipulates the + given rsb and lkb and queues callbacks. + + For remote operations, send_xxxx() results in the corresponding do_xxxx() + function being executed on the remote node. The connecting send/receive + calls on local (L) and remote (R) nodes: + + L: send_xxxx() -> R: receive_xxxx() + R: do_xxxx() + L: receive_xxxx_reply() <- R: send_xxxx_reply() +*/ + +#include "dlm_internal.h" +#include "memory.h" +#include "lowcomms.h" +#include "requestqueue.h" +#include "util.h" +#include "dir.h" +#include "member.h" +#include "lockspace.h" +#include "ast.h" +#include "lock.h" +#include "rcom.h" +#include "recover.h" +#include "lvb_table.h" +#include "config.h" + +static int send_request(struct dlm_rsb *r, struct dlm_lkb *lkb); +static int send_convert(struct dlm_rsb *r, struct dlm_lkb *lkb); +static int send_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb); +static int send_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb); +static int send_grant(struct dlm_rsb *r, struct dlm_lkb *lkb); +static int send_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int mode); +static int send_lookup(struct dlm_rsb *r, struct dlm_lkb *lkb); +static int send_remove(struct dlm_rsb *r); +static int _request_lock(struct dlm_rsb *r, struct dlm_lkb *lkb); +static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, + struct dlm_message *ms); +static int receive_extralen(struct dlm_message *ms); + +/* + * Lock compatibilty matrix - thanks Steve + * UN = Unlocked state. Not really a state, used as a flag + * PD = Padding. Used to make the matrix a nice power of two in size + * Other states are the same as the VMS DLM. + * Usage: matrix[grmode+1][rqmode+1] (although m[rq+1][gr+1] is the same) + */ + +static const int __dlm_compat_matrix[8][8] = { + /* UN NL CR CW PR PW EX PD */ + {1, 1, 1, 1, 1, 1, 1, 0}, /* UN */ + {1, 1, 1, 1, 1, 1, 1, 0}, /* NL */ + {1, 1, 1, 1, 1, 1, 0, 0}, /* CR */ + {1, 1, 1, 1, 0, 0, 0, 0}, /* CW */ + {1, 1, 1, 0, 1, 0, 0, 0}, /* PR */ + {1, 1, 1, 0, 0, 0, 0, 0}, /* PW */ + {1, 1, 0, 0, 0, 0, 0, 0}, /* EX */ + {0, 0, 0, 0, 0, 0, 0, 0} /* PD */ +}; + +/* + * This defines the direction of transfer of LVB data. + * Granted mode is the row; requested mode is the column. + * Usage: matrix[grmode+1][rqmode+1] + * 1 = LVB is returned to the caller + * 0 = LVB is written to the resource + * -1 = nothing happens to the LVB + */ + +const int dlm_lvb_operations[8][8] = { + /* UN NL CR CW PR PW EX PD*/ + { -1, 1, 1, 1, 1, 1, 1, -1 }, /* UN */ + { -1, 1, 1, 1, 1, 1, 1, 0 }, /* NL */ + { -1, -1, 1, 1, 1, 1, 1, 0 }, /* CR */ + { -1, -1, -1, 1, 1, 1, 1, 0 }, /* CW */ + { -1, -1, -1, -1, 1, 1, 1, 0 }, /* PR */ + { -1, 0, 0, 0, 0, 0, 1, 0 }, /* PW */ + { -1, 0, 0, 0, 0, 0, 0, 0 }, /* EX */ + { -1, 0, 0, 0, 0, 0, 0, 0 } /* PD */ +}; +EXPORT_SYMBOL_GPL(dlm_lvb_operations); + +#define modes_compat(gr, rq) \ + __dlm_compat_matrix[(gr)->lkb_grmode + 1][(rq)->lkb_rqmode + 1] + +int dlm_modes_compat(int mode1, int mode2) +{ + return __dlm_compat_matrix[mode1 + 1][mode2 + 1]; +} + +/* + * Compatibility matrix for conversions with QUECVT set. + * Granted mode is the row; requested mode is the column. + * Usage: matrix[grmode+1][rqmode+1] + */ + +static const int __quecvt_compat_matrix[8][8] = { + /* UN NL CR CW PR PW EX PD */ + {0, 0, 0, 0, 0, 0, 0, 0}, /* UN */ + {0, 0, 1, 1, 1, 1, 1, 0}, /* NL */ + {0, 0, 0, 1, 1, 1, 1, 0}, /* CR */ + {0, 0, 0, 0, 1, 1, 1, 0}, /* CW */ + {0, 0, 0, 1, 0, 1, 1, 0}, /* PR */ + {0, 0, 0, 0, 0, 0, 1, 0}, /* PW */ + {0, 0, 0, 0, 0, 0, 0, 0}, /* EX */ + {0, 0, 0, 0, 0, 0, 0, 0} /* PD */ +}; + +static void dlm_print_lkb(struct dlm_lkb *lkb) +{ + printk(KERN_ERR "lkb: nodeid %d id %x remid %x exflags %x flags %x\n" + " status %d rqmode %d grmode %d wait_type %d ast_type %d\n", + lkb->lkb_nodeid, lkb->lkb_id, lkb->lkb_remid, lkb->lkb_exflags, + lkb->lkb_flags, lkb->lkb_status, lkb->lkb_rqmode, + lkb->lkb_grmode, lkb->lkb_wait_type, lkb->lkb_ast_type); +} + +void dlm_print_rsb(struct dlm_rsb *r) +{ + printk(KERN_ERR "rsb: nodeid %d flags %lx first %x rlc %d name %s\n", + r->res_nodeid, r->res_flags, r->res_first_lkid, + r->res_recover_locks_count, r->res_name); +} + +/* Threads cannot use the lockspace while it's being recovered */ + +static inline void lock_recovery(struct dlm_ls *ls) +{ + down_read(&ls->ls_in_recovery); +} + +static inline void unlock_recovery(struct dlm_ls *ls) +{ + up_read(&ls->ls_in_recovery); +} + +static inline int lock_recovery_try(struct dlm_ls *ls) +{ + return down_read_trylock(&ls->ls_in_recovery); +} + +static inline int can_be_queued(struct dlm_lkb *lkb) +{ + return !(lkb->lkb_exflags & DLM_LKF_NOQUEUE); +} + +static inline int force_blocking_asts(struct dlm_lkb *lkb) +{ + return (lkb->lkb_exflags & DLM_LKF_NOQUEUEBAST); +} + +static inline int is_demoted(struct dlm_lkb *lkb) +{ + return (lkb->lkb_sbflags & DLM_SBF_DEMOTED); +} + +static inline int is_remote(struct dlm_rsb *r) +{ + DLM_ASSERT(r->res_nodeid >= 0, dlm_print_rsb(r);); + return !!r->res_nodeid; +} + +static inline int is_process_copy(struct dlm_lkb *lkb) +{ + return (lkb->lkb_nodeid && !(lkb->lkb_flags & DLM_IFL_MSTCPY)); +} + +static inline int is_master_copy(struct dlm_lkb *lkb) +{ + if (lkb->lkb_flags & DLM_IFL_MSTCPY) + DLM_ASSERT(lkb->lkb_nodeid, dlm_print_lkb(lkb);); + return (lkb->lkb_flags & DLM_IFL_MSTCPY) ? TRUE : FALSE; +} + +static inline int middle_conversion(struct dlm_lkb *lkb) +{ + if ((lkb->lkb_grmode==DLM_LOCK_PR && lkb->lkb_rqmode==DLM_LOCK_CW) || + (lkb->lkb_rqmode==DLM_LOCK_PR && lkb->lkb_grmode==DLM_LOCK_CW)) + return TRUE; + return FALSE; +} + +static inline int down_conversion(struct dlm_lkb *lkb) +{ + return (!middle_conversion(lkb) && lkb->lkb_rqmode < lkb->lkb_grmode); +} + +static void queue_cast(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) +{ + if (is_master_copy(lkb)) + return; + + DLM_ASSERT(lkb->lkb_lksb, dlm_print_lkb(lkb);); + + lkb->lkb_lksb->sb_status = rv; + lkb->lkb_lksb->sb_flags = lkb->lkb_sbflags; + + dlm_add_ast(lkb, AST_COMP); +} + +static void queue_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int rqmode) +{ + if (is_master_copy(lkb)) + send_bast(r, lkb, rqmode); + else { + lkb->lkb_bastmode = rqmode; + dlm_add_ast(lkb, AST_BAST); + } +} + +/* + * Basic operations on rsb's and lkb's + */ + +static struct dlm_rsb *create_rsb(struct dlm_ls *ls, char *name, int len) +{ + struct dlm_rsb *r; + + r = allocate_rsb(ls, len); + if (!r) + return NULL; + + r->res_ls = ls; + r->res_length = len; + memcpy(r->res_name, name, len); + init_MUTEX(&r->res_sem); + + INIT_LIST_HEAD(&r->res_lookup); + INIT_LIST_HEAD(&r->res_grantqueue); + INIT_LIST_HEAD(&r->res_convertqueue); + INIT_LIST_HEAD(&r->res_waitqueue); + INIT_LIST_HEAD(&r->res_root_list); + INIT_LIST_HEAD(&r->res_recover_list); + + return r; +} + +static int search_rsb_list(struct list_head *head, char *name, int len, + unsigned int flags, struct dlm_rsb **r_ret) +{ + struct dlm_rsb *r; + int error = 0; + + list_for_each_entry(r, head, res_hashchain) { + if (len == r->res_length && !memcmp(name, r->res_name, len)) + goto found; + } + return -ENOENT; + + found: + if (r->res_nodeid && (flags & R_MASTER)) + error = -ENOTBLK; + *r_ret = r; + return error; +} + +static int _search_rsb(struct dlm_ls *ls, char *name, int len, int b, + unsigned int flags, struct dlm_rsb **r_ret) +{ + struct dlm_rsb *r; + int error; + + error = search_rsb_list(&ls->ls_rsbtbl[b].list, name, len, flags, &r); + if (!error) { + kref_get(&r->res_ref); + goto out; + } + error = search_rsb_list(&ls->ls_rsbtbl[b].toss, name, len, flags, &r); + if (error) + goto out; + + list_move(&r->res_hashchain, &ls->ls_rsbtbl[b].list); + + if (dlm_no_directory(ls)) + goto out; + + if (r->res_nodeid == -1) { + rsb_clear_flag(r, RSB_MASTER_UNCERTAIN); + r->res_first_lkid = 0; + } else if (r->res_nodeid > 0) { + rsb_set_flag(r, RSB_MASTER_UNCERTAIN); + r->res_first_lkid = 0; + } else { + DLM_ASSERT(r->res_nodeid == 0, dlm_print_rsb(r);); + DLM_ASSERT(!rsb_flag(r, RSB_MASTER_UNCERTAIN),); + } + out: + *r_ret = r; + return error; +} + +static int search_rsb(struct dlm_ls *ls, char *name, int len, int b, + unsigned int flags, struct dlm_rsb **r_ret) +{ + int error; + write_lock(&ls->ls_rsbtbl[b].lock); + error = _search_rsb(ls, name, len, b, flags, r_ret); + write_unlock(&ls->ls_rsbtbl[b].lock); + return error; +} + +/* + * Find rsb in rsbtbl and potentially create/add one + * + * Delaying the release of rsb's has a similar benefit to applications keeping + * NL locks on an rsb, but without the guarantee that the cached master value + * will still be valid when the rsb is reused. Apps aren't always smart enough + * to keep NL locks on an rsb that they may lock again shortly; this can lead + * to excessive master lookups and removals if we don't delay the release. + * + * Searching for an rsb means looking through both the normal list and toss + * list. When found on the toss list the rsb is moved to the normal list with + * ref count of 1; when found on normal list the ref count is incremented. + */ + +static int find_rsb(struct dlm_ls *ls, char *name, int namelen, + unsigned int flags, struct dlm_rsb **r_ret) +{ + struct dlm_rsb *r, *tmp; + uint32_t hash, bucket; + int error = 0; + + if (dlm_no_directory(ls)) + flags |= R_CREATE; + + hash = jhash(name, namelen, 0); + bucket = hash & (ls->ls_rsbtbl_size - 1); + + error = search_rsb(ls, name, namelen, bucket, flags, &r); + if (!error) + goto out; + + if (error == -ENOENT && !(flags & R_CREATE)) + goto out; + + /* the rsb was found but wasn't a master copy */ + if (error == -ENOTBLK) + goto out; + + error = -ENOMEM; + r = create_rsb(ls, name, namelen); + if (!r) + goto out; + + r->res_hash = hash; + r->res_bucket = bucket; + r->res_nodeid = -1; + kref_init(&r->res_ref); + + /* With no directory, the master can be set immediately */ + if (dlm_no_directory(ls)) { + int nodeid = dlm_dir_nodeid(r); + if (nodeid == dlm_our_nodeid()) + nodeid = 0; + r->res_nodeid = nodeid; + } + + write_lock(&ls->ls_rsbtbl[bucket].lock); + error = _search_rsb(ls, name, namelen, bucket, 0, &tmp); + if (!error) { + write_unlock(&ls->ls_rsbtbl[bucket].lock); + free_rsb(r); + r = tmp; + goto out; + } + list_add(&r->res_hashchain, &ls->ls_rsbtbl[bucket].list); + write_unlock(&ls->ls_rsbtbl[bucket].lock); + error = 0; + out: + *r_ret = r; + return error; +} + +int dlm_find_rsb(struct dlm_ls *ls, char *name, int namelen, + unsigned int flags, struct dlm_rsb **r_ret) +{ + return find_rsb(ls, name, namelen, flags, r_ret); +} + +/* This is only called to add a reference when the code already holds + a valid reference to the rsb, so there's no need for locking. */ + +static inline void hold_rsb(struct dlm_rsb *r) +{ + kref_get(&r->res_ref); +} + +void dlm_hold_rsb(struct dlm_rsb *r) +{ + hold_rsb(r); +} + +static void toss_rsb(struct kref *kref) +{ + struct dlm_rsb *r = container_of(kref, struct dlm_rsb, res_ref); + struct dlm_ls *ls = r->res_ls; + + DLM_ASSERT(list_empty(&r->res_root_list), dlm_print_rsb(r);); + kref_init(&r->res_ref); + list_move(&r->res_hashchain, &ls->ls_rsbtbl[r->res_bucket].toss); + r->res_toss_time = jiffies; + if (r->res_lvbptr) { + free_lvb(r->res_lvbptr); + r->res_lvbptr = NULL; + } +} + +/* When all references to the rsb are gone it's transfered to + the tossed list for later disposal. */ + +static void put_rsb(struct dlm_rsb *r) +{ + struct dlm_ls *ls = r->res_ls; + uint32_t bucket = r->res_bucket; + + write_lock(&ls->ls_rsbtbl[bucket].lock); + kref_put(&r->res_ref, toss_rsb); + write_unlock(&ls->ls_rsbtbl[bucket].lock); +} + +void dlm_put_rsb(struct dlm_rsb *r) +{ + put_rsb(r); +} + +/* See comment for unhold_lkb */ + +static void unhold_rsb(struct dlm_rsb *r) +{ + int rv; + rv = kref_put(&r->res_ref, toss_rsb); + DLM_ASSERT(!rv, dlm_print_rsb(r);); +} + +static void kill_rsb(struct kref *kref) +{ + struct dlm_rsb *r = container_of(kref, struct dlm_rsb, res_ref); + + /* All work is done after the return from kref_put() so we + can release the write_lock before the remove and free. */ + + DLM_ASSERT(list_empty(&r->res_lookup),); + DLM_ASSERT(list_empty(&r->res_grantqueue),); + DLM_ASSERT(list_empty(&r->res_convertqueue),); + DLM_ASSERT(list_empty(&r->res_waitqueue),); + DLM_ASSERT(list_empty(&r->res_root_list),); + DLM_ASSERT(list_empty(&r->res_recover_list),); +} + +/* Attaching/detaching lkb's from rsb's is for rsb reference counting. + The rsb must exist as long as any lkb's for it do. */ + +static void attach_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + hold_rsb(r); + lkb->lkb_resource = r; +} + +static void detach_lkb(struct dlm_lkb *lkb) +{ + if (lkb->lkb_resource) { + put_rsb(lkb->lkb_resource); + lkb->lkb_resource = NULL; + } +} + +static int create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret) +{ + struct dlm_lkb *lkb, *tmp; + uint32_t lkid = 0; + uint16_t bucket; + + lkb = allocate_lkb(ls); + if (!lkb) + return -ENOMEM; + + lkb->lkb_nodeid = -1; + lkb->lkb_grmode = DLM_LOCK_IV; + kref_init(&lkb->lkb_ref); + + get_random_bytes(&bucket, sizeof(bucket)); + bucket &= (ls->ls_lkbtbl_size - 1); + + write_lock(&ls->ls_lkbtbl[bucket].lock); + + /* counter can roll over so we must verify lkid is not in use */ + + while (lkid == 0) { + lkid = bucket | (ls->ls_lkbtbl[bucket].counter++ << 16); + + list_for_each_entry(tmp, &ls->ls_lkbtbl[bucket].list, + lkb_idtbl_list) { + if (tmp->lkb_id != lkid) + continue; + lkid = 0; + break; + } + } + + lkb->lkb_id = lkid; + list_add(&lkb->lkb_idtbl_list, &ls->ls_lkbtbl[bucket].list); + write_unlock(&ls->ls_lkbtbl[bucket].lock); + + *lkb_ret = lkb; + return 0; +} + +static struct dlm_lkb *__find_lkb(struct dlm_ls *ls, uint32_t lkid) +{ + uint16_t bucket = lkid & 0xFFFF; + struct dlm_lkb *lkb; + + list_for_each_entry(lkb, &ls->ls_lkbtbl[bucket].list, lkb_idtbl_list) { + if (lkb->lkb_id == lkid) + return lkb; + } + return NULL; +} + +static int find_lkb(struct dlm_ls *ls, uint32_t lkid, struct dlm_lkb **lkb_ret) +{ + struct dlm_lkb *lkb; + uint16_t bucket = lkid & 0xFFFF; + + if (bucket >= ls->ls_lkbtbl_size) + return -EBADSLT; + + read_lock(&ls->ls_lkbtbl[bucket].lock); + lkb = __find_lkb(ls, lkid); + if (lkb) + kref_get(&lkb->lkb_ref); + read_unlock(&ls->ls_lkbtbl[bucket].lock); + + *lkb_ret = lkb; + return lkb ? 0 : -ENOENT; +} + +static void kill_lkb(struct kref *kref) +{ + struct dlm_lkb *lkb = container_of(kref, struct dlm_lkb, lkb_ref); + + /* All work is done after the return from kref_put() so we + can release the write_lock before the detach_lkb */ + + DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb);); +} + +static int put_lkb(struct dlm_lkb *lkb) +{ + struct dlm_ls *ls = lkb->lkb_resource->res_ls; + uint16_t bucket = lkb->lkb_id & 0xFFFF; + + write_lock(&ls->ls_lkbtbl[bucket].lock); + if (kref_put(&lkb->lkb_ref, kill_lkb)) { + list_del(&lkb->lkb_idtbl_list); + write_unlock(&ls->ls_lkbtbl[bucket].lock); + + detach_lkb(lkb); + + /* for local/process lkbs, lvbptr points to caller's lksb */ + if (lkb->lkb_lvbptr && is_master_copy(lkb)) + free_lvb(lkb->lkb_lvbptr); + if (lkb->lkb_range) + free_range(lkb->lkb_range); + free_lkb(lkb); + return 1; + } else { + write_unlock(&ls->ls_lkbtbl[bucket].lock); + return 0; + } +} + +int dlm_put_lkb(struct dlm_lkb *lkb) +{ + return put_lkb(lkb); +} + +/* This is only called to add a reference when the code already holds + a valid reference to the lkb, so there's no need for locking. */ + +static inline void hold_lkb(struct dlm_lkb *lkb) +{ + kref_get(&lkb->lkb_ref); +} + +/* This is called when we need to remove a reference and are certain + it's not the last ref. e.g. del_lkb is always called between a + find_lkb/put_lkb and is always the inverse of a previous add_lkb. + put_lkb would work fine, but would involve unnecessary locking */ + +static inline void unhold_lkb(struct dlm_lkb *lkb) +{ + int rv; + rv = kref_put(&lkb->lkb_ref, kill_lkb); + DLM_ASSERT(!rv, dlm_print_lkb(lkb);); +} + +static void lkb_add_ordered(struct list_head *new, struct list_head *head, + int mode) +{ + struct dlm_lkb *lkb = NULL; + + list_for_each_entry(lkb, head, lkb_statequeue) + if (lkb->lkb_rqmode < mode) + break; + + if (!lkb) + list_add_tail(new, head); + else + __list_add(new, lkb->lkb_statequeue.prev, &lkb->lkb_statequeue); +} + +/* add/remove lkb to rsb's grant/convert/wait queue */ + +static void add_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb, int status) +{ + kref_get(&lkb->lkb_ref); + + DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb);); + + lkb->lkb_status = status; + + switch (status) { + case DLM_LKSTS_WAITING: + if (lkb->lkb_exflags & DLM_LKF_HEADQUE) + list_add(&lkb->lkb_statequeue, &r->res_waitqueue); + else + list_add_tail(&lkb->lkb_statequeue, &r->res_waitqueue); + break; + case DLM_LKSTS_GRANTED: + /* convention says granted locks kept in order of grmode */ + lkb_add_ordered(&lkb->lkb_statequeue, &r->res_grantqueue, + lkb->lkb_grmode); + break; + case DLM_LKSTS_CONVERT: + if (lkb->lkb_exflags & DLM_LKF_HEADQUE) + list_add(&lkb->lkb_statequeue, &r->res_convertqueue); + else + list_add_tail(&lkb->lkb_statequeue, + &r->res_convertqueue); + break; + default: + DLM_ASSERT(0, dlm_print_lkb(lkb); printk("sts=%d\n", status);); + } +} + +static void del_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + lkb->lkb_status = 0; + list_del(&lkb->lkb_statequeue); + unhold_lkb(lkb); +} + +static void move_lkb(struct dlm_rsb *r, struct dlm_lkb *lkb, int sts) +{ + hold_lkb(lkb); + del_lkb(r, lkb); + add_lkb(r, lkb, sts); + unhold_lkb(lkb); +} + +/* add/remove lkb from global waiters list of lkb's waiting for + a reply from a remote node */ + +static void add_to_waiters(struct dlm_lkb *lkb, int mstype) +{ + struct dlm_ls *ls = lkb->lkb_resource->res_ls; + + down(&ls->ls_waiters_sem); + if (lkb->lkb_wait_type) { + log_print("add_to_waiters error %d", lkb->lkb_wait_type); + goto out; + } + lkb->lkb_wait_type = mstype; + kref_get(&lkb->lkb_ref); + list_add(&lkb->lkb_wait_reply, &ls->ls_waiters); + out: + up(&ls->ls_waiters_sem); +} + +static int _remove_from_waiters(struct dlm_lkb *lkb) +{ + int error = 0; + + if (!lkb->lkb_wait_type) { + log_print("remove_from_waiters error"); + error = -EINVAL; + goto out; + } + lkb->lkb_wait_type = 0; + list_del(&lkb->lkb_wait_reply); + unhold_lkb(lkb); + out: + return error; +} + +static int remove_from_waiters(struct dlm_lkb *lkb) +{ + struct dlm_ls *ls = lkb->lkb_resource->res_ls; + int error; + + down(&ls->ls_waiters_sem); + error = _remove_from_waiters(lkb); + up(&ls->ls_waiters_sem); + return error; +} + +static void dir_remove(struct dlm_rsb *r) +{ + int to_nodeid; + + if (dlm_no_directory(r->res_ls)) + return; + + to_nodeid = dlm_dir_nodeid(r); + if (to_nodeid != dlm_our_nodeid()) + send_remove(r); + else + dlm_dir_remove_entry(r->res_ls, to_nodeid, + r->res_name, r->res_length); +} + +/* FIXME: shouldn't this be able to exit as soon as one non-due rsb is + found since they are in order of newest to oldest? */ + +static int shrink_bucket(struct dlm_ls *ls, int b) +{ + struct dlm_rsb *r; + int count = 0, found; + + for (;;) { + found = FALSE; + write_lock(&ls->ls_rsbtbl[b].lock); + list_for_each_entry_reverse(r, &ls->ls_rsbtbl[b].toss, + res_hashchain) { + if (!time_after_eq(jiffies, r->res_toss_time + + dlm_config.toss_secs * HZ)) + continue; + found = TRUE; + break; + } + + if (!found) { + write_unlock(&ls->ls_rsbtbl[b].lock); + break; + } + + if (kref_put(&r->res_ref, kill_rsb)) { + list_del(&r->res_hashchain); + write_unlock(&ls->ls_rsbtbl[b].lock); + + if (is_master(r)) + dir_remove(r); + free_rsb(r); + count++; + } else { + write_unlock(&ls->ls_rsbtbl[b].lock); + log_error(ls, "tossed rsb in use %s", r->res_name); + } + } + + return count; +} + +void dlm_scan_rsbs(struct dlm_ls *ls) +{ + int i; + + if (dlm_locking_stopped(ls)) + return; + + for (i = 0; i < ls->ls_rsbtbl_size; i++) { + shrink_bucket(ls, i); + cond_resched(); + } +} + +/* lkb is master or local copy */ + +static void set_lvb_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + int b, len = r->res_ls->ls_lvblen; + + /* b=1 lvb returned to caller + b=0 lvb written to rsb or invalidated + b=-1 do nothing */ + + b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1]; + + if (b == 1) { + if (!lkb->lkb_lvbptr) + return; + + if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) + return; + + if (!r->res_lvbptr) + return; + + memcpy(lkb->lkb_lvbptr, r->res_lvbptr, len); + lkb->lkb_lvbseq = r->res_lvbseq; + + } else if (b == 0) { + if (lkb->lkb_exflags & DLM_LKF_IVVALBLK) { + rsb_set_flag(r, RSB_VALNOTVALID); + return; + } + + if (!lkb->lkb_lvbptr) + return; + + if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) + return; + + if (!r->res_lvbptr) + r->res_lvbptr = allocate_lvb(r->res_ls); + + if (!r->res_lvbptr) + return; + + memcpy(r->res_lvbptr, lkb->lkb_lvbptr, len); + r->res_lvbseq++; + lkb->lkb_lvbseq = r->res_lvbseq; + rsb_clear_flag(r, RSB_VALNOTVALID); + } + + if (rsb_flag(r, RSB_VALNOTVALID)) + lkb->lkb_sbflags |= DLM_SBF_VALNOTVALID; +} + +static void set_lvb_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + if (lkb->lkb_grmode < DLM_LOCK_PW) + return; + + if (lkb->lkb_exflags & DLM_LKF_IVVALBLK) { + rsb_set_flag(r, RSB_VALNOTVALID); + return; + } + + if (!lkb->lkb_lvbptr) + return; + + if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) + return; + + if (!r->res_lvbptr) + r->res_lvbptr = allocate_lvb(r->res_ls); + + if (!r->res_lvbptr) + return; + + memcpy(r->res_lvbptr, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); + r->res_lvbseq++; + rsb_clear_flag(r, RSB_VALNOTVALID); +} + +/* lkb is process copy (pc) */ + +static void set_lvb_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb, + struct dlm_message *ms) +{ + int b; + + if (!lkb->lkb_lvbptr) + return; + + if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) + return; + + b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1]; + if (b == 1) { + int len = receive_extralen(ms); + memcpy(lkb->lkb_lvbptr, ms->m_extra, len); + lkb->lkb_lvbseq = ms->m_lvbseq; + } +} + +/* Manipulate lkb's on rsb's convert/granted/waiting queues + remove_lock -- used for unlock, removes lkb from granted + revert_lock -- used for cancel, moves lkb from convert to granted + grant_lock -- used for request and convert, adds lkb to granted or + moves lkb from convert or waiting to granted + + Each of these is used for master or local copy lkb's. There is + also a _pc() variation used to make the corresponding change on + a process copy (pc) lkb. */ + +static void _remove_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + del_lkb(r, lkb); + lkb->lkb_grmode = DLM_LOCK_IV; + /* this unhold undoes the original ref from create_lkb() + so this leads to the lkb being freed */ + unhold_lkb(lkb); +} + +static void remove_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + set_lvb_unlock(r, lkb); + _remove_lock(r, lkb); +} + +static void remove_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + _remove_lock(r, lkb); +} + +static void revert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + lkb->lkb_rqmode = DLM_LOCK_IV; + + switch (lkb->lkb_status) { + case DLM_LKSTS_CONVERT: + move_lkb(r, lkb, DLM_LKSTS_GRANTED); + break; + case DLM_LKSTS_WAITING: + del_lkb(r, lkb); + lkb->lkb_grmode = DLM_LOCK_IV; + /* this unhold undoes the original ref from create_lkb() + so this leads to the lkb being freed */ + unhold_lkb(lkb); + break; + default: + log_print("invalid status for revert %d", lkb->lkb_status); + } +} + +static void revert_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + revert_lock(r, lkb); +} + +static void _grant_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + if (lkb->lkb_grmode != lkb->lkb_rqmode) { + lkb->lkb_grmode = lkb->lkb_rqmode; + if (lkb->lkb_status) + move_lkb(r, lkb, DLM_LKSTS_GRANTED); + else + add_lkb(r, lkb, DLM_LKSTS_GRANTED); + } + + lkb->lkb_rqmode = DLM_LOCK_IV; + + if (lkb->lkb_range) { + lkb->lkb_range[GR_RANGE_START] = lkb->lkb_range[RQ_RANGE_START]; + lkb->lkb_range[GR_RANGE_END] = lkb->lkb_range[RQ_RANGE_END]; + } +} + +static void grant_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + set_lvb_lock(r, lkb); + _grant_lock(r, lkb); + lkb->lkb_highbast = 0; +} + +static void grant_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb, + struct dlm_message *ms) +{ + set_lvb_lock_pc(r, lkb, ms); + _grant_lock(r, lkb); +} + +/* called by grant_pending_locks() which means an async grant message must + be sent to the requesting node in addition to granting the lock if the + lkb belongs to a remote node. */ + +static void grant_lock_pending(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + grant_lock(r, lkb); + if (is_master_copy(lkb)) + send_grant(r, lkb); + else + queue_cast(r, lkb, 0); +} + +static inline int first_in_list(struct dlm_lkb *lkb, struct list_head *head) +{ + struct dlm_lkb *first = list_entry(head->next, struct dlm_lkb, + lkb_statequeue); + if (lkb->lkb_id == first->lkb_id) + return TRUE; + + return FALSE; +} + +/* Return 1 if the locks' ranges overlap. If the lkb has no range then it is + assumed to cover 0-ffffffff.ffffffff */ + +static inline int ranges_overlap(struct dlm_lkb *lkb1, struct dlm_lkb *lkb2) +{ + if (!lkb1->lkb_range || !lkb2->lkb_range) + return TRUE; + + if (lkb1->lkb_range[RQ_RANGE_END] < lkb2->lkb_range[GR_RANGE_START] || + lkb1->lkb_range[RQ_RANGE_START] > lkb2->lkb_range[GR_RANGE_END]) + return FALSE; + + return TRUE; +} + +/* Check if the given lkb conflicts with another lkb on the queue. */ + +static int queue_conflict(struct list_head *head, struct dlm_lkb *lkb) +{ + struct dlm_lkb *this; + + list_for_each_entry(this, head, lkb_statequeue) { + if (this == lkb) + continue; + if (ranges_overlap(lkb, this) && !modes_compat(this, lkb)) + return TRUE; + } + return FALSE; +} + +/* + * "A conversion deadlock arises with a pair of lock requests in the converting + * queue for one resource. The granted mode of each lock blocks the requested + * mode of the other lock." + * + * Part 2: if the granted mode of lkb is preventing the first lkb in the + * convert queue from being granted, then demote lkb (set grmode to NL). + * This second form requires that we check for conv-deadlk even when + * now == 0 in _can_be_granted(). + * + * Example: + * Granted Queue: empty + * Convert Queue: NL->EX (first lock) + * PR->EX (second lock) + * + * The first lock can't be granted because of the granted mode of the second + * lock and the second lock can't be granted because it's not first in the + * list. We demote the granted mode of the second lock (the lkb passed to this + * function). + * + * After the resolution, the "grant pending" function needs to go back and try + * to grant locks on the convert queue again since the first lock can now be + * granted. + */ + +static int conversion_deadlock_detect(struct dlm_rsb *rsb, struct dlm_lkb *lkb) +{ + struct dlm_lkb *this, *first = NULL, *self = NULL; + + list_for_each_entry(this, &rsb->res_convertqueue, lkb_statequeue) { + if (!first) + first = this; + if (this == lkb) { + self = lkb; + continue; + } + + if (!ranges_overlap(lkb, this)) + continue; + + if (!modes_compat(this, lkb) && !modes_compat(lkb, this)) + return TRUE; + } + + /* if lkb is on the convert queue and is preventing the first + from being granted, then there's deadlock and we demote lkb. + multiple converting locks may need to do this before the first + converting lock can be granted. */ + + if (self && self != first) { + if (!modes_compat(lkb, first) && + !queue_conflict(&rsb->res_grantqueue, first)) + return TRUE; + } + + return FALSE; +} + +/* + * Return 1 if the lock can be granted, 0 otherwise. + * Also detect and resolve conversion deadlocks. + * + * lkb is the lock to be granted + * + * now is 1 if the function is being called in the context of the + * immediate request, it is 0 if called later, after the lock has been + * queued. + * + * References are from chapter 6 of "VAXcluster Principles" by Roy Davis + */ + +static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) +{ + int8_t conv = (lkb->lkb_grmode != DLM_LOCK_IV); + + /* + * 6-10: Version 5.4 introduced an option to address the phenomenon of + * a new request for a NL mode lock being blocked. + * + * 6-11: If the optional EXPEDITE flag is used with the new NL mode + * request, then it would be granted. In essence, the use of this flag + * tells the Lock Manager to expedite theis request by not considering + * what may be in the CONVERTING or WAITING queues... As of this + * writing, the EXPEDITE flag can be used only with new requests for NL + * mode locks. This flag is not valid for conversion requests. + * + * A shortcut. Earlier checks return an error if EXPEDITE is used in a + * conversion or used with a non-NL requested mode. We also know an + * EXPEDITE request is always granted immediately, so now must always + * be 1. The full condition to grant an expedite request: (now && + * !conv && lkb->rqmode == DLM_LOCK_NL && (flags & EXPEDITE)) can + * therefore be shortened to just checking the flag. + */ + + if (lkb->lkb_exflags & DLM_LKF_EXPEDITE) + return TRUE; + + /* + * A shortcut. Without this, !queue_conflict(grantqueue, lkb) would be + * added to the remaining conditions. + */ + + if (queue_conflict(&r->res_grantqueue, lkb)) + goto out; + + /* + * 6-3: By default, a conversion request is immediately granted if the + * requested mode is compatible with the modes of all other granted + * locks + */ + + if (queue_conflict(&r->res_convertqueue, lkb)) + goto out; + + /* + * 6-5: But the default algorithm for deciding whether to grant or + * queue conversion requests does not by itself guarantee that such + * requests are serviced on a "first come first serve" basis. This, in + * turn, can lead to a phenomenon known as "indefinate postponement". + * + * 6-7: This issue is dealt with by using the optional QUECVT flag with + * the system service employed to request a lock conversion. This flag + * forces certain conversion requests to be queued, even if they are + * compatible with the granted modes of other locks on the same + * resource. Thus, the use of this flag results in conversion requests + * being ordered on a "first come first servce" basis. + * + * DCT: This condition is all about new conversions being able to occur + * "in place" while the lock remains on the granted queue (assuming + * nothing else conflicts.) IOW if QUECVT isn't set, a conversion + * doesn't _have_ to go onto the convert queue where it's processed in + * order. The "now" variable is necessary to distinguish converts + * being received and processed for the first time now, because once a + * convert is moved to the conversion queue the condition below applies + * requiring fifo granting. + */ + + if (now && conv && !(lkb->lkb_exflags & DLM_LKF_QUECVT)) + return TRUE; + + /* + * When using range locks the NOORDER flag is set to avoid the standard + * vms rules on grant order. + */ + + if (lkb->lkb_exflags & DLM_LKF_NOORDER) + return TRUE; + + /* + * 6-3: Once in that queue [CONVERTING], a conversion request cannot be + * granted until all other conversion requests ahead of it are granted + * and/or canceled. + */ + + if (!now && conv && first_in_list(lkb, &r->res_convertqueue)) + return TRUE; + + /* + * 6-4: By default, a new request is immediately granted only if all + * three of the following conditions are satisfied when the request is + * issued: + * - The queue of ungranted conversion requests for the resource is + * empty. + * - The queue of ungranted new requests for the resource is empty. + * - The mode of the new request is compatible with the most + * restrictive mode of all granted locks on the resource. + */ + + if (now && !conv && list_empty(&r->res_convertqueue) && + list_empty(&r->res_waitqueue)) + return TRUE; + + /* + * 6-4: Once a lock request is in the queue of ungranted new requests, + * it cannot be granted until the queue of ungranted conversion + * requests is empty, all ungranted new requests ahead of it are + * granted and/or canceled, and it is compatible with the granted mode + * of the most restrictive lock granted on the resource. + */ + + if (!now && !conv && list_empty(&r->res_convertqueue) && + first_in_list(lkb, &r->res_waitqueue)) + return TRUE; + + out: + /* + * The following, enabled by CONVDEADLK, departs from VMS. + */ + + if (conv && (lkb->lkb_exflags & DLM_LKF_CONVDEADLK) && + conversion_deadlock_detect(r, lkb)) { + lkb->lkb_grmode = DLM_LOCK_NL; + lkb->lkb_sbflags |= DLM_SBF_DEMOTED; + } + + return FALSE; +} + +/* + * The ALTPR and ALTCW flags aren't traditional lock manager flags, but are a + * simple way to provide a big optimization to applications that can use them. + */ + +static int can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) +{ + uint32_t flags = lkb->lkb_exflags; + int rv; + int8_t alt = 0, rqmode = lkb->lkb_rqmode; + + rv = _can_be_granted(r, lkb, now); + if (rv) + goto out; + + if (lkb->lkb_sbflags & DLM_SBF_DEMOTED) + goto out; + + if (rqmode != DLM_LOCK_PR && flags & DLM_LKF_ALTPR) + alt = DLM_LOCK_PR; + else if (rqmode != DLM_LOCK_CW && flags & DLM_LKF_ALTCW) + alt = DLM_LOCK_CW; + + if (alt) { + lkb->lkb_rqmode = alt; + rv = _can_be_granted(r, lkb, now); + if (rv) + lkb->lkb_sbflags |= DLM_SBF_ALTMODE; + else + lkb->lkb_rqmode = rqmode; + } + out: + return rv; +} + +static int grant_pending_convert(struct dlm_rsb *r, int high) +{ + struct dlm_lkb *lkb, *s; + int hi, demoted, quit, grant_restart, demote_restart; + + quit = 0; + restart: + grant_restart = 0; + demote_restart = 0; + hi = DLM_LOCK_IV; + + list_for_each_entry_safe(lkb, s, &r->res_convertqueue, lkb_statequeue) { + demoted = is_demoted(lkb); + if (can_be_granted(r, lkb, FALSE)) { + grant_lock_pending(r, lkb); + grant_restart = 1; + } else { + hi = max_t(int, lkb->lkb_rqmode, hi); + if (!demoted && is_demoted(lkb)) + demote_restart = 1; + } + } + + if (grant_restart) + goto restart; + if (demote_restart && !quit) { + quit = 1; + goto restart; + } + + return max_t(int, high, hi); +} + +static int grant_pending_wait(struct dlm_rsb *r, int high) +{ + struct dlm_lkb *lkb, *s; + + list_for_each_entry_safe(lkb, s, &r->res_waitqueue, lkb_statequeue) { + if (can_be_granted(r, lkb, FALSE)) + grant_lock_pending(r, lkb); + else + high = max_t(int, lkb->lkb_rqmode, high); + } + + return high; +} + +static void grant_pending_locks(struct dlm_rsb *r) +{ + struct dlm_lkb *lkb, *s; + int high = DLM_LOCK_IV; + + DLM_ASSERT(is_master(r), dlm_print_rsb(r);); + + high = grant_pending_convert(r, high); + high = grant_pending_wait(r, high); + + if (high == DLM_LOCK_IV) + return; + + /* + * If there are locks left on the wait/convert queue then send blocking + * ASTs to granted locks based on the largest requested mode (high) + * found above. This can generate spurious blocking ASTs for range + * locks. FIXME: highbast < high comparison not valid for PR/CW. + */ + + list_for_each_entry_safe(lkb, s, &r->res_grantqueue, lkb_statequeue) { + if (lkb->lkb_bastaddr && (lkb->lkb_highbast < high) && + !__dlm_compat_matrix[lkb->lkb_grmode+1][high+1]) { + queue_bast(r, lkb, high); + lkb->lkb_highbast = high; + } + } +} + +static void send_bast_queue(struct dlm_rsb *r, struct list_head *head, + struct dlm_lkb *lkb) +{ + struct dlm_lkb *gr; + + list_for_each_entry(gr, head, lkb_statequeue) { + if (gr->lkb_bastaddr && + gr->lkb_highbast < lkb->lkb_rqmode && + ranges_overlap(lkb, gr) && !modes_compat(gr, lkb)) { + queue_bast(r, gr, lkb->lkb_rqmode); + gr->lkb_highbast = lkb->lkb_rqmode; + } + } +} + +static void send_blocking_asts(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + send_bast_queue(r, &r->res_grantqueue, lkb); +} + +static void send_blocking_asts_all(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + send_bast_queue(r, &r->res_grantqueue, lkb); + send_bast_queue(r, &r->res_convertqueue, lkb); +} + +/* set_master(r, lkb) -- set the master nodeid of a resource + + The purpose of this function is to set the nodeid field in the given + lkb using the nodeid field in the given rsb. If the rsb's nodeid is + known, it can just be copied to the lkb and the function will return + 0. If the rsb's nodeid is _not_ known, it needs to be looked up + before it can be copied to the lkb. + + When the rsb nodeid is being looked up remotely, the initial lkb + causing the lookup is kept on the ls_waiters list waiting for the + lookup reply. Other lkb's waiting for the same rsb lookup are kept + on the rsb's res_lookup list until the master is verified. + + Return values: + 0: nodeid is set in rsb/lkb and the caller should go ahead and use it + 1: the rsb master is not available and the lkb has been placed on + a wait queue +*/ + +static int set_master(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + struct dlm_ls *ls = r->res_ls; + int error, dir_nodeid, ret_nodeid, our_nodeid = dlm_our_nodeid(); + + if (rsb_flag(r, RSB_MASTER_UNCERTAIN)) { + rsb_clear_flag(r, RSB_MASTER_UNCERTAIN); + r->res_first_lkid = lkb->lkb_id; + lkb->lkb_nodeid = r->res_nodeid; + return 0; + } + + if (r->res_first_lkid && r->res_first_lkid != lkb->lkb_id) { + list_add_tail(&lkb->lkb_rsb_lookup, &r->res_lookup); + return 1; + } + + if (r->res_nodeid == 0) { + lkb->lkb_nodeid = 0; + return 0; + } + + if (r->res_nodeid > 0) { + lkb->lkb_nodeid = r->res_nodeid; + return 0; + } + + DLM_ASSERT(r->res_nodeid == -1, dlm_print_rsb(r);); + + dir_nodeid = dlm_dir_nodeid(r); + + if (dir_nodeid != our_nodeid) { + r->res_first_lkid = lkb->lkb_id; + send_lookup(r, lkb); + return 1; + } + + for (;;) { + /* It's possible for dlm_scand to remove an old rsb for + this same resource from the toss list, us to create + a new one, look up the master locally, and find it + already exists just before dlm_scand does the + dir_remove() on the previous rsb. */ + + error = dlm_dir_lookup(ls, our_nodeid, r->res_name, + r->res_length, &ret_nodeid); + if (!error) + break; + log_debug(ls, "dir_lookup error %d %s", error, r->res_name); + schedule(); + } + + if (ret_nodeid == our_nodeid) { + r->res_first_lkid = 0; + r->res_nodeid = 0; + lkb->lkb_nodeid = 0; + } else { + r->res_first_lkid = lkb->lkb_id; + r->res_nodeid = ret_nodeid; + lkb->lkb_nodeid = ret_nodeid; + } + return 0; +} + +static void process_lookup_list(struct dlm_rsb *r) +{ + struct dlm_lkb *lkb, *safe; + + list_for_each_entry_safe(lkb, safe, &r->res_lookup, lkb_rsb_lookup) { + list_del(&lkb->lkb_rsb_lookup); + _request_lock(r, lkb); + schedule(); + } +} + +/* confirm_master -- confirm (or deny) an rsb's master nodeid */ + +static void confirm_master(struct dlm_rsb *r, int error) +{ + struct dlm_lkb *lkb; + + if (!r->res_first_lkid) + return; + + switch (error) { + case 0: + case -EINPROGRESS: + r->res_first_lkid = 0; + process_lookup_list(r); + break; + + case -EAGAIN: + /* the remote master didn't queue our NOQUEUE request; + make a waiting lkb the first_lkid */ + + r->res_first_lkid = 0; + + if (!list_empty(&r->res_lookup)) { + lkb = list_entry(r->res_lookup.next, struct dlm_lkb, + lkb_rsb_lookup); + list_del(&lkb->lkb_rsb_lookup); + r->res_first_lkid = lkb->lkb_id; + _request_lock(r, lkb); + } else + r->res_nodeid = -1; + break; + + default: + log_error(r->res_ls, "confirm_master unknown error %d", error); + } +} + +static int set_lock_args(int mode, struct dlm_lksb *lksb, uint32_t flags, + int namelen, uint32_t parent_lkid, void *ast, + void *astarg, void *bast, struct dlm_range *range, + struct dlm_args *args) +{ + int rv = -EINVAL; + + /* check for invalid arg usage */ + + if (mode < 0 || mode > DLM_LOCK_EX) + goto out; + + if (!(flags & DLM_LKF_CONVERT) && (namelen > DLM_RESNAME_MAXLEN)) + goto out; + + if (flags & DLM_LKF_CANCEL) + goto out; + + if (flags & DLM_LKF_QUECVT && !(flags & DLM_LKF_CONVERT)) + goto out; + + if (flags & DLM_LKF_CONVDEADLK && !(flags & DLM_LKF_CONVERT)) + goto out; + + if (flags & DLM_LKF_CONVDEADLK && flags & DLM_LKF_NOQUEUE) + goto out; + + if (flags & DLM_LKF_EXPEDITE && flags & DLM_LKF_CONVERT) + goto out; + + if (flags & DLM_LKF_EXPEDITE && flags & DLM_LKF_QUECVT) + goto out; + + if (flags & DLM_LKF_EXPEDITE && flags & DLM_LKF_NOQUEUE) + goto out; + + if (flags & DLM_LKF_EXPEDITE && mode != DLM_LOCK_NL) + goto out; + + if (!ast || !lksb) + goto out; + + if (flags & DLM_LKF_VALBLK && !lksb->sb_lvbptr) + goto out; + + /* parent/child locks not yet supported */ + if (parent_lkid) + goto out; + + if (flags & DLM_LKF_CONVERT && !lksb->sb_lkid) + goto out; + + /* these args will be copied to the lkb in validate_lock_args, + it cannot be done now because when converting locks, fields in + an active lkb cannot be modified before locking the rsb */ + + args->flags = flags; + args->astaddr = ast; + args->astparam = (long) astarg; + args->bastaddr = bast; + args->mode = mode; + args->lksb = lksb; + args->range = range; + rv = 0; + out: + return rv; +} + +static int set_unlock_args(uint32_t flags, void *astarg, struct dlm_args *args) +{ + if (flags & ~(DLM_LKF_CANCEL | DLM_LKF_VALBLK | DLM_LKF_IVVALBLK | + DLM_LKF_FORCEUNLOCK)) + return -EINVAL; + + args->flags = flags; + args->astparam = (long) astarg; + return 0; +} + +static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, + struct dlm_args *args) +{ + int rv = -EINVAL; + + if (args->flags & DLM_LKF_CONVERT) { + if (lkb->lkb_flags & DLM_IFL_MSTCPY) + goto out; + + if (args->flags & DLM_LKF_QUECVT && + !__quecvt_compat_matrix[lkb->lkb_grmode+1][args->mode+1]) + goto out; + + rv = -EBUSY; + if (lkb->lkb_status != DLM_LKSTS_GRANTED) + goto out; + + if (lkb->lkb_wait_type) + goto out; + } + + lkb->lkb_exflags = args->flags; + lkb->lkb_sbflags = 0; + lkb->lkb_astaddr = args->astaddr; + lkb->lkb_astparam = args->astparam; + lkb->lkb_bastaddr = args->bastaddr; + lkb->lkb_rqmode = args->mode; + lkb->lkb_lksb = args->lksb; + lkb->lkb_lvbptr = args->lksb->sb_lvbptr; + lkb->lkb_ownpid = (int) current->pid; + + rv = 0; + if (!args->range) + goto out; + + if (!lkb->lkb_range) { + rv = -ENOMEM; + lkb->lkb_range = allocate_range(ls); + if (!lkb->lkb_range) + goto out; + /* This is needed for conversions that contain ranges + where the original lock didn't but it's harmless for + new locks too. */ + lkb->lkb_range[GR_RANGE_START] = 0LL; + lkb->lkb_range[GR_RANGE_END] = 0xffffffffffffffffULL; + } + + lkb->lkb_range[RQ_RANGE_START] = args->range->ra_start; + lkb->lkb_range[RQ_RANGE_END] = args->range->ra_end; + lkb->lkb_flags |= DLM_IFL_RANGE; + rv = 0; + out: + return rv; +} + +static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args) +{ + int rv = -EINVAL; + + if (lkb->lkb_flags & DLM_IFL_MSTCPY) + goto out; + + if (args->flags & DLM_LKF_FORCEUNLOCK) + goto out_ok; + + if (args->flags & DLM_LKF_CANCEL && + lkb->lkb_status == DLM_LKSTS_GRANTED) + goto out; + + if (!(args->flags & DLM_LKF_CANCEL) && + lkb->lkb_status != DLM_LKSTS_GRANTED) + goto out; + + rv = -EBUSY; + if (lkb->lkb_wait_type) + goto out; + + out_ok: + lkb->lkb_exflags = args->flags; + lkb->lkb_sbflags = 0; + lkb->lkb_astparam = args->astparam; + + rv = 0; + out: + return rv; +} + +/* + * Four stage 4 varieties: + * do_request(), do_convert(), do_unlock(), do_cancel() + * These are called on the master node for the given lock and + * from the central locking logic. + */ + +static int do_request(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + int error = 0; + + if (can_be_granted(r, lkb, TRUE)) { + grant_lock(r, lkb); + queue_cast(r, lkb, 0); + goto out; + } + + if (can_be_queued(lkb)) { + error = -EINPROGRESS; + add_lkb(r, lkb, DLM_LKSTS_WAITING); + send_blocking_asts(r, lkb); + goto out; + } + + error = -EAGAIN; + if (force_blocking_asts(lkb)) + send_blocking_asts_all(r, lkb); + queue_cast(r, lkb, -EAGAIN); + + out: + return error; +} + +static int do_convert(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + int error = 0; + + /* changing an existing lock may allow others to be granted */ + + if (can_be_granted(r, lkb, TRUE)) { + grant_lock(r, lkb); + queue_cast(r, lkb, 0); + grant_pending_locks(r); + goto out; + } + + if (can_be_queued(lkb)) { + if (is_demoted(lkb)) + grant_pending_locks(r); + error = -EINPROGRESS; + del_lkb(r, lkb); + add_lkb(r, lkb, DLM_LKSTS_CONVERT); + send_blocking_asts(r, lkb); + goto out; + } + + error = -EAGAIN; + if (force_blocking_asts(lkb)) + send_blocking_asts_all(r, lkb); + queue_cast(r, lkb, -EAGAIN); + + out: + return error; +} + +static int do_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + remove_lock(r, lkb); + queue_cast(r, lkb, -DLM_EUNLOCK); + grant_pending_locks(r); + return -DLM_EUNLOCK; +} + +static int do_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + revert_lock(r, lkb); + queue_cast(r, lkb, -DLM_ECANCEL); + grant_pending_locks(r); + return -DLM_ECANCEL; +} + +/* + * Four stage 3 varieties: + * _request_lock(), _convert_lock(), _unlock_lock(), _cancel_lock() + */ + +/* add a new lkb to a possibly new rsb, called by requesting process */ + +static int _request_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + int error; + + /* set_master: sets lkb nodeid from r */ + + error = set_master(r, lkb); + if (error < 0) + goto out; + if (error) { + error = 0; + goto out; + } + + if (is_remote(r)) + /* receive_request() calls do_request() on remote node */ + error = send_request(r, lkb); + else + error = do_request(r, lkb); + out: + return error; +} + +/* change some property of an existing lkb, e.g. mode, range */ + +static int _convert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + int error; + + if (is_remote(r)) + /* receive_convert() calls do_convert() on remote node */ + error = send_convert(r, lkb); + else + error = do_convert(r, lkb); + + return error; +} + +/* remove an existing lkb from the granted queue */ + +static int _unlock_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + int error; + + if (is_remote(r)) + /* receive_unlock() calls do_unlock() on remote node */ + error = send_unlock(r, lkb); + else + error = do_unlock(r, lkb); + + return error; +} + +/* remove an existing lkb from the convert or wait queue */ + +static int _cancel_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + int error; + + if (is_remote(r)) + /* receive_cancel() calls do_cancel() on remote node */ + error = send_cancel(r, lkb); + else + error = do_cancel(r, lkb); + + return error; +} + +/* + * Four stage 2 varieties: + * request_lock(), convert_lock(), unlock_lock(), cancel_lock() + */ + +static int request_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, char *name, + int len, struct dlm_args *args) +{ + struct dlm_rsb *r; + int error; + + error = validate_lock_args(ls, lkb, args); + if (error) + goto out; + + error = find_rsb(ls, name, len, R_CREATE, &r); + if (error) + goto out; + + lock_rsb(r); + + attach_lkb(r, lkb); + lkb->lkb_lksb->sb_lkid = lkb->lkb_id; + + error = _request_lock(r, lkb); + + unlock_rsb(r); + put_rsb(r); + + out: + return error; +} + +static int convert_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, + struct dlm_args *args) +{ + struct dlm_rsb *r; + int error; + + r = lkb->lkb_resource; + + hold_rsb(r); + lock_rsb(r); + + error = validate_lock_args(ls, lkb, args); + if (error) + goto out; + + error = _convert_lock(r, lkb); + out: + unlock_rsb(r); + put_rsb(r); + return error; +} + +static int unlock_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, + struct dlm_args *args) +{ + struct dlm_rsb *r; + int error; + + r = lkb->lkb_resource; + + hold_rsb(r); + lock_rsb(r); + + error = validate_unlock_args(lkb, args); + if (error) + goto out; + + error = _unlock_lock(r, lkb); + out: + unlock_rsb(r); + put_rsb(r); + return error; +} + +static int cancel_lock(struct dlm_ls *ls, struct dlm_lkb *lkb, + struct dlm_args *args) +{ + struct dlm_rsb *r; + int error; + + r = lkb->lkb_resource; + + hold_rsb(r); + lock_rsb(r); + + error = validate_unlock_args(lkb, args); + if (error) + goto out; + + error = _cancel_lock(r, lkb); + out: + unlock_rsb(r); + put_rsb(r); + return error; +} + +/* + * Two stage 1 varieties: dlm_lock() and dlm_unlock() + */ + +int dlm_lock(dlm_lockspace_t *lockspace, + int mode, + struct dlm_lksb *lksb, + uint32_t flags, + void *name, + unsigned int namelen, + uint32_t parent_lkid, + void (*ast) (void *astarg), + void *astarg, + void (*bast) (void *astarg, int mode), + struct dlm_range *range) +{ + struct dlm_ls *ls; + struct dlm_lkb *lkb; + struct dlm_args args; + int error, convert = flags & DLM_LKF_CONVERT; + + ls = dlm_find_lockspace_local(lockspace); + if (!ls) + return -EINVAL; + + lock_recovery(ls); + + if (convert) + error = find_lkb(ls, lksb->sb_lkid, &lkb); + else + error = create_lkb(ls, &lkb); + + if (error) + goto out; + + error = set_lock_args(mode, lksb, flags, namelen, parent_lkid, ast, + astarg, bast, range, &args); + if (error) + goto out_put; + + if (convert) + error = convert_lock(ls, lkb, &args); + else + error = request_lock(ls, lkb, name, namelen, &args); + + if (error == -EINPROGRESS) + error = 0; + out_put: + if (convert || error) + put_lkb(lkb); + if (error == -EAGAIN) + error = 0; + out: + unlock_recovery(ls); + dlm_put_lockspace(ls); + return error; +} + +int dlm_unlock(dlm_lockspace_t *lockspace, + uint32_t lkid, + uint32_t flags, + struct dlm_lksb *lksb, + void *astarg) +{ + struct dlm_ls *ls; + struct dlm_lkb *lkb; + struct dlm_args args; + int error; + + ls = dlm_find_lockspace_local(lockspace); + if (!ls) + return -EINVAL; + + lock_recovery(ls); + + error = find_lkb(ls, lkid, &lkb); + if (error) + goto out; + + error = set_unlock_args(flags, astarg, &args); + if (error) + goto out_put; + + if (flags & DLM_LKF_CANCEL) + error = cancel_lock(ls, lkb, &args); + else + error = unlock_lock(ls, lkb, &args); + + if (error == -DLM_EUNLOCK || error == -DLM_ECANCEL) + error = 0; + out_put: + put_lkb(lkb); + out: + unlock_recovery(ls); + dlm_put_lockspace(ls); + return error; +} + +/* + * send/receive routines for remote operations and replies + * + * send_args + * send_common + * send_request receive_request + * send_convert receive_convert + * send_unlock receive_unlock + * send_cancel receive_cancel + * send_grant receive_grant + * send_bast receive_bast + * send_lookup receive_lookup + * send_remove receive_remove + * + * send_common_reply + * receive_request_reply send_request_reply + * receive_convert_reply send_convert_reply + * receive_unlock_reply send_unlock_reply + * receive_cancel_reply send_cancel_reply + * receive_lookup_reply send_lookup_reply + */ + +static int create_message(struct dlm_rsb *r, struct dlm_lkb *lkb, + int to_nodeid, int mstype, + struct dlm_message **ms_ret, + struct dlm_mhandle **mh_ret) +{ + struct dlm_message *ms; + struct dlm_mhandle *mh; + char *mb; + int mb_len = sizeof(struct dlm_message); + + switch (mstype) { + case DLM_MSG_REQUEST: + case DLM_MSG_LOOKUP: + case DLM_MSG_REMOVE: + mb_len += r->res_length; + break; + case DLM_MSG_CONVERT: + case DLM_MSG_UNLOCK: + case DLM_MSG_REQUEST_REPLY: + case DLM_MSG_CONVERT_REPLY: + case DLM_MSG_GRANT: + if (lkb && lkb->lkb_lvbptr) + mb_len += r->res_ls->ls_lvblen; + break; + } + + /* get_buffer gives us a message handle (mh) that we need to + pass into lowcomms_commit and a message buffer (mb) that we + write our data into */ + + mh = dlm_lowcomms_get_buffer(to_nodeid, mb_len, GFP_KERNEL, &mb); + if (!mh) + return -ENOBUFS; + + memset(mb, 0, mb_len); + + ms = (struct dlm_message *) mb; + + ms->m_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); + ms->m_header.h_lockspace = r->res_ls->ls_global_id; + ms->m_header.h_nodeid = dlm_our_nodeid(); + ms->m_header.h_length = mb_len; + ms->m_header.h_cmd = DLM_MSG; + + ms->m_type = mstype; + + *mh_ret = mh; + *ms_ret = ms; + return 0; +} + +/* further lowcomms enhancements or alternate implementations may make + the return value from this function useful at some point */ + +static int send_message(struct dlm_mhandle *mh, struct dlm_message *ms) +{ + dlm_message_out(ms); + dlm_lowcomms_commit_buffer(mh); + return 0; +} + +static void send_args(struct dlm_rsb *r, struct dlm_lkb *lkb, + struct dlm_message *ms) +{ + ms->m_nodeid = lkb->lkb_nodeid; + ms->m_pid = lkb->lkb_ownpid; + ms->m_lkid = lkb->lkb_id; + ms->m_remid = lkb->lkb_remid; + ms->m_exflags = lkb->lkb_exflags; + ms->m_sbflags = lkb->lkb_sbflags; + ms->m_flags = lkb->lkb_flags; + ms->m_lvbseq = lkb->lkb_lvbseq; + ms->m_status = lkb->lkb_status; + ms->m_grmode = lkb->lkb_grmode; + ms->m_rqmode = lkb->lkb_rqmode; + ms->m_hash = r->res_hash; + + /* m_result and m_bastmode are set from function args, + not from lkb fields */ + + if (lkb->lkb_bastaddr) + ms->m_asts |= AST_BAST; + if (lkb->lkb_astaddr) + ms->m_asts |= AST_COMP; + + if (lkb->lkb_range) { + ms->m_range[0] = lkb->lkb_range[RQ_RANGE_START]; + ms->m_range[1] = lkb->lkb_range[RQ_RANGE_END]; + } + + if (ms->m_type == DLM_MSG_REQUEST || ms->m_type == DLM_MSG_LOOKUP) + memcpy(ms->m_extra, r->res_name, r->res_length); + + else if (lkb->lkb_lvbptr) + memcpy(ms->m_extra, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); + +} + +static int send_common(struct dlm_rsb *r, struct dlm_lkb *lkb, int mstype) +{ + struct dlm_message *ms; + struct dlm_mhandle *mh; + int to_nodeid, error; + + add_to_waiters(lkb, mstype); + + to_nodeid = r->res_nodeid; + + error = create_message(r, lkb, to_nodeid, mstype, &ms, &mh); + if (error) + goto fail; + + send_args(r, lkb, ms); + + error = send_message(mh, ms); + if (error) + goto fail; + return 0; + + fail: + remove_from_waiters(lkb); + return error; +} + +static int send_request(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + return send_common(r, lkb, DLM_MSG_REQUEST); +} + +static int send_convert(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + int error; + + error = send_common(r, lkb, DLM_MSG_CONVERT); + + /* down conversions go without a reply from the master */ + if (!error && down_conversion(lkb)) { + remove_from_waiters(lkb); + r->res_ls->ls_stub_ms.m_result = 0; + __receive_convert_reply(r, lkb, &r->res_ls->ls_stub_ms); + } + + return error; +} + +/* FIXME: if this lkb is the only lock we hold on the rsb, then set + MASTER_UNCERTAIN to force the next request on the rsb to confirm + that the master is still correct. */ + +static int send_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + return send_common(r, lkb, DLM_MSG_UNLOCK); +} + +static int send_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + return send_common(r, lkb, DLM_MSG_CANCEL); +} + +static int send_grant(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + struct dlm_message *ms; + struct dlm_mhandle *mh; + int to_nodeid, error; + + to_nodeid = lkb->lkb_nodeid; + + error = create_message(r, lkb, to_nodeid, DLM_MSG_GRANT, &ms, &mh); + if (error) + goto out; + + send_args(r, lkb, ms); + + ms->m_result = 0; + + error = send_message(mh, ms); + out: + return error; +} + +static int send_bast(struct dlm_rsb *r, struct dlm_lkb *lkb, int mode) +{ + struct dlm_message *ms; + struct dlm_mhandle *mh; + int to_nodeid, error; + + to_nodeid = lkb->lkb_nodeid; + + error = create_message(r, NULL, to_nodeid, DLM_MSG_BAST, &ms, &mh); + if (error) + goto out; + + send_args(r, lkb, ms); + + ms->m_bastmode = mode; + + error = send_message(mh, ms); + out: + return error; +} + +static int send_lookup(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + struct dlm_message *ms; + struct dlm_mhandle *mh; + int to_nodeid, error; + + add_to_waiters(lkb, DLM_MSG_LOOKUP); + + to_nodeid = dlm_dir_nodeid(r); + + error = create_message(r, NULL, to_nodeid, DLM_MSG_LOOKUP, &ms, &mh); + if (error) + goto fail; + + send_args(r, lkb, ms); + + error = send_message(mh, ms); + if (error) + goto fail; + return 0; + + fail: + remove_from_waiters(lkb); + return error; +} + +static int send_remove(struct dlm_rsb *r) +{ + struct dlm_message *ms; + struct dlm_mhandle *mh; + int to_nodeid, error; + + to_nodeid = dlm_dir_nodeid(r); + + error = create_message(r, NULL, to_nodeid, DLM_MSG_REMOVE, &ms, &mh); + if (error) + goto out; + + memcpy(ms->m_extra, r->res_name, r->res_length); + ms->m_hash = r->res_hash; + + error = send_message(mh, ms); + out: + return error; +} + +static int send_common_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, + int mstype, int rv) +{ + struct dlm_message *ms; + struct dlm_mhandle *mh; + int to_nodeid, error; + + to_nodeid = lkb->lkb_nodeid; + + error = create_message(r, lkb, to_nodeid, mstype, &ms, &mh); + if (error) + goto out; + + send_args(r, lkb, ms); + + ms->m_result = rv; + + error = send_message(mh, ms); + out: + return error; +} + +static int send_request_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) +{ + return send_common_reply(r, lkb, DLM_MSG_REQUEST_REPLY, rv); +} + +static int send_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) +{ + return send_common_reply(r, lkb, DLM_MSG_CONVERT_REPLY, rv); +} + +static int send_unlock_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) +{ + return send_common_reply(r, lkb, DLM_MSG_UNLOCK_REPLY, rv); +} + +static int send_cancel_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, int rv) +{ + return send_common_reply(r, lkb, DLM_MSG_CANCEL_REPLY, rv); +} + +static int send_lookup_reply(struct dlm_ls *ls, struct dlm_message *ms_in, + int ret_nodeid, int rv) +{ + struct dlm_rsb *r = &ls->ls_stub_rsb; + struct dlm_message *ms; + struct dlm_mhandle *mh; + int error, nodeid = ms_in->m_header.h_nodeid; + + error = create_message(r, NULL, nodeid, DLM_MSG_LOOKUP_REPLY, &ms, &mh); + if (error) + goto out; + + ms->m_lkid = ms_in->m_lkid; + ms->m_result = rv; + ms->m_nodeid = ret_nodeid; + + error = send_message(mh, ms); + out: + return error; +} + +/* which args we save from a received message depends heavily on the type + of message, unlike the send side where we can safely send everything about + the lkb for any type of message */ + +static void receive_flags(struct dlm_lkb *lkb, struct dlm_message *ms) +{ + lkb->lkb_exflags = ms->m_exflags; + lkb->lkb_flags = (lkb->lkb_flags & 0xFFFF0000) | + (ms->m_flags & 0x0000FFFF); +} + +static void receive_flags_reply(struct dlm_lkb *lkb, struct dlm_message *ms) +{ + lkb->lkb_sbflags = ms->m_sbflags; + lkb->lkb_flags = (lkb->lkb_flags & 0xFFFF0000) | + (ms->m_flags & 0x0000FFFF); +} + +static int receive_extralen(struct dlm_message *ms) +{ + return (ms->m_header.h_length - sizeof(struct dlm_message)); +} + +static int receive_range(struct dlm_ls *ls, struct dlm_lkb *lkb, + struct dlm_message *ms) +{ + if (lkb->lkb_flags & DLM_IFL_RANGE) { + if (!lkb->lkb_range) + lkb->lkb_range = allocate_range(ls); + if (!lkb->lkb_range) + return -ENOMEM; + lkb->lkb_range[RQ_RANGE_START] = ms->m_range[0]; + lkb->lkb_range[RQ_RANGE_END] = ms->m_range[1]; + } + return 0; +} + +static int receive_lvb(struct dlm_ls *ls, struct dlm_lkb *lkb, + struct dlm_message *ms) +{ + int len; + + if (lkb->lkb_exflags & DLM_LKF_VALBLK) { + if (!lkb->lkb_lvbptr) + lkb->lkb_lvbptr = allocate_lvb(ls); + if (!lkb->lkb_lvbptr) + return -ENOMEM; + len = receive_extralen(ms); + memcpy(lkb->lkb_lvbptr, ms->m_extra, len); + } + return 0; +} + +static int receive_request_args(struct dlm_ls *ls, struct dlm_lkb *lkb, + struct dlm_message *ms) +{ + lkb->lkb_nodeid = ms->m_header.h_nodeid; + lkb->lkb_ownpid = ms->m_pid; + lkb->lkb_remid = ms->m_lkid; + lkb->lkb_grmode = DLM_LOCK_IV; + lkb->lkb_rqmode = ms->m_rqmode; + lkb->lkb_bastaddr = (void *) (long) (ms->m_asts & AST_BAST); + lkb->lkb_astaddr = (void *) (long) (ms->m_asts & AST_COMP); + + DLM_ASSERT(is_master_copy(lkb), dlm_print_lkb(lkb);); + + if (receive_range(ls, lkb, ms)) + return -ENOMEM; + + if (receive_lvb(ls, lkb, ms)) + return -ENOMEM; + + return 0; +} + +static int receive_convert_args(struct dlm_ls *ls, struct dlm_lkb *lkb, + struct dlm_message *ms) +{ + if (lkb->lkb_nodeid != ms->m_header.h_nodeid) { + log_error(ls, "convert_args nodeid %d %d lkid %x %x", + lkb->lkb_nodeid, ms->m_header.h_nodeid, + lkb->lkb_id, lkb->lkb_remid); + return -EINVAL; + } + + if (!is_master_copy(lkb)) + return -EINVAL; + + if (lkb->lkb_status != DLM_LKSTS_GRANTED) + return -EBUSY; + + if (receive_range(ls, lkb, ms)) + return -ENOMEM; + if (lkb->lkb_range) { + lkb->lkb_range[GR_RANGE_START] = 0LL; + lkb->lkb_range[GR_RANGE_END] = 0xffffffffffffffffULL; + } + + if (receive_lvb(ls, lkb, ms)) + return -ENOMEM; + + lkb->lkb_rqmode = ms->m_rqmode; + lkb->lkb_lvbseq = ms->m_lvbseq; + + return 0; +} + +static int receive_unlock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, + struct dlm_message *ms) +{ + if (!is_master_copy(lkb)) + return -EINVAL; + if (receive_lvb(ls, lkb, ms)) + return -ENOMEM; + return 0; +} + +/* We fill in the stub-lkb fields with the info that send_xxxx_reply() + uses to send a reply and that the remote end uses to process the reply. */ + +static void setup_stub_lkb(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb = &ls->ls_stub_lkb; + lkb->lkb_nodeid = ms->m_header.h_nodeid; + lkb->lkb_remid = ms->m_lkid; +} + +static void receive_request(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + struct dlm_rsb *r; + int error, namelen; + + error = create_lkb(ls, &lkb); + if (error) + goto fail; + + receive_flags(lkb, ms); + lkb->lkb_flags |= DLM_IFL_MSTCPY; + error = receive_request_args(ls, lkb, ms); + if (error) { + put_lkb(lkb); + goto fail; + } + + namelen = receive_extralen(ms); + + error = find_rsb(ls, ms->m_extra, namelen, R_MASTER, &r); + if (error) { + put_lkb(lkb); + goto fail; + } + + lock_rsb(r); + + attach_lkb(r, lkb); + error = do_request(r, lkb); + send_request_reply(r, lkb, error); + + unlock_rsb(r); + put_rsb(r); + + if (error == -EINPROGRESS) + error = 0; + if (error) + put_lkb(lkb); + return; + + fail: + setup_stub_lkb(ls, ms); + send_request_reply(&ls->ls_stub_rsb, &ls->ls_stub_lkb, error); +} + +static void receive_convert(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + struct dlm_rsb *r; + int error, reply = TRUE; + + error = find_lkb(ls, ms->m_remid, &lkb); + if (error) + goto fail; + + r = lkb->lkb_resource; + + hold_rsb(r); + lock_rsb(r); + + receive_flags(lkb, ms); + error = receive_convert_args(ls, lkb, ms); + if (error) + goto out; + reply = !down_conversion(lkb); + + error = do_convert(r, lkb); + out: + if (reply) + send_convert_reply(r, lkb, error); + + unlock_rsb(r); + put_rsb(r); + put_lkb(lkb); + return; + + fail: + setup_stub_lkb(ls, ms); + send_convert_reply(&ls->ls_stub_rsb, &ls->ls_stub_lkb, error); +} + +static void receive_unlock(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + struct dlm_rsb *r; + int error; + + error = find_lkb(ls, ms->m_remid, &lkb); + if (error) + goto fail; + + r = lkb->lkb_resource; + + hold_rsb(r); + lock_rsb(r); + + receive_flags(lkb, ms); + error = receive_unlock_args(ls, lkb, ms); + if (error) + goto out; + + error = do_unlock(r, lkb); + out: + send_unlock_reply(r, lkb, error); + + unlock_rsb(r); + put_rsb(r); + put_lkb(lkb); + return; + + fail: + setup_stub_lkb(ls, ms); + send_unlock_reply(&ls->ls_stub_rsb, &ls->ls_stub_lkb, error); +} + +static void receive_cancel(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + struct dlm_rsb *r; + int error; + + error = find_lkb(ls, ms->m_remid, &lkb); + if (error) + goto fail; + + receive_flags(lkb, ms); + + r = lkb->lkb_resource; + + hold_rsb(r); + lock_rsb(r); + + error = do_cancel(r, lkb); + send_cancel_reply(r, lkb, error); + + unlock_rsb(r); + put_rsb(r); + put_lkb(lkb); + return; + + fail: + setup_stub_lkb(ls, ms); + send_cancel_reply(&ls->ls_stub_rsb, &ls->ls_stub_lkb, error); +} + +static void receive_grant(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + struct dlm_rsb *r; + int error; + + error = find_lkb(ls, ms->m_remid, &lkb); + if (error) { + log_error(ls, "receive_grant no lkb"); + return; + } + DLM_ASSERT(is_process_copy(lkb), dlm_print_lkb(lkb);); + + r = lkb->lkb_resource; + + hold_rsb(r); + lock_rsb(r); + + receive_flags_reply(lkb, ms); + grant_lock_pc(r, lkb, ms); + queue_cast(r, lkb, 0); + + unlock_rsb(r); + put_rsb(r); + put_lkb(lkb); +} + +static void receive_bast(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + struct dlm_rsb *r; + int error; + + error = find_lkb(ls, ms->m_remid, &lkb); + if (error) { + log_error(ls, "receive_bast no lkb"); + return; + } + DLM_ASSERT(is_process_copy(lkb), dlm_print_lkb(lkb);); + + r = lkb->lkb_resource; + + hold_rsb(r); + lock_rsb(r); + + queue_bast(r, lkb, ms->m_bastmode); + + unlock_rsb(r); + put_rsb(r); + put_lkb(lkb); +} + +static void receive_lookup(struct dlm_ls *ls, struct dlm_message *ms) +{ + int len, error, ret_nodeid, dir_nodeid, from_nodeid, our_nodeid; + + from_nodeid = ms->m_header.h_nodeid; + our_nodeid = dlm_our_nodeid(); + + len = receive_extralen(ms); + + dir_nodeid = dlm_hash2nodeid(ls, ms->m_hash); + if (dir_nodeid != our_nodeid) { + log_error(ls, "lookup dir_nodeid %d from %d", + dir_nodeid, from_nodeid); + error = -EINVAL; + ret_nodeid = -1; + goto out; + } + + error = dlm_dir_lookup(ls, from_nodeid, ms->m_extra, len, &ret_nodeid); + + /* Optimization: we're master so treat lookup as a request */ + if (!error && ret_nodeid == our_nodeid) { + receive_request(ls, ms); + return; + } + out: + send_lookup_reply(ls, ms, ret_nodeid, error); +} + +static void receive_remove(struct dlm_ls *ls, struct dlm_message *ms) +{ + int len, dir_nodeid, from_nodeid; + + from_nodeid = ms->m_header.h_nodeid; + + len = receive_extralen(ms); + + dir_nodeid = dlm_hash2nodeid(ls, ms->m_hash); + if (dir_nodeid != dlm_our_nodeid()) { + log_error(ls, "remove dir entry dir_nodeid %d from %d", + dir_nodeid, from_nodeid); + return; + } + + dlm_dir_remove_entry(ls, from_nodeid, ms->m_extra, len); +} + +static void receive_request_reply(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + struct dlm_rsb *r; + int error, mstype; + + error = find_lkb(ls, ms->m_remid, &lkb); + if (error) { + log_error(ls, "receive_request_reply no lkb"); + return; + } + DLM_ASSERT(is_process_copy(lkb), dlm_print_lkb(lkb);); + + mstype = lkb->lkb_wait_type; + error = remove_from_waiters(lkb); + if (error) { + log_error(ls, "receive_request_reply not on waiters"); + goto out; + } + + /* this is the value returned from do_request() on the master */ + error = ms->m_result; + + r = lkb->lkb_resource; + hold_rsb(r); + lock_rsb(r); + + /* Optimization: the dir node was also the master, so it took our + lookup as a request and sent request reply instead of lookup reply */ + if (mstype == DLM_MSG_LOOKUP) { + r->res_nodeid = ms->m_header.h_nodeid; + lkb->lkb_nodeid = r->res_nodeid; + } + + switch (error) { + case -EAGAIN: + /* request would block (be queued) on remote master; + the unhold undoes the original ref from create_lkb() + so it leads to the lkb being freed */ + queue_cast(r, lkb, -EAGAIN); + confirm_master(r, -EAGAIN); + unhold_lkb(lkb); + break; + + case -EINPROGRESS: + case 0: + /* request was queued or granted on remote master */ + receive_flags_reply(lkb, ms); + lkb->lkb_remid = ms->m_lkid; + if (error) + add_lkb(r, lkb, DLM_LKSTS_WAITING); + else { + grant_lock_pc(r, lkb, ms); + queue_cast(r, lkb, 0); + } + confirm_master(r, error); + break; + + case -ENOENT: + case -ENOTBLK: + /* find_rsb failed to find rsb or rsb wasn't master */ + r->res_nodeid = -1; + lkb->lkb_nodeid = -1; + _request_lock(r, lkb); + break; + + default: + log_error(ls, "receive_request_reply error %d", error); + } + + unlock_rsb(r); + put_rsb(r); + out: + put_lkb(lkb); +} + +static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, + struct dlm_message *ms) +{ + int error = ms->m_result; + + /* this is the value returned from do_convert() on the master */ + + switch (error) { + case -EAGAIN: + /* convert would block (be queued) on remote master */ + queue_cast(r, lkb, -EAGAIN); + break; + + case -EINPROGRESS: + /* convert was queued on remote master */ + del_lkb(r, lkb); + add_lkb(r, lkb, DLM_LKSTS_CONVERT); + break; + + case 0: + /* convert was granted on remote master */ + receive_flags_reply(lkb, ms); + grant_lock_pc(r, lkb, ms); + queue_cast(r, lkb, 0); + break; + + default: + log_error(r->res_ls, "receive_convert_reply error %d", error); + } +} + +static void _receive_convert_reply(struct dlm_lkb *lkb, struct dlm_message *ms) +{ + struct dlm_rsb *r = lkb->lkb_resource; + + hold_rsb(r); + lock_rsb(r); + + __receive_convert_reply(r, lkb, ms); + + unlock_rsb(r); + put_rsb(r); +} + +static void receive_convert_reply(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + int error; + + error = find_lkb(ls, ms->m_remid, &lkb); + if (error) { + log_error(ls, "receive_convert_reply no lkb"); + return; + } + DLM_ASSERT(is_process_copy(lkb), dlm_print_lkb(lkb);); + + error = remove_from_waiters(lkb); + if (error) { + log_error(ls, "receive_convert_reply not on waiters"); + goto out; + } + + _receive_convert_reply(lkb, ms); + out: + put_lkb(lkb); +} + +static void _receive_unlock_reply(struct dlm_lkb *lkb, struct dlm_message *ms) +{ + struct dlm_rsb *r = lkb->lkb_resource; + int error = ms->m_result; + + hold_rsb(r); + lock_rsb(r); + + /* this is the value returned from do_unlock() on the master */ + + switch (error) { + case -DLM_EUNLOCK: + receive_flags_reply(lkb, ms); + remove_lock_pc(r, lkb); + queue_cast(r, lkb, -DLM_EUNLOCK); + break; + default: + log_error(r->res_ls, "receive_unlock_reply error %d", error); + } + + unlock_rsb(r); + put_rsb(r); +} + +static void receive_unlock_reply(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + int error; + + error = find_lkb(ls, ms->m_remid, &lkb); + if (error) { + log_error(ls, "receive_unlock_reply no lkb"); + return; + } + DLM_ASSERT(is_process_copy(lkb), dlm_print_lkb(lkb);); + + error = remove_from_waiters(lkb); + if (error) { + log_error(ls, "receive_unlock_reply not on waiters"); + goto out; + } + + _receive_unlock_reply(lkb, ms); + out: + put_lkb(lkb); +} + +static void _receive_cancel_reply(struct dlm_lkb *lkb, struct dlm_message *ms) +{ + struct dlm_rsb *r = lkb->lkb_resource; + int error = ms->m_result; + + hold_rsb(r); + lock_rsb(r); + + /* this is the value returned from do_cancel() on the master */ + + switch (error) { + case -DLM_ECANCEL: + receive_flags_reply(lkb, ms); + revert_lock_pc(r, lkb); + queue_cast(r, lkb, -DLM_ECANCEL); + break; + default: + log_error(r->res_ls, "receive_cancel_reply error %d", error); + } + + unlock_rsb(r); + put_rsb(r); +} + +static void receive_cancel_reply(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + int error; + + error = find_lkb(ls, ms->m_remid, &lkb); + if (error) { + log_error(ls, "receive_cancel_reply no lkb"); + return; + } + DLM_ASSERT(is_process_copy(lkb), dlm_print_lkb(lkb);); + + error = remove_from_waiters(lkb); + if (error) { + log_error(ls, "receive_cancel_reply not on waiters"); + goto out; + } + + _receive_cancel_reply(lkb, ms); + out: + put_lkb(lkb); +} + +static void receive_lookup_reply(struct dlm_ls *ls, struct dlm_message *ms) +{ + struct dlm_lkb *lkb; + struct dlm_rsb *r; + int error, ret_nodeid; + + error = find_lkb(ls, ms->m_lkid, &lkb); + if (error) { + log_error(ls, "receive_lookup_reply no lkb"); + return; + } + + error = remove_from_waiters(lkb); + if (error) { + log_error(ls, "receive_lookup_reply not on waiters"); + goto out; + } + + /* this is the value returned by dlm_dir_lookup on dir node + FIXME: will a non-zero error ever be returned? */ + error = ms->m_result; + + r = lkb->lkb_resource; + hold_rsb(r); + lock_rsb(r); + + ret_nodeid = ms->m_nodeid; + if (ret_nodeid == dlm_our_nodeid()) { + r->res_nodeid = 0; + ret_nodeid = 0; + r->res_first_lkid = 0; + } else { + /* set_master() will copy res_nodeid to lkb_nodeid */ + r->res_nodeid = ret_nodeid; + } + + _request_lock(r, lkb); + + if (!ret_nodeid) + process_lookup_list(r); + + unlock_rsb(r); + put_rsb(r); + out: + put_lkb(lkb); +} + +int dlm_receive_message(struct dlm_header *hd, int nodeid, int recovery) +{ + struct dlm_message *ms = (struct dlm_message *) hd; + struct dlm_ls *ls; + int error; + + if (!recovery) + dlm_message_in(ms); + + ls = dlm_find_lockspace_global(hd->h_lockspace); + if (!ls) { + log_print("drop message %d from %d for unknown lockspace %d", + ms->m_type, nodeid, hd->h_lockspace); + return -EINVAL; + } + + /* recovery may have just ended leaving a bunch of backed-up requests + in the requestqueue; wait while dlm_recoverd clears them */ + + if (!recovery) + dlm_wait_requestqueue(ls); + + /* recovery may have just started while there were a bunch of + in-flight requests -- save them in requestqueue to be processed + after recovery. we can't let dlm_recvd block on the recovery + lock. if dlm_recoverd is calling this function to clear the + requestqueue, it needs to be interrupted (-EINTR) if another + recovery operation is starting. */ + + while (1) { + if (dlm_locking_stopped(ls)) { + if (!recovery) + dlm_add_requestqueue(ls, nodeid, hd); + error = -EINTR; + goto out; + } + + if (lock_recovery_try(ls)) + break; + schedule(); + } + + switch (ms->m_type) { + + /* messages sent to a master node */ + + case DLM_MSG_REQUEST: + receive_request(ls, ms); + break; + + case DLM_MSG_CONVERT: + receive_convert(ls, ms); + break; + + case DLM_MSG_UNLOCK: + receive_unlock(ls, ms); + break; + + case DLM_MSG_CANCEL: + receive_cancel(ls, ms); + break; + + /* messages sent from a master node (replies to above) */ + + case DLM_MSG_REQUEST_REPLY: + receive_request_reply(ls, ms); + break; + + case DLM_MSG_CONVERT_REPLY: + receive_convert_reply(ls, ms); + break; + + case DLM_MSG_UNLOCK_REPLY: + receive_unlock_reply(ls, ms); + break; + + case DLM_MSG_CANCEL_REPLY: + receive_cancel_reply(ls, ms); + break; + + /* messages sent from a master node (only two types of async msg) */ + + case DLM_MSG_GRANT: + receive_grant(ls, ms); + break; + + case DLM_MSG_BAST: + receive_bast(ls, ms); + break; + + /* messages sent to a dir node */ + + case DLM_MSG_LOOKUP: + receive_lookup(ls, ms); + break; + + case DLM_MSG_REMOVE: + receive_remove(ls, ms); + break; + + /* messages sent from a dir node (remove has no reply) */ + + case DLM_MSG_LOOKUP_REPLY: + receive_lookup_reply(ls, ms); + break; + + default: + log_error(ls, "unknown message type %d", ms->m_type); + } + + unlock_recovery(ls); + out: + dlm_put_lockspace(ls); + dlm_astd_wake(); + return 0; +} + + +/* + * Recovery related + */ + +static void recover_convert_waiter(struct dlm_ls *ls, struct dlm_lkb *lkb) +{ + if (middle_conversion(lkb)) { + hold_lkb(lkb); + ls->ls_stub_ms.m_result = -EINPROGRESS; + _remove_from_waiters(lkb); + _receive_convert_reply(lkb, &ls->ls_stub_ms); + + /* Same special case as in receive_rcom_lock_args() */ + lkb->lkb_grmode = DLM_LOCK_IV; + rsb_set_flag(lkb->lkb_resource, RSB_RECOVER_CONVERT); + unhold_lkb(lkb); + + } else if (lkb->lkb_rqmode >= lkb->lkb_grmode) { + lkb->lkb_flags |= DLM_IFL_RESEND; + } + + /* lkb->lkb_rqmode < lkb->lkb_grmode shouldn't happen since down + conversions are async; there's no reply from the remote master */ +} + +/* A waiting lkb needs recovery if the master node has failed, or + the master node is changing (only when no directory is used) */ + +static int waiter_needs_recovery(struct dlm_ls *ls, struct dlm_lkb *lkb) +{ + if (dlm_is_removed(ls, lkb->lkb_nodeid)) + return 1; + + if (!dlm_no_directory(ls)) + return 0; + + if (dlm_dir_nodeid(lkb->lkb_resource) != lkb->lkb_nodeid) + return 1; + + return 0; +} + +/* Recovery for locks that are waiting for replies from nodes that are now + gone. We can just complete unlocks and cancels by faking a reply from the + dead node. Requests and up-conversions we flag to be resent after + recovery. Down-conversions can just be completed with a fake reply like + unlocks. Conversions between PR and CW need special attention. */ + +void dlm_recover_waiters_pre(struct dlm_ls *ls) +{ + struct dlm_lkb *lkb, *safe; + + down(&ls->ls_waiters_sem); + + list_for_each_entry_safe(lkb, safe, &ls->ls_waiters, lkb_wait_reply) { + log_debug(ls, "pre recover waiter lkid %x type %d flags %x", + lkb->lkb_id, lkb->lkb_wait_type, lkb->lkb_flags); + + /* all outstanding lookups, regardless of destination will be + resent after recovery is done */ + + if (lkb->lkb_wait_type == DLM_MSG_LOOKUP) { + lkb->lkb_flags |= DLM_IFL_RESEND; + continue; + } + + if (!waiter_needs_recovery(ls, lkb)) + continue; + + switch (lkb->lkb_wait_type) { + + case DLM_MSG_REQUEST: + lkb->lkb_flags |= DLM_IFL_RESEND; + break; + + case DLM_MSG_CONVERT: + recover_convert_waiter(ls, lkb); + break; + + case DLM_MSG_UNLOCK: + hold_lkb(lkb); + ls->ls_stub_ms.m_result = -DLM_EUNLOCK; + _remove_from_waiters(lkb); + _receive_unlock_reply(lkb, &ls->ls_stub_ms); + put_lkb(lkb); + break; + + case DLM_MSG_CANCEL: + hold_lkb(lkb); + ls->ls_stub_ms.m_result = -DLM_ECANCEL; + _remove_from_waiters(lkb); + _receive_cancel_reply(lkb, &ls->ls_stub_ms); + put_lkb(lkb); + break; + + default: + log_error(ls, "invalid lkb wait_type %d", + lkb->lkb_wait_type); + } + } + up(&ls->ls_waiters_sem); +} + +static int remove_resend_waiter(struct dlm_ls *ls, struct dlm_lkb **lkb_ret) +{ + struct dlm_lkb *lkb; + int rv = 0; + + down(&ls->ls_waiters_sem); + list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) { + if (lkb->lkb_flags & DLM_IFL_RESEND) { + rv = lkb->lkb_wait_type; + _remove_from_waiters(lkb); + lkb->lkb_flags &= ~DLM_IFL_RESEND; + break; + } + } + up(&ls->ls_waiters_sem); + + if (!rv) + lkb = NULL; + *lkb_ret = lkb; + return rv; +} + +/* Deal with lookups and lkb's marked RESEND from _pre. We may now be the + master or dir-node for r. Processing the lkb may result in it being placed + back on waiters. */ + +int dlm_recover_waiters_post(struct dlm_ls *ls) +{ + struct dlm_lkb *lkb; + struct dlm_rsb *r; + int error = 0, mstype; + + while (1) { + if (dlm_locking_stopped(ls)) { + log_debug(ls, "recover_waiters_post aborted"); + error = -EINTR; + break; + } + + mstype = remove_resend_waiter(ls, &lkb); + if (!mstype) + break; + + r = lkb->lkb_resource; + + log_debug(ls, "recover_waiters_post %x type %d flags %x %s", + lkb->lkb_id, mstype, lkb->lkb_flags, r->res_name); + + switch (mstype) { + + case DLM_MSG_LOOKUP: + hold_rsb(r); + lock_rsb(r); + _request_lock(r, lkb); + if (is_master(r)) + confirm_master(r, 0); + unlock_rsb(r); + put_rsb(r); + break; + + case DLM_MSG_REQUEST: + hold_rsb(r); + lock_rsb(r); + _request_lock(r, lkb); + unlock_rsb(r); + put_rsb(r); + break; + + case DLM_MSG_CONVERT: + hold_rsb(r); + lock_rsb(r); + _convert_lock(r, lkb); + unlock_rsb(r); + put_rsb(r); + break; + + default: + log_error(ls, "recover_waiters_post type %d", mstype); + } + } + + return error; +} + +static void purge_queue(struct dlm_rsb *r, struct list_head *queue, + int (*test)(struct dlm_ls *ls, struct dlm_lkb *lkb)) +{ + struct dlm_ls *ls = r->res_ls; + struct dlm_lkb *lkb, *safe; + + list_for_each_entry_safe(lkb, safe, queue, lkb_statequeue) { + if (test(ls, lkb)) { + del_lkb(r, lkb); + /* this put should free the lkb */ + if (!put_lkb(lkb)) + log_error(ls, "purged lkb not released"); + } + } +} + +static int purge_dead_test(struct dlm_ls *ls, struct dlm_lkb *lkb) +{ + return (is_master_copy(lkb) && dlm_is_removed(ls, lkb->lkb_nodeid)); +} + +static int purge_mstcpy_test(struct dlm_ls *ls, struct dlm_lkb *lkb) +{ + return is_master_copy(lkb); +} + +static void purge_dead_locks(struct dlm_rsb *r) +{ + purge_queue(r, &r->res_grantqueue, &purge_dead_test); + purge_queue(r, &r->res_convertqueue, &purge_dead_test); + purge_queue(r, &r->res_waitqueue, &purge_dead_test); +} + +void dlm_purge_mstcpy_locks(struct dlm_rsb *r) +{ + purge_queue(r, &r->res_grantqueue, &purge_mstcpy_test); + purge_queue(r, &r->res_convertqueue, &purge_mstcpy_test); + purge_queue(r, &r->res_waitqueue, &purge_mstcpy_test); +} + +/* Get rid of locks held by nodes that are gone. */ + +int dlm_purge_locks(struct dlm_ls *ls) +{ + struct dlm_rsb *r; + + log_debug(ls, "dlm_purge_locks"); + + down_write(&ls->ls_root_sem); + list_for_each_entry(r, &ls->ls_root_list, res_root_list) { + hold_rsb(r); + lock_rsb(r); + if (is_master(r)) + purge_dead_locks(r); + unlock_rsb(r); + unhold_rsb(r); + + schedule(); + } + up_write(&ls->ls_root_sem); + + return 0; +} + +int dlm_grant_after_purge(struct dlm_ls *ls) +{ + struct dlm_rsb *r; + int i; + + for (i = 0; i < ls->ls_rsbtbl_size; i++) { + read_lock(&ls->ls_rsbtbl[i].lock); + list_for_each_entry(r, &ls->ls_rsbtbl[i].list, res_hashchain) { + hold_rsb(r); + lock_rsb(r); + if (is_master(r)) { + grant_pending_locks(r); + confirm_master(r, 0); + } + unlock_rsb(r); + put_rsb(r); + } + read_unlock(&ls->ls_rsbtbl[i].lock); + } + + return 0; +} + +static struct dlm_lkb *search_remid_list(struct list_head *head, int nodeid, + uint32_t remid) +{ + struct dlm_lkb *lkb; + + list_for_each_entry(lkb, head, lkb_statequeue) { + if (lkb->lkb_nodeid == nodeid && lkb->lkb_remid == remid) + return lkb; + } + return NULL; +} + +static struct dlm_lkb *search_remid(struct dlm_rsb *r, int nodeid, + uint32_t remid) +{ + struct dlm_lkb *lkb; + + lkb = search_remid_list(&r->res_grantqueue, nodeid, remid); + if (lkb) + return lkb; + lkb = search_remid_list(&r->res_convertqueue, nodeid, remid); + if (lkb) + return lkb; + lkb = search_remid_list(&r->res_waitqueue, nodeid, remid); + if (lkb) + return lkb; + return NULL; +} + +static int receive_rcom_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, + struct dlm_rsb *r, struct dlm_rcom *rc) +{ + struct rcom_lock *rl = (struct rcom_lock *) rc->rc_buf; + int lvblen; + + lkb->lkb_nodeid = rc->rc_header.h_nodeid; + lkb->lkb_ownpid = rl->rl_ownpid; + lkb->lkb_remid = rl->rl_lkid; + lkb->lkb_exflags = rl->rl_exflags; + lkb->lkb_flags = rl->rl_flags & 0x0000FFFF; + lkb->lkb_flags |= DLM_IFL_MSTCPY; + lkb->lkb_lvbseq = rl->rl_lvbseq; + lkb->lkb_rqmode = rl->rl_rqmode; + lkb->lkb_grmode = rl->rl_grmode; + /* don't set lkb_status because add_lkb wants to itself */ + + lkb->lkb_bastaddr = (void *) (long) (rl->rl_asts & AST_BAST); + lkb->lkb_astaddr = (void *) (long) (rl->rl_asts & AST_COMP); + + if (lkb->lkb_flags & DLM_IFL_RANGE) { + lkb->lkb_range = allocate_range(ls); + if (!lkb->lkb_range) + return -ENOMEM; + memcpy(lkb->lkb_range, rl->rl_range, 4*sizeof(uint64_t)); + } + + if (lkb->lkb_exflags & DLM_LKF_VALBLK) { + lkb->lkb_lvbptr = allocate_lvb(ls); + if (!lkb->lkb_lvbptr) + return -ENOMEM; + lvblen = rc->rc_header.h_length - sizeof(struct dlm_rcom) - + sizeof(struct rcom_lock); + memcpy(lkb->lkb_lvbptr, rl->rl_lvb, lvblen); + } + + /* Conversions between PR and CW (middle modes) need special handling. + The real granted mode of these converting locks cannot be determined + until all locks have been rebuilt on the rsb (recover_conversion) */ + + if (rl->rl_wait_type == DLM_MSG_CONVERT && middle_conversion(lkb)) { + rl->rl_status = DLM_LKSTS_CONVERT; + lkb->lkb_grmode = DLM_LOCK_IV; + rsb_set_flag(r, RSB_RECOVER_CONVERT); + } + + return 0; +} + +/* This lkb may have been recovered in a previous aborted recovery so we need + to check if the rsb already has an lkb with the given remote nodeid/lkid. + If so we just send back a standard reply. If not, we create a new lkb with + the given values and send back our lkid. We send back our lkid by sending + back the rcom_lock struct we got but with the remid field filled in. */ + +int dlm_recover_master_copy(struct dlm_ls *ls, struct dlm_rcom *rc) +{ + struct rcom_lock *rl = (struct rcom_lock *) rc->rc_buf; + struct dlm_rsb *r; + struct dlm_lkb *lkb; + int error; + + if (rl->rl_parent_lkid) { + error = -EOPNOTSUPP; + goto out; + } + + error = find_rsb(ls, rl->rl_name, rl->rl_namelen, R_MASTER, &r); + if (error) + goto out; + + lock_rsb(r); + + lkb = search_remid(r, rc->rc_header.h_nodeid, rl->rl_lkid); + if (lkb) { + error = -EEXIST; + goto out_remid; + } + + error = create_lkb(ls, &lkb); + if (error) + goto out_unlock; + + error = receive_rcom_lock_args(ls, lkb, r, rc); + if (error) { + put_lkb(lkb); + goto out_unlock; + } + + attach_lkb(r, lkb); + add_lkb(r, lkb, rl->rl_status); + error = 0; + + out_remid: + /* this is the new value returned to the lock holder for + saving in its process-copy lkb */ + rl->rl_remid = lkb->lkb_id; + + out_unlock: + unlock_rsb(r); + put_rsb(r); + out: + if (error) + log_print("recover_master_copy %d %x", error, rl->rl_lkid); + rl->rl_result = error; + return error; +} + +int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc) +{ + struct rcom_lock *rl = (struct rcom_lock *) rc->rc_buf; + struct dlm_rsb *r; + struct dlm_lkb *lkb; + int error; + + error = find_lkb(ls, rl->rl_lkid, &lkb); + if (error) { + log_error(ls, "recover_process_copy no lkid %x", rl->rl_lkid); + return error; + } + + DLM_ASSERT(is_process_copy(lkb), dlm_print_lkb(lkb);); + + error = rl->rl_result; + + r = lkb->lkb_resource; + hold_rsb(r); + lock_rsb(r); + + switch (error) { + case -EEXIST: + log_debug(ls, "master copy exists %x", lkb->lkb_id); + /* fall through */ + case 0: + lkb->lkb_remid = rl->rl_remid; + break; + default: + log_error(ls, "dlm_recover_process_copy unknown error %d %x", + error, lkb->lkb_id); + } + + /* an ack for dlm_recover_locks() which waits for replies from + all the locks it sends to new masters */ + dlm_recovered_lock(r); + + unlock_rsb(r); + put_rsb(r); + put_lkb(lkb); + + return 0; +} + diff --git a/fs/dlm/lock.h b/fs/dlm/lock.h new file mode 100644 index 000000000000..9e6499f773da --- /dev/null +++ b/fs/dlm/lock.h @@ -0,0 +1,50 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __LOCK_DOT_H__ +#define __LOCK_DOT_H__ + +void dlm_print_rsb(struct dlm_rsb *r); +int dlm_receive_message(struct dlm_header *hd, int nodeid, int recovery); +int dlm_modes_compat(int mode1, int mode2); +int dlm_find_rsb(struct dlm_ls *ls, char *name, int namelen, + unsigned int flags, struct dlm_rsb **r_ret); +void dlm_put_rsb(struct dlm_rsb *r); +void dlm_hold_rsb(struct dlm_rsb *r); +int dlm_put_lkb(struct dlm_lkb *lkb); +void dlm_scan_rsbs(struct dlm_ls *ls); + +int dlm_purge_locks(struct dlm_ls *ls); +void dlm_purge_mstcpy_locks(struct dlm_rsb *r); +int dlm_grant_after_purge(struct dlm_ls *ls); +int dlm_recover_waiters_post(struct dlm_ls *ls); +void dlm_recover_waiters_pre(struct dlm_ls *ls); +int dlm_recover_master_copy(struct dlm_ls *ls, struct dlm_rcom *rc); +int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc); + +static inline int is_master(struct dlm_rsb *r) +{ + return !r->res_nodeid; +} + +static inline void lock_rsb(struct dlm_rsb *r) +{ + down(&r->res_sem); +} + +static inline void unlock_rsb(struct dlm_rsb *r) +{ + up(&r->res_sem); +} + +#endif + diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c new file mode 100644 index 000000000000..fee4659b6582 --- /dev/null +++ b/fs/dlm/lockspace.c @@ -0,0 +1,666 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "lockspace.h" +#include "member.h" +#include "recoverd.h" +#include "ast.h" +#include "dir.h" +#include "lowcomms.h" +#include "config.h" +#include "memory.h" +#include "lock.h" + +#ifdef CONFIG_DLM_DEBUG +int dlm_create_debug_file(struct dlm_ls *ls); +void dlm_delete_debug_file(struct dlm_ls *ls); +#else +static inline int dlm_create_debug_file(struct dlm_ls *ls) { return 0; } +static inline void dlm_delete_debug_file(struct dlm_ls *ls) { } +#endif + +static int ls_count; +static struct semaphore ls_lock; +static struct list_head lslist; +static spinlock_t lslist_lock; +static struct task_struct * scand_task; + + +static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_t len) +{ + ssize_t ret = len; + int n = simple_strtol(buf, NULL, 0); + + switch (n) { + case 0: + dlm_ls_stop(ls); + break; + case 1: + dlm_ls_start(ls); + break; + default: + ret = -EINVAL; + } + return ret; +} + +static ssize_t dlm_event_store(struct dlm_ls *ls, const char *buf, size_t len) +{ + ls->ls_uevent_result = simple_strtol(buf, NULL, 0); + set_bit(LSFL_UEVENT_WAIT, &ls->ls_flags); + wake_up(&ls->ls_uevent_wait); + return len; +} + +static ssize_t dlm_id_show(struct dlm_ls *ls, char *buf) +{ + return sprintf(buf, "%u\n", ls->ls_global_id); +} + +static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len) +{ + ls->ls_global_id = simple_strtoul(buf, NULL, 0); + return len; +} + +struct dlm_attr { + struct attribute attr; + ssize_t (*show)(struct dlm_ls *, char *); + ssize_t (*store)(struct dlm_ls *, const char *, size_t); +}; + +static struct dlm_attr dlm_attr_control = { + .attr = {.name = "control", .mode = S_IWUSR}, + .store = dlm_control_store +}; + +static struct dlm_attr dlm_attr_event = { + .attr = {.name = "event_done", .mode = S_IWUSR}, + .store = dlm_event_store +}; + +static struct dlm_attr dlm_attr_id = { + .attr = {.name = "id", .mode = S_IRUGO | S_IWUSR}, + .show = dlm_id_show, + .store = dlm_id_store +}; + +static struct attribute *dlm_attrs[] = { + &dlm_attr_control.attr, + &dlm_attr_event.attr, + &dlm_attr_id.attr, + NULL, +}; + +static ssize_t dlm_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj); + struct dlm_attr *a = container_of(attr, struct dlm_attr, attr); + return a->show ? a->show(ls, buf) : 0; +} + +static ssize_t dlm_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t len) +{ + struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj); + struct dlm_attr *a = container_of(attr, struct dlm_attr, attr); + return a->store ? a->store(ls, buf, len) : len; +} + +static struct sysfs_ops dlm_attr_ops = { + .show = dlm_attr_show, + .store = dlm_attr_store, +}; + +static struct kobj_type dlm_ktype = { + .default_attrs = dlm_attrs, + .sysfs_ops = &dlm_attr_ops, +}; + +static struct kset dlm_kset = { + .subsys = &kernel_subsys, + .kobj = {.name = "dlm",}, + .ktype = &dlm_ktype, +}; + +static int kobject_setup(struct dlm_ls *ls) +{ + char lsname[DLM_LOCKSPACE_LEN]; + int error; + + memset(lsname, 0, DLM_LOCKSPACE_LEN); + snprintf(lsname, DLM_LOCKSPACE_LEN, "%s", ls->ls_name); + + error = kobject_set_name(&ls->ls_kobj, "%s", lsname); + if (error) + return error; + + ls->ls_kobj.kset = &dlm_kset; + ls->ls_kobj.ktype = &dlm_ktype; + return 0; +} + +static int do_uevent(struct dlm_ls *ls, int in) +{ + int error; + + if (in) + kobject_uevent(&ls->ls_kobj, KOBJ_ONLINE); + else + kobject_uevent(&ls->ls_kobj, KOBJ_OFFLINE); + + error = wait_event_interruptible(ls->ls_uevent_wait, + test_and_clear_bit(LSFL_UEVENT_WAIT, &ls->ls_flags)); + if (error) + goto out; + + error = ls->ls_uevent_result; + out: + return error; +} + + +int dlm_lockspace_init(void) +{ + int error; + + ls_count = 0; + init_MUTEX(&ls_lock); + INIT_LIST_HEAD(&lslist); + spin_lock_init(&lslist_lock); + + error = kset_register(&dlm_kset); + if (error) + printk("dlm_lockspace_init: cannot register kset %d\n", error); + return error; +} + +void dlm_lockspace_exit(void) +{ + kset_unregister(&dlm_kset); +} + +static int dlm_scand(void *data) +{ + struct dlm_ls *ls; + + while (!kthread_should_stop()) { + list_for_each_entry(ls, &lslist, ls_list) + dlm_scan_rsbs(ls); + schedule_timeout_interruptible(dlm_config.scan_secs * HZ); + } + return 0; +} + +static int dlm_scand_start(void) +{ + struct task_struct *p; + int error = 0; + + p = kthread_run(dlm_scand, NULL, "dlm_scand"); + if (IS_ERR(p)) + error = PTR_ERR(p); + else + scand_task = p; + return error; +} + +static void dlm_scand_stop(void) +{ + kthread_stop(scand_task); +} + +static struct dlm_ls *dlm_find_lockspace_name(char *name, int namelen) +{ + struct dlm_ls *ls; + + spin_lock(&lslist_lock); + + list_for_each_entry(ls, &lslist, ls_list) { + if (ls->ls_namelen == namelen && + memcmp(ls->ls_name, name, namelen) == 0) + goto out; + } + ls = NULL; + out: + spin_unlock(&lslist_lock); + return ls; +} + +struct dlm_ls *dlm_find_lockspace_global(uint32_t id) +{ + struct dlm_ls *ls; + + spin_lock(&lslist_lock); + + list_for_each_entry(ls, &lslist, ls_list) { + if (ls->ls_global_id == id) { + ls->ls_count++; + goto out; + } + } + ls = NULL; + out: + spin_unlock(&lslist_lock); + return ls; +} + +struct dlm_ls *dlm_find_lockspace_local(void *id) +{ + struct dlm_ls *ls = id; + + spin_lock(&lslist_lock); + ls->ls_count++; + spin_unlock(&lslist_lock); + return ls; +} + +void dlm_put_lockspace(struct dlm_ls *ls) +{ + spin_lock(&lslist_lock); + ls->ls_count--; + spin_unlock(&lslist_lock); +} + +static void remove_lockspace(struct dlm_ls *ls) +{ + for (;;) { + spin_lock(&lslist_lock); + if (ls->ls_count == 0) { + list_del(&ls->ls_list); + spin_unlock(&lslist_lock); + return; + } + spin_unlock(&lslist_lock); + ssleep(1); + } +} + +static int threads_start(void) +{ + int error; + + /* Thread which process lock requests for all lockspace's */ + error = dlm_astd_start(); + if (error) { + log_print("cannot start dlm_astd thread %d", error); + goto fail; + } + + error = dlm_scand_start(); + if (error) { + log_print("cannot start dlm_scand thread %d", error); + goto astd_fail; + } + + /* Thread for sending/receiving messages for all lockspace's */ + error = dlm_lowcomms_start(); + if (error) { + log_print("cannot start dlm lowcomms %d", error); + goto scand_fail; + } + + return 0; + + scand_fail: + dlm_scand_stop(); + astd_fail: + dlm_astd_stop(); + fail: + return error; +} + +static void threads_stop(void) +{ + dlm_scand_stop(); + dlm_lowcomms_stop(); + dlm_astd_stop(); +} + +static int new_lockspace(char *name, int namelen, void **lockspace, + uint32_t flags, int lvblen) +{ + struct dlm_ls *ls; + int i, size, error = -ENOMEM; + + if (namelen > DLM_LOCKSPACE_LEN) + return -EINVAL; + + if (!lvblen || (lvblen % 8)) + return -EINVAL; + + if (!try_module_get(THIS_MODULE)) + return -EINVAL; + + ls = dlm_find_lockspace_name(name, namelen); + if (ls) { + *lockspace = ls; + module_put(THIS_MODULE); + return -EEXIST; + } + + ls = kmalloc(sizeof(struct dlm_ls) + namelen, GFP_KERNEL); + if (!ls) + goto out; + memset(ls, 0, sizeof(struct dlm_ls) + namelen); + memcpy(ls->ls_name, name, namelen); + ls->ls_namelen = namelen; + ls->ls_exflags = flags; + ls->ls_lvblen = lvblen; + ls->ls_count = 0; + ls->ls_flags = 0; + + size = dlm_config.rsbtbl_size; + ls->ls_rsbtbl_size = size; + + ls->ls_rsbtbl = kmalloc(sizeof(struct dlm_rsbtable) * size, GFP_KERNEL); + if (!ls->ls_rsbtbl) + goto out_lsfree; + for (i = 0; i < size; i++) { + INIT_LIST_HEAD(&ls->ls_rsbtbl[i].list); + INIT_LIST_HEAD(&ls->ls_rsbtbl[i].toss); + rwlock_init(&ls->ls_rsbtbl[i].lock); + } + + size = dlm_config.lkbtbl_size; + ls->ls_lkbtbl_size = size; + + ls->ls_lkbtbl = kmalloc(sizeof(struct dlm_lkbtable) * size, GFP_KERNEL); + if (!ls->ls_lkbtbl) + goto out_rsbfree; + for (i = 0; i < size; i++) { + INIT_LIST_HEAD(&ls->ls_lkbtbl[i].list); + rwlock_init(&ls->ls_lkbtbl[i].lock); + ls->ls_lkbtbl[i].counter = 1; + } + + size = dlm_config.dirtbl_size; + ls->ls_dirtbl_size = size; + + ls->ls_dirtbl = kmalloc(sizeof(struct dlm_dirtable) * size, GFP_KERNEL); + if (!ls->ls_dirtbl) + goto out_lkbfree; + for (i = 0; i < size; i++) { + INIT_LIST_HEAD(&ls->ls_dirtbl[i].list); + rwlock_init(&ls->ls_dirtbl[i].lock); + } + + INIT_LIST_HEAD(&ls->ls_waiters); + init_MUTEX(&ls->ls_waiters_sem); + + INIT_LIST_HEAD(&ls->ls_nodes); + INIT_LIST_HEAD(&ls->ls_nodes_gone); + ls->ls_num_nodes = 0; + ls->ls_low_nodeid = 0; + ls->ls_total_weight = 0; + ls->ls_node_array = NULL; + + memset(&ls->ls_stub_rsb, 0, sizeof(struct dlm_rsb)); + ls->ls_stub_rsb.res_ls = ls; + + ls->ls_debug_dentry = NULL; + + init_waitqueue_head(&ls->ls_uevent_wait); + ls->ls_uevent_result = 0; + + ls->ls_recoverd_task = NULL; + init_MUTEX(&ls->ls_recoverd_active); + spin_lock_init(&ls->ls_recover_lock); + ls->ls_recover_status = 0; + ls->ls_recover_seq = 0; + ls->ls_recover_args = NULL; + init_rwsem(&ls->ls_in_recovery); + INIT_LIST_HEAD(&ls->ls_requestqueue); + init_MUTEX(&ls->ls_requestqueue_lock); + + ls->ls_recover_buf = kmalloc(dlm_config.buffer_size, GFP_KERNEL); + if (!ls->ls_recover_buf) + goto out_dirfree; + + INIT_LIST_HEAD(&ls->ls_recover_list); + spin_lock_init(&ls->ls_recover_list_lock); + ls->ls_recover_list_count = 0; + init_waitqueue_head(&ls->ls_wait_general); + INIT_LIST_HEAD(&ls->ls_root_list); + init_rwsem(&ls->ls_root_sem); + + down_write(&ls->ls_in_recovery); + + error = dlm_recoverd_start(ls); + if (error) { + log_error(ls, "can't start dlm_recoverd %d", error); + goto out_rcomfree; + } + + spin_lock(&lslist_lock); + list_add(&ls->ls_list, &lslist); + spin_unlock(&lslist_lock); + + dlm_create_debug_file(ls); + + error = kobject_setup(ls); + if (error) + goto out_del; + + error = kobject_register(&ls->ls_kobj); + if (error) + goto out_del; + + error = do_uevent(ls, 1); + if (error) + goto out_unreg; + + *lockspace = ls; + return 0; + + out_unreg: + kobject_unregister(&ls->ls_kobj); + out_del: + dlm_delete_debug_file(ls); + spin_lock(&lslist_lock); + list_del(&ls->ls_list); + spin_unlock(&lslist_lock); + dlm_recoverd_stop(ls); + out_rcomfree: + kfree(ls->ls_recover_buf); + out_dirfree: + kfree(ls->ls_dirtbl); + out_lkbfree: + kfree(ls->ls_lkbtbl); + out_rsbfree: + kfree(ls->ls_rsbtbl); + out_lsfree: + kfree(ls); + out: + module_put(THIS_MODULE); + return error; +} + +int dlm_new_lockspace(char *name, int namelen, void **lockspace, + uint32_t flags, int lvblen) +{ + int error = 0; + + down(&ls_lock); + if (!ls_count) + error = threads_start(); + if (error) + goto out; + + error = new_lockspace(name, namelen, lockspace, flags, lvblen); + if (!error) + ls_count++; + out: + up(&ls_lock); + return error; +} + +/* Return 1 if the lockspace still has active remote locks, + * 2 if the lockspace still has active local locks. + */ +static int lockspace_busy(struct dlm_ls *ls) +{ + int i, lkb_found = 0; + struct dlm_lkb *lkb; + + /* NOTE: We check the lockidtbl here rather than the resource table. + This is because there may be LKBs queued as ASTs that have been + unlinked from their RSBs and are pending deletion once the AST has + been delivered */ + + for (i = 0; i < ls->ls_lkbtbl_size; i++) { + read_lock(&ls->ls_lkbtbl[i].lock); + if (!list_empty(&ls->ls_lkbtbl[i].list)) { + lkb_found = 1; + list_for_each_entry(lkb, &ls->ls_lkbtbl[i].list, + lkb_idtbl_list) { + if (!lkb->lkb_nodeid) { + read_unlock(&ls->ls_lkbtbl[i].lock); + return 2; + } + } + } + read_unlock(&ls->ls_lkbtbl[i].lock); + } + return lkb_found; +} + +static int release_lockspace(struct dlm_ls *ls, int force) +{ + struct dlm_lkb *lkb; + struct dlm_rsb *rsb; + struct list_head *head; + int i; + int busy = lockspace_busy(ls); + + if (busy > force) + return -EBUSY; + + if (force < 3) + do_uevent(ls, 0); + + dlm_recoverd_stop(ls); + + remove_lockspace(ls); + + dlm_delete_debug_file(ls); + + dlm_astd_suspend(); + + kfree(ls->ls_recover_buf); + + /* + * Free direntry structs. + */ + + dlm_dir_clear(ls); + kfree(ls->ls_dirtbl); + + /* + * Free all lkb's on lkbtbl[] lists. + */ + + for (i = 0; i < ls->ls_lkbtbl_size; i++) { + head = &ls->ls_lkbtbl[i].list; + while (!list_empty(head)) { + lkb = list_entry(head->next, struct dlm_lkb, + lkb_idtbl_list); + + list_del(&lkb->lkb_idtbl_list); + + dlm_del_ast(lkb); + + if (lkb->lkb_lvbptr && lkb->lkb_flags & DLM_IFL_MSTCPY) + free_lvb(lkb->lkb_lvbptr); + + free_lkb(lkb); + } + } + dlm_astd_resume(); + + kfree(ls->ls_lkbtbl); + + /* + * Free all rsb's on rsbtbl[] lists + */ + + for (i = 0; i < ls->ls_rsbtbl_size; i++) { + head = &ls->ls_rsbtbl[i].list; + while (!list_empty(head)) { + rsb = list_entry(head->next, struct dlm_rsb, + res_hashchain); + + list_del(&rsb->res_hashchain); + free_rsb(rsb); + } + + head = &ls->ls_rsbtbl[i].toss; + while (!list_empty(head)) { + rsb = list_entry(head->next, struct dlm_rsb, + res_hashchain); + list_del(&rsb->res_hashchain); + free_rsb(rsb); + } + } + + kfree(ls->ls_rsbtbl); + + /* + * Free structures on any other lists + */ + + kfree(ls->ls_recover_args); + dlm_clear_free_entries(ls); + dlm_clear_members(ls); + dlm_clear_members_gone(ls); + kfree(ls->ls_node_array); + kobject_unregister(&ls->ls_kobj); + kfree(ls); + + down(&ls_lock); + ls_count--; + if (!ls_count) + threads_stop(); + up(&ls_lock); + + module_put(THIS_MODULE); + return 0; +} + +/* + * Called when a system has released all its locks and is not going to use the + * lockspace any longer. We free everything we're managing for this lockspace. + * Remaining nodes will go through the recovery process as if we'd died. The + * lockspace must continue to function as usual, participating in recoveries, + * until this returns. + * + * Force has 4 possible values: + * 0 - don't destroy locksapce if it has any LKBs + * 1 - destroy lockspace if it has remote LKBs but not if it has local LKBs + * 2 - destroy lockspace regardless of LKBs + * 3 - destroy lockspace as part of a forced shutdown + */ + +int dlm_release_lockspace(void *lockspace, int force) +{ + struct dlm_ls *ls; + + ls = dlm_find_lockspace_local(lockspace); + if (!ls) + return -EINVAL; + dlm_put_lockspace(ls); + return release_lockspace(ls, force); +} + diff --git a/fs/dlm/lockspace.h b/fs/dlm/lockspace.h new file mode 100644 index 000000000000..17bd3ba863a9 --- /dev/null +++ b/fs/dlm/lockspace.h @@ -0,0 +1,24 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __LOCKSPACE_DOT_H__ +#define __LOCKSPACE_DOT_H__ + +int dlm_lockspace_init(void); +void dlm_lockspace_exit(void); +struct dlm_ls *dlm_find_lockspace_global(uint32_t id); +struct dlm_ls *dlm_find_lockspace_local(void *id); +void dlm_put_lockspace(struct dlm_ls *ls); + +#endif /* __LOCKSPACE_DOT_H__ */ + diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c new file mode 100644 index 000000000000..09b0124f7fc4 --- /dev/null +++ b/fs/dlm/lowcomms.c @@ -0,0 +1,1218 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +/* + * lowcomms.c + * + * This is the "low-level" comms layer. + * + * It is responsible for sending/receiving messages + * from other nodes in the cluster. + * + * Cluster nodes are referred to by their nodeids. nodeids are + * simply 32 bit numbers to the locking module - if they need to + * be expanded for the cluster infrastructure then that is it's + * responsibility. It is this layer's + * responsibility to resolve these into IP address or + * whatever it needs for inter-node communication. + * + * The comms level is two kernel threads that deal mainly with + * the receiving of messages from other nodes and passing them + * up to the mid-level comms layer (which understands the + * message format) for execution by the locking core, and + * a send thread which does all the setting up of connections + * to remote nodes and the sending of data. Threads are not allowed + * to send their own data because it may cause them to wait in times + * of high load. Also, this way, the sending thread can collect together + * messages bound for one node and send them in one block. + * + * I don't see any problem with the recv thread executing the locking + * code on behalf of remote processes as the locking code is + * short, efficient and never (well, hardly ever) waits. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "dlm_internal.h" +#include "lowcomms.h" +#include "config.h" +#include "midcomms.h" + +static struct sockaddr_storage *local_addr[DLM_MAX_ADDR_COUNT]; +static int local_count; +static int local_nodeid; + +/* One of these per connected node */ + +#define NI_INIT_PENDING 1 +#define NI_WRITE_PENDING 2 + +struct nodeinfo { + spinlock_t lock; + sctp_assoc_t assoc_id; + unsigned long flags; + struct list_head write_list; /* nodes with pending writes */ + struct list_head writequeue; /* outgoing writequeue_entries */ + spinlock_t writequeue_lock; + int nodeid; +}; + +static DEFINE_IDR(nodeinfo_idr); +static struct rw_semaphore nodeinfo_lock; +static int max_nodeid; + +struct cbuf { + unsigned base; + unsigned len; + unsigned mask; +}; + +/* Just the one of these, now. But this struct keeps + the connection-specific variables together */ + +#define CF_READ_PENDING 1 + +struct connection { + struct socket *sock; + unsigned long flags; + struct page *rx_page; + atomic_t waiting_requests; + struct cbuf cb; + int eagain_flag; +}; + +/* An entry waiting to be sent */ + +struct writequeue_entry { + struct list_head list; + struct page *page; + int offset; + int len; + int end; + int users; + struct nodeinfo *ni; +}; + +#define CBUF_ADD(cb, n) do { (cb)->len += n; } while(0) +#define CBUF_EMPTY(cb) ((cb)->len == 0) +#define CBUF_MAY_ADD(cb, n) (((cb)->len + (n)) < ((cb)->mask + 1)) +#define CBUF_DATA(cb) (((cb)->base + (cb)->len) & (cb)->mask) + +#define CBUF_INIT(cb, size) \ +do { \ + (cb)->base = (cb)->len = 0; \ + (cb)->mask = ((size)-1); \ +} while(0) + +#define CBUF_EAT(cb, n) \ +do { \ + (cb)->len -= (n); \ + (cb)->base += (n); \ + (cb)->base &= (cb)->mask; \ +} while(0) + + +/* List of nodes which have writes pending */ +static struct list_head write_nodes; +static spinlock_t write_nodes_lock; + +/* Maximum number of incoming messages to process before + * doing a schedule() + */ +#define MAX_RX_MSG_COUNT 25 + +/* Manage daemons */ +static struct task_struct *recv_task; +static struct task_struct *send_task; +static wait_queue_head_t lowcomms_recv_wait; +static atomic_t accepting; + +/* The SCTP connection */ +static struct connection sctp_con; + + +static int nodeid_to_addr(int nodeid, struct sockaddr *retaddr) +{ + struct sockaddr_storage addr; + int error; + + if (!local_count) + return -1; + + error = dlm_nodeid_to_addr(nodeid, &addr); + if (error) + return error; + + if (local_addr[0]->ss_family == AF_INET) { + struct sockaddr_in *in4 = (struct sockaddr_in *) &addr; + struct sockaddr_in *ret4 = (struct sockaddr_in *) retaddr; + ret4->sin_addr.s_addr = in4->sin_addr.s_addr; + } else { + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &addr; + struct sockaddr_in6 *ret6 = (struct sockaddr_in6 *) retaddr; + memcpy(&ret6->sin6_addr, &in6->sin6_addr, + sizeof(in6->sin6_addr)); + } + + return 0; +} + +static struct nodeinfo *nodeid2nodeinfo(int nodeid, int alloc) +{ + struct nodeinfo *ni; + int r; + int n; + + down_read(&nodeinfo_lock); + ni = idr_find(&nodeinfo_idr, nodeid); + up_read(&nodeinfo_lock); + + if (!ni && alloc) { + down_write(&nodeinfo_lock); + + ni = idr_find(&nodeinfo_idr, nodeid); + if (ni) + goto out_up; + + r = idr_pre_get(&nodeinfo_idr, alloc); + if (!r) + goto out_up; + + ni = kmalloc(sizeof(struct nodeinfo), alloc); + if (!ni) + goto out_up; + + r = idr_get_new_above(&nodeinfo_idr, ni, nodeid, &n); + if (r) { + kfree(ni); + ni = NULL; + goto out_up; + } + if (n != nodeid) { + idr_remove(&nodeinfo_idr, n); + kfree(ni); + ni = NULL; + goto out_up; + } + memset(ni, 0, sizeof(struct nodeinfo)); + spin_lock_init(&ni->lock); + INIT_LIST_HEAD(&ni->writequeue); + spin_lock_init(&ni->writequeue_lock); + ni->nodeid = nodeid; + + if (nodeid > max_nodeid) + max_nodeid = nodeid; + out_up: + up_write(&nodeinfo_lock); + } + + return ni; +} + +/* Don't call this too often... */ +static struct nodeinfo *assoc2nodeinfo(sctp_assoc_t assoc) +{ + int i; + struct nodeinfo *ni; + + for (i=1; i<=max_nodeid; i++) { + ni = nodeid2nodeinfo(i, 0); + if (ni && ni->assoc_id == assoc) + return ni; + } + return NULL; +} + +/* Data or notification available on socket */ +static void lowcomms_data_ready(struct sock *sk, int count_unused) +{ + atomic_inc(&sctp_con.waiting_requests); + if (test_and_set_bit(CF_READ_PENDING, &sctp_con.flags)) + return; + + wake_up_interruptible(&lowcomms_recv_wait); +} + + +/* Add the port number to an IP6 or 4 sockaddr and return the address length. + Also padd out the struct with zeros to make comparisons meaningful */ + +static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port, + int *addr_len) +{ + struct sockaddr_in *local4_addr; + struct sockaddr_in6 *local6_addr; + + if (!local_count) + return; + + if (!port) { + if (local_addr[0]->ss_family == AF_INET) { + local4_addr = (struct sockaddr_in *)local_addr[0]; + port = be16_to_cpu(local4_addr->sin_port); + } else { + local6_addr = (struct sockaddr_in6 *)local_addr[0]; + port = be16_to_cpu(local6_addr->sin6_port); + } + } + + saddr->ss_family = local_addr[0]->ss_family; + if (local_addr[0]->ss_family == AF_INET) { + struct sockaddr_in *in4_addr = (struct sockaddr_in *)saddr; + in4_addr->sin_port = cpu_to_be16(port); + memset(&in4_addr->sin_zero, 0, sizeof(in4_addr->sin_zero)); + memset(in4_addr+1, 0, sizeof(struct sockaddr_storage) - + sizeof(struct sockaddr_in)); + *addr_len = sizeof(struct sockaddr_in); + } else { + struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)saddr; + in6_addr->sin6_port = cpu_to_be16(port); + memset(in6_addr+1, 0, sizeof(struct sockaddr_storage) - + sizeof(struct sockaddr_in6)); + *addr_len = sizeof(struct sockaddr_in6); + } +} + +/* Close the connection and tidy up */ +static void close_connection(void) +{ + if (sctp_con.sock) { + sock_release(sctp_con.sock); + sctp_con.sock = NULL; + } + + if (sctp_con.rx_page) { + __free_page(sctp_con.rx_page); + sctp_con.rx_page = NULL; + } +} + +/* We only send shutdown messages to nodes that are not part of the cluster */ +static void send_shutdown(sctp_assoc_t associd) +{ + static char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; + struct msghdr outmessage; + struct cmsghdr *cmsg; + struct sctp_sndrcvinfo *sinfo; + int ret; + + outmessage.msg_name = NULL; + outmessage.msg_namelen = 0; + outmessage.msg_control = outcmsg; + outmessage.msg_controllen = sizeof(outcmsg); + outmessage.msg_flags = MSG_EOR; + + cmsg = CMSG_FIRSTHDR(&outmessage); + cmsg->cmsg_level = IPPROTO_SCTP; + cmsg->cmsg_type = SCTP_SNDRCV; + cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); + outmessage.msg_controllen = cmsg->cmsg_len; + sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); + memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo)); + + sinfo->sinfo_flags |= MSG_EOF; + sinfo->sinfo_assoc_id = associd; + + ret = kernel_sendmsg(sctp_con.sock, &outmessage, NULL, 0, 0); + + if (ret != 0) + log_print("send EOF to node failed: %d", ret); +} + + +/* INIT failed but we don't know which node... + restart INIT on all pending nodes */ +static void init_failed(void) +{ + int i; + struct nodeinfo *ni; + + for (i=1; i<=max_nodeid; i++) { + ni = nodeid2nodeinfo(i, 0); + if (!ni) + continue; + + if (test_and_clear_bit(NI_INIT_PENDING, &ni->flags)) { + ni->assoc_id = 0; + if (!test_and_set_bit(NI_WRITE_PENDING, &ni->flags)) { + spin_lock_bh(&write_nodes_lock); + list_add_tail(&ni->write_list, &write_nodes); + spin_unlock_bh(&write_nodes_lock); + } + } + } + wake_up_process(send_task); +} + +/* Something happened to an association */ +static void process_sctp_notification(struct msghdr *msg, char *buf) +{ + union sctp_notification *sn = (union sctp_notification *)buf; + + if (sn->sn_header.sn_type == SCTP_ASSOC_CHANGE) { + switch (sn->sn_assoc_change.sac_state) { + + case SCTP_COMM_UP: + case SCTP_RESTART: + { + /* Check that the new node is in the lockspace */ + struct sctp_prim prim; + mm_segment_t fs; + int nodeid; + int prim_len, ret; + int addr_len; + struct nodeinfo *ni; + + /* This seems to happen when we received a connection + * too early... or something... anyway, it happens but + * we always seem to get a real message too, see + * receive_from_sock */ + + if ((int)sn->sn_assoc_change.sac_assoc_id <= 0) { + log_print("COMM_UP for invalid assoc ID %d", + (int)sn->sn_assoc_change.sac_assoc_id); + init_failed(); + return; + } + memset(&prim, 0, sizeof(struct sctp_prim)); + prim_len = sizeof(struct sctp_prim); + prim.ssp_assoc_id = sn->sn_assoc_change.sac_assoc_id; + + fs = get_fs(); + set_fs(get_ds()); + ret = sctp_con.sock->ops->getsockopt(sctp_con.sock, + IPPROTO_SCTP, SCTP_PRIMARY_ADDR, + (char*)&prim, &prim_len); + set_fs(fs); + if (ret < 0) { + struct nodeinfo *ni; + + log_print("getsockopt/sctp_primary_addr on " + "new assoc %d failed : %d", + (int)sn->sn_assoc_change.sac_assoc_id, ret); + + /* Retry INIT later */ + ni = assoc2nodeinfo(sn->sn_assoc_change.sac_assoc_id); + if (ni) + clear_bit(NI_INIT_PENDING, &ni->flags); + return; + } + make_sockaddr(&prim.ssp_addr, 0, &addr_len); + if (dlm_addr_to_nodeid(&prim.ssp_addr, &nodeid)) { + log_print("reject connect from unknown addr"); + send_shutdown(prim.ssp_assoc_id); + return; + } + + ni = nodeid2nodeinfo(nodeid, GFP_KERNEL); + if (!ni) + return; + + /* Save the assoc ID */ + spin_lock(&ni->lock); + ni->assoc_id = sn->sn_assoc_change.sac_assoc_id; + spin_unlock(&ni->lock); + + log_print("got new/restarted association %d nodeid %d", + (int)sn->sn_assoc_change.sac_assoc_id, nodeid); + + /* Send any pending writes */ + clear_bit(NI_INIT_PENDING, &ni->flags); + if (!test_and_set_bit(NI_WRITE_PENDING, &ni->flags)) { + spin_lock_bh(&write_nodes_lock); + list_add_tail(&ni->write_list, &write_nodes); + spin_unlock_bh(&write_nodes_lock); + } + wake_up_process(send_task); + } + break; + + case SCTP_COMM_LOST: + case SCTP_SHUTDOWN_COMP: + { + struct nodeinfo *ni; + + ni = assoc2nodeinfo(sn->sn_assoc_change.sac_assoc_id); + if (ni) { + spin_lock(&ni->lock); + ni->assoc_id = 0; + spin_unlock(&ni->lock); + } + } + break; + + /* We don't know which INIT failed, so clear the PENDING flags + * on them all. if assoc_id is zero then it will then try + * again */ + + case SCTP_CANT_STR_ASSOC: + { + log_print("Can't start SCTP association - retrying"); + init_failed(); + } + break; + + default: + log_print("unexpected SCTP assoc change id=%d state=%d", + (int)sn->sn_assoc_change.sac_assoc_id, + sn->sn_assoc_change.sac_state); + } + } +} + +/* Data received from remote end */ +static int receive_from_sock(void) +{ + int ret = 0; + struct msghdr msg; + struct kvec iov[2]; + unsigned len; + int r; + struct sctp_sndrcvinfo *sinfo; + struct cmsghdr *cmsg; + struct nodeinfo *ni; + + /* These two are marginally too big for stack allocation, but this + * function is (currently) only called by dlm_recvd so static should be + * OK. + */ + static struct sockaddr_storage msgname; + static char incmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; + + if (sctp_con.sock == NULL) + goto out; + + if (sctp_con.rx_page == NULL) { + /* + * This doesn't need to be atomic, but I think it should + * improve performance if it is. + */ + sctp_con.rx_page = alloc_page(GFP_ATOMIC); + if (sctp_con.rx_page == NULL) + goto out_resched; + CBUF_INIT(&sctp_con.cb, PAGE_CACHE_SIZE); + } + + memset(&incmsg, 0, sizeof(incmsg)); + memset(&msgname, 0, sizeof(msgname)); + + memset(incmsg, 0, sizeof(incmsg)); + msg.msg_name = &msgname; + msg.msg_namelen = sizeof(msgname); + msg.msg_flags = 0; + msg.msg_control = incmsg; + msg.msg_controllen = sizeof(incmsg); + + /* I don't see why this circular buffer stuff is necessary for SCTP + * which is a packet-based protocol, but the whole thing breaks under + * load without it! The overhead is minimal (and is in the TCP lowcomms + * anyway, of course) so I'll leave it in until I can figure out what's + * really happening. + */ + + /* + * iov[0] is the bit of the circular buffer between the current end + * point (cb.base + cb.len) and the end of the buffer. + */ + iov[0].iov_len = sctp_con.cb.base - CBUF_DATA(&sctp_con.cb); + iov[0].iov_base = page_address(sctp_con.rx_page) + + CBUF_DATA(&sctp_con.cb); + iov[1].iov_len = 0; + + /* + * iov[1] is the bit of the circular buffer between the start of the + * buffer and the start of the currently used section (cb.base) + */ + if (CBUF_DATA(&sctp_con.cb) >= sctp_con.cb.base) { + iov[0].iov_len = PAGE_CACHE_SIZE - CBUF_DATA(&sctp_con.cb); + iov[1].iov_len = sctp_con.cb.base; + iov[1].iov_base = page_address(sctp_con.rx_page); + msg.msg_iovlen = 2; + } + len = iov[0].iov_len + iov[1].iov_len; + + r = ret = kernel_recvmsg(sctp_con.sock, &msg, iov, 1, len, + MSG_NOSIGNAL | MSG_DONTWAIT); + if (ret <= 0) + goto out_close; + + msg.msg_control = incmsg; + msg.msg_controllen = sizeof(incmsg); + cmsg = CMSG_FIRSTHDR(&msg); + sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); + + if (msg.msg_flags & MSG_NOTIFICATION) { + process_sctp_notification(&msg, page_address(sctp_con.rx_page)); + return 0; + } + + /* Is this a new association ? */ + ni = nodeid2nodeinfo(le32_to_cpu(sinfo->sinfo_ppid), GFP_KERNEL); + if (ni) { + ni->assoc_id = sinfo->sinfo_assoc_id; + if (test_and_clear_bit(NI_INIT_PENDING, &ni->flags)) { + + if (!test_and_set_bit(NI_WRITE_PENDING, &ni->flags)) { + spin_lock_bh(&write_nodes_lock); + list_add_tail(&ni->write_list, &write_nodes); + spin_unlock_bh(&write_nodes_lock); + } + wake_up_process(send_task); + } + } + + /* INIT sends a message with length of 1 - ignore it */ + if (r == 1) + return 0; + + CBUF_ADD(&sctp_con.cb, ret); + ret = dlm_process_incoming_buffer(cpu_to_le32(sinfo->sinfo_ppid), + page_address(sctp_con.rx_page), + sctp_con.cb.base, sctp_con.cb.len, + PAGE_CACHE_SIZE); + if (ret < 0) + goto out_close; + CBUF_EAT(&sctp_con.cb, ret); + + out: + ret = 0; + goto out_ret; + + out_resched: + lowcomms_data_ready(sctp_con.sock->sk, 0); + ret = 0; + schedule(); + goto out_ret; + + out_close: + if (ret != -EAGAIN) + log_print("error reading from sctp socket: %d", ret); + out_ret: + return ret; +} + +/* Bind to an IP address. SCTP allows multiple address so it can do multi-homing */ +static int add_bind_addr(struct sockaddr_storage *addr, int addr_len, int num) +{ + mm_segment_t fs; + int result = 0; + + fs = get_fs(); + set_fs(get_ds()); + if (num == 1) + result = sctp_con.sock->ops->bind(sctp_con.sock, + (struct sockaddr *) addr, addr_len); + else + result = sctp_con.sock->ops->setsockopt(sctp_con.sock, SOL_SCTP, + SCTP_SOCKOPT_BINDX_ADD, (char *)addr, addr_len); + set_fs(fs); + + if (result < 0) + log_print("Can't bind to port %d addr number %d", + dlm_config.tcp_port, num); + + return result; +} + +static void init_local(void) +{ + struct sockaddr_storage sas, *addr; + int i; + + local_nodeid = dlm_our_nodeid(); + + for (i = 0; i < DLM_MAX_ADDR_COUNT - 1; i++) { + if (dlm_our_addr(&sas, i)) + break; + + addr = kmalloc(sizeof(*addr), GFP_KERNEL); + if (!addr) + break; + memcpy(addr, &sas, sizeof(*addr)); + local_addr[local_count++] = addr; + } +} + +/* Initialise SCTP socket and bind to all interfaces */ +static int init_sock(void) +{ + mm_segment_t fs; + struct socket *sock = NULL; + struct sockaddr_storage localaddr; + struct sctp_event_subscribe subscribe; + int result = -EINVAL, num = 1, i, addr_len; + + if (!local_count) { + init_local(); + if (!local_count) { + log_print("no local IP address has been set"); + goto out; + } + } + + result = sock_create_kern(local_addr[0]->ss_family, SOCK_SEQPACKET, + IPPROTO_SCTP, &sock); + if (result < 0) { + log_print("Can't create comms socket, check SCTP is loaded"); + goto out; + } + + /* Listen for events */ + memset(&subscribe, 0, sizeof(subscribe)); + subscribe.sctp_data_io_event = 1; + subscribe.sctp_association_event = 1; + subscribe.sctp_send_failure_event = 1; + subscribe.sctp_shutdown_event = 1; + subscribe.sctp_partial_delivery_event = 1; + + fs = get_fs(); + set_fs(get_ds()); + result = sock->ops->setsockopt(sock, SOL_SCTP, SCTP_EVENTS, + (char *)&subscribe, sizeof(subscribe)); + set_fs(fs); + + if (result < 0) { + log_print("Failed to set SCTP_EVENTS on socket: result=%d", + result); + goto create_delsock; + } + + /* Init con struct */ + sock->sk->sk_user_data = &sctp_con; + sctp_con.sock = sock; + sctp_con.sock->sk->sk_data_ready = lowcomms_data_ready; + + /* Bind to all interfaces. */ + for (i = 0; i < local_count; i++) { + memcpy(&localaddr, local_addr[i], sizeof(localaddr)); + make_sockaddr(&localaddr, dlm_config.tcp_port, &addr_len); + + result = add_bind_addr(&localaddr, addr_len, num); + if (result) + goto create_delsock; + ++num; + } + + result = sock->ops->listen(sock, 5); + if (result < 0) { + log_print("Can't set socket listening"); + goto create_delsock; + } + + return 0; + + create_delsock: + sock_release(sock); + sctp_con.sock = NULL; + out: + return result; +} + + +static struct writequeue_entry *new_writequeue_entry(int allocation) +{ + struct writequeue_entry *entry; + + entry = kmalloc(sizeof(struct writequeue_entry), allocation); + if (!entry) + return NULL; + + entry->page = alloc_page(allocation); + if (!entry->page) { + kfree(entry); + return NULL; + } + + entry->offset = 0; + entry->len = 0; + entry->end = 0; + entry->users = 0; + + return entry; +} + +void *dlm_lowcomms_get_buffer(int nodeid, int len, int allocation, char **ppc) +{ + struct writequeue_entry *e; + int offset = 0; + int users = 0; + struct nodeinfo *ni; + + if (!atomic_read(&accepting)) + return NULL; + + ni = nodeid2nodeinfo(nodeid, allocation); + if (!ni) + return NULL; + + spin_lock(&ni->writequeue_lock); + e = list_entry(ni->writequeue.prev, struct writequeue_entry, list); + if (((struct list_head *) e == &ni->writequeue) || + (PAGE_CACHE_SIZE - e->end < len)) { + e = NULL; + } else { + offset = e->end; + e->end += len; + users = e->users++; + } + spin_unlock(&ni->writequeue_lock); + + if (e) { + got_one: + if (users == 0) + kmap(e->page); + *ppc = page_address(e->page) + offset; + return e; + } + + e = new_writequeue_entry(allocation); + if (e) { + spin_lock(&ni->writequeue_lock); + offset = e->end; + e->end += len; + e->ni = ni; + users = e->users++; + list_add_tail(&e->list, &ni->writequeue); + spin_unlock(&ni->writequeue_lock); + goto got_one; + } + return NULL; +} + +void dlm_lowcomms_commit_buffer(void *arg) +{ + struct writequeue_entry *e = (struct writequeue_entry *) arg; + int users; + struct nodeinfo *ni = e->ni; + + if (!atomic_read(&accepting)) + return; + + spin_lock(&ni->writequeue_lock); + users = --e->users; + if (users) + goto out; + e->len = e->end - e->offset; + kunmap(e->page); + spin_unlock(&ni->writequeue_lock); + + if (!test_and_set_bit(NI_WRITE_PENDING, &ni->flags)) { + spin_lock_bh(&write_nodes_lock); + list_add_tail(&ni->write_list, &write_nodes); + spin_unlock_bh(&write_nodes_lock); + wake_up_process(send_task); + } + return; + + out: + spin_unlock(&ni->writequeue_lock); + return; +} + +static void free_entry(struct writequeue_entry *e) +{ + __free_page(e->page); + kfree(e); +} + +/* Initiate an SCTP association. In theory we could just use sendmsg() on + the first IP address and it should work, but this allows us to set up the + association before sending any valuable data that we can't afford to lose. + It also keeps the send path clean as it can now always use the association ID */ +static void initiate_association(int nodeid) +{ + struct sockaddr_storage rem_addr; + static char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; + struct msghdr outmessage; + struct cmsghdr *cmsg; + struct sctp_sndrcvinfo *sinfo; + int ret; + int addrlen; + char buf[1]; + struct kvec iov[1]; + struct nodeinfo *ni; + + log_print("Initiating association with node %d", nodeid); + + ni = nodeid2nodeinfo(nodeid, GFP_KERNEL); + if (!ni) + return; + + if (nodeid_to_addr(nodeid, (struct sockaddr *)&rem_addr)) { + log_print("no address for nodeid %d", nodeid); + return; + } + + make_sockaddr(&rem_addr, dlm_config.tcp_port, &addrlen); + + outmessage.msg_name = &rem_addr; + outmessage.msg_namelen = addrlen; + outmessage.msg_control = outcmsg; + outmessage.msg_controllen = sizeof(outcmsg); + outmessage.msg_flags = MSG_EOR; + + iov[0].iov_base = buf; + iov[0].iov_len = 1; + + /* Real INIT messages seem to cause trouble. Just send a 1 byte message + we can afford to lose */ + cmsg = CMSG_FIRSTHDR(&outmessage); + cmsg->cmsg_level = IPPROTO_SCTP; + cmsg->cmsg_type = SCTP_SNDRCV; + cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); + sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); + memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo)); + sinfo->sinfo_ppid = cpu_to_le32(local_nodeid); + + outmessage.msg_controllen = cmsg->cmsg_len; + ret = kernel_sendmsg(sctp_con.sock, &outmessage, iov, 1, 1); + if (ret < 0) { + log_print("send INIT to node failed: %d", ret); + /* Try again later */ + clear_bit(NI_INIT_PENDING, &ni->flags); + } +} + +/* Send a message */ +static int send_to_sock(struct nodeinfo *ni) +{ + int ret = 0; + struct writequeue_entry *e; + int len, offset; + struct msghdr outmsg; + static char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; + struct cmsghdr *cmsg; + struct sctp_sndrcvinfo *sinfo; + struct kvec iov; + + /* See if we need to init an association before we start + sending precious messages */ + spin_lock(&ni->lock); + if (!ni->assoc_id && !test_and_set_bit(NI_INIT_PENDING, &ni->flags)) { + spin_unlock(&ni->lock); + initiate_association(ni->nodeid); + return 0; + } + spin_unlock(&ni->lock); + + outmsg.msg_name = NULL; /* We use assoc_id */ + outmsg.msg_namelen = 0; + outmsg.msg_control = outcmsg; + outmsg.msg_controllen = sizeof(outcmsg); + outmsg.msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL | MSG_EOR; + + cmsg = CMSG_FIRSTHDR(&outmsg); + cmsg->cmsg_level = IPPROTO_SCTP; + cmsg->cmsg_type = SCTP_SNDRCV; + cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); + sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); + memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo)); + sinfo->sinfo_ppid = cpu_to_le32(local_nodeid); + sinfo->sinfo_assoc_id = ni->assoc_id; + outmsg.msg_controllen = cmsg->cmsg_len; + + spin_lock(&ni->writequeue_lock); + for (;;) { + if (list_empty(&ni->writequeue)) + break; + e = list_entry(ni->writequeue.next, struct writequeue_entry, + list); + kmap(e->page); + len = e->len; + offset = e->offset; + BUG_ON(len == 0 && e->users == 0); + spin_unlock(&ni->writequeue_lock); + + ret = 0; + if (len) { + iov.iov_base = page_address(e->page)+offset; + iov.iov_len = len; + + ret = kernel_sendmsg(sctp_con.sock, &outmsg, &iov, 1, + len); + if (ret == -EAGAIN) { + sctp_con.eagain_flag = 1; + goto out; + } else if (ret < 0) + goto send_error; + } else { + /* Don't starve people filling buffers */ + schedule(); + } + + spin_lock(&ni->writequeue_lock); + e->offset += ret; + e->len -= ret; + + if (e->len == 0 && e->users == 0) { + list_del(&e->list); + free_entry(e); + continue; + } + } + spin_unlock(&ni->writequeue_lock); + out: + return ret; + + send_error: + log_print("Error sending to node %d %d", ni->nodeid, ret); + spin_lock(&ni->lock); + if (!test_and_set_bit(NI_INIT_PENDING, &ni->flags)) { + ni->assoc_id = 0; + spin_unlock(&ni->lock); + initiate_association(ni->nodeid); + } else + spin_unlock(&ni->lock); + + return ret; +} + +/* Try to send any messages that are pending */ +static void process_output_queue(void) +{ + struct list_head *list; + struct list_head *temp; + + spin_lock_bh(&write_nodes_lock); + list_for_each_safe(list, temp, &write_nodes) { + struct nodeinfo *ni = + list_entry(list, struct nodeinfo, write_list); + clear_bit(NI_WRITE_PENDING, &ni->flags); + list_del(&ni->write_list); + + spin_unlock_bh(&write_nodes_lock); + + send_to_sock(ni); + spin_lock_bh(&write_nodes_lock); + } + spin_unlock_bh(&write_nodes_lock); +} + +/* Called after we've had -EAGAIN and been woken up */ +static void refill_write_queue(void) +{ + int i; + + for (i=1; i<=max_nodeid; i++) { + struct nodeinfo *ni = nodeid2nodeinfo(i, 0); + + if (ni) { + if (!test_and_set_bit(NI_WRITE_PENDING, &ni->flags)) { + spin_lock_bh(&write_nodes_lock); + list_add_tail(&ni->write_list, &write_nodes); + spin_unlock_bh(&write_nodes_lock); + } + } + } +} + +static void clean_one_writequeue(struct nodeinfo *ni) +{ + struct list_head *list; + struct list_head *temp; + + spin_lock(&ni->writequeue_lock); + list_for_each_safe(list, temp, &ni->writequeue) { + struct writequeue_entry *e = + list_entry(list, struct writequeue_entry, list); + list_del(&e->list); + free_entry(e); + } + spin_unlock(&ni->writequeue_lock); +} + +static void clean_writequeues(void) +{ + int i; + + for (i=1; i<=max_nodeid; i++) { + struct nodeinfo *ni = nodeid2nodeinfo(i, 0); + if (ni) + clean_one_writequeue(ni); + } +} + + +static void dealloc_nodeinfo(void) +{ + int i; + + for (i=1; i<=max_nodeid; i++) { + struct nodeinfo *ni = nodeid2nodeinfo(i, 0); + if (ni) { + idr_remove(&nodeinfo_idr, i); + kfree(ni); + } + } +} + +static int write_list_empty(void) +{ + int status; + + spin_lock_bh(&write_nodes_lock); + status = list_empty(&write_nodes); + spin_unlock_bh(&write_nodes_lock); + + return status; +} + +static int dlm_recvd(void *data) +{ + DECLARE_WAITQUEUE(wait, current); + + while (!kthread_should_stop()) { + int count = 0; + + set_current_state(TASK_INTERRUPTIBLE); + add_wait_queue(&lowcomms_recv_wait, &wait); + if (!test_bit(CF_READ_PENDING, &sctp_con.flags)) + schedule(); + remove_wait_queue(&lowcomms_recv_wait, &wait); + set_current_state(TASK_RUNNING); + + if (test_and_clear_bit(CF_READ_PENDING, &sctp_con.flags)) { + int ret; + + do { + ret = receive_from_sock(); + + /* Don't starve out everyone else */ + if (++count >= MAX_RX_MSG_COUNT) { + schedule(); + count = 0; + } + } while (!kthread_should_stop() && ret >=0); + } + schedule(); + } + + return 0; +} + +static int dlm_sendd(void *data) +{ + DECLARE_WAITQUEUE(wait, current); + + add_wait_queue(sctp_con.sock->sk->sk_sleep, &wait); + + while (!kthread_should_stop()) { + set_current_state(TASK_INTERRUPTIBLE); + if (write_list_empty()) + schedule(); + set_current_state(TASK_RUNNING); + + if (sctp_con.eagain_flag) { + sctp_con.eagain_flag = 0; + refill_write_queue(); + } + process_output_queue(); + } + + remove_wait_queue(sctp_con.sock->sk->sk_sleep, &wait); + + return 0; +} + +static void daemons_stop(void) +{ + kthread_stop(recv_task); + kthread_stop(send_task); +} + +static int daemons_start(void) +{ + struct task_struct *p; + int error; + + p = kthread_run(dlm_recvd, NULL, "dlm_recvd"); + error = IS_ERR(p); + if (error) { + log_print("can't start dlm_recvd %d", error); + return error; + } + recv_task = p; + + p = kthread_run(dlm_sendd, NULL, "dlm_sendd"); + error = IS_ERR(p); + if (error) { + log_print("can't start dlm_sendd %d", error); + kthread_stop(recv_task); + return error; + } + send_task = p; + + return 0; +} + +/* + * This is quite likely to sleep... + */ +int dlm_lowcomms_start(void) +{ + int error; + + spin_lock_init(&write_nodes_lock); + INIT_LIST_HEAD(&write_nodes); + init_rwsem(&nodeinfo_lock); + + error = init_sock(); + if (error) + goto fail_sock; + error = daemons_start(); + if (error) + goto fail_sock; + atomic_set(&accepting, 1); + return 0; + + fail_sock: + close_connection(); + return error; +} + +/* Set all the activity flags to prevent any socket activity. */ + +void dlm_lowcomms_stop(void) +{ + atomic_set(&accepting, 0); + sctp_con.flags = 0x7; + daemons_stop(); + clean_writequeues(); + close_connection(); + dealloc_nodeinfo(); + max_nodeid = 0; +} + +int dlm_lowcomms_init(void) +{ + init_waitqueue_head(&lowcomms_recv_wait); + return 0; +} + +void dlm_lowcomms_exit(void) +{ + int i; + + for (i = 0; i < local_count; i++) + kfree(local_addr[i]); + local_count = 0; + local_nodeid = 0; +} + diff --git a/fs/dlm/lowcomms.h b/fs/dlm/lowcomms.h new file mode 100644 index 000000000000..3af8035ff12f --- /dev/null +++ b/fs/dlm/lowcomms.h @@ -0,0 +1,25 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __LOWCOMMS_DOT_H__ +#define __LOWCOMMS_DOT_H__ + +int dlm_lowcomms_init(void); +void dlm_lowcomms_exit(void); +int dlm_lowcomms_start(void); +void dlm_lowcomms_stop(void); +void *dlm_lowcomms_get_buffer(int nodeid, int len, int allocation, char **ppc); +void dlm_lowcomms_commit_buffer(void *mh); + +#endif /* __LOWCOMMS_DOT_H__ */ + diff --git a/fs/dlm/lvb_table.h b/fs/dlm/lvb_table.h new file mode 100644 index 000000000000..cc3e92f3feef --- /dev/null +++ b/fs/dlm/lvb_table.h @@ -0,0 +1,18 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __LVB_TABLE_DOT_H__ +#define __LVB_TABLE_DOT_H__ + +extern const int dlm_lvb_operations[8][8]; + +#endif diff --git a/fs/dlm/main.c b/fs/dlm/main.c new file mode 100644 index 000000000000..81bf4cb22033 --- /dev/null +++ b/fs/dlm/main.c @@ -0,0 +1,89 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "lockspace.h" +#include "lock.h" +#include "memory.h" +#include "lowcomms.h" +#include "config.h" + +#ifdef CONFIG_DLM_DEBUG +int dlm_register_debugfs(void); +void dlm_unregister_debugfs(void); +#else +static inline int dlm_register_debugfs(void) { return 0; } +static inline void dlm_unregister_debugfs(void) { } +#endif + +static int __init init_dlm(void) +{ + int error; + + error = dlm_memory_init(); + if (error) + goto out; + + error = dlm_lockspace_init(); + if (error) + goto out_mem; + + error = dlm_config_init(); + if (error) + goto out_lockspace; + + error = dlm_register_debugfs(); + if (error) + goto out_config; + + error = dlm_lowcomms_init(); + if (error) + goto out_debug; + + printk("DLM (built %s %s) installed\n", __DATE__, __TIME__); + + return 0; + + out_debug: + dlm_unregister_debugfs(); + out_config: + dlm_config_exit(); + out_lockspace: + dlm_lockspace_exit(); + out_mem: + dlm_memory_exit(); + out: + return error; +} + +static void __exit exit_dlm(void) +{ + dlm_lowcomms_exit(); + dlm_config_exit(); + dlm_memory_exit(); + dlm_lockspace_exit(); + dlm_unregister_debugfs(); +} + +module_init(init_dlm); +module_exit(exit_dlm); + +MODULE_DESCRIPTION("Distributed Lock Manager"); +MODULE_AUTHOR("Red Hat, Inc."); +MODULE_LICENSE("GPL"); + +EXPORT_SYMBOL_GPL(dlm_new_lockspace); +EXPORT_SYMBOL_GPL(dlm_release_lockspace); +EXPORT_SYMBOL_GPL(dlm_lock); +EXPORT_SYMBOL_GPL(dlm_unlock); + diff --git a/fs/dlm/member.c b/fs/dlm/member.c new file mode 100644 index 000000000000..439249b62a57 --- /dev/null +++ b/fs/dlm/member.c @@ -0,0 +1,314 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "lockspace.h" +#include "member.h" +#include "recoverd.h" +#include "recover.h" +#include "lowcomms.h" +#include "rcom.h" +#include "config.h" + +/* + * Following called by dlm_recoverd thread + */ + +static void add_ordered_member(struct dlm_ls *ls, struct dlm_member *new) +{ + struct dlm_member *memb = NULL; + struct list_head *tmp; + struct list_head *newlist = &new->list; + struct list_head *head = &ls->ls_nodes; + + list_for_each(tmp, head) { + memb = list_entry(tmp, struct dlm_member, list); + if (new->nodeid < memb->nodeid) + break; + } + + if (!memb) + list_add_tail(newlist, head); + else { + /* FIXME: can use list macro here */ + newlist->prev = tmp->prev; + newlist->next = tmp; + tmp->prev->next = newlist; + tmp->prev = newlist; + } +} + +static int dlm_add_member(struct dlm_ls *ls, int nodeid) +{ + struct dlm_member *memb; + int w; + + memb = kmalloc(sizeof(struct dlm_member), GFP_KERNEL); + if (!memb) + return -ENOMEM; + + w = dlm_node_weight(ls->ls_name, nodeid); + if (w < 0) + return w; + + memb->nodeid = nodeid; + memb->weight = w; + add_ordered_member(ls, memb); + ls->ls_num_nodes++; + return 0; +} + +static void dlm_remove_member(struct dlm_ls *ls, struct dlm_member *memb) +{ + list_move(&memb->list, &ls->ls_nodes_gone); + ls->ls_num_nodes--; +} + +static int dlm_is_member(struct dlm_ls *ls, int nodeid) +{ + struct dlm_member *memb; + + list_for_each_entry(memb, &ls->ls_nodes, list) { + if (memb->nodeid == nodeid) + return TRUE; + } + return FALSE; +} + +int dlm_is_removed(struct dlm_ls *ls, int nodeid) +{ + struct dlm_member *memb; + + list_for_each_entry(memb, &ls->ls_nodes_gone, list) { + if (memb->nodeid == nodeid) + return TRUE; + } + return FALSE; +} + +static void clear_memb_list(struct list_head *head) +{ + struct dlm_member *memb; + + while (!list_empty(head)) { + memb = list_entry(head->next, struct dlm_member, list); + list_del(&memb->list); + kfree(memb); + } +} + +void dlm_clear_members(struct dlm_ls *ls) +{ + clear_memb_list(&ls->ls_nodes); + ls->ls_num_nodes = 0; +} + +void dlm_clear_members_gone(struct dlm_ls *ls) +{ + clear_memb_list(&ls->ls_nodes_gone); +} + +static void make_member_array(struct dlm_ls *ls) +{ + struct dlm_member *memb; + int i, w, x = 0, total = 0, all_zero = 0, *array; + + kfree(ls->ls_node_array); + ls->ls_node_array = NULL; + + list_for_each_entry(memb, &ls->ls_nodes, list) { + if (memb->weight) + total += memb->weight; + } + + /* all nodes revert to weight of 1 if all have weight 0 */ + + if (!total) { + total = ls->ls_num_nodes; + all_zero = 1; + } + + ls->ls_total_weight = total; + + array = kmalloc(sizeof(int) * total, GFP_KERNEL); + if (!array) + return; + + list_for_each_entry(memb, &ls->ls_nodes, list) { + if (!all_zero && !memb->weight) + continue; + + if (all_zero) + w = 1; + else + w = memb->weight; + + DLM_ASSERT(x < total, printk("total %d x %d\n", total, x);); + + for (i = 0; i < w; i++) + array[x++] = memb->nodeid; + } + + ls->ls_node_array = array; +} + +/* send a status request to all members just to establish comms connections */ + +static void ping_members(struct dlm_ls *ls) +{ + struct dlm_member *memb; + list_for_each_entry(memb, &ls->ls_nodes, list) + dlm_rcom_status(ls, memb->nodeid); +} + +int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out) +{ + struct dlm_member *memb, *safe; + int i, error, found, pos = 0, neg = 0, low = -1; + + /* move departed members from ls_nodes to ls_nodes_gone */ + + list_for_each_entry_safe(memb, safe, &ls->ls_nodes, list) { + found = FALSE; + for (i = 0; i < rv->node_count; i++) { + if (memb->nodeid == rv->nodeids[i]) { + found = TRUE; + break; + } + } + + if (!found) { + neg++; + dlm_remove_member(ls, memb); + log_debug(ls, "remove member %d", memb->nodeid); + } + } + + /* add new members to ls_nodes */ + + for (i = 0; i < rv->node_count; i++) { + if (dlm_is_member(ls, rv->nodeids[i])) + continue; + dlm_add_member(ls, rv->nodeids[i]); + pos++; + log_debug(ls, "add member %d", rv->nodeids[i]); + } + + list_for_each_entry(memb, &ls->ls_nodes, list) { + if (low == -1 || memb->nodeid < low) + low = memb->nodeid; + } + ls->ls_low_nodeid = low; + + make_member_array(ls); + dlm_set_recover_status(ls, DLM_RS_NODES); + *neg_out = neg; + + ping_members(ls); + + error = dlm_recover_members_wait(ls); + log_debug(ls, "total members %d", ls->ls_num_nodes); + return error; +} + +/* + * Following called from lockspace.c + */ + +int dlm_ls_stop(struct dlm_ls *ls) +{ + int new; + + /* + * A stop cancels any recovery that's in progress (see RECOVERY_STOP, + * dlm_recovery_stopped()) and prevents any new locks from being + * processed (see RUNNING, dlm_locking_stopped()). + */ + + spin_lock(&ls->ls_recover_lock); + set_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); + new = test_and_clear_bit(LSFL_RUNNING, &ls->ls_flags); + ls->ls_recover_seq++; + spin_unlock(&ls->ls_recover_lock); + + /* + * This in_recovery lock does two things: + * + * 1) Keeps this function from returning until all threads are out + * of locking routines and locking is truely stopped. + * 2) Keeps any new requests from being processed until it's unlocked + * when recovery is complete. + */ + + if (new) + down_write(&ls->ls_in_recovery); + + /* + * The recoverd suspend/resume makes sure that dlm_recoverd (if + * running) has noticed the clearing of RUNNING above and quit + * processing the previous recovery. This will be true for all nodes + * before any nodes start the new recovery. + */ + + dlm_recoverd_suspend(ls); + ls->ls_recover_status = 0; + dlm_recoverd_resume(ls); + return 0; +} + +int dlm_ls_start(struct dlm_ls *ls) +{ + struct dlm_recover *rv = NULL, *rv_old; + int *ids = NULL; + int error, count; + + rv = kmalloc(sizeof(struct dlm_recover), GFP_KERNEL); + if (!rv) + return -ENOMEM; + memset(rv, 0, sizeof(struct dlm_recover)); + + error = count = dlm_nodeid_list(ls->ls_name, &ids); + if (error <= 0) + goto fail; + + spin_lock(&ls->ls_recover_lock); + + /* the lockspace needs to be stopped before it can be started */ + + if (!dlm_locking_stopped(ls)) { + spin_unlock(&ls->ls_recover_lock); + log_error(ls, "start ignored: lockspace running"); + error = -EINVAL; + goto fail; + } + + rv->nodeids = ids; + rv->node_count = count; + rv->seq = ++ls->ls_recover_seq; + rv_old = ls->ls_recover_args; + ls->ls_recover_args = rv; + spin_unlock(&ls->ls_recover_lock); + + if (rv_old) { + kfree(rv_old->nodeids); + kfree(rv_old); + } + + dlm_recoverd_kick(ls); + return 0; + + fail: + kfree(rv); + kfree(ids); + return error; +} + diff --git a/fs/dlm/member.h b/fs/dlm/member.h new file mode 100644 index 000000000000..927c08c19214 --- /dev/null +++ b/fs/dlm/member.h @@ -0,0 +1,24 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __MEMBER_DOT_H__ +#define __MEMBER_DOT_H__ + +int dlm_ls_stop(struct dlm_ls *ls); +int dlm_ls_start(struct dlm_ls *ls); +void dlm_clear_members(struct dlm_ls *ls); +void dlm_clear_members_gone(struct dlm_ls *ls); +int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv,int *neg_out); +int dlm_is_removed(struct dlm_ls *ls, int nodeid); + +#endif /* __MEMBER_DOT_H__ */ + diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c new file mode 100644 index 000000000000..0b9851d0bdb2 --- /dev/null +++ b/fs/dlm/memory.c @@ -0,0 +1,122 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "config.h" +#include "memory.h" + +static kmem_cache_t *lkb_cache; + + +int dlm_memory_init(void) +{ + int ret = 0; + + lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb), + __alignof__(struct dlm_lkb), 0, NULL, NULL); + if (!lkb_cache) + ret = -ENOMEM; + return ret; +} + +void dlm_memory_exit(void) +{ + if (lkb_cache) + kmem_cache_destroy(lkb_cache); +} + +char *allocate_lvb(struct dlm_ls *ls) +{ + char *p; + + p = kmalloc(ls->ls_lvblen, GFP_KERNEL); + if (p) + memset(p, 0, ls->ls_lvblen); + return p; +} + +void free_lvb(char *p) +{ + kfree(p); +} + +uint64_t *allocate_range(struct dlm_ls *ls) +{ + int ralen = 4*sizeof(uint64_t); + uint64_t *p; + + p = kmalloc(ralen, GFP_KERNEL); + if (p) + memset(p, 0, ralen); + return p; +} + +void free_range(uint64_t *p) +{ + kfree(p); +} + +/* FIXME: have some minimal space built-in to rsb for the name and + kmalloc a separate name if needed, like dentries are done */ + +struct dlm_rsb *allocate_rsb(struct dlm_ls *ls, int namelen) +{ + struct dlm_rsb *r; + + DLM_ASSERT(namelen <= DLM_RESNAME_MAXLEN,); + + r = kmalloc(sizeof(*r) + namelen, GFP_KERNEL); + if (r) + memset(r, 0, sizeof(*r) + namelen); + return r; +} + +void free_rsb(struct dlm_rsb *r) +{ + if (r->res_lvbptr) + free_lvb(r->res_lvbptr); + kfree(r); +} + +struct dlm_lkb *allocate_lkb(struct dlm_ls *ls) +{ + struct dlm_lkb *lkb; + + lkb = kmem_cache_alloc(lkb_cache, GFP_KERNEL); + if (lkb) + memset(lkb, 0, sizeof(*lkb)); + return lkb; +} + +void free_lkb(struct dlm_lkb *lkb) +{ + kmem_cache_free(lkb_cache, lkb); +} + +struct dlm_direntry *allocate_direntry(struct dlm_ls *ls, int namelen) +{ + struct dlm_direntry *de; + + DLM_ASSERT(namelen <= DLM_RESNAME_MAXLEN,); + + de = kmalloc(sizeof(*de) + namelen, GFP_KERNEL); + if (de) + memset(de, 0, sizeof(*de) + namelen); + return de; +} + +void free_direntry(struct dlm_direntry *de) +{ + kfree(de); +} + diff --git a/fs/dlm/memory.h b/fs/dlm/memory.h new file mode 100644 index 000000000000..7b235132b0b4 --- /dev/null +++ b/fs/dlm/memory.h @@ -0,0 +1,31 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __MEMORY_DOT_H__ +#define __MEMORY_DOT_H__ + +int dlm_memory_init(void); +void dlm_memory_exit(void); +struct dlm_rsb *allocate_rsb(struct dlm_ls *ls, int namelen); +void free_rsb(struct dlm_rsb *r); +struct dlm_lkb *allocate_lkb(struct dlm_ls *ls); +void free_lkb(struct dlm_lkb *l); +struct dlm_direntry *allocate_direntry(struct dlm_ls *ls, int namelen); +void free_direntry(struct dlm_direntry *de); +char *allocate_lvb(struct dlm_ls *ls); +void free_lvb(char *l); +uint64_t *allocate_range(struct dlm_ls *ls); +void free_range(uint64_t *l); + +#endif /* __MEMORY_DOT_H__ */ + diff --git a/fs/dlm/midcomms.c b/fs/dlm/midcomms.c new file mode 100644 index 000000000000..d96f9bbb407c --- /dev/null +++ b/fs/dlm/midcomms.c @@ -0,0 +1,140 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +/* + * midcomms.c + * + * This is the appallingly named "mid-level" comms layer. + * + * Its purpose is to take packets from the "real" comms layer, + * split them up into packets and pass them to the interested + * part of the locking mechanism. + * + * It also takes messages from the locking layer, formats them + * into packets and sends them to the comms layer. + */ + +#include "dlm_internal.h" +#include "lowcomms.h" +#include "config.h" +#include "rcom.h" +#include "lock.h" +#include "midcomms.h" + + +static void copy_from_cb(void *dst, const void *base, unsigned offset, + unsigned len, unsigned limit) +{ + unsigned copy = len; + + if ((copy + offset) > limit) + copy = limit - offset; + memcpy(dst, base + offset, copy); + len -= copy; + if (len) + memcpy(dst + copy, base, len); +} + +/* + * Called from the low-level comms layer to process a buffer of + * commands. + * + * Only complete messages are processed here, any "spare" bytes from + * the end of a buffer are saved and tacked onto the front of the next + * message that comes in. I doubt this will happen very often but we + * need to be able to cope with it and I don't want the task to be waiting + * for packets to come in when there is useful work to be done. + */ + +int dlm_process_incoming_buffer(int nodeid, const void *base, + unsigned offset, unsigned len, unsigned limit) +{ + unsigned char __tmp[DLM_INBUF_LEN]; + struct dlm_header *msg = (struct dlm_header *) __tmp; + int ret = 0; + int err = 0; + uint16_t msglen; + uint32_t lockspace; + + while (len > sizeof(struct dlm_header)) { + + /* Copy just the header to check the total length. The + message may wrap around the end of the buffer back to the + start, so we need to use a temp buffer and copy_from_cb. */ + + copy_from_cb(msg, base, offset, sizeof(struct dlm_header), + limit); + + msglen = le16_to_cpu(msg->h_length); + lockspace = msg->h_lockspace; + + err = -EINVAL; + if (msglen < sizeof(struct dlm_header)) + break; + err = -E2BIG; + if (msglen > dlm_config.buffer_size) { + log_print("message size %d from %d too big, buf len %d", + msglen, nodeid, len); + break; + } + err = 0; + + /* If only part of the full message is contained in this + buffer, then do nothing and wait for lowcomms to call + us again later with more data. We return 0 meaning + we've consumed none of the input buffer. */ + + if (msglen > len) + break; + + /* Allocate a larger temp buffer if the full message won't fit + in the buffer on the stack (which should work for most + ordinary messages). */ + + if (msglen > sizeof(__tmp) && + msg == (struct dlm_header *) __tmp) { + msg = kmalloc(dlm_config.buffer_size, GFP_KERNEL); + if (msg == NULL) + return ret; + } + + copy_from_cb(msg, base, offset, msglen, limit); + + BUG_ON(lockspace != msg->h_lockspace); + + ret += msglen; + offset += msglen; + offset &= (limit - 1); + len -= msglen; + + switch (msg->h_cmd) { + case DLM_MSG: + dlm_receive_message(msg, nodeid, FALSE); + break; + + case DLM_RCOM: + dlm_receive_rcom(msg, nodeid); + break; + + default: + log_print("unknown msg type %x from %u: %u %u %u %u", + msg->h_cmd, nodeid, msglen, len, offset, ret); + } + } + + if (msg != (struct dlm_header *) __tmp) + kfree(msg); + + return err ? err : ret; +} + diff --git a/fs/dlm/midcomms.h b/fs/dlm/midcomms.h new file mode 100644 index 000000000000..95852a5f111d --- /dev/null +++ b/fs/dlm/midcomms.h @@ -0,0 +1,21 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __MIDCOMMS_DOT_H__ +#define __MIDCOMMS_DOT_H__ + +int dlm_process_incoming_buffer(int nodeid, const void *base, unsigned offset, + unsigned len, unsigned limit); + +#endif /* __MIDCOMMS_DOT_H__ */ + diff --git a/fs/dlm/rcom.c b/fs/dlm/rcom.c new file mode 100644 index 000000000000..4c5c08a8860e --- /dev/null +++ b/fs/dlm/rcom.c @@ -0,0 +1,460 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "lockspace.h" +#include "member.h" +#include "lowcomms.h" +#include "midcomms.h" +#include "rcom.h" +#include "recover.h" +#include "dir.h" +#include "config.h" +#include "memory.h" +#include "lock.h" +#include "util.h" + + +static int rcom_response(struct dlm_ls *ls) +{ + return test_bit(LSFL_RCOM_READY, &ls->ls_flags); +} + +static int create_rcom(struct dlm_ls *ls, int to_nodeid, int type, int len, + struct dlm_rcom **rc_ret, struct dlm_mhandle **mh_ret) +{ + struct dlm_rcom *rc; + struct dlm_mhandle *mh; + char *mb; + int mb_len = sizeof(struct dlm_rcom) + len; + + mh = dlm_lowcomms_get_buffer(to_nodeid, mb_len, GFP_KERNEL, &mb); + if (!mh) { + log_print("create_rcom to %d type %d len %d ENOBUFS", + to_nodeid, type, len); + return -ENOBUFS; + } + memset(mb, 0, mb_len); + + rc = (struct dlm_rcom *) mb; + + rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); + rc->rc_header.h_lockspace = ls->ls_global_id; + rc->rc_header.h_nodeid = dlm_our_nodeid(); + rc->rc_header.h_length = mb_len; + rc->rc_header.h_cmd = DLM_RCOM; + + rc->rc_type = type; + + *mh_ret = mh; + *rc_ret = rc; + return 0; +} + +static void send_rcom(struct dlm_ls *ls, struct dlm_mhandle *mh, + struct dlm_rcom *rc) +{ + dlm_rcom_out(rc); + dlm_lowcomms_commit_buffer(mh); +} + +/* When replying to a status request, a node also sends back its + configuration values. The requesting node then checks that the remote + node is configured the same way as itself. */ + +static void make_config(struct dlm_ls *ls, struct rcom_config *rf) +{ + rf->rf_lvblen = ls->ls_lvblen; + rf->rf_lsflags = ls->ls_exflags; +} + +static int check_config(struct dlm_ls *ls, struct rcom_config *rf, int nodeid) +{ + if (rf->rf_lvblen != ls->ls_lvblen || + rf->rf_lsflags != ls->ls_exflags) { + log_error(ls, "config mismatch: %d,%x nodeid %d: %d,%x", + ls->ls_lvblen, ls->ls_exflags, + nodeid, rf->rf_lvblen, rf->rf_lsflags); + return -EINVAL; + } + return 0; +} + +int dlm_rcom_status(struct dlm_ls *ls, int nodeid) +{ + struct dlm_rcom *rc; + struct dlm_mhandle *mh; + int error = 0; + + memset(ls->ls_recover_buf, 0, dlm_config.buffer_size); + + if (nodeid == dlm_our_nodeid()) { + rc = (struct dlm_rcom *) ls->ls_recover_buf; + rc->rc_result = dlm_recover_status(ls); + goto out; + } + + error = create_rcom(ls, nodeid, DLM_RCOM_STATUS, 0, &rc, &mh); + if (error) + goto out; + + send_rcom(ls, mh, rc); + + error = dlm_wait_function(ls, &rcom_response); + clear_bit(LSFL_RCOM_READY, &ls->ls_flags); + if (error) + goto out; + + rc = (struct dlm_rcom *) ls->ls_recover_buf; + + if (rc->rc_result == -ESRCH) { + /* we pretend the remote lockspace exists with 0 status */ + log_debug(ls, "remote node %d not ready", nodeid); + rc->rc_result = 0; + } else + error = check_config(ls, (struct rcom_config *) rc->rc_buf, + nodeid); + /* the caller looks at rc_result for the remote recovery status */ + out: + return error; +} + +static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in) +{ + struct dlm_rcom *rc; + struct dlm_mhandle *mh; + int error, nodeid = rc_in->rc_header.h_nodeid; + + error = create_rcom(ls, nodeid, DLM_RCOM_STATUS_REPLY, + sizeof(struct rcom_config), &rc, &mh); + if (error) + return; + rc->rc_result = dlm_recover_status(ls); + make_config(ls, (struct rcom_config *) rc->rc_buf); + + send_rcom(ls, mh, rc); +} + +static void receive_rcom_status_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) +{ + memcpy(ls->ls_recover_buf, rc_in, rc_in->rc_header.h_length); + set_bit(LSFL_RCOM_READY, &ls->ls_flags); + wake_up(&ls->ls_wait_general); +} + +int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len) +{ + struct dlm_rcom *rc; + struct dlm_mhandle *mh; + int error = 0, len = sizeof(struct dlm_rcom); + + memset(ls->ls_recover_buf, 0, dlm_config.buffer_size); + + if (nodeid == dlm_our_nodeid()) { + dlm_copy_master_names(ls, last_name, last_len, + ls->ls_recover_buf + len, + dlm_config.buffer_size - len, nodeid); + goto out; + } + + error = create_rcom(ls, nodeid, DLM_RCOM_NAMES, last_len, &rc, &mh); + if (error) + goto out; + memcpy(rc->rc_buf, last_name, last_len); + + send_rcom(ls, mh, rc); + + error = dlm_wait_function(ls, &rcom_response); + clear_bit(LSFL_RCOM_READY, &ls->ls_flags); + out: + return error; +} + +static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in) +{ + struct dlm_rcom *rc; + struct dlm_mhandle *mh; + int error, inlen, outlen; + int nodeid = rc_in->rc_header.h_nodeid; + uint32_t status = dlm_recover_status(ls); + + /* + * We can't run dlm_dir_rebuild_send (which uses ls_nodes) while + * dlm_recoverd is running ls_nodes_reconfig (which changes ls_nodes). + * It could only happen in rare cases where we get a late NAMES + * message from a previous instance of recovery. + */ + + if (!(status & DLM_RS_NODES)) { + log_debug(ls, "ignoring RCOM_NAMES from %u", nodeid); + return; + } + + nodeid = rc_in->rc_header.h_nodeid; + inlen = rc_in->rc_header.h_length - sizeof(struct dlm_rcom); + outlen = dlm_config.buffer_size - sizeof(struct dlm_rcom); + + error = create_rcom(ls, nodeid, DLM_RCOM_NAMES_REPLY, outlen, &rc, &mh); + if (error) + return; + + dlm_copy_master_names(ls, rc_in->rc_buf, inlen, rc->rc_buf, outlen, + nodeid); + send_rcom(ls, mh, rc); +} + +static void receive_rcom_names_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) +{ + memcpy(ls->ls_recover_buf, rc_in, rc_in->rc_header.h_length); + set_bit(LSFL_RCOM_READY, &ls->ls_flags); + wake_up(&ls->ls_wait_general); +} + +int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodeid) +{ + struct dlm_rcom *rc; + struct dlm_mhandle *mh; + struct dlm_ls *ls = r->res_ls; + int error; + + error = create_rcom(ls, dir_nodeid, DLM_RCOM_LOOKUP, r->res_length, + &rc, &mh); + if (error) + goto out; + memcpy(rc->rc_buf, r->res_name, r->res_length); + rc->rc_id = (unsigned long) r; + + send_rcom(ls, mh, rc); + out: + return error; +} + +static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in) +{ + struct dlm_rcom *rc; + struct dlm_mhandle *mh; + int error, ret_nodeid, nodeid = rc_in->rc_header.h_nodeid; + int len = rc_in->rc_header.h_length - sizeof(struct dlm_rcom); + + error = create_rcom(ls, nodeid, DLM_RCOM_LOOKUP_REPLY, 0, &rc, &mh); + if (error) + return; + + error = dlm_dir_lookup(ls, nodeid, rc_in->rc_buf, len, &ret_nodeid); + if (error) + ret_nodeid = error; + rc->rc_result = ret_nodeid; + rc->rc_id = rc_in->rc_id; + + send_rcom(ls, mh, rc); +} + +static void receive_rcom_lookup_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) +{ + dlm_recover_master_reply(ls, rc_in); +} + +static void pack_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb, + struct rcom_lock *rl) +{ + memset(rl, 0, sizeof(*rl)); + + rl->rl_ownpid = lkb->lkb_ownpid; + rl->rl_lkid = lkb->lkb_id; + rl->rl_exflags = lkb->lkb_exflags; + rl->rl_flags = lkb->lkb_flags; + rl->rl_lvbseq = lkb->lkb_lvbseq; + rl->rl_rqmode = lkb->lkb_rqmode; + rl->rl_grmode = lkb->lkb_grmode; + rl->rl_status = lkb->lkb_status; + rl->rl_wait_type = lkb->lkb_wait_type; + + if (lkb->lkb_bastaddr) + rl->rl_asts |= AST_BAST; + if (lkb->lkb_astaddr) + rl->rl_asts |= AST_COMP; + + if (lkb->lkb_range) + memcpy(rl->rl_range, lkb->lkb_range, 4*sizeof(uint64_t)); + + rl->rl_namelen = r->res_length; + memcpy(rl->rl_name, r->res_name, r->res_length); + + /* FIXME: might we have an lvb without DLM_LKF_VALBLK set ? + If so, receive_rcom_lock_args() won't take this copy. */ + + if (lkb->lkb_lvbptr) + memcpy(rl->rl_lvb, lkb->lkb_lvbptr, r->res_ls->ls_lvblen); +} + +int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) +{ + struct dlm_ls *ls = r->res_ls; + struct dlm_rcom *rc; + struct dlm_mhandle *mh; + struct rcom_lock *rl; + int error, len = sizeof(struct rcom_lock); + + if (lkb->lkb_lvbptr) + len += ls->ls_lvblen; + + error = create_rcom(ls, r->res_nodeid, DLM_RCOM_LOCK, len, &rc, &mh); + if (error) + goto out; + + rl = (struct rcom_lock *) rc->rc_buf; + pack_rcom_lock(r, lkb, rl); + rc->rc_id = (unsigned long) r; + + send_rcom(ls, mh, rc); + out: + return error; +} + +static void receive_rcom_lock(struct dlm_ls *ls, struct dlm_rcom *rc_in) +{ + struct dlm_rcom *rc; + struct dlm_mhandle *mh; + int error, nodeid = rc_in->rc_header.h_nodeid; + + dlm_recover_master_copy(ls, rc_in); + + error = create_rcom(ls, nodeid, DLM_RCOM_LOCK_REPLY, + sizeof(struct rcom_lock), &rc, &mh); + if (error) + return; + + /* We send back the same rcom_lock struct we received, but + dlm_recover_master_copy() has filled in rl_remid and rl_result */ + + memcpy(rc->rc_buf, rc_in->rc_buf, sizeof(struct rcom_lock)); + rc->rc_id = rc_in->rc_id; + + send_rcom(ls, mh, rc); +} + +static void receive_rcom_lock_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) +{ + uint32_t status = dlm_recover_status(ls); + + if (!(status & DLM_RS_DIR)) { + log_debug(ls, "ignoring RCOM_LOCK_REPLY from %u", + rc_in->rc_header.h_nodeid); + return; + } + + dlm_recover_process_copy(ls, rc_in); +} + +static int send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in) +{ + struct dlm_rcom *rc; + struct dlm_mhandle *mh; + char *mb; + int mb_len = sizeof(struct dlm_rcom); + + mh = dlm_lowcomms_get_buffer(nodeid, mb_len, GFP_KERNEL, &mb); + if (!mh) + return -ENOBUFS; + memset(mb, 0, mb_len); + + rc = (struct dlm_rcom *) mb; + + rc->rc_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR); + rc->rc_header.h_lockspace = rc_in->rc_header.h_lockspace; + rc->rc_header.h_nodeid = dlm_our_nodeid(); + rc->rc_header.h_length = mb_len; + rc->rc_header.h_cmd = DLM_RCOM; + + rc->rc_type = DLM_RCOM_STATUS_REPLY; + rc->rc_result = -ESRCH; + + dlm_rcom_out(rc); + dlm_lowcomms_commit_buffer(mh); + + return 0; +} + +/* Called by dlm_recvd; corresponds to dlm_receive_message() but special + recovery-only comms are sent through here. */ + +void dlm_receive_rcom(struct dlm_header *hd, int nodeid) +{ + struct dlm_rcom *rc = (struct dlm_rcom *) hd; + struct dlm_ls *ls; + + dlm_rcom_in(rc); + + /* If the lockspace doesn't exist then still send a status message + back; it's possible that it just doesn't have its global_id yet. */ + + ls = dlm_find_lockspace_global(hd->h_lockspace); + if (!ls) { + log_print("lockspace %x from %d not found", + hd->h_lockspace, nodeid); + send_ls_not_ready(nodeid, rc); + return; + } + + if (dlm_recovery_stopped(ls) && (rc->rc_type != DLM_RCOM_STATUS)) { + log_error(ls, "ignoring recovery message %x from %d", + rc->rc_type, nodeid); + goto out; + } + + if (nodeid != rc->rc_header.h_nodeid) { + log_error(ls, "bad rcom nodeid %d from %d", + rc->rc_header.h_nodeid, nodeid); + goto out; + } + + switch (rc->rc_type) { + case DLM_RCOM_STATUS: + receive_rcom_status(ls, rc); + break; + + case DLM_RCOM_NAMES: + receive_rcom_names(ls, rc); + break; + + case DLM_RCOM_LOOKUP: + receive_rcom_lookup(ls, rc); + break; + + case DLM_RCOM_LOCK: + receive_rcom_lock(ls, rc); + break; + + case DLM_RCOM_STATUS_REPLY: + receive_rcom_status_reply(ls, rc); + break; + + case DLM_RCOM_NAMES_REPLY: + receive_rcom_names_reply(ls, rc); + break; + + case DLM_RCOM_LOOKUP_REPLY: + receive_rcom_lookup_reply(ls, rc); + break; + + case DLM_RCOM_LOCK_REPLY: + receive_rcom_lock_reply(ls, rc); + break; + + default: + DLM_ASSERT(0, printk("rc_type=%x\n", rc->rc_type);); + } + out: + dlm_put_lockspace(ls); +} + diff --git a/fs/dlm/rcom.h b/fs/dlm/rcom.h new file mode 100644 index 000000000000..d7984321ff41 --- /dev/null +++ b/fs/dlm/rcom.h @@ -0,0 +1,24 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __RCOM_DOT_H__ +#define __RCOM_DOT_H__ + +int dlm_rcom_status(struct dlm_ls *ls, int nodeid); +int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name,int last_len); +int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodeid); +int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb); +void dlm_receive_rcom(struct dlm_header *hd, int nodeid); + +#endif + diff --git a/fs/dlm/recover.c b/fs/dlm/recover.c new file mode 100644 index 000000000000..1712c97bc229 --- /dev/null +++ b/fs/dlm/recover.c @@ -0,0 +1,762 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "lockspace.h" +#include "dir.h" +#include "config.h" +#include "ast.h" +#include "memory.h" +#include "rcom.h" +#include "lock.h" +#include "lowcomms.h" +#include "member.h" +#include "recover.h" + + +/* + * Recovery waiting routines: these functions wait for a particular reply from + * a remote node, or for the remote node to report a certain status. They need + * to abort if the lockspace is stopped indicating a node has failed (perhaps + * the one being waited for). + */ + +/* + * Wait until given function returns non-zero or lockspace is stopped + * (LS_RECOVERY_STOP set due to failure of a node in ls_nodes). When another + * function thinks it could have completed the waited-on task, they should wake + * up ls_wait_general to get an immediate response rather than waiting for the + * timer to detect the result. A timer wakes us up periodically while waiting + * to see if we should abort due to a node failure. This should only be called + * by the dlm_recoverd thread. + */ + +static void dlm_wait_timer_fn(unsigned long data) +{ + struct dlm_ls *ls = (struct dlm_ls *) data; + mod_timer(&ls->ls_timer, jiffies + (dlm_config.recover_timer * HZ)); + wake_up(&ls->ls_wait_general); +} + +int dlm_wait_function(struct dlm_ls *ls, int (*testfn) (struct dlm_ls *ls)) +{ + int error = 0; + + init_timer(&ls->ls_timer); + ls->ls_timer.function = dlm_wait_timer_fn; + ls->ls_timer.data = (long) ls; + ls->ls_timer.expires = jiffies + (dlm_config.recover_timer * HZ); + add_timer(&ls->ls_timer); + + wait_event(ls->ls_wait_general, testfn(ls) || dlm_recovery_stopped(ls)); + del_timer_sync(&ls->ls_timer); + + if (dlm_recovery_stopped(ls)) { + log_debug(ls, "dlm_wait_function aborted"); + error = -EINTR; + } + return error; +} + +/* + * An efficient way for all nodes to wait for all others to have a certain + * status. The node with the lowest nodeid polls all the others for their + * status (wait_status_all) and all the others poll the node with the low id + * for its accumulated result (wait_status_low). When all nodes have set + * status flag X, then status flag X_ALL will be set on the low nodeid. + */ + +uint32_t dlm_recover_status(struct dlm_ls *ls) +{ + uint32_t status; + spin_lock(&ls->ls_recover_lock); + status = ls->ls_recover_status; + spin_unlock(&ls->ls_recover_lock); + return status; +} + +void dlm_set_recover_status(struct dlm_ls *ls, uint32_t status) +{ + spin_lock(&ls->ls_recover_lock); + ls->ls_recover_status |= status; + spin_unlock(&ls->ls_recover_lock); +} + +static int wait_status_all(struct dlm_ls *ls, uint32_t wait_status) +{ + struct dlm_rcom *rc = (struct dlm_rcom *) ls->ls_recover_buf; + struct dlm_member *memb; + int error = 0, delay; + + list_for_each_entry(memb, &ls->ls_nodes, list) { + delay = 0; + for (;;) { + if (dlm_recovery_stopped(ls)) { + error = -EINTR; + goto out; + } + + error = dlm_rcom_status(ls, memb->nodeid); + if (error) + goto out; + + if (rc->rc_result & wait_status) + break; + if (delay < 1000) + delay += 20; + msleep(delay); + } + } + out: + return error; +} + +static int wait_status_low(struct dlm_ls *ls, uint32_t wait_status) +{ + struct dlm_rcom *rc = (struct dlm_rcom *) ls->ls_recover_buf; + int error = 0, delay = 0, nodeid = ls->ls_low_nodeid; + + for (;;) { + if (dlm_recovery_stopped(ls)) { + error = -EINTR; + goto out; + } + + error = dlm_rcom_status(ls, nodeid); + if (error) + break; + + if (rc->rc_result & wait_status) + break; + if (delay < 1000) + delay += 20; + msleep(delay); + } + out: + return error; +} + +static int wait_status(struct dlm_ls *ls, uint32_t status) +{ + uint32_t status_all = status << 1; + int error; + + if (ls->ls_low_nodeid == dlm_our_nodeid()) { + error = wait_status_all(ls, status); + if (!error) + dlm_set_recover_status(ls, status_all); + } else + error = wait_status_low(ls, status_all); + + return error; +} + +int dlm_recover_members_wait(struct dlm_ls *ls) +{ + return wait_status(ls, DLM_RS_NODES); +} + +int dlm_recover_directory_wait(struct dlm_ls *ls) +{ + return wait_status(ls, DLM_RS_DIR); +} + +int dlm_recover_locks_wait(struct dlm_ls *ls) +{ + return wait_status(ls, DLM_RS_LOCKS); +} + +int dlm_recover_done_wait(struct dlm_ls *ls) +{ + return wait_status(ls, DLM_RS_DONE); +} + +/* + * The recover_list contains all the rsb's for which we've requested the new + * master nodeid. As replies are returned from the resource directories the + * rsb's are removed from the list. When the list is empty we're done. + * + * The recover_list is later similarly used for all rsb's for which we've sent + * new lkb's and need to receive new corresponding lkid's. + * + * We use the address of the rsb struct as a simple local identifier for the + * rsb so we can match an rcom reply with the rsb it was sent for. + */ + +static int recover_list_empty(struct dlm_ls *ls) +{ + int empty; + + spin_lock(&ls->ls_recover_list_lock); + empty = list_empty(&ls->ls_recover_list); + spin_unlock(&ls->ls_recover_list_lock); + + return empty; +} + +static void recover_list_add(struct dlm_rsb *r) +{ + struct dlm_ls *ls = r->res_ls; + + spin_lock(&ls->ls_recover_list_lock); + if (list_empty(&r->res_recover_list)) { + list_add_tail(&r->res_recover_list, &ls->ls_recover_list); + ls->ls_recover_list_count++; + dlm_hold_rsb(r); + } + spin_unlock(&ls->ls_recover_list_lock); +} + +static void recover_list_del(struct dlm_rsb *r) +{ + struct dlm_ls *ls = r->res_ls; + + spin_lock(&ls->ls_recover_list_lock); + list_del_init(&r->res_recover_list); + ls->ls_recover_list_count--; + spin_unlock(&ls->ls_recover_list_lock); + + dlm_put_rsb(r); +} + +static struct dlm_rsb *recover_list_find(struct dlm_ls *ls, uint64_t id) +{ + struct dlm_rsb *r = NULL; + + spin_lock(&ls->ls_recover_list_lock); + + list_for_each_entry(r, &ls->ls_recover_list, res_recover_list) { + if (id == (unsigned long) r) + goto out; + } + r = NULL; + out: + spin_unlock(&ls->ls_recover_list_lock); + return r; +} + +static void recover_list_clear(struct dlm_ls *ls) +{ + struct dlm_rsb *r, *s; + + spin_lock(&ls->ls_recover_list_lock); + list_for_each_entry_safe(r, s, &ls->ls_recover_list, res_recover_list) { + list_del_init(&r->res_recover_list); + dlm_put_rsb(r); + ls->ls_recover_list_count--; + } + + if (ls->ls_recover_list_count != 0) { + log_error(ls, "warning: recover_list_count %d", + ls->ls_recover_list_count); + ls->ls_recover_list_count = 0; + } + spin_unlock(&ls->ls_recover_list_lock); +} + + +/* Master recovery: find new master node for rsb's that were + mastered on nodes that have been removed. + + dlm_recover_masters + recover_master + dlm_send_rcom_lookup -> receive_rcom_lookup + dlm_dir_lookup + receive_rcom_lookup_reply <- + dlm_recover_master_reply + set_new_master + set_master_lkbs + set_lock_master +*/ + +/* + * Set the lock master for all LKBs in a lock queue + * If we are the new master of the rsb, we may have received new + * MSTCPY locks from other nodes already which we need to ignore + * when setting the new nodeid. + */ + +static void set_lock_master(struct list_head *queue, int nodeid) +{ + struct dlm_lkb *lkb; + + list_for_each_entry(lkb, queue, lkb_statequeue) + if (!(lkb->lkb_flags & DLM_IFL_MSTCPY)) + lkb->lkb_nodeid = nodeid; +} + +static void set_master_lkbs(struct dlm_rsb *r) +{ + set_lock_master(&r->res_grantqueue, r->res_nodeid); + set_lock_master(&r->res_convertqueue, r->res_nodeid); + set_lock_master(&r->res_waitqueue, r->res_nodeid); +} + +/* + * Propogate the new master nodeid to locks + * The NEW_MASTER flag tells dlm_recover_locks() which rsb's to consider. + * The NEW_MASTER2 flag tells recover_lvb() which rsb's to consider. + */ + +static void set_new_master(struct dlm_rsb *r, int nodeid) +{ + lock_rsb(r); + r->res_nodeid = nodeid; + set_master_lkbs(r); + rsb_set_flag(r, RSB_NEW_MASTER); + rsb_set_flag(r, RSB_NEW_MASTER2); + unlock_rsb(r); +} + +/* + * We do async lookups on rsb's that need new masters. The rsb's + * waiting for a lookup reply are kept on the recover_list. + */ + +static int recover_master(struct dlm_rsb *r) +{ + struct dlm_ls *ls = r->res_ls; + int error, dir_nodeid, ret_nodeid, our_nodeid = dlm_our_nodeid(); + + dir_nodeid = dlm_dir_nodeid(r); + + if (dir_nodeid == our_nodeid) { + error = dlm_dir_lookup(ls, our_nodeid, r->res_name, + r->res_length, &ret_nodeid); + if (error) + log_error(ls, "recover dir lookup error %d", error); + + if (ret_nodeid == our_nodeid) + ret_nodeid = 0; + set_new_master(r, ret_nodeid); + } else { + recover_list_add(r); + error = dlm_send_rcom_lookup(r, dir_nodeid); + } + + return error; +} + +/* + * When not using a directory, most resource names will hash to a new static + * master nodeid and the resource will need to be remastered. + */ + +static int recover_master_static(struct dlm_rsb *r) +{ + int master = dlm_dir_nodeid(r); + + if (master == dlm_our_nodeid()) + master = 0; + + if (r->res_nodeid != master) { + if (is_master(r)) + dlm_purge_mstcpy_locks(r); + set_new_master(r, master); + return 1; + } + return 0; +} + +/* + * Go through local root resources and for each rsb which has a master which + * has departed, get the new master nodeid from the directory. The dir will + * assign mastery to the first node to look up the new master. That means + * we'll discover in this lookup if we're the new master of any rsb's. + * + * We fire off all the dir lookup requests individually and asynchronously to + * the correct dir node. + */ + +int dlm_recover_masters(struct dlm_ls *ls) +{ + struct dlm_rsb *r; + int error = 0, count = 0; + + log_debug(ls, "dlm_recover_masters"); + + down_read(&ls->ls_root_sem); + list_for_each_entry(r, &ls->ls_root_list, res_root_list) { + if (dlm_recovery_stopped(ls)) { + up_read(&ls->ls_root_sem); + error = -EINTR; + goto out; + } + + if (dlm_no_directory(ls)) + count += recover_master_static(r); + else if (!is_master(r) && dlm_is_removed(ls, r->res_nodeid)) { + recover_master(r); + count++; + } + + schedule(); + } + up_read(&ls->ls_root_sem); + + log_debug(ls, "dlm_recover_masters %d resources", count); + + error = dlm_wait_function(ls, &recover_list_empty); + out: + if (error) + recover_list_clear(ls); + return error; +} + +int dlm_recover_master_reply(struct dlm_ls *ls, struct dlm_rcom *rc) +{ + struct dlm_rsb *r; + int nodeid; + + r = recover_list_find(ls, rc->rc_id); + if (!r) { + log_error(ls, "dlm_recover_master_reply no id %"PRIx64"", + rc->rc_id); + goto out; + } + + nodeid = rc->rc_result; + if (nodeid == dlm_our_nodeid()) + nodeid = 0; + + set_new_master(r, nodeid); + recover_list_del(r); + + if (recover_list_empty(ls)) + wake_up(&ls->ls_wait_general); + out: + return 0; +} + + +/* Lock recovery: rebuild the process-copy locks we hold on a + remastered rsb on the new rsb master. + + dlm_recover_locks + recover_locks + recover_locks_queue + dlm_send_rcom_lock -> receive_rcom_lock + dlm_recover_master_copy + receive_rcom_lock_reply <- + dlm_recover_process_copy +*/ + + +/* + * keep a count of the number of lkb's we send to the new master; when we get + * an equal number of replies then recovery for the rsb is done + */ + +static int recover_locks_queue(struct dlm_rsb *r, struct list_head *head) +{ + struct dlm_lkb *lkb; + int error = 0; + + list_for_each_entry(lkb, head, lkb_statequeue) { + error = dlm_send_rcom_lock(r, lkb); + if (error) + break; + r->res_recover_locks_count++; + } + + return error; +} + +static int all_queues_empty(struct dlm_rsb *r) +{ + if (!list_empty(&r->res_grantqueue) || + !list_empty(&r->res_convertqueue) || + !list_empty(&r->res_waitqueue)) + return FALSE; + return TRUE; +} + +static int recover_locks(struct dlm_rsb *r) +{ + int error = 0; + + lock_rsb(r); + if (all_queues_empty(r)) + goto out; + + DLM_ASSERT(!r->res_recover_locks_count, dlm_print_rsb(r);); + + error = recover_locks_queue(r, &r->res_grantqueue); + if (error) + goto out; + error = recover_locks_queue(r, &r->res_convertqueue); + if (error) + goto out; + error = recover_locks_queue(r, &r->res_waitqueue); + if (error) + goto out; + + if (r->res_recover_locks_count) + recover_list_add(r); + else + rsb_clear_flag(r, RSB_NEW_MASTER); + out: + unlock_rsb(r); + return error; +} + +int dlm_recover_locks(struct dlm_ls *ls) +{ + struct dlm_rsb *r; + int error, count = 0; + + log_debug(ls, "dlm_recover_locks"); + + down_read(&ls->ls_root_sem); + list_for_each_entry(r, &ls->ls_root_list, res_root_list) { + if (is_master(r)) { + rsb_clear_flag(r, RSB_NEW_MASTER); + continue; + } + + if (!rsb_flag(r, RSB_NEW_MASTER)) + continue; + + if (dlm_recovery_stopped(ls)) { + error = -EINTR; + up_read(&ls->ls_root_sem); + goto out; + } + + error = recover_locks(r); + if (error) { + up_read(&ls->ls_root_sem); + goto out; + } + + count += r->res_recover_locks_count; + } + up_read(&ls->ls_root_sem); + + log_debug(ls, "dlm_recover_locks %d locks", count); + + error = dlm_wait_function(ls, &recover_list_empty); + out: + if (error) + recover_list_clear(ls); + else + dlm_set_recover_status(ls, DLM_RS_LOCKS); + return error; +} + +void dlm_recovered_lock(struct dlm_rsb *r) +{ + DLM_ASSERT(rsb_flag(r, RSB_NEW_MASTER), dlm_print_rsb(r);); + + r->res_recover_locks_count--; + if (!r->res_recover_locks_count) { + rsb_clear_flag(r, RSB_NEW_MASTER); + recover_list_del(r); + } + + if (recover_list_empty(r->res_ls)) + wake_up(&r->res_ls->ls_wait_general); +} + +/* + * The lvb needs to be recovered on all master rsb's. This includes setting + * the VALNOTVALID flag if necessary, and determining the correct lvb contents + * based on the lvb's of the locks held on the rsb. + * + * RSB_VALNOTVALID is set if there are only NL/CR locks on the rsb. If it + * was already set prior to recovery, it's not cleared, regardless of locks. + * + * The LVB contents are only considered for changing when this is a new master + * of the rsb (NEW_MASTER2). Then, the rsb's lvb is taken from any lkb with + * mode > CR. If no lkb's exist with mode above CR, the lvb contents are taken + * from the lkb with the largest lvb sequence number. + */ + +static void recover_lvb(struct dlm_rsb *r) +{ + struct dlm_lkb *lkb, *high_lkb = NULL; + uint32_t high_seq = 0; + int lock_lvb_exists = FALSE; + int big_lock_exists = FALSE; + int lvblen = r->res_ls->ls_lvblen; + + list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) { + if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) + continue; + + lock_lvb_exists = TRUE; + + if (lkb->lkb_grmode > DLM_LOCK_CR) { + big_lock_exists = TRUE; + goto setflag; + } + + if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) { + high_lkb = lkb; + high_seq = lkb->lkb_lvbseq; + } + } + + list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) { + if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) + continue; + + lock_lvb_exists = TRUE; + + if (lkb->lkb_grmode > DLM_LOCK_CR) { + big_lock_exists = TRUE; + goto setflag; + } + + if (((int)lkb->lkb_lvbseq - (int)high_seq) >= 0) { + high_lkb = lkb; + high_seq = lkb->lkb_lvbseq; + } + } + + setflag: + if (!lock_lvb_exists) + goto out; + + if (!big_lock_exists) + rsb_set_flag(r, RSB_VALNOTVALID); + + /* don't mess with the lvb unless we're the new master */ + if (!rsb_flag(r, RSB_NEW_MASTER2)) + goto out; + + if (!r->res_lvbptr) { + r->res_lvbptr = allocate_lvb(r->res_ls); + if (!r->res_lvbptr) + goto out; + } + + if (big_lock_exists) { + r->res_lvbseq = lkb->lkb_lvbseq; + memcpy(r->res_lvbptr, lkb->lkb_lvbptr, lvblen); + } else if (high_lkb) { + r->res_lvbseq = high_lkb->lkb_lvbseq; + memcpy(r->res_lvbptr, high_lkb->lkb_lvbptr, lvblen); + } else { + r->res_lvbseq = 0; + memset(r->res_lvbptr, 0, lvblen); + } + out: + return; +} + +/* All master rsb's flagged RECOVER_CONVERT need to be looked at. The locks + converting PR->CW or CW->PR need to have their lkb_grmode set. */ + +static void recover_conversion(struct dlm_rsb *r) +{ + struct dlm_lkb *lkb; + int grmode = -1; + + list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) { + if (lkb->lkb_grmode == DLM_LOCK_PR || + lkb->lkb_grmode == DLM_LOCK_CW) { + grmode = lkb->lkb_grmode; + break; + } + } + + list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) { + if (lkb->lkb_grmode != DLM_LOCK_IV) + continue; + if (grmode == -1) + lkb->lkb_grmode = lkb->lkb_rqmode; + else + lkb->lkb_grmode = grmode; + } +} + +void dlm_recover_rsbs(struct dlm_ls *ls) +{ + struct dlm_rsb *r; + int count = 0; + + log_debug(ls, "dlm_recover_rsbs"); + + down_read(&ls->ls_root_sem); + list_for_each_entry(r, &ls->ls_root_list, res_root_list) { + lock_rsb(r); + if (is_master(r)) { + if (rsb_flag(r, RSB_RECOVER_CONVERT)) + recover_conversion(r); + recover_lvb(r); + count++; + } + rsb_clear_flag(r, RSB_RECOVER_CONVERT); + unlock_rsb(r); + } + up_read(&ls->ls_root_sem); + + log_debug(ls, "dlm_recover_rsbs %d rsbs", count); +} + +/* Create a single list of all root rsb's to be used during recovery */ + +int dlm_create_root_list(struct dlm_ls *ls) +{ + struct dlm_rsb *r; + int i, error = 0; + + down_write(&ls->ls_root_sem); + if (!list_empty(&ls->ls_root_list)) { + log_error(ls, "root list not empty"); + error = -EINVAL; + goto out; + } + + for (i = 0; i < ls->ls_rsbtbl_size; i++) { + read_lock(&ls->ls_rsbtbl[i].lock); + list_for_each_entry(r, &ls->ls_rsbtbl[i].list, res_hashchain) { + list_add(&r->res_root_list, &ls->ls_root_list); + dlm_hold_rsb(r); + } + read_unlock(&ls->ls_rsbtbl[i].lock); + } + out: + up_write(&ls->ls_root_sem); + return error; +} + +void dlm_release_root_list(struct dlm_ls *ls) +{ + struct dlm_rsb *r, *safe; + + down_write(&ls->ls_root_sem); + list_for_each_entry_safe(r, safe, &ls->ls_root_list, res_root_list) { + list_del_init(&r->res_root_list); + dlm_put_rsb(r); + } + up_write(&ls->ls_root_sem); +} + +void dlm_clear_toss_list(struct dlm_ls *ls) +{ + struct dlm_rsb *r, *safe; + int i; + + for (i = 0; i < ls->ls_rsbtbl_size; i++) { + write_lock(&ls->ls_rsbtbl[i].lock); + list_for_each_entry_safe(r, safe, &ls->ls_rsbtbl[i].toss, + res_hashchain) { + list_del(&r->res_hashchain); + free_rsb(r); + } + write_unlock(&ls->ls_rsbtbl[i].lock); + } +} + diff --git a/fs/dlm/recover.h b/fs/dlm/recover.h new file mode 100644 index 000000000000..ebd0363f1e08 --- /dev/null +++ b/fs/dlm/recover.h @@ -0,0 +1,34 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __RECOVER_DOT_H__ +#define __RECOVER_DOT_H__ + +int dlm_wait_function(struct dlm_ls *ls, int (*testfn) (struct dlm_ls *ls)); +uint32_t dlm_recover_status(struct dlm_ls *ls); +void dlm_set_recover_status(struct dlm_ls *ls, uint32_t status); +int dlm_recover_members_wait(struct dlm_ls *ls); +int dlm_recover_directory_wait(struct dlm_ls *ls); +int dlm_recover_locks_wait(struct dlm_ls *ls); +int dlm_recover_done_wait(struct dlm_ls *ls); +int dlm_recover_masters(struct dlm_ls *ls); +int dlm_recover_master_reply(struct dlm_ls *ls, struct dlm_rcom *rc); +int dlm_recover_locks(struct dlm_ls *ls); +void dlm_recovered_lock(struct dlm_rsb *r); +int dlm_create_root_list(struct dlm_ls *ls); +void dlm_release_root_list(struct dlm_ls *ls); +void dlm_clear_toss_list(struct dlm_ls *ls); +void dlm_recover_rsbs(struct dlm_ls *ls); + +#endif /* __RECOVER_DOT_H__ */ + diff --git a/fs/dlm/recoverd.c b/fs/dlm/recoverd.c new file mode 100644 index 000000000000..06e4f7cab6e7 --- /dev/null +++ b/fs/dlm/recoverd.c @@ -0,0 +1,285 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "lockspace.h" +#include "member.h" +#include "dir.h" +#include "ast.h" +#include "recover.h" +#include "lowcomms.h" +#include "lock.h" +#include "requestqueue.h" +#include "recoverd.h" + + +/* If the start for which we're re-enabling locking (seq) has been superseded + by a newer stop (ls_recover_seq), we need to leave locking disabled. */ + +static int enable_locking(struct dlm_ls *ls, uint64_t seq) +{ + int error = -EINTR; + + spin_lock(&ls->ls_recover_lock); + if (ls->ls_recover_seq == seq) { + set_bit(LSFL_RUNNING, &ls->ls_flags); + up_write(&ls->ls_in_recovery); + error = 0; + } + spin_unlock(&ls->ls_recover_lock); + return error; +} + +static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv) +{ + unsigned long start; + int error, neg = 0; + + log_debug(ls, "recover %"PRIx64"", rv->seq); + + down(&ls->ls_recoverd_active); + + /* + * Suspending and resuming dlm_astd ensures that no lkb's from this ls + * will be processed by dlm_astd during recovery. + */ + + dlm_astd_suspend(); + dlm_astd_resume(); + + /* + * This list of root rsb's will be the basis of most of the recovery + * routines. + */ + + dlm_create_root_list(ls); + + /* + * Free all the tossed rsb's so we don't have to recover them. + */ + + dlm_clear_toss_list(ls); + + /* + * Add or remove nodes from the lockspace's ls_nodes list. + * Also waits for all nodes to complete dlm_recover_members. + */ + + error = dlm_recover_members(ls, rv, &neg); + if (error) { + log_error(ls, "recover_members failed %d", error); + goto fail; + } + start = jiffies; + + /* + * Rebuild our own share of the directory by collecting from all other + * nodes their master rsb names that hash to us. + */ + + error = dlm_recover_directory(ls); + if (error) { + log_error(ls, "recover_directory failed %d", error); + goto fail; + } + + /* + * Purge directory-related requests that are saved in requestqueue. + * All dir requests from before recovery are invalid now due to the dir + * rebuild and will be resent by the requesting nodes. + */ + + dlm_purge_requestqueue(ls); + + /* + * Wait for all nodes to complete directory rebuild. + */ + + error = dlm_recover_directory_wait(ls); + if (error) { + log_error(ls, "recover_directory_wait failed %d", error); + goto fail; + } + + /* + * We may have outstanding operations that are waiting for a reply from + * a failed node. Mark these to be resent after recovery. Unlock and + * cancel ops can just be completed. + */ + + dlm_recover_waiters_pre(ls); + + error = dlm_recovery_stopped(ls); + if (error) + goto fail; + + if (neg || dlm_no_directory(ls)) { + /* + * Clear lkb's for departed nodes. + */ + + dlm_purge_locks(ls); + + /* + * Get new master nodeid's for rsb's that were mastered on + * departed nodes. + */ + + error = dlm_recover_masters(ls); + if (error) { + log_error(ls, "recover_masters failed %d", error); + goto fail; + } + + /* + * Send our locks on remastered rsb's to the new masters. + */ + + error = dlm_recover_locks(ls); + if (error) { + log_error(ls, "recover_locks failed %d", error); + goto fail; + } + + error = dlm_recover_locks_wait(ls); + if (error) { + log_error(ls, "recover_locks_wait failed %d", error); + goto fail; + } + + /* + * Finalize state in master rsb's now that all locks can be + * checked. This includes conversion resolution and lvb + * settings. + */ + + dlm_recover_rsbs(ls); + } + + dlm_release_root_list(ls); + + dlm_set_recover_status(ls, DLM_RS_DONE); + error = dlm_recover_done_wait(ls); + if (error) { + log_error(ls, "recover_done_wait failed %d", error); + goto fail; + } + + dlm_clear_members_gone(ls); + + error = enable_locking(ls, rv->seq); + if (error) { + log_error(ls, "enable_locking failed %d", error); + goto fail; + } + + error = dlm_process_requestqueue(ls); + if (error) { + log_error(ls, "process_requestqueue failed %d", error); + goto fail; + } + + error = dlm_recover_waiters_post(ls); + if (error) { + log_error(ls, "recover_waiters_post failed %d", error); + goto fail; + } + + dlm_grant_after_purge(ls); + + dlm_astd_wake(); + + log_debug(ls, "recover %"PRIx64" done: %u ms", rv->seq, + jiffies_to_msecs(jiffies - start)); + up(&ls->ls_recoverd_active); + + return 0; + + fail: + dlm_release_root_list(ls); + log_debug(ls, "recover %"PRIx64" error %d", rv->seq, error); + up(&ls->ls_recoverd_active); + return error; +} + +static void do_ls_recovery(struct dlm_ls *ls) +{ + struct dlm_recover *rv = NULL; + + spin_lock(&ls->ls_recover_lock); + rv = ls->ls_recover_args; + ls->ls_recover_args = NULL; + clear_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); + spin_unlock(&ls->ls_recover_lock); + + if (rv) { + ls_recover(ls, rv); + kfree(rv->nodeids); + kfree(rv); + } +} + +static int dlm_recoverd(void *arg) +{ + struct dlm_ls *ls; + + ls = dlm_find_lockspace_local(arg); + + while (!kthread_should_stop()) { + set_current_state(TASK_INTERRUPTIBLE); + if (!test_bit(LSFL_WORK, &ls->ls_flags)) + schedule(); + set_current_state(TASK_RUNNING); + + if (test_and_clear_bit(LSFL_WORK, &ls->ls_flags)) + do_ls_recovery(ls); + } + + dlm_put_lockspace(ls); + return 0; +} + +void dlm_recoverd_kick(struct dlm_ls *ls) +{ + set_bit(LSFL_WORK, &ls->ls_flags); + wake_up_process(ls->ls_recoverd_task); +} + +int dlm_recoverd_start(struct dlm_ls *ls) +{ + struct task_struct *p; + int error = 0; + + p = kthread_run(dlm_recoverd, ls, "dlm_recoverd"); + if (IS_ERR(p)) + error = PTR_ERR(p); + else + ls->ls_recoverd_task = p; + return error; +} + +void dlm_recoverd_stop(struct dlm_ls *ls) +{ + kthread_stop(ls->ls_recoverd_task); +} + +void dlm_recoverd_suspend(struct dlm_ls *ls) +{ + down(&ls->ls_recoverd_active); +} + +void dlm_recoverd_resume(struct dlm_ls *ls) +{ + up(&ls->ls_recoverd_active); +} + diff --git a/fs/dlm/recoverd.h b/fs/dlm/recoverd.h new file mode 100644 index 000000000000..866657c5d69d --- /dev/null +++ b/fs/dlm/recoverd.h @@ -0,0 +1,24 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __RECOVERD_DOT_H__ +#define __RECOVERD_DOT_H__ + +void dlm_recoverd_kick(struct dlm_ls *ls); +void dlm_recoverd_stop(struct dlm_ls *ls); +int dlm_recoverd_start(struct dlm_ls *ls); +void dlm_recoverd_suspend(struct dlm_ls *ls); +void dlm_recoverd_resume(struct dlm_ls *ls); + +#endif /* __RECOVERD_DOT_H__ */ + diff --git a/fs/dlm/requestqueue.c b/fs/dlm/requestqueue.c new file mode 100644 index 000000000000..36afe99e4f93 --- /dev/null +++ b/fs/dlm/requestqueue.c @@ -0,0 +1,184 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "member.h" +#include "lock.h" +#include "dir.h" +#include "config.h" +#include "requestqueue.h" + +struct rq_entry { + struct list_head list; + int nodeid; + char request[1]; +}; + +/* + * Requests received while the lockspace is in recovery get added to the + * request queue and processed when recovery is complete. This happens when + * the lockspace is suspended on some nodes before it is on others, or the + * lockspace is enabled on some while still suspended on others. + */ + +void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, struct dlm_header *hd) +{ + struct rq_entry *e; + int length = hd->h_length; + + if (dlm_is_removed(ls, nodeid)) + return; + + e = kmalloc(sizeof(struct rq_entry) + length, GFP_KERNEL); + if (!e) { + log_print("dlm_add_requestqueue: out of memory\n"); + return; + } + + e->nodeid = nodeid; + memcpy(e->request, hd, length); + + down(&ls->ls_requestqueue_lock); + list_add_tail(&e->list, &ls->ls_requestqueue); + up(&ls->ls_requestqueue_lock); +} + +int dlm_process_requestqueue(struct dlm_ls *ls) +{ + struct rq_entry *e; + struct dlm_header *hd; + int error = 0; + + down(&ls->ls_requestqueue_lock); + + for (;;) { + if (list_empty(&ls->ls_requestqueue)) { + up(&ls->ls_requestqueue_lock); + error = 0; + break; + } + e = list_entry(ls->ls_requestqueue.next, struct rq_entry, list); + up(&ls->ls_requestqueue_lock); + + hd = (struct dlm_header *) e->request; + error = dlm_receive_message(hd, e->nodeid, TRUE); + + if (error == -EINTR) { + /* entry is left on requestqueue */ + log_debug(ls, "process_requestqueue abort eintr"); + break; + } + + down(&ls->ls_requestqueue_lock); + list_del(&e->list); + kfree(e); + + if (dlm_locking_stopped(ls)) { + log_debug(ls, "process_requestqueue abort running"); + up(&ls->ls_requestqueue_lock); + error = -EINTR; + break; + } + schedule(); + } + + return error; +} + +/* + * After recovery is done, locking is resumed and dlm_recoverd takes all the + * saved requests and processes them as they would have been by dlm_recvd. At + * the same time, dlm_recvd will start receiving new requests from remote + * nodes. We want to delay dlm_recvd processing new requests until + * dlm_recoverd has finished processing the old saved requests. + */ + +void dlm_wait_requestqueue(struct dlm_ls *ls) +{ + for (;;) { + down(&ls->ls_requestqueue_lock); + if (list_empty(&ls->ls_requestqueue)) + break; + if (dlm_locking_stopped(ls)) + break; + up(&ls->ls_requestqueue_lock); + schedule(); + } + up(&ls->ls_requestqueue_lock); +} + +static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid) +{ + uint32_t type = ms->m_type; + + if (dlm_is_removed(ls, nodeid)) + return 1; + + /* directory operations are always purged because the directory is + always rebuilt during recovery and the lookups resent */ + + if (type == DLM_MSG_REMOVE || + type == DLM_MSG_LOOKUP || + type == DLM_MSG_LOOKUP_REPLY) + return 1; + + if (!dlm_no_directory(ls)) + return 0; + + /* with no directory, the master is likely to change as a part of + recovery; requests to/from the defunct master need to be purged */ + + switch (type) { + case DLM_MSG_REQUEST: + case DLM_MSG_CONVERT: + case DLM_MSG_UNLOCK: + case DLM_MSG_CANCEL: + /* we're no longer the master of this resource, the sender + will resend to the new master (see waiter_needs_recovery) */ + + if (dlm_hash2nodeid(ls, ms->m_hash) != dlm_our_nodeid()) + return 1; + break; + + case DLM_MSG_REQUEST_REPLY: + case DLM_MSG_CONVERT_REPLY: + case DLM_MSG_UNLOCK_REPLY: + case DLM_MSG_CANCEL_REPLY: + case DLM_MSG_GRANT: + /* this reply is from the former master of the resource, + we'll resend to the new master if needed */ + + if (dlm_hash2nodeid(ls, ms->m_hash) != nodeid) + return 1; + break; + } + + return 0; +} + +void dlm_purge_requestqueue(struct dlm_ls *ls) +{ + struct dlm_message *ms; + struct rq_entry *e, *safe; + + down(&ls->ls_requestqueue_lock); + list_for_each_entry_safe(e, safe, &ls->ls_requestqueue, list) { + ms = (struct dlm_message *) e->request; + + if (purge_request(ls, ms, e->nodeid)) { + list_del(&e->list); + kfree(e); + } + } + up(&ls->ls_requestqueue_lock); +} + diff --git a/fs/dlm/requestqueue.h b/fs/dlm/requestqueue.h new file mode 100644 index 000000000000..349f0d292d95 --- /dev/null +++ b/fs/dlm/requestqueue.h @@ -0,0 +1,22 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __REQUESTQUEUE_DOT_H__ +#define __REQUESTQUEUE_DOT_H__ + +void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, struct dlm_header *hd); +int dlm_process_requestqueue(struct dlm_ls *ls); +void dlm_wait_requestqueue(struct dlm_ls *ls); +void dlm_purge_requestqueue(struct dlm_ls *ls); + +#endif + diff --git a/fs/dlm/util.c b/fs/dlm/util.c new file mode 100644 index 000000000000..826d122edf55 --- /dev/null +++ b/fs/dlm/util.c @@ -0,0 +1,173 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include "dlm_internal.h" +#include "rcom.h" +#include "util.h" + +static void header_out(struct dlm_header *hd) +{ + hd->h_version = cpu_to_le32(hd->h_version); + hd->h_lockspace = cpu_to_le32(hd->h_lockspace); + hd->h_nodeid = cpu_to_le32(hd->h_nodeid); + hd->h_length = cpu_to_le16(hd->h_length); +} + +static void header_in(struct dlm_header *hd) +{ + hd->h_version = le32_to_cpu(hd->h_version); + hd->h_lockspace = le32_to_cpu(hd->h_lockspace); + hd->h_nodeid = le32_to_cpu(hd->h_nodeid); + hd->h_length = le16_to_cpu(hd->h_length); +} + +void dlm_message_out(struct dlm_message *ms) +{ + struct dlm_header *hd = (struct dlm_header *) ms; + + header_out(hd); + + ms->m_type = cpu_to_le32(ms->m_type); + ms->m_nodeid = cpu_to_le32(ms->m_nodeid); + ms->m_pid = cpu_to_le32(ms->m_pid); + ms->m_lkid = cpu_to_le32(ms->m_lkid); + ms->m_remid = cpu_to_le32(ms->m_remid); + ms->m_parent_lkid = cpu_to_le32(ms->m_parent_lkid); + ms->m_parent_remid = cpu_to_le32(ms->m_parent_remid); + ms->m_exflags = cpu_to_le32(ms->m_exflags); + ms->m_sbflags = cpu_to_le32(ms->m_sbflags); + ms->m_flags = cpu_to_le32(ms->m_flags); + ms->m_lvbseq = cpu_to_le32(ms->m_lvbseq); + ms->m_hash = cpu_to_le32(ms->m_hash); + ms->m_status = cpu_to_le32(ms->m_status); + ms->m_grmode = cpu_to_le32(ms->m_grmode); + ms->m_rqmode = cpu_to_le32(ms->m_rqmode); + ms->m_bastmode = cpu_to_le32(ms->m_bastmode); + ms->m_asts = cpu_to_le32(ms->m_asts); + ms->m_result = cpu_to_le32(ms->m_result); + ms->m_range[0] = cpu_to_le64(ms->m_range[0]); + ms->m_range[1] = cpu_to_le64(ms->m_range[1]); +} + +void dlm_message_in(struct dlm_message *ms) +{ + struct dlm_header *hd = (struct dlm_header *) ms; + + header_in(hd); + + ms->m_type = le32_to_cpu(ms->m_type); + ms->m_nodeid = le32_to_cpu(ms->m_nodeid); + ms->m_pid = le32_to_cpu(ms->m_pid); + ms->m_lkid = le32_to_cpu(ms->m_lkid); + ms->m_remid = le32_to_cpu(ms->m_remid); + ms->m_parent_lkid = le32_to_cpu(ms->m_parent_lkid); + ms->m_parent_remid = le32_to_cpu(ms->m_parent_remid); + ms->m_exflags = le32_to_cpu(ms->m_exflags); + ms->m_sbflags = le32_to_cpu(ms->m_sbflags); + ms->m_flags = le32_to_cpu(ms->m_flags); + ms->m_lvbseq = le32_to_cpu(ms->m_lvbseq); + ms->m_hash = le32_to_cpu(ms->m_hash); + ms->m_status = le32_to_cpu(ms->m_status); + ms->m_grmode = le32_to_cpu(ms->m_grmode); + ms->m_rqmode = le32_to_cpu(ms->m_rqmode); + ms->m_bastmode = le32_to_cpu(ms->m_bastmode); + ms->m_asts = le32_to_cpu(ms->m_asts); + ms->m_result = le32_to_cpu(ms->m_result); + ms->m_range[0] = le64_to_cpu(ms->m_range[0]); + ms->m_range[1] = le64_to_cpu(ms->m_range[1]); +} + +static void rcom_lock_out(struct rcom_lock *rl) +{ + rl->rl_ownpid = cpu_to_le32(rl->rl_ownpid); + rl->rl_lkid = cpu_to_le32(rl->rl_lkid); + rl->rl_remid = cpu_to_le32(rl->rl_remid); + rl->rl_parent_lkid = cpu_to_le32(rl->rl_parent_lkid); + rl->rl_parent_remid = cpu_to_le32(rl->rl_parent_remid); + rl->rl_exflags = cpu_to_le32(rl->rl_exflags); + rl->rl_flags = cpu_to_le32(rl->rl_flags); + rl->rl_lvbseq = cpu_to_le32(rl->rl_lvbseq); + rl->rl_result = cpu_to_le32(rl->rl_result); + rl->rl_wait_type = cpu_to_le16(rl->rl_wait_type); + rl->rl_namelen = cpu_to_le16(rl->rl_namelen); + rl->rl_range[0] = cpu_to_le64(rl->rl_range[0]); + rl->rl_range[1] = cpu_to_le64(rl->rl_range[1]); + rl->rl_range[2] = cpu_to_le64(rl->rl_range[2]); + rl->rl_range[3] = cpu_to_le64(rl->rl_range[3]); +} + +static void rcom_lock_in(struct rcom_lock *rl) +{ + rl->rl_ownpid = le32_to_cpu(rl->rl_ownpid); + rl->rl_lkid = le32_to_cpu(rl->rl_lkid); + rl->rl_remid = le32_to_cpu(rl->rl_remid); + rl->rl_parent_lkid = le32_to_cpu(rl->rl_parent_lkid); + rl->rl_parent_remid = le32_to_cpu(rl->rl_parent_remid); + rl->rl_exflags = le32_to_cpu(rl->rl_exflags); + rl->rl_flags = le32_to_cpu(rl->rl_flags); + rl->rl_lvbseq = le32_to_cpu(rl->rl_lvbseq); + rl->rl_result = le32_to_cpu(rl->rl_result); + rl->rl_wait_type = le16_to_cpu(rl->rl_wait_type); + rl->rl_namelen = le16_to_cpu(rl->rl_namelen); + rl->rl_range[0] = le64_to_cpu(rl->rl_range[0]); + rl->rl_range[1] = le64_to_cpu(rl->rl_range[1]); + rl->rl_range[2] = le64_to_cpu(rl->rl_range[2]); + rl->rl_range[3] = le64_to_cpu(rl->rl_range[3]); +} + +static void rcom_config_out(struct rcom_config *rf) +{ + rf->rf_lvblen = cpu_to_le32(rf->rf_lvblen); + rf->rf_lsflags = cpu_to_le32(rf->rf_lsflags); +} + +static void rcom_config_in(struct rcom_config *rf) +{ + rf->rf_lvblen = le32_to_cpu(rf->rf_lvblen); + rf->rf_lsflags = le32_to_cpu(rf->rf_lsflags); +} + +void dlm_rcom_out(struct dlm_rcom *rc) +{ + struct dlm_header *hd = (struct dlm_header *) rc; + int type = rc->rc_type; + + header_out(hd); + + rc->rc_type = cpu_to_le32(rc->rc_type); + rc->rc_result = cpu_to_le32(rc->rc_result); + rc->rc_id = cpu_to_le64(rc->rc_id); + + if (type == DLM_RCOM_LOCK) + rcom_lock_out((struct rcom_lock *) rc->rc_buf); + + else if (type == DLM_RCOM_STATUS_REPLY) + rcom_config_out((struct rcom_config *) rc->rc_buf); +} + +void dlm_rcom_in(struct dlm_rcom *rc) +{ + struct dlm_header *hd = (struct dlm_header *) rc; + + header_in(hd); + + rc->rc_type = le32_to_cpu(rc->rc_type); + rc->rc_result = le32_to_cpu(rc->rc_result); + rc->rc_id = le64_to_cpu(rc->rc_id); + + if (rc->rc_type == DLM_RCOM_LOCK) + rcom_lock_in((struct rcom_lock *) rc->rc_buf); + + else if (rc->rc_type == DLM_RCOM_STATUS_REPLY) + rcom_config_in((struct rcom_config *) rc->rc_buf); +} + diff --git a/fs/dlm/util.h b/fs/dlm/util.h new file mode 100644 index 000000000000..2b25915161c0 --- /dev/null +++ b/fs/dlm/util.h @@ -0,0 +1,22 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __UTIL_DOT_H__ +#define __UTIL_DOT_H__ + +void dlm_message_out(struct dlm_message *ms); +void dlm_message_in(struct dlm_message *ms); +void dlm_rcom_out(struct dlm_rcom *rc); +void dlm_rcom_in(struct dlm_rcom *rc); + +#endif + diff --git a/include/linux/dlm.h b/include/linux/dlm.h new file mode 100644 index 000000000000..dd324ba44d80 --- /dev/null +++ b/include/linux/dlm.h @@ -0,0 +1,312 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#ifndef __DLM_DOT_H__ +#define __DLM_DOT_H__ + +/* + * Interface to Distributed Lock Manager (DLM) + * routines and structures to use DLM lockspaces + */ + +/* + * Lock Modes + */ + +#define DLM_LOCK_IV -1 /* invalid */ +#define DLM_LOCK_NL 0 /* null */ +#define DLM_LOCK_CR 1 /* concurrent read */ +#define DLM_LOCK_CW 2 /* concurrent write */ +#define DLM_LOCK_PR 3 /* protected read */ +#define DLM_LOCK_PW 4 /* protected write */ +#define DLM_LOCK_EX 5 /* exclusive */ + +/* + * Maximum size in bytes of a dlm_lock name + */ + +#define DLM_RESNAME_MAXLEN 64 + +/* + * Flags to dlm_lock + * + * DLM_LKF_NOQUEUE + * + * Do not queue the lock request on the wait queue if it cannot be granted + * immediately. If the lock cannot be granted because of this flag, DLM will + * either return -EAGAIN from the dlm_lock call or will return 0 from + * dlm_lock and -EAGAIN in the lock status block when the AST is executed. + * + * DLM_LKF_CANCEL + * + * Used to cancel a pending lock request or conversion. A converting lock is + * returned to its previously granted mode. + * + * DLM_LKF_CONVERT + * + * Indicates a lock conversion request. For conversions the name and namelen + * are ignored and the lock ID in the LKSB is used to identify the lock. + * + * DLM_LKF_VALBLK + * + * Requests DLM to return the current contents of the lock value block in the + * lock status block. When this flag is set in a lock conversion from PW or EX + * modes, DLM assigns the value specified in the lock status block to the lock + * value block of the lock resource. The LVB is a DLM_LVB_LEN size array + * containing application-specific information. + * + * DLM_LKF_QUECVT + * + * Force a conversion request to be queued, even if it is compatible with + * the granted modes of other locks on the same resource. + * + * DLM_LKF_IVVALBLK + * + * Invalidate the lock value block. + * + * DLM_LKF_CONVDEADLK + * + * Allows the dlm to resolve conversion deadlocks internally by demoting the + * granted mode of a converting lock to NL. The DLM_SBF_DEMOTED flag is + * returned for a conversion that's been effected by this. + * + * DLM_LKF_PERSISTENT + * + * Only relevant to locks originating in userspace. A persistent lock will not + * be removed if the process holding the lock exits. + * + * DLM_LKF_NODLKWT + * DLM_LKF_NODLCKBLK + * + * net yet implemented + * + * DLM_LKF_EXPEDITE + * + * Used only with new requests for NL mode locks. Tells the lock manager + * to grant the lock, ignoring other locks in convert and wait queues. + * + * DLM_LKF_NOQUEUEBAST + * + * Send blocking AST's before returning -EAGAIN to the caller. It is only + * used along with the NOQUEUE flag. Blocking AST's are not sent for failed + * NOQUEUE requests otherwise. + * + * DLM_LKF_HEADQUE + * + * Add a lock to the head of the convert or wait queue rather than the tail. + * + * DLM_LKF_NOORDER + * + * Disregard the standard grant order rules and grant a lock as soon as it + * is compatible with other granted locks. + * + * DLM_LKF_ORPHAN + * + * not yet implemented + * + * DLM_LKF_ALTPR + * + * If the requested mode cannot be granted immediately, try to grant the lock + * in PR mode instead. If this alternate mode is granted instead of the + * requested mode, DLM_SBF_ALTMODE is returned in the lksb. + * + * DLM_LKF_ALTCW + * + * The same as ALTPR, but the alternate mode is CW. + * + * DLM_LKF_FORCEUNLOCK + * + * Unlock the lock even if it is converting or waiting or has sublocks. + * Only really for use by the userland device.c code. + * + */ + +#define DLM_LKF_NOQUEUE 0x00000001 +#define DLM_LKF_CANCEL 0x00000002 +#define DLM_LKF_CONVERT 0x00000004 +#define DLM_LKF_VALBLK 0x00000008 +#define DLM_LKF_QUECVT 0x00000010 +#define DLM_LKF_IVVALBLK 0x00000020 +#define DLM_LKF_CONVDEADLK 0x00000040 +#define DLM_LKF_PERSISTENT 0x00000080 +#define DLM_LKF_NODLCKWT 0x00000100 +#define DLM_LKF_NODLCKBLK 0x00000200 +#define DLM_LKF_EXPEDITE 0x00000400 +#define DLM_LKF_NOQUEUEBAST 0x00000800 +#define DLM_LKF_HEADQUE 0x00001000 +#define DLM_LKF_NOORDER 0x00002000 +#define DLM_LKF_ORPHAN 0x00004000 +#define DLM_LKF_ALTPR 0x00008000 +#define DLM_LKF_ALTCW 0x00010000 +#define DLM_LKF_FORCEUNLOCK 0x00020000 + +/* + * Some return codes that are not in errno.h + */ + +#define DLM_ECANCEL 0x10001 +#define DLM_EUNLOCK 0x10002 + +typedef void dlm_lockspace_t; + +/* + * Lock range structure + */ + +struct dlm_range { + uint64_t ra_start; + uint64_t ra_end; +}; + +/* + * Lock status block + * + * Use this structure to specify the contents of the lock value block. For a + * conversion request, this structure is used to specify the lock ID of the + * lock. DLM writes the status of the lock request and the lock ID assigned + * to the request in the lock status block. + * + * sb_lkid: the returned lock ID. It is set on new (non-conversion) requests. + * It is available when dlm_lock returns. + * + * sb_lvbptr: saves or returns the contents of the lock's LVB according to rules + * shown for the DLM_LKF_VALBLK flag. + * + * sb_flags: DLM_SBF_DEMOTED is returned if in the process of promoting a lock, + * it was first demoted to NL to avoid conversion deadlock. + * DLM_SBF_VALNOTVALID is returned if the resource's LVB is marked invalid. + * + * sb_status: the returned status of the lock request set prior to AST + * execution. Possible return values: + * + * 0 if lock request was successful + * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE + * -ENOMEM if there is no memory to process request + * -EINVAL if there are invalid parameters + * -DLM_EUNLOCK if unlock request was successful + * -DLM_ECANCEL if a cancel completed successfully + */ + +#define DLM_SBF_DEMOTED 0x01 +#define DLM_SBF_VALNOTVALID 0x02 +#define DLM_SBF_ALTMODE 0x04 + +struct dlm_lksb { + int sb_status; + uint32_t sb_lkid; + char sb_flags; + char * sb_lvbptr; +}; + + +#ifdef __KERNEL__ + +#define DLM_LSFL_NODIR 0x00000001 + +/* + * dlm_new_lockspace + * + * Starts a lockspace with the given name. If the named lockspace exists in + * the cluster, the calling node joins it. + */ + +int dlm_new_lockspace(char *name, int namelen, dlm_lockspace_t **lockspace, + uint32_t flags, int lvblen); + +/* + * dlm_release_lockspace + * + * Stop a lockspace. + */ + +int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force); + +/* + * dlm_lock + * + * Make an asyncronous request to acquire or convert a lock on a named + * resource. + * + * lockspace: context for the request + * mode: the requested mode of the lock (DLM_LOCK_) + * lksb: lock status block for input and async return values + * flags: input flags (DLM_LKF_) + * name: name of the resource to lock, can be binary + * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN) + * parent: the lock ID of a parent lock or 0 if none + * lockast: function DLM executes when it completes processing the request + * astarg: argument passed to lockast and bast functions + * bast: function DLM executes when this lock later blocks another request + * + * Returns: + * 0 if request is successfully queued for processing + * -EINVAL if any input parameters are invalid + * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE + * -ENOMEM if there is no memory to process request + * -ENOTCONN if there is a communication error + * + * If the call to dlm_lock returns an error then the operation has failed and + * the AST routine will not be called. If dlm_lock returns 0 it is still + * possible that the lock operation will fail. The AST routine will be called + * when the locking is complete and the status is returned in the lksb. + * + * If the AST routines or parameter are passed to a conversion operation then + * they will overwrite those values that were passed to a previous dlm_lock + * call. + * + * AST routines should not block (at least not for long), but may make + * any locking calls they please. + */ + +int dlm_lock(dlm_lockspace_t *lockspace, + int mode, + struct dlm_lksb *lksb, + uint32_t flags, + void *name, + unsigned int namelen, + uint32_t parent_lkid, + void (*lockast) (void *astarg), + void *astarg, + void (*bast) (void *astarg, int mode), + struct dlm_range *range); + +/* + * dlm_unlock + * + * Asynchronously release a lock on a resource. The AST routine is called + * when the resource is successfully unlocked. + * + * lockspace: context for the request + * lkid: the lock ID as returned in the lksb + * flags: input flags (DLM_LKF_) + * lksb: if NULL the lksb parameter passed to last lock request is used + * astarg: the arg used with the completion ast for the unlock + * + * Returns: + * 0 if request is successfully queued for processing + * -EINVAL if any input parameters are invalid + * -ENOTEMPTY if the lock still has sublocks + * -EBUSY if the lock is waiting for a remote lock operation + * -ENOTCONN if there is a communication error + */ + +int dlm_unlock(dlm_lockspace_t *lockspace, + uint32_t lkid, + uint32_t flags, + struct dlm_lksb *lksb, + void *astarg); + +#endif /* __KERNEL__ */ + +#endif /* __DLM_DOT_H__ */ + diff --git a/include/linux/dlm_device.h b/include/linux/dlm_device.h new file mode 100644 index 000000000000..5e17d295544b --- /dev/null +++ b/include/linux/dlm_device.h @@ -0,0 +1,84 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +/* This is the device interface for dlm, most users will use a library + * interface. + */ + +#define DLM_USER_LVB_LEN 32 + +/* Version of the device interface */ +#define DLM_DEVICE_VERSION_MAJOR 3 +#define DLM_DEVICE_VERSION_MINOR 0 +#define DLM_DEVICE_VERSION_PATCH 0 + +/* struct passed to the lock write */ +struct dlm_lock_params { + __u8 mode; + __u16 flags; + __u32 lkid; + __u32 parent; + struct dlm_range range; + __u8 namelen; + void __user *castparam; + void __user *castaddr; + void __user *bastparam; + void __user *bastaddr; + struct dlm_lksb __user *lksb; + char lvb[DLM_USER_LVB_LEN]; + char name[1]; +}; + +struct dlm_lspace_params { + __u32 flags; + __u32 minor; + char name[1]; +}; + +struct dlm_write_request { + __u32 version[3]; + __u8 cmd; + + union { + struct dlm_lock_params lock; + struct dlm_lspace_params lspace; + } i; +}; + +/* struct read from the "device" fd, + consists mainly of userspace pointers for the library to use */ +struct dlm_lock_result { + __u32 length; + void __user * user_astaddr; + void __user * user_astparam; + struct dlm_lksb __user * user_lksb; + struct dlm_lksb lksb; + __u8 bast_mode; + /* Offsets may be zero if no data is present */ + __u32 lvb_offset; +}; + +/* Commands passed to the device */ +#define DLM_USER_LOCK 1 +#define DLM_USER_UNLOCK 2 +#define DLM_USER_QUERY 3 +#define DLM_USER_CREATE_LOCKSPACE 4 +#define DLM_USER_REMOVE_LOCKSPACE 5 + +/* Arbitrary length restriction */ +#define MAX_LS_NAME_LEN 64 + +/* Lockspace flags */ +#define DLM_USER_LSFLG_AUTOFREE 1 +#define DLM_USER_LSFLG_FORCEFREE 2 + From 5ddec5b3d79eed6df1a37be435f183915a4b696a Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 18 Jan 2006 09:34:14 +0000 Subject: [PATCH 011/292] [GFS2] Only two args for kobject_uevent() in locking/dlm/mount.c Update the dlm interface module to take account of the recently removed third argument to kobject_uevent() Signed-off-by: David Teigland Signed-off-by: Steve Whitehouse --- fs/gfs2/locking/dlm/mount.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c index bfb224638f2d..042f3a75c441 100644 --- a/fs/gfs2/locking/dlm/mount.c +++ b/fs/gfs2/locking/dlm/mount.c @@ -195,14 +195,14 @@ static void gdlm_recovery_done(lm_lockspace_t *lockspace, unsigned int jid, { struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; ls->recover_jid_done = jid; - kobject_uevent(&ls->kobj, KOBJ_CHANGE, NULL); + kobject_uevent(&ls->kobj, KOBJ_CHANGE); } static void gdlm_others_may_mount(lm_lockspace_t *lockspace) { struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; ls->first_done = 1; - kobject_uevent(&ls->kobj, KOBJ_CHANGE, NULL); + kobject_uevent(&ls->kobj, KOBJ_CHANGE); } /* Userspace gets the offline uevent, blocks new gfs locks on @@ -213,7 +213,7 @@ static void gdlm_withdraw(lm_lockspace_t *lockspace) { struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; - kobject_uevent(&ls->kobj, KOBJ_OFFLINE, NULL); + kobject_uevent(&ls->kobj, KOBJ_OFFLINE); wait_event_interruptible(ls->wait_control, test_bit(DFL_WITHDRAW, &ls->flags)); From c73530a1f9633b2e7e6e19d0274b575febf8e8dc Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 18 Jan 2006 10:11:51 +0000 Subject: [PATCH 012/292] [GFS2] Remove remains of the GFS2 identify ioctl() We don't need this ioctl, we can use stat() to gain the same information. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 1e6f51b74f44..563c19d0d406 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -1214,16 +1214,9 @@ static int gfs2_ioctl(struct inode *inode, struct file *file, unsigned int cmd, atomic_inc(&ip->i_sbd->sd_ops_file); switch (cmd) { - case GFS2_IOCTL_IDENTIFY: { - unsigned int x = GFS2_MAGIC; - if (copy_to_user((unsigned int __user *)arg, &x, sizeof(unsigned int))) - return -EFAULT; - return 0; - case GFS2_IOCTL_SETFLAGS: case GFS2_IOCTL_GETFLAGS: return gfs2_ioctl_flags(ip, cmd, arg); - } default: return -ENOTTY; From 666a2c534cc6238932296a95c9e9c06ca3b73d97 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 18 Jan 2006 10:29:04 +0000 Subject: [PATCH 013/292] [GFS2] Remove unused code from various files Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 81 +------------------------------------------------ fs/gfs2/bmap.h | 2 -- fs/gfs2/dir.c | 51 ------------------------------- fs/gfs2/dir.h | 2 -- fs/gfs2/eattr.c | 57 ---------------------------------- fs/gfs2/eattr.h | 2 -- fs/gfs2/util.c | 30 ------------------ fs/gfs2/util.h | 8 ----- 8 files changed, 1 insertion(+), 232 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 4b4e295b3bf5..bece3620f1c0 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -999,7 +999,7 @@ static int do_shrink(struct gfs2_inode *ip, uint64_t size, } /** - * gfs2_truncatei - make a file a give size + * gfs2_truncatei - make a file a given size * @ip: the inode * @size: the size to make the file * @truncator: function to truncate the last partial block @@ -1125,82 +1125,3 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, return 0; } -/** - * do_gfm - Copy out the dinode/indirect blocks of a file - * @ip: the file - * @dibh: the dinode buffer - * @bh: the indirect buffer we're looking at - * @top: the first pointer in the block - * @bottom: one more than the last pointer in the block - * @height: the height the block is at - * @data: a pointer to a struct gfs2_user_buffer structure - * - * If this is a journaled file, copy out the data too. - * - * Returns: errno - */ - -static int do_gfm(struct gfs2_inode *ip, struct buffer_head *dibh, - struct buffer_head *bh, uint64_t *top, uint64_t *bottom, - unsigned int height, void *data) -{ - struct gfs2_user_buffer *ub = (struct gfs2_user_buffer *)data; - int error; - - error = gfs2_add_bh_to_ub(ub, bh); - if (error) - return error; - - if (!S_ISDIR(ip->i_di.di_mode) || - height + 1 != ip->i_di.di_height) - return 0; - - for (; top < bottom; top++) - if (*top) { - struct buffer_head *data_bh; - - error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*top), - DIO_START | DIO_WAIT, - &data_bh); - if (error) - return error; - - error = gfs2_add_bh_to_ub(ub, data_bh); - - brelse(data_bh); - - if (error) - return error; - } - - return 0; -} - -/** - * gfs2_get_file_meta - return all the metadata for a file - * @ip: the file - * @ub: the structure representing the meta - * - * Returns: errno - */ - -int gfs2_get_file_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub) -{ - int error; - - if (gfs2_is_stuffed(ip)) { - struct buffer_head *dibh; - error = gfs2_meta_inode_buffer(ip, &dibh); - if (!error) { - error = gfs2_add_bh_to_ub(ub, dibh); - brelse(dibh); - } - } else { - struct metapath mp; - find_metapath(ip, 0, &mp); - error = recursive_scan(ip, NULL, &mp, 0, 0, 1, do_gfm, ub); - } - - return error; -} - diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index de16e44f049f..25ea32905c67 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -34,6 +34,4 @@ void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, unsigned int len, int *alloc_required); -int gfs2_get_file_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub); - #endif /* __BMAP_DOT_H__ */ diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 6b1dc3dc3a2d..f6304e55dbc1 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -2104,54 +2104,3 @@ int gfs2_diradd_alloc_required(struct gfs2_inode *dip, struct qstr *filename, return error; } -/** - * do_gdm - copy out one leaf (or list of leaves) - * @dip: the directory - * @index: the hash table offset in the directory - * @len: the number of pointers to this leaf - * @leaf_no: the leaf number - * @data: a pointer to a struct gfs2_user_buffer structure - * - * Returns: errno - */ - -static int do_gdm(struct gfs2_inode *dip, uint32_t index, uint32_t len, - uint64_t leaf_no, void *data) -{ - struct gfs2_user_buffer *ub = (struct gfs2_user_buffer *)data; - struct gfs2_leaf leaf; - struct buffer_head *bh; - uint64_t blk; - int error = 0; - - for (blk = leaf_no; blk; blk = leaf.lf_next) { - error = get_leaf(dip, blk, &bh); - if (error) - break; - - gfs2_leaf_in(&leaf, bh->b_data); - - error = gfs2_add_bh_to_ub(ub, bh); - - brelse(bh); - - if (error) - break; - } - - return error; -} - -/** - * gfs2_get_dir_meta - return all the leaf blocks of a directory - * @dip: the directory - * @ub: the structure representing the meta - * - * Returns: errno - */ - -int gfs2_get_dir_meta(struct gfs2_inode *dip, struct gfs2_user_buffer *ub) -{ - return foreach_leaf(dip, do_gdm, ub); -} - diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h index 79f77aab4264..ff6d1c597ee9 100644 --- a/fs/gfs2/dir.h +++ b/fs/gfs2/dir.h @@ -46,6 +46,4 @@ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip); int gfs2_diradd_alloc_required(struct gfs2_inode *dip, struct qstr *filename, int *alloc_required); -int gfs2_get_dir_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub); - #endif /* __DIR_DOT_H__ */ diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 63a5cf1e2472..dec55dcb9dbc 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -1561,60 +1561,3 @@ int gfs2_ea_dealloc(struct gfs2_inode *ip) return error; } -/** - * gfs2_get_eattr_meta - return all the eattr blocks of a file - * @dip: the directory - * @ub: the structure representing the user buffer to copy to - * - * Returns: errno - */ - -int gfs2_get_eattr_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub) -{ - struct buffer_head *bh; - int error; - - error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, - DIO_START | DIO_WAIT, &bh); - if (error) - return error; - - gfs2_add_bh_to_ub(ub, bh); - - if (ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT) { - struct buffer_head *eabh; - uint64_t *eablk, *end; - - if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_IN)) { - error = -EIO; - goto out; - } - - eablk = (uint64_t *)(bh->b_data + - sizeof(struct gfs2_meta_header)); - end = eablk + ip->i_sbd->sd_inptrs; - - for (; eablk < end; eablk++) { - uint64_t bn; - - if (!*eablk) - break; - bn = be64_to_cpu(*eablk); - - error = gfs2_meta_read(ip->i_gl, bn, - DIO_START | DIO_WAIT, &eabh); - if (error) - break; - gfs2_add_bh_to_ub(ub, eabh); - brelse(eabh); - if (error) - break; - } - } - - out: - brelse(bh); - - return error; -} - diff --git a/fs/gfs2/eattr.h b/fs/gfs2/eattr.h index a64039295759..e5a42abf68a3 100644 --- a/fs/gfs2/eattr.h +++ b/fs/gfs2/eattr.h @@ -74,8 +74,6 @@ int gfs2_ea_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er); int gfs2_ea_dealloc(struct gfs2_inode *ip); -int gfs2_get_eattr_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub); - /* Exported to acl.c */ int gfs2_ea_find(struct gfs2_inode *ip, diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 74e2c62f2370..ad49153c33d1 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -221,36 +221,6 @@ int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, return rv; } -/** - * gfs2_add_bh_to_ub - copy a buffer up to user space - * @ub: the structure representing where to copy - * @bh: the buffer - * - * Returns: errno - */ - -int gfs2_add_bh_to_ub(struct gfs2_user_buffer *ub, struct buffer_head *bh) -{ - uint64_t blkno = bh->b_blocknr; - - if (ub->ub_count + sizeof(uint64_t) + bh->b_size > ub->ub_size) - return -ENOMEM; - - if (copy_to_user(ub->ub_data + ub->ub_count, - &blkno, - sizeof(uint64_t))) - return -EFAULT; - ub->ub_count += sizeof(uint64_t); - - if (copy_to_user(ub->ub_data + ub->ub_count, - bh->b_data, - bh->b_size)) - return -EFAULT; - ub->ub_count += bh->b_size; - - return 0; -} - void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap, unsigned int bit, int new_value) { diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index 21466fe9bf43..8d6eba3bdf0a 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -152,14 +152,6 @@ extern kmem_cache_t *gfs2_glock_cachep; extern kmem_cache_t *gfs2_inode_cachep; extern kmem_cache_t *gfs2_bufdata_cachep; -struct gfs2_user_buffer { - char __user *ub_data; - unsigned int ub_size; - unsigned int ub_count; -}; - -int gfs2_add_bh_to_ub(struct gfs2_user_buffer *ub, struct buffer_head *bh); - static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt, unsigned int *p) { From 3bd7662c4de28522d4709ab5a56033e3c33e1d4a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 18 Jan 2006 10:40:17 +0000 Subject: [PATCH 014/292] [GFS2] Remove unused code from ondisk.c/gfs2_ondisk.h Removal of unused conversion functions from ondisk.c and gfs2_ondisk.h Signed-off-by: Steven Whitehouse --- fs/gfs2/ondisk.c | 63 ------------------------------------- include/linux/gfs2_ondisk.h | 5 --- 2 files changed, 68 deletions(-) diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index 2a1ef5aa7f0c..0d54e082e62b 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -120,24 +120,6 @@ void gfs2_sb_in(struct gfs2_sb *sb, char *buf) memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN); } -void gfs2_sb_out(struct gfs2_sb *sb, char *buf) -{ - struct gfs2_sb *str = (struct gfs2_sb *)buf; - - gfs2_meta_header_out(&sb->sb_header, buf); - - str->sb_fs_format = cpu_to_be32(sb->sb_fs_format); - str->sb_multihost_format = cpu_to_be32(sb->sb_multihost_format); - str->sb_bsize = cpu_to_be32(sb->sb_bsize); - str->sb_bsize_shift = cpu_to_be32(sb->sb_bsize_shift); - - gfs2_inum_out(&sb->sb_master_dir, (char *)&str->sb_master_dir); - gfs2_inum_out(&sb->sb_root_dir, (char *)&str->sb_root_dir); - - memcpy(str->sb_lockproto, sb->sb_lockproto, GFS2_LOCKNAME_LEN); - memcpy(str->sb_locktable, sb->sb_locktable, GFS2_LOCKNAME_LEN); -} - void gfs2_sb_print(struct gfs2_sb *sb) { gfs2_meta_header_print(&sb->sb_header); @@ -344,30 +326,6 @@ void gfs2_dinode_print(struct gfs2_dinode *di) pv(di, di_eattr, "%llu"); } -void gfs2_dirent_in(struct gfs2_dirent *de, char *buf) -{ - struct gfs2_dirent *str = (struct gfs2_dirent *)buf; - - gfs2_inum_in(&de->de_inum, buf); - de->de_hash = be32_to_cpu(str->de_hash); - de->de_rec_len = be32_to_cpu(str->de_rec_len); - de->de_name_len = str->de_name_len; - de->de_type = str->de_type; -} - -void gfs2_dirent_out(struct gfs2_dirent *de, char *buf) -{ - struct gfs2_dirent *str = (struct gfs2_dirent *)buf; - - gfs2_inum_out(&de->de_inum, buf); - str->de_hash = cpu_to_be32(de->de_hash); - str->de_rec_len = cpu_to_be32(de->de_rec_len); - str->de_name_len = de->de_name_len; - str->de_type = de->de_type; - str->__pad1 = 0; - str->__pad2 = 0; -} - void gfs2_dirent_print(struct gfs2_dirent *de, char *name) { char buf[GFS2_FNAMESIZE + 1]; @@ -394,18 +352,6 @@ void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf) lf->lf_next = be64_to_cpu(str->lf_next); } -void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf) -{ - struct gfs2_leaf *str = (struct gfs2_leaf *)buf; - - gfs2_meta_header_out(&lf->lf_header, buf); - str->lf_depth = cpu_to_be16(lf->lf_depth); - str->lf_entries = cpu_to_be16(lf->lf_entries); - str->lf_dirent_format = cpu_to_be32(lf->lf_dirent_format); - str->lf_next = cpu_to_be64(lf->lf_next); - memset(&str->lf_reserved, 0, sizeof(str->lf_reserved)); -} - void gfs2_leaf_print(struct gfs2_leaf *lf) { gfs2_meta_header_print(&lf->lf_header); @@ -570,15 +516,6 @@ void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf) qc->qc_id = be32_to_cpu(str->qc_id); } -void gfs2_quota_change_out(struct gfs2_quota_change *qc, char *buf) -{ - struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf; - - str->qc_change = cpu_to_be64(qc->qc_change); - str->qc_flags = cpu_to_be32(qc->qc_flags); - str->qc_id = cpu_to_be32(qc->qc_id); -} - void gfs2_quota_change_print(struct gfs2_quota_change *qc) { pv(qc, qc_change, "%lld"); diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index 213d664d495d..8354b9c4f408 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -407,7 +407,6 @@ extern void gfs2_inum_out(struct gfs2_inum *no, char *buf); extern void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf); extern void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf); extern void gfs2_sb_in(struct gfs2_sb *sb, char *buf); -extern void gfs2_sb_out(struct gfs2_sb *sb, char *buf); extern void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf); extern void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf); extern void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf); @@ -416,10 +415,7 @@ extern void gfs2_quota_in(struct gfs2_quota *qu, char *buf); extern void gfs2_quota_out(struct gfs2_quota *qu, char *buf); extern void gfs2_dinode_in(struct gfs2_dinode *di, char *buf); extern void gfs2_dinode_out(struct gfs2_dinode *di, char *buf); -extern void gfs2_dirent_in(struct gfs2_dirent *de, char *buf); -extern void gfs2_dirent_out(struct gfs2_dirent *de, char *buf); extern void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf); -extern void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf); extern void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf); extern void gfs2_ea_header_out(struct gfs2_ea_header *ea, char *buf); extern void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf); @@ -430,7 +426,6 @@ extern void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf); extern void gfs2_unlinked_tag_in(struct gfs2_unlinked_tag *ut, char *buf); extern void gfs2_unlinked_tag_out(struct gfs2_unlinked_tag *ut, char *buf); extern void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf); -extern void gfs2_quota_change_out(struct gfs2_quota_change *qc, char *buf); /* Printing functions */ From b96ca4fa4e3b510d528a093a5bac0befbc2ba46d Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 18 Jan 2006 10:57:10 +0000 Subject: [PATCH 015/292] [GFS2] Update init_dinode() to reduce stack usage We no longer allocate a dinode on the stack in init_dinode() and we no longer use gfs2_dinode_out (eliminating one copy) and gfs2_meta_header_in (eliminating another copy). The meta_header_in fucntion is now no longer referenced from outside gfs2_ondisk.c, so make it static. Signed-off-by: Steven Whitehouse --- fs/gfs2/inode.c | 43 ++++++++++++++++++++++++------------- fs/gfs2/ondisk.c | 4 ++-- include/linux/gfs2_ondisk.h | 2 -- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 73922dba5398..aa5311ef7ba7 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -993,37 +993,50 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, unsigned int uid, unsigned int gid) { struct gfs2_sbd *sdp = dip->i_sbd; - struct gfs2_dinode di; + struct gfs2_dinode *di; struct buffer_head *dibh; dibh = gfs2_meta_new(gl, inum->no_addr); gfs2_trans_add_bh(gl, dibh); gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI); gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); + di = (struct gfs2_dinode *)dibh->b_data; - memset(&di, 0, sizeof(struct gfs2_dinode)); - gfs2_meta_header_in(&di.di_header, dibh->b_data); - di.di_num = *inum; - di.di_mode = mode; - di.di_uid = uid; - di.di_gid = gid; - di.di_blocks = 1; - di.di_atime = di.di_mtime = di.di_ctime = get_seconds(); - di.di_goal_meta = di.di_goal_data = inum->no_addr; + di->di_num = *inum; + di->di_mode = cpu_to_be32(mode); + di->di_uid = cpu_to_be32(uid); + di->di_gid = cpu_to_be32(gid); + di->di_nlink = cpu_to_be32(0); + di->di_size = cpu_to_be64(0); + di->di_blocks = cpu_to_be64(1); + di->di_atime = di->di_mtime = di->di_ctime = cpu_to_be64(get_seconds()); + di->di_major = di->di_minor = cpu_to_be32(0); + di->di_goal_meta = di->di_goal_data = cpu_to_be64(inum->no_addr); + di->__pad[0] = di->__pad[1] = 0; + di->di_flags = cpu_to_be32(0); if (S_ISREG(mode)) { if ((dip->i_di.di_flags & GFS2_DIF_INHERIT_JDATA) || gfs2_tune_get(sdp, gt_new_files_jdata)) - di.di_flags |= GFS2_DIF_JDATA; + di->di_flags |= cpu_to_be32(GFS2_DIF_JDATA); if ((dip->i_di.di_flags & GFS2_DIF_INHERIT_DIRECTIO) || gfs2_tune_get(sdp, gt_new_files_directio)) - di.di_flags |= GFS2_DIF_DIRECTIO; + di->di_flags |= cpu_to_be32(GFS2_DIF_DIRECTIO); } else if (S_ISDIR(mode)) { - di.di_flags |= (dip->i_di.di_flags & GFS2_DIF_INHERIT_DIRECTIO); - di.di_flags |= (dip->i_di.di_flags & GFS2_DIF_INHERIT_JDATA); + di->di_flags |= cpu_to_be32(dip->i_di.di_flags & GFS2_DIF_INHERIT_DIRECTIO); + di->di_flags |= cpu_to_be32(dip->i_di.di_flags & GFS2_DIF_INHERIT_JDATA); } - gfs2_dinode_out(&di, dibh->b_data); + di->__pad1 = 0; + di->di_height = cpu_to_be32(0); + di->__pad2 = 0; + di->__pad3 = 0; + di->di_depth = cpu_to_be16(0); + di->di_entries = cpu_to_be32(0); + memset(&di->__pad4, 0, sizeof(di->__pad4)); + di->di_eattr = cpu_to_be64(0); + memset(&di->di_reserved, 0, sizeof(di->di_reserved)); + brelse(dibh); } diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index 0d54e082e62b..854b5049b8d5 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -77,7 +77,7 @@ void gfs2_inum_print(struct gfs2_inum *no) pv(no, no_addr, "%llu"); } -void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf) +static void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf) { struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf; @@ -86,7 +86,7 @@ void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf) mh->mh_format = be16_to_cpu(str->mh_format); } -void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf) +static void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf) { struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf; diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index 8354b9c4f408..f1302e2616da 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -404,8 +404,6 @@ struct gfs2_quota_change { extern void gfs2_inum_in(struct gfs2_inum *no, char *buf); extern void gfs2_inum_out(struct gfs2_inum *no, char *buf); -extern void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf); -extern void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf); extern void gfs2_sb_in(struct gfs2_sb *sb, char *buf); extern void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf); extern void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf); From d4e9c4c3bf861ef2ac96e0de659c75a00da92b28 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 18 Jan 2006 11:19:28 +0000 Subject: [PATCH 016/292] [GFS2] Add an additional argument to gfs2_trans_add_bh() This adds an extra argument to gfs2_trans_add_bh() to indicate whether the bh being added to the transaction is metadata or data. Its currently unused since all existing callers set it to 1 (metadata) but following patches will make use of it. Signed-off-by: Steven Whitehouse --- fs/gfs2/acl.c | 2 +- fs/gfs2/bmap.c | 24 ++++++++++++------------ fs/gfs2/dir.c | 32 ++++++++++++++++---------------- fs/gfs2/eattr.c | 38 +++++++++++++++++++------------------- fs/gfs2/inode.c | 16 ++++++++-------- fs/gfs2/jdata.c | 8 ++++---- fs/gfs2/meta_io.c | 2 +- fs/gfs2/ops_address.c | 2 +- fs/gfs2/ops_file.c | 10 +++++----- fs/gfs2/ops_inode.c | 4 ++-- fs/gfs2/quota.c | 2 +- fs/gfs2/resize.c | 2 +- fs/gfs2/rgrp.c | 16 ++++++++-------- fs/gfs2/super.c | 6 +++--- fs/gfs2/trans.c | 3 ++- fs/gfs2/trans.h | 2 +- fs/gfs2/unlinked.c | 2 +- 17 files changed, 86 insertions(+), 85 deletions(-) diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index 33c465a2ab53..9482a677ea47 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -202,7 +202,7 @@ static int munge_mode(struct gfs2_inode *ip, mode_t mode) gfs2_assert_withdraw(sdp, (ip->i_di.di_mode & S_IFMT) == (mode & S_IFMT)); ip->i_di.di_mode = mode; - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index bece3620f1c0..967cbc68195a 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -124,7 +124,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, /* Set up the pointer to the new block */ - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); @@ -223,7 +223,7 @@ static int build_height(struct gfs2_inode *ip, int height) block = gfs2_alloc_meta(ip); bh = gfs2_meta_new(ip->i_gl, block); - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); @@ -236,7 +236,7 @@ static int build_height(struct gfs2_inode *ip, int height) /* Set up the new direct pointer and write it out to disk */ - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); @@ -382,7 +382,7 @@ static void lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, else *block = gfs2_alloc_meta(ip); - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); *ptr = cpu_to_be64(*block); ip->i_di.di_blocks++; @@ -490,7 +490,7 @@ int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, if (*new) { error = gfs2_meta_inode_buffer(ip, &bh); if (!error) { - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_dinode_out(&ip->i_di, bh->b_data); brelse(bh); } @@ -672,8 +672,8 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, down_write(&ip->i_rw_mutex); - gfs2_trans_add_bh(ip->i_gl, dibh); - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); + gfs2_trans_add_bh(ip->i_gl, bh, 1); bstart = 0; blen = 0; @@ -795,7 +795,7 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size) if (error) goto out_end_trans; - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); @@ -833,7 +833,7 @@ static int truncator_journaled(struct gfs2_inode *ip, uint64_t size) if (error) return error; - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header) + off); brelse(bh); @@ -861,7 +861,7 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size, if (gfs2_is_stuffed(ip)) { ip->i_di.di_size = size; ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode) + size); error = 1; @@ -879,7 +879,7 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size, ip->i_di.di_size = size; ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); ip->i_di.di_flags |= GFS2_DIF_TRUNC_IN_PROG; - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); } } @@ -957,7 +957,7 @@ static int trunc_end(struct gfs2_inode *ip) ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); ip->i_di.di_flags &= ~GFS2_DIF_TRUNC_IN_PROG; - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index f6304e55dbc1..93d3704ac58c 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -201,7 +201,7 @@ static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh, return; } - gfs2_trans_add_bh(dip->i_gl, bh); + gfs2_trans_add_bh(dip->i_gl, bh, 1); /* If there is no prev entry, this is the first entry in the block. The de_rec_len is already as big as it needs to be. Just zero @@ -264,7 +264,7 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, return -EIO; } - gfs2_trans_add_bh(dip->i_gl, bh); + gfs2_trans_add_bh(dip->i_gl, bh, 1); dent->de_rec_len = bh->b_size - offset; dent->de_rec_len = cpu_to_be32(dent->de_rec_len); @@ -282,7 +282,7 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) { - gfs2_trans_add_bh(dip->i_gl, bh); + gfs2_trans_add_bh(dip->i_gl, bh, 1); if (dent->de_inum.no_addr) { new = (struct gfs2_dirent *)((char *)dent + @@ -552,7 +552,7 @@ static int dir_make_exhash(struct gfs2_inode *dip) /* Turn over a new leaf */ bh = gfs2_meta_new(dip->i_gl, bn); - gfs2_trans_add_bh(dip->i_gl, bh); + gfs2_trans_add_bh(dip->i_gl, bh, 1); gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); @@ -596,7 +596,7 @@ static int dir_make_exhash(struct gfs2_inode *dip) /* We're done with the new leaf block, now setup the new hash table. */ - gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_trans_add_bh(dip->i_gl, dibh, 1); gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); lp = (uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)); @@ -647,7 +647,7 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, /* Get the new leaf block */ nbh = gfs2_meta_new(dip->i_gl, bn); - gfs2_trans_add_bh(dip->i_gl, nbh); + gfs2_trans_add_bh(dip->i_gl, nbh, 1); gfs2_metatype_set(nbh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); gfs2_buffer_clear_tail(nbh, sizeof(struct gfs2_meta_header)); @@ -661,7 +661,7 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, if (error) goto fail; - gfs2_trans_add_bh(dip->i_gl, obh); + gfs2_trans_add_bh(dip->i_gl, obh, 1); oleaf = (struct gfs2_leaf *)obh->b_data; @@ -1285,14 +1285,14 @@ static int dir_e_add(struct gfs2_inode *dip, struct qstr *filename, bn = gfs2_alloc_meta(dip); nbh = gfs2_meta_new(dip->i_gl, bn); - gfs2_trans_add_bh(dip->i_gl, nbh); + gfs2_trans_add_bh(dip->i_gl, nbh, 1); gfs2_metatype_set(nbh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); gfs2_buffer_clear_tail(nbh, sizeof(struct gfs2_meta_header)); - gfs2_trans_add_bh(dip->i_gl, bh); + gfs2_trans_add_bh(dip->i_gl, bh, 1); leaf->lf_next = cpu_to_be64(bn); nleaf = (struct gfs2_leaf *)nbh->b_data; @@ -1330,7 +1330,7 @@ static int dir_e_add(struct gfs2_inode *dip, struct qstr *filename, dip->i_di.di_entries++; dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_trans_add_bh(dip->i_gl, dibh, 1); gfs2_dinode_out(&dip->i_di, dibh->b_data); brelse(dibh); @@ -1376,7 +1376,7 @@ static int dir_e_del(struct gfs2_inode *dip, struct qstr *filename) dip->i_di.di_entries--; dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_trans_add_bh(dip->i_gl, dibh, 1); gfs2_dinode_out(&dip->i_di, dibh->b_data); brelse(dibh); @@ -1481,7 +1481,7 @@ static int dir_e_mvino(struct gfs2_inode *dip, struct qstr *filename, if (error) return error; - gfs2_trans_add_bh(dip->i_gl, bh); + gfs2_trans_add_bh(dip->i_gl, bh, 1); gfs2_inum_out(inum, (char *)&dent->de_inum); dent->de_type = new_type; @@ -1494,7 +1494,7 @@ static int dir_e_mvino(struct gfs2_inode *dip, struct qstr *filename, dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_trans_add_bh(dip->i_gl, dibh, 1); gfs2_dinode_out(&dip->i_di, dibh->b_data); brelse(dibh); @@ -1681,7 +1681,7 @@ static int dir_l_mvino(struct gfs2_inode *dip, struct qstr *filename, if (error) goto out; - gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_trans_add_bh(dip->i_gl, dibh, 1); gfs2_inum_out(inum, (char *)&dent->de_inum); dent->de_type = new_type; @@ -1976,7 +1976,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, if (error) goto out_end_trans; - gfs2_trans_add_bh(dip->i_gl, dibh); + gfs2_trans_add_bh(dip->i_gl, dibh, 1); gfs2_dinode_out(&dip->i_di, dibh->b_data); brelse(dibh); @@ -2030,7 +2030,7 @@ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip) error = gfs2_meta_inode_buffer(dip, &bh); if (!error) { - gfs2_trans_add_bh(dip->i_gl, bh); + gfs2_trans_add_bh(dip->i_gl, bh, 1); ((struct gfs2_dinode *)bh->b_data)->di_mode = cpu_to_be32(S_IFREG); brelse(bh); } diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index dec55dcb9dbc..02e45c4ecbec 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -268,7 +268,7 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, if (error) goto out_gunlock; - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); dataptrs = GFS2_EA2DATAPTRS(ea); for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) { @@ -309,7 +309,7 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, error = gfs2_meta_inode_buffer(ip, &dibh); if (!error) { ip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } @@ -628,7 +628,7 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp) block = gfs2_alloc_meta(ip); *bhp = gfs2_meta_new(ip->i_gl, block); - gfs2_trans_add_bh(ip->i_gl, *bhp); + gfs2_trans_add_bh(ip->i_gl, *bhp, 1); gfs2_metatype_set(*bhp, GFS2_METATYPE_EA, GFS2_FORMAT_EA); gfs2_buffer_clear_tail(*bhp, sizeof(struct gfs2_meta_header)); @@ -686,7 +686,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, block = gfs2_alloc_meta(ip); bh = gfs2_meta_new(ip->i_gl, block); - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_metatype_set(bh, GFS2_METATYPE_ED, GFS2_FORMAT_ED); ip->i_di.di_blocks++; @@ -759,7 +759,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, ip->i_di.di_mode = er->er_mode; } ip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } @@ -839,7 +839,7 @@ static void ea_set_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_header *prev = el->el_prev; uint32_t len; - gfs2_trans_add_bh(ip->i_gl, el->el_bh); + gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1); if (!prev || !GFS2_EA_IS_STUFFED(ea)) { ea->ea_type = GFS2_EATYPE_UNUSED; @@ -877,7 +877,7 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh, if (error) return error; - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); if (es->ea_split) ea = ea_split_ea(ea); @@ -897,7 +897,7 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh, ip->i_di.di_mode = er->er_mode; } ip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); out: @@ -913,7 +913,7 @@ static int ea_set_simple_alloc(struct gfs2_inode *ip, struct gfs2_ea_header *ea = es->es_ea; int error; - gfs2_trans_add_bh(ip->i_gl, es->es_bh); + gfs2_trans_add_bh(ip->i_gl, es->es_bh, 1); if (es->ea_split) ea = ea_split_ea(ea); @@ -1007,14 +1007,14 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, goto out; } - gfs2_trans_add_bh(ip->i_gl, indbh); + gfs2_trans_add_bh(ip->i_gl, indbh, 1); } else { uint64_t blk; blk = gfs2_alloc_meta(ip); indbh = gfs2_meta_new(ip->i_gl, blk); - gfs2_trans_add_bh(ip->i_gl, indbh); + gfs2_trans_add_bh(ip->i_gl, indbh, 1); gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); gfs2_buffer_clear_tail(indbh, mh_size); @@ -1163,7 +1163,7 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el) if (error) return error; - gfs2_trans_add_bh(ip->i_gl, el->el_bh); + gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1); if (prev) { uint32_t len; @@ -1179,7 +1179,7 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el) error = gfs2_meta_inode_buffer(ip, &dibh); if (!error) { ip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } @@ -1288,7 +1288,7 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, goto fail; } - gfs2_trans_add_bh(ip->i_gl, bh[x]); + gfs2_trans_add_bh(ip->i_gl, bh[x], 1); memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), data, @@ -1323,7 +1323,7 @@ int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el, if (error) return error; - gfs2_trans_add_bh(ip->i_gl, el->el_bh); + gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1); memcpy(GFS2_EA2DATA(el->el_ea), data, GFS2_EA_DATA_LEN(el->el_ea)); @@ -1338,7 +1338,7 @@ int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el, error = inode_setattr(ip->i_vnode, attr); gfs2_assert_warn(ip->i_sbd, !error); gfs2_inode_attr_out(ip); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } @@ -1416,7 +1416,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) if (error) goto out_gunlock; - gfs2_trans_add_bh(ip->i_gl, indbh); + gfs2_trans_add_bh(ip->i_gl, indbh, 1); eablk = (uint64_t *)(indbh->b_data + sizeof(struct gfs2_meta_header)); bstart = 0; @@ -1450,7 +1450,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) error = gfs2_meta_inode_buffer(ip, &dibh); if (!error) { - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } @@ -1502,7 +1502,7 @@ static int ea_dealloc_block(struct gfs2_inode *ip) error = gfs2_meta_inode_buffer(ip, &dibh); if (!error) { - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index aa5311ef7ba7..9ed7c0541065 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -691,7 +691,7 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) ip->i_di.di_nlink = nlink; ip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); @@ -786,7 +786,7 @@ static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) if (ir.ir_length) { *formal_ino = ir.ir_start++; ir.ir_length--; - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_inum_range_out(&ir, bh->b_data + sizeof(struct gfs2_dinode)); brelse(bh); @@ -843,7 +843,7 @@ static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) if (x < y) gfs2_consist_inode(m_ip); x = cpu_to_be64(x); - gfs2_trans_add_bh(m_ip->i_gl, m_bh); + gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1); *(uint64_t *)(m_bh->b_data + sizeof(struct gfs2_dinode)) = x; brelse(m_bh); @@ -852,7 +852,7 @@ static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) *formal_ino = ir.ir_start++; ir.ir_length--; - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_inum_range_out(&ir, bh->b_data + sizeof(struct gfs2_dinode)); out_brelse: @@ -997,7 +997,7 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, struct buffer_head *dibh; dibh = gfs2_meta_new(gl, inum->no_addr); - gfs2_trans_add_bh(gl, dibh); + gfs2_trans_add_bh(gl, dibh, 1); gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI); gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); di = (struct gfs2_dinode *)dibh->b_data; @@ -1135,7 +1135,7 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name, if (error) goto fail_end_trans; ip->i_di.di_nlink = 1; - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); @@ -1601,7 +1601,7 @@ int gfs2_glock_nq_atime(struct gfs2_holder *gh) ip->i_di.di_atime = curtime; - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); @@ -1776,7 +1776,7 @@ __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) gfs2_assert_warn(ip->i_sbd, !error); gfs2_inode_attr_out(ip); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } diff --git a/fs/gfs2/jdata.c b/fs/gfs2/jdata.c index d4adbf171ed3..6caa93e46ce0 100644 --- a/fs/gfs2/jdata.c +++ b/fs/gfs2/jdata.c @@ -30,7 +30,7 @@ int gfs2_jdata_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, if (new) { bh = gfs2_meta_new(ip->i_gl, block); - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_metatype_set(bh, GFS2_METATYPE_JD, GFS2_FORMAT_JD); gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); } else { @@ -220,7 +220,7 @@ int gfs2_jdata_read(struct gfs2_inode *ip, char __user *buf, uint64_t offset, int gfs2_copy_from_mem(struct gfs2_inode *ip, struct buffer_head *bh, const char **buf, unsigned int offset, unsigned int size) { - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); memcpy(bh->b_data + offset, *buf, size); *buf += size; @@ -243,7 +243,7 @@ int gfs2_copy_from_user(struct gfs2_inode *ip, struct buffer_head *bh, { int error = 0; - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); if (copy_from_user(bh->b_data + offset, *buf, size)) error = -EFAULT; else @@ -368,7 +368,7 @@ int gfs2_jdata_write(struct gfs2_inode *ip, const char __user *buf, uint64_t off ip->i_di.di_size = offset + copied; ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 177b0246d194..8bbe11855223 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -786,7 +786,7 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num, brelse(bh); return -EIO; } - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 0aa5f140ddb1..d352b3528f5e 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -368,7 +368,7 @@ static int gfs2_commit_write(struct file *file, struct page *page, if (error) goto fail; - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); kaddr = kmap(page); memcpy(dibh->b_data + sizeof(struct gfs2_dinode) + from, diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 563c19d0d406..0f356fc4690c 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -456,7 +456,7 @@ static ssize_t do_write_direct_alloc(struct file *file, const char __user *buf, ip->i_di.di_mode &= (ip->i_di.di_mode & S_IXGRP) ? (~(S_ISUID | S_ISGID)) : (~S_ISUID); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } @@ -481,7 +481,7 @@ static ssize_t do_write_direct_alloc(struct file *file, const char __user *buf, ip->i_di.di_size = inode->i_size; ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); @@ -721,7 +721,7 @@ static ssize_t do_do_write_buf(struct file *file, const char __user *buf, size_t ip->i_di.di_mode &= (ip->i_di.di_mode & S_IXGRP) ? (~(S_ISUID | S_ISGID)) : (~S_ISUID); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } @@ -752,7 +752,7 @@ static ssize_t do_do_write_buf(struct file *file, const char __user *buf, size_t ip->i_di.di_size = inode->i_size; ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } @@ -1177,7 +1177,7 @@ static int gfs2_ioctl_flags(struct gfs2_inode *ip, unsigned int cmd, unsigned lo ip->i_di.di_flags = flags; - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index d0f90b88380c..89417a6cb723 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -839,7 +839,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, if (error) goto out_end_trans; ip->i_di.di_ctime = get_seconds(); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } @@ -1043,7 +1043,7 @@ static int setattr_chown(struct inode *inode, struct iattr *attr) gfs2_assert_warn(sdp, !error); gfs2_inode_attr_out(ip); - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index a0320f22b57b..5fb5a5305e0e 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -527,7 +527,7 @@ static void do_qc(struct gfs2_quota_data *qd, int64_t change) int64_t x; down(&sdp->sd_quota_mutex); - gfs2_trans_add_bh(ip->i_gl, qd->qd_bh); + gfs2_trans_add_bh(ip->i_gl, qd->qd_bh, 1); if (!test_bit(QDF_CHANGE, &qd->qd_flags)) { qc->qc_change = 0; diff --git a/fs/gfs2/resize.c b/fs/gfs2/resize.c index 67d26b99a73c..a53096682500 100644 --- a/fs/gfs2/resize.c +++ b/fs/gfs2/resize.c @@ -255,7 +255,7 @@ int gfs2_rename2system(struct gfs2_inode *ip, if (error) goto out_trans; ip->i_di.di_flags |= GFS2_DIF_SYSTEM; - gfs2_trans_add_bh(ip->i_gl, dibh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 8df6fba20fac..87c80bbce1cf 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -967,7 +967,7 @@ static uint32_t rgblk_search(struct gfs2_rgrpd *rgd, uint32_t goal, if (gfs2_assert_withdraw(rgd->rd_sbd, x <= length)) blk = 0; - gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh); + gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); gfs2_setbit(rgd, bi->bi_bh->b_data + bi->bi_offset, bi->bi_len, blk, new_state); @@ -1027,7 +1027,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, uint64_t bstart, bi->bi_bh->b_data + bi->bi_offset, bi->bi_len); } - gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh); + gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); gfs2_setbit(rgd, bi->bi_bh->b_data + bi->bi_offset, bi->bi_len, buf_blk, new_state); @@ -1066,7 +1066,7 @@ uint64_t gfs2_alloc_data(struct gfs2_inode *ip) gfs2_assert_withdraw(sdp, rgd->rd_rg.rg_free); rgd->rd_rg.rg_free--; - gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); al->al_alloced++; @@ -1111,7 +1111,7 @@ uint64_t gfs2_alloc_meta(struct gfs2_inode *ip) gfs2_assert_withdraw(sdp, rgd->rd_rg.rg_free); rgd->rd_rg.rg_free--; - gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); al->al_alloced++; @@ -1153,7 +1153,7 @@ uint64_t gfs2_alloc_di(struct gfs2_inode *dip) rgd->rd_rg.rg_free--; rgd->rd_rg.rg_dinodes++; - gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); al->al_alloced++; @@ -1187,7 +1187,7 @@ void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) rgd->rd_rg.rg_free += blen; - gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); gfs2_trans_add_rg(rgd); @@ -1216,7 +1216,7 @@ void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) rgd->rd_rg.rg_free += blen; - gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); gfs2_trans_add_rg(rgd); @@ -1242,7 +1242,7 @@ void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno) rgd->rd_rg.rg_dinodes--; rgd->rd_rg.rg_free++; - gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh); + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); gfs2_statfs_change(sdp, 0, +1, -1); diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index d37f203e133b..cab7ab5fb506 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -608,7 +608,7 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, return; down(&sdp->sd_statfs_mutex); - gfs2_trans_add_bh(l_ip->i_gl, l_bh); + gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); up(&sdp->sd_statfs_mutex); spin_lock(&sdp->sd_statfs_spin); @@ -659,7 +659,7 @@ int gfs2_statfs_sync(struct gfs2_sbd *sdp) goto out_bh2; down(&sdp->sd_statfs_mutex); - gfs2_trans_add_bh(l_ip->i_gl, l_bh); + gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); up(&sdp->sd_statfs_mutex); spin_lock(&sdp->sd_statfs_spin); @@ -671,7 +671,7 @@ int gfs2_statfs_sync(struct gfs2_sbd *sdp) 0, sizeof(struct gfs2_statfs_change)); spin_unlock(&sdp->sd_statfs_spin); - gfs2_trans_add_bh(m_ip->i_gl, m_bh); + gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1); gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode)); gfs2_trans_end(sdp); diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index afa5408c0008..82952fb64830 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -138,10 +138,11 @@ void gfs2_trans_add_gl(struct gfs2_glock *gl) * gfs2_trans_add_bh - Add a to-be-modified buffer to the current transaction * @gl: the glock the buffer belongs to * @bh: The buffer to add + * @meta: True in the case of adding metadata * */ -void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh) +void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta) { struct gfs2_sbd *sdp = gl->gl_sbd; struct gfs2_bufdata *bd; diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h index ac615e9e8521..5a7da1e853c9 100644 --- a/fs/gfs2/trans.h +++ b/fs/gfs2/trans.h @@ -31,7 +31,7 @@ int gfs2_trans_begin_i(struct gfs2_sbd *sdp, void gfs2_trans_end(struct gfs2_sbd *sdp); void gfs2_trans_add_gl(struct gfs2_glock *gl); -void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh); +void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta); void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, uint64_t blkno); void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, uint64_t blkno); void gfs2_trans_add_rg(struct gfs2_rgrpd *rgd); diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c index 4a993af58c1a..b8d836e3a5c0 100644 --- a/fs/gfs2/unlinked.c +++ b/fs/gfs2/unlinked.c @@ -47,7 +47,7 @@ static int munge_ondisk(struct gfs2_sbd *sdp, unsigned int slot, } down(&sdp->sd_unlinked_mutex); - gfs2_trans_add_bh(ip->i_gl, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_unlinked_tag_out(ut, bh->b_data + sizeof(struct gfs2_meta_header) + offset * sizeof(struct gfs2_unlinked_tag)); From 586dfdaaf328d79bb356d760db963b03a75a4131 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 18 Jan 2006 11:32:00 +0000 Subject: [PATCH 017/292] [GFS2] Make the new argument to gfs2_trans_add_bh() actually do something Passes the flag through to ensure that the correct log operations are invoked when the flag is set. Signed-off-by: Steven Whitehouse: --- fs/gfs2/meta_io.c | 11 +++++++---- fs/gfs2/meta_io.h | 2 +- fs/gfs2/trans.c | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 8bbe11855223..134f31efe515 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -537,13 +537,13 @@ int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags) } /** - * gfs2_meta_attach_bufdata - attach a struct gfs2_bufdata structure to a buffer + * gfs2_attach_bufdata - attach a struct gfs2_bufdata structure to a buffer * @gl: the glock the buffer belongs to * @bh: The buffer to be attached to - * + * @meta: Flag to indicate whether its metadata or not */ -void gfs2_meta_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh) +void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta) { struct gfs2_bufdata *bd; @@ -563,7 +563,10 @@ void gfs2_meta_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh) bd->bd_gl = gl; INIT_LIST_HEAD(&bd->bd_list_tr); - lops_init_le(&bd->bd_le, &gfs2_buf_lops); + if (meta) + lops_init_le(&bd->bd_le, &gfs2_buf_lops); + else + lops_init_le(&bd->bd_le, &gfs2_databuf_lops); set_v2bd(bh, bd); diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index 5556df8cc6c9..10fbf825c110 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h @@ -64,7 +64,7 @@ int gfs2_meta_read(struct gfs2_glock *gl, uint64_t blkno, int flags, struct buffer_head **bhp); int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags); -void gfs2_meta_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh); +void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta); void gfs2_meta_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); void gfs2_meta_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, struct gfs2_ail *ai); diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 82952fb64830..a9df4a34ebad 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -151,7 +151,7 @@ void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta) if (bd) gfs2_assert(sdp, bd->bd_gl == gl); else { - gfs2_meta_attach_bufdata(gl, bh); + gfs2_attach_bufdata(gl, bh, meta); bd = get_v2bd(bh); } From 64fb4eb7d4cc9de89f4d9b9061adde46ed3b5641 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 18 Jan 2006 13:14:40 +0000 Subject: [PATCH 018/292] [GFS2] Remove gfs2_databuf in favour of gfs2_bufdata structure Removing the gfs2_databuf structure and using gfs2_bufdata instead is a step towards allowing journaling of data without requiring the metadata header on each journaled block. The idea is to merge the code paths for ordered data with that of journaled data, with the log operations in lops.c tacking account of the different types of buffers as they are presented to it. Largely the code path for metadata will be similar too, but obviously through a different set of log operations. Signed-off-by: Steven Whitehouse --- fs/gfs2/gfs2.h | 2 -- fs/gfs2/incore.h | 6 ------ fs/gfs2/lops.c | 20 ++++++++++---------- fs/gfs2/ops_address.c | 10 +++++----- fs/gfs2/trans.c | 18 +++++++++--------- 5 files changed, 24 insertions(+), 32 deletions(-) diff --git a/fs/gfs2/gfs2.h b/fs/gfs2/gfs2.h index a5d118238466..6c53d080675c 100644 --- a/fs/gfs2/gfs2.h +++ b/fs/gfs2/gfs2.h @@ -45,8 +45,6 @@ enum { #define set_v2fp(file, fp) (file)->private_data = (fp) #define get_v2bd(bh) ((struct gfs2_bufdata *)(bh)->b_private) #define set_v2bd(bh, bd) (bh)->b_private = (bd) -#define get_v2db(bh) ((struct gfs2_databuf *)(bh)->b_private) -#define set_v2db(bh, db) (bh)->b_private = (db) #define get_transaction ((struct gfs2_trans *)(current->journal_info)) #define set_transaction(tr) (current->journal_info) = (tr) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 3ed0a7f26e45..3bc40ff5fdf9 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -25,7 +25,6 @@ struct gfs2_log_element; struct gfs2_bitmap; struct gfs2_rgrpd; struct gfs2_bufdata; -struct gfs2_databuf; struct gfs2_glock_operations; struct gfs2_holder; struct gfs2_glock; @@ -116,11 +115,6 @@ struct gfs2_bufdata { struct list_head bd_ail_gl_list; }; -struct gfs2_databuf { - struct gfs2_log_element db_le; - struct buffer_head *db_bh; -}; - struct gfs2_glock_operations { void (*go_xmote_th) (struct gfs2_glock * gl, unsigned int state, int flags); diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index d501e8224ed0..efb1087d0fa8 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -442,15 +442,15 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) { struct list_head *head = &sdp->sd_log_le_databuf; LIST_HEAD(started); - struct gfs2_databuf *db; + struct gfs2_bufdata *bd; struct buffer_head *bh; while (!list_empty(head)) { - db = list_entry(head->prev, struct gfs2_databuf, db_le.le_list); - list_move(&db->db_le.le_list, &started); + bd = list_entry(head->prev, struct gfs2_bufdata, bd_le.le_list); + list_move(&bd->bd_le.le_list, &started); gfs2_log_lock(sdp); - bh = db->db_bh; + bh = bd->bd_bh; if (bh) { get_bh(bh); gfs2_log_unlock(sdp); @@ -464,22 +464,22 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) } while (!list_empty(&started)) { - db = list_entry(started.next, struct gfs2_databuf, - db_le.le_list); - list_del(&db->db_le.le_list); + bd = list_entry(started.next, struct gfs2_bufdata, + bd_le.le_list); + list_del(&bd->bd_le.le_list); sdp->sd_log_num_databuf--; gfs2_log_lock(sdp); - bh = db->db_bh; + bh = bd->bd_bh; if (bh) { - set_v2db(bh, NULL); + set_v2bd(bh, NULL); gfs2_log_unlock(sdp); wait_on_buffer(bh); brelse(bh); } else gfs2_log_unlock(sdp); - kfree(db); + kfree(bd); } gfs2_assert_warn(sdp, !sdp->sd_log_num_databuf); diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index d352b3528f5e..db66d3287550 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -429,13 +429,13 @@ static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock) static void discard_buffer(struct gfs2_sbd *sdp, struct buffer_head *bh) { - struct gfs2_databuf *db; + struct gfs2_bufdata *bd; gfs2_log_lock(sdp); - db = get_v2db(bh); - if (db) { - db->db_bh = NULL; - set_v2db(bh, NULL); + bd = get_v2bd(bh); + if (bd) { + bd->bd_bh = NULL; + set_v2bd(bh, NULL); gfs2_log_unlock(sdp); brelse(bh); } else diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index a9df4a34ebad..b014591fa4a4 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -199,17 +199,17 @@ void gfs2_trans_add_rg(struct gfs2_rgrpd *rgd) void gfs2_trans_add_databuf(struct gfs2_sbd *sdp, struct buffer_head *bh) { - struct gfs2_databuf *db; + struct gfs2_bufdata *bd; - db = get_v2db(bh); - if (!db) { - db = kmalloc(sizeof(struct gfs2_databuf), - GFP_KERNEL | __GFP_NOFAIL); - lops_init_le(&db->db_le, &gfs2_databuf_lops); + bd = get_v2bd(bh); + if (!bd) { + bd = kmalloc(sizeof(struct gfs2_bufdata), + GFP_NOFS | __GFP_NOFAIL); + lops_init_le(&bd->bd_le, &gfs2_databuf_lops); get_bh(bh); - db->db_bh = bh; - set_v2db(bh, db); - lops_add(sdp, &db->db_le); + bd->bd_bh = bh; + set_v2bd(bh, bd); + lops_add(sdp, &bd->bd_le); } } From 4f3df04137d426a0ad1758ab744f5b6d658617bf Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 18 Jan 2006 13:20:16 +0000 Subject: [PATCH 019/292] [GFS2] Change memory allocations to GFP_NOFS I'd like to be rid of these memory allocations entirely so far as is possible. For the moment though, mark them GFP_NOFS to make them less harmful. Signed-off-by: Steven Whitehouse --- fs/gfs2/log.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 736d0d33dd1b..f6d00130f96f 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -350,7 +350,7 @@ struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp) struct gfs2_log_buf *lb; struct buffer_head *bh; - lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_KERNEL | __GFP_NOFAIL); + lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_NOFS | __GFP_NOFAIL); list_add(&lb->lb_list, &sdp->sd_log_flush_list); bh = lb->lb_bh = sb_getblk(sdp->sd_vfs, blkno); @@ -380,7 +380,7 @@ struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, struct gfs2_log_buf *lb; struct buffer_head *bh; - lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_KERNEL | __GFP_NOFAIL); + lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_NOFS | __GFP_NOFAIL); list_add(&lb->lb_list, &sdp->sd_log_flush_list); lb->lb_real = real; @@ -510,7 +510,7 @@ void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) atomic_inc(&sdp->sd_log_flush_incore); - ai = kzalloc(sizeof(struct gfs2_ail), GFP_KERNEL | __GFP_NOFAIL); + ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); INIT_LIST_HEAD(&ai->ai_ail1_list); INIT_LIST_HEAD(&ai->ai_ail2_list); From a98ab2204f8ed414c5e95fbca28a9f001c53bc7b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 18 Jan 2006 13:38:44 +0000 Subject: [PATCH 020/292] [GFS2] Rename gfs2_meta_pin to gfs2_pin Since we'll need to pin data if we are going to journal it, then I'm renaming this function to make it less confusing. It might also be worth moving it into lops.c since there are no users outside that file. Signed-off-by: Steven Whitehouse --- fs/gfs2/lops.c | 4 ++-- fs/gfs2/meta_io.c | 10 +++++----- fs/gfs2/meta_io.h | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index efb1087d0fa8..a065f7667238 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -79,7 +79,7 @@ static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) gfs2_trans_add_gl(bd->bd_gl); gfs2_meta_check(sdp, bd->bd_bh); - gfs2_meta_pin(sdp, bd->bd_bh); + gfs2_pin(sdp, bd->bd_bh); gfs2_log_lock(sdp); sdp->sd_log_num_buf++; @@ -169,7 +169,7 @@ static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) list_del_init(&bd->bd_le.le_list); sdp->sd_log_num_buf--; - gfs2_meta_unpin(sdp, bd->bd_bh, ai); + gfs2_unpin(sdp, bd->bd_bh, ai); } gfs2_assert_warn(sdp, !sdp->sd_log_num_buf); } diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 134f31efe515..b6bd2ebfc2cc 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -574,13 +574,13 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta } /** - * gfs2_meta_pin - Pin a metadata buffer in memory + * gfs2_pin - Pin a buffer in memory * @sdp: the filesystem the buffer belongs to * @bh: The buffer to be pinned * */ -void gfs2_meta_pin(struct gfs2_sbd *sdp, struct buffer_head *bh) +void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh) { struct gfs2_bufdata *bd = get_v2bd(bh); @@ -609,15 +609,15 @@ void gfs2_meta_pin(struct gfs2_sbd *sdp, struct buffer_head *bh) } /** - * gfs2_meta_unpin - Unpin a buffer + * gfs2_unpin - Unpin a buffer * @sdp: the filesystem the buffer belongs to * @bh: The buffer to unpin * @ai: * */ -void gfs2_meta_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, - struct gfs2_ail *ai) +void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, + struct gfs2_ail *ai) { struct gfs2_bufdata *bd = get_v2bd(bh); diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index 10fbf825c110..887cac302c1b 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h @@ -65,9 +65,9 @@ int gfs2_meta_read(struct gfs2_glock *gl, uint64_t blkno, int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags); void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta); -void gfs2_meta_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); -void gfs2_meta_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, - struct gfs2_ail *ai); +void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); +void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, + struct gfs2_ail *ai); void gfs2_meta_wipe(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); From ec5800246607183a1d7fd0bae5f087c12439e9e7 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 18 Jan 2006 14:21:40 +0000 Subject: [PATCH 021/292] [DLM] Export config_group_find_obj for use by the DLM Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/configfs/item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/configfs/item.c b/fs/configfs/item.c index e07485ac50ad..24421209f854 100644 --- a/fs/configfs/item.c +++ b/fs/configfs/item.c @@ -224,4 +224,4 @@ EXPORT_SYMBOL(config_item_init); EXPORT_SYMBOL(config_group_init); EXPORT_SYMBOL(config_item_get); EXPORT_SYMBOL(config_item_put); - +EXPORT_SYMBOL(config_group_find_obj); From 901359256b2666f52a3a7d3f31927677e91b3a2a Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 20 Jan 2006 08:47:07 +0000 Subject: [PATCH 022/292] [DLM] Update DLM to the latest patch level Signed-off-by: David Teigland Signed-off-by: Steve Whitehouse --- fs/dlm/ast.c | 16 +++++----- fs/dlm/config.c | 20 ++++++------ fs/dlm/debug_fs.c | 4 +-- fs/dlm/device.c | 55 ++++++++++++++++++++------------- fs/dlm/dir.c | 4 +-- fs/dlm/dlm_internal.h | 23 +++----------- fs/dlm/lock.c | 72 +++++++++++++++++++++---------------------- fs/dlm/lock.h | 4 +-- fs/dlm/lockspace.c | 21 ++++++------- fs/dlm/member.c | 17 +++++----- fs/dlm/midcomms.c | 2 +- fs/dlm/recover.c | 18 +++++------ fs/dlm/recoverd.c | 16 +++++----- fs/dlm/requestqueue.c | 26 ++++++++-------- 14 files changed, 147 insertions(+), 151 deletions(-) diff --git a/fs/dlm/ast.c b/fs/dlm/ast.c index 2bd1c5e1a72c..57bdf09b520a 100644 --- a/fs/dlm/ast.c +++ b/fs/dlm/ast.c @@ -21,7 +21,7 @@ static struct list_head ast_queue; static spinlock_t ast_queue_lock; static struct task_struct * astd_task; static unsigned long astd_wakeflags; -static struct semaphore astd_running; +static struct mutex astd_running; void dlm_del_ast(struct dlm_lkb *lkb) @@ -56,7 +56,7 @@ static void process_asts(void) int type = 0, found, bmode; for (;;) { - found = FALSE; + found = 0; spin_lock(&ast_queue_lock); list_for_each_entry(lkb, &ast_queue, lkb_astqueue) { r = lkb->lkb_resource; @@ -68,7 +68,7 @@ static void process_asts(void) list_del(&lkb->lkb_astqueue); type = lkb->lkb_ast_type; lkb->lkb_ast_type = 0; - found = TRUE; + found = 1; break; } spin_unlock(&ast_queue_lock); @@ -117,10 +117,10 @@ static int dlm_astd(void *data) schedule(); set_current_state(TASK_RUNNING); - down(&astd_running); + mutex_lock(&astd_running); if (test_and_clear_bit(WAKE_ASTS, &astd_wakeflags)) process_asts(); - up(&astd_running); + mutex_unlock(&astd_running); } return 0; } @@ -140,7 +140,7 @@ int dlm_astd_start(void) INIT_LIST_HEAD(&ast_queue); spin_lock_init(&ast_queue_lock); - init_MUTEX(&astd_running); + mutex_init(&astd_running); p = kthread_run(dlm_astd, NULL, "dlm_astd"); if (IS_ERR(p)) @@ -157,11 +157,11 @@ void dlm_astd_stop(void) void dlm_astd_suspend(void) { - down(&astd_running); + mutex_lock(&astd_running); } void dlm_astd_resume(void) { - up(&astd_running); + mutex_unlock(&astd_running); } diff --git a/fs/dlm/config.c b/fs/dlm/config.c index 024ace9973a8..87df9616415e 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c @@ -162,7 +162,7 @@ struct spaces { struct space { struct config_group group; struct list_head members; - struct semaphore members_lock; + struct mutex members_lock; int members_count; }; @@ -374,7 +374,7 @@ static struct config_group *make_space(struct config_group *g, const char *name) sp->group.default_groups[1] = NULL; INIT_LIST_HEAD(&sp->members); - init_MUTEX(&sp->members_lock); + mutex_init(&sp->members_lock); sp->members_count = 0; return &sp->group; @@ -453,10 +453,10 @@ static struct config_item *make_node(struct config_group *g, const char *name) nd->nodeid = -1; nd->weight = 1; /* default weight of 1 if none is set */ - down(&sp->members_lock); + mutex_lock(&sp->members_lock); list_add(&nd->list, &sp->members); sp->members_count++; - up(&sp->members_lock); + mutex_unlock(&sp->members_lock); return &nd->item; } @@ -466,10 +466,10 @@ static void drop_node(struct config_group *g, struct config_item *i) struct space *sp = to_space(g->cg_item.ci_parent); struct node *nd = to_node(i); - down(&sp->members_lock); + mutex_lock(&sp->members_lock); list_del(&nd->list); sp->members_count--; - up(&sp->members_lock); + mutex_unlock(&sp->members_lock); config_item_put(i); } @@ -677,7 +677,7 @@ int dlm_nodeid_list(char *lsname, int **ids_out) if (!sp) return -EEXIST; - down(&sp->members_lock); + mutex_lock(&sp->members_lock); if (!sp->members_count) { rv = 0; goto out; @@ -698,7 +698,7 @@ int dlm_nodeid_list(char *lsname, int **ids_out) *ids_out = ids; out: - up(&sp->members_lock); + mutex_unlock(&sp->members_lock); put_space(sp); return rv; } @@ -713,14 +713,14 @@ int dlm_node_weight(char *lsname, int nodeid) if (!sp) goto out; - down(&sp->members_lock); + mutex_lock(&sp->members_lock); list_for_each_entry(nd, &sp->members, list) { if (nd->nodeid != nodeid) continue; w = nd->weight; break; } - up(&sp->members_lock); + mutex_unlock(&sp->members_lock); put_space(sp); out: return w; diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index 98b49a1ece47..5080bbffd586 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -63,12 +63,12 @@ static void print_lock(struct seq_file *s, struct dlm_lkb *lkb, /* FIXME: this warns on Alpha */ if (lkb->lkb_status == DLM_LKSTS_CONVERT || lkb->lkb_status == DLM_LKSTS_GRANTED) - seq_printf(s, " %" PRIx64 "-%" PRIx64, + seq_printf(s, " %llx-%llx", lkb->lkb_range[GR_RANGE_START], lkb->lkb_range[GR_RANGE_END]); if (lkb->lkb_status == DLM_LKSTS_CONVERT || lkb->lkb_status == DLM_LKSTS_WAITING) - seq_printf(s, " (%" PRIx64 "-%" PRIx64 ")", + seq_printf(s, " (%llx-%llx)", lkb->lkb_range[RQ_RANGE_START], lkb->lkb_range[RQ_RANGE_END]); } diff --git a/fs/dlm/device.c b/fs/dlm/device.c index a8bf600ed13d..899d4f92a4d7 100644 --- a/fs/dlm/device.c +++ b/fs/dlm/device.c @@ -43,7 +43,7 @@ static struct file_operations _dlm_fops; static const char *name_prefix="dlm"; static struct list_head user_ls_list; -static struct semaphore user_ls_lock; +static struct mutex user_ls_lock; /* Lock infos are stored in here indexed by lock ID */ static DEFINE_IDR(lockinfo_idr); @@ -53,6 +53,7 @@ static rwlock_t lockinfo_lock; #define LI_FLAG_COMPLETE 1 #define LI_FLAG_FIRSTLOCK 2 #define LI_FLAG_PERSISTENT 3 +#define LI_FLAG_ONLIST 4 /* flags in ls_flags*/ #define LS_FLAG_DELETED 1 @@ -211,18 +212,18 @@ static struct user_ls *find_lockspace(int minor) { struct user_ls *lsinfo; - down(&user_ls_lock); + mutex_lock(&user_ls_lock); lsinfo = __find_lockspace(minor); - up(&user_ls_lock); + mutex_unlock(&user_ls_lock); return lsinfo; } static void add_lockspace_to_list(struct user_ls *lsinfo) { - down(&user_ls_lock); + mutex_lock(&user_ls_lock); list_add(&lsinfo->ls_list, &user_ls_list); - up(&user_ls_lock); + mutex_unlock(&user_ls_lock); } /* Register a lockspace with the DLM and create a misc @@ -235,12 +236,11 @@ static int register_lockspace(char *name, struct user_ls **ls, int flags) namelen = strlen(name)+strlen(name_prefix)+2; - newls = kmalloc(sizeof(struct user_ls), GFP_KERNEL); + newls = kzalloc(sizeof(struct user_ls), GFP_KERNEL); if (!newls) return -ENOMEM; - memset(newls, 0, sizeof(struct user_ls)); - newls->ls_miscinfo.name = kmalloc(namelen, GFP_KERNEL); + newls->ls_miscinfo.name = kzalloc(namelen, GFP_KERNEL); if (!newls->ls_miscinfo.name) { kfree(newls); return -ENOMEM; @@ -277,7 +277,7 @@ static int register_lockspace(char *name, struct user_ls **ls, int flags) return 0; } -/* Called with the user_ls_lock semaphore held */ +/* Called with the user_ls_lock mutex held */ static int unregister_lockspace(struct user_ls *lsinfo, int force) { int status; @@ -305,11 +305,10 @@ static int unregister_lockspace(struct user_ls *lsinfo, int force) static void add_to_astqueue(struct lock_info *li, void *astaddr, void *astparam, int lvb_updated) { - struct ast_info *ast = kmalloc(sizeof(struct ast_info), GFP_KERNEL); + struct ast_info *ast = kzalloc(sizeof(struct ast_info), GFP_KERNEL); if (!ast) return; - memset(ast, 0, sizeof(*ast)); ast->result.user_astparam = astparam; ast->result.user_astaddr = astaddr; ast->result.user_lksb = li->li_user_lksb; @@ -382,6 +381,7 @@ static void ast_routine(void *param) spin_lock(&li->li_file->fi_li_lock); list_del(&li->li_ownerqueue); + clear_bit(LI_FLAG_ONLIST, &li->li_flags); spin_unlock(&li->li_file->fi_li_lock); release_lockinfo(li); return; @@ -437,7 +437,7 @@ static int dlm_open(struct inode *inode, struct file *file) if (!lsinfo) return -ENOENT; - f = kmalloc(sizeof(struct file_info), GFP_KERNEL); + f = kzalloc(sizeof(struct file_info), GFP_KERNEL); if (!f) return -ENOMEM; @@ -570,7 +570,7 @@ static int dlm_close(struct inode *inode, struct file *file) * then free the struct. If it's an AUTOFREE lockspace * then free the whole thing. */ - down(&user_ls_lock); + mutex_lock(&user_ls_lock); if (atomic_dec_and_test(&lsinfo->ls_refcnt)) { if (lsinfo->ls_lockspace) { @@ -582,7 +582,7 @@ static int dlm_close(struct inode *inode, struct file *file) kfree(lsinfo); } } - up(&user_ls_lock); + mutex_unlock(&user_ls_lock); put_file_info(f); /* Restore signals */ @@ -620,10 +620,10 @@ static int do_user_remove_lockspace(struct file_info *fi, uint8_t cmd, if (!capable(CAP_SYS_ADMIN)) return -EPERM; - down(&user_ls_lock); + mutex_lock(&user_ls_lock); lsinfo = __find_lockspace(kparams->minor); if (!lsinfo) { - up(&user_ls_lock); + mutex_unlock(&user_ls_lock); return -EINVAL; } @@ -631,7 +631,7 @@ static int do_user_remove_lockspace(struct file_info *fi, uint8_t cmd, force = 2; status = unregister_lockspace(lsinfo, force); - up(&user_ls_lock); + mutex_unlock(&user_ls_lock); return status; } @@ -752,7 +752,7 @@ static struct lock_info *allocate_lockinfo(struct file_info *fi, uint8_t cmd, if (!try_module_get(THIS_MODULE)) return NULL; - li = kmalloc(sizeof(struct lock_info), GFP_KERNEL); + li = kzalloc(sizeof(struct lock_info), GFP_KERNEL); if (li) { li->li_magic = LOCKINFO_MAGIC; li->li_file = fi; @@ -800,8 +800,10 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, /* If this is a persistent lock we will have to create a lockinfo again */ - if (!li && DLM_LKF_PERSISTENT) { + if (!li && (kparams->flags & DLM_LKF_PERSISTENT)) { li = allocate_lockinfo(fi, cmd, kparams); + if (!li) + return -ENOMEM; li->li_lksb.sb_lkid = kparams->lkid; li->li_castaddr = kparams->castaddr; @@ -887,6 +889,7 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, spin_lock(&fi->fi_li_lock); list_add(&li->li_ownerqueue, &fi->fi_li_list); + set_bit(LI_FLAG_ONLIST, &li->li_flags); spin_unlock(&fi->fi_li_lock); if (add_lockinfo(li)) printk(KERN_WARNING "Add lockinfo failed\n"); @@ -914,12 +917,13 @@ static int do_user_unlock(struct file_info *fi, uint8_t cmd, li = get_lockinfo(kparams->lkid); if (!li) { li = allocate_lockinfo(fi, cmd, kparams); + if (!li) + return -ENOMEM; spin_lock(&fi->fi_li_lock); list_add(&li->li_ownerqueue, &fi->fi_li_list); + set_bit(LI_FLAG_ONLIST, &li->li_flags); spin_unlock(&fi->fi_li_lock); } - if (!li) - return -ENOMEM; if (li->li_magic != LOCKINFO_MAGIC) return -EINVAL; @@ -932,6 +936,12 @@ static int do_user_unlock(struct file_info *fi, uint8_t cmd, if (kparams->flags & DLM_LKF_CANCEL && li->li_grmode != -1) convert_cancel = 1; + /* Wait until dlm_lock() has completed */ + if (!test_bit(LI_FLAG_ONLIST, &li->li_flags)) { + down(&li->li_firstlock); + up(&li->li_firstlock); + } + /* dlm_unlock() passes a 0 for castaddr which means don't overwrite the existing li_castaddr as that's the completion routine for unlocks. dlm_unlock_wait() specifies a new AST routine to be @@ -947,6 +957,7 @@ static int do_user_unlock(struct file_info *fi, uint8_t cmd, if (!status && !convert_cancel) { spin_lock(&fi->fi_li_lock); list_del(&li->li_ownerqueue); + clear_bit(LI_FLAG_ONLIST, &li->li_flags); spin_unlock(&fi->fi_li_lock); } @@ -1055,7 +1066,7 @@ static int __init dlm_device_init(void) int r; INIT_LIST_HEAD(&user_ls_list); - init_MUTEX(&user_ls_lock); + mutex_init(&user_ls_lock); rwlock_init(&lockinfo_lock); ctl_device.name = "dlm-control"; diff --git a/fs/dlm/dir.c b/fs/dlm/dir.c index 0f1dde54bcd2..46754553fdcc 100644 --- a/fs/dlm/dir.c +++ b/fs/dlm/dir.c @@ -33,7 +33,7 @@ static void put_free_de(struct dlm_ls *ls, struct dlm_direntry *de) static struct dlm_direntry *get_free_de(struct dlm_ls *ls, int len) { - int found = FALSE; + int found = 0; struct dlm_direntry *de; spin_lock(&ls->ls_recover_list_lock); @@ -42,7 +42,7 @@ static struct dlm_direntry *get_free_de(struct dlm_ls *ls, int len) list_del(&de->list); de->master_nodeid = 0; memset(de->name, 0, len); - found = TRUE; + found = 1; break; } } diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index 0020cd07baf7..16f20cfd9197 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -42,20 +43,6 @@ #define DLM_LOCKSPACE_LEN 64 -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#if (BITS_PER_LONG == 64) -#define PRIx64 "lx" -#else -#define PRIx64 "Lx" -#endif - /* Size of the temp buffer midcomms allocates on the stack. We try to make this large enough so most messages fit. FIXME: should sctp make this unnecessary? */ @@ -266,7 +253,7 @@ struct dlm_lkb { struct dlm_rsb { struct dlm_ls *res_ls; /* the lockspace */ struct kref res_ref; - struct semaphore res_sem; + struct mutex res_mutex; unsigned long res_flags; int res_length; /* length of rsb name */ int res_nodeid; @@ -449,7 +436,7 @@ struct dlm_ls { struct dlm_dirtable *ls_dirtbl; uint32_t ls_dirtbl_size; - struct semaphore ls_waiters_sem; + struct mutex ls_waiters_mutex; struct list_head ls_waiters; /* lkbs needing a reply */ struct list_head ls_nodes; /* current nodes in ls */ @@ -472,14 +459,14 @@ struct dlm_ls { struct timer_list ls_timer; struct task_struct *ls_recoverd_task; - struct semaphore ls_recoverd_active; + struct mutex ls_recoverd_active; spinlock_t ls_recover_lock; uint32_t ls_recover_status; /* DLM_RS_ */ uint64_t ls_recover_seq; struct dlm_recover *ls_recover_args; struct rw_semaphore ls_in_recovery; /* block local requests */ struct list_head ls_requestqueue;/* queue remote requests */ - struct semaphore ls_requestqueue_lock; + struct mutex ls_requestqueue_mutex; char *ls_recover_buf; struct list_head ls_recover_list; spinlock_t ls_recover_list_lock; diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 81efb361f95d..29d3b95dbb63 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -215,15 +215,15 @@ static inline int is_master_copy(struct dlm_lkb *lkb) { if (lkb->lkb_flags & DLM_IFL_MSTCPY) DLM_ASSERT(lkb->lkb_nodeid, dlm_print_lkb(lkb);); - return (lkb->lkb_flags & DLM_IFL_MSTCPY) ? TRUE : FALSE; + return (lkb->lkb_flags & DLM_IFL_MSTCPY) ? 1 : 0; } static inline int middle_conversion(struct dlm_lkb *lkb) { if ((lkb->lkb_grmode==DLM_LOCK_PR && lkb->lkb_rqmode==DLM_LOCK_CW) || (lkb->lkb_rqmode==DLM_LOCK_PR && lkb->lkb_grmode==DLM_LOCK_CW)) - return TRUE; - return FALSE; + return 1; + return 0; } static inline int down_conversion(struct dlm_lkb *lkb) @@ -269,7 +269,7 @@ static struct dlm_rsb *create_rsb(struct dlm_ls *ls, char *name, int len) r->res_ls = ls; r->res_length = len; memcpy(r->res_name, name, len); - init_MUTEX(&r->res_sem); + mutex_init(&r->res_mutex); INIT_LIST_HEAD(&r->res_lookup); INIT_LIST_HEAD(&r->res_grantqueue); @@ -712,7 +712,7 @@ static void add_to_waiters(struct dlm_lkb *lkb, int mstype) { struct dlm_ls *ls = lkb->lkb_resource->res_ls; - down(&ls->ls_waiters_sem); + mutex_lock(&ls->ls_waiters_mutex); if (lkb->lkb_wait_type) { log_print("add_to_waiters error %d", lkb->lkb_wait_type); goto out; @@ -721,7 +721,7 @@ static void add_to_waiters(struct dlm_lkb *lkb, int mstype) kref_get(&lkb->lkb_ref); list_add(&lkb->lkb_wait_reply, &ls->ls_waiters); out: - up(&ls->ls_waiters_sem); + mutex_unlock(&ls->ls_waiters_mutex); } static int _remove_from_waiters(struct dlm_lkb *lkb) @@ -745,9 +745,9 @@ static int remove_from_waiters(struct dlm_lkb *lkb) struct dlm_ls *ls = lkb->lkb_resource->res_ls; int error; - down(&ls->ls_waiters_sem); + mutex_lock(&ls->ls_waiters_mutex); error = _remove_from_waiters(lkb); - up(&ls->ls_waiters_sem); + mutex_unlock(&ls->ls_waiters_mutex); return error; } @@ -775,14 +775,14 @@ static int shrink_bucket(struct dlm_ls *ls, int b) int count = 0, found; for (;;) { - found = FALSE; + found = 0; write_lock(&ls->ls_rsbtbl[b].lock); list_for_each_entry_reverse(r, &ls->ls_rsbtbl[b].toss, res_hashchain) { if (!time_after_eq(jiffies, r->res_toss_time + dlm_config.toss_secs * HZ)) continue; - found = TRUE; + found = 1; break; } @@ -1027,9 +1027,9 @@ static inline int first_in_list(struct dlm_lkb *lkb, struct list_head *head) struct dlm_lkb *first = list_entry(head->next, struct dlm_lkb, lkb_statequeue); if (lkb->lkb_id == first->lkb_id) - return TRUE; + return 1; - return FALSE; + return 0; } /* Return 1 if the locks' ranges overlap. If the lkb has no range then it is @@ -1038,13 +1038,13 @@ static inline int first_in_list(struct dlm_lkb *lkb, struct list_head *head) static inline int ranges_overlap(struct dlm_lkb *lkb1, struct dlm_lkb *lkb2) { if (!lkb1->lkb_range || !lkb2->lkb_range) - return TRUE; + return 1; if (lkb1->lkb_range[RQ_RANGE_END] < lkb2->lkb_range[GR_RANGE_START] || lkb1->lkb_range[RQ_RANGE_START] > lkb2->lkb_range[GR_RANGE_END]) - return FALSE; + return 0; - return TRUE; + return 1; } /* Check if the given lkb conflicts with another lkb on the queue. */ @@ -1057,9 +1057,9 @@ static int queue_conflict(struct list_head *head, struct dlm_lkb *lkb) if (this == lkb) continue; if (ranges_overlap(lkb, this) && !modes_compat(this, lkb)) - return TRUE; + return 1; } - return FALSE; + return 0; } /* @@ -1103,7 +1103,7 @@ static int conversion_deadlock_detect(struct dlm_rsb *rsb, struct dlm_lkb *lkb) continue; if (!modes_compat(this, lkb) && !modes_compat(lkb, this)) - return TRUE; + return 1; } /* if lkb is on the convert queue and is preventing the first @@ -1114,10 +1114,10 @@ static int conversion_deadlock_detect(struct dlm_rsb *rsb, struct dlm_lkb *lkb) if (self && self != first) { if (!modes_compat(lkb, first) && !queue_conflict(&rsb->res_grantqueue, first)) - return TRUE; + return 1; } - return FALSE; + return 0; } /* @@ -1157,7 +1157,7 @@ static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) */ if (lkb->lkb_exflags & DLM_LKF_EXPEDITE) - return TRUE; + return 1; /* * A shortcut. Without this, !queue_conflict(grantqueue, lkb) would be @@ -1200,7 +1200,7 @@ static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) */ if (now && conv && !(lkb->lkb_exflags & DLM_LKF_QUECVT)) - return TRUE; + return 1; /* * When using range locks the NOORDER flag is set to avoid the standard @@ -1208,7 +1208,7 @@ static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) */ if (lkb->lkb_exflags & DLM_LKF_NOORDER) - return TRUE; + return 1; /* * 6-3: Once in that queue [CONVERTING], a conversion request cannot be @@ -1217,7 +1217,7 @@ static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) */ if (!now && conv && first_in_list(lkb, &r->res_convertqueue)) - return TRUE; + return 1; /* * 6-4: By default, a new request is immediately granted only if all @@ -1232,7 +1232,7 @@ static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) if (now && !conv && list_empty(&r->res_convertqueue) && list_empty(&r->res_waitqueue)) - return TRUE; + return 1; /* * 6-4: Once a lock request is in the queue of ungranted new requests, @@ -1244,7 +1244,7 @@ static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) if (!now && !conv && list_empty(&r->res_convertqueue) && first_in_list(lkb, &r->res_waitqueue)) - return TRUE; + return 1; out: /* @@ -1257,7 +1257,7 @@ static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) lkb->lkb_sbflags |= DLM_SBF_DEMOTED; } - return FALSE; + return 0; } /* @@ -1308,7 +1308,7 @@ static int grant_pending_convert(struct dlm_rsb *r, int high) list_for_each_entry_safe(lkb, s, &r->res_convertqueue, lkb_statequeue) { demoted = is_demoted(lkb); - if (can_be_granted(r, lkb, FALSE)) { + if (can_be_granted(r, lkb, 0)) { grant_lock_pending(r, lkb); grant_restart = 1; } else { @@ -1333,7 +1333,7 @@ static int grant_pending_wait(struct dlm_rsb *r, int high) struct dlm_lkb *lkb, *s; list_for_each_entry_safe(lkb, s, &r->res_waitqueue, lkb_statequeue) { - if (can_be_granted(r, lkb, FALSE)) + if (can_be_granted(r, lkb, 0)) grant_lock_pending(r, lkb); else high = max_t(int, lkb->lkb_rqmode, high); @@ -1705,7 +1705,7 @@ static int do_request(struct dlm_rsb *r, struct dlm_lkb *lkb) { int error = 0; - if (can_be_granted(r, lkb, TRUE)) { + if (can_be_granted(r, lkb, 1)) { grant_lock(r, lkb); queue_cast(r, lkb, 0); goto out; @@ -1733,7 +1733,7 @@ static int do_convert(struct dlm_rsb *r, struct dlm_lkb *lkb) /* changing an existing lock may allow others to be granted */ - if (can_be_granted(r, lkb, TRUE)) { + if (can_be_granted(r, lkb, 1)) { grant_lock(r, lkb); queue_cast(r, lkb, 0); grant_pending_locks(r); @@ -2556,7 +2556,7 @@ static void receive_convert(struct dlm_ls *ls, struct dlm_message *ms) { struct dlm_lkb *lkb; struct dlm_rsb *r; - int error, reply = TRUE; + int error, reply = 1; error = find_lkb(ls, ms->m_remid, &lkb); if (error) @@ -3205,7 +3205,7 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls) { struct dlm_lkb *lkb, *safe; - down(&ls->ls_waiters_sem); + mutex_lock(&ls->ls_waiters_mutex); list_for_each_entry_safe(lkb, safe, &ls->ls_waiters, lkb_wait_reply) { log_debug(ls, "pre recover waiter lkid %x type %d flags %x", @@ -3253,7 +3253,7 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls) lkb->lkb_wait_type); } } - up(&ls->ls_waiters_sem); + mutex_unlock(&ls->ls_waiters_mutex); } static int remove_resend_waiter(struct dlm_ls *ls, struct dlm_lkb **lkb_ret) @@ -3261,7 +3261,7 @@ static int remove_resend_waiter(struct dlm_ls *ls, struct dlm_lkb **lkb_ret) struct dlm_lkb *lkb; int rv = 0; - down(&ls->ls_waiters_sem); + mutex_lock(&ls->ls_waiters_mutex); list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) { if (lkb->lkb_flags & DLM_IFL_RESEND) { rv = lkb->lkb_wait_type; @@ -3270,7 +3270,7 @@ static int remove_resend_waiter(struct dlm_ls *ls, struct dlm_lkb **lkb_ret) break; } } - up(&ls->ls_waiters_sem); + mutex_unlock(&ls->ls_waiters_mutex); if (!rv) lkb = NULL; diff --git a/fs/dlm/lock.h b/fs/dlm/lock.h index 9e6499f773da..bffab9c88b1d 100644 --- a/fs/dlm/lock.h +++ b/fs/dlm/lock.h @@ -38,12 +38,12 @@ static inline int is_master(struct dlm_rsb *r) static inline void lock_rsb(struct dlm_rsb *r) { - down(&r->res_sem); + mutex_lock(&r->res_mutex); } static inline void unlock_rsb(struct dlm_rsb *r) { - up(&r->res_sem); + mutex_unlock(&r->res_mutex); } #endif diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index fee4659b6582..d2ff505d51cd 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -31,7 +31,7 @@ static inline void dlm_delete_debug_file(struct dlm_ls *ls) { } #endif static int ls_count; -static struct semaphore ls_lock; +static struct mutex ls_lock; static struct list_head lslist; static spinlock_t lslist_lock; static struct task_struct * scand_task; @@ -177,7 +177,7 @@ int dlm_lockspace_init(void) int error; ls_count = 0; - init_MUTEX(&ls_lock); + mutex_init(&ls_lock); INIT_LIST_HEAD(&lslist); spin_lock_init(&lslist_lock); @@ -351,10 +351,9 @@ static int new_lockspace(char *name, int namelen, void **lockspace, return -EEXIST; } - ls = kmalloc(sizeof(struct dlm_ls) + namelen, GFP_KERNEL); + ls = kzalloc(sizeof(struct dlm_ls) + namelen, GFP_KERNEL); if (!ls) goto out; - memset(ls, 0, sizeof(struct dlm_ls) + namelen); memcpy(ls->ls_name, name, namelen); ls->ls_namelen = namelen; ls->ls_exflags = flags; @@ -398,7 +397,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace, } INIT_LIST_HEAD(&ls->ls_waiters); - init_MUTEX(&ls->ls_waiters_sem); + mutex_init(&ls->ls_waiters_mutex); INIT_LIST_HEAD(&ls->ls_nodes); INIT_LIST_HEAD(&ls->ls_nodes_gone); @@ -416,14 +415,14 @@ static int new_lockspace(char *name, int namelen, void **lockspace, ls->ls_uevent_result = 0; ls->ls_recoverd_task = NULL; - init_MUTEX(&ls->ls_recoverd_active); + mutex_init(&ls->ls_recoverd_active); spin_lock_init(&ls->ls_recover_lock); ls->ls_recover_status = 0; ls->ls_recover_seq = 0; ls->ls_recover_args = NULL; init_rwsem(&ls->ls_in_recovery); INIT_LIST_HEAD(&ls->ls_requestqueue); - init_MUTEX(&ls->ls_requestqueue_lock); + mutex_init(&ls->ls_requestqueue_mutex); ls->ls_recover_buf = kmalloc(dlm_config.buffer_size, GFP_KERNEL); if (!ls->ls_recover_buf) @@ -493,7 +492,7 @@ int dlm_new_lockspace(char *name, int namelen, void **lockspace, { int error = 0; - down(&ls_lock); + mutex_lock(&ls_lock); if (!ls_count) error = threads_start(); if (error) @@ -503,7 +502,7 @@ int dlm_new_lockspace(char *name, int namelen, void **lockspace, if (!error) ls_count++; out: - up(&ls_lock); + mutex_unlock(&ls_lock); return error; } @@ -629,11 +628,11 @@ static int release_lockspace(struct dlm_ls *ls, int force) kobject_unregister(&ls->ls_kobj); kfree(ls); - down(&ls_lock); + mutex_lock(&ls_lock); ls_count--; if (!ls_count) threads_stop(); - up(&ls_lock); + mutex_unlock(&ls_lock); module_put(THIS_MODULE); return 0; diff --git a/fs/dlm/member.c b/fs/dlm/member.c index 439249b62a57..926cd0cb6bff 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -52,7 +52,7 @@ static int dlm_add_member(struct dlm_ls *ls, int nodeid) struct dlm_member *memb; int w; - memb = kmalloc(sizeof(struct dlm_member), GFP_KERNEL); + memb = kzalloc(sizeof(struct dlm_member), GFP_KERNEL); if (!memb) return -ENOMEM; @@ -79,9 +79,9 @@ static int dlm_is_member(struct dlm_ls *ls, int nodeid) list_for_each_entry(memb, &ls->ls_nodes, list) { if (memb->nodeid == nodeid) - return TRUE; + return 1; } - return FALSE; + return 0; } int dlm_is_removed(struct dlm_ls *ls, int nodeid) @@ -90,9 +90,9 @@ int dlm_is_removed(struct dlm_ls *ls, int nodeid) list_for_each_entry(memb, &ls->ls_nodes_gone, list) { if (memb->nodeid == nodeid) - return TRUE; + return 1; } - return FALSE; + return 0; } static void clear_memb_list(struct list_head *head) @@ -178,10 +178,10 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out) /* move departed members from ls_nodes to ls_nodes_gone */ list_for_each_entry_safe(memb, safe, &ls->ls_nodes, list) { - found = FALSE; + found = 0; for (i = 0; i < rv->node_count; i++) { if (memb->nodeid == rv->nodeids[i]) { - found = TRUE; + found = 1; break; } } @@ -271,10 +271,9 @@ int dlm_ls_start(struct dlm_ls *ls) int *ids = NULL; int error, count; - rv = kmalloc(sizeof(struct dlm_recover), GFP_KERNEL); + rv = kzalloc(sizeof(struct dlm_recover), GFP_KERNEL); if (!rv) return -ENOMEM; - memset(rv, 0, sizeof(struct dlm_recover)); error = count = dlm_nodeid_list(ls->ls_name, &ids); if (error <= 0) diff --git a/fs/dlm/midcomms.c b/fs/dlm/midcomms.c index d96f9bbb407c..c9b1c3d535f4 100644 --- a/fs/dlm/midcomms.c +++ b/fs/dlm/midcomms.c @@ -119,7 +119,7 @@ int dlm_process_incoming_buffer(int nodeid, const void *base, switch (msg->h_cmd) { case DLM_MSG: - dlm_receive_message(msg, nodeid, FALSE); + dlm_receive_message(msg, nodeid, 0); break; case DLM_RCOM: diff --git a/fs/dlm/recover.c b/fs/dlm/recover.c index 1712c97bc229..b036ee7dcb32 100644 --- a/fs/dlm/recover.c +++ b/fs/dlm/recover.c @@ -420,7 +420,7 @@ int dlm_recover_master_reply(struct dlm_ls *ls, struct dlm_rcom *rc) r = recover_list_find(ls, rc->rc_id); if (!r) { - log_error(ls, "dlm_recover_master_reply no id %"PRIx64"", + log_error(ls, "dlm_recover_master_reply no id %llx", rc->rc_id); goto out; } @@ -477,8 +477,8 @@ static int all_queues_empty(struct dlm_rsb *r) if (!list_empty(&r->res_grantqueue) || !list_empty(&r->res_convertqueue) || !list_empty(&r->res_waitqueue)) - return FALSE; - return TRUE; + return 0; + return 1; } static int recover_locks(struct dlm_rsb *r) @@ -586,18 +586,18 @@ static void recover_lvb(struct dlm_rsb *r) { struct dlm_lkb *lkb, *high_lkb = NULL; uint32_t high_seq = 0; - int lock_lvb_exists = FALSE; - int big_lock_exists = FALSE; + int lock_lvb_exists = 0; + int big_lock_exists = 0; int lvblen = r->res_ls->ls_lvblen; list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) { if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) continue; - lock_lvb_exists = TRUE; + lock_lvb_exists = 1; if (lkb->lkb_grmode > DLM_LOCK_CR) { - big_lock_exists = TRUE; + big_lock_exists = 1; goto setflag; } @@ -611,10 +611,10 @@ static void recover_lvb(struct dlm_rsb *r) if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) continue; - lock_lvb_exists = TRUE; + lock_lvb_exists = 1; if (lkb->lkb_grmode > DLM_LOCK_CR) { - big_lock_exists = TRUE; + big_lock_exists = 1; goto setflag; } diff --git a/fs/dlm/recoverd.c b/fs/dlm/recoverd.c index 06e4f7cab6e7..70103533677d 100644 --- a/fs/dlm/recoverd.c +++ b/fs/dlm/recoverd.c @@ -45,9 +45,9 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv) unsigned long start; int error, neg = 0; - log_debug(ls, "recover %"PRIx64"", rv->seq); + log_debug(ls, "recover %llx", rv->seq); - down(&ls->ls_recoverd_active); + mutex_lock(&ls->ls_recoverd_active); /* * Suspending and resuming dlm_astd ensures that no lkb's from this ls @@ -199,16 +199,16 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv) dlm_astd_wake(); - log_debug(ls, "recover %"PRIx64" done: %u ms", rv->seq, + log_debug(ls, "recover %llx done: %u ms", rv->seq, jiffies_to_msecs(jiffies - start)); - up(&ls->ls_recoverd_active); + mutex_unlock(&ls->ls_recoverd_active); return 0; fail: dlm_release_root_list(ls); - log_debug(ls, "recover %"PRIx64" error %d", rv->seq, error); - up(&ls->ls_recoverd_active); + log_debug(ls, "recover %llx error %d", rv->seq, error); + mutex_unlock(&ls->ls_recoverd_active); return error; } @@ -275,11 +275,11 @@ void dlm_recoverd_stop(struct dlm_ls *ls) void dlm_recoverd_suspend(struct dlm_ls *ls) { - down(&ls->ls_recoverd_active); + mutex_lock(&ls->ls_recoverd_active); } void dlm_recoverd_resume(struct dlm_ls *ls) { - up(&ls->ls_recoverd_active); + mutex_unlock(&ls->ls_recoverd_active); } diff --git a/fs/dlm/requestqueue.c b/fs/dlm/requestqueue.c index 36afe99e4f93..7b2b089634a2 100644 --- a/fs/dlm/requestqueue.c +++ b/fs/dlm/requestqueue.c @@ -47,9 +47,9 @@ void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, struct dlm_header *hd) e->nodeid = nodeid; memcpy(e->request, hd, length); - down(&ls->ls_requestqueue_lock); + mutex_lock(&ls->ls_requestqueue_mutex); list_add_tail(&e->list, &ls->ls_requestqueue); - up(&ls->ls_requestqueue_lock); + mutex_unlock(&ls->ls_requestqueue_mutex); } int dlm_process_requestqueue(struct dlm_ls *ls) @@ -58,19 +58,19 @@ int dlm_process_requestqueue(struct dlm_ls *ls) struct dlm_header *hd; int error = 0; - down(&ls->ls_requestqueue_lock); + mutex_lock(&ls->ls_requestqueue_mutex); for (;;) { if (list_empty(&ls->ls_requestqueue)) { - up(&ls->ls_requestqueue_lock); + mutex_unlock(&ls->ls_requestqueue_mutex); error = 0; break; } e = list_entry(ls->ls_requestqueue.next, struct rq_entry, list); - up(&ls->ls_requestqueue_lock); + mutex_unlock(&ls->ls_requestqueue_mutex); hd = (struct dlm_header *) e->request; - error = dlm_receive_message(hd, e->nodeid, TRUE); + error = dlm_receive_message(hd, e->nodeid, 1); if (error == -EINTR) { /* entry is left on requestqueue */ @@ -78,13 +78,13 @@ int dlm_process_requestqueue(struct dlm_ls *ls) break; } - down(&ls->ls_requestqueue_lock); + mutex_lock(&ls->ls_requestqueue_mutex); list_del(&e->list); kfree(e); if (dlm_locking_stopped(ls)) { log_debug(ls, "process_requestqueue abort running"); - up(&ls->ls_requestqueue_lock); + mutex_unlock(&ls->ls_requestqueue_mutex); error = -EINTR; break; } @@ -105,15 +105,15 @@ int dlm_process_requestqueue(struct dlm_ls *ls) void dlm_wait_requestqueue(struct dlm_ls *ls) { for (;;) { - down(&ls->ls_requestqueue_lock); + mutex_lock(&ls->ls_requestqueue_mutex); if (list_empty(&ls->ls_requestqueue)) break; if (dlm_locking_stopped(ls)) break; - up(&ls->ls_requestqueue_lock); + mutex_unlock(&ls->ls_requestqueue_mutex); schedule(); } - up(&ls->ls_requestqueue_lock); + mutex_unlock(&ls->ls_requestqueue_mutex); } static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid) @@ -170,7 +170,7 @@ void dlm_purge_requestqueue(struct dlm_ls *ls) struct dlm_message *ms; struct rq_entry *e, *safe; - down(&ls->ls_requestqueue_lock); + mutex_lock(&ls->ls_requestqueue_mutex); list_for_each_entry_safe(e, safe, &ls->ls_requestqueue, list) { ms = (struct dlm_message *) e->request; @@ -179,6 +179,6 @@ void dlm_purge_requestqueue(struct dlm_ls *ls) kfree(e); } } - up(&ls->ls_requestqueue_lock); + mutex_unlock(&ls->ls_requestqueue_mutex); } From 8ca05c60de49c3bb523a435abc216b6b6eeb1067 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 24 Jan 2006 10:03:04 +0000 Subject: [PATCH 023/292] [GFS2] Update ioctl() numbering to use official numbers. This patch adds us into the official ioctl-number.txt registry and updates GFS2 accordingly. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- Documentation/ioctl-number.txt | 1 + include/linux/gfs2_ioctl.h | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Documentation/ioctl-number.txt b/Documentation/ioctl-number.txt index aa7ba00ec082..7d5ce496f39f 100644 --- a/Documentation/ioctl-number.txt +++ b/Documentation/ioctl-number.txt @@ -126,6 +126,7 @@ Code Seq# Include File Comments 'e' 00-1F linux/video_encoder.h conflict! 'e' 00-1F net/irda/irtty.h conflict! 'f' 00-1F linux/ext2_fs.h +'g' 00-1F linux/gfs2_ioctl.h 'h' 00-7F Charon filesystem 'i' 00-3F linux/i2o.h diff --git a/include/linux/gfs2_ioctl.h b/include/linux/gfs2_ioctl.h index ca9632862833..fb7c0cf72c56 100644 --- a/include/linux/gfs2_ioctl.h +++ b/include/linux/gfs2_ioctl.h @@ -10,12 +10,8 @@ #ifndef __GFS2_IOCTL_DOT_H__ #define __GFS2_IOCTL_DOT_H__ -#define _GFS2C_(x) (('G' << 16) | ('2' << 8) | (x)) - -/* Ioctls implemented */ - -#define GFS2_IOCTL_SETFLAGS _GFS2C_(3) -#define GFS2_IOCTL_GETFLAGS _GFS2C_(4) +#define GFS2_IOCTL_SETFLAGS _IOW('g', 3, long) +#define GFS2_IOCTL_GETFLAGS _IOR('g', 4, long) #endif /* ___GFS2_IOCTL_DOT_H__ */ From aa6a85a971065b013a71a399c3fc4312e2dd81eb Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 24 Jan 2006 10:37:06 +0000 Subject: [PATCH 024/292] [GFS2] Remove pointless argument relating to truncate For some reason a function pointer was being passed through the truncate code which only ever took one value. This removes the function pointer and replaces it with a single call to the function in question. Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 15 ++++++--------- fs/gfs2/bmap.h | 3 +-- fs/gfs2/ops_inode.c | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 967cbc68195a..ff4a9175b4e1 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -841,8 +841,7 @@ static int truncator_journaled(struct gfs2_inode *ip, uint64_t size) return 0; } -static int trunc_start(struct gfs2_inode *ip, uint64_t size, - gfs2_truncator_t truncator) +static int trunc_start(struct gfs2_inode *ip, uint64_t size) { struct gfs2_sbd *sdp = ip->i_sbd; struct buffer_head *dibh; @@ -873,7 +872,7 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size, if (do_div(junk, sdp->sd_jbsize)) error = truncator_journaled(ip, size); } else if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1)) - error = truncator(ip, size); + error = gfs2_truncator_page(ip, size); if (!error) { ip->i_di.di_size = size; @@ -980,12 +979,11 @@ static int trunc_end(struct gfs2_inode *ip) * Returns: errno */ -static int do_shrink(struct gfs2_inode *ip, uint64_t size, - gfs2_truncator_t truncator) +static int do_shrink(struct gfs2_inode *ip, uint64_t size) { int error; - error = trunc_start(ip, size, truncator); + error = trunc_start(ip, size); if (error < 0) return error; if (error > 0) @@ -1009,8 +1007,7 @@ static int do_shrink(struct gfs2_inode *ip, uint64_t size, * Returns: errno */ -int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size, - gfs2_truncator_t truncator) +int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size) { int error; @@ -1020,7 +1017,7 @@ int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size, if (size > ip->i_di.di_size) error = do_grow(ip, size); else - error = do_shrink(ip, size, truncator); + error = do_shrink(ip, size); return error; } diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index 25ea32905c67..b83b5924828f 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -23,8 +23,7 @@ int gfs2_block_map(struct gfs2_inode *ip, uint64_t *dblock, uint32_t *extlen); typedef int (*gfs2_truncator_t) (struct gfs2_inode * ip, uint64_t size); -int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size, - gfs2_truncator_t truncator); +int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size); int gfs2_truncatei_resume(struct gfs2_inode *ip); int gfs2_file_dealloc(struct gfs2_inode *ip); diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 89417a6cb723..6fff30ef8b70 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -994,7 +994,7 @@ static int setattr_size(struct inode *inode, struct iattr *attr) return error; } - error = gfs2_truncatei(ip, attr->ia_size, gfs2_truncator_page); + error = gfs2_truncatei(ip, attr->ia_size); if (error) return error; From b381beadee8a3d6e690d30bdccddd08ab024945e Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 30 Jan 2006 08:47:14 +0000 Subject: [PATCH 025/292] [GFS2] Remove unused file resize.c The code in this file is no longer used as the rindex file is now accessible to userspace, so can be read/written directly. Signed-off-by: Steven Whitehouse --- fs/gfs2/Makefile | 1 - fs/gfs2/resize.c | 291 ----------------------------------------------- fs/gfs2/resize.h | 19 ---- 3 files changed, 311 deletions(-) delete mode 100644 fs/gfs2/resize.c delete mode 100644 fs/gfs2/resize.h diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile index 974c76d0c6fc..4e87b8661af0 100644 --- a/fs/gfs2/Makefile +++ b/fs/gfs2/Makefile @@ -30,7 +30,6 @@ gfs2-y := \ ops_vm.o \ page.o \ quota.o \ - resize.o \ recovery.o \ rgrp.o \ super.o \ diff --git a/fs/gfs2/resize.c b/fs/gfs2/resize.c deleted file mode 100644 index a53096682500..000000000000 --- a/fs/gfs2/resize.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#include -#include -#include -#include -#include -#include - -#include "gfs2.h" -#include "bmap.h" -#include "dir.h" -#include "glock.h" -#include "inode.h" -#include "jdata.h" -#include "meta_io.h" -#include "quota.h" -#include "resize.h" -#include "rgrp.h" -#include "super.h" -#include "trans.h" - -/* A single transaction needs to add the structs to rindex and make the - statfs change. */ - -int gfs2_resize_add_rgrps(struct gfs2_sbd *sdp, char __user *buf, - unsigned int size) -{ - unsigned int num = size / sizeof(struct gfs2_rindex); - struct gfs2_inode *ip = sdp->sd_rindex; - struct gfs2_alloc *al = NULL; - struct gfs2_holder i_gh; - unsigned int data_blocks, ind_blocks; - int alloc_required; - unsigned int x; - int error; - - gfs2_write_calc_reserv(ip, size, &data_blocks, &ind_blocks); - - error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, - LM_FLAG_PRIORITY | GL_SYNC, &i_gh); - if (error) - return error; - - if (!gfs2_is_jdata(ip)) { - gfs2_consist_inode(ip); - error = -EIO; - goto out; - } - - error = gfs2_write_alloc_required(ip, ip->i_di.di_size, size, - &alloc_required); - if (error) - goto out; - - if (alloc_required) { - al = gfs2_alloc_get(ip); - - al->al_requested = data_blocks + ind_blocks; - - error = gfs2_inplace_reserve(ip); - if (error) - goto out_alloc; - - error = gfs2_trans_begin(sdp, - al->al_rgd->rd_ri.ri_length + - data_blocks + ind_blocks + - RES_DINODE + RES_STATFS, 0); - if (error) - goto out_relse; - } else { - error = gfs2_trans_begin(sdp, data_blocks + - RES_DINODE + RES_STATFS, 0); - if (error) - goto out; - } - - for (x = 0; x < num; x++) { - struct gfs2_rindex ri; - char ri_buf[sizeof(struct gfs2_rindex)]; - - error = copy_from_user(&ri, buf, sizeof(struct gfs2_rindex)); - if (error) { - error = -EFAULT; - goto out_trans; - } - gfs2_rindex_out(&ri, ri_buf); - - error = gfs2_jdata_write_mem(ip, ri_buf, ip->i_di.di_size, - sizeof(struct gfs2_rindex)); - if (error < 0) - goto out_trans; - gfs2_assert_withdraw(sdp, error == sizeof(struct gfs2_rindex)); - error = 0; - - gfs2_statfs_change(sdp, ri.ri_data, ri.ri_data, 0); - - buf += sizeof(struct gfs2_rindex); - } - - out_trans: - gfs2_trans_end(sdp); - - out_relse: - if (alloc_required) - gfs2_inplace_release(ip); - - out_alloc: - if (alloc_required) - gfs2_alloc_put(ip); - - out: - ip->i_gl->gl_vn++; - gfs2_glock_dq_uninit(&i_gh); - - return error; -} - -static void drop_dentries(struct gfs2_inode *ip) -{ - struct inode *inode; - struct dentry *d; - - inode = gfs2_ip2v_lookup(ip); - if (!inode) - return; - - restart: - spin_lock(&dcache_lock); - list_for_each_entry(d, &inode->i_dentry, d_alias) { - if (d_unhashed(d)) - continue; - dget_locked(d); - __d_drop(d); - spin_unlock(&dcache_lock); - dput(d); - goto restart; - } - spin_unlock(&dcache_lock); - - iput(inode); -} - -/* This is called by an ioctl to rename an ordinary file that's represented - in the vfs to a hidden system file that isn't represented in the vfs. It's - used to add journals, along with the associated system files, to a fs. */ - -int gfs2_rename2system(struct gfs2_inode *ip, - struct gfs2_inode *old_dip, char *old_name, - struct gfs2_inode *new_dip, char *new_name) -{ - struct gfs2_sbd *sdp = ip->i_sbd; - struct gfs2_holder ghs[3]; - struct qstr old_qstr, new_qstr; - struct gfs2_inum inum; - int alloc_required; - struct buffer_head *dibh; - int error; - - gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, ghs); - gfs2_holder_init(old_dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); - gfs2_holder_init(new_dip->i_gl, LM_ST_EXCLUSIVE, GL_SYNC, ghs + 2); - - error = gfs2_glock_nq_m(3, ghs); - if (error) - goto out; - - error = -EMLINK; - if (ip->i_di.di_nlink != 1) - goto out_gunlock; - error = -EINVAL; - if (!S_ISREG(ip->i_di.di_mode)) - goto out_gunlock; - - old_qstr.name = old_name; - old_qstr.len = strlen(old_name); - error = gfs2_dir_search(old_dip, &old_qstr, &inum, NULL); - switch (error) { - case 0: - break; - default: - goto out_gunlock; - } - - error = -EINVAL; - if (!gfs2_inum_equal(&inum, &ip->i_num)) - goto out_gunlock; - - new_qstr.name = new_name; - new_qstr.len = strlen(new_name); - error = gfs2_dir_search(new_dip, &new_qstr, NULL, NULL); - switch (error) { - case -ENOENT: - break; - case 0: - error = -EEXIST; - default: - goto out_gunlock; - } - - gfs2_alloc_get(ip); - - error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); - if (error) - goto out_alloc; - - error = gfs2_diradd_alloc_required(new_dip, &new_qstr, &alloc_required); - if (error) - goto out_unhold; - - if (alloc_required) { - struct gfs2_alloc *al = gfs2_alloc_get(new_dip); - - al->al_requested = sdp->sd_max_dirres; - - error = gfs2_inplace_reserve(new_dip); - if (error) - goto out_alloc2; - - error = gfs2_trans_begin(sdp, - sdp->sd_max_dirres + - al->al_rgd->rd_ri.ri_length + - 3 * RES_DINODE + RES_LEAF + - RES_STATFS + RES_QUOTA, 0); - if (error) - goto out_ipreserv; - } else { - error = gfs2_trans_begin(sdp, - 3 * RES_DINODE + 2 * RES_LEAF + - RES_QUOTA, 0); - if (error) - goto out_unhold; - } - - error = gfs2_dir_del(old_dip, &old_qstr); - if (error) - goto out_trans; - - error = gfs2_dir_add(new_dip, &new_qstr, &ip->i_num, - IF2DT(ip->i_di.di_mode)); - if (error) - goto out_trans; - - gfs2_quota_change(ip, -ip->i_di.di_blocks, ip->i_di.di_uid, - ip->i_di.di_gid); - - error = gfs2_meta_inode_buffer(ip, &dibh); - if (error) - goto out_trans; - ip->i_di.di_flags |= GFS2_DIF_SYSTEM; - gfs2_trans_add_bh(ip->i_gl, dibh, 1); - gfs2_dinode_out(&ip->i_di, dibh->b_data); - brelse(dibh); - - drop_dentries(ip); - - out_trans: - gfs2_trans_end(sdp); - - out_ipreserv: - if (alloc_required) - gfs2_inplace_release(new_dip); - - out_alloc2: - if (alloc_required) - gfs2_alloc_put(new_dip); - - out_unhold: - gfs2_quota_unhold(ip); - - out_alloc: - gfs2_alloc_put(ip); - - out_gunlock: - gfs2_glock_dq_m(3, ghs); - - out: - gfs2_holder_uninit(ghs); - gfs2_holder_uninit(ghs + 1); - gfs2_holder_uninit(ghs + 2); - - return error; -} - diff --git a/fs/gfs2/resize.h b/fs/gfs2/resize.h deleted file mode 100644 index bb97f0501598..000000000000 --- a/fs/gfs2/resize.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#ifndef __RESIZE_DOT_H__ -#define __RESIZE_DOT_H__ - -int gfs2_resize_add_rgrps(struct gfs2_sbd *sdp, char __user *buf, - unsigned int size); -int gfs2_rename2system(struct gfs2_inode *ip, - struct gfs2_inode *old_dip, char *old_name, - struct gfs2_inode *new_dip, char *new_name); - -#endif /* __RESIZE_DOT_H__ */ From d41cc702cc4ba3782ebe3b2e189633607d5ccd6a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 30 Jan 2006 08:53:33 +0000 Subject: [PATCH 026/292] [GFS2] Export file_ra_state_init Export file_ra_state_init so that its possible to use the already exported functions which require a struct ra_state as an argument from a module. Signed-off-by: Steven Whitehouse --- mm/readahead.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/readahead.c b/mm/readahead.c index 8d6eeaaa6296..9f0b98227b41 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -38,6 +38,7 @@ file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping) ra->ra_pages = mapping->backing_dev_info->ra_pages; ra->prev_page = -1; } +EXPORT_SYMBOL_GPL(file_ra_state_init); /* * Return max readahead size for this inode in number-of-pages. From c25ec8f5684cb3c5dde6a67c1bbc33a449eefbe2 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 30 Jan 2006 08:57:31 +0000 Subject: [PATCH 027/292] [GFS2] Export file_read_actor Export file_read_actor so that it can be used from modules since functions which take this function as an argument are already exported. Signed-off-by: Steven Whitehouse --- mm/filemap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/filemap.c b/mm/filemap.c index 44da3d476994..7624c26fcea6 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -981,6 +981,7 @@ success: desc->arg.buf += size; return size; } +EXPORT_SYMBOL(file_read_actor); /* * This is the "read()" routine for all filesystems From 4ff14670ee2a8229381ff295eaae84aa51beff43 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 30 Jan 2006 09:39:10 +0000 Subject: [PATCH 028/292] [GFS2] Rename get_block and make it extern This renames get_block to gfs2_get_block and makes it accessible from outside ops_address.c. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 14 +++++++------- fs/gfs2/ops_address.h | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index db66d3287550..a7fbfa0bbaf8 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -28,7 +28,7 @@ #include "trans.h" /** - * get_block - Fills in a buffer head with details about a block + * gfs2_get_block - Fills in a buffer head with details about a block * @inode: The inode * @lblock: The block number to look up * @bh_result: The buffer head to return the result in @@ -37,8 +37,8 @@ * Returns: errno */ -static int get_block(struct inode *inode, sector_t lblock, - struct buffer_head *bh_result, int create) +int gfs2_get_block(struct inode *inode, sector_t lblock, + struct buffer_head *bh_result, int create) { struct gfs2_inode *ip = get_v2ip(inode); int new = create; @@ -286,7 +286,7 @@ static int gfs2_readpage(struct file *file, struct page *page) } else error = zero_readpage(page); } else - error = block_read_full_page(page, get_block); + error = block_read_full_page(page, gfs2_get_block); } else error = jdata_readpage(ip, page); @@ -328,11 +328,11 @@ static int gfs2_prepare_write(struct file *file, struct page *page, page); if (!error) error = block_prepare_write(page, from, to, - get_block); + gfs2_get_block); } else if (!PageUptodate(page)) error = stuffed_readpage(ip, page); } else - error = block_prepare_write(page, from, to, get_block); + error = block_prepare_write(page, from, to, gfs2_get_block); return error; } @@ -420,7 +420,7 @@ static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock) return 0; if (!gfs2_is_stuffed(ip)) - dblock = generic_block_bmap(mapping, lblock, get_block); + dblock = generic_block_bmap(mapping, lblock, gfs2_get_block); gfs2_glock_dq_uninit(&i_gh); diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h index ced9ea0fdd31..f201a059fd91 100644 --- a/fs/gfs2/ops_address.h +++ b/fs/gfs2/ops_address.h @@ -11,5 +11,7 @@ #define __OPS_ADDRESS_DOT_H__ extern struct address_space_operations gfs2_file_aops; +extern int gfs2_get_block(struct inode *inode, sector_t lblock, + struct buffer_head *bh_result, int create); #endif /* __OPS_ADDRESS_DOT_H__ */ From 2442a098be6b38ee3abe8edda3224b48ff4d604a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 30 Jan 2006 11:49:32 +0000 Subject: [PATCH 029/292] [GFS2] Bug fix relating to endian conversion in inode.c A two line fix to get endian conversion correct. Signed-off-by: Steven Whitehouse --- fs/gfs2/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 9ed7c0541065..e4ba380b286a 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -1002,7 +1002,8 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); di = (struct gfs2_dinode *)dibh->b_data; - di->di_num = *inum; + di->di_num.no_formal_ino = cpu_to_be64(inum->no_formal_ino); + di->di_num.no_addr = cpu_to_be64(inum->no_addr); di->di_mode = cpu_to_be32(mode); di->di_uid = cpu_to_be32(uid); di->di_gid = cpu_to_be32(gid); From 9b124fbb8ddb3d0b17f5a807414d85cbaf527a56 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 30 Jan 2006 11:55:32 +0000 Subject: [PATCH 030/292] [GFS2] Use mpage_readpage() in gfs2_readpage() Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index a7fbfa0bbaf8..da5a0b445188 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -286,7 +287,7 @@ static int gfs2_readpage(struct file *file, struct page *page) } else error = zero_readpage(page); } else - error = block_read_full_page(page, gfs2_get_block); + error = mpage_readpage(page, gfs2_get_block); } else error = jdata_readpage(ip, page); From e13940ba56157a663944f2a827be96b6b787e260 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 30 Jan 2006 13:31:50 +0000 Subject: [PATCH 031/292] [GFS2] Make dir.c independant of jdata.c Copy & rename various jdata functions into dir.c. The plan being that directory metadata format will not change although the journalled data format for "normal" files will change. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 264 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 255 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 93d3704ac58c..ada283a0f5f3 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -65,11 +65,11 @@ #include "dir.h" #include "glock.h" #include "inode.h" -#include "jdata.h" #include "meta_io.h" #include "quota.h" #include "rgrp.h" #include "trans.h" +#include "bmap.h" #define IS_LEAF 1 /* Hashed (leaf) directory */ #define IS_DINODE 2 /* Linear (stuffed dinode block) directory */ @@ -86,6 +86,252 @@ typedef int (*leaf_call_t) (struct gfs2_inode *dip, uint32_t index, uint32_t len, uint64_t leaf_no, void *data); +static int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, + struct buffer_head **bhp) +{ + struct buffer_head *bh; + int error = 0; + + if (new) { + bh = gfs2_meta_new(ip->i_gl, block); + gfs2_trans_add_bh(ip->i_gl, bh, 1); + gfs2_metatype_set(bh, GFS2_METATYPE_JD, GFS2_FORMAT_JD); + gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); + } else { + error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT, &bh); + if (error) + return error; + if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_JD)) { + brelse(bh); + return -EIO; + } + } + + *bhp = bh; + return 0; +} + + + +static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf, + unsigned int offset, unsigned int size) + +{ + struct buffer_head *dibh; + int error; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + return error; + + gfs2_trans_add_bh(ip->i_gl, dibh, 1); + memcpy(dibh->b_data + offset + sizeof(struct gfs2_inode), buf, size); + if (ip->i_di.di_size < offset + size) + ip->i_di.di_size = offset + size; + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + + brelse(dibh); + + return size; +} + + + +/** + * gfs2_dir_write_data - Write directory information to the inode + * @ip: The GFS2 inode + * @buf: The buffer containing information to be written + * @offset: The file offset to start writing at + * @size: The amount of data to write + * + * Returns: The number of bytes correctly written or error code + */ +static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, + uint64_t offset, unsigned int size) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + struct buffer_head *dibh; + uint64_t lblock, dblock; + uint32_t extlen = 0; + unsigned int o; + int copied = 0; + int error = 0; + + if (!size) + return 0; + + if (gfs2_is_stuffed(ip) && + offset + size <= sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) + return gfs2_dir_write_stuffed(ip, buf, (unsigned int)offset, size); + + if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) + return -EINVAL; + + if (gfs2_is_stuffed(ip)) { + error = gfs2_unstuff_dinode(ip, NULL, NULL); + if (error) + return error; + } + + lblock = offset; + o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header); + + while (copied < size) { + unsigned int amount; + struct buffer_head *bh; + int new; + + amount = size - copied; + if (amount > sdp->sd_sb.sb_bsize - o) + amount = sdp->sd_sb.sb_bsize - o; + + if (!extlen) { + new = 1; + error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); + if (error) + goto fail; + error = -EIO; + if (gfs2_assert_withdraw(sdp, dblock)) + goto fail; + } + + error = gfs2_dir_get_buffer(ip, dblock, (amount == sdp->sd_jbsize) ? 1 : new, &bh); + if (error) + goto fail; + + gfs2_trans_add_bh(ip->i_gl, bh, 1); + memcpy(bh->b_data + o, buf, amount); + brelse(bh); + if (error) + goto fail; + + copied += amount; + lblock++; + dblock++; + extlen--; + + o = sizeof(struct gfs2_meta_header); + } + +out: + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + return error; + + if (ip->i_di.di_size < offset + copied) + ip->i_di.di_size = offset + copied; + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + + gfs2_trans_add_bh(ip->i_gl, dibh, 1); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + + return copied; +fail: + if (copied) + goto out; + return error; +} + +static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf, + unsigned int offset, unsigned int size) +{ + struct buffer_head *dibh; + int error; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + offset += sizeof(struct gfs2_dinode); + memcpy(buf, dibh->b_data + offset, size); + brelse(dibh); + } + + return (error) ? error : size; +} + + +/** + * gfs2_dir_read_data - Read a data from a directory inode + * @ip: The GFS2 Inode + * @buf: The buffer to place result into + * @offset: File offset to begin jdata_readng from + * @size: Amount of data to transfer + * + * Returns: The amount of data actually copied or the error + */ +static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, + uint64_t offset, unsigned int size) +{ + struct gfs2_sbd *sdp = ip->i_sbd; + uint64_t lblock, dblock; + uint32_t extlen = 0; + unsigned int o; + int copied = 0; + int error = 0; + + if (offset >= ip->i_di.di_size) + return 0; + + if ((offset + size) > ip->i_di.di_size) + size = ip->i_di.di_size - offset; + + if (!size) + return 0; + + if (gfs2_is_stuffed(ip)) + return gfs2_dir_read_stuffed(ip, buf, (unsigned int)offset, size); + + if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) + return -EINVAL; + + lblock = offset; + o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header); + + while (copied < size) { + unsigned int amount; + struct buffer_head *bh; + int new; + + amount = size - copied; + if (amount > sdp->sd_sb.sb_bsize - o) + amount = sdp->sd_sb.sb_bsize - o; + + if (!extlen) { + new = 0; + error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); + if (error) + goto fail; + } + + if (extlen > 1) + gfs2_meta_ra(ip->i_gl, dblock, extlen); + + if (dblock) { + error = gfs2_dir_get_buffer(ip, dblock, new, &bh); + if (error) + goto fail; + dblock++; + extlen--; + } else + bh = NULL; + + memcpy(buf, bh->b_data + o, amount); + brelse(bh); + if (error) + goto fail; + + copied += amount; + lblock++; + + o = sizeof(struct gfs2_meta_header); + } + + return copied; +fail: + return (copied) ? copied : error; +} + /** * int gfs2_filecmp - Compare two filenames * @file1: The first filename @@ -428,7 +674,7 @@ static int get_leaf_nr(struct gfs2_inode *dip, uint32_t index, uint64_t leaf_no; int error; - error = gfs2_jdata_read_mem(dip, (char *)&leaf_no, + error = gfs2_dir_read_data(dip, (char *)&leaf_no, index * sizeof(uint64_t), sizeof(uint64_t)); if (error != sizeof(uint64_t)) @@ -683,7 +929,7 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, lp = kcalloc(half_len, sizeof(uint64_t), GFP_KERNEL | __GFP_NOFAIL); - error = gfs2_jdata_read_mem(dip, (char *)lp, start * sizeof(uint64_t), + error = gfs2_dir_read_data(dip, (char *)lp, start * sizeof(uint64_t), half_len * sizeof(uint64_t)); if (error != half_len * sizeof(uint64_t)) { if (error >= 0) @@ -696,7 +942,7 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, for (x = 0; x < half_len; x++) lp[x] = cpu_to_be64(bn); - error = gfs2_jdata_write_mem(dip, (char *)lp, start * sizeof(uint64_t), + error = gfs2_dir_write_data(dip, (char *)lp, start * sizeof(uint64_t), half_len * sizeof(uint64_t)); if (error != half_len * sizeof(uint64_t)) { if (error >= 0) @@ -816,7 +1062,7 @@ static int dir_double_exhash(struct gfs2_inode *dip) buf = kcalloc(3, sdp->sd_hash_bsize, GFP_KERNEL | __GFP_NOFAIL); for (block = dip->i_di.di_size >> sdp->sd_hash_bsize_shift; block--;) { - error = gfs2_jdata_read_mem(dip, (char *)buf, + error = gfs2_dir_read_data(dip, (char *)buf, block * sdp->sd_hash_bsize, sdp->sd_hash_bsize); if (error != sdp->sd_hash_bsize) { @@ -833,7 +1079,7 @@ static int dir_double_exhash(struct gfs2_inode *dip) *to++ = *from; } - error = gfs2_jdata_write_mem(dip, + error = gfs2_dir_write_data(dip, (char *)buf + sdp->sd_hash_bsize, block * sdp->sd_sb.sb_bsize, sdp->sd_sb.sb_bsize); @@ -1424,7 +1670,7 @@ static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, ht_offset = index - lp_offset; if (ht_offset_cur != ht_offset) { - error = gfs2_jdata_read_mem(dip, (char *)lp, + error = gfs2_dir_read_data(dip, (char *)lp, ht_offset * sizeof(uint64_t), sdp->sd_hash_bsize); if (error != sdp->sd_hash_bsize) { @@ -1839,7 +2085,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) ht_offset = index - lp_offset; if (ht_offset_cur != ht_offset) { - error = gfs2_jdata_read_mem(dip, (char *)lp, + error = gfs2_dir_read_data(dip, (char *)lp, ht_offset * sizeof(uint64_t), sdp->sd_hash_bsize); if (error != sdp->sd_hash_bsize) { @@ -1965,7 +2211,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, dip->i_di.di_blocks--; } - error = gfs2_jdata_write_mem(dip, ht, index * sizeof(uint64_t), size); + error = gfs2_dir_write_data(dip, ht, index * sizeof(uint64_t), size); if (error != size) { if (error >= 0) error = -EIO; From fd2ee6bb1ef02dfe1f1e1f5b44322e0854596e9a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 30 Jan 2006 13:36:53 +0000 Subject: [PATCH 032/292] [GFS2] Remove unused prototype Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.h | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index b83b5924828f..ee9ec8d7515c 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -22,7 +22,6 @@ int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, uint64_t *dblock, uint32_t *extlen); -typedef int (*gfs2_truncator_t) (struct gfs2_inode * ip, uint64_t size); int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size); int gfs2_truncatei_resume(struct gfs2_inode *ip); int gfs2_file_dealloc(struct gfs2_inode *ip); From f42faf4fa4eaf7e108dd60f3f2ca5c6e9b45352c Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 30 Jan 2006 18:34:10 +0000 Subject: [PATCH 033/292] [GFS2] Add gfs2_internal_read() Add the new external read function. Its temporarily in jdata.c even though the protoype is in ops_file.h - this will change shortly. The current implementation will change to a page cache one when that happens. In order to effect the above changes, the various internal inodes now have Linux inodes attached to them. We keep the references to the Linux inodes, rather than the gfs2_inodes in the super block. In order to get everything to work correctly I've had to reorder the init sequence on mount (which I should probably have done earlier when .gfs2_admin was made visible). Signed-off-by: Steven Whitehouse --- fs/gfs2/incore.h | 29 ++++--- fs/gfs2/inode.c | 10 +-- fs/gfs2/inode.h | 15 +++- fs/gfs2/jdata.c | 7 ++ fs/gfs2/ops_export.c | 2 +- fs/gfs2/ops_file.h | 4 + fs/gfs2/ops_fstype.c | 184 ++++++++++++++++++++++--------------------- fs/gfs2/ops_super.c | 22 +++--- fs/gfs2/quota.c | 27 ++++--- fs/gfs2/rgrp.c | 13 +-- fs/gfs2/super.c | 19 ++--- fs/gfs2/unlinked.c | 4 +- 12 files changed, 187 insertions(+), 149 deletions(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 3bc40ff5fdf9..d1954e2bb908 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -98,10 +98,13 @@ struct gfs2_rgrpd { enum gfs2_state_bits { BH_Pinned = BH_PrivateStart, + BH_Escaped = BH_PrivateStart + 1, }; BUFFER_FNS(Pinned, pinned) TAS_BUFFER_FNS(Pinned, pinned) +BUFFER_FNS(Escaped, escaped) +TAS_BUFFER_FNS(Escaped, escaped) struct gfs2_bufdata { struct buffer_head *bd_bh; @@ -254,7 +257,7 @@ struct gfs2_inode { struct inode *i_vnode; struct gfs2_holder i_iopen_gh; - + struct gfs2_holder i_gh; /* for prepare/commit_write only */ struct gfs2_alloc i_alloc; uint64_t i_last_rg_alloc; @@ -511,17 +514,17 @@ struct gfs2_sbd { /* Inode Stuff */ - struct gfs2_inode *sd_master_dir; - struct gfs2_inode *sd_jindex; - struct gfs2_inode *sd_inum_inode; - struct gfs2_inode *sd_statfs_inode; - struct gfs2_inode *sd_ir_inode; - struct gfs2_inode *sd_sc_inode; - struct gfs2_inode *sd_ut_inode; - struct gfs2_inode *sd_qc_inode; - struct gfs2_inode *sd_rindex; - struct gfs2_inode *sd_quota_inode; - struct gfs2_inode *sd_root_dir; + struct inode *sd_master_dir; + struct inode *sd_jindex; + struct inode *sd_inum_inode; + struct inode *sd_statfs_inode; + struct inode *sd_ir_inode; + struct inode *sd_sc_inode; + struct inode *sd_ut_inode; + struct inode *sd_qc_inode; + struct inode *sd_rindex; + struct inode *sd_quota_inode; + struct inode *sd_root_dir; /* Inum stuff */ @@ -615,6 +618,8 @@ struct gfs2_sbd { unsigned int sd_log_num_revoke; unsigned int sd_log_num_rg; unsigned int sd_log_num_databuf; + unsigned int sd_log_num_jdata; + struct list_head sd_log_le_gl; struct list_head sd_log_le_buf; struct list_head sd_log_le_revoke; diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index e4ba380b286a..4c193e38f8e4 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -725,7 +725,7 @@ int gfs2_lookupi(struct gfs2_inode *dip, struct qstr *name, int is_root, return -ENAMETOOLONG; if (gfs2_filecmp(name, ".", 1) || - (gfs2_filecmp(name, "..", 2) && dip == sdp->sd_root_dir)) { + (gfs2_filecmp(name, "..", 2) && dip == get_v2ip(sdp->sd_root_dir))) { gfs2_inode_hold(dip); *ipp = dip; return 0; @@ -764,7 +764,7 @@ int gfs2_lookupi(struct gfs2_inode *dip, struct qstr *name, int is_root, static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) { - struct gfs2_inode *ip = sdp->sd_ir_inode; + struct gfs2_inode *ip = get_v2ip(sdp->sd_ir_inode); struct buffer_head *bh; struct gfs2_inum_range ir; int error; @@ -805,8 +805,8 @@ static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) { - struct gfs2_inode *ip = sdp->sd_ir_inode; - struct gfs2_inode *m_ip = sdp->sd_inum_inode; + struct gfs2_inode *ip = get_v2ip(sdp->sd_ir_inode); + struct gfs2_inode *m_ip = get_v2ip(sdp->sd_inum_inode); struct gfs2_holder gh; struct buffer_head *bh; struct gfs2_inum_range ir; @@ -1460,7 +1460,7 @@ int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) error = -EINVAL; break; } - if (to == sdp->sd_root_dir) { + if (to == get_v2ip(sdp->sd_root_dir)) { error = 0; break; } diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index 4df7da51f715..e42ae38d6778 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -60,14 +60,23 @@ int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr); int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd); -static inline int gfs2_lookup_simple(struct gfs2_inode *dip, char *name, - struct gfs2_inode **ipp) +static inline int gfs2_lookup_simple(struct inode *dip, char *name, + struct inode **ipp) { + struct gfs2_inode *ip; struct qstr qstr; + int err; memset(&qstr, 0, sizeof(struct qstr)); qstr.name = name; qstr.len = strlen(name); - return gfs2_lookupi(dip, &qstr, 1, ipp); + err = gfs2_lookupi(get_v2ip(dip), &qstr, 1, &ip); + if (err == 0) { + *ipp = gfs2_ip2v(ip); + if (*ipp == NULL) + err = -ENOMEM; + gfs2_inode_put(ip); + } + return err; } #endif /* __INODE_DOT_H__ */ diff --git a/fs/gfs2/jdata.c b/fs/gfs2/jdata.c index 6caa93e46ce0..e43eaf133f10 100644 --- a/fs/gfs2/jdata.c +++ b/fs/gfs2/jdata.c @@ -22,6 +22,13 @@ #include "meta_io.h" #include "trans.h" +int gfs2_internal_read(struct gfs2_inode *ip, + struct file_ra_state *ra_state, + char *buf, loff_t *pos, unsigned size) +{ + return gfs2_jdata_read_mem(ip, buf, *pos, size); +} + int gfs2_jdata_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, struct buffer_head **bhp) { diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index 0ae3a0af192d..335448d3be21 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -81,7 +81,7 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, fh[3] = cpu_to_be32(fh[3]); *len = 4; - if (!connectable || ip == sdp->sd_root_dir) + if (!connectable || ip == get_v2ip(sdp->sd_root_dir)) return *len; spin_lock(&dentry->d_lock); diff --git a/fs/gfs2/ops_file.h b/fs/gfs2/ops_file.h index 95123d7bbcdf..3c237bfc143d 100644 --- a/fs/gfs2/ops_file.h +++ b/fs/gfs2/ops_file.h @@ -10,6 +10,10 @@ #ifndef __OPS_FILE_DOT_H__ #define __OPS_FILE_DOT_H__ +extern int gfs2_internal_read(struct gfs2_inode *ip, + struct file_ra_state *ra_state, + char *buf, loff_t *pos, unsigned size); + extern struct file_operations gfs2_file_fops; extern struct file_operations gfs2_dir_fops; diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index c61a80c439a6..139cef8fff3a 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -275,14 +275,38 @@ static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, return error; } +int gfs2_lookup_root(struct gfs2_sbd *sdp) +{ + int error; + struct gfs2_glock *gl; + struct gfs2_inode *ip; + + error = gfs2_glock_get(sdp, sdp->sd_sb.sb_root_dir.no_addr, + &gfs2_inode_glops, CREATE, &gl); + if (!error) { + error = gfs2_inode_get(gl, &sdp->sd_sb.sb_root_dir, + CREATE, &ip); + if (!error) { + if (!error) + gfs2_inode_min_init(ip, DT_DIR); + sdp->sd_root_dir = gfs2_ip2v(ip); + gfs2_inode_put(ip); + } + gfs2_glock_put(gl); + } + + return error; +} + static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) { struct super_block *sb = sdp->sd_vfs; struct gfs2_holder sb_gh; + struct inode *inode; int error = 0; if (undo) { - gfs2_inode_put(sdp->sd_master_dir); + iput(sdp->sd_master_dir); return 0; } @@ -321,14 +345,35 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); - error = gfs2_lookup_master_dir(sdp); - if (error) - fs_err(sdp, "can't read in master directory: %d\n", error); + /* Get the root inode */ + error = gfs2_lookup_root(sdp); + if (error) { + fs_err(sdp, "can't read in root inode: %d\n", error); + goto out; + } - out: + /* Get the root inode/dentry */ + inode = sdp->sd_root_dir; + if (!inode) { + fs_err(sdp, "can't get root inode\n"); + error = -ENOMEM; + goto out_rooti; + } + + sb->s_root = d_alloc_root(inode); + if (!sb->s_root) { + fs_err(sdp, "can't get root dentry\n"); + error = -ENOMEM; + goto out_rooti; + } + +out: gfs2_glock_dq_uninit(&sb_gh); return error; +out_rooti: + iput(sdp->sd_root_dir); + goto out; } static int init_journal(struct gfs2_sbd *sdp, int undo) @@ -349,7 +394,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) fs_err(sdp, "can't lookup journal index: %d\n", error); return error; } - set_bit(GLF_STICKY, &sdp->sd_jindex->i_gl->gl_flags); + set_bit(GLF_STICKY, &get_v2ip(sdp->sd_jindex)->i_gl->gl_flags); /* Load in the journal index special file */ @@ -465,53 +510,44 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) gfs2_glock_dq_uninit(&ji_gh); fail: - gfs2_inode_put(sdp->sd_jindex); + iput(sdp->sd_jindex); return error; } -int gfs2_lookup_root(struct gfs2_sbd *sdp) -{ - int error; - struct gfs2_glock *gl; - - error = gfs2_glock_get(sdp, sdp->sd_sb.sb_root_dir.no_addr, - &gfs2_inode_glops, CREATE, &gl); - if (!error) { - error = gfs2_inode_get(gl, &sdp->sd_sb.sb_root_dir, - CREATE, &sdp->sd_root_dir); - if (!error) - gfs2_inode_min_init(sdp->sd_root_dir, DT_DIR); - gfs2_glock_put(gl); - } - - return error; -} - static int init_inodes(struct gfs2_sbd *sdp, int undo) { - struct inode *inode; - struct dentry **dentry = &sdp->sd_vfs->s_root; int error = 0; if (undo) - goto fail_dput; + goto fail_qinode; + + error = gfs2_lookup_master_dir(sdp); + if (error) { + fs_err(sdp, "can't read in master directory: %d\n", error); + goto fail; + } + + error = init_journal(sdp, undo); + if (error) + goto fail_master; /* Read in the master inode number inode */ error = gfs2_lookup_simple(sdp->sd_master_dir, "inum", &sdp->sd_inum_inode); if (error) { fs_err(sdp, "can't read in inum inode: %d\n", error); - return error; + goto fail_journal; } + /* Read in the master statfs inode */ error = gfs2_lookup_simple(sdp->sd_master_dir, "statfs", &sdp->sd_statfs_inode); if (error) { fs_err(sdp, "can't read in statfs inode: %d\n", error); - goto fail; + goto fail_inum; } /* Read in the resource index inode */ @@ -521,8 +557,8 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) fs_err(sdp, "can't get resource index inode: %d\n", error); goto fail_statfs; } - set_bit(GLF_STICKY, &sdp->sd_rindex->i_gl->gl_flags); - sdp->sd_rindex_vn = sdp->sd_rindex->i_gl->gl_vn - 1; + set_bit(GLF_STICKY, &get_v2ip(sdp->sd_rindex)->i_gl->gl_flags); + sdp->sd_rindex_vn = get_v2ip(sdp->sd_rindex)->i_gl->gl_vn - 1; /* Read in the quota inode */ error = gfs2_lookup_simple(sdp->sd_master_dir, "quota", @@ -531,58 +567,31 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) fs_err(sdp, "can't get quota file inode: %d\n", error); goto fail_rindex; } - - /* Get the root inode */ - error = gfs2_lookup_root(sdp); - if (error) { - fs_err(sdp, "can't read in root inode: %d\n", error); - goto fail_qinode; - } - - /* Get the root inode/dentry */ - inode = gfs2_ip2v(sdp->sd_root_dir); - if (!inode) { - fs_err(sdp, "can't get root inode\n"); - error = -ENOMEM; - goto fail_rooti; - } - - *dentry = d_alloc_root(inode); - if (!*dentry) { - iput(inode); - fs_err(sdp, "can't get root dentry\n"); - error = -ENOMEM; - goto fail_rooti; - } - return 0; - fail_dput: - dput(*dentry); - *dentry = NULL; +fail_qinode: + iput(sdp->sd_quota_inode); - fail_rooti: - gfs2_inode_put(sdp->sd_root_dir); - - fail_qinode: - gfs2_inode_put(sdp->sd_quota_inode); - - fail_rindex: +fail_rindex: gfs2_clear_rgrpd(sdp); - gfs2_inode_put(sdp->sd_rindex); + iput(sdp->sd_rindex); - fail_statfs: - gfs2_inode_put(sdp->sd_statfs_inode); - - fail: - gfs2_inode_put(sdp->sd_inum_inode); +fail_statfs: + iput(sdp->sd_statfs_inode); +fail_inum: + iput(sdp->sd_inum_inode); +fail_journal: + init_journal(sdp, UNDO); +fail_master: + iput(sdp->sd_master_dir); +fail: return error; } static int init_per_node(struct gfs2_sbd *sdp, int undo) { - struct gfs2_inode *pn = NULL; + struct inode *pn = NULL; char buf[30]; int error = 0; @@ -626,10 +635,10 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) goto fail_ut_i; } - gfs2_inode_put(pn); + iput(pn); pn = NULL; - error = gfs2_glock_nq_init(sdp->sd_ir_inode->i_gl, + error = gfs2_glock_nq_init(get_v2ip(sdp->sd_ir_inode)->i_gl, LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, &sdp->sd_ir_gh); if (error) { @@ -637,7 +646,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) goto fail_qc_i; } - error = gfs2_glock_nq_init(sdp->sd_sc_inode->i_gl, + error = gfs2_glock_nq_init(get_v2ip(sdp->sd_sc_inode)->i_gl, LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, &sdp->sd_sc_gh); if (error) { @@ -645,7 +654,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) goto fail_ir_gh; } - error = gfs2_glock_nq_init(sdp->sd_ut_inode->i_gl, + error = gfs2_glock_nq_init(get_v2ip(sdp->sd_ut_inode)->i_gl, LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, &sdp->sd_ut_gh); if (error) { @@ -653,7 +662,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) goto fail_sc_gh; } - error = gfs2_glock_nq_init(sdp->sd_qc_inode->i_gl, + error = gfs2_glock_nq_init(get_v2ip(sdp->sd_qc_inode)->i_gl, LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, &sdp->sd_qc_gh); if (error) { @@ -676,20 +685,20 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) gfs2_glock_dq_uninit(&sdp->sd_ir_gh); fail_qc_i: - gfs2_inode_put(sdp->sd_qc_inode); + iput(sdp->sd_qc_inode); fail_ut_i: - gfs2_inode_put(sdp->sd_ut_inode); + iput(sdp->sd_ut_inode); fail_sc_i: - gfs2_inode_put(sdp->sd_sc_inode); + iput(sdp->sd_sc_inode); fail_ir_i: - gfs2_inode_put(sdp->sd_ir_inode); + iput(sdp->sd_ir_inode); fail: if (pn) - gfs2_inode_put(pn); + iput(pn); return error; } @@ -793,14 +802,10 @@ static int fill_super(struct super_block *sb, void *data, int silent) error = init_sb(sdp, silent, DO); if (error) goto fail_locking; - - error = init_journal(sdp, DO); - if (error) - goto fail_sb; error = init_inodes(sdp, DO); if (error) - goto fail_journals; + goto fail_sb; error = init_per_node(sdp, DO); if (error) @@ -837,9 +842,6 @@ static int fill_super(struct super_block *sb, void *data, int silent) fail_inodes: init_inodes(sdp, UNDO); - fail_journals: - init_journal(sdp, UNDO); - fail_sb: init_sb(sdp, 0, UNDO); diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index ca6a4d81bc26..e06ef8dbd4d3 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -97,13 +97,13 @@ static void gfs2_put_super(struct super_block *sb) /* Release stuff */ - gfs2_inode_put(sdp->sd_master_dir); - gfs2_inode_put(sdp->sd_jindex); - gfs2_inode_put(sdp->sd_inum_inode); - gfs2_inode_put(sdp->sd_statfs_inode); - gfs2_inode_put(sdp->sd_rindex); - gfs2_inode_put(sdp->sd_quota_inode); - gfs2_inode_put(sdp->sd_root_dir); + iput(sdp->sd_master_dir); + iput(sdp->sd_jindex); + iput(sdp->sd_inum_inode); + iput(sdp->sd_statfs_inode); + iput(sdp->sd_rindex); + iput(sdp->sd_quota_inode); + iput(sdp->sd_root_dir); gfs2_glock_put(sdp->sd_rename_gl); gfs2_glock_put(sdp->sd_trans_gl); @@ -115,10 +115,10 @@ static void gfs2_put_super(struct super_block *sb) gfs2_glock_dq_uninit(&sdp->sd_sc_gh); gfs2_glock_dq_uninit(&sdp->sd_ut_gh); gfs2_glock_dq_uninit(&sdp->sd_qc_gh); - gfs2_inode_put(sdp->sd_ir_inode); - gfs2_inode_put(sdp->sd_sc_inode); - gfs2_inode_put(sdp->sd_ut_inode); - gfs2_inode_put(sdp->sd_qc_inode); + iput(sdp->sd_ir_inode); + iput(sdp->sd_sc_inode); + iput(sdp->sd_ut_inode); + iput(sdp->sd_qc_inode); } gfs2_glock_dq_uninit(&sdp->sd_live_gh); diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 5fb5a5305e0e..69e8f4e92e57 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -56,6 +56,7 @@ #include "rgrp.h" #include "super.h" #include "trans.h" +#include "ops_file.h" #define QUOTA_USER 1 #define QUOTA_GROUP 0 @@ -241,7 +242,7 @@ static void slot_put(struct gfs2_quota_data *qd) static int bh_get(struct gfs2_quota_data *qd) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; - struct gfs2_inode *ip = sdp->sd_qc_inode; + struct gfs2_inode *ip = get_v2ip(sdp->sd_qc_inode); unsigned int block, offset; uint64_t dblock; int new = 0; @@ -522,7 +523,7 @@ static int sort_qd(const void *a, const void *b) static void do_qc(struct gfs2_quota_data *qd, int64_t change) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; - struct gfs2_inode *ip = sdp->sd_qc_inode; + struct gfs2_inode *ip = get_v2ip(sdp->sd_qc_inode); struct gfs2_quota_change *qc = qd->qd_bh_qc; int64_t x; @@ -563,12 +564,13 @@ static void do_qc(struct gfs2_quota_data *qd, int64_t change) static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) { struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd; - struct gfs2_inode *ip = sdp->sd_quota_inode; + struct gfs2_inode *ip = get_v2ip(sdp->sd_quota_inode); unsigned int data_blocks, ind_blocks; + struct file_ra_state ra_state; struct gfs2_holder *ghs, i_gh; unsigned int qx, x; struct gfs2_quota_data *qd; - uint64_t offset; + loff_t offset; unsigned int nalloc = 0; struct gfs2_alloc *al = NULL; int error; @@ -631,6 +633,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) goto out_gunlock; } + file_ra_state_init(&ra_state, ip->i_vnode->i_mapping); for (x = 0; x < num_qd; x++) { char buf[sizeof(struct gfs2_quota)]; struct gfs2_quota q; @@ -642,7 +645,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) sizeof(struct gfs2_quota) bytes. */ memset(buf, 0, sizeof(struct gfs2_quota)); - error = gfs2_jdata_read_mem(ip, buf, offset, + error = gfs2_internal_read(ip, &ra_state, buf, &offset, sizeof(struct gfs2_quota)); if (error < 0) goto out_end_trans; @@ -703,8 +706,10 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, struct gfs2_holder i_gh; struct gfs2_quota q; char buf[sizeof(struct gfs2_quota)]; + struct file_ra_state ra_state; int error; + file_ra_state_init(&ra_state, sdp->sd_quota_inode->i_mapping); restart: error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh); if (error) @@ -713,6 +718,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, gfs2_quota_lvb_in(&qd->qd_qb, qd->qd_gl->gl_lvb); if (force_refresh || qd->qd_qb.qb_magic != GFS2_MAGIC) { + loff_t pos; gfs2_glock_dq_uninit(q_gh); error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, @@ -720,16 +726,17 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, if (error) return error; - error = gfs2_glock_nq_init(sdp->sd_quota_inode->i_gl, + error = gfs2_glock_nq_init(get_v2ip(sdp->sd_quota_inode)->i_gl, LM_ST_SHARED, 0, &i_gh); if (error) goto fail; memset(buf, 0, sizeof(struct gfs2_quota)); - - error = gfs2_jdata_read_mem(sdp->sd_quota_inode, buf, - qd2offset(qd), + pos = qd2offset(qd); + error = gfs2_internal_read(get_v2ip(sdp->sd_quota_inode), + &ra_state, buf, + &pos, sizeof(struct gfs2_quota)); if (error < 0) goto fail_gunlock; @@ -1059,7 +1066,7 @@ int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, int gfs2_quota_init(struct gfs2_sbd *sdp) { - struct gfs2_inode *ip = sdp->sd_qc_inode; + struct gfs2_inode *ip = get_v2ip(sdp->sd_qc_inode); unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; unsigned int x, slot = 0; unsigned int found = 0; diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 87c80bbce1cf..758cc565813a 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -12,19 +12,20 @@ #include #include #include +#include #include #include "gfs2.h" #include "bits.h" #include "glock.h" #include "glops.h" -#include "jdata.h" #include "lops.h" #include "meta_io.h" #include "quota.h" #include "rgrp.h" #include "super.h" #include "trans.h" +#include "ops_file.h" /** * gfs2_rgrp_verify - Verify that a resource group is consistent @@ -268,8 +269,10 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd) static int gfs2_ri_update(struct gfs2_inode *ip) { struct gfs2_sbd *sdp = ip->i_sbd; + struct inode *inode = ip->i_vnode; struct gfs2_rgrpd *rgd; char buf[sizeof(struct gfs2_rindex)]; + struct file_ra_state ra_state; uint64_t junk = ip->i_di.di_size; int error; @@ -280,10 +283,10 @@ static int gfs2_ri_update(struct gfs2_inode *ip) clear_rgrpdi(sdp); + file_ra_state_init(&ra_state, inode->i_mapping); for (sdp->sd_rgrps = 0;; sdp->sd_rgrps++) { - error = gfs2_jdata_read_mem(ip, buf, - sdp->sd_rgrps * - sizeof(struct gfs2_rindex), + loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex); + error = gfs2_internal_read(ip, &ra_state, buf, &pos, sizeof(struct gfs2_rindex)); if (!error) break; @@ -350,7 +353,7 @@ static int gfs2_ri_update(struct gfs2_inode *ip) int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh) { - struct gfs2_inode *ip = sdp->sd_rindex; + struct gfs2_inode *ip = get_v2ip(sdp->sd_rindex); struct gfs2_glock *gl = ip->i_gl; int error; diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index cab7ab5fb506..bae32ba0c481 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -271,7 +271,7 @@ int gfs2_do_upgrade(struct gfs2_sbd *sdp, struct gfs2_glock *sb_gl) int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) { - struct gfs2_inode *dip = sdp->sd_jindex; + struct gfs2_inode *dip = get_v2ip(sdp->sd_jindex); struct qstr name; char buf[20]; struct gfs2_jdesc *jd; @@ -289,7 +289,7 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) name.len = sprintf(buf, "journal%u", sdp->sd_journals); - error = gfs2_dir_search(sdp->sd_jindex, &name, NULL, NULL); + error = gfs2_dir_search(get_v2ip(sdp->sd_jindex), &name, NULL, NULL); if (error == -ENOENT) { error = 0; break; @@ -437,6 +437,7 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd) int gfs2_lookup_master_dir(struct gfs2_sbd *sdp) { + struct inode *inode = NULL; struct gfs2_glock *gl; int error; @@ -444,8 +445,8 @@ int gfs2_lookup_master_dir(struct gfs2_sbd *sdp) sdp->sd_sb.sb_master_dir.no_addr, &gfs2_inode_glops, CREATE, &gl); if (!error) { - error = gfs2_inode_get(gl, &sdp->sd_sb.sb_master_dir, CREATE, - &sdp->sd_master_dir); + error = gfs2_lookup_simple(sdp->sd_root_dir, ".gfs2_admin", &inode); + sdp->sd_master_dir = inode; gfs2_glock_put(gl); } @@ -549,9 +550,9 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp) int gfs2_statfs_init(struct gfs2_sbd *sdp) { - struct gfs2_inode *m_ip = sdp->sd_statfs_inode; + struct gfs2_inode *m_ip = get_v2ip(sdp->sd_statfs_inode); struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; - struct gfs2_inode *l_ip = sdp->sd_sc_inode; + struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode); struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; struct buffer_head *m_bh, *l_bh; struct gfs2_holder gh; @@ -598,7 +599,7 @@ int gfs2_statfs_init(struct gfs2_sbd *sdp) void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, int64_t dinodes) { - struct gfs2_inode *l_ip = sdp->sd_sc_inode; + struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode); struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; struct buffer_head *l_bh; int error; @@ -624,8 +625,8 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, int gfs2_statfs_sync(struct gfs2_sbd *sdp) { - struct gfs2_inode *m_ip = sdp->sd_statfs_inode; - struct gfs2_inode *l_ip = sdp->sd_sc_inode; + struct gfs2_inode *m_ip = get_v2ip(sdp->sd_statfs_inode); + struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode); struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; struct gfs2_holder gh; diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c index b8d836e3a5c0..405b91b0295d 100644 --- a/fs/gfs2/unlinked.c +++ b/fs/gfs2/unlinked.c @@ -25,7 +25,7 @@ static int munge_ondisk(struct gfs2_sbd *sdp, unsigned int slot, struct gfs2_unlinked_tag *ut) { - struct gfs2_inode *ip = sdp->sd_ut_inode; + struct gfs2_inode *ip = get_v2ip(sdp->sd_ut_inode); unsigned int block, offset; uint64_t dblock; int new = 0; @@ -312,7 +312,7 @@ int gfs2_unlinked_dealloc(struct gfs2_sbd *sdp) int gfs2_unlinked_init(struct gfs2_sbd *sdp) { - struct gfs2_inode *ip = sdp->sd_ut_inode; + struct gfs2_inode *ip = get_v2ip(sdp->sd_ut_inode); unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; unsigned int x, slot = 0; unsigned int found = 0; From 257f9b4e97e9a6cceeb247cead92119a4396d37b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 31 Jan 2006 10:00:25 +0000 Subject: [PATCH 034/292] [GFS2] Update truncate function (shrinking partial blocks) Update the function in GFS2 which deals with truncation of partial blocks. Some of the code is "borrowed" from ext3 since it appears to give a good model of how to do this operation. The function is renamed gfs2_block_truncate_page accordingly. Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 2 +- fs/gfs2/ops_address.c | 2 +- fs/gfs2/page.c | 110 ++++++++++++++++++++++-------------------- fs/gfs2/page.h | 4 +- 4 files changed, 62 insertions(+), 56 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index ff4a9175b4e1..bd194f645c52 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -872,7 +872,7 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size) if (do_div(junk, sdp->sd_jbsize)) error = truncator_journaled(ip, size); } else if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1)) - error = gfs2_truncator_page(ip, size); + error = gfs2_block_truncate_page(ip->i_vnode->i_mapping); if (!error) { ip->i_di.di_size = size; diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index da5a0b445188..d611b2ad2e97 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -385,7 +385,7 @@ static int gfs2_commit_write(struct file *file, struct page *page, i_size_write(inode, file_size); } else { if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) - gfs2_page_add_databufs(sdp, page, from, to); + gfs2_page_add_databufs(ip, page, from, to); error = generic_commit_write(file, page, from, to); if (error) goto fail; diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c index 05453c5a06f0..ea31bceac4f2 100644 --- a/fs/gfs2/page.c +++ b/fs/gfs2/page.c @@ -21,6 +21,7 @@ #include "inode.h" #include "page.h" #include "trans.h" +#include "ops_address.h" /** * gfs2_pte_inval - Sync and invalidate all PTEs associated with a glock @@ -184,76 +185,81 @@ int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, } /** - * gfs2_truncator_page - truncate a partial data block in the page cache - * @ip: the inode - * @size: the size the file should be + * gfs2_block_truncate_page - Deal with zeroing out data for truncate * - * Returns: errno + * This is partly borrowed from ext3. */ - -int gfs2_truncator_page(struct gfs2_inode *ip, uint64_t size) +int gfs2_block_truncate_page(struct address_space *mapping) { + struct inode *inode = mapping->host; + struct gfs2_inode *ip = get_v2ip(inode); struct gfs2_sbd *sdp = ip->i_sbd; - struct inode *inode = ip->i_vnode; - struct page *page; + loff_t from = inode->i_size; + unsigned long index = from >> PAGE_CACHE_SHIFT; + unsigned offset = from & (PAGE_CACHE_SIZE-1); + unsigned blocksize, iblock, length, pos; struct buffer_head *bh; + struct page *page; void *kaddr; - uint64_t lbn, dbn; - unsigned long index; - unsigned int offset; - unsigned int bufnum; - int new = 0; - int error; + int err; - lbn = size >> inode->i_blkbits; - error = gfs2_block_map(ip, lbn, &new, &dbn, NULL); - if (error || !dbn) - return error; + page = grab_cache_page(mapping, index); + if (!page) + return 0; - index = size >> PAGE_CACHE_SHIFT; - offset = size & (PAGE_CACHE_SIZE - 1); - bufnum = lbn - (index << (PAGE_CACHE_SHIFT - inode->i_blkbits)); - - page = read_cache_page(inode->i_mapping, index, - (filler_t *)inode->i_mapping->a_ops->readpage, - NULL); - if (IS_ERR(page)) - return PTR_ERR(page); - - lock_page(page); - - if (!PageUptodate(page) || PageError(page)) { - error = -EIO; - goto out; - } - - kaddr = kmap(page); - memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset); - kunmap(page); + blocksize = inode->i_sb->s_blocksize; + length = blocksize - (offset & (blocksize - 1)); + iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits); if (!page_has_buffers(page)) - create_empty_buffers(page, 1 << inode->i_blkbits, - (1 << BH_Uptodate)); + create_empty_buffers(page, blocksize, 0); - for (bh = page_buffers(page); bufnum--; bh = bh->b_this_page) - /* Do nothing */; + /* Find the buffer that contains "offset" */ + bh = page_buffers(page); + pos = blocksize; + while (offset >= pos) { + bh = bh->b_this_page; + iblock++; + pos += blocksize; + } - if (!buffer_mapped(bh)) - map_bh(bh, inode->i_sb, dbn); + err = 0; - set_buffer_uptodate(bh); - if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) + if (!buffer_mapped(bh)) { + gfs2_get_block(inode, iblock, bh, 0); + /* unmapped? It's a hole - nothing to do */ + if (!buffer_mapped(bh)) + goto unlock; + } + + /* Ok, it's mapped. Make sure it's up-to-date */ + if (PageUptodate(page)) + set_buffer_uptodate(bh); + + if (!buffer_uptodate(bh)) { + err = -EIO; + ll_rw_block(READ, 1, &bh); + wait_on_buffer(bh); + /* Uhhuh. Read error. Complain and punt. */ + if (!buffer_uptodate(bh)) + goto unlock; + } + + if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED/* || gfs2_is_jdata(ip)*/) gfs2_trans_add_databuf(sdp, bh); - mark_buffer_dirty(bh); - out: + kaddr = kmap_atomic(page, KM_USER0); + memset(kaddr + offset, 0, length); + flush_dcache_page(page); + kunmap_atomic(kaddr, KM_USER0); + +unlock: unlock_page(page); page_cache_release(page); - - return error; + return err; } -void gfs2_page_add_databufs(struct gfs2_sbd *sdp, struct page *page, +void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, unsigned int from, unsigned int to) { struct buffer_head *head = page_buffers(page); @@ -267,7 +273,7 @@ void gfs2_page_add_databufs(struct gfs2_sbd *sdp, struct page *page, end = start + bsize; if (end <= from || start >= to) continue; - gfs2_trans_add_databuf(sdp, bh); + gfs2_trans_add_databuf(ip->i_sbd, bh); } } diff --git a/fs/gfs2/page.h b/fs/gfs2/page.h index 7ad8c99ee0ef..346e296420c6 100644 --- a/fs/gfs2/page.h +++ b/fs/gfs2/page.h @@ -16,8 +16,8 @@ void gfs2_page_sync(struct gfs2_glock *gl, int flags); int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, uint64_t block, void *private); -int gfs2_truncator_page(struct gfs2_inode *ip, uint64_t size); -void gfs2_page_add_databufs(struct gfs2_sbd *sdp, struct page *page, +int gfs2_block_truncate_page(struct address_space *mapping); +void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, unsigned int from, unsigned int to); #endif /* __PAGE_DOT_H__ */ From 18ec7d5c3f434aed9661ed10a9e1f48cdeb4981d Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 8 Feb 2006 11:50:51 +0000 Subject: [PATCH 035/292] [GFS2] Make journaled data files identical to normal files on disk This is a very large patch, with a few still to be resolved issues so you might want to check out the previous head of the tree since this is known to be unstable. Fixes for the various bugs will be forthcoming shortly. This patch removes the special data format which has been used up till now for journaled data files. Directories still retain the old format so that they will remain on disk compatible with earlier releases. As a result you can now do the following with journaled data files: 1) mmap them 2) export them over NFS 3) convert to/from normal files whenever you want to (the zero length restriction is gone) In addition the level at which GFS' locking is done has changed for all files (since they all now use the page cache) such that the locking is done at the page cache level rather than the level of the fs operations. This should mean that things like loopback mounts and other things which touch the page cache directly should now work. Current known issues: 1. There is a lock mode inversion problem related to the resource group hold function which needs to be resolved. 2. Any significant amount of I/O causes an oops with an offset of hex 320 (NULL pointer dereference) which appears to be related to a journaled data buffer appearing on a list where it shouldn't be. 3. Direct I/O writes are disabled for the time being (will reappear later) 4. There is probably a deadlock between the page lock and GFS' locks under certain combinations of mmap and fs operation I/O. 5. Issue relating to ref counting on internally used inodes causes a hang on umount (discovered before this patch, and not fixed by it) 6. One part of the directory metadata is different from GFS1 and will need to be resolved before next release. Signed-off-by: Steven Whitehouse --- fs/gfs2/Makefile | 1 - fs/gfs2/bmap.c | 59 +-- fs/gfs2/dir.c | 4 +- fs/gfs2/dir.h | 2 + fs/gfs2/inode.h | 7 +- fs/gfs2/jdata.c | 389 --------------- fs/gfs2/jdata.h | 52 -- fs/gfs2/log.c | 4 +- fs/gfs2/lops.c | 284 ++++++++++- fs/gfs2/meta_io.c | 16 +- fs/gfs2/ops_address.c | 260 ++++++---- fs/gfs2/ops_file.c | 953 ++++++------------------------------ fs/gfs2/ops_vm.c | 3 - fs/gfs2/page.c | 10 +- fs/gfs2/quota.c | 114 +++-- fs/gfs2/trans.c | 19 +- fs/gfs2/trans.h | 1 - fs/gfs2/util.c | 3 + include/linux/gfs2_ondisk.h | 7 + 19 files changed, 716 insertions(+), 1472 deletions(-) delete mode 100644 fs/gfs2/jdata.c delete mode 100644 fs/gfs2/jdata.h diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile index 4e87b8661af0..88f927948113 100644 --- a/fs/gfs2/Makefile +++ b/fs/gfs2/Makefile @@ -10,7 +10,6 @@ gfs2-y := \ glock.o \ glops.o \ inode.o \ - jdata.o \ lm.o \ log.o \ lops.o \ diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index bd194f645c52..4efcd8a39e98 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -18,12 +18,12 @@ #include "bmap.h" #include "glock.h" #include "inode.h" -#include "jdata.h" #include "meta_io.h" #include "page.h" #include "quota.h" #include "rgrp.h" #include "trans.h" +#include "dir.h" /* This doesn't need to be that large as max 64 bit pointers in a 4k * block is 512, so __u16 is fine for that. It saves stack space to @@ -90,7 +90,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, { struct buffer_head *bh, *dibh; uint64_t block = 0; - int journaled = gfs2_is_jdata(ip); + int isdir = gfs2_is_dir(ip); int error; down_write(&ip->i_rw_mutex); @@ -103,10 +103,10 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, /* Get a free block, fill it with the stuffed data, and write it out to disk */ - if (journaled) { + if (isdir) { block = gfs2_alloc_meta(ip); - error = gfs2_jdata_get_buffer(ip, block, 1, &bh); + error = gfs2_dir_get_buffer(ip, block, 1, &bh); if (error) goto out_brelse; gfs2_buffer_copy_tail(bh, @@ -168,7 +168,7 @@ static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size) if (ip->i_di.di_size > size) size = ip->i_di.di_size; - if (gfs2_is_jdata(ip)) { + if (gfs2_is_dir(ip)) { arr = sdp->sd_jheightsize; max = sdp->sd_max_jheight; } else { @@ -377,7 +377,7 @@ static void lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, return; if (height == ip->i_di.di_height - 1 && - !gfs2_is_jdata(ip)) + !gfs2_is_dir(ip)) *block = gfs2_alloc_data(ip); else *block = gfs2_alloc_meta(ip); @@ -430,7 +430,7 @@ int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) goto out; - bsize = (gfs2_is_jdata(ip)) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize; + bsize = (gfs2_is_dir(ip)) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize; height = calc_tree_height(ip, (lblock + 1) * bsize); if (ip->i_di.di_height < height) { @@ -618,7 +618,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, sm->sm_first = 0; } - metadata = (height != ip->i_di.di_height - 1) || gfs2_is_jdata(ip); + metadata = (height != ip->i_di.di_height - 1); if (metadata) revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs; @@ -814,33 +814,6 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size) return error; } -static int truncator_journaled(struct gfs2_inode *ip, uint64_t size) -{ - uint64_t lbn, dbn; - uint32_t off; - struct buffer_head *bh; - int new = 0; - int error; - - lbn = size; - off = do_div(lbn, ip->i_sbd->sd_jbsize); - - error = gfs2_block_map(ip, lbn, &new, &dbn, NULL); - if (error || !dbn) - return error; - - error = gfs2_jdata_get_buffer(ip, dbn, 0, &bh); - if (error) - return error; - - gfs2_trans_add_bh(ip->i_gl, bh, 1); - gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header) + off); - - brelse(bh); - - return 0; -} - static int trunc_start(struct gfs2_inode *ip, uint64_t size) { struct gfs2_sbd *sdp = ip->i_sbd; @@ -866,12 +839,7 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size) error = 1; } else { - if (journaled) { - uint64_t junk = size; - /* we're just interested in the modulus */ - if (do_div(junk, sdp->sd_jbsize)) - error = truncator_journaled(ip, size); - } else if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1)) + if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1)) error = gfs2_block_truncate_page(ip->i_vnode->i_mapping); if (!error) { @@ -900,10 +868,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size) if (!size) lblock = 0; - else if (gfs2_is_jdata(ip)) { - lblock = size - 1; - do_div(lblock, ip->i_sbd->sd_jbsize); - } else + else lblock = (size - 1) >> ip->i_sbd->sd_sb.sb_bsize_shift; find_metapath(ip, lblock, &mp); @@ -1051,7 +1016,7 @@ void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, struct gfs2_sbd *sdp = ip->i_sbd; unsigned int tmp; - if (gfs2_is_jdata(ip)) { + if (gfs2_is_dir(ip)) { *data_blocks = DIV_RU(len, sdp->sd_jbsize) + 2; *ind_blocks = 3 * (sdp->sd_max_jheight - 1); } else { @@ -1096,7 +1061,7 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, return 0; } - if (gfs2_is_jdata(ip)) { + if (gfs2_is_dir(ip)) { unsigned int bsize = sdp->sd_jbsize; lblock = offset; do_div(lblock, bsize); diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index ada283a0f5f3..c77e18048d98 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -86,8 +86,8 @@ typedef int (*leaf_call_t) (struct gfs2_inode *dip, uint32_t index, uint32_t len, uint64_t leaf_no, void *data); -static int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, - struct buffer_head **bhp) +int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, + struct buffer_head **bhp) { struct buffer_head *bh; int error = 0; diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h index ff6d1c597ee9..5b01497b3ab3 100644 --- a/fs/gfs2/dir.h +++ b/fs/gfs2/dir.h @@ -45,5 +45,7 @@ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip); int gfs2_diradd_alloc_required(struct gfs2_inode *dip, struct qstr *filename, int *alloc_required); +int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, + struct buffer_head **bhp); #endif /* __DIR_DOT_H__ */ diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index e42ae38d6778..214975c6bb22 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -20,6 +20,11 @@ static inline int gfs2_is_jdata(struct gfs2_inode *ip) return ip->i_di.di_flags & GFS2_DIF_JDATA; } +static inline int gfs2_is_dir(struct gfs2_inode *ip) +{ + return S_ISDIR(ip->i_di.di_mode); +} + void gfs2_inode_attr_in(struct gfs2_inode *ip); void gfs2_inode_attr_out(struct gfs2_inode *ip); struct inode *gfs2_ip2v_lookup(struct gfs2_inode *ip); @@ -72,9 +77,9 @@ static inline int gfs2_lookup_simple(struct inode *dip, char *name, err = gfs2_lookupi(get_v2ip(dip), &qstr, 1, &ip); if (err == 0) { *ipp = gfs2_ip2v(ip); + gfs2_inode_put(ip); if (*ipp == NULL) err = -ENOMEM; - gfs2_inode_put(ip); } return err; } diff --git a/fs/gfs2/jdata.c b/fs/gfs2/jdata.c deleted file mode 100644 index e43eaf133f10..000000000000 --- a/fs/gfs2/jdata.c +++ /dev/null @@ -1,389 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "gfs2.h" -#include "bmap.h" -#include "inode.h" -#include "jdata.h" -#include "meta_io.h" -#include "trans.h" - -int gfs2_internal_read(struct gfs2_inode *ip, - struct file_ra_state *ra_state, - char *buf, loff_t *pos, unsigned size) -{ - return gfs2_jdata_read_mem(ip, buf, *pos, size); -} - -int gfs2_jdata_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, - struct buffer_head **bhp) -{ - struct buffer_head *bh; - int error = 0; - - if (new) { - bh = gfs2_meta_new(ip->i_gl, block); - gfs2_trans_add_bh(ip->i_gl, bh, 1); - gfs2_metatype_set(bh, GFS2_METATYPE_JD, GFS2_FORMAT_JD); - gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); - } else { - error = gfs2_meta_read(ip->i_gl, block, - DIO_START | DIO_WAIT, &bh); - if (error) - return error; - if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_JD)) { - brelse(bh); - return -EIO; - } - } - - *bhp = bh; - - return 0; -} - -/** - * gfs2_copy2mem - Trivial copy function for gfs2_jdata_read() - * @bh: The buffer to copy from, or NULL meaning zero the buffer - * @buf: The buffer to copy/zero - * @offset: The offset in the buffer to copy from - * @size: The amount of data to copy/zero - * - * Returns: errno - */ - -int gfs2_copy2mem(struct buffer_head *bh, char **buf, unsigned int offset, - unsigned int size) -{ - if (bh) - memcpy(*buf, bh->b_data + offset, size); - else - memset(*buf, 0, size); - *buf += size; - return 0; -} - -/** - * gfs2_copy2user - Copy bytes to user space for gfs2_jdata_read() - * @bh: The buffer - * @buf: The destination of the data - * @offset: The offset into the buffer - * @size: The amount of data to copy - * - * Returns: errno - */ - -int gfs2_copy2user(struct buffer_head *bh, char **buf, unsigned int offset, - unsigned int size) -{ - int error; - - if (bh) - error = copy_to_user(*buf, bh->b_data + offset, size); - else - error = clear_user(*buf, size); - - if (error) - error = -EFAULT; - else - *buf += size; - - return error; -} - -static int jdata_read_stuffed(struct gfs2_inode *ip, char *buf, - unsigned int offset, unsigned int size, - read_copy_fn_t copy_fn) -{ - struct buffer_head *dibh; - int error; - - error = gfs2_meta_inode_buffer(ip, &dibh); - if (!error) { - error = copy_fn(dibh, &buf, - offset + sizeof(struct gfs2_dinode), size); - brelse(dibh); - } - - return (error) ? error : size; -} - -/** - * gfs2_jdata_read - Read a jdata file - * @ip: The GFS2 Inode - * @buf: The buffer to place result into - * @offset: File offset to begin jdata_readng from - * @size: Amount of data to transfer - * @copy_fn: Function to actually perform the copy - * - * The @copy_fn only copies a maximum of a single block at once so - * we are safe calling it with int arguments. It is done so that - * we don't needlessly put 64bit arguments on the stack and it - * also makes the code in the @copy_fn nicer too. - * - * Returns: The amount of data actually copied or the error - */ - -int gfs2_jdata_read(struct gfs2_inode *ip, char __user *buf, uint64_t offset, - unsigned int size, read_copy_fn_t copy_fn) -{ - struct gfs2_sbd *sdp = ip->i_sbd; - uint64_t lblock, dblock; - uint32_t extlen = 0; - unsigned int o; - int copied = 0; - int error = 0; - - if (offset >= ip->i_di.di_size) - return 0; - - if ((offset + size) > ip->i_di.di_size) - size = ip->i_di.di_size - offset; - - if (!size) - return 0; - - if (gfs2_is_stuffed(ip)) - return jdata_read_stuffed(ip, buf, (unsigned int)offset, size, - copy_fn); - - if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) - return -EINVAL; - - lblock = offset; - o = do_div(lblock, sdp->sd_jbsize) + - sizeof(struct gfs2_meta_header); - - while (copied < size) { - unsigned int amount; - struct buffer_head *bh; - int new; - - amount = size - copied; - if (amount > sdp->sd_sb.sb_bsize - o) - amount = sdp->sd_sb.sb_bsize - o; - - if (!extlen) { - new = 0; - error = gfs2_block_map(ip, lblock, &new, - &dblock, &extlen); - if (error) - goto fail; - } - - if (extlen > 1) - gfs2_meta_ra(ip->i_gl, dblock, extlen); - - if (dblock) { - error = gfs2_jdata_get_buffer(ip, dblock, new, &bh); - if (error) - goto fail; - dblock++; - extlen--; - } else - bh = NULL; - - error = copy_fn(bh, &buf, o, amount); - brelse(bh); - if (error) - goto fail; - - copied += amount; - lblock++; - - o = sizeof(struct gfs2_meta_header); - } - - return copied; - - fail: - return (copied) ? copied : error; -} - -/** - * gfs2_copy_from_mem - Trivial copy function for gfs2_jdata_write() - * @bh: The buffer to copy to or clear - * @buf: The buffer to copy from - * @offset: The offset in the buffer to write to - * @size: The amount of data to write - * - * Returns: errno - */ - -int gfs2_copy_from_mem(struct gfs2_inode *ip, struct buffer_head *bh, - const char **buf, unsigned int offset, unsigned int size) -{ - gfs2_trans_add_bh(ip->i_gl, bh, 1); - memcpy(bh->b_data + offset, *buf, size); - - *buf += size; - - return 0; -} - -/** - * gfs2_copy_from_user - Copy bytes from user space for gfs2_jdata_write() - * @bh: The buffer to copy to or clear - * @buf: The buffer to copy from - * @offset: The offset in the buffer to write to - * @size: The amount of data to write - * - * Returns: errno - */ - -int gfs2_copy_from_user(struct gfs2_inode *ip, struct buffer_head *bh, - const char __user **buf, unsigned int offset, unsigned int size) -{ - int error = 0; - - gfs2_trans_add_bh(ip->i_gl, bh, 1); - if (copy_from_user(bh->b_data + offset, *buf, size)) - error = -EFAULT; - else - *buf += size; - - return error; -} - -static int jdata_write_stuffed(struct gfs2_inode *ip, char *buf, - unsigned int offset, unsigned int size, - write_copy_fn_t copy_fn) -{ - struct buffer_head *dibh; - int error; - - error = gfs2_meta_inode_buffer(ip, &dibh); - if (error) - return error; - - error = copy_fn(ip, - dibh, &buf, - offset + sizeof(struct gfs2_dinode), size); - if (!error) { - if (ip->i_di.di_size < offset + size) - ip->i_di.di_size = offset + size; - ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); - gfs2_dinode_out(&ip->i_di, dibh->b_data); - } - - brelse(dibh); - - return (error) ? error : size; -} - -/** - * gfs2_jdata_write - Write bytes to a file - * @ip: The GFS2 inode - * @buf: The buffer containing information to be written - * @offset: The file offset to start writing at - * @size: The amount of data to write - * @copy_fn: Function to do the actual copying - * - * Returns: The number of bytes correctly written or error code - */ - -int gfs2_jdata_write(struct gfs2_inode *ip, const char __user *buf, uint64_t offset, - unsigned int size, write_copy_fn_t copy_fn) -{ - struct gfs2_sbd *sdp = ip->i_sbd; - struct buffer_head *dibh; - uint64_t lblock, dblock; - uint32_t extlen = 0; - unsigned int o; - int copied = 0; - int error = 0; - - if (!size) - return 0; - - if (gfs2_is_stuffed(ip) && - offset + size <= sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) - return jdata_write_stuffed(ip, buf, (unsigned int)offset, size, - copy_fn); - - if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) - return -EINVAL; - - if (gfs2_is_stuffed(ip)) { - error = gfs2_unstuff_dinode(ip, NULL, NULL); - if (error) - return error; - } - - lblock = offset; - o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header); - - while (copied < size) { - unsigned int amount; - struct buffer_head *bh; - int new; - - amount = size - copied; - if (amount > sdp->sd_sb.sb_bsize - o) - amount = sdp->sd_sb.sb_bsize - o; - - if (!extlen) { - new = 1; - error = gfs2_block_map(ip, lblock, &new, - &dblock, &extlen); - if (error) - goto fail; - error = -EIO; - if (gfs2_assert_withdraw(sdp, dblock)) - goto fail; - } - - error = gfs2_jdata_get_buffer(ip, dblock, - (amount == sdp->sd_jbsize) ? 1 : new, - &bh); - if (error) - goto fail; - - error = copy_fn(ip, bh, &buf, o, amount); - brelse(bh); - if (error) - goto fail; - - copied += amount; - lblock++; - dblock++; - extlen--; - - o = sizeof(struct gfs2_meta_header); - } - - out: - error = gfs2_meta_inode_buffer(ip, &dibh); - if (error) - return error; - - if (ip->i_di.di_size < offset + copied) - ip->i_di.di_size = offset + copied; - ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); - - gfs2_trans_add_bh(ip->i_gl, dibh, 1); - gfs2_dinode_out(&ip->i_di, dibh->b_data); - brelse(dibh); - - return copied; - - fail: - if (copied) - goto out; - return error; -} - diff --git a/fs/gfs2/jdata.h b/fs/gfs2/jdata.h deleted file mode 100644 index 95e18fcb8f82..000000000000 --- a/fs/gfs2/jdata.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#ifndef __FILE_DOT_H__ -#define __FILE_DOT_H__ - -int gfs2_jdata_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, - struct buffer_head **bhp); - -typedef int (*read_copy_fn_t) (struct buffer_head *bh, char **buf, - unsigned int offset, unsigned int size); -typedef int (*write_copy_fn_t) (struct gfs2_inode *ip, - struct buffer_head *bh, const char **buf, - unsigned int offset, unsigned int size); - -int gfs2_copy2mem(struct buffer_head *bh, char **buf, - unsigned int offset, unsigned int size); -int gfs2_copy2user(struct buffer_head *bh, char __user **buf, - unsigned int offset, unsigned int size); -int gfs2_jdata_read(struct gfs2_inode *ip, char __user *buf, - uint64_t offset, unsigned int size, - read_copy_fn_t copy_fn); - -int gfs2_copy_from_mem(struct gfs2_inode *ip, - struct buffer_head *bh, const char **buf, - unsigned int offset, unsigned int size); -int gfs2_copy_from_user(struct gfs2_inode *ip, - struct buffer_head *bh, const char __user **buf, - unsigned int offset, unsigned int size); -int gfs2_jdata_write(struct gfs2_inode *ip, const char __user *buf, - uint64_t offset, unsigned int size, - write_copy_fn_t copy_fn); - -static inline int gfs2_jdata_read_mem(struct gfs2_inode *ip, char *buf, - uint64_t offset, unsigned int size) -{ - return gfs2_jdata_read(ip, (__force char __user *)buf, offset, size, gfs2_copy2mem); -} - -static inline int gfs2_jdata_write_mem(struct gfs2_inode *ip, const char *buf, - uint64_t offset, unsigned int size) -{ - return gfs2_jdata_write(ip, (__force const char __user *)buf, offset, size, gfs2_copy_from_mem); -} - -#endif /* __FILE_DOT_H__ */ diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index f6d00130f96f..9b4484d366ca 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -387,8 +387,7 @@ struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, bh = lb->lb_bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL); atomic_set(&bh->b_count, 1); bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate); - set_bh_page(bh, virt_to_page(real->b_data), - ((unsigned long)real->b_data) & (PAGE_SIZE - 1)); + set_bh_page(bh, real->b_page, bh_offset(real)); bh->b_blocknr = blkno; bh->b_size = sdp->sd_sb.sb_bsize; bh->b_bdev = sdp->sd_vfs->s_bdev; @@ -634,6 +633,7 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp) gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); gfs2_assert_withdraw(sdp, !sdp->sd_log_num_gl); gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf); + gfs2_assert_withdraw(sdp, !sdp->sd_log_num_jdata); gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg); gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf); diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index a065f7667238..dd41863810d7 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -428,49 +428,188 @@ static void rg_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) gfs2_assert_warn(sdp, !sdp->sd_log_num_rg); } +/** + * databuf_lo_add - Add a databuf to the transaction. + * + * This is used in two distinct cases: + * i) In ordered write mode + * We put the data buffer on a list so that we can ensure that its + * synced to disk at the right time + * ii) In journaled data mode + * We need to journal the data block in the same way as metadata in + * the functions above. The difference is that here we have a tag + * which is two __be64's being the block number (as per meta data) + * and a flag which says whether the data block needs escaping or + * not. This means we need a new log entry for each 251 or so data + * blocks, which isn't an enormous overhead but twice as much as + * for normal metadata blocks. + */ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) { - get_transaction->tr_touched = 1; + struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le); + struct gfs2_trans *tr = get_transaction; + struct address_space *mapping = bd->bd_bh->b_page->mapping; + struct gfs2_inode *ip = get_v2ip(mapping->host); + tr->tr_touched = 1; + if (!list_empty(&bd->bd_list_tr) && + (ip->i_di.di_flags & GFS2_DIF_JDATA)) { + tr->tr_num_buf++; + gfs2_trans_add_gl(bd->bd_gl); + list_add(&bd->bd_list_tr, &tr->tr_list_buf); + gfs2_pin(sdp, bd->bd_bh); + } else { + clear_buffer_pinned(bd->bd_bh); + } gfs2_log_lock(sdp); + if (ip->i_di.di_flags & GFS2_DIF_JDATA) + sdp->sd_log_num_jdata++; sdp->sd_log_num_databuf++; list_add(&le->le_list, &sdp->sd_log_le_databuf); gfs2_log_unlock(sdp); } +static int gfs2_check_magic(struct buffer_head *bh) +{ + struct page *page = bh->b_page; + void *kaddr; + __be32 *ptr; + int rv = 0; + + kaddr = kmap_atomic(page, KM_USER0); + ptr = kaddr + bh_offset(bh); + if (*ptr == cpu_to_be32(GFS2_MAGIC)) + rv = 1; + kunmap_atomic(page, KM_USER0); + + return rv; +} + +/** + * databuf_lo_before_commit - Scan the data buffers, writing as we go + * + * Here we scan through the lists of buffers and make the assumption + * that any buffer thats been pinned is being journaled, and that + * any unpinned buffer is an ordered write data buffer and therefore + * will be written back rather than journaled. + */ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) { - struct list_head *head = &sdp->sd_log_le_databuf; LIST_HEAD(started); - struct gfs2_bufdata *bd; - struct buffer_head *bh; + struct gfs2_bufdata *bd1 = NULL, *bd2, *bdt; + struct buffer_head *bh = NULL; + unsigned int offset = sizeof(struct gfs2_log_descriptor); + struct gfs2_log_descriptor *ld; + unsigned int limit; + unsigned int total_dbuf = sdp->sd_log_num_databuf; + unsigned int total_jdata = sdp->sd_log_num_jdata; + unsigned int num, n; + __be64 *ptr; - while (!list_empty(head)) { - bd = list_entry(head->prev, struct gfs2_bufdata, bd_le.le_list); - list_move(&bd->bd_le.le_list, &started); + offset += (2*sizeof(__be64) - 1); + offset &= ~(2*sizeof(__be64) - 1); + limit = (sdp->sd_sb.sb_bsize - offset)/sizeof(__be64); - gfs2_log_lock(sdp); - bh = bd->bd_bh; - if (bh) { - get_bh(bh); - gfs2_log_unlock(sdp); - if (buffer_dirty(bh)) { - wait_on_buffer(bh); - ll_rw_block(WRITE, 1, &bh); + /* printk(KERN_INFO "totals: jdata=%u dbuf=%u\n", total_jdata, total_dbuf); */ + /* + * Start writing ordered buffers, write journaled buffers + * into the log along with a header + */ + bd2 = bd1 = list_prepare_entry(bd1, &sdp->sd_log_le_databuf, bd_le.le_list); + while(total_dbuf) { + num = total_jdata; + if (num > limit) + num = limit; + n = 0; + list_for_each_entry_safe_continue(bd1, bdt, &sdp->sd_log_le_databuf, bd_le.le_list) { + gfs2_log_lock(sdp); + /* An ordered write buffer */ + if (bd1->bd_bh && !buffer_pinned(bd1->bd_bh)) { + list_move(&bd1->bd_le.le_list, &started); + if (bd1 == bd2) { + bd2 = NULL; + bd2 = list_prepare_entry(bd2, &sdp->sd_log_le_databuf, bd_le.le_list); + } + total_dbuf--; + if (bd1->bd_bh) { + get_bh(bd1->bd_bh); + gfs2_log_unlock(sdp); + if (buffer_dirty(bd1->bd_bh)) { + wait_on_buffer(bd1->bd_bh); + ll_rw_block(WRITE, 1, &bd1->bd_bh); + } + brelse(bd1->bd_bh); + continue; + } + gfs2_log_unlock(sdp); + continue; + } else if (bd1->bd_bh) { /* A journaled buffer */ + int magic; + gfs2_log_unlock(sdp); + /* printk(KERN_INFO "journaled buffer\n"); */ + if (!bh) { + bh = gfs2_log_get_buf(sdp); + ld = (struct gfs2_log_descriptor *)bh->b_data; + ptr = (__be64 *)(bh->b_data + offset); + ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC); + ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD); + ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD); + ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_JDATA); + ld->ld_length = cpu_to_be32(num + 1); + ld->ld_data1 = cpu_to_be32(num); + ld->ld_data2 = cpu_to_be32(0); + memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved)); + } + magic = gfs2_check_magic(bd1->bd_bh); + *ptr++ = cpu_to_be64(bd1->bd_bh->b_blocknr); + *ptr++ = cpu_to_be64((__u64)magic); + clear_buffer_escaped(bd1->bd_bh); + if (unlikely(magic != 0)) + set_buffer_escaped(bd1->bd_bh); + if (n++ > num) + break; } - brelse(bh); - } else - gfs2_log_unlock(sdp); + } + if (bh) { + set_buffer_dirty(bh); + ll_rw_block(WRITE, 1, &bh); + bh = NULL; + } + n = 0; + /* printk(KERN_INFO "totals2: jdata=%u dbuf=%u\n", total_jdata, total_dbuf); */ + list_for_each_entry_continue(bd2, &sdp->sd_log_le_databuf, bd_le.le_list) { + if (!bd2->bd_bh) + continue; + /* copy buffer if it needs escaping */ + if (unlikely(buffer_escaped(bd2->bd_bh))) { + void *kaddr; + struct page *page = bd2->bd_bh->b_page; + bh = gfs2_log_get_buf(sdp); + kaddr = kmap_atomic(page, KM_USER0); + memcpy(bh->b_data, kaddr + bh_offset(bd2->bd_bh), sdp->sd_sb.sb_bsize); + kunmap_atomic(page, KM_USER0); + *(__be32 *)bh->b_data = 0; + } else { + bh = gfs2_log_fake_buf(sdp, bd2->bd_bh); + } + set_buffer_dirty(bh); + ll_rw_block(WRITE, 1, &bh); + if (++n >= num) + break; + } + bh = NULL; + total_dbuf -= num; + total_jdata -= num; } - + /* printk(KERN_INFO "wait on ordered data buffers\n"); */ + /* Wait on all ordered buffers */ while (!list_empty(&started)) { - bd = list_entry(started.next, struct gfs2_bufdata, - bd_le.le_list); - list_del(&bd->bd_le.le_list); + bd1 = list_entry(started.next, struct gfs2_bufdata, bd_le.le_list); + list_del(&bd1->bd_le.le_list); sdp->sd_log_num_databuf--; gfs2_log_lock(sdp); - bh = bd->bd_bh; + bh = bd1->bd_bh; if (bh) { set_v2bd(bh, NULL); gfs2_log_unlock(sdp); @@ -479,12 +618,103 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) } else gfs2_log_unlock(sdp); - kfree(bd); + kfree(bd1); } - gfs2_assert_warn(sdp, !sdp->sd_log_num_databuf); + /* printk(KERN_INFO "sd_log_num_databuf %u sd_log_num_jdata %u\n", sdp->sd_log_num_databuf, sdp->sd_log_num_jdata); */ + /* We've removed all the ordered write bufs here, so only jdata left */ + gfs2_assert_warn(sdp, sdp->sd_log_num_databuf == sdp->sd_log_num_jdata); } +static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, + struct gfs2_log_descriptor *ld, + __be64 *ptr, int pass) +{ + struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_glock *gl = jd->jd_inode->i_gl; + unsigned int blks = be32_to_cpu(ld->ld_data1); + struct buffer_head *bh_log, *bh_ip; + uint64_t blkno; + uint64_t esc; + int error = 0; + + if (pass != 1 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_JDATA) + return 0; + + gfs2_replay_incr_blk(sdp, &start); + for (; blks; gfs2_replay_incr_blk(sdp, &start), blks--) { + blkno = be64_to_cpu(*ptr++); + esc = be64_to_cpu(*ptr++); + + sdp->sd_found_blocks++; + + if (gfs2_revoke_check(sdp, blkno, start)) + continue; + + error = gfs2_replay_read_block(jd, start, &bh_log); + if (error) + return error; + + bh_ip = gfs2_meta_new(gl, blkno); + memcpy(bh_ip->b_data, bh_log->b_data, bh_log->b_size); + + /* Unescape */ + if (esc) { + __be32 *eptr = (__be32 *)bh_ip->b_data; + *eptr = cpu_to_be32(GFS2_MAGIC); + } + mark_buffer_dirty(bh_ip); + + brelse(bh_log); + brelse(bh_ip); + if (error) + break; + + sdp->sd_replayed_blocks++; + } + + return error; +} + +/* FIXME: sort out accounting for log blocks etc. */ + +static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) +{ + struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + + if (error) { + gfs2_meta_sync(jd->jd_inode->i_gl, DIO_START | DIO_WAIT); + return; + } + if (pass != 1) + return; + + /* data sync? */ + gfs2_meta_sync(jd->jd_inode->i_gl, DIO_START | DIO_WAIT); + + fs_info(sdp, "jid=%u: Replayed %u of %u data blocks\n", + jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); +} + +static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) +{ + struct list_head *head = &sdp->sd_log_le_databuf; + struct gfs2_bufdata *bd; + + while (!list_empty(head)) { + bd = list_entry(head->next, struct gfs2_bufdata, bd_le.le_list); + list_del_init(&bd->bd_le.le_list); + sdp->sd_log_num_databuf--; + sdp->sd_log_num_jdata--; + gfs2_unpin(sdp, bd->bd_bh, ai); + brelse(bd->bd_bh); + kfree(bd); + } + gfs2_assert_warn(sdp, !sdp->sd_log_num_databuf); + gfs2_assert_warn(sdp, !sdp->sd_log_num_jdata); +} + + struct gfs2_log_operations gfs2_glock_lops = { .lo_add = glock_lo_add, .lo_after_commit = glock_lo_after_commit, @@ -519,7 +749,11 @@ struct gfs2_log_operations gfs2_rg_lops = { struct gfs2_log_operations gfs2_databuf_lops = { .lo_add = databuf_lo_add, + .lo_incore_commit = buf_lo_incore_commit, .lo_before_commit = databuf_lo_before_commit, + .lo_after_commit = databuf_lo_after_commit, + .lo_scan_elements = databuf_lo_scan_elements, + .lo_after_scan = databuf_lo_after_scan, .lo_name = "databuf" }; diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index b6bd2ebfc2cc..ef58d43b67ee 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -547,10 +547,12 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta { struct gfs2_bufdata *bd; - lock_page(bh->b_page); + if (meta) + lock_page(bh->b_page); if (get_v2bd(bh)) { - unlock_page(bh->b_page); + if (meta) + unlock_page(bh->b_page); return; } @@ -563,14 +565,16 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta bd->bd_gl = gl; INIT_LIST_HEAD(&bd->bd_list_tr); - if (meta) + if (meta) { lops_init_le(&bd->bd_le, &gfs2_buf_lops); - else + } else { lops_init_le(&bd->bd_le, &gfs2_databuf_lops); - + get_bh(bh); + } set_v2bd(bh, bd); - unlock_page(bh->b_page); + if (meta) + unlock_page(bh->b_page); } /** diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index d611b2ad2e97..b14357e89421 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -20,13 +20,13 @@ #include "bmap.h" #include "glock.h" #include "inode.h" -#include "jdata.h" #include "log.h" #include "meta_io.h" #include "ops_address.h" #include "page.h" #include "quota.h" #include "trans.h" +#include "rgrp.h" /** * gfs2_get_block - Fills in a buffer head with details about a block @@ -149,33 +149,55 @@ static int get_blocks_noalloc(struct inode *inode, sector_t lblock, * * Returns: errno * - * Use Linux VFS block_write_full_page() to write one page, - * using GFS2's get_block_noalloc to find which blocks to write. + * Some of this is copied from block_write_full_page() although we still + * call it to do most of the work. */ static int gfs2_writepage(struct page *page, struct writeback_control *wbc) { + struct inode *inode = page->mapping->host; struct gfs2_inode *ip = get_v2ip(page->mapping->host); struct gfs2_sbd *sdp = ip->i_sbd; + loff_t i_size = i_size_read(inode); + pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT; + unsigned offset; int error; + int done_trans = 0; atomic_inc(&sdp->sd_ops_address); - if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(ip->i_gl))) { unlock_page(page); return -EIO; } - if (get_transaction) { - redirty_page_for_writepage(wbc, page); + if (get_transaction) + goto out_ignore; + + /* Is the page fully outside i_size? (truncate in progress) */ + offset = i_size & (PAGE_CACHE_SIZE-1); + if (page->index >= end_index+1 || !offset) { + page->mapping->a_ops->invalidatepage(page, 0); unlock_page(page); - return 0; + return 0; /* don't care */ + } + + if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) { + error = gfs2_trans_begin(sdp, RES_DINODE + 1, 0); + if (error) + goto out_ignore; + gfs2_page_add_databufs(ip, page, 0, sdp->sd_vfs->s_blocksize-1); + done_trans = 1; } error = block_write_full_page(page, get_block_noalloc, wbc); - + if (done_trans) + gfs2_trans_end(sdp); gfs2_meta_cache_flush(ip); - return error; + +out_ignore: + redirty_page_for_writepage(wbc, page); + unlock_page(page); + return 0; } /** @@ -226,41 +248,10 @@ static int zero_readpage(struct page *page) return 0; } -/** - * jdata_readpage - readpage that goes through gfs2_jdata_read_mem() - * @ip: - * @page: The page to read - * - * Returns: errno - */ - -static int jdata_readpage(struct gfs2_inode *ip, struct page *page) -{ - void *kaddr; - int ret; - - kaddr = kmap(page); - - ret = gfs2_jdata_read_mem(ip, kaddr, - (uint64_t)page->index << PAGE_CACHE_SHIFT, - PAGE_CACHE_SIZE); - if (ret >= 0) { - if (ret < PAGE_CACHE_SIZE) - memset(kaddr + ret, 0, PAGE_CACHE_SIZE - ret); - SetPageUptodate(page); - ret = 0; - } - - kunmap(page); - - unlock_page(page); - - return ret; -} - /** * gfs2_readpage - readpage with locking - * @file: The file to read a page for + * @file: The file to read a page for. N.B. This may be NULL if we are + * reading an internal file. * @page: The page to read * * Returns: errno @@ -270,31 +261,35 @@ static int gfs2_readpage(struct file *file, struct page *page) { struct gfs2_inode *ip = get_v2ip(page->mapping->host); struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_holder gh; int error; atomic_inc(&sdp->sd_ops_address); - if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl))) { - unlock_page(page); - return -EOPNOTSUPP; - } + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); + error = gfs2_glock_nq_m_atime(1, &gh); + if (error) + goto out_unlock; - if (!gfs2_is_jdata(ip)) { - if (gfs2_is_stuffed(ip)) { - if (!page->index) { - error = stuffed_readpage(ip, page); - unlock_page(page); - } else - error = zero_readpage(page); + if (gfs2_is_stuffed(ip)) { + if (!page->index) { + error = stuffed_readpage(ip, page); + unlock_page(page); } else - error = mpage_readpage(page, gfs2_get_block); + error = zero_readpage(page); } else - error = jdata_readpage(ip, page); + error = mpage_readpage(page, gfs2_get_block); if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = -EIO; + gfs2_glock_dq_m(1, &gh); + gfs2_holder_uninit(&gh); +out: return error; +out_unlock: + unlock_page(page); + goto out; } /** @@ -312,28 +307,82 @@ static int gfs2_prepare_write(struct file *file, struct page *page, { struct gfs2_inode *ip = get_v2ip(page->mapping->host); struct gfs2_sbd *sdp = ip->i_sbd; + unsigned int data_blocks, ind_blocks, rblocks; + int alloc_required; int error = 0; + loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + from; + loff_t end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to; + struct gfs2_alloc *al; atomic_inc(&sdp->sd_ops_address); - if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl))) - return -EOPNOTSUPP; + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ATIME, &ip->i_gh); + error = gfs2_glock_nq_m_atime(1, &ip->i_gh); + if (error) + goto out_uninit; + + gfs2_write_calc_reserv(ip, to - from, &data_blocks, &ind_blocks); + + error = gfs2_write_alloc_required(ip, pos, from - to, &alloc_required); + if (error) + goto out_unlock; + + + if (alloc_required) { + al = gfs2_alloc_get(ip); + + error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); + if (error) + goto out_alloc_put; + + error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid); + if (error) + goto out_qunlock; + + al->al_requested = data_blocks + ind_blocks; + error = gfs2_inplace_reserve(ip); + if (error) + goto out_qunlock; + } + + rblocks = RES_DINODE + ind_blocks; + if (gfs2_is_jdata(ip)) + rblocks += data_blocks ? data_blocks : 1; + if (ind_blocks || data_blocks) + rblocks += RES_STATFS + RES_QUOTA; + + error = gfs2_trans_begin(sdp, rblocks, 0); + if (error) + goto out; if (gfs2_is_stuffed(ip)) { - uint64_t file_size; - file_size = ((uint64_t)page->index << PAGE_CACHE_SHIFT) + to; - - if (file_size > sdp->sd_sb.sb_bsize - - sizeof(struct gfs2_dinode)) { - error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, - page); - if (!error) - error = block_prepare_write(page, from, to, - gfs2_get_block); - } else if (!PageUptodate(page)) + if (end > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) { + error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, page); + if (error) + goto out; + } else if (!PageUptodate(page)) { error = stuffed_readpage(ip, page); - } else - error = block_prepare_write(page, from, to, gfs2_get_block); + goto out; + } + } + + error = block_prepare_write(page, from, to, gfs2_get_block); + +out: + if (error) { + gfs2_trans_end(sdp); + if (alloc_required) { + gfs2_inplace_release(ip); +out_qunlock: + gfs2_quota_unlock(ip); +out_alloc_put: + gfs2_alloc_put(ip); + } +out_unlock: + gfs2_glock_dq_m(1, &ip->i_gh); +out_uninit: + gfs2_holder_uninit(&ip->i_gh); + } return error; } @@ -354,48 +403,73 @@ static int gfs2_commit_write(struct file *file, struct page *page, struct inode *inode = page->mapping->host; struct gfs2_inode *ip = get_v2ip(inode); struct gfs2_sbd *sdp = ip->i_sbd; - int error; + int error = -EOPNOTSUPP; + struct buffer_head *dibh; + struct gfs2_alloc *al = &ip->i_alloc;; atomic_inc(&sdp->sd_ops_address); + + if (gfs2_assert_withdraw(sdp, gfs2_glock_is_locked_by_me(ip->i_gl))) + goto fail_nounlock; + + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + goto fail_endtrans; + + gfs2_trans_add_bh(ip->i_gl, dibh, 1); + if (gfs2_is_stuffed(ip)) { - struct buffer_head *dibh; uint64_t file_size; void *kaddr; file_size = ((uint64_t)page->index << PAGE_CACHE_SHIFT) + to; - error = gfs2_meta_inode_buffer(ip, &dibh); - if (error) - goto fail; - - gfs2_trans_add_bh(ip->i_gl, dibh, 1); - - kaddr = kmap(page); + kaddr = kmap_atomic(page, KM_USER0); memcpy(dibh->b_data + sizeof(struct gfs2_dinode) + from, - (char *)kaddr + from, - to - from); - kunmap(page); - - brelse(dibh); + (char *)kaddr + from, to - from); + kunmap_atomic(page, KM_USER0); SetPageUptodate(page); if (inode->i_size < file_size) i_size_write(inode, file_size); } else { - if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) + if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) gfs2_page_add_databufs(ip, page, from, to); error = generic_commit_write(file, page, from, to); if (error) goto fail; } + if (ip->i_di.di_size < inode->i_size) + ip->i_di.di_size = inode->i_size; + + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + gfs2_trans_end(sdp); + if (al->al_requested) { + gfs2_inplace_release(ip); + gfs2_quota_unlock(ip); + gfs2_alloc_put(ip); + } + gfs2_glock_dq_m(1, &ip->i_gh); + gfs2_holder_uninit(&ip->i_gh); return 0; - fail: +fail: + brelse(dibh); +fail_endtrans: + gfs2_trans_end(sdp); + if (al->al_requested) { + gfs2_inplace_release(ip); + gfs2_quota_unlock(ip); + gfs2_alloc_put(ip); + } + gfs2_glock_dq_m(1, &ip->i_gh); + gfs2_holder_uninit(&ip->i_gh); +fail_nounlock: ClearPageUptodate(page); - return error; } @@ -492,12 +566,16 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, const struct iovec *io atomic_inc(&sdp->sd_ops_address); - if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl)) || - gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) + if (gfs2_is_jdata(ip)) return -EINVAL; - if (rw == WRITE && !get_transaction) - gb = get_blocks_noalloc; + if (rw == WRITE) { + return -EOPNOTSUPP; /* for now */ + } else { + if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl)) || + gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) + return -EINVAL; + } return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, offset, nr_segs, gb, NULL); diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 0f356fc4690c..56820b39a993 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -27,7 +28,6 @@ #include "glock.h" #include "glops.h" #include "inode.h" -#include "jdata.h" #include "lm.h" #include "log.h" #include "meta_io.h" @@ -67,10 +67,37 @@ struct filldir_reg { void *fdr_opaque; }; -typedef ssize_t(*do_rw_t) (struct file *file, - char __user *buf, - size_t size, loff_t *offset, - unsigned int num_gh, struct gfs2_holder *ghs); +static int gfs2_read_actor(read_descriptor_t *desc, struct page *page, + unsigned long offset, unsigned long size) +{ + char *kaddr; + unsigned long count = desc->count; + + if (size > count) + size = count; + + kaddr = kmap(page); + memcpy(desc->arg.buf, kaddr + offset, size); + kunmap(page); + + desc->count = count - size; + desc->written += size; + desc->arg.buf += size; + return size; +} + +int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, + char *buf, loff_t *pos, unsigned size) +{ + struct inode *inode = ip->i_vnode; + read_descriptor_t desc; + desc.written = 0; + desc.arg.buf = buf; + desc.count = size; + desc.error = 0; + do_generic_mapping_read(inode->i_mapping, ra_state, NULL, pos, &desc, gfs2_read_actor); + return desc.written ? desc.written : desc.error; +} /** * gfs2_llseek - seek to a location in a file @@ -105,247 +132,114 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) return error; } -static inline unsigned int vma2state(struct vm_area_struct *vma) + +static ssize_t gfs2_direct_IO_read(struct kiocb *iocb, const struct iovec *iov, + loff_t offset, unsigned long nr_segs) { - if ((vma->vm_flags & (VM_MAYWRITE | VM_MAYSHARE)) == - (VM_MAYWRITE | VM_MAYSHARE)) - return LM_ST_EXCLUSIVE; - return LM_ST_SHARED; -} + struct file *file = iocb->ki_filp; + struct address_space *mapping = file->f_mapping; + ssize_t retval; -static ssize_t walk_vm_hard(struct file *file, const char __user *buf, size_t size, - loff_t *offset, do_rw_t operation) -{ - struct gfs2_holder *ghs; - unsigned int num_gh = 0; - ssize_t count; - struct super_block *sb = file->f_dentry->d_inode->i_sb; - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - unsigned long start = (unsigned long)buf; - unsigned long end = start + size; - int dumping = (current->flags & PF_DUMPCORE); - unsigned int x = 0; - - for (vma = find_vma(mm, start); vma; vma = vma->vm_next) { - if (end <= vma->vm_start) - break; - if (vma->vm_file && - vma->vm_file->f_dentry->d_inode->i_sb == sb) { - num_gh++; - } + retval = filemap_write_and_wait(mapping); + if (retval == 0) { + retval = mapping->a_ops->direct_IO(READ, iocb, iov, offset, + nr_segs); } - - ghs = kcalloc((num_gh + 1), sizeof(struct gfs2_holder), GFP_KERNEL); - if (!ghs) { - if (!dumping) - up_read(&mm->mmap_sem); - return -ENOMEM; - } - - for (vma = find_vma(mm, start); vma; vma = vma->vm_next) { - if (end <= vma->vm_start) - break; - if (vma->vm_file) { - struct inode *inode = vma->vm_file->f_dentry->d_inode; - if (inode->i_sb == sb) - gfs2_holder_init(get_v2ip(inode)->i_gl, - vma2state(vma), 0, &ghs[x++]); - } - } - - if (!dumping) - up_read(&mm->mmap_sem); - - gfs2_assert(get_v2sdp(sb), x == num_gh); - - count = operation(file, buf, size, offset, num_gh, ghs); - - while (num_gh--) - gfs2_holder_uninit(&ghs[num_gh]); - kfree(ghs); - - return count; + return retval; } /** - * walk_vm - Walk the vmas associated with a buffer for read or write. - * If any of them are gfs2, pass the gfs2 inode down to the read/write - * worker function so that locks can be acquired in the correct order. - * @file: The file to read/write from/to - * @buf: The buffer to copy to/from - * @size: The amount of data requested - * @offset: The current file offset - * @operation: The read or write worker function - * - * Outputs: Offset - updated according to number of bytes written - * - * Returns: The number of bytes written, errno on failure + * __gfs2_file_aio_read - The main GFS2 read function + * + * N.B. This is almost, but not quite the same as __generic_file_aio_read() + * the important subtle different being that inode->i_size isn't valid + * unless we are holding a lock, and we do this _only_ on the O_DIRECT + * path since otherwise locking is done entirely at the page cache + * layer. */ - -static ssize_t walk_vm(struct file *file, const char __user *buf, size_t size, - loff_t *offset, do_rw_t operation) +static ssize_t __gfs2_file_aio_read(struct kiocb *iocb, + const struct iovec *iov, + unsigned long nr_segs, loff_t *ppos) { + struct file *filp = iocb->ki_filp; + struct gfs2_inode *ip = get_v2ip(filp->f_mapping->host); struct gfs2_holder gh; + ssize_t retval; + unsigned long seg; + size_t count; - if (current->mm) { - struct super_block *sb = file->f_dentry->d_inode->i_sb; - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - unsigned long start = (unsigned long)buf; - unsigned long end = start + size; - int dumping = (current->flags & PF_DUMPCORE); + count = 0; + for (seg = 0; seg < nr_segs; seg++) { + const struct iovec *iv = &iov[seg]; - if (!dumping) - down_read(&mm->mmap_sem); - - for (vma = find_vma(mm, start); vma; vma = vma->vm_next) { - if (end <= vma->vm_start) - break; - if (vma->vm_file && - vma->vm_file->f_dentry->d_inode->i_sb == sb) - goto do_locks; - } - - if (!dumping) - up_read(&mm->mmap_sem); - } - - return operation(file, buf, size, offset, 0, &gh); - -do_locks: - return walk_vm_hard(file, buf, size, offset, operation); -} - -static ssize_t do_jdata_read(struct file *file, char __user *buf, size_t size, - loff_t *offset) -{ - struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); - ssize_t count = 0; - - if (*offset < 0) + /* + * If any segment has a negative length, or the cumulative + * length ever wraps negative then return -EINVAL. + */ + count += iv->iov_len; + if (unlikely((ssize_t)(count|iv->iov_len) < 0)) return -EINVAL; - if (!access_ok(VERIFY_WRITE, buf, size)) + if (access_ok(VERIFY_WRITE, iv->iov_base, iv->iov_len)) + continue; + if (seg == 0) return -EFAULT; - - if (!(file->f_flags & O_LARGEFILE)) { - if (*offset >= MAX_NON_LFS) - return -EFBIG; - if (*offset + size > MAX_NON_LFS) - size = MAX_NON_LFS - *offset; + nr_segs = seg; + count -= iv->iov_len; /* This segment is no good */ + break; } - count = gfs2_jdata_read(ip, buf, *offset, size, gfs2_copy2user); + /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ + if (filp->f_flags & O_DIRECT) { + loff_t pos = *ppos, size; + struct address_space *mapping; + struct inode *inode; - if (count > 0) - *offset += count; + mapping = filp->f_mapping; + inode = mapping->host; + retval = 0; + if (!count) + goto out; /* skip atime */ - return count; -} + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); + retval = gfs2_glock_nq_m_atime(1, &gh); + if (retval) + goto out; -/** - * do_read_direct - Read bytes from a file - * @file: The file to read from - * @buf: The buffer to copy into - * @size: The amount of data requested - * @offset: The current file offset - * @num_gh: The number of other locks we need to do the read - * @ghs: the locks we need plus one for our lock - * - * Outputs: Offset - updated according to number of bytes read - * - * Returns: The number of bytes read, errno on failure - */ - -static ssize_t do_read_direct(struct file *file, char __user *buf, size_t size, - loff_t *offset, unsigned int num_gh, - struct gfs2_holder *ghs) -{ - struct inode *inode = file->f_mapping->host; - struct gfs2_inode *ip = get_v2ip(inode); - unsigned int state = LM_ST_DEFERRED; - int flags = 0; - unsigned int x; - ssize_t count = 0; - int error; - - for (x = 0; x < num_gh; x++) - if (ghs[x].gh_gl == ip->i_gl) { - state = LM_ST_SHARED; - flags |= GL_LOCAL_EXCL; - break; + size = i_size_read(inode); + if (pos < size) { + retval = gfs2_direct_IO_read(iocb, iov, pos, nr_segs); + if (retval > 0 && !is_sync_kiocb(iocb)) + retval = -EIOCBQUEUED; + if (retval > 0) + *ppos = pos + retval; } - - gfs2_holder_init(ip->i_gl, state, flags, &ghs[num_gh]); - - error = gfs2_glock_nq_m(num_gh + 1, ghs); - if (error) + file_accessed(filp); + gfs2_glock_dq_m(1, &gh); + gfs2_holder_uninit(&gh); goto out; + } - error = -EINVAL; - if (gfs2_is_jdata(ip)) - goto out_gunlock; + retval = 0; + if (count) { + for (seg = 0; seg < nr_segs; seg++) { + read_descriptor_t desc; - if (gfs2_is_stuffed(ip)) { - size_t mask = bdev_hardsect_size(inode->i_sb->s_bdev) - 1; - - if (((*offset) & mask) || (((unsigned long)buf) & mask)) - goto out_gunlock; - - count = do_jdata_read(file, buf, size & ~mask, offset); - } else - count = generic_file_read(file, buf, size, offset); - - error = 0; - - out_gunlock: - gfs2_glock_dq_m(num_gh + 1, ghs); - - out: - gfs2_holder_uninit(&ghs[num_gh]); - - return (count) ? count : error; -} - -/** - * do_read_buf - Read bytes from a file - * @file: The file to read from - * @buf: The buffer to copy into - * @size: The amount of data requested - * @offset: The current file offset - * @num_gh: The number of other locks we need to do the read - * @ghs: the locks we need plus one for our lock - * - * Outputs: Offset - updated according to number of bytes read - * - * Returns: The number of bytes read, errno on failure - */ - -static ssize_t do_read_buf(struct file *file, char __user *buf, size_t size, - loff_t *offset, unsigned int num_gh, - struct gfs2_holder *ghs) -{ - struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); - ssize_t count = 0; - int error; - - gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &ghs[num_gh]); - - error = gfs2_glock_nq_m_atime(num_gh + 1, ghs); - if (error) - goto out; - - if (gfs2_is_jdata(ip)) - count = do_jdata_read(file, buf, size, offset); - else - count = generic_file_read(file, buf, size, offset); - - gfs2_glock_dq_m(num_gh + 1, ghs); - - out: - gfs2_holder_uninit(&ghs[num_gh]); - - return (count) ? count : error; + desc.written = 0; + desc.arg.buf = iov[seg].iov_base; + desc.count = iov[seg].iov_len; + if (desc.count == 0) + continue; + desc.error = 0; + do_generic_file_read(filp,ppos,&desc,file_read_actor); + retval += desc.written; + if (desc.error) { + retval = retval ?: desc.error; + break; + } + } + } +out: + return retval; } /** @@ -360,550 +254,49 @@ static ssize_t do_read_buf(struct file *file, char __user *buf, size_t size, * Returns: The number of bytes read, errno on failure */ -static ssize_t gfs2_read(struct file *file, char __user *buf, size_t size, +static ssize_t gfs2_read(struct file *filp, char __user *buf, size_t size, loff_t *offset) { - atomic_inc(&get_v2sdp(file->f_mapping->host->i_sb)->sd_ops_file); - - if (file->f_flags & O_DIRECT) - return walk_vm(file, buf, size, offset, do_read_direct); - else - return walk_vm(file, buf, size, offset, do_read_buf); -} - -/** - * grope_mapping - feel up a mapping that needs to be written - * @buf: the start of the memory to be written - * @size: the size of the memory to be written - * - * We do this after acquiring the locks on the mapping, - * but before starting the write transaction. We need to make - * sure that we don't cause recursive transactions if blocks - * need to be allocated to the file backing the mapping. - * - * Returns: errno - */ - -static int grope_mapping(const char __user *buf, size_t size) -{ - const char __user *stop = buf + size; - char c; - - while (buf < stop) { - if (copy_from_user(&c, buf, 1)) - return -EFAULT; - buf += PAGE_CACHE_SIZE; - buf = (const char __user *)PAGE_ALIGN((unsigned long)buf); - } - - return 0; -} - -/** - * do_write_direct_alloc - Write bytes to a file - * @file: The file to write to - * @buf: The buffer to copy from - * @size: The amount of data requested - * @offset: The current file offset - * - * Outputs: Offset - updated according to number of bytes written - * - * Returns: The number of bytes written, errno on failure - */ - -static ssize_t do_write_direct_alloc(struct file *file, const char __user *buf, size_t size, - loff_t *offset) -{ - struct inode *inode = file->f_mapping->host; - struct gfs2_inode *ip = get_v2ip(inode); - struct gfs2_sbd *sdp = ip->i_sbd; - struct gfs2_alloc *al = NULL; struct iovec local_iov = { .iov_base = buf, .iov_len = size }; - struct buffer_head *dibh; - unsigned int data_blocks, ind_blocks; - ssize_t count; - int error; + struct kiocb kiocb; + ssize_t ret; - gfs2_write_calc_reserv(ip, size, &data_blocks, &ind_blocks); + atomic_inc(&get_v2sdp(filp->f_mapping->host->i_sb)->sd_ops_file); - al = gfs2_alloc_get(ip); - - error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); - if (error) - goto fail; - - error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid); - if (error) - goto fail_gunlock_q; - - al->al_requested = data_blocks + ind_blocks; - - error = gfs2_inplace_reserve(ip); - if (error) - goto fail_gunlock_q; - - error = gfs2_trans_begin(sdp, - al->al_rgd->rd_ri.ri_length + ind_blocks + - RES_DINODE + RES_STATFS + RES_QUOTA, 0); - if (error) - goto fail_ipres; - - if ((ip->i_di.di_mode & (S_ISUID | S_ISGID)) && !capable(CAP_FSETID)) { - error = gfs2_meta_inode_buffer(ip, &dibh); - if (error) - goto fail_end_trans; - - ip->i_di.di_mode &= (ip->i_di.di_mode & S_IXGRP) ? - (~(S_ISUID | S_ISGID)) : (~S_ISUID); - - gfs2_trans_add_bh(ip->i_gl, dibh, 1); - gfs2_dinode_out(&ip->i_di, dibh->b_data); - brelse(dibh); - } - - if (gfs2_is_stuffed(ip)) { - error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_sync, NULL); - if (error) - goto fail_end_trans; - } - - count = generic_file_write_nolock(file, &local_iov, 1, offset); - if (count < 0) { - error = count; - goto fail_end_trans; - } - - error = gfs2_meta_inode_buffer(ip, &dibh); - if (error) - goto fail_end_trans; - - if (ip->i_di.di_size < inode->i_size) - ip->i_di.di_size = inode->i_size; - ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); - - gfs2_trans_add_bh(ip->i_gl, dibh, 1); - gfs2_dinode_out(&ip->i_di, dibh->b_data); - brelse(dibh); - - gfs2_trans_end(sdp); - - if (file->f_flags & O_SYNC) - gfs2_log_flush_glock(ip->i_gl); - - gfs2_inplace_release(ip); - gfs2_quota_unlock(ip); - gfs2_alloc_put(ip); - - if (file->f_mapping->nrpages) { - error = filemap_fdatawrite(file->f_mapping); - if (!error) - error = filemap_fdatawait(file->f_mapping); - } - if (error) - return error; - - return count; - - fail_end_trans: - gfs2_trans_end(sdp); - - fail_ipres: - gfs2_inplace_release(ip); - - fail_gunlock_q: - gfs2_quota_unlock(ip); - - fail: - gfs2_alloc_put(ip); - - return error; + init_sync_kiocb(&kiocb, filp); + ret = __gfs2_file_aio_read(&kiocb, &local_iov, 1, offset); + if (-EIOCBQUEUED == ret) + ret = wait_on_sync_kiocb(&kiocb); + return ret; } -/** - * do_write_direct - Write bytes to a file - * @file: The file to write to - * @buf: The buffer to copy from - * @size: The amount of data requested - * @offset: The current file offset - * @num_gh: The number of other locks we need to do the read - * @gh: the locks we need plus one for our lock - * - * Outputs: Offset - updated according to number of bytes written - * - * Returns: The number of bytes written, errno on failure - */ - -static ssize_t do_write_direct(struct file *file, const char __user *buf, size_t size, - loff_t *offset, unsigned int num_gh, - struct gfs2_holder *ghs) +static ssize_t gfs2_file_readv(struct file *filp, const struct iovec *iov, + unsigned long nr_segs, loff_t *ppos) { - struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); - struct gfs2_sbd *sdp = ip->i_sbd; - struct gfs2_file *fp = get_v2fp(file); - unsigned int state = LM_ST_DEFERRED; - int alloc_required; - unsigned int x; - size_t s; - ssize_t count = 0; - int error; + struct kiocb kiocb; + ssize_t ret; - if (test_bit(GFF_DID_DIRECT_ALLOC, &fp->f_flags)) - state = LM_ST_EXCLUSIVE; - else - for (x = 0; x < num_gh; x++) - if (ghs[x].gh_gl == ip->i_gl) { - state = LM_ST_EXCLUSIVE; - break; - } + atomic_inc(&get_v2sdp(filp->f_mapping->host->i_sb)->sd_ops_file); - restart: - gfs2_holder_init(ip->i_gl, state, 0, &ghs[num_gh]); - - error = gfs2_glock_nq_m(num_gh + 1, ghs); - if (error) - goto out; - - error = -EINVAL; - if (gfs2_is_jdata(ip)) - goto out_gunlock; - - if (num_gh) { - error = grope_mapping(buf, size); - if (error) - goto out_gunlock; - } - - if (file->f_flags & O_APPEND) - *offset = ip->i_di.di_size; - - if (!(file->f_flags & O_LARGEFILE)) { - error = -EFBIG; - if (*offset >= MAX_NON_LFS) - goto out_gunlock; - if (*offset + size > MAX_NON_LFS) - size = MAX_NON_LFS - *offset; - } - - if (gfs2_is_stuffed(ip) || - *offset + size > ip->i_di.di_size || - ((ip->i_di.di_mode & (S_ISUID | S_ISGID)) && !capable(CAP_FSETID))) - alloc_required = 1; - else { - error = gfs2_write_alloc_required(ip, *offset, size, - &alloc_required); - if (error) - goto out_gunlock; - } - - if (alloc_required && state != LM_ST_EXCLUSIVE) { - gfs2_glock_dq_m(num_gh + 1, ghs); - gfs2_holder_uninit(&ghs[num_gh]); - state = LM_ST_EXCLUSIVE; - goto restart; - } - - if (alloc_required) { - set_bit(GFF_DID_DIRECT_ALLOC, &fp->f_flags); - - /* split large writes into smaller atomic transactions */ - while (size) { - s = gfs2_tune_get(sdp, gt_max_atomic_write); - if (s > size) - s = size; - - error = do_write_direct_alloc(file, buf, s, offset); - if (error < 0) - goto out_gunlock; - - buf += error; - size -= error; - count += error; - } - } else { - struct iovec local_iov = { .iov_base = buf, .iov_len = size }; - struct gfs2_holder t_gh; - - clear_bit(GFF_DID_DIRECT_ALLOC, &fp->f_flags); - - error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, - GL_NEVER_RECURSE, &t_gh); - if (error) - goto out_gunlock; - - count = generic_file_write_nolock(file, &local_iov, 1, offset); - - gfs2_glock_dq_uninit(&t_gh); - } - - error = 0; - - out_gunlock: - gfs2_glock_dq_m(num_gh + 1, ghs); - - out: - gfs2_holder_uninit(&ghs[num_gh]); - - return (count) ? count : error; + init_sync_kiocb(&kiocb, filp); + ret = __gfs2_file_aio_read(&kiocb, iov, nr_segs, ppos); + if (-EIOCBQUEUED == ret) + ret = wait_on_sync_kiocb(&kiocb); + return ret; } -/** - * do_do_write_buf - Write bytes to a file - * @file: The file to write to - * @buf: The buffer to copy from - * @size: The amount of data requested - * @offset: The current file offset - * - * Outputs: Offset - updated according to number of bytes written - * - * Returns: The number of bytes written, errno on failure - */ - -static ssize_t do_do_write_buf(struct file *file, const char __user *buf, size_t size, - loff_t *offset) +static ssize_t gfs2_file_aio_read(struct kiocb *iocb, char __user *buf, + size_t count, loff_t pos) { - struct inode *inode = file->f_mapping->host; - struct gfs2_inode *ip = get_v2ip(inode); - struct gfs2_sbd *sdp = ip->i_sbd; - struct gfs2_alloc *al = NULL; - struct buffer_head *dibh; - unsigned int data_blocks, ind_blocks; - int alloc_required, journaled; - ssize_t count; - int error; + struct file *filp = iocb->ki_filp; + struct iovec local_iov = { .iov_base = buf, .iov_len = count }; - journaled = gfs2_is_jdata(ip); + atomic_inc(&get_v2sdp(filp->f_mapping->host->i_sb)->sd_ops_file); - gfs2_write_calc_reserv(ip, size, &data_blocks, &ind_blocks); - - error = gfs2_write_alloc_required(ip, *offset, size, &alloc_required); - if (error) - return error; - - if (alloc_required) { - al = gfs2_alloc_get(ip); - - error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); - if (error) - goto fail; - - error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid); - if (error) - goto fail_gunlock_q; - - al->al_requested = data_blocks + ind_blocks; - - error = gfs2_inplace_reserve(ip); - if (error) - goto fail_gunlock_q; - - error = gfs2_trans_begin(sdp, - al->al_rgd->rd_ri.ri_length + - ind_blocks + - ((journaled) ? data_blocks : 0) + - RES_DINODE + RES_STATFS + RES_QUOTA, - 0); - if (error) - goto fail_ipres; - } else { - error = gfs2_trans_begin(sdp, - ((journaled) ? data_blocks : 0) + - RES_DINODE, - 0); - if (error) - goto fail_ipres; - } - - if ((ip->i_di.di_mode & (S_ISUID | S_ISGID)) && !capable(CAP_FSETID)) { - error = gfs2_meta_inode_buffer(ip, &dibh); - if (error) - goto fail_end_trans; - - ip->i_di.di_mode &= (ip->i_di.di_mode & S_IXGRP) ? - (~(S_ISUID | S_ISGID)) : (~S_ISUID); - - gfs2_trans_add_bh(ip->i_gl, dibh, 1); - gfs2_dinode_out(&ip->i_di, dibh->b_data); - brelse(dibh); - } - - if (journaled) { - count = gfs2_jdata_write(ip, buf, *offset, size, - gfs2_copy_from_user); - if (count < 0) { - error = count; - goto fail_end_trans; - } - - *offset += count; - } else { - struct iovec local_iov = { .iov_base = buf, .iov_len = size }; - - count = generic_file_write_nolock(file, &local_iov, 1, offset); - if (count < 0) { - error = count; - goto fail_end_trans; - } - - error = gfs2_meta_inode_buffer(ip, &dibh); - if (error) - goto fail_end_trans; - - if (ip->i_di.di_size < inode->i_size) - ip->i_di.di_size = inode->i_size; - ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); - - gfs2_trans_add_bh(ip->i_gl, dibh, 1); - gfs2_dinode_out(&ip->i_di, dibh->b_data); - brelse(dibh); - } - - gfs2_trans_end(sdp); - - if (file->f_flags & O_SYNC || IS_SYNC(inode)) { - gfs2_log_flush_glock(ip->i_gl); - error = filemap_fdatawrite(file->f_mapping); - if (error == 0) - error = filemap_fdatawait(file->f_mapping); - if (error) - goto fail_ipres; - } - - if (alloc_required) { - gfs2_assert_warn(sdp, count != size || - al->al_alloced); - gfs2_inplace_release(ip); - gfs2_quota_unlock(ip); - gfs2_alloc_put(ip); - } - - return count; - - fail_end_trans: - gfs2_trans_end(sdp); - - fail_ipres: - if (alloc_required) - gfs2_inplace_release(ip); - - fail_gunlock_q: - if (alloc_required) - gfs2_quota_unlock(ip); - - fail: - if (alloc_required) - gfs2_alloc_put(ip); - - return error; + BUG_ON(iocb->ki_pos != pos); + return __gfs2_file_aio_read(iocb, &local_iov, 1, &iocb->ki_pos); } -/** - * do_write_buf - Write bytes to a file - * @file: The file to write to - * @buf: The buffer to copy from - * @size: The amount of data requested - * @offset: The current file offset - * @num_gh: The number of other locks we need to do the read - * @gh: the locks we need plus one for our lock - * - * Outputs: Offset - updated according to number of bytes written - * - * Returns: The number of bytes written, errno on failure - */ - -static ssize_t do_write_buf(struct file *file, const char __user *buf, size_t size, - loff_t *offset, unsigned int num_gh, - struct gfs2_holder *ghs) -{ - struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); - struct gfs2_sbd *sdp = ip->i_sbd; - size_t s; - ssize_t count = 0; - int error; - - gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &ghs[num_gh]); - - error = gfs2_glock_nq_m(num_gh + 1, ghs); - if (error) - goto out; - - if (num_gh) { - error = grope_mapping(buf, size); - if (error) - goto out_gunlock; - } - - if (file->f_flags & O_APPEND) - *offset = ip->i_di.di_size; - - if (!(file->f_flags & O_LARGEFILE)) { - error = -EFBIG; - if (*offset >= MAX_NON_LFS) - goto out_gunlock; - if (*offset + size > MAX_NON_LFS) - size = MAX_NON_LFS - *offset; - } - - /* split large writes into smaller atomic transactions */ - while (size) { - s = gfs2_tune_get(sdp, gt_max_atomic_write); - if (s > size) - s = size; - - error = do_do_write_buf(file, buf, s, offset); - if (error < 0) - goto out_gunlock; - - buf += error; - size -= error; - count += error; - } - - error = 0; - - out_gunlock: - gfs2_glock_dq_m(num_gh + 1, ghs); - - out: - gfs2_holder_uninit(&ghs[num_gh]); - - return (count) ? count : error; -} - -/** - * gfs2_write - Write bytes to a file - * @file: The file to write to - * @buf: The buffer to copy from - * @size: The amount of data requested - * @offset: The current file offset - * - * Outputs: Offset - updated according to number of bytes written - * - * Returns: The number of bytes written, errno on failure - */ - -static ssize_t gfs2_write(struct file *file, const char __user *buf, - size_t size, loff_t *offset) -{ - struct inode *inode = file->f_mapping->host; - ssize_t count; - - atomic_inc(&get_v2sdp(inode->i_sb)->sd_ops_file); - - if (*offset < 0) - return -EINVAL; - if (!access_ok(VERIFY_READ, buf, size)) - return -EFAULT; - - mutex_lock(&inode->i_mutex); - if (file->f_flags & O_DIRECT) - count = walk_vm(file, buf, size, offset, - do_write_direct); - else - count = walk_vm(file, buf, size, offset, do_write_buf); - mutex_unlock(&inode->i_mutex); - - return count; -} /** * filldir_reg_func - Report a directory entry to the caller of gfs2_dir_read() @@ -1158,9 +551,6 @@ static int gfs2_ioctl_flags(struct gfs2_inode *ip, unsigned int cmd, unsigned lo if (flags & (GFS2_DIF_JDATA|GFS2_DIF_DIRECTIO)) { if (!S_ISREG(ip->i_di.di_mode)) goto out; - /* FIXME: Would be nice not to require the following test */ - if ((flags & GFS2_DIF_JDATA) && ip->i_di.di_size) - goto out; } if (flags & (GFS2_DIF_INHERIT_JDATA|GFS2_DIF_INHERIT_DIRECTIO)) { if (!S_ISDIR(ip->i_di.di_mode)) @@ -1246,21 +636,14 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) return error; } - if (gfs2_is_jdata(ip)) { - if (vma->vm_flags & VM_MAYSHARE) - error = -EOPNOTSUPP; - else - vma->vm_ops = &gfs2_vm_ops_private; - } else { - /* This is VM_MAYWRITE instead of VM_WRITE because a call - to mprotect() can turn on VM_WRITE later. */ + /* This is VM_MAYWRITE instead of VM_WRITE because a call + to mprotect() can turn on VM_WRITE later. */ - if ((vma->vm_flags & (VM_MAYSHARE | VM_MAYWRITE)) == - (VM_MAYSHARE | VM_MAYWRITE)) - vma->vm_ops = &gfs2_vm_ops_sharewrite; - else - vma->vm_ops = &gfs2_vm_ops_private; - } + if ((vma->vm_flags & (VM_MAYSHARE | VM_MAYWRITE)) == + (VM_MAYSHARE | VM_MAYWRITE)) + vma->vm_ops = &gfs2_vm_ops_sharewrite; + else + vma->vm_ops = &gfs2_vm_ops_private; gfs2_glock_dq_uninit(&i_gh); @@ -1313,13 +696,6 @@ static int gfs2_open(struct inode *inode, struct file *file) if (ip->i_di.di_flags & GFS2_DIF_DIRECTIO) file->f_flags |= O_DIRECT; - /* Don't let the user open O_DIRECT on a jdata file */ - - if ((file->f_flags & O_DIRECT) && gfs2_is_jdata(ip)) { - error = -EINVAL; - goto fail_gunlock; - } - gfs2_glock_dq_uninit(&i_gh); } @@ -1446,29 +822,10 @@ static ssize_t gfs2_sendfile(struct file *in_file, loff_t *offset, size_t count, read_actor_t actor, void *target) { struct gfs2_inode *ip = get_v2ip(in_file->f_mapping->host); - struct gfs2_holder gh; - ssize_t retval; atomic_inc(&ip->i_sbd->sd_ops_file); - gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); - - retval = gfs2_glock_nq_atime(&gh); - if (retval) - goto out; - - if (gfs2_is_jdata(ip)) - retval = -EOPNOTSUPP; - else - retval = generic_file_sendfile(in_file, offset, count, actor, - target); - - gfs2_glock_dq(&gh); - - out: - gfs2_holder_uninit(&gh); - - return retval; + return generic_file_sendfile(in_file, offset, count, actor, target); } static int do_flock(struct file *file, int cmd, struct file_lock *fl) @@ -1567,7 +924,11 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) struct file_operations gfs2_file_fops = { .llseek = gfs2_llseek, .read = gfs2_read, - .write = gfs2_write, + .readv = gfs2_file_readv, + .aio_read = gfs2_file_aio_read, + .write = generic_file_write, + .writev = generic_file_writev, + .aio_write = generic_file_aio_write, .ioctl = gfs2_ioctl, .mmap = gfs2_mmap, .open = gfs2_open, diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index a1b409ce75e1..8f77bb7896bd 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -155,9 +155,6 @@ static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, if (error) return NULL; - if (gfs2_is_jdata(ip)) - goto out; - set_bit(GIF_PAGED, &ip->i_flags); set_bit(GIF_SW_PAGED, &ip->i_flags); diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c index ea31bceac4f2..3542aa6b01c4 100644 --- a/fs/gfs2/page.c +++ b/fs/gfs2/page.c @@ -172,8 +172,8 @@ int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, map_bh(bh, inode->i_sb, block); set_buffer_uptodate(bh); - if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) - gfs2_trans_add_databuf(sdp, bh); + if ((sdp->sd_args.ar_data == GFS2_DATA_ORDERED) || gfs2_is_jdata(ip)) + gfs2_trans_add_bh(ip->i_gl, bh, 0); mark_buffer_dirty(bh); if (release) { @@ -245,8 +245,8 @@ int gfs2_block_truncate_page(struct address_space *mapping) goto unlock; } - if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED/* || gfs2_is_jdata(ip)*/) - gfs2_trans_add_databuf(sdp, bh); + if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) + gfs2_trans_add_bh(ip->i_gl, bh, 0); kaddr = kmap_atomic(page, KM_USER0); memset(kaddr + offset, 0, length); @@ -273,7 +273,7 @@ void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, end = start + bsize; if (end <= from || start >= to) continue; - gfs2_trans_add_databuf(ip->i_sbd, bh); + gfs2_trans_add_bh(ip->i_gl, bh, 0); } } diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 69e8f4e92e57..138fdf559a9a 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -43,20 +43,22 @@ #include #include #include +#include #include #include "gfs2.h" #include "bmap.h" #include "glock.h" #include "glops.h" -#include "jdata.h" #include "log.h" #include "meta_io.h" #include "quota.h" #include "rgrp.h" #include "super.h" #include "trans.h" +#include "inode.h" #include "ops_file.h" +#include "ops_address.h" #define QUOTA_USER 1 #define QUOTA_GROUP 0 @@ -561,6 +563,81 @@ static void do_qc(struct gfs2_quota_data *qd, int64_t change) up(&sdp->sd_quota_mutex); } +/** + * gfs2_adjust_quota + * + * This function was mostly borrowed from gfs2_block_truncate_page which was + * in turn mostly borrowed from ext3 + */ +static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, + int64_t change, struct gfs2_quota_data *qd) +{ + struct inode *inode = gfs2_ip2v(ip); + struct address_space *mapping = inode->i_mapping; + unsigned long index = loc >> PAGE_CACHE_SHIFT; + unsigned offset = loc & (PAGE_CACHE_SHIFT - 1); + unsigned blocksize, iblock, pos; + struct buffer_head *bh; + struct page *page; + void *kaddr; + __be64 *ptr; + u64 value; + int err = -EIO; + + page = grab_cache_page(mapping, index); + if (!page) + return -ENOMEM; + + blocksize = inode->i_sb->s_blocksize; + iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits); + + if (!page_has_buffers(page)) + create_empty_buffers(page, blocksize, 0); + + bh = page_buffers(page); + pos = blocksize; + while (offset >= pos) { + bh = bh->b_this_page; + iblock++; + pos += blocksize; + } + + if (!buffer_mapped(bh)) { + gfs2_get_block(inode, iblock, bh, 1); + if (!buffer_mapped(bh)) + goto unlock; + } + + if (PageUptodate(page)) + set_buffer_uptodate(bh); + + if (!buffer_uptodate(bh)) { + ll_rw_block(READ, 1, &bh); + wait_on_buffer(bh); + if (!buffer_uptodate(bh)) + goto unlock; + } + + gfs2_trans_add_bh(ip->i_gl, bh, 0); + + kaddr = kmap_atomic(page, KM_USER0); + ptr = (__be64 *)(kaddr + offset); + value = *ptr = cpu_to_be64(be64_to_cpu(*ptr) + change); + flush_dcache_page(page); + kunmap_atomic(kaddr, KM_USER0); + err = 0; + qd->qd_qb.qb_magic = cpu_to_be32(GFS2_MAGIC); +#if 0 + qd->qd_qb.qb_limit = cpu_to_be64(q.qu_limit); + qd->qd_qb.qb_warn = cpu_to_be64(q.qu_warn); +#endif + qd->qd_qb.qb_value = cpu_to_be64(value); +unlock: + unlock_page(page); + page_cache_release(page); + return err; +} + static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) { struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd; @@ -635,43 +712,14 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) file_ra_state_init(&ra_state, ip->i_vnode->i_mapping); for (x = 0; x < num_qd; x++) { - char buf[sizeof(struct gfs2_quota)]; - struct gfs2_quota q; - qd = qda[x]; offset = qd2offset(qd); - - /* The quota file may not be a multiple of - sizeof(struct gfs2_quota) bytes. */ - memset(buf, 0, sizeof(struct gfs2_quota)); - - error = gfs2_internal_read(ip, &ra_state, buf, &offset, - sizeof(struct gfs2_quota)); - if (error < 0) + error = gfs2_adjust_quota(ip, offset, qd->qd_change_sync, + (struct gfs2_quota_data *)qd->qd_gl->gl_lvb); + if (error) goto out_end_trans; - gfs2_quota_in(&q, buf); - q.qu_value += qda[x]->qd_change_sync; - gfs2_quota_out(&q, buf); - - error = gfs2_jdata_write_mem(ip, buf, offset, - sizeof(struct gfs2_quota)); - if (error < 0) - goto out_end_trans; - else if (error != sizeof(struct gfs2_quota)) { - error = -EIO; - goto out_end_trans; - } - do_qc(qd, -qd->qd_change_sync); - - memset(&qd->qd_qb, 0, sizeof(struct gfs2_quota_lvb)); - qd->qd_qb.qb_magic = GFS2_MAGIC; - qd->qd_qb.qb_limit = q.qu_limit; - qd->qd_qb.qb_warn = q.qu_warn; - qd->qd_qb.qb_value = q.qu_value; - - gfs2_quota_lvb_out(&qd->qd_qb, qd->qd_gl->gl_lvb); } error = 0; diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index b014591fa4a4..104e664fa182 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -154,14 +154,13 @@ void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta) gfs2_attach_bufdata(gl, bh, meta); bd = get_v2bd(bh); } - lops_add(sdp, &bd->bd_le); } void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, uint64_t blkno) { struct gfs2_revoke *rv = kmalloc(sizeof(struct gfs2_revoke), - GFP_KERNEL | __GFP_NOFAIL); + GFP_NOFS | __GFP_NOFAIL); lops_init_le(&rv->rv_le, &gfs2_revoke_lops); rv->rv_blkno = blkno; lops_add(sdp, &rv->rv_le); @@ -197,19 +196,3 @@ void gfs2_trans_add_rg(struct gfs2_rgrpd *rgd) lops_add(rgd->rd_sbd, &rgd->rd_le); } -void gfs2_trans_add_databuf(struct gfs2_sbd *sdp, struct buffer_head *bh) -{ - struct gfs2_bufdata *bd; - - bd = get_v2bd(bh); - if (!bd) { - bd = kmalloc(sizeof(struct gfs2_bufdata), - GFP_NOFS | __GFP_NOFAIL); - lops_init_le(&bd->bd_le, &gfs2_databuf_lops); - get_bh(bh); - bd->bd_bh = bh; - set_v2bd(bh, bd); - lops_add(sdp, &bd->bd_le); - } -} - diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h index 5a7da1e853c9..f7f3e2a3d590 100644 --- a/fs/gfs2/trans.h +++ b/fs/gfs2/trans.h @@ -35,6 +35,5 @@ void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta); void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, uint64_t blkno); void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, uint64_t blkno); void gfs2_trans_add_rg(struct gfs2_rgrpd *rgd); -void gfs2_trans_add_databuf(struct gfs2_sbd *sdp, struct buffer_head *bh); #endif /* __TRANS_DOT_H__ */ diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index ad49153c33d1..4fb1704aac10 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -50,6 +50,7 @@ int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion, "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", sdp->sd_fsname, assertion, sdp->sd_fsname, function, file, line); + dump_stack(); return (me) ? -1 : -2; } @@ -75,6 +76,8 @@ int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, if (sdp->sd_args.ar_debug) BUG(); + else + dump_stack(); sdp->sd_last_warning = jiffies; diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index f1302e2616da..99d7ae4f6b7e 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -336,6 +336,10 @@ struct gfs2_log_header { /* ld_data1 is the number of revoke blocks in the descriptor. ld_data2 is unused. */ +#define GFS2_LOG_DESC_JDATA 302 +/* ld_data1 is the number of data blocks in the descriptor. + ld_data2 is unused. */ + struct gfs2_log_descriptor { struct gfs2_meta_header ld_header; @@ -400,6 +404,7 @@ struct gfs2_quota_change { __be32 qc_id; }; +#ifdef __KERNEL__ /* Translation functions */ extern void gfs2_inum_in(struct gfs2_inum *no, char *buf); @@ -444,4 +449,6 @@ extern void gfs2_statfs_change_print(struct gfs2_statfs_change *sc); extern void gfs2_unlinked_tag_print(struct gfs2_unlinked_tag *ut); extern void gfs2_quota_change_print(struct gfs2_quota_change *qc); +#endif /* __KERNEL__ */ + #endif /* __GFS2_ONDISK_DOT_H__ */ From 7359a19cc758946aba0e45233b8641256b194884 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 13 Feb 2006 12:27:43 +0000 Subject: [PATCH 036/292] [GFS2] Fix for root inode ref count bug Umount is now working correctly again. The bug was due to not getting an extra ref count when mounting the fs. We should have bumped it by two (once for the internal pointer to the root inode from the super block and once for the inode hanging off the dcache entry for root). Also this patch tidys up the code dealing with looking up and creating inodes. We now pass Linux inodes (with gfs2_inodes attached) rather than the other way around and this reduces code duplication in various places. Signed-off-by: Steven Whitehouse --- fs/gfs2/glops.c | 4 +-- fs/gfs2/incore.h | 2 +- fs/gfs2/inode.c | 70 +++++++++++++++++++++++++++----------------- fs/gfs2/inode.h | 15 +++------- fs/gfs2/log.c | 2 +- fs/gfs2/lops.c | 30 +++++++++---------- fs/gfs2/ops_export.c | 9 +----- fs/gfs2/ops_fstype.c | 3 +- fs/gfs2/ops_inode.c | 67 ++++++++++++------------------------------ fs/gfs2/quota.c | 2 +- fs/gfs2/recovery.c | 20 ++++++------- fs/gfs2/super.c | 12 ++++---- 12 files changed, 103 insertions(+), 133 deletions(-) diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 127008146a57..27374306ecde 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -358,13 +358,13 @@ static void trans_go_xmote_th(struct gfs2_glock *gl, unsigned int state, static void trans_go_xmote_bh(struct gfs2_glock *gl) { struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_glock *j_gl = sdp->sd_jdesc->jd_inode->i_gl; + struct gfs2_glock *j_gl = get_v2ip(sdp->sd_jdesc->jd_inode)->i_gl; struct gfs2_log_header head; int error; if (gl->gl_state != LM_ST_UNLOCKED && test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { - gfs2_meta_cache_flush(sdp->sd_jdesc->jd_inode); + gfs2_meta_cache_flush(get_v2ip(sdp->sd_jdesc->jd_inode)); j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA); error = gfs2_find_jhead(sdp->sd_jdesc, &head); diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index d1954e2bb908..e43a0475d0d8 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -378,7 +378,7 @@ struct gfs2_ail { struct gfs2_jdesc { struct list_head jd_list; - struct gfs2_inode *jd_inode; + struct inode *jd_inode; unsigned int jd_jid; int jd_dirty; diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 4c193e38f8e4..2a00b96eac01 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -711,24 +711,28 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) * Returns: errno */ -int gfs2_lookupi(struct gfs2_inode *dip, struct qstr *name, int is_root, - struct gfs2_inode **ipp) +int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, + struct inode **inodep) { + struct gfs2_inode *ipp; + struct gfs2_inode *dip = get_v2ip(dir); struct gfs2_sbd *sdp = dip->i_sbd; struct gfs2_holder d_gh; struct gfs2_inum inum; unsigned int type; struct gfs2_glock *gl; - int error; + int error = 0; + + *inodep = NULL; if (!name->len || name->len > GFS2_FNAMESIZE) return -ENAMETOOLONG; if (gfs2_filecmp(name, ".", 1) || - (gfs2_filecmp(name, "..", 2) && dip == get_v2ip(sdp->sd_root_dir))) { + (gfs2_filecmp(name, "..", 2) && dir == sdp->sd_root_dir)) { gfs2_inode_hold(dip); - *ipp = dip; - return 0; + ipp = dip; + goto done; } error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); @@ -750,15 +754,21 @@ int gfs2_lookupi(struct gfs2_inode *dip, struct qstr *name, int is_root, if (error) goto out; - error = gfs2_inode_get(gl, &inum, CREATE, ipp); + error = gfs2_inode_get(gl, &inum, CREATE, &ipp); if (!error) - gfs2_inode_min_init(*ipp, type); + gfs2_inode_min_init(ipp, type); gfs2_glock_put(gl); - out: +out: gfs2_glock_dq_uninit(&d_gh); - +done: + if (error == 0) { + *inodep = gfs2_ip2v(ipp); + if (!*inodep) + error = -ENOMEM; + gfs2_inode_put(ipp); + } return error; } @@ -1171,15 +1181,16 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name, * @ghs[0] is an initialized holder for the directory * @ghs[1] is the holder for the inode lock * - * If the return value is 0, the glocks on both the directory and the new + * If the return value is not NULL, the glocks on both the directory and the new * file are held. A transaction has been started and an inplace reservation * is held, as well. * - * Returns: errno + * Returns: An inode */ -int gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode) +struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode) { + struct inode *inode; struct gfs2_inode *dip = get_gl2ip(ghs->gh_gl); struct gfs2_sbd *sdp = dip->i_sbd; struct gfs2_unlinked *ul; @@ -1187,11 +1198,11 @@ int gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode) int error; if (!name->len || name->len > GFS2_FNAMESIZE) - return -ENAMETOOLONG; + return ERR_PTR(-ENAMETOOLONG); error = gfs2_unlinked_get(sdp, &ul); if (error) - return error; + return ERR_PTR(error); gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs); error = gfs2_glock_nq(ghs); @@ -1220,7 +1231,7 @@ int gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode) ghs + 1); if (error) { gfs2_unlinked_put(sdp, ul); - return error; + return ERR_PTR(error); } gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs); @@ -1228,7 +1239,7 @@ int gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode) if (error) { gfs2_glock_dq_uninit(ghs + 1); gfs2_unlinked_put(sdp, ul); - return error; + return ERR_PTR(error); } error = create_ok(dip, name, mode); @@ -1266,7 +1277,11 @@ int gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode) gfs2_unlinked_put(sdp, ul); - return 0; + inode = gfs2_ip2v(ip); + gfs2_inode_put(ip); + if (!inode) + return ERR_PTR(-ENOMEM); + return inode; fail_iput: gfs2_inode_put(ip); @@ -1280,7 +1295,7 @@ int gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode) fail: gfs2_unlinked_put(sdp, ul); - return error; + return ERR_PTR(error); } /** @@ -1445,7 +1460,8 @@ int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name, int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) { struct gfs2_sbd *sdp = this->i_sbd; - struct gfs2_inode *tmp; + struct inode *dir = to->i_vnode; + struct inode *tmp; struct qstr dotdot; int error = 0; @@ -1453,27 +1469,27 @@ int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) dotdot.name = ".."; dotdot.len = 2; - gfs2_inode_hold(to); + igrab(dir); for (;;) { - if (to == this) { + if (dir == this->i_vnode) { error = -EINVAL; break; } - if (to == get_v2ip(sdp->sd_root_dir)) { + if (dir == sdp->sd_root_dir) { error = 0; break; } - error = gfs2_lookupi(to, &dotdot, 1, &tmp); + error = gfs2_lookupi(dir, &dotdot, 1, &tmp); if (error) break; - gfs2_inode_put(to); - to = tmp; + iput(dir); + dir = tmp; } - gfs2_inode_put(to); + iput(dir); return error; } diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index 214975c6bb22..8ef85f5feb1b 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -44,9 +44,9 @@ void gfs2_inode_destroy(struct gfs2_inode *ip); int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); int gfs2_change_nlink(struct gfs2_inode *ip, int diff); -int gfs2_lookupi(struct gfs2_inode *dip, struct qstr *name, int is_root, - struct gfs2_inode **ipp); -int gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode); +int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, + struct inode **ipp); +struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode); int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name, struct gfs2_inode *ip, struct gfs2_unlinked *ul); int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, @@ -68,19 +68,12 @@ int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd); static inline int gfs2_lookup_simple(struct inode *dip, char *name, struct inode **ipp) { - struct gfs2_inode *ip; struct qstr qstr; int err; memset(&qstr, 0, sizeof(struct qstr)); qstr.name = name; qstr.len = strlen(name); - err = gfs2_lookupi(get_v2ip(dip), &qstr, 1, &ip); - if (err == 0) { - *ipp = gfs2_ip2v(ip); - gfs2_inode_put(ip); - if (*ipp == NULL) - err = -ENOMEM; - } + err = gfs2_lookupi(dip, &qstr, 1, ipp); return err; } diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 9b4484d366ca..49190a29dd4f 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -274,7 +274,7 @@ static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) uint64_t dbn; int error; - error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, &new, &dbn, NULL); + error = gfs2_block_map(get_v2ip(sdp->sd_jdesc->jd_inode), lbn, &new, &dbn, NULL); gfs2_assert_withdraw(sdp, !error && dbn); return dbn; diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index dd41863810d7..23be00141901 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -177,7 +177,7 @@ static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) static void buf_lo_before_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head, int pass) { - struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; if (pass != 0) return; @@ -190,8 +190,8 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_log_descriptor *ld, __be64 *ptr, int pass) { - struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; - struct gfs2_glock *gl = jd->jd_inode->i_gl; + struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; + struct gfs2_glock *gl = get_v2ip(jd->jd_inode)->i_gl; unsigned int blks = be32_to_cpu(ld->ld_data1); struct buffer_head *bh_log, *bh_ip; uint64_t blkno; @@ -236,16 +236,16 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) { - struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; if (error) { - gfs2_meta_sync(jd->jd_inode->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT); return; } if (pass != 1) return; - gfs2_meta_sync(jd->jd_inode->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT); fs_info(sdp, "jid=%u: Replayed %u of %u blocks\n", jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); @@ -320,7 +320,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp) static void revoke_lo_before_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head, int pass) { - struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; if (pass != 0) return; @@ -333,7 +333,7 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_log_descriptor *ld, __be64 *ptr, int pass) { - struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; unsigned int blks = be32_to_cpu(ld->ld_length); unsigned int revokes = be32_to_cpu(ld->ld_data1); struct buffer_head *bh; @@ -379,7 +379,7 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, static void revoke_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) { - struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; if (error) { gfs2_revoke_clean(sdp); @@ -458,8 +458,6 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) gfs2_trans_add_gl(bd->bd_gl); list_add(&bd->bd_list_tr, &tr->tr_list_buf); gfs2_pin(sdp, bd->bd_bh); - } else { - clear_buffer_pinned(bd->bd_bh); } gfs2_log_lock(sdp); if (ip->i_di.di_flags & GFS2_DIF_JDATA) @@ -630,8 +628,8 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_log_descriptor *ld, __be64 *ptr, int pass) { - struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; - struct gfs2_glock *gl = jd->jd_inode->i_gl; + struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; + struct gfs2_glock *gl = get_v2ip(jd->jd_inode)->i_gl; unsigned int blks = be32_to_cpu(ld->ld_data1); struct buffer_head *bh_log, *bh_ip; uint64_t blkno; @@ -680,17 +678,17 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) { - struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; if (error) { - gfs2_meta_sync(jd->jd_inode->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT); return; } if (pass != 1) return; /* data sync? */ - gfs2_meta_sync(jd->jd_inode->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT); fs_info(sdp, "jid=%u: Replayed %u of %u data blocks\n", jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index 335448d3be21..8389f771d28b 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -169,23 +169,16 @@ static struct dentry *gfs2_get_parent(struct dentry *child) { struct gfs2_inode *dip = get_v2ip(child->d_inode); struct qstr dotdot = { .name = "..", .len = 2 }; - struct gfs2_inode *ip; struct inode *inode; struct dentry *dentry; int error; atomic_inc(&dip->i_sbd->sd_ops_export); - error = gfs2_lookupi(dip, &dotdot, 1, &ip); + error = gfs2_lookupi(child->d_inode, &dotdot, 1, &inode); if (error) return ERR_PTR(error); - inode = gfs2_ip2v(ip); - gfs2_inode_put(ip); - - if (!inode) - return ERR_PTR(-ENOMEM); - dentry = d_alloc_anon(inode); if (!dentry) { iput(inode); diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 139cef8fff3a..80d5582d9d9b 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -360,6 +360,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) goto out_rooti; } + igrab(inode); sb->s_root = d_alloc_root(inode); if (!sb->s_root) { fs_err(sdp, "can't get root dentry\n"); @@ -434,7 +435,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) goto fail_jindex; } - error = gfs2_glock_nq_init(sdp->sd_jdesc->jd_inode->i_gl, + error = gfs2_glock_nq_init(get_v2ip(sdp->sd_jdesc->jd_inode)->i_gl, LM_ST_SHARED, LM_FLAG_NOEXP | GL_EXACT, &sdp->sd_jinode_gh); diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 6fff30ef8b70..9fb9490eb67a 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -49,7 +49,7 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd) { - struct gfs2_inode *dip = get_v2ip(dir), *ip; + struct gfs2_inode *dip = get_v2ip(dir); struct gfs2_sbd *sdp = dip->i_sbd; struct gfs2_holder ghs[2]; struct inode *inode; @@ -61,9 +61,8 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, gfs2_holder_init(dip->i_gl, 0, 0, ghs); for (;;) { - error = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode); - if (!error) { - ip = get_gl2ip(ghs[1].gh_gl); + inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode); + if (!IS_ERR(inode)) { gfs2_trans_end(sdp); if (dip->i_alloc.al_rgd) gfs2_inplace_release(dip); @@ -71,13 +70,13 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, gfs2_alloc_put(dip); gfs2_glock_dq_uninit_m(2, ghs); break; - } else if (error != -EEXIST || + } else if (PTR_ERR(inode) != -EEXIST || (nd->intent.open.flags & O_EXCL)) { gfs2_holder_uninit(ghs); - return error; + return PTR_ERR(inode); } - error = gfs2_lookupi(dip, &dentry->d_name, 0, &ip); + error = gfs2_lookupi(dir, &dentry->d_name, 0, &inode); if (!error) { new = 0; gfs2_holder_uninit(ghs); @@ -88,12 +87,6 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, } } - inode = gfs2_ip2v(ip); - gfs2_inode_put(ip); - - if (!inode) - return -ENOMEM; - d_instantiate(dentry, inode); if (new) mark_inode_dirty(inode); @@ -115,7 +108,7 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) { - struct gfs2_inode *dip = get_v2ip(dir), *ip; + struct gfs2_inode *dip = get_v2ip(dir); struct gfs2_sbd *sdp = dip->i_sbd; struct inode *inode = NULL; int error; @@ -125,14 +118,8 @@ static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, if (!sdp->sd_args.ar_localcaching) dentry->d_op = &gfs2_dops; - error = gfs2_lookupi(dip, &dentry->d_name, 0, &ip); - if (!error) { - inode = gfs2_ip2v(ip); - gfs2_inode_put(ip); - if (!inode) - return ERR_PTR(-ENOMEM); - - } else if (error != -ENOENT) + error = gfs2_lookupi(dir, &dentry->d_name, 0, &inode); + if (error && error != -ENOENT) return ERR_PTR(error); if (inode) @@ -367,10 +354,10 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry, gfs2_holder_init(dip->i_gl, 0, 0, ghs); - error = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO); - if (error) { + inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO); + if (IS_ERR(inode)) { gfs2_holder_uninit(ghs); - return error; + return PTR_ERR(inode); } ip = get_gl2ip(ghs[1].gh_gl); @@ -394,12 +381,6 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry, gfs2_glock_dq_uninit_m(2, ghs); - inode = gfs2_ip2v(ip); - gfs2_inode_put(ip); - - if (!inode) - return -ENOMEM; - d_instantiate(dentry, inode); mark_inode_dirty(inode); @@ -428,10 +409,10 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) gfs2_holder_init(dip->i_gl, 0, 0, ghs); - error = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode); - if (error) { + inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode); + if (IS_ERR(inode)) { gfs2_holder_uninit(ghs); - return error; + return PTR_ERR(inode); } ip = get_gl2ip(ghs[1].gh_gl); @@ -481,12 +462,6 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) gfs2_glock_dq_uninit_m(2, ghs); - inode = gfs2_ip2v(ip); - gfs2_inode_put(ip); - - if (!inode) - return -ENOMEM; - d_instantiate(dentry, inode); mark_inode_dirty(inode); @@ -598,10 +573,10 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, gfs2_holder_init(dip->i_gl, 0, 0, ghs); - error = gfs2_createi(ghs, &dentry->d_name, mode); - if (error) { + inode = gfs2_createi(ghs, &dentry->d_name, mode); + if (IS_ERR(inode)) { gfs2_holder_uninit(ghs); - return error; + return PTR_ERR(inode); } ip = get_gl2ip(ghs[1].gh_gl); @@ -624,12 +599,6 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, gfs2_glock_dq_uninit_m(2, ghs); - inode = gfs2_ip2v(ip); - gfs2_inode_put(ip); - - if (!inode) - return -ENOMEM; - d_instantiate(dentry, inode); mark_inode_dirty(inode); diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 138fdf559a9a..7b5573946f19 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -572,7 +572,7 @@ static void do_qc(struct gfs2_quota_data *qd, int64_t change) static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, int64_t change, struct gfs2_quota_data *qd) { - struct inode *inode = gfs2_ip2v(ip); + struct inode *inode = ip->i_vnode; struct address_space *mapping = inode->i_mapping; unsigned long index = loc >> PAGE_CACHE_SHIFT; unsigned offset = loc & (PAGE_CACHE_SHIFT - 1); diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 15cd26fbcff9..bcb81c768c8b 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -27,17 +27,17 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, struct buffer_head **bh) { - struct gfs2_glock *gl = jd->jd_inode->i_gl; + struct gfs2_glock *gl = get_v2ip(jd->jd_inode)->i_gl; int new = 0; uint64_t dblock; uint32_t extlen; int error; - error = gfs2_block_map(jd->jd_inode, blk, &new, &dblock, &extlen); + error = gfs2_block_map(get_v2ip(jd->jd_inode), blk, &new, &dblock, &extlen); if (error) return error; if (!dblock) { - gfs2_consist_inode(jd->jd_inode); + gfs2_consist_inode(get_v2ip(jd->jd_inode)); return -EIO; } @@ -184,7 +184,7 @@ static int find_good_lh(struct gfs2_jdesc *jd, unsigned int *blk, *blk = 0; if (*blk == orig_blk) { - gfs2_consist_inode(jd->jd_inode); + gfs2_consist_inode(get_v2ip(jd->jd_inode)); return -EIO; } } @@ -218,7 +218,7 @@ static int jhead_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head) continue; if (lh.lh_sequence == head->lh_sequence) { - gfs2_consist_inode(jd->jd_inode); + gfs2_consist_inode(get_v2ip(jd->jd_inode)); return -EIO; } if (lh.lh_sequence < head->lh_sequence) @@ -294,7 +294,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header *head) static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, unsigned int end, int pass) { - struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; struct buffer_head *bh; struct gfs2_log_descriptor *ld; int error = 0; @@ -323,7 +323,7 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, continue; } if (error == 1) { - gfs2_consist_inode(jd->jd_inode); + gfs2_consist_inode(get_v2ip(jd->jd_inode)); error = -EIO; } brelse(bh); @@ -360,7 +360,7 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) { - struct gfs2_inode *ip = jd->jd_inode; + struct gfs2_inode *ip = get_v2ip(jd->jd_inode); struct gfs2_sbd *sdp = ip->i_sbd; unsigned int lblock; int new = 0; @@ -419,7 +419,7 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) int gfs2_recover_journal(struct gfs2_jdesc *jd, int wait) { - struct gfs2_sbd *sdp = jd->jd_inode->i_sbd; + struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; struct gfs2_log_header head; struct gfs2_holder j_gh, ji_gh, t_gh; unsigned long t; @@ -449,7 +449,7 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd, int wait) goto fail; }; - error = gfs2_glock_nq_init(jd->jd_inode->i_gl, LM_ST_SHARED, + error = gfs2_glock_nq_init(get_v2ip(jd->jd_inode)->i_gl, LM_ST_SHARED, LM_FLAG_NOEXP, &ji_gh); if (error) goto fail_gunlock_j; diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index bae32ba0c481..9b5c31952c5d 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -305,7 +305,7 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) if (!jd) break; - error = gfs2_lookupi(dip, &name, 1, &jd->jd_inode); + error = gfs2_lookupi(sdp->sd_jindex, &name, 1, &jd->jd_inode); if (error) { kfree(jd); break; @@ -342,7 +342,7 @@ void gfs2_jindex_free(struct gfs2_sbd *sdp) while (!list_empty(&list)) { jd = list_entry(list.next, struct gfs2_jdesc, jd_list); list_del(&jd->jd_list); - gfs2_inode_put(jd->jd_inode); + iput(jd->jd_inode); kfree(jd); } } @@ -411,7 +411,7 @@ struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp) int gfs2_jdesc_check(struct gfs2_jdesc *jd) { - struct gfs2_inode *ip = jd->jd_inode; + struct gfs2_inode *ip = get_v2ip(jd->jd_inode); struct gfs2_sbd *sdp = ip->i_sbd; int ar; int error; @@ -462,7 +462,7 @@ int gfs2_lookup_master_dir(struct gfs2_sbd *sdp) int gfs2_make_fs_rw(struct gfs2_sbd *sdp) { - struct gfs2_glock *j_gl = sdp->sd_jdesc->jd_inode->i_gl; + struct gfs2_glock *j_gl = get_v2ip(sdp->sd_jdesc->jd_inode)->i_gl; struct gfs2_holder t_gh; struct gfs2_log_header head; int error; @@ -472,7 +472,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp) if (error) return error; - gfs2_meta_cache_flush(sdp->sd_jdesc->jd_inode); + gfs2_meta_cache_flush(get_v2ip(sdp->sd_jdesc->jd_inode)); j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA); error = gfs2_find_jhead(sdp->sd_jdesc, &head); @@ -854,7 +854,7 @@ int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh) error = -ENOMEM; goto out; } - error = gfs2_glock_nq_init(jd->jd_inode->i_gl, LM_ST_SHARED, 0, + error = gfs2_glock_nq_init(get_v2ip(jd->jd_inode)->i_gl, LM_ST_SHARED, 0, &lfcc->gh); if (error) { kfree(lfcc); From fc69d0d336214219abb521d8ff060f786d7f369e Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 13 Feb 2006 16:21:47 +0000 Subject: [PATCH 037/292] [GFS2] Change ondisk format (hopefully for the last time) There were one or two fields in structures which didn't get changed last time back to their gfs1 sizes and alignments. One or two constants have also changed back to their original values which were missed the first time. Its possible that indirect pointer blocks might need to change. If they don't we'll have to rewrite them all on upgrade due to a change in the amount of padding that they use. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 36 ++++++++++++++++--------------- include/linux/gfs2_ondisk.h | 42 ++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index c77e18048d98..c32f7b3de662 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -397,11 +397,11 @@ static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, { struct gfs2_dirent *tmp, *cur; char *bh_end; - uint32_t cur_rec_len; + uint16_t cur_rec_len; cur = *dent; bh_end = bh->b_data + bh->b_size; - cur_rec_len = be32_to_cpu(cur->de_rec_len); + cur_rec_len = be16_to_cpu(cur->de_rec_len); if ((char *)cur + cur_rec_len >= bh_end) { if ((char *)cur + cur_rec_len > bh_end) { @@ -413,7 +413,7 @@ static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, tmp = (struct gfs2_dirent *)((char *)cur + cur_rec_len); - if ((char *)tmp + be32_to_cpu(tmp->de_rec_len) > bh_end) { + if ((char *)tmp + be16_to_cpu(tmp->de_rec_len) > bh_end) { gfs2_consist_inode(dip); return -EIO; } @@ -440,7 +440,7 @@ static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh, struct gfs2_dirent *prev, struct gfs2_dirent *cur) { - uint32_t cur_rec_len, prev_rec_len; + uint16_t cur_rec_len, prev_rec_len; if (!cur->de_inum.no_addr) { gfs2_consist_inode(dip); @@ -460,8 +460,8 @@ static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh, /* Combine this dentry with the previous one. */ - prev_rec_len = be32_to_cpu(prev->de_rec_len); - cur_rec_len = be32_to_cpu(cur->de_rec_len); + prev_rec_len = be16_to_cpu(prev->de_rec_len); + cur_rec_len = be16_to_cpu(cur->de_rec_len); if ((char *)prev + prev_rec_len != (char *)cur) gfs2_consist_inode(dip); @@ -469,7 +469,7 @@ static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh, gfs2_consist_inode(dip); prev_rec_len += cur_rec_len; - prev->de_rec_len = cpu_to_be32(prev_rec_len); + prev->de_rec_len = cpu_to_be16(prev_rec_len); } /** @@ -513,7 +513,7 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, gfs2_trans_add_bh(dip->i_gl, bh, 1); dent->de_rec_len = bh->b_size - offset; - dent->de_rec_len = cpu_to_be32(dent->de_rec_len); + dent->de_rec_len = cpu_to_be16(dent->de_rec_len); dent->de_name_len = name_len; *dent_out = dent; @@ -521,9 +521,10 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, } do { - uint32_t cur_rec_len, cur_name_len; + uint16_t cur_rec_len; + uint32_t cur_name_len; - cur_rec_len = be32_to_cpu(dent->de_rec_len); + cur_rec_len = be16_to_cpu(dent->de_rec_len); cur_name_len = dent->de_name_len; if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || @@ -536,11 +537,11 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, memset(new, 0, sizeof(struct gfs2_dirent)); new->de_rec_len = cur_rec_len - GFS2_DIRENT_SIZE(cur_name_len); - new->de_rec_len = cpu_to_be32(new->de_rec_len); + new->de_rec_len = cpu_to_be16(new->de_rec_len); new->de_name_len = name_len; - dent->de_rec_len = cur_rec_len - be32_to_cpu(new->de_rec_len); - dent->de_rec_len = cpu_to_be32(dent->de_rec_len); + dent->de_rec_len = cur_rec_len - be16_to_cpu(new->de_rec_len); + dent->de_rec_len = cpu_to_be16(dent->de_rec_len); *dent_out = new; return 0; @@ -589,9 +590,10 @@ static int dirent_fits(struct gfs2_inode *dip, struct buffer_head *bh, return 1; do { - uint32_t cur_rec_len, cur_name_len; + uint16_t cur_rec_len; + uint32_t cur_name_len; - cur_rec_len = be32_to_cpu(dent->de_rec_len); + cur_rec_len = be16_to_cpu(dent->de_rec_len); cur_name_len = dent->de_name_len; if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || @@ -832,10 +834,10 @@ static int dir_make_exhash(struct gfs2_inode *dip) /* Adjust the last dirent's record length (Remember that dent still points to the last entry.) */ - dent->de_rec_len = be32_to_cpu(dent->de_rec_len) + + dent->de_rec_len = be16_to_cpu(dent->de_rec_len) + sizeof(struct gfs2_dinode) - sizeof(struct gfs2_leaf); - dent->de_rec_len = cpu_to_be32(dent->de_rec_len); + dent->de_rec_len = cpu_to_be16(dent->de_rec_len); brelse(bh); diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index 99d7ae4f6b7e..ec432e0c208d 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -1,11 +1,11 @@ /* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ +* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +* Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +*/ #ifndef __GFS2_ONDISK_DOT_H__ #define __GFS2_ONDISK_DOT_H__ @@ -34,14 +34,14 @@ #define GFS2_FORMAT_LH 800 #define GFS2_FORMAT_LD 900 #define GFS2_FORMAT_LB 1000 -#define GFS2_FORMAT_EA 1100 -#define GFS2_FORMAT_ED 1200 +#define GFS2_FORMAT_EA 1600 +#define GFS2_FORMAT_ED 1700 #define GFS2_FORMAT_UT 1300 #define GFS2_FORMAT_QC 1400 /* These are format numbers for entities contained in files */ -#define GFS2_FORMAT_RI 1500 -#define GFS2_FORMAT_DE 1600 -#define GFS2_FORMAT_QU 1700 +#define GFS2_FORMAT_RI 1100 +#define GFS2_FORMAT_DE 1200 +#define GFS2_FORMAT_QU 1500 /* These are part of the superblock */ #define GFS2_FORMAT_FS 1801 #define GFS2_FORMAT_MULTI 1900 @@ -74,9 +74,9 @@ struct gfs2_inum { #define GFS2_METATYPE_JD 7 #define GFS2_METATYPE_LH 8 #define GFS2_METATYPE_LD 9 -#define GFS2_METATYPE_LB 10 -#define GFS2_METATYPE_EA 11 -#define GFS2_METATYPE_ED 12 +#define GFS2_METATYPE_LB 12 +#define GFS2_METATYPE_EA 10 +#define GFS2_METATYPE_ED 11 #define GFS2_METATYPE_UT 13 #define GFS2_METATYPE_QC 14 @@ -181,6 +181,7 @@ struct gfs2_quota { __be64 qu_limit; __be64 qu_warn; __be64 qu_value; + __u8 qu_reserved[64]; }; /* @@ -260,11 +261,10 @@ struct gfs2_dinode { struct gfs2_dirent { struct gfs2_inum de_inum; __be32 de_hash; - __be32 de_rec_len; - __u8 de_name_len; - __u8 de_type; - __u16 __pad1; - __u32 __pad2; + __be16 de_rec_len; + __be16 de_name_len; + __be16 de_type; + __u8 __pad[14]; }; /* @@ -279,7 +279,7 @@ struct gfs2_leaf { __be32 lf_dirent_format; /* Format of the dirents */ __be64 lf_next; /* Next leaf, if overflow */ - __u8 lf_reserved[32]; + __u8 lf_reserved[64]; }; /* From d1665e414297c3a46fd80cb8242ad0c8e82acae7 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 14 Feb 2006 11:54:42 +0000 Subject: [PATCH 038/292] [GFS2] Put back O_DIRECT support This patch adds back O_DIRECT support with various caveats attached: 1. Journaled data can be read via O_DIRECT since its now the same on disk format as normal data files. 2. Journaled data writes with O_DIRECT will be failed sliently back to normal writes (should we really do this I wonder or should we return an error instead?) 3. Stuffed files will be failed back to normal buffered I/O 4. All the usual corner cases (write beyond current end of file, write to an unallocated block) will also revert to normal buffered I/O. The I/O path is slightly odd as reads arrive at the page cache layer with the lock for the file already held, but writes arrive unlocked. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 72 ++++++++++++++++++++++++++++++++++--------- fs/gfs2/ops_file.c | 29 +++++++++-------- 2 files changed, 75 insertions(+), 26 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index b14357e89421..74706f352780 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -555,30 +556,73 @@ static int gfs2_invalidatepage(struct page *page, unsigned long offset) return ret; } -static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, - loff_t offset, unsigned long nr_segs) +static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov, + loff_t offset, unsigned long nr_segs) +{ + struct file *file = iocb->ki_filp; + struct inode *inode = file->f_mapping->host; + struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_holder gh; + int rv; + + /* + * Shared lock, even though its write, since we do no allocation + * on this path. All we need change is atime. + */ + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); + rv = gfs2_glock_nq_m_atime(1, &gh); + if (rv) + goto out; + + /* + * Should we return an error here? I can't see that O_DIRECT for + * a journaled file makes any sense. For now we'll silently fall + * back to buffered I/O, likewise we do the same for stuffed + * files since they are (a) small and (b) unaligned. + */ + if (gfs2_is_jdata(ip)) + goto out; + + if (gfs2_is_stuffed(ip)) + goto out; + + rv = __blockdev_direct_IO(WRITE, iocb, inode, inode->i_sb->s_bdev, + iov, offset, nr_segs, get_blocks_noalloc, + NULL, DIO_OWN_LOCKING); +out: + gfs2_glock_dq_m(1, &gh); + gfs2_holder_uninit(&gh); + + return rv; +} + +/** + * gfs2_direct_IO + * + * This is called with a shared lock already held for the read path. + * Currently, no locks are held when the write path is called. + */ +static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, + const struct iovec *iov, loff_t offset, + unsigned long nr_segs) { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; struct gfs2_inode *ip = get_v2ip(inode); struct gfs2_sbd *sdp = ip->i_sbd; - get_blocks_t *gb = get_blocks; atomic_inc(&sdp->sd_ops_address); - if (gfs2_is_jdata(ip)) + if (rw == WRITE) + return gfs2_direct_IO_write(iocb, iov, offset, nr_segs); + + if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl)) || + gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) return -EINVAL; - if (rw == WRITE) { - return -EOPNOTSUPP; /* for now */ - } else { - if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl)) || - gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) - return -EINVAL; - } - - return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, - offset, nr_segs, gb, NULL); + return __blockdev_direct_IO(READ, iocb, inode, inode->i_sb->s_bdev, iov, + offset, nr_segs, get_blocks, NULL, + DIO_OWN_LOCKING); } struct address_space_operations gfs2_file_aops = { diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 56820b39a993..bcde7a0b76f1 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -176,16 +176,16 @@ static ssize_t __gfs2_file_aio_read(struct kiocb *iocb, * If any segment has a negative length, or the cumulative * length ever wraps negative then return -EINVAL. */ - count += iv->iov_len; - if (unlikely((ssize_t)(count|iv->iov_len) < 0)) - return -EINVAL; - if (access_ok(VERIFY_WRITE, iv->iov_base, iv->iov_len)) - continue; - if (seg == 0) - return -EFAULT; - nr_segs = seg; - count -= iv->iov_len; /* This segment is no good */ - break; + count += iv->iov_len; + if (unlikely((ssize_t)(count|iv->iov_len) < 0)) + return -EINVAL; + if (access_ok(VERIFY_WRITE, iv->iov_base, iv->iov_len)) + continue; + if (seg == 0) + return -EFAULT; + nr_segs = seg; + count -= iv->iov_len; /* This segment is no good */ + break; } /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ @@ -204,10 +204,14 @@ static ssize_t __gfs2_file_aio_read(struct kiocb *iocb, retval = gfs2_glock_nq_m_atime(1, &gh); if (retval) goto out; - + if (gfs2_is_stuffed(ip)) { + gfs2_glock_dq_m(1, &gh); + gfs2_holder_uninit(&gh); + goto fallback_to_normal; + } size = i_size_read(inode); if (pos < size) { - retval = gfs2_direct_IO_read(iocb, iov, pos, nr_segs); + retval = gfs2_direct_IO_read(iocb, iov, pos, nr_segs); if (retval > 0 && !is_sync_kiocb(iocb)) retval = -EIOCBQUEUED; if (retval > 0) @@ -219,6 +223,7 @@ static ssize_t __gfs2_file_aio_read(struct kiocb *iocb, goto out; } +fallback_to_normal: retval = 0; if (count) { for (seg = 0; seg < nr_segs; seg++) { From 4dd651adbb4898d3200426c197b26c99d2209d8d Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 14 Feb 2006 15:56:44 +0000 Subject: [PATCH 039/292] [GFS2] Fix the bugs I introduced in the last patch but one Various endianess changes required in the directory code. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 56 ++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index c32f7b3de662..65871a2b460e 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -417,6 +417,12 @@ static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, gfs2_consist_inode(dip); return -EIO; } + + if (cur_rec_len == 0) { + gfs2_consist_inode(dip); + return -EIO; + } + /* Only the first dent could ever have de_inum.no_addr == 0 */ if (!tmp->de_inum.no_addr) { gfs2_consist_inode(dip); @@ -512,9 +518,8 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, gfs2_trans_add_bh(dip->i_gl, bh, 1); - dent->de_rec_len = bh->b_size - offset; - dent->de_rec_len = cpu_to_be16(dent->de_rec_len); - dent->de_name_len = name_len; + dent->de_rec_len = cpu_to_be16(bh->b_size - offset); + dent->de_name_len = cpu_to_be16(name_len); *dent_out = dent; return 0; @@ -522,10 +527,10 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, do { uint16_t cur_rec_len; - uint32_t cur_name_len; + uint16_t cur_name_len; cur_rec_len = be16_to_cpu(dent->de_rec_len); - cur_name_len = dent->de_name_len; + cur_name_len = be16_to_cpu(dent->de_name_len); if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) { @@ -536,18 +541,16 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, GFS2_DIRENT_SIZE(cur_name_len)); memset(new, 0, sizeof(struct gfs2_dirent)); - new->de_rec_len = cur_rec_len - GFS2_DIRENT_SIZE(cur_name_len); - new->de_rec_len = cpu_to_be16(new->de_rec_len); - new->de_name_len = name_len; + new->de_rec_len = cpu_to_be16(cur_rec_len - GFS2_DIRENT_SIZE(cur_name_len)); + new->de_name_len = cpu_to_be16(name_len); - dent->de_rec_len = cur_rec_len - be16_to_cpu(new->de_rec_len); - dent->de_rec_len = cpu_to_be16(dent->de_rec_len); + dent->de_rec_len = cpu_to_be16(cur_rec_len - be16_to_cpu(new->de_rec_len)); *dent_out = new; return 0; } - dent->de_name_len = name_len; + dent->de_name_len = cpu_to_be16(name_len); *dent_out = dent; return 0; @@ -594,7 +597,7 @@ static int dirent_fits(struct gfs2_inode *dip, struct buffer_head *bh, uint32_t cur_name_len; cur_rec_len = be16_to_cpu(dent->de_rec_len); - cur_name_len = dent->de_name_len; + cur_name_len = be16_to_cpu(dent->de_name_len); if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) @@ -635,7 +638,7 @@ static int leaf_search(struct gfs2_inode *dip, struct buffer_head *bh, if (be32_to_cpu(dent->de_hash) == hash && gfs2_filecmp(filename, (char *)(dent + 1), - dent->de_name_len)) { + be16_to_cpu(dent->de_name_len))) { *dent_out = dent; if (dent_prev) *dent_prev = prev; @@ -834,10 +837,9 @@ static int dir_make_exhash(struct gfs2_inode *dip) /* Adjust the last dirent's record length (Remember that dent still points to the last entry.) */ - dent->de_rec_len = be16_to_cpu(dent->de_rec_len) + + dent->de_rec_len = cpu_to_be16(be16_to_cpu(dent->de_rec_len) + sizeof(struct gfs2_dinode) - - sizeof(struct gfs2_leaf); - dent->de_rec_len = cpu_to_be16(dent->de_rec_len); + sizeof(struct gfs2_leaf)); brelse(bh); @@ -969,7 +971,7 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, if (dent->de_inum.no_addr && be32_to_cpu(dent->de_hash) < divider) { - name_len = dent->de_name_len; + name_len = be16_to_cpu(dent->de_name_len); gfs2_dirent_alloc(dip, nbh, name_len, &new); @@ -1139,8 +1141,8 @@ static int compare_dents(const void *a, const void *b) else if (hash_a < hash_b) ret = -1; else { - unsigned int len_a = dent_a->de_name_len; - unsigned int len_b = dent_b->de_name_len; + unsigned int len_a = be16_to_cpu(dent_a->de_name_len); + unsigned int len_b = be16_to_cpu(dent_b->de_name_len); if (len_a > len_b) ret = 1; @@ -1219,9 +1221,9 @@ static int do_filldir_main(struct gfs2_inode *dip, uint64_t *offset, gfs2_inum_in(&inum, (char *)&dent->de_inum); error = filldir(opaque, (char *)(dent + 1), - dent->de_name_len, + be16_to_cpu(dent->de_name_len), off, &inum, - dent->de_type); + be16_to_cpu(dent->de_type)); if (error) return 1; @@ -1454,7 +1456,7 @@ static int dir_e_search(struct gfs2_inode *dip, struct qstr *filename, if (inum) gfs2_inum_in(inum, (char *)&dent->de_inum); if (type) - *type = dent->de_type; + *type = be16_to_cpu(dent->de_type); brelse(bh); @@ -1563,7 +1565,7 @@ static int dir_e_add(struct gfs2_inode *dip, struct qstr *filename, gfs2_inum_out(inum, (char *)&dent->de_inum); dent->de_hash = cpu_to_be32(hash); - dent->de_type = type; + dent->de_type = cpu_to_be16(type); memcpy((char *)(dent + 1), filename->name, filename->len); leaf->lf_entries = be16_to_cpu(leaf->lf_entries) + 1; @@ -1732,7 +1734,7 @@ static int dir_e_mvino(struct gfs2_inode *dip, struct qstr *filename, gfs2_trans_add_bh(dip->i_gl, bh, 1); gfs2_inum_out(inum, (char *)&dent->de_inum); - dent->de_type = new_type; + dent->de_type = cpu_to_be16(new_type); brelse(bh); @@ -1780,7 +1782,7 @@ static int dir_l_search(struct gfs2_inode *dip, struct qstr *filename, if (inum) gfs2_inum_in(inum, (char *)&dent->de_inum); if (type) - *type = dent->de_type; + *type = be16_to_cpu(dent->de_type); } brelse(dibh); @@ -1819,7 +1821,7 @@ static int dir_l_add(struct gfs2_inode *dip, struct qstr *filename, gfs2_inum_out(inum, (char *)&dent->de_inum); dent->de_hash = gfs2_disk_hash(filename->name, filename->len); dent->de_hash = cpu_to_be32(dent->de_hash); - dent->de_type = type; + dent->de_type = cpu_to_be16(type); memcpy((char *)(dent + 1), filename->name, filename->len); dip->i_di.di_entries++; @@ -1932,7 +1934,7 @@ static int dir_l_mvino(struct gfs2_inode *dip, struct qstr *filename, gfs2_trans_add_bh(dip->i_gl, dibh, 1); gfs2_inum_out(inum, (char *)&dent->de_inum); - dent->de_type = new_type; + dent->de_type = cpu_to_be16(new_type); dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); From 61a30dcb5866eb7e92796b2988ddb4c94b9f78ac Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 15 Feb 2006 10:15:18 +0000 Subject: [PATCH 040/292] [GFS2] Fix for lock recursion problem for internal files Two internal files which are read through the gfs2_internal_read() routine were already locked when the routine was called and this do not need locking at the redapages level. This patch introduces a struct file which is used as a sentinal so that readpage will only perform locking in the case that the struct file passed to it is _not_ equal to this sentinal. Since the comments in the generic kernel code indicate that the struct file will never be used for anything other than passing straight through to readpage(), this should be ok. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 17 +++++++++++------ fs/gfs2/ops_file.c | 14 +++++++++++++- fs/gfs2/ops_file.h | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 74706f352780..39d03f3f2d54 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -28,6 +28,7 @@ #include "quota.h" #include "trans.h" #include "rgrp.h" +#include "ops_file.h" /** * gfs2_get_block - Fills in a buffer head with details about a block @@ -267,10 +268,12 @@ static int gfs2_readpage(struct file *file, struct page *page) atomic_inc(&sdp->sd_ops_address); - gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); - error = gfs2_glock_nq_m_atime(1, &gh); - if (error) - goto out_unlock; + if (file != &gfs2_internal_file_sentinal) { + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); + error = gfs2_glock_nq_m_atime(1, &gh); + if (error) + goto out_unlock; + } if (gfs2_is_stuffed(ip)) { if (!page->index) { @@ -284,8 +287,10 @@ static int gfs2_readpage(struct file *file, struct page *page) if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = -EIO; - gfs2_glock_dq_m(1, &gh); - gfs2_holder_uninit(&gh); + if (file != &gfs2_internal_file_sentinal) { + gfs2_glock_dq_m(1, &gh); + gfs2_holder_uninit(&gh); + } out: return error; out_unlock: diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index bcde7a0b76f1..b86037832299 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -67,6 +67,16 @@ struct filldir_reg { void *fdr_opaque; }; +/* + * Most fields left uninitialised to catch anybody who tries to + * use them. f_flags set to prevent file_accessed() from touching + * any other part of this. Its use is purely as a flag so that we + * know (in readpage()) whether or not do to locking. + */ +struct file gfs2_internal_file_sentinal = { + .f_flags = O_NOATIME|O_RDONLY, +}; + static int gfs2_read_actor(read_descriptor_t *desc, struct page *page, unsigned long offset, unsigned long size) { @@ -95,7 +105,9 @@ int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, desc.arg.buf = buf; desc.count = size; desc.error = 0; - do_generic_mapping_read(inode->i_mapping, ra_state, NULL, pos, &desc, gfs2_read_actor); + do_generic_mapping_read(inode->i_mapping, ra_state, + &gfs2_internal_file_sentinal, pos, &desc, + gfs2_read_actor); return desc.written ? desc.written : desc.error; } diff --git a/fs/gfs2/ops_file.h b/fs/gfs2/ops_file.h index 3c237bfc143d..192577b411f0 100644 --- a/fs/gfs2/ops_file.h +++ b/fs/gfs2/ops_file.h @@ -9,7 +9,7 @@ #ifndef __OPS_FILE_DOT_H__ #define __OPS_FILE_DOT_H__ - +extern struct file gfs2_internal_file_sentinal; extern int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, char *buf, loff_t *pos, unsigned size); From 5c4e9e036678fae65c9288e1c00a6f33cd447283 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 15 Feb 2006 12:26:19 +0000 Subject: [PATCH 041/292] [GFS2] Fix a case where we didn't get unstuffing right There was a bug in the unstuffing logic which caused a crash under certain circumstances. This is now fixed. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 39d03f3f2d54..1ccc26426821 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -220,14 +220,14 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page) if (error) return error; - kaddr = kmap(page); + kaddr = kmap_atomic(page, KM_USER0); memcpy((char *)kaddr, dibh->b_data + sizeof(struct gfs2_dinode), ip->i_di.di_size); memset((char *)kaddr + ip->i_di.di_size, 0, PAGE_CACHE_SIZE - ip->i_di.di_size); - kunmap(page); + kunmap_atomic(page, KM_USER0); brelse(dibh); @@ -240,9 +240,9 @@ static int zero_readpage(struct page *page) { void *kaddr; - kaddr = kmap(page); + kaddr = kmap_atomic(page, KM_USER0); memset(kaddr, 0, PAGE_CACHE_SIZE); - kunmap(page); + kunmap_atomic(page, KM_USER0); SetPageUptodate(page); unlock_page(page); @@ -364,14 +364,14 @@ static int gfs2_prepare_write(struct file *file, struct page *page, if (gfs2_is_stuffed(ip)) { if (end > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) { error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, page); - if (error) - goto out; - } else if (!PageUptodate(page)) { + if (error == 0) + goto prepare_write; + } else if (!PageUptodate(page)) error = stuffed_readpage(ip, page); - goto out; - } + goto out; } +prepare_write: error = block_prepare_write(page, from, to, gfs2_get_block); out: From f55ab26a8f92a23988c3e6da28dae4741933a4e2 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 21 Feb 2006 12:51:39 +0000 Subject: [PATCH 042/292] [GFS2] Use mutices rather than semaphores As well as a number of minor bug fixes, this patch changes GFS to use mutices rather than semaphores. This results in better information in case there are any locking problems. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 8 +++---- fs/gfs2/incore.h | 22 +++++++++--------- fs/gfs2/inode.c | 12 +++++----- fs/gfs2/log.c | 54 +++++++++++++++---------------------------- fs/gfs2/log.h | 3 --- fs/gfs2/lops.c | 36 ++++++++++++++++++++++------- fs/gfs2/meta_io.c | 2 +- fs/gfs2/ops_address.c | 1 - fs/gfs2/ops_file.c | 10 ++++---- fs/gfs2/ops_fstype.c | 18 +++++++-------- fs/gfs2/ops_super.c | 4 ++-- fs/gfs2/quota.c | 16 ++++++------- fs/gfs2/rgrp.c | 18 +++++++-------- fs/gfs2/super.c | 20 ++++++++-------- fs/gfs2/sys.c | 4 ++-- fs/gfs2/trans.c | 4 ++-- fs/gfs2/unlinked.c | 4 ++-- 17 files changed, 118 insertions(+), 118 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 321945fde12d..4df78ecfeeb3 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -149,7 +149,7 @@ int gfs2_glock_put(struct gfs2_glock *gl) struct gfs2_gl_hash_bucket *bucket = gl->gl_bucket; int rv = 0; - down(&sdp->sd_invalidate_inodes_mutex); + mutex_lock(&sdp->sd_invalidate_inodes_mutex); write_lock(&bucket->hb_lock); if (kref_put(&gl->gl_ref, kill_glock)) { @@ -161,7 +161,7 @@ int gfs2_glock_put(struct gfs2_glock *gl) } write_unlock(&bucket->hb_lock); out: - up(&sdp->sd_invalidate_inodes_mutex); + mutex_unlock(&sdp->sd_invalidate_inodes_mutex); return rv; } @@ -2312,9 +2312,9 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait) invalidate_inodes_mutex prevents glock_put()'s during an invalidate_inodes() */ - down(&sdp->sd_invalidate_inodes_mutex); + mutex_lock(&sdp->sd_invalidate_inodes_mutex); invalidate_inodes(sdp->sd_vfs); - up(&sdp->sd_invalidate_inodes_mutex); + mutex_unlock(&sdp->sd_invalidate_inodes_mutex); yield(); } } diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index e43a0475d0d8..7fe422537ff0 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -88,7 +88,7 @@ struct gfs2_rgrpd { uint64_t rd_rg_vn; struct gfs2_bitmap *rd_bits; unsigned int rd_bh_count; - struct semaphore rd_mutex; + struct mutex rd_mutex; uint32_t rd_free_clone; struct gfs2_log_element rd_le; uint32_t rd_last_alloc_data; @@ -277,7 +277,7 @@ enum { struct gfs2_file { unsigned long f_flags; /* GFF_... */ - struct semaphore f_fl_mutex; + struct mutex f_fl_mutex; struct gfs2_holder f_fl_gh; struct gfs2_inode *f_inode; @@ -510,7 +510,7 @@ struct gfs2_sbd { struct gfs2_holder sd_live_gh; struct gfs2_glock *sd_rename_gl; struct gfs2_glock *sd_trans_gl; - struct semaphore sd_invalidate_inodes_mutex; + struct mutex sd_invalidate_inodes_mutex; /* Inode Stuff */ @@ -528,12 +528,12 @@ struct gfs2_sbd { /* Inum stuff */ - struct semaphore sd_inum_mutex; + struct mutex sd_inum_mutex; /* StatFS stuff */ spinlock_t sd_statfs_spin; - struct semaphore sd_statfs_mutex; + struct mutex sd_statfs_mutex; struct gfs2_statfs_change sd_statfs_master; struct gfs2_statfs_change sd_statfs_local; unsigned long sd_statfs_sync_time; @@ -542,7 +542,7 @@ struct gfs2_sbd { uint64_t sd_rindex_vn; spinlock_t sd_rindex_spin; - struct semaphore sd_rindex_mutex; + struct mutex sd_rindex_mutex; struct list_head sd_rindex_list; struct list_head sd_rindex_mru_list; struct list_head sd_rindex_recent_list; @@ -553,7 +553,7 @@ struct gfs2_sbd { struct list_head sd_jindex_list; spinlock_t sd_jindex_spin; - struct semaphore sd_jindex_mutex; + struct mutex sd_jindex_mutex; unsigned int sd_journals; unsigned long sd_jindex_refresh_time; @@ -581,7 +581,7 @@ struct gfs2_sbd { struct list_head sd_unlinked_list; atomic_t sd_unlinked_count; spinlock_t sd_unlinked_spin; - struct semaphore sd_unlinked_mutex; + struct mutex sd_unlinked_mutex; unsigned int sd_unlinked_slots; unsigned int sd_unlinked_chunks; @@ -592,7 +592,7 @@ struct gfs2_sbd { struct list_head sd_quota_list; atomic_t sd_quota_count; spinlock_t sd_quota_spin; - struct semaphore sd_quota_mutex; + struct mutex sd_quota_mutex; unsigned int sd_quota_slots; unsigned int sd_quota_chunks; @@ -637,7 +637,7 @@ struct gfs2_sbd { int sd_log_idle; unsigned long sd_log_flush_time; - struct semaphore sd_log_flush_lock; + struct mutex sd_log_flush_lock; struct list_head sd_log_flush_list; unsigned int sd_log_flush_head; @@ -659,7 +659,7 @@ struct gfs2_sbd { /* For quiescing the filesystem */ struct gfs2_holder sd_freeze_gh; - struct semaphore sd_freeze_lock; + struct mutex sd_freeze_lock; unsigned int sd_freeze_count; /* Counters */ diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 2a00b96eac01..30ca82a1addf 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -782,11 +782,11 @@ static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) error = gfs2_trans_begin(sdp, RES_DINODE, 0); if (error) return error; - down(&sdp->sd_inum_mutex); + mutex_lock(&sdp->sd_inum_mutex); error = gfs2_meta_inode_buffer(ip, &bh); if (error) { - up(&sdp->sd_inum_mutex); + mutex_unlock(&sdp->sd_inum_mutex); gfs2_trans_end(sdp); return error; } @@ -800,14 +800,14 @@ static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) gfs2_inum_range_out(&ir, bh->b_data + sizeof(struct gfs2_dinode)); brelse(bh); - up(&sdp->sd_inum_mutex); + mutex_unlock(&sdp->sd_inum_mutex); gfs2_trans_end(sdp); return 0; } brelse(bh); - up(&sdp->sd_inum_mutex); + mutex_unlock(&sdp->sd_inum_mutex); gfs2_trans_end(sdp); return 1; @@ -829,7 +829,7 @@ static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0); if (error) goto out; - down(&sdp->sd_inum_mutex); + mutex_lock(&sdp->sd_inum_mutex); error = gfs2_meta_inode_buffer(ip, &bh); if (error) @@ -869,7 +869,7 @@ static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) brelse(bh); out_end_trans: - up(&sdp->sd_inum_mutex); + mutex_unlock(&sdp->sd_inum_mutex); gfs2_trans_end(sdp); out: diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 49190a29dd4f..e6acb41332e7 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -23,29 +23,16 @@ #define PULL 1 -static inline int is_done(struct gfs2_sbd *sdp, atomic_t *a) -{ - int done; - gfs2_log_lock(sdp); - done = atomic_read(a) ? 0 : 1; - gfs2_log_unlock(sdp); - return done; -} - static void do_lock_wait(struct gfs2_sbd *sdp, wait_queue_head_t *wq, atomic_t *a) { - gfs2_log_unlock(sdp); - wait_event(*wq, is_done(sdp, a)); - gfs2_log_lock(sdp); + wait_event(*wq, atomic_read(a) ? 0 : 1); } static void lock_for_trans(struct gfs2_sbd *sdp) { - gfs2_log_lock(sdp); do_lock_wait(sdp, &sdp->sd_log_trans_wq, &sdp->sd_log_flush_count); atomic_inc(&sdp->sd_log_trans_count); - gfs2_log_unlock(sdp); } static void unlock_from_trans(struct gfs2_sbd *sdp) @@ -55,15 +42,13 @@ static void unlock_from_trans(struct gfs2_sbd *sdp) wake_up(&sdp->sd_log_flush_wq); } -void gfs2_lock_for_flush(struct gfs2_sbd *sdp) +static void gfs2_lock_for_flush(struct gfs2_sbd *sdp) { - gfs2_log_lock(sdp); atomic_inc(&sdp->sd_log_flush_count); do_lock_wait(sdp, &sdp->sd_log_flush_wq, &sdp->sd_log_trans_count); - gfs2_log_unlock(sdp); } -void gfs2_unlock_from_flush(struct gfs2_sbd *sdp) +static void gfs2_unlock_from_flush(struct gfs2_sbd *sdp) { gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_flush_count)); if (atomic_dec_and_test(&sdp->sd_log_flush_count)) @@ -209,7 +194,6 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) for (;;) { gfs2_log_lock(sdp); - if (list_empty(&list)) { list_add_tail(&list, &sdp->sd_log_blks_list); while (sdp->sd_log_blks_list.next != &list) { @@ -225,7 +209,6 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) set_current_state(TASK_RUNNING); } } - /* Never give away the last block so we can always pull the tail if we need to. */ if (sdp->sd_log_blks_free > blks) { @@ -237,14 +220,12 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) } gfs2_log_unlock(sdp); - gfs2_ail1_empty(sdp, 0); gfs2_log_flush(sdp); if (try++) gfs2_ail1_start(sdp, 0); } - lock_for_trans(sdp); return 0; @@ -512,22 +493,26 @@ void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); INIT_LIST_HEAD(&ai->ai_ail1_list); INIT_LIST_HEAD(&ai->ai_ail2_list); - gfs2_lock_for_flush(sdp); - down(&sdp->sd_log_flush_lock); + + if (gl) { + gfs2_log_lock(sdp); + if (list_empty(&gl->gl_le.le_list)) { + gfs2_log_unlock(sdp); + gfs2_unlock_from_flush(sdp); + kfree(ai); + return; + } + gfs2_log_unlock(sdp); + } + + mutex_lock(&sdp->sd_log_flush_lock); gfs2_assert_withdraw(sdp, sdp->sd_log_num_buf == sdp->sd_log_commited_buf); gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke); - if (gl && list_empty(&gl->gl_le.le_list)) { - up(&sdp->sd_log_flush_lock); - gfs2_unlock_from_flush(sdp); - kfree(ai); - return; - } - sdp->sd_log_flush_head = sdp->sd_log_head; sdp->sd_log_flush_wrapped = 0; ai->ai_first = sdp->sd_log_flush_head; @@ -538,7 +523,6 @@ void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle) log_write_header(sdp, 0, PULL); lops_after_commit(sdp, ai); - sdp->sd_log_head = sdp->sd_log_flush_head; if (sdp->sd_log_flush_wrapped) sdp->sd_log_wraps++; @@ -554,7 +538,7 @@ void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) } gfs2_log_unlock(sdp); - up(&sdp->sd_log_flush_lock); + mutex_unlock(&sdp->sd_log_flush_lock); sdp->sd_vfs->s_dirt = 0; gfs2_unlock_from_flush(sdp); @@ -627,7 +611,7 @@ void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) void gfs2_log_shutdown(struct gfs2_sbd *sdp) { - down(&sdp->sd_log_flush_lock); + mutex_lock(&sdp->sd_log_flush_lock); gfs2_assert_withdraw(sdp, !atomic_read(&sdp->sd_log_trans_count)); gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); @@ -654,6 +638,6 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp) sdp->sd_log_wraps++; sdp->sd_log_tail = sdp->sd_log_head; - up(&sdp->sd_log_flush_lock); + mutex_unlock(&sdp->sd_log_flush_lock); } diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h index 4413cda81154..e7a6a65c530f 100644 --- a/fs/gfs2/log.h +++ b/fs/gfs2/log.h @@ -42,9 +42,6 @@ static inline void gfs2_log_pointers_init(struct gfs2_sbd *sdp, sdp->sd_log_head = sdp->sd_log_tail = value; } -void gfs2_lock_for_flush(struct gfs2_sbd *sdp); -void gfs2_unlock_from_flush(struct gfs2_sbd *sdp); - unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, unsigned int ssize); diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 23be00141901..5e7e7d91fc5e 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -502,7 +502,8 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) unsigned int total_dbuf = sdp->sd_log_num_databuf; unsigned int total_jdata = sdp->sd_log_num_jdata; unsigned int num, n; - __be64 *ptr; + __be64 *ptr = NULL; + unsigned i; offset += (2*sizeof(__be64) - 1); offset &= ~(2*sizeof(__be64) - 1); @@ -513,14 +514,17 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) * Start writing ordered buffers, write journaled buffers * into the log along with a header */ + gfs2_log_lock(sdp); + /* printk(KERN_INFO "locked in lops databuf_before_commit\n"); */ bd2 = bd1 = list_prepare_entry(bd1, &sdp->sd_log_le_databuf, bd_le.le_list); while(total_dbuf) { num = total_jdata; if (num > limit) num = limit; + /* printk(KERN_INFO "total_dbuf=%u num=%u\n", total_dbuf, num); */ n = 0; + i = 0; list_for_each_entry_safe_continue(bd1, bdt, &sdp->sd_log_le_databuf, bd_le.le_list) { - gfs2_log_lock(sdp); /* An ordered write buffer */ if (bd1->bd_bh && !buffer_pinned(bd1->bd_bh)) { list_move(&bd1->bd_le.le_list, &started); @@ -531,20 +535,28 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) total_dbuf--; if (bd1->bd_bh) { get_bh(bd1->bd_bh); - gfs2_log_unlock(sdp); if (buffer_dirty(bd1->bd_bh)) { + gfs2_log_unlock(sdp); wait_on_buffer(bd1->bd_bh); ll_rw_block(WRITE, 1, &bd1->bd_bh); + gfs2_log_lock(sdp); } brelse(bd1->bd_bh); + /* printk(KERN_INFO "db write %p\n", bd1); */ + if (++i > 100000) { + printk(KERN_INFO "looping bd1=%p bdt=%p eol=%p started=%p\n", bd1, bdt, &sdp->sd_log_le_databuf, &started); + dump_stack(); + BUG(); + } continue; } - gfs2_log_unlock(sdp); + /* printk(KERN_INFO "db skip\n"); */ continue; } else if (bd1->bd_bh) { /* A journaled buffer */ int magic; gfs2_log_unlock(sdp); - /* printk(KERN_INFO "journaled buffer\n"); */ + printk(KERN_INFO "journaled buffer %p\n", bd1->bd_bh); + printk(KERN_INFO "%lu %u %p %p\n", bd1->bd_bh->b_blocknr, bd1->bd_bh->b_size, bd1->bd_bh->b_data, bd1->bd_bh->b_page); if (!bh) { bh = gfs2_log_get_buf(sdp); ld = (struct gfs2_log_descriptor *)bh->b_data; @@ -558,16 +570,21 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) ld->ld_data2 = cpu_to_be32(0); memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved)); } + /* printk(KERN_INFO "check_magic\n"); */ magic = gfs2_check_magic(bd1->bd_bh); + /* printk(KERN_INFO "write data\n"); */ *ptr++ = cpu_to_be64(bd1->bd_bh->b_blocknr); *ptr++ = cpu_to_be64((__u64)magic); + /* printk(KERN_INFO "mark escaped or not\n"); */ clear_buffer_escaped(bd1->bd_bh); if (unlikely(magic != 0)) set_buffer_escaped(bd1->bd_bh); + gfs2_log_lock(sdp); if (n++ > num) break; } } + gfs2_log_unlock(sdp); if (bh) { set_buffer_dirty(bh); ll_rw_block(WRITE, 1, &bh); @@ -575,10 +592,12 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) } n = 0; /* printk(KERN_INFO "totals2: jdata=%u dbuf=%u\n", total_jdata, total_dbuf); */ + gfs2_log_lock(sdp); list_for_each_entry_continue(bd2, &sdp->sd_log_le_databuf, bd_le.le_list) { if (!bd2->bd_bh) continue; /* copy buffer if it needs escaping */ + gfs2_log_unlock(sdp); if (unlikely(buffer_escaped(bd2->bd_bh))) { void *kaddr; struct page *page = bd2->bd_bh->b_page; @@ -592,6 +611,7 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) } set_buffer_dirty(bh); ll_rw_block(WRITE, 1, &bh); + gfs2_log_lock(sdp); if (++n >= num) break; } @@ -599,6 +619,8 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) total_dbuf -= num; total_jdata -= num; } + gfs2_log_unlock(sdp); + /* printk(KERN_INFO "wait on ordered data buffers\n"); */ /* Wait on all ordered buffers */ while (!list_empty(&started)) { @@ -701,12 +723,10 @@ static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) while (!list_empty(head)) { bd = list_entry(head->next, struct gfs2_bufdata, bd_le.le_list); - list_del_init(&bd->bd_le.le_list); + list_del(&bd->bd_le.le_list); sdp->sd_log_num_databuf--; sdp->sd_log_num_jdata--; gfs2_unpin(sdp, bd->bd_bh, ai); - brelse(bd->bd_bh); - kfree(bd); } gfs2_assert_warn(sdp, !sdp->sd_log_num_databuf); gfs2_assert_warn(sdp, !sdp->sd_log_num_jdata); diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index ef58d43b67ee..8fba84306755 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -556,7 +556,7 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta return; } - bd = kmem_cache_alloc(gfs2_bufdata_cachep, GFP_KERNEL | __GFP_NOFAIL), + bd = kmem_cache_alloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL), atomic_inc(&gl->gl_sbd->sd_bufdata_count); memset(bd, 0, sizeof(struct gfs2_bufdata)); diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 1ccc26426821..c719a2a40698 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -189,7 +189,6 @@ static int gfs2_writepage(struct page *page, struct writeback_control *wbc) gfs2_page_add_databufs(ip, page, 0, sdp->sd_vfs->s_blocksize-1); done_trans = 1; } - error = block_write_full_page(page, get_block_noalloc, wbc); if (done_trans) gfs2_trans_end(sdp); diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index b86037832299..cf2e26e07245 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -688,7 +688,7 @@ static int gfs2_open(struct inode *inode, struct file *file) if (!fp) return -ENOMEM; - init_MUTEX(&fp->f_fl_mutex); + mutex_init(&fp->f_fl_mutex); fp->f_inode = ip; fp->f_vfile = file; @@ -858,7 +858,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; flags = ((IS_SETLKW(cmd)) ? 0 : LM_FLAG_TRY) | GL_EXACT | GL_NOCACHE; - down(&fp->f_fl_mutex); + mutex_lock(&fp->f_fl_mutex); gl = fl_gh->gh_gl; if (gl) { @@ -890,7 +890,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) } out: - up(&fp->f_fl_mutex); + mutex_unlock(&fp->f_fl_mutex); return error; } @@ -900,11 +900,11 @@ static void do_unflock(struct file *file, struct file_lock *fl) struct gfs2_file *fp = get_v2fp(file); struct gfs2_holder *fl_gh = &fp->f_fl_gh; - down(&fp->f_fl_mutex); + mutex_lock(&fp->f_fl_mutex); flock_lock_file_wait(file, fl); if (fl_gh->gh_gl) gfs2_glock_dq_uninit(fl_gh); - up(&fp->f_fl_mutex); + mutex_unlock(&fp->f_fl_mutex); } /** diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 80d5582d9d9b..751178ab497c 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -59,29 +59,29 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) INIT_LIST_HEAD(&sdp->sd_reclaim_list); spin_lock_init(&sdp->sd_reclaim_lock); init_waitqueue_head(&sdp->sd_reclaim_wq); - init_MUTEX(&sdp->sd_invalidate_inodes_mutex); + mutex_init(&sdp->sd_invalidate_inodes_mutex); - init_MUTEX(&sdp->sd_inum_mutex); + mutex_init(&sdp->sd_inum_mutex); spin_lock_init(&sdp->sd_statfs_spin); - init_MUTEX(&sdp->sd_statfs_mutex); + mutex_init(&sdp->sd_statfs_mutex); spin_lock_init(&sdp->sd_rindex_spin); - init_MUTEX(&sdp->sd_rindex_mutex); + mutex_init(&sdp->sd_rindex_mutex); INIT_LIST_HEAD(&sdp->sd_rindex_list); INIT_LIST_HEAD(&sdp->sd_rindex_mru_list); INIT_LIST_HEAD(&sdp->sd_rindex_recent_list); INIT_LIST_HEAD(&sdp->sd_jindex_list); spin_lock_init(&sdp->sd_jindex_spin); - init_MUTEX(&sdp->sd_jindex_mutex); + mutex_init(&sdp->sd_jindex_mutex); INIT_LIST_HEAD(&sdp->sd_unlinked_list); spin_lock_init(&sdp->sd_unlinked_spin); - init_MUTEX(&sdp->sd_unlinked_mutex); + mutex_init(&sdp->sd_unlinked_mutex); INIT_LIST_HEAD(&sdp->sd_quota_list); spin_lock_init(&sdp->sd_quota_spin); - init_MUTEX(&sdp->sd_quota_mutex); + mutex_init(&sdp->sd_quota_mutex); spin_lock_init(&sdp->sd_log_lock); init_waitqueue_head(&sdp->sd_log_trans_wq); @@ -99,12 +99,12 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) INIT_LIST_HEAD(&sdp->sd_ail1_list); INIT_LIST_HEAD(&sdp->sd_ail2_list); - init_MUTEX(&sdp->sd_log_flush_lock); + mutex_init(&sdp->sd_log_flush_lock); INIT_LIST_HEAD(&sdp->sd_log_flush_list); INIT_LIST_HEAD(&sdp->sd_revoke_list); - init_MUTEX(&sdp->sd_freeze_lock); + mutex_init(&sdp->sd_freeze_lock); return sdp; } diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index e06ef8dbd4d3..9130d0d0df3c 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -74,10 +74,10 @@ static void gfs2_put_super(struct super_block *sb) /* Unfreeze the filesystem, if we need to */ - down(&sdp->sd_freeze_lock); + mutex_lock(&sdp->sd_freeze_lock); if (sdp->sd_freeze_count) gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); - up(&sdp->sd_freeze_lock); + mutex_unlock(&sdp->sd_freeze_lock); kthread_stop(sdp->sd_inoded_process); kthread_stop(sdp->sd_quotad_process); diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 7b5573946f19..c0352cf330a3 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -251,10 +251,10 @@ static int bh_get(struct gfs2_quota_data *qd) struct buffer_head *bh; int error; - down(&sdp->sd_quota_mutex); + mutex_lock(&sdp->sd_quota_mutex); if (qd->qd_bh_count++) { - up(&sdp->sd_quota_mutex); + mutex_unlock(&sdp->sd_quota_mutex); return 0; } @@ -276,7 +276,7 @@ static int bh_get(struct gfs2_quota_data *qd) (bh->b_data + sizeof(struct gfs2_meta_header) + offset * sizeof(struct gfs2_quota_change)); - up(&sdp->sd_quota_mutex); + mutex_lock(&sdp->sd_quota_mutex); return 0; @@ -285,7 +285,7 @@ static int bh_get(struct gfs2_quota_data *qd) fail: qd->qd_bh_count--; - up(&sdp->sd_quota_mutex); + mutex_unlock(&sdp->sd_quota_mutex); return error; } @@ -293,14 +293,14 @@ static void bh_put(struct gfs2_quota_data *qd) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; - down(&sdp->sd_quota_mutex); + mutex_lock(&sdp->sd_quota_mutex); gfs2_assert(sdp, qd->qd_bh_count); if (!--qd->qd_bh_count) { brelse(qd->qd_bh); qd->qd_bh = NULL; qd->qd_bh_qc = NULL; } - up(&sdp->sd_quota_mutex); + mutex_unlock(&sdp->sd_quota_mutex); } static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp) @@ -529,7 +529,7 @@ static void do_qc(struct gfs2_quota_data *qd, int64_t change) struct gfs2_quota_change *qc = qd->qd_bh_qc; int64_t x; - down(&sdp->sd_quota_mutex); + mutex_lock(&sdp->sd_quota_mutex); gfs2_trans_add_bh(ip->i_gl, qd->qd_bh, 1); if (!test_bit(QDF_CHANGE, &qd->qd_flags)) { @@ -560,7 +560,7 @@ static void do_qc(struct gfs2_quota_data *qd, int64_t change) slot_hold(qd); } - up(&sdp->sd_quota_mutex); + mutex_unlock(&sdp->sd_quota_mutex); } /** diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 758cc565813a..2e69e5cda967 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -182,9 +182,9 @@ static void clear_rgrpdi(struct gfs2_sbd *sdp) void gfs2_clear_rgrpd(struct gfs2_sbd *sdp) { - down(&sdp->sd_rindex_mutex); + mutex_lock(&sdp->sd_rindex_mutex); clear_rgrpdi(sdp); - up(&sdp->sd_rindex_mutex); + mutex_unlock(&sdp->sd_rindex_mutex); } /** @@ -301,7 +301,7 @@ static int gfs2_ri_update(struct gfs2_inode *ip) if (!rgd) goto fail; - init_MUTEX(&rgd->rd_mutex); + mutex_init(&rgd->rd_mutex); lops_init_le(&rgd->rd_le, &gfs2_rg_lops); rgd->rd_sbd = sdp; @@ -363,13 +363,13 @@ int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh) /* Read new copy from disk if we don't have the latest */ if (sdp->sd_rindex_vn != gl->gl_vn) { - down(&sdp->sd_rindex_mutex); + mutex_lock(&sdp->sd_rindex_mutex); if (sdp->sd_rindex_vn != gl->gl_vn) { error = gfs2_ri_update(ip); if (error) gfs2_glock_dq_uninit(ri_gh); } - up(&sdp->sd_rindex_mutex); + mutex_unlock(&sdp->sd_rindex_mutex); } return error; @@ -394,13 +394,13 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd) unsigned int x, y; int error; - down(&rgd->rd_mutex); + mutex_lock(&rgd->rd_mutex); spin_lock(&sdp->sd_rindex_spin); if (rgd->rd_bh_count) { rgd->rd_bh_count++; spin_unlock(&sdp->sd_rindex_spin); - up(&rgd->rd_mutex); + mutex_unlock(&rgd->rd_mutex); return 0; } spin_unlock(&sdp->sd_rindex_spin); @@ -436,7 +436,7 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd) rgd->rd_bh_count++; spin_unlock(&sdp->sd_rindex_spin); - up(&rgd->rd_mutex); + mutex_unlock(&rgd->rd_mutex); return 0; @@ -447,7 +447,7 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd) bi->bi_bh = NULL; gfs2_assert_warn(sdp, !bi->bi_clone); } - up(&rgd->rd_mutex); + mutex_unlock(&rgd->rd_mutex); return error; } diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 9b5c31952c5d..be80771c414d 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -279,7 +279,7 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) name.name = buf; - down(&sdp->sd_jindex_mutex); + mutex_lock(&sdp->sd_jindex_mutex); for (;;) { error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, @@ -317,7 +317,7 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) spin_unlock(&sdp->sd_jindex_spin); } - up(&sdp->sd_jindex_mutex); + mutex_unlock(&sdp->sd_jindex_mutex); return error; } @@ -608,9 +608,9 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, if (error) return; - down(&sdp->sd_statfs_mutex); + mutex_lock(&sdp->sd_statfs_mutex); gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); - up(&sdp->sd_statfs_mutex); + mutex_unlock(&sdp->sd_statfs_mutex); spin_lock(&sdp->sd_statfs_spin); l_sc->sc_total += total; @@ -659,9 +659,9 @@ int gfs2_statfs_sync(struct gfs2_sbd *sdp) if (error) goto out_bh2; - down(&sdp->sd_statfs_mutex); + mutex_lock(&sdp->sd_statfs_mutex); gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); - up(&sdp->sd_statfs_mutex); + mutex_unlock(&sdp->sd_statfs_mutex); spin_lock(&sdp->sd_statfs_spin); m_sc->sc_total += l_sc->sc_total; @@ -910,7 +910,7 @@ int gfs2_freeze_fs(struct gfs2_sbd *sdp) { int error = 0; - down(&sdp->sd_freeze_lock); + mutex_lock(&sdp->sd_freeze_lock); if (!sdp->sd_freeze_count++) { error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh); @@ -918,7 +918,7 @@ int gfs2_freeze_fs(struct gfs2_sbd *sdp) sdp->sd_freeze_count--; } - up(&sdp->sd_freeze_lock); + mutex_unlock(&sdp->sd_freeze_lock); return error; } @@ -935,11 +935,11 @@ int gfs2_freeze_fs(struct gfs2_sbd *sdp) void gfs2_unfreeze_fs(struct gfs2_sbd *sdp) { - down(&sdp->sd_freeze_lock); + mutex_lock(&sdp->sd_freeze_lock); if (sdp->sd_freeze_count && !--sdp->sd_freeze_count) gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); - up(&sdp->sd_freeze_lock); + mutex_unlock(&sdp->sd_freeze_lock); } diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index 75e9a3231b8f..c5984351e4d8 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -41,9 +41,9 @@ static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) { unsigned int count; - down(&sdp->sd_freeze_lock); + mutex_lock(&sdp->sd_freeze_lock); count = sdp->sd_freeze_count; - up(&sdp->sd_freeze_lock); + mutex_unlock(&sdp->sd_freeze_lock); return sprintf(buf, "%u\n", count); } diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 104e664fa182..0a0ea70eac4c 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -33,7 +33,7 @@ int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, return -EINVAL; } - tr = kzalloc(sizeof(struct gfs2_trans), GFP_KERNEL); + tr = kzalloc(sizeof(struct gfs2_trans), GFP_NOFS); if (!tr) return -ENOMEM; @@ -51,7 +51,7 @@ int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, error = -ENOMEM; tr->tr_t_gh = gfs2_holder_get(sdp->sd_trans_gl, LM_ST_SHARED, - GL_NEVER_RECURSE, GFP_KERNEL); + GL_NEVER_RECURSE, GFP_NOFS); if (!tr->tr_t_gh) goto fail; diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c index 405b91b0295d..e92a3a11815b 100644 --- a/fs/gfs2/unlinked.c +++ b/fs/gfs2/unlinked.c @@ -46,12 +46,12 @@ static int munge_ondisk(struct gfs2_sbd *sdp, unsigned int slot, goto out; } - down(&sdp->sd_unlinked_mutex); + mutex_lock(&sdp->sd_unlinked_mutex); gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_unlinked_tag_out(ut, bh->b_data + sizeof(struct gfs2_meta_header) + offset * sizeof(struct gfs2_unlinked_tag)); - up(&sdp->sd_unlinked_mutex); + mutex_unlock(&sdp->sd_unlinked_mutex); out: brelse(bh); From 13538b8e46022b6a3721cda097fe3e0d91f16959 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 22 Feb 2006 11:15:03 +0000 Subject: [PATCH 043/292] [GFS2] Add list empty test to databuf_lo_add Heinz had spotted that I'd forgotten to test in databuf_lo_add() that the data buffer in question hadn't already been added to the list. This was causing an infinite loop later on in the "before commit" routine. This means that GFS2 is now ready to be tested by everybody. Signed-off-by: Steven Whitehouse --- fs/gfs2/lops.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 5e7e7d91fc5e..ef39fb2e7234 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -291,7 +291,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp) while (!list_empty(head)) { rv = list_entry(head->next, struct gfs2_revoke, rv_le.le_list); - list_del(&rv->rv_le.le_list); + list_del_init(&rv->rv_le.le_list); sdp->sd_log_num_revoke--; if (offset + sizeof(uint64_t) > sdp->sd_sb.sb_bsize) { @@ -460,10 +460,12 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) gfs2_pin(sdp, bd->bd_bh); } gfs2_log_lock(sdp); - if (ip->i_di.di_flags & GFS2_DIF_JDATA) - sdp->sd_log_num_jdata++; - sdp->sd_log_num_databuf++; - list_add(&le->le_list, &sdp->sd_log_le_databuf); + if (!list_empty(&le->le_list)) { + if (ip->i_di.di_flags & GFS2_DIF_JDATA) + sdp->sd_log_num_jdata++; + sdp->sd_log_num_databuf++; + list_add(&le->le_list, &sdp->sd_log_le_databuf); + } gfs2_log_unlock(sdp); } @@ -503,25 +505,21 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) unsigned int total_jdata = sdp->sd_log_num_jdata; unsigned int num, n; __be64 *ptr = NULL; - unsigned i; offset += (2*sizeof(__be64) - 1); offset &= ~(2*sizeof(__be64) - 1); limit = (sdp->sd_sb.sb_bsize - offset)/sizeof(__be64); - /* printk(KERN_INFO "totals: jdata=%u dbuf=%u\n", total_jdata, total_dbuf); */ /* * Start writing ordered buffers, write journaled buffers * into the log along with a header */ gfs2_log_lock(sdp); - /* printk(KERN_INFO "locked in lops databuf_before_commit\n"); */ bd2 = bd1 = list_prepare_entry(bd1, &sdp->sd_log_le_databuf, bd_le.le_list); while(total_dbuf) { num = total_jdata; if (num > limit) num = limit; - /* printk(KERN_INFO "total_dbuf=%u num=%u\n", total_dbuf, num); */ n = 0; i = 0; list_for_each_entry_safe_continue(bd1, bdt, &sdp->sd_log_le_databuf, bd_le.le_list) { @@ -542,21 +540,12 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) gfs2_log_lock(sdp); } brelse(bd1->bd_bh); - /* printk(KERN_INFO "db write %p\n", bd1); */ - if (++i > 100000) { - printk(KERN_INFO "looping bd1=%p bdt=%p eol=%p started=%p\n", bd1, bdt, &sdp->sd_log_le_databuf, &started); - dump_stack(); - BUG(); - } continue; } - /* printk(KERN_INFO "db skip\n"); */ continue; } else if (bd1->bd_bh) { /* A journaled buffer */ int magic; gfs2_log_unlock(sdp); - printk(KERN_INFO "journaled buffer %p\n", bd1->bd_bh); - printk(KERN_INFO "%lu %u %p %p\n", bd1->bd_bh->b_blocknr, bd1->bd_bh->b_size, bd1->bd_bh->b_data, bd1->bd_bh->b_page); if (!bh) { bh = gfs2_log_get_buf(sdp); ld = (struct gfs2_log_descriptor *)bh->b_data; @@ -570,12 +559,9 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) ld->ld_data2 = cpu_to_be32(0); memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved)); } - /* printk(KERN_INFO "check_magic\n"); */ magic = gfs2_check_magic(bd1->bd_bh); - /* printk(KERN_INFO "write data\n"); */ *ptr++ = cpu_to_be64(bd1->bd_bh->b_blocknr); *ptr++ = cpu_to_be64((__u64)magic); - /* printk(KERN_INFO "mark escaped or not\n"); */ clear_buffer_escaped(bd1->bd_bh); if (unlikely(magic != 0)) set_buffer_escaped(bd1->bd_bh); @@ -591,7 +577,6 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) bh = NULL; } n = 0; - /* printk(KERN_INFO "totals2: jdata=%u dbuf=%u\n", total_jdata, total_dbuf); */ gfs2_log_lock(sdp); list_for_each_entry_continue(bd2, &sdp->sd_log_le_databuf, bd_le.le_list) { if (!bd2->bd_bh) @@ -621,14 +606,13 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) } gfs2_log_unlock(sdp); - /* printk(KERN_INFO "wait on ordered data buffers\n"); */ /* Wait on all ordered buffers */ while (!list_empty(&started)) { + gfs2_log_lock(sdp); bd1 = list_entry(started.next, struct gfs2_bufdata, bd_le.le_list); list_del(&bd1->bd_le.le_list); sdp->sd_log_num_databuf--; - gfs2_log_lock(sdp); bh = bd1->bd_bh; if (bh) { set_v2bd(bh, NULL); @@ -641,7 +625,6 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) kfree(bd1); } - /* printk(KERN_INFO "sd_log_num_databuf %u sd_log_num_jdata %u\n", sdp->sd_log_num_databuf, sdp->sd_log_num_jdata); */ /* We've removed all the ordered write bufs here, so only jdata left */ gfs2_assert_warn(sdp, sdp->sd_log_num_databuf == sdp->sd_log_num_jdata); } From 91ffd7db71e7451f89941a8f428b4daa2a7c1e38 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 22 Feb 2006 16:41:45 +0000 Subject: [PATCH 044/292] [GFS2] Missed deletion of debugging code One line which should have been deleted in the last patch was missed. Signed-off-by: Steven Whitehouse --- fs/gfs2/lops.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index ef39fb2e7234..3d792f81e48c 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -521,7 +521,6 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) if (num > limit) num = limit; n = 0; - i = 0; list_for_each_entry_safe_continue(bd1, bdt, &sdp->sd_log_le_databuf, bd_le.le_list) { /* An ordered write buffer */ if (bd1->bd_bh && !buffer_pinned(bd1->bd_bh)) { From 3bcd3687f895f178fa8480a7bcc47a363817354a Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 23 Feb 2006 09:56:38 +0000 Subject: [PATCH 045/292] [DLM] Remove range locks from the DLM This patch removes support for range locking from the DLM Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/debug_fs.c | 14 ----- fs/dlm/device.c | 6 +-- fs/dlm/dlm_internal.h | 12 ----- fs/dlm/lock.c | 103 ++++--------------------------------- fs/dlm/memory.c | 16 ------ fs/dlm/memory.h | 2 - fs/dlm/rcom.c | 3 -- fs/dlm/util.c | 12 ----- include/linux/dlm.h | 12 +---- include/linux/dlm_device.h | 3 +- 10 files changed, 13 insertions(+), 170 deletions(-) diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index 5080bbffd586..49deca845dba 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -59,20 +59,6 @@ static void print_lock(struct seq_file *s, struct dlm_lkb *lkb, || lkb->lkb_status == DLM_LKSTS_WAITING) seq_printf(s, " (%s)", print_lockmode(lkb->lkb_rqmode)); - if (lkb->lkb_range) { - /* FIXME: this warns on Alpha */ - if (lkb->lkb_status == DLM_LKSTS_CONVERT - || lkb->lkb_status == DLM_LKSTS_GRANTED) - seq_printf(s, " %llx-%llx", - lkb->lkb_range[GR_RANGE_START], - lkb->lkb_range[GR_RANGE_END]); - if (lkb->lkb_status == DLM_LKSTS_CONVERT - || lkb->lkb_status == DLM_LKSTS_WAITING) - seq_printf(s, " (%llx-%llx)", - lkb->lkb_range[RQ_RANGE_START], - lkb->lkb_range[RQ_RANGE_END]); - } - if (lkb->lkb_nodeid) { if (lkb->lkb_nodeid != res->res_nodeid) seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid, diff --git a/fs/dlm/device.c b/fs/dlm/device.c index 899d4f92a4d7..99d8b6b07fba 100644 --- a/fs/dlm/device.c +++ b/fs/dlm/device.c @@ -532,8 +532,7 @@ static int dlm_close(struct inode *inode, struct file *file) status = dlm_lock(f->fi_ls->ls_lockspace, old_li->li_grmode, &li.li_lksb, DLM_LKF_CONVERT|DLM_LKF_ORPHAN, - NULL, 0, 0, ast_routine, NULL, - NULL, NULL); + NULL, 0, 0, ast_routine, NULL, NULL); if (status != 0) printk("dlm: Error orphaning lock %x: %d\n", old_li->li_lksb.sb_lkid, status); @@ -878,8 +877,7 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, ast_routine, li, (li->li_pend_bastaddr || li->li_bastaddr) ? - bast_routine : NULL, - kparams->range.ra_end ? &kparams->range : NULL); + bast_routine : NULL); if (status) goto out_err; diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index 16f20cfd9197..c3299020c8f3 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -146,7 +146,6 @@ struct dlm_args { void *bastaddr; int mode; struct dlm_lksb *lksb; - struct dlm_range *range; }; @@ -195,13 +194,6 @@ struct dlm_args { #define AST_COMP 1 #define AST_BAST 2 -/* lkb_range[] */ - -#define GR_RANGE_START 0 -#define GR_RANGE_END 1 -#define RQ_RANGE_START 2 -#define RQ_RANGE_END 3 - /* lkb_status */ #define DLM_LKSTS_WAITING 1 @@ -212,7 +204,6 @@ struct dlm_args { #define DLM_IFL_MSTCPY 0x00010000 #define DLM_IFL_RESEND 0x00020000 -#define DLM_IFL_RANGE 0x00000001 struct dlm_lkb { struct dlm_rsb *lkb_resource; /* the rsb */ @@ -241,7 +232,6 @@ struct dlm_lkb { struct list_head lkb_wait_reply; /* waiting for remote reply */ struct list_head lkb_astqueue; /* need ast to be sent */ - uint64_t *lkb_range; /* array of gr/rq ranges */ char *lkb_lvbptr; struct dlm_lksb *lkb_lksb; /* caller's status block */ void *lkb_astaddr; /* caller's ast function */ @@ -360,7 +350,6 @@ struct dlm_message { int m_bastmode; int m_asts; int m_result; /* 0 or -EXXX */ - uint64_t m_range[2]; char m_extra[0]; /* name or lvb */ }; @@ -413,7 +402,6 @@ struct rcom_lock { int8_t rl_asts; uint16_t rl_wait_type; uint16_t rl_namelen; - uint64_t rl_range[4]; char rl_name[DLM_RESNAME_MAXLEN]; char rl_lvb[0]; }; diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 29d3b95dbb63..80487703d582 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -606,8 +606,6 @@ static int put_lkb(struct dlm_lkb *lkb) /* for local/process lkbs, lvbptr points to caller's lksb */ if (lkb->lkb_lvbptr && is_master_copy(lkb)) free_lvb(lkb->lkb_lvbptr); - if (lkb->lkb_range) - free_range(lkb->lkb_range); free_lkb(lkb); return 1; } else { @@ -988,11 +986,6 @@ static void _grant_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) } lkb->lkb_rqmode = DLM_LOCK_IV; - - if (lkb->lkb_range) { - lkb->lkb_range[GR_RANGE_START] = lkb->lkb_range[RQ_RANGE_START]; - lkb->lkb_range[GR_RANGE_END] = lkb->lkb_range[RQ_RANGE_END]; - } } static void grant_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) @@ -1032,21 +1025,6 @@ static inline int first_in_list(struct dlm_lkb *lkb, struct list_head *head) return 0; } -/* Return 1 if the locks' ranges overlap. If the lkb has no range then it is - assumed to cover 0-ffffffff.ffffffff */ - -static inline int ranges_overlap(struct dlm_lkb *lkb1, struct dlm_lkb *lkb2) -{ - if (!lkb1->lkb_range || !lkb2->lkb_range) - return 1; - - if (lkb1->lkb_range[RQ_RANGE_END] < lkb2->lkb_range[GR_RANGE_START] || - lkb1->lkb_range[RQ_RANGE_START] > lkb2->lkb_range[GR_RANGE_END]) - return 0; - - return 1; -} - /* Check if the given lkb conflicts with another lkb on the queue. */ static int queue_conflict(struct list_head *head, struct dlm_lkb *lkb) @@ -1056,7 +1034,7 @@ static int queue_conflict(struct list_head *head, struct dlm_lkb *lkb) list_for_each_entry(this, head, lkb_statequeue) { if (this == lkb) continue; - if (ranges_overlap(lkb, this) && !modes_compat(this, lkb)) + if (!modes_compat(this, lkb)) return 1; } return 0; @@ -1099,9 +1077,6 @@ static int conversion_deadlock_detect(struct dlm_rsb *rsb, struct dlm_lkb *lkb) continue; } - if (!ranges_overlap(lkb, this)) - continue; - if (!modes_compat(this, lkb) && !modes_compat(lkb, this)) return 1; } @@ -1203,8 +1178,8 @@ static int _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, int now) return 1; /* - * When using range locks the NOORDER flag is set to avoid the standard - * vms rules on grant order. + * The NOORDER flag is set to avoid the standard vms rules on grant + * order. */ if (lkb->lkb_exflags & DLM_LKF_NOORDER) @@ -1358,8 +1333,7 @@ static void grant_pending_locks(struct dlm_rsb *r) /* * If there are locks left on the wait/convert queue then send blocking * ASTs to granted locks based on the largest requested mode (high) - * found above. This can generate spurious blocking ASTs for range - * locks. FIXME: highbast < high comparison not valid for PR/CW. + * found above. FIXME: highbast < high comparison not valid for PR/CW. */ list_for_each_entry_safe(lkb, s, &r->res_grantqueue, lkb_statequeue) { @@ -1379,7 +1353,7 @@ static void send_bast_queue(struct dlm_rsb *r, struct list_head *head, list_for_each_entry(gr, head, lkb_statequeue) { if (gr->lkb_bastaddr && gr->lkb_highbast < lkb->lkb_rqmode && - ranges_overlap(lkb, gr) && !modes_compat(gr, lkb)) { + !modes_compat(gr, lkb)) { queue_bast(r, gr, lkb->lkb_rqmode); gr->lkb_highbast = lkb->lkb_rqmode; } @@ -1530,8 +1504,7 @@ static void confirm_master(struct dlm_rsb *r, int error) static int set_lock_args(int mode, struct dlm_lksb *lksb, uint32_t flags, int namelen, uint32_t parent_lkid, void *ast, - void *astarg, void *bast, struct dlm_range *range, - struct dlm_args *args) + void *astarg, void *bast, struct dlm_args *args) { int rv = -EINVAL; @@ -1590,7 +1563,6 @@ static int set_lock_args(int mode, struct dlm_lksb *lksb, uint32_t flags, args->bastaddr = bast; args->mode = mode; args->lksb = lksb; - args->range = range; rv = 0; out: return rv; @@ -1637,26 +1609,6 @@ static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, lkb->lkb_lksb = args->lksb; lkb->lkb_lvbptr = args->lksb->sb_lvbptr; lkb->lkb_ownpid = (int) current->pid; - - rv = 0; - if (!args->range) - goto out; - - if (!lkb->lkb_range) { - rv = -ENOMEM; - lkb->lkb_range = allocate_range(ls); - if (!lkb->lkb_range) - goto out; - /* This is needed for conversions that contain ranges - where the original lock didn't but it's harmless for - new locks too. */ - lkb->lkb_range[GR_RANGE_START] = 0LL; - lkb->lkb_range[GR_RANGE_END] = 0xffffffffffffffffULL; - } - - lkb->lkb_range[RQ_RANGE_START] = args->range->ra_start; - lkb->lkb_range[RQ_RANGE_END] = args->range->ra_end; - lkb->lkb_flags |= DLM_IFL_RANGE; rv = 0; out: return rv; @@ -1805,7 +1757,7 @@ static int _request_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) return error; } -/* change some property of an existing lkb, e.g. mode, range */ +/* change some property of an existing lkb, e.g. mode */ static int _convert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) { @@ -1962,8 +1914,7 @@ int dlm_lock(dlm_lockspace_t *lockspace, uint32_t parent_lkid, void (*ast) (void *astarg), void *astarg, - void (*bast) (void *astarg, int mode), - struct dlm_range *range) + void (*bast) (void *astarg, int mode)) { struct dlm_ls *ls; struct dlm_lkb *lkb; @@ -1985,7 +1936,7 @@ int dlm_lock(dlm_lockspace_t *lockspace, goto out; error = set_lock_args(mode, lksb, flags, namelen, parent_lkid, ast, - astarg, bast, range, &args); + astarg, bast, &args); if (error) goto out_put; @@ -2154,11 +2105,6 @@ static void send_args(struct dlm_rsb *r, struct dlm_lkb *lkb, if (lkb->lkb_astaddr) ms->m_asts |= AST_COMP; - if (lkb->lkb_range) { - ms->m_range[0] = lkb->lkb_range[RQ_RANGE_START]; - ms->m_range[1] = lkb->lkb_range[RQ_RANGE_END]; - } - if (ms->m_type == DLM_MSG_REQUEST || ms->m_type == DLM_MSG_LOOKUP) memcpy(ms->m_extra, r->res_name, r->res_length); @@ -2402,20 +2348,6 @@ static int receive_extralen(struct dlm_message *ms) return (ms->m_header.h_length - sizeof(struct dlm_message)); } -static int receive_range(struct dlm_ls *ls, struct dlm_lkb *lkb, - struct dlm_message *ms) -{ - if (lkb->lkb_flags & DLM_IFL_RANGE) { - if (!lkb->lkb_range) - lkb->lkb_range = allocate_range(ls); - if (!lkb->lkb_range) - return -ENOMEM; - lkb->lkb_range[RQ_RANGE_START] = ms->m_range[0]; - lkb->lkb_range[RQ_RANGE_END] = ms->m_range[1]; - } - return 0; -} - static int receive_lvb(struct dlm_ls *ls, struct dlm_lkb *lkb, struct dlm_message *ms) { @@ -2445,9 +2377,6 @@ static int receive_request_args(struct dlm_ls *ls, struct dlm_lkb *lkb, DLM_ASSERT(is_master_copy(lkb), dlm_print_lkb(lkb);); - if (receive_range(ls, lkb, ms)) - return -ENOMEM; - if (receive_lvb(ls, lkb, ms)) return -ENOMEM; @@ -2470,13 +2399,6 @@ static int receive_convert_args(struct dlm_ls *ls, struct dlm_lkb *lkb, if (lkb->lkb_status != DLM_LKSTS_GRANTED) return -EBUSY; - if (receive_range(ls, lkb, ms)) - return -ENOMEM; - if (lkb->lkb_range) { - lkb->lkb_range[GR_RANGE_START] = 0LL; - lkb->lkb_range[GR_RANGE_END] = 0xffffffffffffffffULL; - } - if (receive_lvb(ls, lkb, ms)) return -ENOMEM; @@ -3476,13 +3398,6 @@ static int receive_rcom_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, lkb->lkb_bastaddr = (void *) (long) (rl->rl_asts & AST_BAST); lkb->lkb_astaddr = (void *) (long) (rl->rl_asts & AST_COMP); - if (lkb->lkb_flags & DLM_IFL_RANGE) { - lkb->lkb_range = allocate_range(ls); - if (!lkb->lkb_range) - return -ENOMEM; - memcpy(lkb->lkb_range, rl->rl_range, 4*sizeof(uint64_t)); - } - if (lkb->lkb_exflags & DLM_LKF_VALBLK) { lkb->lkb_lvbptr = allocate_lvb(ls); if (!lkb->lkb_lvbptr) diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c index 0b9851d0bdb2..f7cf4589fae8 100644 --- a/fs/dlm/memory.c +++ b/fs/dlm/memory.c @@ -50,22 +50,6 @@ void free_lvb(char *p) kfree(p); } -uint64_t *allocate_range(struct dlm_ls *ls) -{ - int ralen = 4*sizeof(uint64_t); - uint64_t *p; - - p = kmalloc(ralen, GFP_KERNEL); - if (p) - memset(p, 0, ralen); - return p; -} - -void free_range(uint64_t *p) -{ - kfree(p); -} - /* FIXME: have some minimal space built-in to rsb for the name and kmalloc a separate name if needed, like dentries are done */ diff --git a/fs/dlm/memory.h b/fs/dlm/memory.h index 7b235132b0b4..6ead158ccc5c 100644 --- a/fs/dlm/memory.h +++ b/fs/dlm/memory.h @@ -24,8 +24,6 @@ struct dlm_direntry *allocate_direntry(struct dlm_ls *ls, int namelen); void free_direntry(struct dlm_direntry *de); char *allocate_lvb(struct dlm_ls *ls); void free_lvb(char *l); -uint64_t *allocate_range(struct dlm_ls *ls); -void free_range(uint64_t *l); #endif /* __MEMORY_DOT_H__ */ diff --git a/fs/dlm/rcom.c b/fs/dlm/rcom.c index 4c5c08a8860e..55fbe313340e 100644 --- a/fs/dlm/rcom.c +++ b/fs/dlm/rcom.c @@ -284,9 +284,6 @@ static void pack_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb, if (lkb->lkb_astaddr) rl->rl_asts |= AST_COMP; - if (lkb->lkb_range) - memcpy(rl->rl_range, lkb->lkb_range, 4*sizeof(uint64_t)); - rl->rl_namelen = r->res_length; memcpy(rl->rl_name, r->res_name, r->res_length); diff --git a/fs/dlm/util.c b/fs/dlm/util.c index 826d122edf55..767197db9944 100644 --- a/fs/dlm/util.c +++ b/fs/dlm/util.c @@ -54,8 +54,6 @@ void dlm_message_out(struct dlm_message *ms) ms->m_bastmode = cpu_to_le32(ms->m_bastmode); ms->m_asts = cpu_to_le32(ms->m_asts); ms->m_result = cpu_to_le32(ms->m_result); - ms->m_range[0] = cpu_to_le64(ms->m_range[0]); - ms->m_range[1] = cpu_to_le64(ms->m_range[1]); } void dlm_message_in(struct dlm_message *ms) @@ -82,8 +80,6 @@ void dlm_message_in(struct dlm_message *ms) ms->m_bastmode = le32_to_cpu(ms->m_bastmode); ms->m_asts = le32_to_cpu(ms->m_asts); ms->m_result = le32_to_cpu(ms->m_result); - ms->m_range[0] = le64_to_cpu(ms->m_range[0]); - ms->m_range[1] = le64_to_cpu(ms->m_range[1]); } static void rcom_lock_out(struct rcom_lock *rl) @@ -99,10 +95,6 @@ static void rcom_lock_out(struct rcom_lock *rl) rl->rl_result = cpu_to_le32(rl->rl_result); rl->rl_wait_type = cpu_to_le16(rl->rl_wait_type); rl->rl_namelen = cpu_to_le16(rl->rl_namelen); - rl->rl_range[0] = cpu_to_le64(rl->rl_range[0]); - rl->rl_range[1] = cpu_to_le64(rl->rl_range[1]); - rl->rl_range[2] = cpu_to_le64(rl->rl_range[2]); - rl->rl_range[3] = cpu_to_le64(rl->rl_range[3]); } static void rcom_lock_in(struct rcom_lock *rl) @@ -118,10 +110,6 @@ static void rcom_lock_in(struct rcom_lock *rl) rl->rl_result = le32_to_cpu(rl->rl_result); rl->rl_wait_type = le16_to_cpu(rl->rl_wait_type); rl->rl_namelen = le16_to_cpu(rl->rl_namelen); - rl->rl_range[0] = le64_to_cpu(rl->rl_range[0]); - rl->rl_range[1] = le64_to_cpu(rl->rl_range[1]); - rl->rl_range[2] = le64_to_cpu(rl->rl_range[2]); - rl->rl_range[3] = le64_to_cpu(rl->rl_range[3]); } static void rcom_config_out(struct rcom_config *rf) diff --git a/include/linux/dlm.h b/include/linux/dlm.h index dd324ba44d80..1b1dcb9a40bb 100644 --- a/include/linux/dlm.h +++ b/include/linux/dlm.h @@ -159,15 +159,6 @@ typedef void dlm_lockspace_t; -/* - * Lock range structure - */ - -struct dlm_range { - uint64_t ra_start; - uint64_t ra_end; -}; - /* * Lock status block * @@ -277,8 +268,7 @@ int dlm_lock(dlm_lockspace_t *lockspace, uint32_t parent_lkid, void (*lockast) (void *astarg), void *astarg, - void (*bast) (void *astarg, int mode), - struct dlm_range *range); + void (*bast) (void *astarg, int mode)); /* * dlm_unlock diff --git a/include/linux/dlm_device.h b/include/linux/dlm_device.h index 5e17d295544b..f8ba1981aa96 100644 --- a/include/linux/dlm_device.h +++ b/include/linux/dlm_device.h @@ -18,7 +18,7 @@ #define DLM_USER_LVB_LEN 32 /* Version of the device interface */ -#define DLM_DEVICE_VERSION_MAJOR 3 +#define DLM_DEVICE_VERSION_MAJOR 4 #define DLM_DEVICE_VERSION_MINOR 0 #define DLM_DEVICE_VERSION_PATCH 0 @@ -28,7 +28,6 @@ struct dlm_lock_params { __u16 flags; __u32 lkid; __u32 parent; - struct dlm_range range; __u8 namelen; void __user *castparam; void __user *castaddr; From 8d3b35a4af87965d1873872b21e504558f62116a Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 23 Feb 2006 10:00:56 +0000 Subject: [PATCH 046/292] [DLM] Remove support for range locks (II) This is the second of two patches removing support for range locks from the DLM Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/lock.c | 10 +++++----- fs/gfs2/locking/dlm/lock_dlm.h | 2 +- fs/gfs2/locking/dlm/thread.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index d799865b64a4..666d696dc8ce 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -223,7 +223,7 @@ void gdlm_put_lock(lm_lock_t *lock) gdlm_delete_lp((struct gdlm_lock *) lock); } -unsigned int gdlm_do_lock(struct gdlm_lock *lp, struct dlm_range *range) +unsigned int gdlm_do_lock(struct gdlm_lock *lp) { struct gdlm_ls *ls = lp->ls; struct gdlm_strname str; @@ -258,7 +258,7 @@ unsigned int gdlm_do_lock(struct gdlm_lock *lp, struct dlm_range *range) error = dlm_lock(ls->dlm_lockspace, lp->req, &lp->lksb, lp->lkf, str.name, str.namelen, 0, gdlm_ast, (void *) lp, - bast ? gdlm_bast : NULL, range); + bast ? gdlm_bast : NULL); if ((error == -EAGAIN) && (lp->lkf & DLM_LKF_NOQUEUE)) { lp->lksb.sb_status = -EAGAIN; @@ -316,7 +316,7 @@ unsigned int gdlm_lock(lm_lock_t *lock, unsigned int cur_state, lp->req = make_mode(req_state); lp->lkf = make_flags(lp, flags, lp->cur, lp->req); - return gdlm_do_lock(lp, NULL); + return gdlm_do_lock(lp); } unsigned int gdlm_unlock(lm_lock_t *lock, unsigned int cur_state) @@ -425,7 +425,7 @@ static int hold_null_lock(struct gdlm_lock *lp) set_bit(LFL_INLOCK, &lpn->flags); init_completion(&lpn->ast_wait); - gdlm_do_lock(lpn, NULL); + gdlm_do_lock(lpn); wait_for_completion(&lpn->ast_wait); error = lp->lksb.sb_status; if (error) { @@ -499,7 +499,7 @@ void gdlm_sync_lvb(lm_lock_t *lock, char *lvb) lp->req = DLM_LOCK_EX; lp->lkf = make_flags(lp, 0, lp->cur, lp->req); - gdlm_do_lock(lp, NULL); + gdlm_do_lock(lp); wait_for_completion(&lp->ast_wait); } diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h index fa545f7872e8..6d76146953ce 100644 --- a/fs/gfs2/locking/dlm/lock_dlm.h +++ b/fs/gfs2/locking/dlm/lock_dlm.h @@ -165,7 +165,7 @@ int gdlm_create_lp(struct gdlm_ls *, struct lm_lockname *, struct gdlm_lock **); void gdlm_delete_lp(struct gdlm_lock *); int gdlm_add_lvb(struct gdlm_lock *); void gdlm_del_lvb(struct gdlm_lock *); -unsigned int gdlm_do_lock(struct gdlm_lock *, struct dlm_range *); +unsigned int gdlm_do_lock(struct gdlm_lock *); unsigned int gdlm_do_unlock(struct gdlm_lock *); int gdlm_get_lock(lm_lockspace_t *, struct lm_lockname *, lm_lock_t **); diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c index 6fe669cd334b..3e2edcc2dbf6 100644 --- a/fs/gfs2/locking/dlm/thread.c +++ b/fs/gfs2/locking/dlm/thread.c @@ -308,7 +308,7 @@ static int gdlm_thread(void *data) process_blocking(lp, blocking); else if (submit) - gdlm_do_lock(lp, NULL); + gdlm_do_lock(lp); if (drop) ls->fscb(ls->fsdata, LM_CB_DROPLOCKS, NULL); From 6a6b3d018f4781f108d170f2181281a3c5589dc8 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 23 Feb 2006 10:11:47 +0000 Subject: [PATCH 047/292] [GFS2] Patch to remove stats gathering from GFS2 Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 23 ++------------ fs/gfs2/incore.h | 20 ------------ fs/gfs2/log.c | 4 --- fs/gfs2/meta_io.c | 3 -- fs/gfs2/ops_address.c | 12 ------- fs/gfs2/ops_dentry.c | 2 -- fs/gfs2/ops_export.c | 12 ------- fs/gfs2/ops_file.c | 29 ++--------------- fs/gfs2/ops_inode.c | 36 --------------------- fs/gfs2/ops_super.c | 17 ---------- fs/gfs2/ops_vm.c | 4 --- fs/gfs2/sys.c | 74 ++++--------------------------------------- 12 files changed, 10 insertions(+), 226 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 4df78ecfeeb3..cf1dc17faf4f 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -106,8 +106,6 @@ static void glock_free(struct gfs2_glock *gl) gfs2_aspace_put(aspace); kmem_cache_free(gfs2_glock_cachep, gl); - - atomic_dec(&sdp->sd_glock_count); } /** @@ -316,8 +314,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, if (error) goto fail_aspace; - atomic_inc(&sdp->sd_glock_count); - write_lock(&bucket->hb_lock); tmp = search_bucket(bucket, &name); if (tmp) { @@ -836,13 +832,10 @@ static void state_change(struct gfs2_glock *gl, unsigned int new_state) held2 = (new_state != LM_ST_UNLOCKED); if (held1 != held2) { - if (held2) { - atomic_inc(&sdp->sd_glock_held_count); + if (held2) gfs2_glock_hold(gl); - } else { - atomic_dec(&sdp->sd_glock_held_count); + else gfs2_glock_put(gl); - } } gl->gl_state = new_state; @@ -994,8 +987,6 @@ void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags) gfs2_glock_hold(gl); gl->gl_req_bh = xmote_bh; - atomic_inc(&sdp->sd_lm_lock_calls); - lck_ret = gfs2_lm_lock(sdp, gl->gl_lock, gl->gl_state, state, lck_flags); @@ -1087,8 +1078,6 @@ void gfs2_glock_drop_th(struct gfs2_glock *gl) gfs2_glock_hold(gl); gl->gl_req_bh = drop_bh; - atomic_inc(&sdp->sd_lm_unlock_calls); - ret = gfs2_lm_unlock(sdp, gl->gl_lock, gl->gl_state); if (gfs2_assert_withdraw(sdp, !(ret & LM_OUT_ERROR))) @@ -1313,8 +1302,6 @@ int gfs2_glock_nq(struct gfs2_holder *gh) struct gfs2_sbd *sdp = gl->gl_sbd; int error = 0; - atomic_inc(&sdp->sd_glock_nq_calls); - restart: if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) { set_bit(HIF_ABORTED, &gh->gh_iflags); @@ -1406,8 +1393,6 @@ void gfs2_glock_dq(struct gfs2_holder *gh) struct gfs2_sbd *sdp = gl->gl_sbd; struct gfs2_glock_operations *glops = gl->gl_ops; - atomic_inc(&sdp->sd_glock_dq_calls); - if (gh->gh_flags & GL_SYNC) set_bit(GLF_SYNC, &gl->gl_flags); @@ -1469,8 +1454,6 @@ void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, int flags) spin_unlock(&gl->gl_spin); glops->go_xmote_th(gl, state, flags); - - atomic_inc(&gl->gl_sbd->sd_glock_prefetch_calls); } /** @@ -1916,8 +1899,6 @@ void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data) { struct gfs2_sbd *sdp = (struct gfs2_sbd *)fsdata; - atomic_inc(&sdp->sd_lm_callbacks); - switch (type) { case LM_CB_NEED_E: blocking_cb(sdp, (struct lm_lockname *)data, LM_ST_UNLOCKED); diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 7fe422537ff0..0e550e8e5be3 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -667,27 +667,7 @@ struct gfs2_sbd { atomic_t sd_glock_count; atomic_t sd_glock_held_count; atomic_t sd_inode_count; - atomic_t sd_bufdata_count; - - atomic_t sd_fh2dentry_misses; atomic_t sd_reclaimed; - atomic_t sd_log_flush_incore; - atomic_t sd_log_flush_ondisk; - - atomic_t sd_glock_nq_calls; - atomic_t sd_glock_dq_calls; - atomic_t sd_glock_prefetch_calls; - atomic_t sd_lm_lock_calls; - atomic_t sd_lm_unlock_calls; - atomic_t sd_lm_callbacks; - - atomic_t sd_ops_address; - atomic_t sd_ops_dentry; - atomic_t sd_ops_export; - atomic_t sd_ops_file; - atomic_t sd_ops_inode; - atomic_t sd_ops_super; - atomic_t sd_ops_vm; char sd_fsname[GFS2_FSNAME_LEN]; char sd_table_name[GFS2_FSNAME_LEN]; diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index e6acb41332e7..2483f0c2c50e 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -408,8 +408,6 @@ static void log_write_header(struct gfs2_sbd *sdp, uint32_t flags, int pull) unsigned int tail; uint32_t hash; - atomic_inc(&sdp->sd_log_flush_ondisk); - bh = sb_getblk(sdp->sd_vfs, blkno); lock_buffer(bh); memset(bh->b_data, 0, bh->b_size); @@ -488,8 +486,6 @@ void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) { struct gfs2_ail *ai; - atomic_inc(&sdp->sd_log_flush_incore); - ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); INIT_LIST_HEAD(&ai->ai_ail1_list); INIT_LIST_HEAD(&ai->ai_ail2_list); diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 8fba84306755..f4c4dfbf6986 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -146,7 +146,6 @@ static int gfs2_aspace_releasepage(struct page *page, gfp_t gfp_mask) gfs2_assert_warn(sdp, list_empty(&bd->bd_le.le_list)); gfs2_assert_warn(sdp, !bd->bd_ail); kmem_cache_free(gfs2_bufdata_cachep, bd); - atomic_dec(&sdp->sd_bufdata_count); set_v2bd(bh, NULL); } @@ -557,8 +556,6 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta } bd = kmem_cache_alloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL), - atomic_inc(&gl->gl_sbd->sd_bufdata_count); - memset(bd, 0, sizeof(struct gfs2_bufdata)); bd->bd_bh = bh; diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index c719a2a40698..8f839120a473 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -166,7 +166,6 @@ static int gfs2_writepage(struct page *page, struct writeback_control *wbc) int error; int done_trans = 0; - atomic_inc(&sdp->sd_ops_address); if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(ip->i_gl))) { unlock_page(page); return -EIO; @@ -265,8 +264,6 @@ static int gfs2_readpage(struct file *file, struct page *page) struct gfs2_holder gh; int error; - atomic_inc(&sdp->sd_ops_address); - if (file != &gfs2_internal_file_sentinal) { gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); error = gfs2_glock_nq_m_atime(1, &gh); @@ -319,8 +316,6 @@ static int gfs2_prepare_write(struct file *file, struct page *page, loff_t end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to; struct gfs2_alloc *al; - atomic_inc(&sdp->sd_ops_address); - gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ATIME, &ip->i_gh); error = gfs2_glock_nq_m_atime(1, &ip->i_gh); if (error) @@ -412,9 +407,6 @@ static int gfs2_commit_write(struct file *file, struct page *page, struct buffer_head *dibh; struct gfs2_alloc *al = &ip->i_alloc;; - atomic_inc(&sdp->sd_ops_address); - - if (gfs2_assert_withdraw(sdp, gfs2_glock_is_locked_by_me(ip->i_gl))) goto fail_nounlock; @@ -493,8 +485,6 @@ static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock) sector_t dblock = 0; int error; - atomic_inc(&ip->i_sbd->sd_ops_address); - error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); if (error) return 0; @@ -615,8 +605,6 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, struct gfs2_inode *ip = get_v2ip(inode); struct gfs2_sbd *sdp = ip->i_sbd; - atomic_inc(&sdp->sd_ops_address); - if (rw == WRITE) return gfs2_direct_IO_write(iocb, iov, offset, nr_segs); diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index 5c618611c11b..fb8f70d225b9 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -45,8 +45,6 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) lock_kernel(); - atomic_inc(&sdp->sd_ops_dentry); - inode = dentry->d_inode; if (inode && is_bad_inode(inode)) goto invalid; diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index 8389f771d28b..611252b7a0d6 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -32,8 +32,6 @@ static struct dentry *gfs2_decode_fh(struct super_block *sb, { struct gfs2_inum this, parent; - atomic_inc(&get_v2sdp(sb)->sd_ops_export); - if (fh_type != fh_len) return NULL; @@ -66,8 +64,6 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, struct gfs2_inode *ip = get_v2ip(inode); struct gfs2_sbd *sdp = ip->i_sbd; - atomic_inc(&sdp->sd_ops_export); - if (*len < 4 || (connectable && *len < 8)) return 255; @@ -139,8 +135,6 @@ static int gfs2_get_name(struct dentry *parent, char *name, if (!dir) return -EINVAL; - atomic_inc(&get_v2sdp(dir->i_sb)->sd_ops_export); - if (!S_ISDIR(dir->i_mode) || !inode) return -EINVAL; @@ -173,8 +167,6 @@ static struct dentry *gfs2_get_parent(struct dentry *child) struct dentry *dentry; int error; - atomic_inc(&dip->i_sbd->sd_ops_export); - error = gfs2_lookupi(child->d_inode, &dotdot, 1, &inode); if (error) return ERR_PTR(error); @@ -199,8 +191,6 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) struct dentry *dentry; int error; - atomic_inc(&sdp->sd_ops_export); - /* System files? */ inode = gfs2_iget(sb, inum); @@ -256,8 +246,6 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) goto fail; } - atomic_inc(&sdp->sd_fh2dentry_misses); - out_ip: error = -EIO; if (ip->i_di.di_flags & GFS2_DIF_SYSTEM) { diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index cf2e26e07245..0f80e9306016 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -129,8 +129,6 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) struct gfs2_holder i_gh; loff_t error; - atomic_inc(&ip->i_sbd->sd_ops_file); - if (origin == 2) { error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); @@ -278,8 +276,6 @@ static ssize_t gfs2_read(struct file *filp, char __user *buf, size_t size, struct kiocb kiocb; ssize_t ret; - atomic_inc(&get_v2sdp(filp->f_mapping->host->i_sb)->sd_ops_file); - init_sync_kiocb(&kiocb, filp); ret = __gfs2_file_aio_read(&kiocb, &local_iov, 1, offset); if (-EIOCBQUEUED == ret) @@ -293,8 +289,6 @@ static ssize_t gfs2_file_readv(struct file *filp, const struct iovec *iov, struct kiocb kiocb; ssize_t ret; - atomic_inc(&get_v2sdp(filp->f_mapping->host->i_sb)->sd_ops_file); - init_sync_kiocb(&kiocb, filp); ret = __gfs2_file_aio_read(&kiocb, iov, nr_segs, ppos); if (-EIOCBQUEUED == ret) @@ -308,8 +302,6 @@ static ssize_t gfs2_file_aio_read(struct kiocb *iocb, char __user *buf, struct file *filp = iocb->ki_filp; struct iovec local_iov = { .iov_base = buf, .iov_len = count }; - atomic_inc(&get_v2sdp(filp->f_mapping->host->i_sb)->sd_ops_file); - BUG_ON(iocb->ki_pos != pos); return __gfs2_file_aio_read(iocb, &local_iov, 1, &iocb->ki_pos); } @@ -529,8 +521,6 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) { int error; - atomic_inc(&get_v2sdp(file->f_mapping->host->i_sb)->sd_ops_file); - if (strcmp(current->comm, "nfsd") != 0) error = readdir_reg(file, dirent, filldir); else @@ -539,7 +529,8 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) return error; } -static int gfs2_ioctl_flags(struct gfs2_inode *ip, unsigned int cmd, unsigned long arg) +static int gfs2_ioctl_flags(struct gfs2_inode *ip, unsigned int cmd, + unsigned long arg) { unsigned int lmode = (cmd == GFS2_IOCTL_SETFLAGS) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; struct buffer_head *dibh; @@ -618,8 +609,6 @@ static int gfs2_ioctl(struct inode *inode, struct file *file, unsigned int cmd, { struct gfs2_inode *ip = get_v2ip(inode); - atomic_inc(&ip->i_sbd->sd_ops_file); - switch (cmd) { case GFS2_IOCTL_SETFLAGS: case GFS2_IOCTL_GETFLAGS: @@ -644,8 +633,6 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) struct gfs2_holder i_gh; int error; - atomic_inc(&ip->i_sbd->sd_ops_file); - gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &i_gh); error = gfs2_glock_nq_atime(&i_gh); if (error) { @@ -682,8 +669,6 @@ static int gfs2_open(struct inode *inode, struct file *file) struct gfs2_file *fp; int error; - atomic_inc(&ip->i_sbd->sd_ops_file); - fp = kzalloc(sizeof(struct gfs2_file), GFP_KERNEL); if (!fp) return -ENOMEM; @@ -741,8 +726,6 @@ static int gfs2_close(struct inode *inode, struct file *file) struct gfs2_sbd *sdp = get_v2sdp(inode->i_sb); struct gfs2_file *fp; - atomic_inc(&sdp->sd_ops_file); - fp = get_v2fp(file); set_v2fp(file, NULL); @@ -766,7 +749,6 @@ static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) { struct gfs2_inode *ip = get_v2ip(dentry->d_inode); - atomic_inc(&ip->i_sbd->sd_ops_file); gfs2_log_flush_glock(ip->i_gl); return 0; @@ -789,8 +771,6 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) { .ln_number = ip->i_num.no_addr, .ln_type = LM_TYPE_PLOCK }; - atomic_inc(&sdp->sd_ops_file); - if (!(fl->fl_flags & FL_POSIX)) return -ENOLCK; if ((ip->i_di.di_mode & (S_ISGID | S_IXGRP)) == S_ISGID) @@ -839,9 +819,6 @@ static ssize_t gfs2_sendfile(struct file *in_file, loff_t *offset, size_t count, read_actor_t actor, void *target) { struct gfs2_inode *ip = get_v2ip(in_file->f_mapping->host); - - atomic_inc(&ip->i_sbd->sd_ops_file); - return generic_file_sendfile(in_file, offset, count, actor, target); } @@ -921,8 +898,6 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); struct gfs2_sbd *sdp = ip->i_sbd; - atomic_inc(&ip->i_sbd->sd_ops_file); - if (!(fl->fl_flags & FL_FLOCK)) return -ENOLCK; if ((ip->i_di.di_mode & (S_ISGID | S_IXGRP)) == S_ISGID) diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 9fb9490eb67a..9971a30eb78e 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -56,8 +56,6 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, int new = 1; int error; - atomic_inc(&sdp->sd_ops_inode); - gfs2_holder_init(dip->i_gl, 0, 0, ghs); for (;;) { @@ -113,8 +111,6 @@ static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, struct inode *inode = NULL; int error; - atomic_inc(&sdp->sd_ops_inode); - if (!sdp->sd_args.ar_localcaching) dentry->d_op = &gfs2_dops; @@ -152,8 +148,6 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, int alloc_required; int error; - atomic_inc(&sdp->sd_ops_inode); - if (S_ISDIR(ip->i_di.di_mode)) return -EPERM; @@ -287,8 +281,6 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry) struct gfs2_holder ghs[2]; int error; - atomic_inc(&sdp->sd_ops_inode); - error = gfs2_unlinked_get(sdp, &ul); if (error) return error; @@ -345,8 +337,6 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry, int size; int error; - atomic_inc(&sdp->sd_ops_inode); - /* Must be stuffed with a null terminator for gfs2_follow_link() */ size = strlen(symname); if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1) @@ -405,8 +395,6 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) struct buffer_head *dibh; int error; - atomic_inc(&sdp->sd_ops_inode); - gfs2_holder_init(dip->i_gl, 0, 0, ghs); inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode); @@ -487,8 +475,6 @@ static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) struct gfs2_holder ghs[2]; int error; - atomic_inc(&sdp->sd_ops_inode); - error = gfs2_unlinked_get(sdp, &ul); if (error) return error; @@ -556,8 +542,6 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, uint32_t major = 0, minor = 0; int error; - atomic_inc(&sdp->sd_ops_inode); - switch (mode & S_IFMT) { case S_IFBLK: case S_IFCHR: @@ -631,8 +615,6 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, unsigned int x; int error; - atomic_inc(&sdp->sd_ops_inode); - if (ndentry->d_inode) { nip = get_v2ip(ndentry->d_inode); if (ip == nip) @@ -871,8 +853,6 @@ static int gfs2_readlink(struct dentry *dentry, char __user *user_buf, unsigned int len = GFS2_FAST_NAME_SIZE; int error; - atomic_inc(&ip->i_sbd->sd_ops_inode); - error = gfs2_readlinki(ip, &buf, &len); if (error) return error; @@ -909,8 +889,6 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) unsigned int len = GFS2_FAST_NAME_SIZE; int error; - atomic_inc(&ip->i_sbd->sd_ops_inode); - error = gfs2_readlinki(ip, &buf, &len); if (!error) { error = vfs_follow_link(nd, buf); @@ -936,8 +914,6 @@ static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd) struct gfs2_holder i_gh; int error; - atomic_inc(&ip->i_sbd->sd_ops_inode); - if (ip->i_vn == ip->i_gl->gl_vn) return generic_permission(inode, mask, gfs2_check_acl); @@ -1053,8 +1029,6 @@ static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) struct gfs2_holder i_gh; int error; - atomic_inc(&ip->i_sbd->sd_ops_inode); - error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); if (error) return error; @@ -1102,8 +1076,6 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, struct gfs2_holder gh; int error; - atomic_inc(&ip->i_sbd->sd_ops_inode); - error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); if (!error) { generic_fillattr(inode, stat); @@ -1119,8 +1091,6 @@ static int gfs2_setxattr(struct dentry *dentry, const char *name, struct gfs2_inode *ip = get_v2ip(dentry->d_inode); struct gfs2_ea_request er; - atomic_inc(&ip->i_sbd->sd_ops_inode); - memset(&er, 0, sizeof(struct gfs2_ea_request)); er.er_type = gfs2_ea_name2type(name, &er.er_name); if (er.er_type == GFS2_EATYPE_UNUSED) @@ -1140,8 +1110,6 @@ static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, { struct gfs2_ea_request er; - atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode); - memset(&er, 0, sizeof(struct gfs2_ea_request)); er.er_type = gfs2_ea_name2type(name, &er.er_name); if (er.er_type == GFS2_EATYPE_UNUSED) @@ -1157,8 +1125,6 @@ static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) { struct gfs2_ea_request er; - atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode); - memset(&er, 0, sizeof(struct gfs2_ea_request)); er.er_data = (size) ? buffer : NULL; er.er_data_len = size; @@ -1170,8 +1136,6 @@ static int gfs2_removexattr(struct dentry *dentry, const char *name) { struct gfs2_ea_request er; - atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode); - memset(&er, 0, sizeof(struct gfs2_ea_request)); er.er_type = gfs2_ea_name2type(name, &er.er_name); if (er.er_type == GFS2_EATYPE_UNUSED) diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 9130d0d0df3c..cd45ec93a043 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -46,8 +46,6 @@ static int gfs2_write_inode(struct inode *inode, int sync) { struct gfs2_inode *ip = get_v2ip(inode); - atomic_inc(&ip->i_sbd->sd_ops_super); - if (current->flags & PF_MEMALLOC) return 0; if (ip && sync) @@ -70,8 +68,6 @@ static void gfs2_put_super(struct super_block *sb) if (!sdp) return; - atomic_inc(&sdp->sd_ops_super); - /* Unfreeze the filesystem, if we need to */ mutex_lock(&sdp->sd_freeze_lock); @@ -156,7 +152,6 @@ static void gfs2_put_super(struct super_block *sb) static void gfs2_write_super(struct super_block *sb) { struct gfs2_sbd *sdp = get_v2sdp(sb); - atomic_inc(&sdp->sd_ops_super); gfs2_log_flush(sdp); } @@ -171,8 +166,6 @@ static void gfs2_write_super_lockfs(struct super_block *sb) struct gfs2_sbd *sdp = get_v2sdp(sb); int error; - atomic_inc(&sdp->sd_ops_super); - for (;;) { error = gfs2_freeze_fs(sdp); if (!error) @@ -202,8 +195,6 @@ static void gfs2_write_super_lockfs(struct super_block *sb) static void gfs2_unlockfs(struct super_block *sb) { struct gfs2_sbd *sdp = get_v2sdp(sb); - - atomic_inc(&sdp->sd_ops_super); gfs2_unfreeze_fs(sdp); } @@ -221,8 +212,6 @@ static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf) struct gfs2_statfs_change sc; int error; - atomic_inc(&sdp->sd_ops_super); - if (gfs2_tune_get(sdp, gt_statfs_slow)) error = gfs2_statfs_slow(sdp, &sc); else @@ -259,8 +248,6 @@ static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) struct gfs2_sbd *sdp = get_v2sdp(sb); int error; - atomic_inc(&sdp->sd_ops_super); - error = gfs2_mount_args(sdp, data, 1); if (error) return error; @@ -298,8 +285,6 @@ static void gfs2_clear_inode(struct inode *inode) { struct gfs2_inode *ip = get_v2ip(inode); - atomic_inc(&get_v2sdp(inode->i_sb)->sd_ops_super); - if (ip) { spin_lock(&ip->i_spin); ip->i_vnode = NULL; @@ -324,8 +309,6 @@ static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) struct gfs2_sbd *sdp = get_v2sdp(mnt->mnt_sb); struct gfs2_args *args = &sdp->sd_args; - atomic_inc(&sdp->sd_ops_super); - if (args->ar_lockproto[0]) seq_printf(s, ",lockproto=%s", args->ar_lockproto); if (args->ar_locktable[0]) diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index 8f77bb7896bd..808110e3ec5e 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -48,8 +48,6 @@ static struct page *gfs2_private_nopage(struct vm_area_struct *area, struct page *result; int error; - atomic_inc(&ip->i_sbd->sd_ops_vm); - error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); if (error) return NULL; @@ -149,8 +147,6 @@ static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, int alloc_required; int error; - atomic_inc(&ip->i_sbd->sd_ops_vm); - error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); if (error) return NULL; diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index c5984351e4d8..f87df8ec041e 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -319,85 +319,23 @@ struct counters_attr { ssize_t (*show)(struct gfs2_sbd *, char *); }; -#define COUNTERS_ATTR_GENERAL(name, fmt, val) \ +#define COUNTERS_ATTR(name, fmt) \ static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ { \ - return sprintf(buf, fmt, val); \ + return sprintf(buf, fmt, (unsigned int)atomic_read(&sdp->sd_##name)); \ } \ static struct counters_attr counters_attr_##name = __ATTR_RO(name) -#define COUNTERS_ATTR_SIMPLE(name, fmt) \ - COUNTERS_ATTR_GENERAL(name, fmt, sdp->sd_##name) - -#define COUNTERS_ATTR_ATOMIC(name, fmt) \ - COUNTERS_ATTR_GENERAL(name, fmt, (unsigned int)atomic_read(&sdp->sd_##name)) - -COUNTERS_ATTR_ATOMIC(glock_count, "%u\n"); -COUNTERS_ATTR_ATOMIC(glock_held_count, "%u\n"); -COUNTERS_ATTR_ATOMIC(inode_count, "%u\n"); -COUNTERS_ATTR_ATOMIC(bufdata_count, "%u\n"); -COUNTERS_ATTR_ATOMIC(unlinked_count, "%u\n"); -COUNTERS_ATTR_ATOMIC(quota_count, "%u\n"); -COUNTERS_ATTR_SIMPLE(log_num_gl, "%u\n"); -COUNTERS_ATTR_SIMPLE(log_num_buf, "%u\n"); -COUNTERS_ATTR_SIMPLE(log_num_revoke, "%u\n"); -COUNTERS_ATTR_SIMPLE(log_num_rg, "%u\n"); -COUNTERS_ATTR_SIMPLE(log_num_databuf, "%u\n"); -COUNTERS_ATTR_SIMPLE(log_blks_free, "%u\n"); -COUNTERS_ATTR_GENERAL(jd_blocks, "%u\n", sdp->sd_jdesc->jd_blocks); -COUNTERS_ATTR_ATOMIC(reclaim_count, "%u\n"); -COUNTERS_ATTR_SIMPLE(log_wraps, "%llu\n"); -COUNTERS_ATTR_ATOMIC(fh2dentry_misses, "%u\n"); -COUNTERS_ATTR_ATOMIC(reclaimed, "%u\n"); -COUNTERS_ATTR_ATOMIC(log_flush_incore, "%u\n"); -COUNTERS_ATTR_ATOMIC(log_flush_ondisk, "%u\n"); -COUNTERS_ATTR_ATOMIC(glock_nq_calls, "%u\n"); -COUNTERS_ATTR_ATOMIC(glock_dq_calls, "%u\n"); -COUNTERS_ATTR_ATOMIC(glock_prefetch_calls, "%u\n"); -COUNTERS_ATTR_ATOMIC(lm_lock_calls, "%u\n"); -COUNTERS_ATTR_ATOMIC(lm_unlock_calls, "%u\n"); -COUNTERS_ATTR_ATOMIC(lm_callbacks, "%u\n"); -COUNTERS_ATTR_ATOMIC(ops_address, "%u\n"); -COUNTERS_ATTR_ATOMIC(ops_dentry, "%u\n"); -COUNTERS_ATTR_ATOMIC(ops_export, "%u\n"); -COUNTERS_ATTR_ATOMIC(ops_file, "%u\n"); -COUNTERS_ATTR_ATOMIC(ops_inode, "%u\n"); -COUNTERS_ATTR_ATOMIC(ops_super, "%u\n"); -COUNTERS_ATTR_ATOMIC(ops_vm, "%u\n"); +COUNTERS_ATTR(glock_count, "%u\n"); +COUNTERS_ATTR(glock_held_count, "%u\n"); +COUNTERS_ATTR(inode_count, "%u\n"); +COUNTERS_ATTR(reclaimed, "%u\n"); static struct attribute *counters_attrs[] = { &counters_attr_glock_count.attr, &counters_attr_glock_held_count.attr, &counters_attr_inode_count.attr, - &counters_attr_bufdata_count.attr, - &counters_attr_unlinked_count.attr, - &counters_attr_quota_count.attr, - &counters_attr_log_num_gl.attr, - &counters_attr_log_num_buf.attr, - &counters_attr_log_num_revoke.attr, - &counters_attr_log_num_rg.attr, - &counters_attr_log_num_databuf.attr, - &counters_attr_log_blks_free.attr, - &counters_attr_jd_blocks.attr, - &counters_attr_reclaim_count.attr, - &counters_attr_log_wraps.attr, - &counters_attr_fh2dentry_misses.attr, &counters_attr_reclaimed.attr, - &counters_attr_log_flush_incore.attr, - &counters_attr_log_flush_ondisk.attr, - &counters_attr_glock_nq_calls.attr, - &counters_attr_glock_dq_calls.attr, - &counters_attr_glock_prefetch_calls.attr, - &counters_attr_lm_lock_calls.attr, - &counters_attr_lm_unlock_calls.attr, - &counters_attr_lm_callbacks.attr, - &counters_attr_ops_address.attr, - &counters_attr_ops_dentry.attr, - &counters_attr_ops_export.attr, - &counters_attr_ops_file.attr, - &counters_attr_ops_inode.attr, - &counters_attr_ops_super.attr, - &counters_attr_ops_vm.attr, NULL }; From d95cb943f5b217c5b5f97f5af0fea3c511ed9c97 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 23 Feb 2006 10:13:13 +0000 Subject: [PATCH 048/292] [GFS2] Patch to remove stats counters from GFS2 (II) Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 2 -- fs/gfs2/ops_dentry.c | 1 - fs/gfs2/ops_export.c | 1 - fs/gfs2/ops_file.c | 2 -- 4 files changed, 6 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index cf1dc17faf4f..d4fa395ed39f 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -825,7 +825,6 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state) static void state_change(struct gfs2_glock *gl, unsigned int new_state) { - struct gfs2_sbd *sdp = gl->gl_sbd; int held1, held2; held1 = (gl->gl_state != LM_ST_UNLOCKED); @@ -1390,7 +1389,6 @@ int gfs2_glock_wait(struct gfs2_holder *gh) void gfs2_glock_dq(struct gfs2_holder *gh) { struct gfs2_glock *gl = gh->gh_gl; - struct gfs2_sbd *sdp = gl->gl_sbd; struct gfs2_glock_operations *glops = gl->gl_ops; if (gh->gh_flags & GL_SYNC) diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index fb8f70d225b9..b020ad8f180b 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -35,7 +35,6 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) { struct dentry *parent = dget_parent(dentry); struct gfs2_inode *dip = get_v2ip(parent->d_inode); - struct gfs2_sbd *sdp = dip->i_sbd; struct inode *inode; struct gfs2_holder d_gh; struct gfs2_inode *ip; diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index 611252b7a0d6..60d006402553 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -161,7 +161,6 @@ static int gfs2_get_name(struct dentry *parent, char *name, static struct dentry *gfs2_get_parent(struct dentry *child) { - struct gfs2_inode *dip = get_v2ip(child->d_inode); struct qstr dotdot = { .name = "..", .len = 2 }; struct inode *inode; struct dentry *dentry; diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 0f80e9306016..989f0f70fc2e 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -299,7 +299,6 @@ static ssize_t gfs2_file_readv(struct file *filp, const struct iovec *iov, static ssize_t gfs2_file_aio_read(struct kiocb *iocb, char __user *buf, size_t count, loff_t pos) { - struct file *filp = iocb->ki_filp; struct iovec local_iov = { .iov_base = buf, .iov_len = count }; BUG_ON(iocb->ki_pos != pos); @@ -818,7 +817,6 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) static ssize_t gfs2_sendfile(struct file *in_file, loff_t *offset, size_t count, read_actor_t actor, void *target) { - struct gfs2_inode *ip = get_v2ip(in_file->f_mapping->host); return generic_file_sendfile(in_file, offset, count, actor, target); } From 2fcb4a1278ec41508d76786f4c5d23bff3b378ee Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 24 Feb 2006 10:42:20 -0500 Subject: [PATCH 049/292] [GFS2] Update documentation Change from gfs2_mkfs to mkfs -t gfs2 in the documentation. Signed-off-by: Steven Whitehouse --- Documentation/filesystems/gfs2.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/filesystems/gfs2.txt b/Documentation/filesystems/gfs2.txt index 4a060d38bed8..a20ba19e9fe5 100644 --- a/Documentation/filesystems/gfs2.txt +++ b/Documentation/filesystems/gfs2.txt @@ -28,7 +28,7 @@ at the URL above. To use gfs as a local file system, no external clustering systems are needed, simply: - $ gfs2_mkfs -p lock_nolock -j 1 /dev/block_device + $ mkfs -t gfs2 -p lock_nolock -j 1 /dev/block_device $ mount -t gfs2 /dev/block_device /dir GFS2 is not on-disk compatible with previous versions of GFS. From d92a8d48085df863032110d9ccb221cde98d14e1 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 27 Feb 2006 10:57:14 -0500 Subject: [PATCH 050/292] [GFS2] Audit printk and kmalloc All printk calls now have KERN_ set where required and a couple of kmalloc(), memset(.., 0, ...) calls changed to kzalloc(). This is in response to comments from: Pekka Enberg and Eric Sesterhenn Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 52 +++++++++++++++++------------------ fs/gfs2/locking.c | 9 +++--- fs/gfs2/locking/dlm/lock.c | 7 +++-- fs/gfs2/locking/dlm/main.c | 4 +-- fs/gfs2/locking/dlm/plock.c | 13 +++++---- fs/gfs2/locking/nolock/main.c | 13 ++++----- fs/gfs2/ondisk.c | 10 +++---- fs/gfs2/ops_fstype.c | 4 +-- fs/gfs2/ops_super.c | 2 +- fs/gfs2/super.c | 16 +++++------ 10 files changed, 64 insertions(+), 66 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index d4fa395ed39f..f30fde91d14a 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -2315,17 +2315,17 @@ static int dump_holder(char *str, struct gfs2_holder *gh) unsigned int x; int error = -ENOBUFS; - printk(" %s\n", str); - printk(" owner = %ld\n", + printk(KERN_INFO " %s\n", str); + printk(KERN_INFO " owner = %ld\n", (gh->gh_owner) ? (long)gh->gh_owner->pid : -1); - printk(" gh_state = %u\n", gh->gh_state); - printk(" gh_flags ="); + printk(KERN_INFO " gh_state = %u\n", gh->gh_state); + printk(KERN_INFO " gh_flags ="); for (x = 0; x < 32; x++) if (gh->gh_flags & (1 << x)) printk(" %u", x); printk(" \n"); - printk(" error = %d\n", gh->gh_error); - printk(" gh_iflags ="); + printk(KERN_INFO " error = %d\n", gh->gh_error); + printk(KERN_INFO " gh_iflags ="); for (x = 0; x < 32; x++) if (test_bit(x, &gh->gh_iflags)) printk(" %u", x); @@ -2348,17 +2348,17 @@ static int dump_inode(struct gfs2_inode *ip) unsigned int x; int error = -ENOBUFS; - printk(" Inode:\n"); - printk(" num = %llu %llu\n", + printk(KERN_INFO " Inode:\n"); + printk(KERN_INFO " num = %llu %llu\n", ip->i_num.no_formal_ino, ip->i_num.no_addr); - printk(" type = %u\n", IF2DT(ip->i_di.di_mode)); - printk(" i_count = %d\n", atomic_read(&ip->i_count)); - printk(" i_flags ="); + printk(KERN_INFO " type = %u\n", IF2DT(ip->i_di.di_mode)); + printk(KERN_INFO " i_count = %d\n", atomic_read(&ip->i_count)); + printk(KERN_INFO " i_flags ="); for (x = 0; x < 32; x++) if (test_bit(x, &ip->i_flags)) printk(" %u", x); printk(" \n"); - printk(" vnode = %s\n", (ip->i_vnode) ? "yes" : "no"); + printk(KERN_INFO " vnode = %s\n", (ip->i_vnode) ? "yes" : "no"); error = 0; @@ -2381,30 +2381,30 @@ static int dump_glock(struct gfs2_glock *gl) spin_lock(&gl->gl_spin); - printk("Glock (%u, %llu)\n", + printk(KERN_INFO "Glock (%u, %llu)\n", gl->gl_name.ln_type, gl->gl_name.ln_number); - printk(" gl_flags ="); + printk(KERN_INFO " gl_flags ="); for (x = 0; x < 32; x++) if (test_bit(x, &gl->gl_flags)) printk(" %u", x); printk(" \n"); - printk(" gl_ref = %d\n", atomic_read(&gl->gl_ref.refcount)); - printk(" gl_state = %u\n", gl->gl_state); - printk(" req_gh = %s\n", (gl->gl_req_gh) ? "yes" : "no"); - printk(" req_bh = %s\n", (gl->gl_req_bh) ? "yes" : "no"); - printk(" lvb_count = %d\n", atomic_read(&gl->gl_lvb_count)); - printk(" object = %s\n", (gl->gl_object) ? "yes" : "no"); - printk(" le = %s\n", + printk(KERN_INFO " gl_ref = %d\n", atomic_read(&gl->gl_ref.refcount)); + printk(KERN_INFO " gl_state = %u\n", gl->gl_state); + printk(KERN_INFO " req_gh = %s\n", (gl->gl_req_gh) ? "yes" : "no"); + printk(KERN_INFO " req_bh = %s\n", (gl->gl_req_bh) ? "yes" : "no"); + printk(KERN_INFO " lvb_count = %d\n", atomic_read(&gl->gl_lvb_count)); + printk(KERN_INFO " object = %s\n", (gl->gl_object) ? "yes" : "no"); + printk(KERN_INFO " le = %s\n", (list_empty(&gl->gl_le.le_list)) ? "no" : "yes"); - printk(" reclaim = %s\n", + printk(KERN_INFO " reclaim = %s\n", (list_empty(&gl->gl_reclaim)) ? "no" : "yes"); if (gl->gl_aspace) - printk(" aspace = %lu\n", + printk(KERN_INFO " aspace = %lu\n", gl->gl_aspace->i_mapping->nrpages); else - printk(" aspace = no\n"); - printk(" ail = %d\n", atomic_read(&gl->gl_ail_count)); + printk(KERN_INFO " aspace = no\n"); + printk(KERN_INFO " ail = %d\n", atomic_read(&gl->gl_ail_count)); if (gl->gl_req_gh) { error = dump_holder("Request", gl->gl_req_gh); if (error) @@ -2438,7 +2438,7 @@ static int dump_glock(struct gfs2_glock *gl) goto out; } else { error = -ENOBUFS; - printk(" Inode: busy\n"); + printk(KERN_INFO " Inode: busy\n"); } } diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c index 2d2f8fe53999..0f4c50ebcbad 100644 --- a/fs/gfs2/locking.c +++ b/fs/gfs2/locking.c @@ -46,18 +46,17 @@ int gfs_register_lockproto(struct lm_lockops *proto) list_for_each_entry(lw, &lmh_list, lw_list) { if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) { up(&lmh_lock); - printk("GFS2: protocol %s already exists\n", + printk(KERN_INFO "GFS2: protocol %s already exists\n", proto->lm_proto_name); return -EEXIST; } } - lw = kmalloc(sizeof(struct lmh_wrapper), GFP_KERNEL); + lw = kzalloc(sizeof(struct lmh_wrapper), GFP_KERNEL); if (!lw) { up(&lmh_lock); return -ENOMEM; } - memset(lw, 0, sizeof(struct lmh_wrapper)); lw->lw_ops = proto; list_add(&lw->lw_list, &lmh_list); @@ -90,7 +89,7 @@ void gfs_unregister_lockproto(struct lm_lockops *proto) up(&lmh_lock); - printk("GFS2: can't unregister lock protocol %s\n", + printk(KERN_WARNING "GFS2: can't unregister lock protocol %s\n", proto->lm_proto_name); } @@ -136,7 +135,7 @@ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, request_module(proto_name); goto retry; } - printk("GFS2: can't find protocol %s\n", proto_name); + printk(KERN_INFO "GFS2: can't find protocol %s\n", proto_name); error = -ENOENT; goto out; } diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index 666d696dc8ce..1799d2237e7e 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -34,7 +34,7 @@ static inline void gdlm_bast(void *astarg, int mode) struct gdlm_ls *ls = lp->ls; if (!mode) { - printk("lock_dlm: bast mode zero %x,%llx\n", + printk(KERN_INFO "lock_dlm: bast mode zero %x,%llx\n", lp->lockname.ln_type, lp->lockname.ln_number); return; } @@ -408,7 +408,7 @@ static int hold_null_lock(struct gdlm_lock *lp) int error; if (lp->hold_null) { - printk("lock_dlm: lvb already held\n"); + printk(KERN_INFO "lock_dlm: lvb already held\n"); return 0; } @@ -429,7 +429,8 @@ static int hold_null_lock(struct gdlm_lock *lp) wait_for_completion(&lpn->ast_wait); error = lp->lksb.sb_status; if (error) { - printk("lock_dlm: hold_null_lock dlm error %d\n", error); + printk(KERN_INFO "lock_dlm: hold_null_lock dlm error %d\n", + error); gdlm_delete_lp(lpn); lpn = NULL; } diff --git a/fs/gfs2/locking/dlm/main.c b/fs/gfs2/locking/dlm/main.c index 2c13c916a352..1c0943de9408 100644 --- a/fs/gfs2/locking/dlm/main.c +++ b/fs/gfs2/locking/dlm/main.c @@ -22,7 +22,7 @@ int __init init_lock_dlm(void) error = gfs_register_lockproto(&gdlm_ops); if (error) { - printk("lock_dlm: can't register protocol: %d\n", error); + printk(KERN_WARNING "lock_dlm: can't register protocol: %d\n", error); return error; } @@ -42,7 +42,7 @@ int __init init_lock_dlm(void) gdlm_drop_count = GDLM_DROP_COUNT; gdlm_drop_period = GDLM_DROP_PERIOD; - printk("Lock_DLM (built %s %s) installed\n", __DATE__, __TIME__); + printk(KERN_INFO "Lock_DLM (built %s %s) installed\n", __DATE__, __TIME__); return 0; } diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c index 382847205bc1..f7ac5821def9 100644 --- a/fs/gfs2/locking/dlm/plock.c +++ b/fs/gfs2/locking/dlm/plock.c @@ -83,7 +83,7 @@ int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, spin_lock(&ops_lock); if (!list_empty(&op->list)) { - printk("plock op on list\n"); + printk(KERN_INFO "plock op on list\n"); list_del(&op->list); } spin_unlock(&ops_lock); @@ -127,7 +127,7 @@ int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, spin_lock(&ops_lock); if (!list_empty(&op->list)) { - printk("punlock op on list\n"); + printk(KERN_INFO "punlock op on list\n"); list_del(&op->list); } spin_unlock(&ops_lock); @@ -162,7 +162,7 @@ int gdlm_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, spin_lock(&ops_lock); if (!list_empty(&op->list)) { - printk("plock_get op on list\n"); + printk(KERN_INFO "plock_get op on list\n"); list_del(&op->list); } spin_unlock(&ops_lock); @@ -242,7 +242,7 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count, if (found) wake_up(&recv_wq); else - printk("gdlm dev_write no op %x %llx\n", info.fsid, + printk(KERN_INFO "gdlm dev_write no op %x %llx\n", info.fsid, info.number); return count; } @@ -285,13 +285,14 @@ int gdlm_plock_init(void) rv = misc_register(&plock_dev_misc); if (rv) - printk("gdlm_plock_init: misc_register failed %d", rv); + printk(KERN_INFO "gdlm_plock_init: misc_register failed %d", + rv); return rv; } void gdlm_plock_exit(void) { if (misc_deregister(&plock_dev_misc) < 0) - printk("gdlm_plock_exit: misc_deregister failed"); + printk(KERN_INFO "gdlm_plock_exit: misc_deregister failed"); } diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index b716e336c073..7ede0906b2c6 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -44,11 +44,10 @@ static int nolock_mount(char *table_name, char *host_data, sscanf(c, "%u", &jid); } - nl = kmalloc(sizeof(struct nolock_lockspace), GFP_KERNEL); + nl = kzalloc(sizeof(struct nolock_lockspace), GFP_KERNEL); if (!nl) return -ENOMEM; - memset(nl, 0, sizeof(struct nolock_lockspace)); nl->nl_lvb_size = min_lvb_size; lockstruct->ls_jid = jid; @@ -147,10 +146,8 @@ static int nolock_hold_lvb(lm_lock_t *lock, char **lvbp) struct nolock_lockspace *nl = (struct nolock_lockspace *)lock; int error = 0; - *lvbp = kmalloc(nl->nl_lvb_size, GFP_KERNEL); - if (*lvbp) - memset(*lvbp, 0, nl->nl_lvb_size); - else + *lvbp = kzalloc(nl->nl_lvb_size, GFP_KERNEL); + if (!*lvbp) error = -ENOMEM; return error; @@ -246,11 +243,11 @@ int __init init_nolock(void) error = gfs_register_lockproto(&nolock_ops); if (error) { - printk("lock_nolock: can't register protocol: %d\n", error); + printk(KERN_WARNING "lock_nolock: can't register protocol: %d\n", error); return error; } - printk("Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__); + printk(KERN_INFO "Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__); return 0; } diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index 854b5049b8d5..964abd2760ff 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -17,7 +17,7 @@ #include "gfs2.h" #include -#define pv(struct, member, fmt) printk(" "#member" = "fmt"\n", struct->member); +#define pv(struct, member, fmt) printk(KERN_INFO " "#member" = "fmt"\n", struct->member); #define pa(struct, member, count) print_array(#member, struct->member, count); /** @@ -32,11 +32,11 @@ static void print_array(char *title, char *buf, int count) { int x; - printk(" %s =\n", title); + printk(KERN_INFO " %s =\n" KERN_INFO, title); for (x = 0; x < count; x++) { printk("%.2X ", (unsigned char)buf[x]); if (x % 16 == 15) - printk("\n"); + printk("\n" KERN_INFO); } if (x % 16) printk("\n"); @@ -338,7 +338,7 @@ void gfs2_dirent_print(struct gfs2_dirent *de, char *name) memset(buf, 0, GFS2_FNAMESIZE + 1); memcpy(buf, name, de->de_name_len); - printk(" name = %s\n", buf); + printk(KERN_INFO " name = %s\n", buf); } void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf) @@ -401,7 +401,7 @@ void gfs2_ea_header_print(struct gfs2_ea_header *ea, char *name) memset(buf, 0, GFS2_EA_MAX_NAME_LEN + 1); memcpy(buf, name, ea->ea_name_len); - printk(" name = %s\n", buf); + printk(KERN_INFO " name = %s\n", buf); } void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 751178ab497c..a85f1a2676f6 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -772,13 +772,13 @@ static int fill_super(struct super_block *sb, void *data, int silent) sdp = init_sbd(sb); if (!sdp) { - printk("GFS2: can't alloc struct gfs2_sbd\n"); + printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n"); return -ENOMEM; } error = gfs2_mount_args(sdp, (char *)data, 0); if (error) { - printk("GFS2: can't parse mount arguments\n"); + printk(KERN_WARNING "GFS2: can't parse mount arguments\n"); goto fail; } diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index cd45ec93a043..48a94522406e 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -12,8 +12,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index be80771c414d..60e266618729 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -94,7 +94,7 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent) if (sb->sb_header.mh_magic != GFS2_MAGIC || sb->sb_header.mh_type != GFS2_METATYPE_SB) { if (!silent) - printk("GFS2: not a GFS2 filesystem\n"); + printk(KERN_WARNING "GFS2: not a GFS2 filesystem\n"); return -EINVAL; } @@ -110,11 +110,11 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent) break; if (!gfs2_old_fs_formats[x]) { - printk("GFS2: code version (%u, %u) is incompatible " + printk(KERN_WARNING "GFS2: code version (%u, %u) is incompatible " "with ondisk format (%u, %u)\n", GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, sb->sb_fs_format, sb->sb_multihost_format); - printk("GFS2: I don't know how to upgrade this FS\n"); + printk(KERN_WARNING "GFS2: I don't know how to upgrade this FS\n"); return -EINVAL; } } @@ -125,23 +125,23 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent) break; if (!gfs2_old_multihost_formats[x]) { - printk("GFS2: code version (%u, %u) is incompatible " + printk(KERN_WARNING "GFS2: code version (%u, %u) is incompatible " "with ondisk format (%u, %u)\n", GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, sb->sb_fs_format, sb->sb_multihost_format); - printk("GFS2: I don't know how to upgrade this FS\n"); + printk(KERN_WARNING "GFS2: I don't know how to upgrade this FS\n"); return -EINVAL; } } if (!sdp->sd_args.ar_upgrade) { - printk("GFS2: code version (%u, %u) is incompatible " + printk(KERN_WARNING "GFS2: code version (%u, %u) is incompatible " "with ondisk format (%u, %u)\n", GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, sb->sb_fs_format, sb->sb_multihost_format); - printk("GFS2: Use the \"upgrade\" mount option to upgrade " + printk(KERN_INFO "GFS2: Use the \"upgrade\" mount option to upgrade " "the FS\n"); - printk("GFS2: See the manual for more details\n"); + printk(KERN_INFO "GFS2: See the manual for more details\n"); return -EINVAL; } From 3a8fe9be6c9794e55ac2253eab91d42b28a9dab6 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 27 Feb 2006 11:00:37 -0500 Subject: [PATCH 051/292] [GFS2] Use BUG_ON() rather then if (...) BUG(); This issue was raised by: Eric Sesterhenn Signed-off-by: Steven Whitehouse --- fs/gfs2/lm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index cc7442261b2e..f86f11f39738 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -101,8 +101,8 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) va_end(args); fs_err(sdp, "about to withdraw from the cluster\n"); - if (sdp->sd_args.ar_debug) - BUG(); + BUG_ON(sdp->sd_args.ar_debug); + fs_err(sdp, "waiting for outstanding I/O\n"); From 568f4c9659a2225b0d29cf86feecbcf25c9045c8 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 27 Feb 2006 12:00:42 -0500 Subject: [PATCH 052/292] [GFS2] 80 Column audit of GFS2 Requested by: Prarit Bhargava Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 10 +++++--- fs/gfs2/dir.c | 30 ++++++++++++++++-------- fs/gfs2/eattr.c | 4 ++-- fs/gfs2/inode.c | 9 +++++--- fs/gfs2/inode.h | 3 ++- fs/gfs2/lm.c | 9 +++++--- fs/gfs2/log.c | 12 ++++++---- fs/gfs2/lops.c | 54 +++++++++++++++++++++++++++++-------------- fs/gfs2/lvb.c | 3 ++- fs/gfs2/meta_io.c | 6 +++-- fs/gfs2/meta_io.h | 3 ++- fs/gfs2/ondisk.c | 3 ++- fs/gfs2/ops_address.c | 6 +++-- fs/gfs2/ops_file.c | 6 +++-- fs/gfs2/ops_fstype.c | 6 +++-- fs/gfs2/ops_vm.c | 6 +++-- fs/gfs2/quota.c | 12 ++++++---- fs/gfs2/recovery.c | 3 ++- fs/gfs2/rgrp.c | 3 ++- fs/gfs2/super.c | 30 ++++++++++++++++-------- 20 files changed, 146 insertions(+), 72 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 4efcd8a39e98..e132d8a41008 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -129,7 +129,8 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); if (ip->i_di.di_size) { - *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) = cpu_to_be64(block); + *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) = + cpu_to_be64(block); ip->i_di.di_blocks++; } @@ -241,7 +242,9 @@ static int build_height(struct gfs2_inode *ip, int height) gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); if (new_block) { - *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) = cpu_to_be64(block); + *(uint64_t *)(dibh->b_data + + sizeof(struct gfs2_dinode)) = + cpu_to_be64(block); ip->i_di.di_blocks++; } @@ -313,7 +316,8 @@ static int build_height(struct gfs2_inode *ip, int height) * */ -static void find_metapath(struct gfs2_inode *ip, uint64_t block, struct metapath *mp) +static void find_metapath(struct gfs2_inode *ip, uint64_t block, + struct metapath *mp) { struct gfs2_sbd *sdp = ip->i_sbd; uint64_t b = block; diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 65871a2b460e..56683788a6cf 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -98,7 +98,8 @@ int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, gfs2_metatype_set(bh, GFS2_METATYPE_JD, GFS2_FORMAT_JD); gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); } else { - error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT, &bh); + error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT, + &bh); if (error) return error; if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_JD)) { @@ -163,7 +164,8 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, if (gfs2_is_stuffed(ip) && offset + size <= sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) - return gfs2_dir_write_stuffed(ip, buf, (unsigned int)offset, size); + return gfs2_dir_write_stuffed(ip, buf, (unsigned int)offset, + size); if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) return -EINVAL; @@ -188,7 +190,8 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, if (!extlen) { new = 1; - error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); + error = gfs2_block_map(ip, lblock, &new, &dblock, + &extlen); if (error) goto fail; error = -EIO; @@ -196,7 +199,9 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, goto fail; } - error = gfs2_dir_get_buffer(ip, dblock, (amount == sdp->sd_jbsize) ? 1 : new, &bh); + error = gfs2_dir_get_buffer(ip, dblock, + (amount == sdp->sd_jbsize) ? + 1 : new, &bh); if (error) goto fail; @@ -280,7 +285,8 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, return 0; if (gfs2_is_stuffed(ip)) - return gfs2_dir_read_stuffed(ip, buf, (unsigned int)offset, size); + return gfs2_dir_read_stuffed(ip, buf, (unsigned int)offset, + size); if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) return -EINVAL; @@ -299,7 +305,8 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, if (!extlen) { new = 0; - error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); + error = gfs2_block_map(ip, lblock, &new, &dblock, + &extlen); if (error) goto fail; } @@ -538,13 +545,15 @@ int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, if (dent->de_inum.no_addr) { new = (struct gfs2_dirent *)((char *)dent + - GFS2_DIRENT_SIZE(cur_name_len)); + GFS2_DIRENT_SIZE(cur_name_len)); memset(new, 0, sizeof(struct gfs2_dirent)); - new->de_rec_len = cpu_to_be16(cur_rec_len - GFS2_DIRENT_SIZE(cur_name_len)); + new->de_rec_len = cpu_to_be16(cur_rec_len - + GFS2_DIRENT_SIZE(cur_name_len)); new->de_name_len = cpu_to_be16(name_len); - dent->de_rec_len = cpu_to_be16(cur_rec_len - be16_to_cpu(new->de_rec_len)); + dent->de_rec_len = cpu_to_be16(cur_rec_len - + be16_to_cpu(new->de_rec_len)); *dent_out = new; return 0; @@ -2281,7 +2290,8 @@ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip) error = gfs2_meta_inode_buffer(dip, &bh); if (!error) { gfs2_trans_add_bh(dip->i_gl, bh, 1); - ((struct gfs2_dinode *)bh->b_data)->di_mode = cpu_to_be32(S_IFREG); + ((struct gfs2_dinode *)bh->b_data)->di_mode = + cpu_to_be32(S_IFREG); brelse(bh); } diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 02e45c4ecbec..146995d9cd65 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -354,7 +354,6 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, return error; } -/******************************************************************************/ static int gfs2_ea_repack_i(struct gfs2_inode *ip) { @@ -819,7 +818,8 @@ static int ea_init(struct gfs2_inode *ip, struct gfs2_ea_request *er) static struct gfs2_ea_header *ea_split_ea(struct gfs2_ea_header *ea) { uint32_t ea_size = GFS2_EA_SIZE(ea); - struct gfs2_ea_header *new = (struct gfs2_ea_header *)((char *)ea + ea_size); + struct gfs2_ea_header *new = (struct gfs2_ea_header *)((char *)ea + + ea_size); uint32_t new_size = GFS2_EA_REC_LEN(ea) - ea_size; int last = ea->ea_flags & GFS2_EAFLAG_LAST; diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 30ca82a1addf..51ecdb8503b0 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -1034,8 +1034,10 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, gfs2_tune_get(sdp, gt_new_files_directio)) di->di_flags |= cpu_to_be32(GFS2_DIF_DIRECTIO); } else if (S_ISDIR(mode)) { - di->di_flags |= cpu_to_be32(dip->i_di.di_flags & GFS2_DIF_INHERIT_DIRECTIO); - di->di_flags |= cpu_to_be32(dip->i_di.di_flags & GFS2_DIF_INHERIT_JDATA); + di->di_flags |= cpu_to_be32(dip->i_di.di_flags & + GFS2_DIF_INHERIT_DIRECTIO); + di->di_flags |= cpu_to_be32(dip->i_di.di_flags & + GFS2_DIF_INHERIT_JDATA); } di->__pad1 = 0; @@ -1188,7 +1190,8 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name, * Returns: An inode */ -struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode) +struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, + unsigned int mode) { struct inode *inode; struct gfs2_inode *dip = get_gl2ip(ghs->gh_gl); diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index 8ef85f5feb1b..069f0e21db6d 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -46,7 +46,8 @@ int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); int gfs2_change_nlink(struct gfs2_inode *ip, int diff); int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, struct inode **ipp); -struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode); +struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, + unsigned int mode); int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name, struct gfs2_inode *ip, struct gfs2_unlinked *ul); int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index f86f11f39738..3df8fa00442d 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -80,7 +80,8 @@ int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent) void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp) { if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - sdp->sd_lockstruct.ls_ops->lm_others_may_mount(sdp->sd_lockstruct.ls_lockspace); + sdp->sd_lockstruct.ls_ops->lm_others_may_mount( + sdp->sd_lockstruct.ls_lockspace); } void gfs2_lm_unmount(struct gfs2_sbd *sdp) @@ -124,7 +125,8 @@ int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = -EIO; else - error = sdp->sd_lockstruct.ls_ops->lm_get_lock(sdp->sd_lockstruct.ls_lockspace, name, lockp); + error = sdp->sd_lockstruct.ls_ops->lm_get_lock( + sdp->sd_lockstruct.ls_lockspace, name, lockp); return error; } @@ -230,6 +232,7 @@ void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid, unsigned int message) { if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - sdp->sd_lockstruct.ls_ops->lm_recovery_done(sdp->sd_lockstruct.ls_lockspace, jid, message); + sdp->sd_lockstruct.ls_ops->lm_recovery_done( + sdp->sd_lockstruct.ls_lockspace, jid, message); } diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 2483f0c2c50e..0e31d46edd4d 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -74,10 +74,12 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, unsigned int first, second; blks = 1; - first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / ssize; + first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / + ssize; if (nstruct > first) { - second = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header)) / ssize; + second = (sdp->sd_sb.sb_bsize - + sizeof(struct gfs2_meta_header)) / ssize; blks += DIV_RU(nstruct - first, second); } @@ -255,7 +257,8 @@ static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) uint64_t dbn; int error; - error = gfs2_block_map(get_v2ip(sdp->sd_jdesc->jd_inode), lbn, &new, &dbn, NULL); + error = gfs2_block_map(get_v2ip(sdp->sd_jdesc->jd_inode), + lbn, &new, &dbn, NULL); gfs2_assert_withdraw(sdp, !error && dbn); return dbn; @@ -554,7 +557,8 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0); if (sdp->sd_log_commited_buf) - reserved += 1 + sdp->sd_log_commited_buf + sdp->sd_log_commited_buf/503; + reserved += 1 + sdp->sd_log_commited_buf + + sdp->sd_log_commited_buf/503; if (sdp->sd_log_commited_revoke) reserved += gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke, sizeof(uint64_t)); diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 3d792f81e48c..4bd89c0781e7 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -137,7 +137,8 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp) memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved)); n = 0; - list_for_each_entry_continue(bd1, &sdp->sd_log_le_buf, bd_le.le_list) { + list_for_each_entry_continue(bd1, &sdp->sd_log_le_buf, + bd_le.le_list) { *ptr++ = cpu_to_be64(bd1->bd_bh->b_blocknr); if (++n >= num) break; @@ -147,7 +148,8 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp) ll_rw_block(WRITE, 1, &bh); n = 0; - list_for_each_entry_continue(bd2, &sdp->sd_log_le_buf, bd_le.le_list) { + list_for_each_entry_continue(bd2, &sdp->sd_log_le_buf, + bd_le.le_list) { bh = gfs2_log_fake_buf(sdp, bd2->bd_bh); set_buffer_dirty(bh); ll_rw_block(WRITE, 1, &bh); @@ -239,7 +241,8 @@ static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; if (error) { - gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, + DIO_START | DIO_WAIT); return; } if (pass != 1) @@ -283,7 +286,8 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp) ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD); ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD); ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_REVOKE); - ld->ld_length = cpu_to_be32(gfs2_struct2blk(sdp, sdp->sd_log_num_revoke, sizeof(uint64_t))); + ld->ld_length = cpu_to_be32(gfs2_struct2blk(sdp, sdp->sd_log_num_revoke, + sizeof(uint64_t))); ld->ld_data1 = cpu_to_be32(sdp->sd_log_num_revoke); ld->ld_data2 = cpu_to_be32(0); memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved)); @@ -515,19 +519,24 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) * into the log along with a header */ gfs2_log_lock(sdp); - bd2 = bd1 = list_prepare_entry(bd1, &sdp->sd_log_le_databuf, bd_le.le_list); + bd2 = bd1 = list_prepare_entry(bd1, &sdp->sd_log_le_databuf, + bd_le.le_list); while(total_dbuf) { num = total_jdata; if (num > limit) num = limit; n = 0; - list_for_each_entry_safe_continue(bd1, bdt, &sdp->sd_log_le_databuf, bd_le.le_list) { + list_for_each_entry_safe_continue(bd1, bdt, + &sdp->sd_log_le_databuf, + bd_le.le_list) { /* An ordered write buffer */ if (bd1->bd_bh && !buffer_pinned(bd1->bd_bh)) { list_move(&bd1->bd_le.le_list, &started); if (bd1 == bd2) { bd2 = NULL; - bd2 = list_prepare_entry(bd2, &sdp->sd_log_le_databuf, bd_le.le_list); + bd2 = list_prepare_entry(bd2, + &sdp->sd_log_le_databuf, + bd_le.le_list); } total_dbuf--; if (bd1->bd_bh) { @@ -535,7 +544,8 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) if (buffer_dirty(bd1->bd_bh)) { gfs2_log_unlock(sdp); wait_on_buffer(bd1->bd_bh); - ll_rw_block(WRITE, 1, &bd1->bd_bh); + ll_rw_block(WRITE, 1, + &bd1->bd_bh); gfs2_log_lock(sdp); } brelse(bd1->bd_bh); @@ -547,12 +557,17 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) gfs2_log_unlock(sdp); if (!bh) { bh = gfs2_log_get_buf(sdp); - ld = (struct gfs2_log_descriptor *)bh->b_data; + ld = (struct gfs2_log_descriptor *) + bh->b_data; ptr = (__be64 *)(bh->b_data + offset); - ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC); - ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD); - ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD); - ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_JDATA); + ld->ld_header.mh_magic = + cpu_to_be32(GFS2_MAGIC); + ld->ld_header.mh_type = + cpu_to_be16(GFS2_METATYPE_LD); + ld->ld_header.mh_format = + cpu_to_be16(GFS2_FORMAT_LD); + ld->ld_type = + cpu_to_be32(GFS2_LOG_DESC_JDATA); ld->ld_length = cpu_to_be32(num + 1); ld->ld_data1 = cpu_to_be32(num); ld->ld_data2 = cpu_to_be32(0); @@ -577,7 +592,8 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) } n = 0; gfs2_log_lock(sdp); - list_for_each_entry_continue(bd2, &sdp->sd_log_le_databuf, bd_le.le_list) { + list_for_each_entry_continue(bd2, &sdp->sd_log_le_databuf, + bd_le.le_list) { if (!bd2->bd_bh) continue; /* copy buffer if it needs escaping */ @@ -587,7 +603,9 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) struct page *page = bd2->bd_bh->b_page; bh = gfs2_log_get_buf(sdp); kaddr = kmap_atomic(page, KM_USER0); - memcpy(bh->b_data, kaddr + bh_offset(bd2->bd_bh), sdp->sd_sb.sb_bsize); + memcpy(bh->b_data, + kaddr + bh_offset(bd2->bd_bh), + sdp->sd_sb.sb_bsize); kunmap_atomic(page, KM_USER0); *(__be32 *)bh->b_data = 0; } else { @@ -608,7 +626,8 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) /* Wait on all ordered buffers */ while (!list_empty(&started)) { gfs2_log_lock(sdp); - bd1 = list_entry(started.next, struct gfs2_bufdata, bd_le.le_list); + bd1 = list_entry(started.next, struct gfs2_bufdata, + bd_le.le_list); list_del(&bd1->bd_le.le_list); sdp->sd_log_num_databuf--; @@ -685,7 +704,8 @@ static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; if (error) { - gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, + DIO_START | DIO_WAIT); return; } if (pass != 1) diff --git a/fs/gfs2/lvb.c b/fs/gfs2/lvb.c index 8af62568a3f4..ca959ebb80c1 100644 --- a/fs/gfs2/lvb.c +++ b/fs/gfs2/lvb.c @@ -16,7 +16,8 @@ #include "gfs2.h" -#define pv(struct, member, fmt) printk(" "#member" = "fmt"\n", struct->member); +#define pv(struct, member, fmt) printk(KERN_INFO " "#member" = "fmt"\n", \ + struct->member); void gfs2_quota_lvb_in(struct gfs2_quota_lvb *qb, char *lvb) { diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index f4c4dfbf6986..53f33fa899f9 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -542,7 +542,8 @@ int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags) * @meta: Flag to indicate whether its metadata or not */ -void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta) +void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, + int meta) { struct gfs2_bufdata *bd; @@ -818,7 +819,8 @@ void gfs2_meta_ra(struct gfs2_glock *gl, uint64_t dblock, uint32_t extlen) struct gfs2_sbd *sdp = gl->gl_sbd; struct inode *aspace = gl->gl_aspace; struct buffer_head *first_bh, *bh; - uint32_t max_ra = gfs2_tune_get(sdp, gt_max_readahead) >> sdp->sd_sb.sb_bsize_shift; + uint32_t max_ra = gfs2_tune_get(sdp, gt_max_readahead) >> + sdp->sd_sb.sb_bsize_shift; int error; if (!extlen || !max_ra) diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index 887cac302c1b..d72144d5d727 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h @@ -64,7 +64,8 @@ int gfs2_meta_read(struct gfs2_glock *gl, uint64_t blkno, int flags, struct buffer_head **bhp); int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags); -void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta); +void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, + int meta); void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, struct gfs2_ail *ai); diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index 964abd2760ff..5a0bdc22a1f4 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -17,7 +17,8 @@ #include "gfs2.h" #include -#define pv(struct, member, fmt) printk(KERN_INFO " "#member" = "fmt"\n", struct->member); +#define pv(struct, member, fmt) printk(KERN_INFO " "#member" = "fmt"\n", \ + struct->member); #define pa(struct, member, count) print_array(#member, struct->member, count); /** diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 8f839120a473..89a8b8fad2e7 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -357,7 +357,8 @@ static int gfs2_prepare_write(struct file *file, struct page *page, if (gfs2_is_stuffed(ip)) { if (end > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) { - error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, page); + error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, + page); if (error == 0) goto prepare_write; } else if (!PageUptodate(page)) @@ -432,7 +433,8 @@ static int gfs2_commit_write(struct file *file, struct page *page, if (inode->i_size < file_size) i_size_write(inode, file_size); } else { - if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) + if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || + gfs2_is_jdata(ip)) gfs2_page_add_databufs(ip, page, from, to); error = generic_commit_write(file, page, from, to); if (error) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 989f0f70fc2e..e6ae2551b0cb 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -531,7 +531,8 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) static int gfs2_ioctl_flags(struct gfs2_inode *ip, unsigned int cmd, unsigned long arg) { - unsigned int lmode = (cmd == GFS2_IOCTL_SETFLAGS) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; + unsigned int lmode = (cmd == GFS2_IOCTL_SETFLAGS) ? + LM_ST_EXCLUSIVE : LM_ST_SHARED; struct buffer_head *dibh; struct gfs2_holder i_gh; int error; @@ -559,7 +560,8 @@ static int gfs2_ioctl_flags(struct gfs2_inode *ip, unsigned int cmd, if (!S_ISREG(ip->i_di.di_mode)) goto out; } - if (flags & (GFS2_DIF_INHERIT_JDATA|GFS2_DIF_INHERIT_DIRECTIO)) { + if (flags & + (GFS2_DIF_INHERIT_JDATA|GFS2_DIF_INHERIT_DIRECTIO)) { if (!S_ISDIR(ip->i_di.di_mode)) goto out; } diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index a85f1a2676f6..535f020f1e0c 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -128,7 +128,8 @@ static void init_vfs(struct gfs2_sbd *sdp) to allow us to read-in the on-disk superblock. */ sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK); sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; - sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT; + sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - + GFS2_BASIC_BLOCK_SHIFT; sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; } @@ -435,7 +436,8 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) goto fail_jindex; } - error = gfs2_glock_nq_init(get_v2ip(sdp->sd_jdesc->jd_inode)->i_gl, + error = gfs2_glock_nq_init( + get_v2ip(sdp->sd_jdesc->jd_inode)->i_gl, LM_ST_SHARED, LM_FLAG_NOEXP | GL_EXACT, &sdp->sd_jinode_gh); diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index 808110e3ec5e..bfeb920dccee 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -68,7 +68,8 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) { struct gfs2_sbd *sdp = ip->i_sbd; unsigned long index = page->index; - uint64_t lblock = index << (PAGE_CACHE_SHIFT - sdp->sd_sb.sb_bsize_shift); + uint64_t lblock = index << (PAGE_CACHE_SHIFT - + sdp->sd_sb.sb_bsize_shift); unsigned int blocks = PAGE_CACHE_SIZE >> sdp->sd_sb.sb_bsize_shift; struct gfs2_alloc *al; unsigned int data_blocks, ind_blocks; @@ -143,7 +144,8 @@ static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, struct gfs2_inode *ip = get_v2ip(area->vm_file->f_mapping->host); struct gfs2_holder i_gh; struct page *result = NULL; - unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) + area->vm_pgoff; + unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) + + area->vm_pgoff; int alloc_required; int error; diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index c0352cf330a3..40c7cf87eb44 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -395,7 +395,8 @@ static int qd_trylock(struct gfs2_quota_data *qd) static void qd_unlock(struct gfs2_quota_data *qd) { - gfs2_assert_warn(qd->qd_gl->gl_sbd, test_bit(QDF_LOCKED, &qd->qd_flags)); + gfs2_assert_warn(qd->qd_gl->gl_sbd, + test_bit(QDF_LOCKED, &qd->qd_flags)); clear_bit(QDF_LOCKED, &qd->qd_flags); bh_put(qd); slot_put(qd); @@ -715,7 +716,8 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) qd = qda[x]; offset = qd2offset(qd); error = gfs2_adjust_quota(ip, offset, qd->qd_change_sync, - (struct gfs2_quota_data *)qd->qd_gl->gl_lvb); + (struct gfs2_quota_data *) + qd->qd_gl->gl_lvb); if (error) goto out_end_trans; @@ -932,7 +934,8 @@ static int print_message(struct gfs2_quota_data *qd, char *type) if (!line) return -ENOMEM; - len = snprintf(line, MAX_LINE-1, "GFS2: fsid=%s: quota %s for %s %u\r\n", + len = snprintf(line, MAX_LINE-1, + "GFS2: fsid=%s: quota %s for %s %u\r\n", sdp->sd_fsname, type, (test_bit(QDF_USER, &qd->qd_flags)) ? "user" : "group", qd->qd_id); @@ -981,7 +984,8 @@ int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) } else if (qd->qd_qb.qb_warn && (int64_t)qd->qd_qb.qb_warn < value && time_after_eq(jiffies, qd->qd_last_warn + - gfs2_tune_get(sdp, gt_quota_warn_period) * HZ)) { + gfs2_tune_get(sdp, + gt_quota_warn_period) * HZ)) { error = print_message(qd, "warning"); qd->qd_last_warn = jiffies; } diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index bcb81c768c8b..e5f2b284fa54 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -33,7 +33,8 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, uint32_t extlen; int error; - error = gfs2_block_map(get_v2ip(jd->jd_inode), blk, &new, &dblock, &extlen); + error = gfs2_block_map(get_v2ip(jd->jd_inode), blk, &new, &dblock, + &extlen); if (error) return error; if (!dblock) { diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 2e69e5cda967..9525b176f502 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -233,7 +233,8 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd) bi->bi_len = bytes; /* other blocks */ } else { - bytes = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header); + bytes = sdp->sd_sb.sb_bsize - + sizeof(struct gfs2_meta_header); bi->bi_offset = sizeof(struct gfs2_meta_header); bi->bi_start = rgd->rd_ri.ri_bitbytes - bytes_left; bi->bi_len = bytes; diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 60e266618729..2c1c6aa1c077 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -110,36 +110,43 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent) break; if (!gfs2_old_fs_formats[x]) { - printk(KERN_WARNING "GFS2: code version (%u, %u) is incompatible " + printk(KERN_WARNING + "GFS2: code version (%u, %u) is incompatible " "with ondisk format (%u, %u)\n", GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, sb->sb_fs_format, sb->sb_multihost_format); - printk(KERN_WARNING "GFS2: I don't know how to upgrade this FS\n"); + printk(KERN_WARNING + "GFS2: I don't know how to upgrade this FS\n"); return -EINVAL; } } if (sb->sb_multihost_format != GFS2_FORMAT_MULTI) { for (x = 0; gfs2_old_multihost_formats[x]; x++) - if (gfs2_old_multihost_formats[x] == sb->sb_multihost_format) + if (gfs2_old_multihost_formats[x] == + sb->sb_multihost_format) break; if (!gfs2_old_multihost_formats[x]) { - printk(KERN_WARNING "GFS2: code version (%u, %u) is incompatible " + printk(KERN_WARNING + "GFS2: code version (%u, %u) is incompatible " "with ondisk format (%u, %u)\n", GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, sb->sb_fs_format, sb->sb_multihost_format); - printk(KERN_WARNING "GFS2: I don't know how to upgrade this FS\n"); + printk(KERN_WARNING + "GFS2: I don't know how to upgrade this FS\n"); return -EINVAL; } } if (!sdp->sd_args.ar_upgrade) { - printk(KERN_WARNING "GFS2: code version (%u, %u) is incompatible " + printk(KERN_WARNING + "GFS2: code version (%u, %u) is incompatible " "with ondisk format (%u, %u)\n", GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, sb->sb_fs_format, sb->sb_multihost_format); - printk(KERN_INFO "GFS2: Use the \"upgrade\" mount option to upgrade " + printk(KERN_INFO + "GFS2: Use the \"upgrade\" mount option to upgrade " "the FS\n"); printk(KERN_INFO "GFS2: See the manual for more details\n"); return -EINVAL; @@ -289,7 +296,8 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) name.len = sprintf(buf, "journal%u", sdp->sd_journals); - error = gfs2_dir_search(get_v2ip(sdp->sd_jindex), &name, NULL, NULL); + error = gfs2_dir_search(get_v2ip(sdp->sd_jindex), + &name, NULL, NULL); if (error == -ENOENT) { error = 0; break; @@ -445,7 +453,8 @@ int gfs2_lookup_master_dir(struct gfs2_sbd *sdp) sdp->sd_sb.sb_master_dir.no_addr, &gfs2_inode_glops, CREATE, &gl); if (!error) { - error = gfs2_lookup_simple(sdp->sd_root_dir, ".gfs2_admin", &inode); + error = gfs2_lookup_simple(sdp->sd_root_dir, ".gfs2_admin", + &inode); sdp->sd_master_dir = inode; gfs2_glock_put(gl); } @@ -854,7 +863,8 @@ int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh) error = -ENOMEM; goto out; } - error = gfs2_glock_nq_init(get_v2ip(jd->jd_inode)->i_gl, LM_ST_SHARED, 0, + error = gfs2_glock_nq_init(get_v2ip(jd->jd_inode)->i_gl, + LM_ST_SHARED, 0, &lfcc->gh); if (error) { kfree(lfcc); From f382894e8889a64f8daf747db477a16da2d54eb0 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 27 Feb 2006 12:07:05 -0500 Subject: [PATCH 053/292] [GFS2] 80 Column audit of locking modules Requested by: Prarit Bhargava Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/main.c | 6 ++++-- fs/gfs2/locking/nolock/main.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/gfs2/locking/dlm/main.c b/fs/gfs2/locking/dlm/main.c index 1c0943de9408..3c9adf18fd9c 100644 --- a/fs/gfs2/locking/dlm/main.c +++ b/fs/gfs2/locking/dlm/main.c @@ -22,7 +22,8 @@ int __init init_lock_dlm(void) error = gfs_register_lockproto(&gdlm_ops); if (error) { - printk(KERN_WARNING "lock_dlm: can't register protocol: %d\n", error); + printk(KERN_WARNING "lock_dlm: can't register protocol: %d\n", + error); return error; } @@ -42,7 +43,8 @@ int __init init_lock_dlm(void) gdlm_drop_count = GDLM_DROP_COUNT; gdlm_drop_period = GDLM_DROP_PERIOD; - printk(KERN_INFO "Lock_DLM (built %s %s) installed\n", __DATE__, __TIME__); + printk(KERN_INFO + "Lock_DLM (built %s %s) installed\n", __DATE__, __TIME__); return 0; } diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index 7ede0906b2c6..57f9e50832f0 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -243,11 +243,13 @@ int __init init_nolock(void) error = gfs_register_lockproto(&nolock_ops); if (error) { - printk(KERN_WARNING "lock_nolock: can't register protocol: %d\n", error); + printk(KERN_WARNING + "lock_nolock: can't register protocol: %d\n", error); return error; } - printk(KERN_INFO "Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__); + printk(KERN_INFO + "Lock_Nolock (built %s %s) installed\n", __DATE__, __TIME__); return 0; } From 116ad29d9839610d2811a1962cac7f3f2a9f9295 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 27 Feb 2006 12:11:18 -0500 Subject: [PATCH 054/292] [GFS2] Remove pointless comment from nolock/main.c As requested by: Pavel Machek Pavel's other comments will be dealt with in later patches. Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/nolock/main.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index 57f9e50832f0..9398309f2810 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -33,9 +33,6 @@ static int nolock_mount(char *table_name, char *host_data, unsigned int jid; struct nolock_lockspace *nl; - /* If there is a "jid=" in the hostdata, return that jid. - Otherwise, return zero. */ - c = strstr(host_data, "jid="); if (!c) jid = 0; From 5c676f6d359b0404d53f542f02e1359583cb2895 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 27 Feb 2006 17:23:27 -0500 Subject: [PATCH 055/292] [GFS2] Macros removal in gfs2.h As suggested by Pekka Enberg . The DIV_RU macro is renamed DIV_ROUND_UP and and moved to kernel.h The other macros are gone from gfs2.h as (although not requested by Pekka Enberg) are a number of included header file which are now included individually. The inode number comparison function is now an inline function. The DT2IF and IF2DT may be addressed in a future patch. Signed-off-by: Steven Whitehouse --- fs/gfs2/acl.c | 8 +++-- fs/gfs2/bits.c | 4 +++ fs/gfs2/bmap.c | 10 ++++-- fs/gfs2/daemon.c | 4 +++ fs/gfs2/dir.c | 8 +++-- fs/gfs2/eaops.c | 4 +++ fs/gfs2/eattr.c | 19 +++++++----- fs/gfs2/eattr.h | 2 +- fs/gfs2/gfs2.h | 29 ----------------- fs/gfs2/glock.c | 20 +++++++----- fs/gfs2/glops.c | 21 ++++++++----- fs/gfs2/incore.h | 8 +++++ fs/gfs2/inode.c | 38 +++++++++++++---------- fs/gfs2/lm.c | 5 +++ fs/gfs2/log.c | 8 +++-- fs/gfs2/lops.c | 56 ++++++++++++++++++++------------- fs/gfs2/lvb.c | 4 +++ fs/gfs2/lvb.h | 8 ----- fs/gfs2/main.c | 4 +++ fs/gfs2/meta_io.c | 37 ++++++++++++---------- fs/gfs2/mount.c | 4 +++ fs/gfs2/ops_address.c | 34 +++++++++++--------- fs/gfs2/ops_dentry.c | 8 +++-- fs/gfs2/ops_export.c | 17 +++++----- fs/gfs2/ops_file.c | 40 +++++++++++++----------- fs/gfs2/ops_fstype.c | 35 ++++++++++++++------- fs/gfs2/ops_inode.c | 62 ++++++++++++++++++++----------------- fs/gfs2/ops_super.c | 26 +++++++++------- fs/gfs2/ops_vm.c | 8 +++-- fs/gfs2/page.c | 12 ++++--- fs/gfs2/quota.c | 20 +++++++----- fs/gfs2/recovery.c | 29 ++++++++++------- fs/gfs2/rgrp.c | 10 ++++-- fs/gfs2/super.c | 36 ++++++++++++--------- fs/gfs2/sys.c | 4 +++ fs/gfs2/trans.c | 19 +++++++----- fs/gfs2/unlinked.c | 11 +++++-- fs/gfs2/util.c | 4 +++ include/linux/gfs2_ondisk.h | 11 ++++--- include/linux/kernel.h | 1 + 40 files changed, 416 insertions(+), 272 deletions(-) diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index 9482a677ea47..e9d05fe94357 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -15,8 +15,11 @@ #include #include #include +#include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "acl.h" #include "eaops.h" #include "eattr.h" @@ -24,6 +27,7 @@ #include "inode.h" #include "meta_io.h" #include "trans.h" +#include "util.h" #define ACL_ACCESS 1 #define ACL_DEFAULT 0 @@ -157,7 +161,7 @@ int gfs2_check_acl_locked(struct inode *inode, int mask) struct posix_acl *acl = NULL; int error; - error = acl_get(get_v2ip(inode), ACL_ACCESS, &acl, NULL, NULL, NULL); + error = acl_get(inode->u.generic_ip, ACL_ACCESS, &acl, NULL, NULL, NULL); if (error) return error; @@ -172,7 +176,7 @@ int gfs2_check_acl_locked(struct inode *inode, int mask) int gfs2_check_acl(struct inode *inode, int mask) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_holder i_gh; int error; diff --git a/fs/gfs2/bits.c b/fs/gfs2/bits.c index 57d420a86adf..49585e3de095 100644 --- a/fs/gfs2/bits.c +++ b/fs/gfs2/bits.c @@ -21,10 +21,14 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bits.h" +#include "util.h" static const char valid_change[16] = { /* current */ diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index e132d8a41008..cd5e4d863ce2 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -12,9 +12,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "glock.h" #include "inode.h" @@ -24,6 +27,7 @@ #include "rgrp.h" #include "trans.h" #include "dir.h" +#include "util.h" /* This doesn't need to be that large as max 64 bit pointers in a 4k * block is 512, so __u16 is fine for that. It saves stack space to @@ -660,7 +664,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, for (x = 0; x < rlist.rl_rgrps; x++) { struct gfs2_rgrpd *rgd; - rgd = get_gl2rgd(rlist.rl_ghs[x].gh_gl); + rgd = rlist.rl_ghs[x].gh_gl->gl_object; rg_blocks += rgd->rd_ri.ri_length; } @@ -1021,7 +1025,7 @@ void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, unsigned int tmp; if (gfs2_is_dir(ip)) { - *data_blocks = DIV_RU(len, sdp->sd_jbsize) + 2; + *data_blocks = DIV_ROUND_UP(len, sdp->sd_jbsize) + 2; *ind_blocks = 3 * (sdp->sd_max_jheight - 1); } else { *data_blocks = (len >> sdp->sd_sb.sb_bsize_shift) + 3; @@ -1029,7 +1033,7 @@ void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, } for (tmp = *data_blocks; tmp > sdp->sd_diptrs;) { - tmp = DIV_RU(tmp, sdp->sd_inptrs); + tmp = DIV_ROUND_UP(tmp, sdp->sd_inptrs); *ind_blocks += tmp; } } diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c index cff8d5368d21..94317dc7e42c 100644 --- a/fs/gfs2/daemon.c +++ b/fs/gfs2/daemon.c @@ -14,9 +14,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "daemon.h" #include "glock.h" #include "log.h" @@ -24,6 +27,7 @@ #include "recovery.h" #include "super.h" #include "unlinked.h" +#include "util.h" /* This uses schedule_timeout() instead of msleep() because it's good for the daemons to wake up more often than the timeout when unmounting so diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 56683788a6cf..37f70ca558cc 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -59,9 +59,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "dir.h" #include "glock.h" #include "inode.h" @@ -70,6 +73,7 @@ #include "rgrp.h" #include "trans.h" #include "bmap.h" +#include "util.h" #define IS_LEAF 1 /* Hashed (leaf) directory */ #define IS_DINODE 2 /* Linear (stuffed dinode block) directory */ @@ -2196,7 +2200,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, for (x = 0; x < rlist.rl_rgrps; x++) { struct gfs2_rgrpd *rgd; - rgd = get_gl2rgd(rlist.rl_ghs[x].gh_gl); + rgd = rlist.rl_ghs[x].gh_gl->gl_object; rg_blocks += rgd->rd_ri.ri_length; } @@ -2205,7 +2209,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, goto out_rlist; error = gfs2_trans_begin(sdp, - rg_blocks + (DIV_RU(size, sdp->sd_jbsize) + 1) + + rg_blocks + (DIV_ROUND_UP(size, sdp->sd_jbsize) + 1) + RES_DINODE + RES_STATFS + RES_QUOTA, l_blocks); if (error) goto out_rg_gunlock; diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index 2914731250c5..4b9f6cff7a34 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -13,13 +13,17 @@ #include #include #include +#include #include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "acl.h" #include "eaops.h" #include "eattr.h" +#include "util.h" /** * gfs2_ea_name2type - get the type of the ea, and truncate type from the name diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 146995d9cd65..8219d471f06c 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -13,10 +13,13 @@ #include #include #include +#include #include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "acl.h" #include "eaops.h" #include "eattr.h" @@ -26,6 +29,7 @@ #include "quota.h" #include "rgrp.h" #include "trans.h" +#include "util.h" /** * ea_calc_size - returns the acutal number of bytes the request will take up @@ -478,7 +482,7 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, struct gfs2_sbd *sdp = ip->i_sbd; struct buffer_head **bh; unsigned int amount = GFS2_EA_DATA_LEN(ea); - unsigned int nptrs = DIV_RU(amount, sdp->sd_jbsize); + unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); uint64_t *dataptrs = GFS2_EA2DATAPTRS(ea); unsigned int x; int error = 0; @@ -676,7 +680,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, unsigned int copy; unsigned int x; - ea->ea_num_ptrs = DIV_RU(er->er_data_len, sdp->sd_jbsize); + ea->ea_num_ptrs = DIV_ROUND_UP(er->er_data_len, sdp->sd_jbsize); for (x = 0; x < ea->ea_num_ptrs; x++) { struct buffer_head *bh; uint64_t block; @@ -810,7 +814,7 @@ static int ea_init(struct gfs2_inode *ip, struct gfs2_ea_request *er) unsigned int blks = 1; if (GFS2_EAREQ_SIZE_STUFFED(er) > jbsize) - blks += DIV_RU(er->er_data_len, jbsize); + blks += DIV_ROUND_UP(er->er_data_len, jbsize); return ea_alloc_skeleton(ip, er, blks, ea_init_i, NULL); } @@ -962,7 +966,8 @@ static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh, es->es_bh = bh; es->es_ea = ea; - blks = 2 + DIV_RU(es->es_er->er_data_len, ip->i_sbd->sd_jbsize); + blks = 2 + DIV_ROUND_UP(es->es_er->er_data_len, + ip->i_sbd->sd_jbsize); error = ea_alloc_skeleton(ip, es->es_er, blks, ea_set_simple_alloc, es); @@ -1066,7 +1071,7 @@ static int ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er, if (!(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT)) blks++; if (GFS2_EAREQ_SIZE_STUFFED(er) > ip->i_sbd->sd_jbsize) - blks += DIV_RU(er->er_data_len, ip->i_sbd->sd_jbsize); + blks += DIV_ROUND_UP(er->er_data_len, ip->i_sbd->sd_jbsize); return ea_alloc_skeleton(ip, er, blks, ea_set_block, el); } @@ -1250,7 +1255,7 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, struct gfs2_sbd *sdp = ip->i_sbd; struct buffer_head **bh; unsigned int amount = GFS2_EA_DATA_LEN(ea); - unsigned int nptrs = DIV_RU(amount, sdp->sd_jbsize); + unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); uint64_t *dataptrs = GFS2_EA2DATAPTRS(ea); unsigned int x; int error; @@ -1402,7 +1407,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) for (x = 0; x < rlist.rl_rgrps; x++) { struct gfs2_rgrpd *rgd; - rgd = get_gl2rgd(rlist.rl_ghs[x].gh_gl); + rgd = rlist.rl_ghs[x].gh_gl->gl_object; rg_blocks += rgd->rd_ri.ri_length; } diff --git a/fs/gfs2/eattr.h b/fs/gfs2/eattr.h index e5a42abf68a3..2b4152b1fcbe 100644 --- a/fs/gfs2/eattr.h +++ b/fs/gfs2/eattr.h @@ -29,7 +29,7 @@ ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + (er)->er_data_len, 8) #define GFS2_EAREQ_SIZE_UNSTUFFED(sdp, er) \ ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + \ - sizeof(uint64_t) * DIV_RU((er)->er_data_len, (sdp)->sd_jbsize), 8) + sizeof(uint64_t) * DIV_ROUND_UP((er)->er_data_len, (sdp)->sd_jbsize), 8) #define GFS2_EA2NAME(ea) ((char *)((struct gfs2_ea_header *)(ea) + 1)) #define GFS2_EA2DATA(ea) (GFS2_EA2NAME(ea) + (ea)->ea_name_len) diff --git a/fs/gfs2/gfs2.h b/fs/gfs2/gfs2.h index 6c53d080675c..57175f70e2bd 100644 --- a/fs/gfs2/gfs2.h +++ b/fs/gfs2/gfs2.h @@ -10,13 +10,6 @@ #ifndef __GFS2_DOT_H__ #define __GFS2_DOT_H__ -#include - -#include "lm_interface.h" -#include "lvb.h" -#include "incore.h" -#include "util.h" - enum { NO_CREATE = 0, CREATE = 1, @@ -32,29 +25,7 @@ enum { FORCE = 1, }; -/* Divide num by den. Round up if there is a remainder. */ -#define DIV_RU(num, den) (((num) + (den) - 1) / (den)) - #define GFS2_FAST_NAME_SIZE 8 -#define get_v2sdp(sb) ((struct gfs2_sbd *)(sb)->s_fs_info) -#define set_v2sdp(sb, sdp) (sb)->s_fs_info = (sdp) -#define get_v2ip(inode) ((struct gfs2_inode *)(inode)->u.generic_ip) -#define set_v2ip(inode, ip) (inode)->u.generic_ip = (ip) -#define get_v2fp(file) ((struct gfs2_file *)(file)->private_data) -#define set_v2fp(file, fp) (file)->private_data = (fp) -#define get_v2bd(bh) ((struct gfs2_bufdata *)(bh)->b_private) -#define set_v2bd(bh, bd) (bh)->b_private = (bd) - -#define get_transaction ((struct gfs2_trans *)(current->journal_info)) -#define set_transaction(tr) (current->journal_info) = (tr) - -#define get_gl2ip(gl) ((struct gfs2_inode *)(gl)->gl_object) -#define set_gl2ip(gl, ip) (gl)->gl_object = (ip) -#define get_gl2rgd(gl) ((struct gfs2_rgrpd *)(gl)->gl_object) -#define set_gl2rgd(gl, rgd) (gl)->gl_object = (rgd) -#define get_gl2gl(gl) ((struct gfs2_glock *)(gl)->gl_object) -#define set_gl2gl(gl, gl2) (gl)->gl_object = (gl2) - #endif /* __GFS2_DOT_H__ */ diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index f30fde91d14a..81b06812b329 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -16,10 +16,13 @@ #include #include #include +#include #include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "glock.h" #include "glops.h" #include "inode.h" @@ -28,6 +31,7 @@ #include "meta_io.h" #include "quota.h" #include "super.h" +#include "util.h" /* Must be kept in sync with the beginning of struct gfs2_glock */ struct glock_plug { @@ -1962,7 +1966,7 @@ void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum) if (!gfs2_glmutex_trylock(gl)) goto out; - ip = get_gl2ip(gl); + ip = gl->gl_object; if (!ip) goto out_unlock; @@ -1994,7 +1998,7 @@ void gfs2_iopen_go_callback(struct gfs2_glock *io_gl, unsigned int state) return; spin_lock(&io_gl->gl_spin); - i_gl = get_gl2gl(io_gl); + i_gl = io_gl->gl_object; if (i_gl) { gfs2_glock_hold(i_gl); spin_unlock(&io_gl->gl_spin); @@ -2004,7 +2008,7 @@ void gfs2_iopen_go_callback(struct gfs2_glock *io_gl, unsigned int state) } if (gfs2_glmutex_trylock(i_gl)) { - struct gfs2_inode *ip = get_gl2ip(i_gl); + struct gfs2_inode *ip = i_gl->gl_object; if (ip) { gfs2_try_toss_vnode(ip); gfs2_glmutex_unlock(i_gl); @@ -2093,7 +2097,7 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp) if (gfs2_glmutex_trylock(gl)) { if (gl->gl_ops == &gfs2_inode_glops) { - struct gfs2_inode *ip = get_gl2ip(gl); + struct gfs2_inode *ip = gl->gl_object; if (ip && !atomic_read(&ip->i_count)) gfs2_inode_destroy(ip); } @@ -2174,7 +2178,7 @@ static void scan_glock(struct gfs2_glock *gl) { if (gfs2_glmutex_trylock(gl)) { if (gl->gl_ops == &gfs2_inode_glops) { - struct gfs2_inode *ip = get_gl2ip(gl); + struct gfs2_inode *ip = gl->gl_object; if (ip && !atomic_read(&ip->i_count)) goto out_schedule; } @@ -2234,7 +2238,7 @@ static void clear_glock(struct gfs2_glock *gl) if (gfs2_glmutex_trylock(gl)) { if (gl->gl_ops == &gfs2_inode_glops) { - struct gfs2_inode *ip = get_gl2ip(gl); + struct gfs2_inode *ip = gl->gl_object; if (ip && !atomic_read(&ip->i_count)) gfs2_inode_destroy(ip); } @@ -2430,10 +2434,10 @@ static int dump_glock(struct gfs2_glock *gl) if (error) goto out; } - if (gl->gl_ops == &gfs2_inode_glops && get_gl2ip(gl)) { + if (gl->gl_ops == &gfs2_inode_glops && gl->gl_object) { if (!test_bit(GLF_LOCK, &gl->gl_flags) && list_empty(&gl->gl_holders)) { - error = dump_inode(get_gl2ip(gl)); + error = dump_inode(gl->gl_object); if (error) goto out; } else { diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 27374306ecde..d9334eb72df8 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -12,9 +12,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "glock.h" #include "glops.h" @@ -24,6 +27,7 @@ #include "page.h" #include "recovery.h" #include "rgrp.h" +#include "util.h" /** * meta_go_sync - sync out the metadata for this glock @@ -193,7 +197,7 @@ static int inode_go_demote_ok(struct gfs2_glock *gl) struct gfs2_sbd *sdp = gl->gl_sbd; int demote = 0; - if (!get_gl2ip(gl) && !gl->gl_aspace->i_mapping->nrpages) + if (!gl->gl_object && !gl->gl_aspace->i_mapping->nrpages) demote = 1; else if (!sdp->sd_args.ar_localcaching && time_after_eq(jiffies, gl->gl_stamp + @@ -214,7 +218,7 @@ static int inode_go_demote_ok(struct gfs2_glock *gl) static int inode_go_lock(struct gfs2_holder *gh) { struct gfs2_glock *gl = gh->gh_gl; - struct gfs2_inode *ip = get_gl2ip(gl); + struct gfs2_inode *ip = gl->gl_object; int error = 0; if (!ip) @@ -246,7 +250,7 @@ static int inode_go_lock(struct gfs2_holder *gh) static void inode_go_unlock(struct gfs2_holder *gh) { struct gfs2_glock *gl = gh->gh_gl; - struct gfs2_inode *ip = get_gl2ip(gl); + struct gfs2_inode *ip = gl->gl_object; if (ip && test_bit(GLF_DIRTY, &gl->gl_flags)) gfs2_inode_attr_in(ip); @@ -264,7 +268,7 @@ static void inode_go_unlock(struct gfs2_holder *gh) static void inode_greedy(struct gfs2_glock *gl) { struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_inode *ip = get_gl2ip(gl); + struct gfs2_inode *ip = gl->gl_object; unsigned int quantum = gfs2_tune_get(sdp, gt_greedy_quantum); unsigned int max = gfs2_tune_get(sdp, gt_greedy_max); unsigned int new_time; @@ -311,7 +315,7 @@ static int rgrp_go_demote_ok(struct gfs2_glock *gl) static int rgrp_go_lock(struct gfs2_holder *gh) { - return gfs2_rgrp_bh_get(get_gl2rgd(gh->gh_gl)); + return gfs2_rgrp_bh_get(gh->gh_gl->gl_object); } /** @@ -324,7 +328,7 @@ static int rgrp_go_lock(struct gfs2_holder *gh) static void rgrp_go_unlock(struct gfs2_holder *gh) { - gfs2_rgrp_bh_put(get_gl2rgd(gh->gh_gl)); + gfs2_rgrp_bh_put(gh->gh_gl->gl_object); } /** @@ -358,13 +362,14 @@ static void trans_go_xmote_th(struct gfs2_glock *gl, unsigned int state, static void trans_go_xmote_bh(struct gfs2_glock *gl) { struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_glock *j_gl = get_v2ip(sdp->sd_jdesc->jd_inode)->i_gl; + struct gfs2_inode *ip = sdp->sd_jdesc->jd_inode->u.generic_ip; + struct gfs2_glock *j_gl = ip->i_gl; struct gfs2_log_header head; int error; if (gl->gl_state != LM_ST_UNLOCKED && test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { - gfs2_meta_cache_flush(get_v2ip(sdp->sd_jdesc->jd_inode)); + gfs2_meta_cache_flush(sdp->sd_jdesc->jd_inode->u.generic_ip); j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA); error = gfs2_find_jhead(sdp->sd_jdesc, &head); diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 0e550e8e5be3..2443e9aad598 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -313,6 +313,14 @@ enum { QDF_LOCKED = 2, }; +struct gfs2_quota_lvb { + uint32_t qb_magic; + uint32_t __pad; + uint64_t qb_limit; /* Hard limit of # blocks to alloc */ + uint64_t qb_warn; /* Warn user when alloc is above this # */ + int64_t qb_value; /* Current # blocks allocated */ +}; + struct gfs2_quota_data { struct list_head qd_list; unsigned int qd_count; diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 51ecdb8503b0..ea9e996f3673 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -14,9 +14,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "acl.h" #include "bmap.h" #include "dir.h" @@ -33,6 +36,7 @@ #include "rgrp.h" #include "trans.h" #include "unlinked.h" +#include "util.h" /** * inode_attr_in - Copy attributes from the dinode into the VFS inode @@ -176,7 +180,7 @@ struct inode *gfs2_ip2v(struct gfs2_inode *ip) init_special_inode(tmp, tmp->i_mode, tmp->i_rdev); } - set_v2ip(tmp, NULL); + tmp->u.generic_ip = NULL; for (;;) { spin_lock(&ip->i_spin); @@ -196,7 +200,7 @@ struct inode *gfs2_ip2v(struct gfs2_inode *ip) gfs2_inode_hold(ip); ip->i_vnode = inode; - set_v2ip(inode, ip); + inode->u.generic_ip = ip; spin_unlock(&ip->i_spin); @@ -207,7 +211,7 @@ struct inode *gfs2_ip2v(struct gfs2_inode *ip) static int iget_test(struct inode *inode, void *opaque) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_inum *inum = (struct gfs2_inum *)opaque; if (ip && ip->i_num.no_addr == inum->no_addr) @@ -320,11 +324,11 @@ static int inode_create(struct gfs2_glock *i_gl, struct gfs2_inum *inum, spin_lock(&io_gl->gl_spin); gfs2_glock_hold(i_gl); - set_gl2gl(io_gl, i_gl); + io_gl->gl_object = i_gl; spin_unlock(&io_gl->gl_spin); gfs2_glock_hold(i_gl); - set_gl2ip(i_gl, ip); + i_gl->gl_object = ip; atomic_inc(&sdp->sd_inode_count); @@ -359,7 +363,7 @@ int gfs2_inode_get(struct gfs2_glock *i_gl, struct gfs2_inum *inum, int create, gfs2_glmutex_lock(i_gl); - *ipp = get_gl2ip(i_gl); + *ipp = i_gl->gl_object; if (*ipp) { error = -ESTALE; if ((*ipp)->i_num.no_formal_ino != inum->no_formal_ino) @@ -404,10 +408,10 @@ void gfs2_inode_destroy(struct gfs2_inode *ip) struct gfs2_glock *i_gl = ip->i_gl; gfs2_assert_warn(sdp, !atomic_read(&ip->i_count)); - gfs2_assert(sdp, get_gl2gl(io_gl) == i_gl); + gfs2_assert(sdp, io_gl->gl_object == i_gl); spin_lock(&io_gl->gl_spin); - set_gl2gl(io_gl, NULL); + io_gl->gl_object = NULL; gfs2_glock_put(i_gl); spin_unlock(&io_gl->gl_spin); @@ -416,7 +420,7 @@ void gfs2_inode_destroy(struct gfs2_inode *ip) gfs2_meta_cache_flush(ip); kmem_cache_free(gfs2_inode_cachep, ip); - set_gl2ip(i_gl, NULL); + i_gl->gl_object = NULL; gfs2_glock_put(i_gl); atomic_dec(&sdp->sd_inode_count); @@ -524,7 +528,7 @@ static int inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul, goto out; } - gfs2_assert_warn(sdp, !get_gl2ip(i_gh.gh_gl)); + gfs2_assert_warn(sdp, !i_gh.gh_gl->gl_object); error = inode_create(i_gh.gh_gl, &ul->ul_ut.ut_inum, io_gh->gh_gl, LM_ST_EXCLUSIVE, &ip); @@ -715,7 +719,7 @@ int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, struct inode **inodep) { struct gfs2_inode *ipp; - struct gfs2_inode *dip = get_v2ip(dir); + struct gfs2_inode *dip = dir->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; struct gfs2_holder d_gh; struct gfs2_inum inum; @@ -774,7 +778,7 @@ done: static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) { - struct gfs2_inode *ip = get_v2ip(sdp->sd_ir_inode); + struct gfs2_inode *ip = sdp->sd_ir_inode->u.generic_ip; struct buffer_head *bh; struct gfs2_inum_range ir; int error; @@ -815,8 +819,8 @@ static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) { - struct gfs2_inode *ip = get_v2ip(sdp->sd_ir_inode); - struct gfs2_inode *m_ip = get_v2ip(sdp->sd_inum_inode); + struct gfs2_inode *ip = sdp->sd_ir_inode->u.generic_ip; + struct gfs2_inode *m_ip = sdp->sd_inum_inode->u.generic_ip; struct gfs2_holder gh; struct buffer_head *bh; struct gfs2_inum_range ir; @@ -1194,7 +1198,7 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode) { struct inode *inode; - struct gfs2_inode *dip = get_gl2ip(ghs->gh_gl); + struct gfs2_inode *dip = ghs->gh_gl->gl_object; struct gfs2_sbd *sdp = dip->i_sbd; struct gfs2_unlinked *ul; struct gfs2_inode *ip; @@ -1570,7 +1574,7 @@ int gfs2_glock_nq_atime(struct gfs2_holder *gh) { struct gfs2_glock *gl = gh->gh_gl; struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_inode *ip = get_gl2ip(gl); + struct gfs2_inode *ip = gl->gl_object; int64_t curtime, quantum = gfs2_tune_get(sdp, gt_atime_quantum); unsigned int state; int flags; @@ -1817,7 +1821,7 @@ int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) { int error; - if (get_transaction) + if (current->journal_info) return __gfs2_setattr_simple(ip, attr); error = gfs2_trans_begin(ip->i_sbd, RES_DINODE, 0); diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index 3df8fa00442d..5b3c56d2df2f 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -13,12 +13,17 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "glock.h" #include "lm.h" #include "super.h" +#include "util.h" +#include "lvb.h" /** * gfs2_lm_mount - mount a locking protocol diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 0e31d46edd4d..32a41a274bf8 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -12,14 +12,18 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "glock.h" #include "log.h" #include "lops.h" #include "meta_io.h" +#include "util.h" #define PULL 1 @@ -80,7 +84,7 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, if (nstruct > first) { second = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header)) / ssize; - blks += DIV_RU(nstruct - first, second); + blks += DIV_ROUND_UP(nstruct - first, second); } return blks; @@ -257,7 +261,7 @@ static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) uint64_t dbn; int error; - error = gfs2_block_map(get_v2ip(sdp->sd_jdesc->jd_inode), + error = gfs2_block_map(sdp->sd_jdesc->jd_inode->u.generic_ip, lbn, &new, &dbn, NULL); gfs2_assert_withdraw(sdp, !error && dbn); diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 4bd89c0781e7..430161a05a21 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -12,9 +12,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "glock.h" #include "log.h" #include "lops.h" @@ -22,12 +25,14 @@ #include "recovery.h" #include "rgrp.h" #include "trans.h" +#include "util.h" static void glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) { struct gfs2_glock *gl; + struct gfs2_trans *tr = current->journal_info; - get_transaction->tr_touched = 1; + tr->tr_touched = 1; if (!list_empty(&le->le_list)) return; @@ -68,7 +73,7 @@ static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) if (!list_empty(&bd->bd_list_tr)) return; - tr = get_transaction; + tr = current->journal_info; tr->tr_touched = 1; tr->tr_num_buf++; list_add(&bd->bd_list_tr, &tr->tr_list_buf); @@ -179,7 +184,8 @@ static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) static void buf_lo_before_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head, int pass) { - struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; if (pass != 0) return; @@ -192,8 +198,9 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_log_descriptor *ld, __be64 *ptr, int pass) { - struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; - struct gfs2_glock *gl = get_v2ip(jd->jd_inode)->i_gl; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_glock *gl = ip->i_gl; unsigned int blks = be32_to_cpu(ld->ld_data1); struct buffer_head *bh_log, *bh_ip; uint64_t blkno; @@ -238,17 +245,18 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) { - struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; if (error) { - gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, + gfs2_meta_sync(ip->i_gl, DIO_START | DIO_WAIT); return; } if (pass != 1) return; - gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(ip->i_gl, DIO_START | DIO_WAIT); fs_info(sdp, "jid=%u: Replayed %u of %u blocks\n", jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); @@ -258,7 +266,7 @@ static void revoke_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) { struct gfs2_trans *tr; - tr = get_transaction; + tr = current->journal_info; tr->tr_touched = 1; tr->tr_num_revoke++; @@ -324,7 +332,8 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp) static void revoke_lo_before_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head, int pass) { - struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; if (pass != 0) return; @@ -337,7 +346,8 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_log_descriptor *ld, __be64 *ptr, int pass) { - struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; unsigned int blks = be32_to_cpu(ld->ld_length); unsigned int revokes = be32_to_cpu(ld->ld_data1); struct buffer_head *bh; @@ -383,7 +393,8 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, static void revoke_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) { - struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; if (error) { gfs2_revoke_clean(sdp); @@ -401,8 +412,9 @@ static void revoke_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) static void rg_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) { struct gfs2_rgrpd *rgd; + struct gfs2_trans *tr = current->journal_info; - get_transaction->tr_touched = 1; + tr->tr_touched = 1; if (!list_empty(&le->le_list)) return; @@ -451,9 +463,9 @@ static void rg_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) { struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le); - struct gfs2_trans *tr = get_transaction; + struct gfs2_trans *tr = current->journal_info; struct address_space *mapping = bd->bd_bh->b_page->mapping; - struct gfs2_inode *ip = get_v2ip(mapping->host); + struct gfs2_inode *ip = mapping->host->u.generic_ip; tr->tr_touched = 1; if (!list_empty(&bd->bd_list_tr) && @@ -633,7 +645,7 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) bh = bd1->bd_bh; if (bh) { - set_v2bd(bh, NULL); + bh->b_private = NULL; gfs2_log_unlock(sdp); wait_on_buffer(bh); brelse(bh); @@ -651,8 +663,9 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_log_descriptor *ld, __be64 *ptr, int pass) { - struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; - struct gfs2_glock *gl = get_v2ip(jd->jd_inode)->i_gl; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_glock *gl = ip->i_gl; unsigned int blks = be32_to_cpu(ld->ld_data1); struct buffer_head *bh_log, *bh_ip; uint64_t blkno; @@ -701,10 +714,11 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) { - struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; if (error) { - gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, + gfs2_meta_sync(ip->i_gl, DIO_START | DIO_WAIT); return; } @@ -712,7 +726,7 @@ static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) return; /* data sync? */ - gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(ip->i_gl, DIO_START | DIO_WAIT); fs_info(sdp, "jid=%u: Replayed %u of %u data blocks\n", jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); diff --git a/fs/gfs2/lvb.c b/fs/gfs2/lvb.c index ca959ebb80c1..63b815dad8e7 100644 --- a/fs/gfs2/lvb.c +++ b/fs/gfs2/lvb.c @@ -12,9 +12,13 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" +#include "lvb.h" #define pv(struct, member, fmt) printk(KERN_INFO " "#member" = "fmt"\n", \ struct->member); diff --git a/fs/gfs2/lvb.h b/fs/gfs2/lvb.h index ca9732b2d9f4..1b9eb69b9534 100644 --- a/fs/gfs2/lvb.h +++ b/fs/gfs2/lvb.h @@ -12,14 +12,6 @@ #define GFS2_MIN_LVB_SIZE 32 -struct gfs2_quota_lvb { - uint32_t qb_magic; - uint32_t __pad; - uint64_t qb_limit; /* Hard limit of # blocks to alloc */ - uint64_t qb_warn; /* Warn user when alloc is above this # */ - int64_t qb_value; /* Current # blocks allocated */ -}; - void gfs2_quota_lvb_in(struct gfs2_quota_lvb *qb, char *lvb); void gfs2_quota_lvb_out(struct gfs2_quota_lvb *qb, char *lvb); void gfs2_quota_lvb_print(struct gfs2_quota_lvb *qb); diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index 0c60f2b10fdd..c54177790318 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -14,11 +14,15 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "ops_fstype.h" #include "sys.h" +#include "util.h" /** * init_gfs2_fs - Register GFS2 as a filesystem diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 53f33fa899f9..b85fa2464666 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -17,9 +17,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "glock.h" #include "glops.h" #include "inode.h" @@ -28,6 +31,7 @@ #include "meta_io.h" #include "rgrp.h" #include "trans.h" +#include "util.h" #define buffer_busy(bh) \ ((bh)->b_state & ((1ul << BH_Dirty) | (1ul << BH_Lock) | (1ul << BH_Pinned))) @@ -37,7 +41,7 @@ static int aspace_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { - gfs2_assert_warn(get_v2sdp(inode->i_sb), 0); + gfs2_assert_warn(inode->i_sb->s_fs_info, 0); return -EOPNOTSUPP; } @@ -55,15 +59,15 @@ static int gfs2_aspace_writepage(struct page *page, static void stuck_releasepage(struct buffer_head *bh) { - struct gfs2_sbd *sdp = get_v2sdp(bh->b_page->mapping->host->i_sb); - struct gfs2_bufdata *bd = get_v2bd(bh); + struct gfs2_sbd *sdp = bh->b_page->mapping->host->i_sb->s_fs_info; + struct gfs2_bufdata *bd = bh->b_private; struct gfs2_glock *gl; fs_warn(sdp, "stuck in gfs2_releasepage()\n"); fs_warn(sdp, "blkno = %llu, bh->b_count = %d\n", (uint64_t)bh->b_blocknr, atomic_read(&bh->b_count)); fs_warn(sdp, "pinned = %u\n", buffer_pinned(bh)); - fs_warn(sdp, "get_v2bd(bh) = %s\n", (bd) ? "!NULL" : "NULL"); + fs_warn(sdp, "bh->b_private = %s\n", (bd) ? "!NULL" : "NULL"); if (!bd) return; @@ -78,7 +82,7 @@ static void stuck_releasepage(struct buffer_head *bh) (list_empty(&bd->bd_le.le_list)) ? "no" : "yes"); if (gl->gl_ops == &gfs2_inode_glops) { - struct gfs2_inode *ip = get_gl2ip(gl); + struct gfs2_inode *ip = gl->gl_object; unsigned int x; if (!ip) @@ -110,7 +114,7 @@ static void stuck_releasepage(struct buffer_head *bh) static int gfs2_aspace_releasepage(struct page *page, gfp_t gfp_mask) { struct inode *aspace = page->mapping->host; - struct gfs2_sbd *sdp = get_v2sdp(aspace->i_sb); + struct gfs2_sbd *sdp = aspace->i_sb->s_fs_info; struct buffer_head *bh, *head; struct gfs2_bufdata *bd; unsigned long t; @@ -139,14 +143,14 @@ static int gfs2_aspace_releasepage(struct page *page, gfp_t gfp_mask) gfs2_assert_warn(sdp, !buffer_pinned(bh)); - bd = get_v2bd(bh); + bd = bh->b_private; if (bd) { gfs2_assert_warn(sdp, bd->bd_bh == bh); gfs2_assert_warn(sdp, list_empty(&bd->bd_list_tr)); gfs2_assert_warn(sdp, list_empty(&bd->bd_le.le_list)); gfs2_assert_warn(sdp, !bd->bd_ail); kmem_cache_free(gfs2_bufdata_cachep, bd); - set_v2bd(bh, NULL); + bh->b_private = NULL; } bh = bh->b_this_page; @@ -184,7 +188,7 @@ struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp) mapping_set_gfp_mask(aspace->i_mapping, GFP_KERNEL); aspace->i_mapping->a_ops = &aspace_aops; aspace->i_size = ~0ULL; - set_v2ip(aspace, NULL); + aspace->u.generic_ip = NULL; insert_inode_hash(aspace); } @@ -523,7 +527,7 @@ int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags) wait_on_buffer(bh); if (!buffer_uptodate(bh)) { - struct gfs2_trans *tr = get_transaction; + struct gfs2_trans *tr = current->journal_info; if (tr && tr->tr_touched) gfs2_io_error_bh(sdp, bh); return -EIO; @@ -550,7 +554,7 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, if (meta) lock_page(bh->b_page); - if (get_v2bd(bh)) { + if (bh->b_private) { if (meta) unlock_page(bh->b_page); return; @@ -569,7 +573,7 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, lops_init_le(&bd->bd_le, &gfs2_databuf_lops); get_bh(bh); } - set_v2bd(bh, bd); + bh->b_private = bd; if (meta) unlock_page(bh->b_page); @@ -584,7 +588,7 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh) { - struct gfs2_bufdata *bd = get_v2bd(bh); + struct gfs2_bufdata *bd = bh->b_private; gfs2_assert_withdraw(sdp, test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)); @@ -621,7 +625,7 @@ void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh) void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, struct gfs2_ail *ai) { - struct gfs2_bufdata *bd = get_v2bd(bh); + struct gfs2_bufdata *bd = bh->b_private; gfs2_assert_withdraw(sdp, buffer_uptodate(bh)); @@ -662,15 +666,16 @@ void gfs2_meta_wipe(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) while (blen) { bh = getbuf(sdp, aspace, bstart, NO_CREATE); if (bh) { - struct gfs2_bufdata *bd = get_v2bd(bh); + struct gfs2_bufdata *bd = bh->b_private; if (test_clear_buffer_pinned(bh)) { + struct gfs2_trans *tr = current->journal_info; gfs2_log_lock(sdp); list_del_init(&bd->bd_le.le_list); gfs2_assert_warn(sdp, sdp->sd_log_num_buf); sdp->sd_log_num_buf--; gfs2_log_unlock(sdp); - get_transaction->tr_num_buf_rm++; + tr->tr_num_buf_rm++; brelse(bh); } if (bd) { diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c index 3e42697aafc7..e90ea7d32f9e 100644 --- a/fs/gfs2/mount.c +++ b/fs/gfs2/mount.c @@ -12,11 +12,15 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "mount.h" #include "sys.h" +#include "util.h" /** * gfs2_mount_args - Parse mount options diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 89a8b8fad2e7..01aa4a9b48c3 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -15,9 +15,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "glock.h" #include "inode.h" @@ -29,6 +32,7 @@ #include "trans.h" #include "rgrp.h" #include "ops_file.h" +#include "util.h" /** * gfs2_get_block - Fills in a buffer head with details about a block @@ -43,7 +47,7 @@ int gfs2_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; int new = create; uint64_t dblock; int error; @@ -75,7 +79,7 @@ int gfs2_get_block(struct inode *inode, sector_t lblock, static int get_block_noalloc(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; int new = 0; uint64_t dblock; int error; @@ -96,7 +100,7 @@ static int get_blocks(struct inode *inode, sector_t lblock, unsigned long max_blocks, struct buffer_head *bh_result, int create) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; int new = create; uint64_t dblock; uint32_t extlen; @@ -124,7 +128,7 @@ static int get_blocks_noalloc(struct inode *inode, sector_t lblock, unsigned long max_blocks, struct buffer_head *bh_result, int create) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; int new = 0; uint64_t dblock; uint32_t extlen; @@ -158,7 +162,7 @@ static int get_blocks_noalloc(struct inode *inode, sector_t lblock, static int gfs2_writepage(struct page *page, struct writeback_control *wbc) { struct inode *inode = page->mapping->host; - struct gfs2_inode *ip = get_v2ip(page->mapping->host); + struct gfs2_inode *ip = page->mapping->host->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; loff_t i_size = i_size_read(inode); pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT; @@ -170,7 +174,7 @@ static int gfs2_writepage(struct page *page, struct writeback_control *wbc) unlock_page(page); return -EIO; } - if (get_transaction) + if (current->journal_info) goto out_ignore; /* Is the page fully outside i_size? (truncate in progress) */ @@ -259,7 +263,7 @@ static int zero_readpage(struct page *page) static int gfs2_readpage(struct file *file, struct page *page) { - struct gfs2_inode *ip = get_v2ip(page->mapping->host); + struct gfs2_inode *ip = page->mapping->host->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; struct gfs2_holder gh; int error; @@ -307,7 +311,7 @@ out_unlock: static int gfs2_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to) { - struct gfs2_inode *ip = get_v2ip(page->mapping->host); + struct gfs2_inode *ip = page->mapping->host->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; unsigned int data_blocks, ind_blocks, rblocks; int alloc_required; @@ -402,7 +406,7 @@ static int gfs2_commit_write(struct file *file, struct page *page, unsigned from, unsigned to) { struct inode *inode = page->mapping->host; - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; int error = -EOPNOTSUPP; struct buffer_head *dibh; @@ -482,7 +486,7 @@ fail_nounlock: static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock) { - struct gfs2_inode *ip = get_v2ip(mapping->host); + struct gfs2_inode *ip = mapping->host->u.generic_ip; struct gfs2_holder i_gh; sector_t dblock = 0; int error; @@ -504,10 +508,10 @@ static void discard_buffer(struct gfs2_sbd *sdp, struct buffer_head *bh) struct gfs2_bufdata *bd; gfs2_log_lock(sdp); - bd = get_v2bd(bh); + bd = bh->b_private; if (bd) { bd->bd_bh = NULL; - set_v2bd(bh, NULL); + bh->b_private = NULL; gfs2_log_unlock(sdp); brelse(bh); } else @@ -525,7 +529,7 @@ static void discard_buffer(struct gfs2_sbd *sdp, struct buffer_head *bh) static int gfs2_invalidatepage(struct page *page, unsigned long offset) { - struct gfs2_sbd *sdp = get_v2sdp(page->mapping->host->i_sb); + struct gfs2_sbd *sdp = page->mapping->host->i_sb->s_fs_info; struct buffer_head *head, *bh, *next; unsigned int curr_off = 0; int ret = 1; @@ -557,7 +561,7 @@ static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov, { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_holder gh; int rv; @@ -604,7 +608,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; if (rw == WRITE) diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index b020ad8f180b..7f6139288519 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -13,12 +13,16 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "dir.h" #include "glock.h" #include "ops_dentry.h" +#include "util.h" /** * gfs2_drevalidate - Check directory lookup consistency @@ -34,7 +38,7 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) { struct dentry *parent = dget_parent(dentry); - struct gfs2_inode *dip = get_v2ip(parent->d_inode); + struct gfs2_inode *dip = parent->d_inode->u.generic_ip; struct inode *inode; struct gfs2_holder d_gh; struct gfs2_inode *ip; @@ -66,7 +70,7 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) goto fail_gunlock; } - ip = get_v2ip(inode); + ip = inode->u.generic_ip; if (!gfs2_inum_equal(&ip->i_num, &inum)) goto invalid_gunlock; diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index 60d006402553..d149584cff30 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -12,9 +12,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "dir.h" #include "glock.h" #include "glops.h" @@ -61,7 +64,7 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, int connectable) { struct inode *inode = dentry->d_inode; - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; if (*len < 4 || (connectable && *len < 8)) @@ -77,12 +80,12 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, fh[3] = cpu_to_be32(fh[3]); *len = 4; - if (!connectable || ip == get_v2ip(sdp->sd_root_dir)) + if (!connectable || ip == sdp->sd_root_dir->u.generic_ip) return *len; spin_lock(&dentry->d_lock); inode = dentry->d_parent->d_inode; - ip = get_v2ip(inode); + ip = inode->u.generic_ip; gfs2_inode_hold(ip); spin_unlock(&dentry->d_lock); @@ -138,8 +141,8 @@ static int gfs2_get_name(struct dentry *parent, char *name, if (!S_ISDIR(dir->i_mode) || !inode) return -EINVAL; - dip = get_v2ip(dir); - ip = get_v2ip(inode); + dip = dir->u.generic_ip; + ip = inode->u.generic_ip; *name = 0; gnfd.inum = ip->i_num; @@ -181,7 +184,7 @@ static struct dentry *gfs2_get_parent(struct dentry *child) static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) { - struct gfs2_sbd *sdp = get_v2sdp(sb); + struct gfs2_sbd *sdp = sb->s_fs_info; struct gfs2_inum *inum = (struct gfs2_inum *)inum_p; struct gfs2_holder i_gh, ri_gh, rgd_gh; struct gfs2_rgrpd *rgd; @@ -194,7 +197,7 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) inode = gfs2_iget(sb, inum); if (inode) { - ip = get_v2ip(inode); + ip = inode->u.generic_ip; if (ip->i_num.no_formal_ino != inum->no_formal_ino) { iput(inode); return ERR_PTR(-ESTALE); diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index e6ae2551b0cb..d30c6db46241 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -19,10 +19,13 @@ #include #include #include +#include #include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "dir.h" #include "glock.h" @@ -36,6 +39,7 @@ #include "quota.h" #include "rgrp.h" #include "trans.h" +#include "util.h" /* "bad" is for NFS support */ struct filldir_bad_entry { @@ -125,7 +129,7 @@ int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) { - struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; struct gfs2_holder i_gh; loff_t error; @@ -172,7 +176,7 @@ static ssize_t __gfs2_file_aio_read(struct kiocb *iocb, unsigned long nr_segs, loff_t *ppos) { struct file *filp = iocb->ki_filp; - struct gfs2_inode *ip = get_v2ip(filp->f_mapping->host); + struct gfs2_inode *ip = filp->f_mapping->host->u.generic_ip; struct gfs2_holder gh; ssize_t retval; unsigned long seg; @@ -354,7 +358,7 @@ static int filldir_reg_func(void *opaque, const char *name, unsigned int length, static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) { - struct gfs2_inode *dip = get_v2ip(file->f_mapping->host); + struct gfs2_inode *dip = file->f_mapping->host->u.generic_ip; struct filldir_reg fdr; struct gfs2_holder d_gh; uint64_t offset = file->f_pos; @@ -443,7 +447,7 @@ static int filldir_bad_func(void *opaque, const char *name, unsigned int length, static int readdir_bad(struct file *file, void *dirent, filldir_t filldir) { - struct gfs2_inode *dip = get_v2ip(file->f_mapping->host); + struct gfs2_inode *dip = file->f_mapping->host->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; struct filldir_reg fdr; unsigned int entries, size; @@ -608,7 +612,7 @@ out: static int gfs2_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; switch (cmd) { case GFS2_IOCTL_SETFLAGS: @@ -630,7 +634,7 @@ static int gfs2_ioctl(struct inode *inode, struct file *file, unsigned int cmd, static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) { - struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; struct gfs2_holder i_gh; int error; @@ -665,7 +669,7 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) static int gfs2_open(struct inode *inode, struct file *file) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_holder i_gh; struct gfs2_file *fp; int error; @@ -679,8 +683,8 @@ static int gfs2_open(struct inode *inode, struct file *file) fp->f_inode = ip; fp->f_vfile = file; - gfs2_assert_warn(ip->i_sbd, !get_v2fp(file)); - set_v2fp(file, fp); + gfs2_assert_warn(ip->i_sbd, !file->private_data); + file->private_data = fp; if (S_ISREG(ip->i_di.di_mode)) { error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, @@ -708,7 +712,7 @@ static int gfs2_open(struct inode *inode, struct file *file) gfs2_glock_dq_uninit(&i_gh); fail: - set_v2fp(file, NULL); + file->private_data = NULL; kfree(fp); return error; @@ -724,11 +728,11 @@ static int gfs2_open(struct inode *inode, struct file *file) static int gfs2_close(struct inode *inode, struct file *file) { - struct gfs2_sbd *sdp = get_v2sdp(inode->i_sb); + struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; struct gfs2_file *fp; - fp = get_v2fp(file); - set_v2fp(file, NULL); + fp = file->private_data; + file->private_data = NULL; if (gfs2_assert_warn(sdp, fp)) return -EIO; @@ -748,7 +752,7 @@ static int gfs2_close(struct inode *inode, struct file *file) static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) { - struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; gfs2_log_flush_glock(ip->i_gl); @@ -766,7 +770,7 @@ static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) { - struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; struct lm_lockname name = { .ln_number = ip->i_num.no_addr, @@ -824,7 +828,7 @@ static ssize_t gfs2_sendfile(struct file *in_file, loff_t *offset, size_t count, static int do_flock(struct file *file, int cmd, struct file_lock *fl) { - struct gfs2_file *fp = get_v2fp(file); + struct gfs2_file *fp = file->private_data; struct gfs2_holder *fl_gh = &fp->f_fl_gh; struct gfs2_inode *ip = fp->f_inode; struct gfs2_glock *gl; @@ -874,7 +878,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) static void do_unflock(struct file *file, struct file_lock *fl) { - struct gfs2_file *fp = get_v2fp(file); + struct gfs2_file *fp = file->private_data; struct gfs2_holder *fl_gh = &fp->f_fl_gh; mutex_lock(&fp->f_fl_mutex); @@ -895,7 +899,7 @@ static void do_unflock(struct file *file, struct file_lock *fl) static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) { - struct gfs2_inode *ip = get_v2ip(file->f_mapping->host); + struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; if (!(fl->fl_flags & FL_FLOCK)) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 535f020f1e0c..4c4115f9d960 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -15,9 +15,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "daemon.h" #include "glock.h" #include "glops.h" @@ -32,6 +35,7 @@ #include "super.h" #include "unlinked.h" #include "sys.h" +#include "util.h" #define DO 0 #define UNDO 1 @@ -47,7 +51,7 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) memset(sdp, 0, sizeof(struct gfs2_sbd)); - set_v2sdp(sb, sdp); + sb->s_fs_info = sdp; sdp->sd_vfs = sb; gfs2_tune_init(&sdp->sd_tune); @@ -382,6 +386,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) { struct gfs2_holder ji_gh; struct task_struct *p; + struct gfs2_inode *ip; int jindex = 1; int error = 0; @@ -396,7 +401,8 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) fs_err(sdp, "can't lookup journal index: %d\n", error); return error; } - set_bit(GLF_STICKY, &get_v2ip(sdp->sd_jindex)->i_gl->gl_flags); + ip = sdp->sd_jindex->u.generic_ip; + set_bit(GLF_STICKY, &ip->i_gl->gl_flags); /* Load in the journal index special file */ @@ -436,8 +442,8 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) goto fail_jindex; } - error = gfs2_glock_nq_init( - get_v2ip(sdp->sd_jdesc->jd_inode)->i_gl, + ip = sdp->sd_jdesc->jd_inode->u.generic_ip; + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_NOEXP | GL_EXACT, &sdp->sd_jinode_gh); @@ -522,6 +528,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) static int init_inodes(struct gfs2_sbd *sdp, int undo) { int error = 0; + struct gfs2_inode *ip; if (undo) goto fail_qinode; @@ -560,8 +567,9 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) fs_err(sdp, "can't get resource index inode: %d\n", error); goto fail_statfs; } - set_bit(GLF_STICKY, &get_v2ip(sdp->sd_rindex)->i_gl->gl_flags); - sdp->sd_rindex_vn = get_v2ip(sdp->sd_rindex)->i_gl->gl_vn - 1; + ip = sdp->sd_rindex->u.generic_ip; + set_bit(GLF_STICKY, &ip->i_gl->gl_flags); + sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1; /* Read in the quota inode */ error = gfs2_lookup_simple(sdp->sd_master_dir, "quota", @@ -597,6 +605,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) struct inode *pn = NULL; char buf[30]; int error = 0; + struct gfs2_inode *ip; if (sdp->sd_args.ar_spectator) return 0; @@ -641,7 +650,8 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) iput(pn); pn = NULL; - error = gfs2_glock_nq_init(get_v2ip(sdp->sd_ir_inode)->i_gl, + ip = sdp->sd_ir_inode->u.generic_ip; + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, &sdp->sd_ir_gh); if (error) { @@ -649,7 +659,8 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) goto fail_qc_i; } - error = gfs2_glock_nq_init(get_v2ip(sdp->sd_sc_inode)->i_gl, + ip = sdp->sd_sc_inode->u.generic_ip; + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, &sdp->sd_sc_gh); if (error) { @@ -657,7 +668,8 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) goto fail_ir_gh; } - error = gfs2_glock_nq_init(get_v2ip(sdp->sd_ut_inode)->i_gl, + ip = sdp->sd_ut_inode->u.generic_ip; + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, &sdp->sd_ut_gh); if (error) { @@ -665,7 +677,8 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) goto fail_sc_gh; } - error = gfs2_glock_nq_init(get_v2ip(sdp->sd_qc_inode)->i_gl, + ip = sdp->sd_qc_inode->u.generic_ip; + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, &sdp->sd_qc_gh); if (error) { @@ -862,7 +875,7 @@ static int fill_super(struct super_block *sb, void *data, int silent) fail: vfree(sdp); - set_v2sdp(sb, NULL); + sb->s_fs_info = NULL; return error; } diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 9971a30eb78e..7633a8584b0d 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -17,10 +17,13 @@ #include #include #include +#include #include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "acl.h" #include "bmap.h" #include "dir.h" @@ -36,6 +39,7 @@ #include "rgrp.h" #include "trans.h" #include "unlinked.h" +#include "util.h" /** * gfs2_create - Create a file @@ -49,7 +53,7 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd) { - struct gfs2_inode *dip = get_v2ip(dir); + struct gfs2_inode *dip = dir->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; struct gfs2_holder ghs[2]; struct inode *inode; @@ -106,7 +110,7 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) { - struct gfs2_inode *dip = get_v2ip(dir); + struct gfs2_inode *dip = dir->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; struct inode *inode = NULL; int error; @@ -140,10 +144,10 @@ static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, static int gfs2_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) { - struct gfs2_inode *dip = get_v2ip(dir); + struct gfs2_inode *dip = dir->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; struct inode *inode = old_dentry->d_inode; - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_holder ghs[2]; int alloc_required; int error; @@ -274,9 +278,9 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, static int gfs2_unlink(struct inode *dir, struct dentry *dentry) { - struct gfs2_inode *dip = get_v2ip(dir); + struct gfs2_inode *dip = dir->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; - struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; struct gfs2_unlinked *ul; struct gfs2_holder ghs[2]; int error; @@ -329,7 +333,7 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry) static int gfs2_symlink(struct inode *dir, struct dentry *dentry, const char *symname) { - struct gfs2_inode *dip = get_v2ip(dir), *ip; + struct gfs2_inode *dip = dir->u.generic_ip, *ip; struct gfs2_sbd *sdp = dip->i_sbd; struct gfs2_holder ghs[2]; struct inode *inode; @@ -350,7 +354,7 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry, return PTR_ERR(inode); } - ip = get_gl2ip(ghs[1].gh_gl); + ip = ghs[1].gh_gl->gl_object; ip->i_di.di_size = size; @@ -388,7 +392,7 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry, static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) { - struct gfs2_inode *dip = get_v2ip(dir), *ip; + struct gfs2_inode *dip = dir->u.generic_ip, *ip; struct gfs2_sbd *sdp = dip->i_sbd; struct gfs2_holder ghs[2]; struct inode *inode; @@ -403,7 +407,7 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) return PTR_ERR(inode); } - ip = get_gl2ip(ghs[1].gh_gl); + ip = ghs[1].gh_gl->gl_object; ip->i_di.di_nlink = 2; ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode); @@ -468,9 +472,9 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) { - struct gfs2_inode *dip = get_v2ip(dir); + struct gfs2_inode *dip = dir->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; - struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; struct gfs2_unlinked *ul; struct gfs2_holder ghs[2]; int error; @@ -534,7 +538,7 @@ static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) { - struct gfs2_inode *dip = get_v2ip(dir), *ip; + struct gfs2_inode *dip = dir->u.generic_ip, *ip; struct gfs2_sbd *sdp = dip->i_sbd; struct gfs2_holder ghs[2]; struct inode *inode; @@ -563,7 +567,7 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, return PTR_ERR(inode); } - ip = get_gl2ip(ghs[1].gh_gl); + ip = ghs[1].gh_gl->gl_object; ip->i_di.di_major = major; ip->i_di.di_minor = minor; @@ -602,9 +606,9 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, static int gfs2_rename(struct inode *odir, struct dentry *odentry, struct inode *ndir, struct dentry *ndentry) { - struct gfs2_inode *odip = get_v2ip(odir); - struct gfs2_inode *ndip = get_v2ip(ndir); - struct gfs2_inode *ip = get_v2ip(odentry->d_inode); + struct gfs2_inode *odip = odir->u.generic_ip; + struct gfs2_inode *ndip = ndir->u.generic_ip; + struct gfs2_inode *ip = odentry->d_inode->u.generic_ip; struct gfs2_inode *nip = NULL; struct gfs2_sbd *sdp = odip->i_sbd; struct gfs2_unlinked *ul; @@ -616,7 +620,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, int error; if (ndentry->d_inode) { - nip = get_v2ip(ndentry->d_inode); + nip = ndentry->d_inode->u.generic_ip; if (ip == nip) return 0; } @@ -848,7 +852,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, static int gfs2_readlink(struct dentry *dentry, char __user *user_buf, int user_size) { - struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; char array[GFS2_FAST_NAME_SIZE], *buf = array; unsigned int len = GFS2_FAST_NAME_SIZE; int error; @@ -884,7 +888,7 @@ static int gfs2_readlink(struct dentry *dentry, char __user *user_buf, static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) { - struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; char array[GFS2_FAST_NAME_SIZE], *buf = array; unsigned int len = GFS2_FAST_NAME_SIZE; int error; @@ -910,7 +914,7 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_holder i_gh; int error; @@ -930,7 +934,7 @@ static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd) static int setattr_size(struct inode *inode, struct iattr *attr) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; int error; if (attr->ia_size != ip->i_di.di_size) { @@ -948,7 +952,7 @@ static int setattr_size(struct inode *inode, struct iattr *attr) static int setattr_chown(struct inode *inode, struct iattr *attr) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; struct buffer_head *dibh; uint32_t ouid, ogid, nuid, ngid; @@ -1025,7 +1029,7 @@ static int setattr_chown(struct inode *inode, struct iattr *attr) static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) { struct inode *inode = dentry->d_inode; - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_holder i_gh; int error; @@ -1072,7 +1076,7 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) { struct inode *inode = dentry->d_inode; - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_holder gh; int error; @@ -1088,7 +1092,7 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, static int gfs2_setxattr(struct dentry *dentry, const char *name, const void *data, size_t size, int flags) { - struct gfs2_inode *ip = get_v2ip(dentry->d_inode); + struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; struct gfs2_ea_request er; memset(&er, 0, sizeof(struct gfs2_ea_request)); @@ -1118,7 +1122,7 @@ static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, er.er_name_len = strlen(er.er_name); er.er_data_len = size; - return gfs2_ea_get(get_v2ip(dentry->d_inode), &er); + return gfs2_ea_get(dentry->d_inode->u.generic_ip, &er); } static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) @@ -1129,7 +1133,7 @@ static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) er.er_data = (size) ? buffer : NULL; er.er_data_len = size; - return gfs2_ea_list(get_v2ip(dentry->d_inode), &er); + return gfs2_ea_list(dentry->d_inode->u.generic_ip, &er); } static int gfs2_removexattr(struct dentry *dentry, const char *name) @@ -1142,7 +1146,7 @@ static int gfs2_removexattr(struct dentry *dentry, const char *name) return -EOPNOTSUPP; er.er_name_len = strlen(er.er_name); - return gfs2_ea_remove(get_v2ip(dentry->d_inode), &er); + return gfs2_ea_remove(dentry->d_inode->u.generic_ip, &er); } struct inode_operations gfs2_file_iops = { diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 48a94522406e..10f70ee12161 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -18,9 +18,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "glock.h" #include "inode.h" #include "lm.h" @@ -33,6 +36,7 @@ #include "rgrp.h" #include "super.h" #include "sys.h" +#include "util.h" /** * gfs2_write_inode - Make sure the inode is stable on the disk @@ -44,7 +48,7 @@ static int gfs2_write_inode(struct inode *inode, int sync) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; if (current->flags & PF_MEMALLOC) return 0; @@ -62,7 +66,7 @@ static int gfs2_write_inode(struct inode *inode, int sync) static void gfs2_put_super(struct super_block *sb) { - struct gfs2_sbd *sdp = get_v2sdp(sb); + struct gfs2_sbd *sdp = sb->s_fs_info; int error; if (!sdp) @@ -138,7 +142,7 @@ static void gfs2_put_super(struct super_block *sb) vfree(sdp); - set_v2sdp(sb, NULL); + sb->s_fs_info = NULL; } /** @@ -151,7 +155,7 @@ static void gfs2_put_super(struct super_block *sb) static void gfs2_write_super(struct super_block *sb) { - struct gfs2_sbd *sdp = get_v2sdp(sb); + struct gfs2_sbd *sdp = sb->s_fs_info; gfs2_log_flush(sdp); } @@ -163,7 +167,7 @@ static void gfs2_write_super(struct super_block *sb) static void gfs2_write_super_lockfs(struct super_block *sb) { - struct gfs2_sbd *sdp = get_v2sdp(sb); + struct gfs2_sbd *sdp = sb->s_fs_info; int error; for (;;) { @@ -194,7 +198,7 @@ static void gfs2_write_super_lockfs(struct super_block *sb) static void gfs2_unlockfs(struct super_block *sb) { - struct gfs2_sbd *sdp = get_v2sdp(sb); + struct gfs2_sbd *sdp = sb->s_fs_info; gfs2_unfreeze_fs(sdp); } @@ -208,7 +212,7 @@ static void gfs2_unlockfs(struct super_block *sb) static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf) { - struct gfs2_sbd *sdp = get_v2sdp(sb); + struct gfs2_sbd *sdp = sb->s_fs_info; struct gfs2_statfs_change sc; int error; @@ -245,7 +249,7 @@ static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf) static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) { - struct gfs2_sbd *sdp = get_v2sdp(sb); + struct gfs2_sbd *sdp = sb->s_fs_info; int error; error = gfs2_mount_args(sdp, data, 1); @@ -283,12 +287,12 @@ static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) static void gfs2_clear_inode(struct inode *inode) { - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; if (ip) { spin_lock(&ip->i_spin); ip->i_vnode = NULL; - set_v2ip(inode, NULL); + inode->u.generic_ip = NULL; spin_unlock(&ip->i_spin); gfs2_glock_schedule_for_reclaim(ip->i_gl); @@ -306,7 +310,7 @@ static void gfs2_clear_inode(struct inode *inode) static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) { - struct gfs2_sbd *sdp = get_v2sdp(mnt->mnt_sb); + struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info; struct gfs2_args *args = &sdp->sd_args; if (args->ar_lockproto[0]) diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index bfeb920dccee..dbc57071e7bb 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -14,9 +14,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "glock.h" #include "inode.h" @@ -25,6 +28,7 @@ #include "quota.h" #include "rgrp.h" #include "trans.h" +#include "util.h" static void pfault_be_greedy(struct gfs2_inode *ip) { @@ -43,7 +47,7 @@ static void pfault_be_greedy(struct gfs2_inode *ip) static struct page *gfs2_private_nopage(struct vm_area_struct *area, unsigned long address, int *type) { - struct gfs2_inode *ip = get_v2ip(area->vm_file->f_mapping->host); + struct gfs2_inode *ip = area->vm_file->f_mapping->host->u.generic_ip; struct gfs2_holder i_gh; struct page *result; int error; @@ -141,7 +145,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, unsigned long address, int *type) { - struct gfs2_inode *ip = get_v2ip(area->vm_file->f_mapping->host); + struct gfs2_inode *ip = area->vm_file->f_mapping->host->u.generic_ip; struct gfs2_holder i_gh; struct page *result = NULL; unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) + diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c index 3542aa6b01c4..a2c9e93c7c39 100644 --- a/fs/gfs2/page.c +++ b/fs/gfs2/page.c @@ -14,14 +14,18 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "inode.h" #include "page.h" #include "trans.h" #include "ops_address.h" +#include "util.h" /** * gfs2_pte_inval - Sync and invalidate all PTEs associated with a glock @@ -34,7 +38,7 @@ void gfs2_pte_inval(struct gfs2_glock *gl) struct gfs2_inode *ip; struct inode *inode; - ip = get_gl2ip(gl); + ip = gl->gl_object; if (!ip || !S_ISREG(ip->i_di.di_mode)) return; @@ -64,7 +68,7 @@ void gfs2_page_inval(struct gfs2_glock *gl) struct gfs2_inode *ip; struct inode *inode; - ip = get_gl2ip(gl); + ip = gl->gl_object; if (!ip || !S_ISREG(ip->i_di.di_mode)) return; @@ -95,7 +99,7 @@ void gfs2_page_sync(struct gfs2_glock *gl, int flags) struct gfs2_inode *ip; struct inode *inode; - ip = get_gl2ip(gl); + ip = gl->gl_object; if (!ip || !S_ISREG(ip->i_di.di_mode)) return; @@ -192,7 +196,7 @@ int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, int gfs2_block_truncate_page(struct address_space *mapping) { struct inode *inode = mapping->host; - struct gfs2_inode *ip = get_v2ip(inode); + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; loff_t from = inode->i_size; unsigned long index = from >> PAGE_CACHE_SHIFT; diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 40c7cf87eb44..c57b5cf1d583 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -44,13 +44,17 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "glock.h" #include "glops.h" #include "log.h" +#include "lvb.h" #include "meta_io.h" #include "quota.h" #include "rgrp.h" @@ -59,6 +63,7 @@ #include "inode.h" #include "ops_file.h" #include "ops_address.h" +#include "util.h" #define QUOTA_USER 1 #define QUOTA_GROUP 0 @@ -244,7 +249,7 @@ static void slot_put(struct gfs2_quota_data *qd) static int bh_get(struct gfs2_quota_data *qd) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; - struct gfs2_inode *ip = get_v2ip(sdp->sd_qc_inode); + struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip; unsigned int block, offset; uint64_t dblock; int new = 0; @@ -526,7 +531,7 @@ static int sort_qd(const void *a, const void *b) static void do_qc(struct gfs2_quota_data *qd, int64_t change) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; - struct gfs2_inode *ip = get_v2ip(sdp->sd_qc_inode); + struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip; struct gfs2_quota_change *qc = qd->qd_bh_qc; int64_t x; @@ -642,7 +647,7 @@ unlock: static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) { struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd; - struct gfs2_inode *ip = get_v2ip(sdp->sd_quota_inode); + struct gfs2_inode *ip = sdp->sd_quota_inode->u.generic_ip; unsigned int data_blocks, ind_blocks; struct file_ra_state ra_state; struct gfs2_holder *ghs, i_gh; @@ -753,6 +758,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, struct gfs2_holder *q_gh) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; + struct gfs2_inode *ip = sdp->sd_quota_inode->u.generic_ip; struct gfs2_holder i_gh; struct gfs2_quota q; char buf[sizeof(struct gfs2_quota)]; @@ -776,7 +782,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, if (error) return error; - error = gfs2_glock_nq_init(get_v2ip(sdp->sd_quota_inode)->i_gl, + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); if (error) @@ -784,7 +790,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, memset(buf, 0, sizeof(struct gfs2_quota)); pos = qd2offset(qd); - error = gfs2_internal_read(get_v2ip(sdp->sd_quota_inode), + error = gfs2_internal_read(ip, &ra_state, buf, &pos, sizeof(struct gfs2_quota)); @@ -1118,7 +1124,7 @@ int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, int gfs2_quota_init(struct gfs2_sbd *sdp) { - struct gfs2_inode *ip = get_v2ip(sdp->sd_qc_inode); + struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip; unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; unsigned int x, slot = 0; unsigned int found = 0; @@ -1133,7 +1139,7 @@ int gfs2_quota_init(struct gfs2_sbd *sdp) return -EIO; } sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block; - sdp->sd_quota_chunks = DIV_RU(sdp->sd_quota_slots, 8 * PAGE_SIZE); + sdp->sd_quota_chunks = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * PAGE_SIZE); error = -ENOMEM; diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index e5f2b284fa54..2df450e2f433 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -12,9 +12,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "glock.h" #include "glops.h" @@ -23,22 +26,24 @@ #include "meta_io.h" #include "recovery.h" #include "super.h" +#include "util.h" int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, struct buffer_head **bh) { - struct gfs2_glock *gl = get_v2ip(jd->jd_inode)->i_gl; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_glock *gl = ip->i_gl; int new = 0; uint64_t dblock; uint32_t extlen; int error; - error = gfs2_block_map(get_v2ip(jd->jd_inode), blk, &new, &dblock, + error = gfs2_block_map(ip, blk, &new, &dblock, &extlen); if (error) return error; if (!dblock) { - gfs2_consist_inode(get_v2ip(jd->jd_inode)); + gfs2_consist_inode(ip); return -EIO; } @@ -185,7 +190,7 @@ static int find_good_lh(struct gfs2_jdesc *jd, unsigned int *blk, *blk = 0; if (*blk == orig_blk) { - gfs2_consist_inode(get_v2ip(jd->jd_inode)); + gfs2_consist_inode(jd->jd_inode->u.generic_ip); return -EIO; } } @@ -219,7 +224,7 @@ static int jhead_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head) continue; if (lh.lh_sequence == head->lh_sequence) { - gfs2_consist_inode(get_v2ip(jd->jd_inode)); + gfs2_consist_inode(jd->jd_inode->u.generic_ip); return -EIO; } if (lh.lh_sequence < head->lh_sequence) @@ -295,7 +300,8 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header *head) static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, unsigned int end, int pass) { - struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; struct buffer_head *bh; struct gfs2_log_descriptor *ld; int error = 0; @@ -324,7 +330,7 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, continue; } if (error == 1) { - gfs2_consist_inode(get_v2ip(jd->jd_inode)); + gfs2_consist_inode(jd->jd_inode->u.generic_ip); error = -EIO; } brelse(bh); @@ -361,7 +367,7 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) { - struct gfs2_inode *ip = get_v2ip(jd->jd_inode); + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; unsigned int lblock; int new = 0; @@ -420,7 +426,8 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) int gfs2_recover_journal(struct gfs2_jdesc *jd, int wait) { - struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd; + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; struct gfs2_log_header head; struct gfs2_holder j_gh, ji_gh, t_gh; unsigned long t; @@ -450,7 +457,7 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd, int wait) goto fail; }; - error = gfs2_glock_nq_init(get_v2ip(jd->jd_inode)->i_gl, LM_ST_SHARED, + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_NOEXP, &ji_gh); if (error) goto fail_gunlock_j; @@ -516,7 +523,7 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd, int wait) gfs2_glock_dq_uninit(&t_gh); - t = DIV_RU(jiffies - t, HZ); + t = DIV_ROUND_UP(jiffies - t, HZ); fs_info(sdp, "jid=%u: Journal replayed in %lus\n", jd->jd_jid, t); diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 9525b176f502..4ae559694396 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -13,9 +13,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bits.h" #include "glock.h" #include "glops.h" @@ -26,6 +29,7 @@ #include "super.h" #include "trans.h" #include "ops_file.h" +#include "util.h" /** * gfs2_rgrp_verify - Verify that a resource group is consistent @@ -171,7 +175,7 @@ static void clear_rgrpdi(struct gfs2_sbd *sdp) list_del(&rgd->rd_list_mru); if (gl) { - set_gl2rgd(gl, NULL); + gl->gl_object = NULL; gfs2_glock_put(gl); } @@ -320,7 +324,7 @@ static int gfs2_ri_update(struct gfs2_inode *ip) if (error) goto fail; - set_gl2rgd(rgd->rd_gl, rgd); + rgd->rd_gl->gl_object = rgd; rgd->rd_rg_vn = rgd->rd_gl->gl_vn - 1; } @@ -354,7 +358,7 @@ static int gfs2_ri_update(struct gfs2_inode *ip) int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh) { - struct gfs2_inode *ip = get_v2ip(sdp->sd_rindex); + struct gfs2_inode *ip = sdp->sd_rindex->u.generic_ip; struct gfs2_glock *gl = ip->i_gl; int error; diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 2c1c6aa1c077..9ccf0b9c5980 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -12,9 +12,12 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "dir.h" #include "format.h" @@ -29,6 +32,7 @@ #include "super.h" #include "trans.h" #include "unlinked.h" +#include "util.h" /** * gfs2_tune_init - Fill a gfs2_tune structure with default values @@ -207,12 +211,12 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) /* Compute maximum reservation required to add a entry to a directory */ - hash_blocks = DIV_RU(sizeof(uint64_t) * (1 << GFS2_DIR_MAX_DEPTH), + hash_blocks = DIV_ROUND_UP(sizeof(uint64_t) * (1 << GFS2_DIR_MAX_DEPTH), sdp->sd_jbsize); ind_blocks = 0; for (tmp_blocks = hash_blocks; tmp_blocks > sdp->sd_diptrs;) { - tmp_blocks = DIV_RU(tmp_blocks, sdp->sd_inptrs); + tmp_blocks = DIV_ROUND_UP(tmp_blocks, sdp->sd_inptrs); ind_blocks += tmp_blocks; } @@ -278,7 +282,7 @@ int gfs2_do_upgrade(struct gfs2_sbd *sdp, struct gfs2_glock *sb_gl) int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) { - struct gfs2_inode *dip = get_v2ip(sdp->sd_jindex); + struct gfs2_inode *dip = sdp->sd_jindex->u.generic_ip; struct qstr name; char buf[20]; struct gfs2_jdesc *jd; @@ -296,7 +300,7 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) name.len = sprintf(buf, "journal%u", sdp->sd_journals); - error = gfs2_dir_search(get_v2ip(sdp->sd_jindex), + error = gfs2_dir_search(sdp->sd_jindex->u.generic_ip, &name, NULL, NULL); if (error == -ENOENT) { error = 0; @@ -419,7 +423,7 @@ struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp) int gfs2_jdesc_check(struct gfs2_jdesc *jd) { - struct gfs2_inode *ip = get_v2ip(jd->jd_inode); + struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; int ar; int error; @@ -471,7 +475,8 @@ int gfs2_lookup_master_dir(struct gfs2_sbd *sdp) int gfs2_make_fs_rw(struct gfs2_sbd *sdp) { - struct gfs2_glock *j_gl = get_v2ip(sdp->sd_jdesc->jd_inode)->i_gl; + struct gfs2_inode *ip = sdp->sd_jdesc->jd_inode->u.generic_ip; + struct gfs2_glock *j_gl = ip->i_gl; struct gfs2_holder t_gh; struct gfs2_log_header head; int error; @@ -481,7 +486,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp) if (error) return error; - gfs2_meta_cache_flush(get_v2ip(sdp->sd_jdesc->jd_inode)); + gfs2_meta_cache_flush(ip); j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA); error = gfs2_find_jhead(sdp->sd_jdesc, &head); @@ -559,9 +564,9 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp) int gfs2_statfs_init(struct gfs2_sbd *sdp) { - struct gfs2_inode *m_ip = get_v2ip(sdp->sd_statfs_inode); + struct gfs2_inode *m_ip = sdp->sd_statfs_inode->u.generic_ip; struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; - struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode); + struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip; struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; struct buffer_head *m_bh, *l_bh; struct gfs2_holder gh; @@ -608,7 +613,7 @@ int gfs2_statfs_init(struct gfs2_sbd *sdp) void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, int64_t dinodes) { - struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode); + struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip; struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; struct buffer_head *l_bh; int error; @@ -634,8 +639,8 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, int gfs2_statfs_sync(struct gfs2_sbd *sdp) { - struct gfs2_inode *m_ip = get_v2ip(sdp->sd_statfs_inode); - struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode); + struct gfs2_inode *m_ip = sdp->sd_statfs_inode->u.generic_ip; + struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip; struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; struct gfs2_holder gh; @@ -795,7 +800,8 @@ int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc) error = err; } else { if (!error) - error = statfs_slow_fill(get_gl2rgd(gh->gh_gl), sc); + error = statfs_slow_fill( + gh->gh_gl->gl_object, sc); gfs2_glock_dq_uninit(gh); } } @@ -846,6 +852,7 @@ struct lfcc { int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh) { + struct gfs2_inode *ip; struct gfs2_holder ji_gh; struct gfs2_jdesc *jd; struct lfcc *lfcc; @@ -863,7 +870,8 @@ int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh) error = -ENOMEM; goto out; } - error = gfs2_glock_nq_init(get_v2ip(jd->jd_inode)->i_gl, + ip = jd->jd_inode->u.generic_ip; + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh); if (error) { diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index f87df8ec041e..f05ba8f69132 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -14,15 +14,19 @@ #include #include #include +#include #include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "lm.h" #include "sys.h" #include "super.h" #include "glock.h" #include "quota.h" +#include "util.h" char *gfs2_sys_margs; spinlock_t gfs2_sys_margs_lock; diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 0a0ea70eac4c..2cce68aec134 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -12,14 +12,18 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "glock.h" #include "log.h" #include "lops.h" #include "meta_io.h" #include "trans.h" +#include "util.h" int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, unsigned int revokes, char *file, unsigned int line) @@ -27,7 +31,7 @@ int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, struct gfs2_trans *tr; int error; - if (gfs2_assert_warn(sdp, !get_transaction) || + if (gfs2_assert_warn(sdp, !current->journal_info) || gfs2_assert_warn(sdp, blocks || revokes)) { fs_warn(sdp, "(%s, %u)\n", file, line); return -EINVAL; @@ -69,7 +73,7 @@ int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, if (error) goto fail_gunlock; - set_transaction(tr); + current->journal_info = tr; return 0; @@ -90,8 +94,8 @@ void gfs2_trans_end(struct gfs2_sbd *sdp) struct gfs2_trans *tr; struct gfs2_holder *t_gh; - tr = get_transaction; - set_transaction(NULL); + tr = current->journal_info; + current->journal_info = NULL; if (gfs2_assert_warn(sdp, tr)) return; @@ -147,12 +151,12 @@ void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta) struct gfs2_sbd *sdp = gl->gl_sbd; struct gfs2_bufdata *bd; - bd = get_v2bd(bh); + bd = bh->b_private; if (bd) gfs2_assert(sdp, bd->bd_gl == gl); else { gfs2_attach_bufdata(gl, bh, meta); - bd = get_v2bd(bh); + bd = bh->b_private; } lops_add(sdp, &bd->bd_le); } @@ -186,8 +190,9 @@ void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, uint64_t blkno) gfs2_log_unlock(sdp); if (found) { + struct gfs2_trans *tr = current->journal_info; kfree(rv); - get_transaction->tr_num_revoke_rm++; + tr->tr_num_revoke_rm++; } } diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c index e92a3a11815b..24b91c23bc2d 100644 --- a/fs/gfs2/unlinked.c +++ b/fs/gfs2/unlinked.c @@ -13,19 +13,23 @@ #include #include #include +#include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "bmap.h" #include "inode.h" #include "meta_io.h" #include "trans.h" #include "unlinked.h" +#include "util.h" static int munge_ondisk(struct gfs2_sbd *sdp, unsigned int slot, struct gfs2_unlinked_tag *ut) { - struct gfs2_inode *ip = get_v2ip(sdp->sd_ut_inode); + struct gfs2_inode *ip = sdp->sd_ut_inode->u.generic_ip; unsigned int block, offset; uint64_t dblock; int new = 0; @@ -312,7 +316,7 @@ int gfs2_unlinked_dealloc(struct gfs2_sbd *sdp) int gfs2_unlinked_init(struct gfs2_sbd *sdp) { - struct gfs2_inode *ip = get_v2ip(sdp->sd_ut_inode); + struct gfs2_inode *ip = sdp->sd_ut_inode->u.generic_ip; unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; unsigned int x, slot = 0; unsigned int found = 0; @@ -327,7 +331,8 @@ int gfs2_unlinked_init(struct gfs2_sbd *sdp) return -EIO; } sdp->sd_unlinked_slots = blocks * sdp->sd_ut_per_block; - sdp->sd_unlinked_chunks = DIV_RU(sdp->sd_unlinked_slots, 8 * PAGE_SIZE); + sdp->sd_unlinked_chunks = DIV_ROUND_UP(sdp->sd_unlinked_slots, + 8 * PAGE_SIZE); error = -ENOMEM; diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 4fb1704aac10..8b22fa91bd14 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -13,12 +13,16 @@ #include #include #include +#include #include #include #include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" #include "glock.h" #include "lm.h" +#include "util.h" kmem_cache_t *gfs2_glock_cachep __read_mostly; kmem_cache_t *gfs2_inode_cachep __read_mostly; diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index ec432e0c208d..8d4f0445df47 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -50,15 +50,18 @@ * An on-disk inode number */ -#define gfs2_inum_equal(ino1, ino2) \ - (((ino1)->no_formal_ino == (ino2)->no_formal_ino) && \ - ((ino1)->no_addr == (ino2)->no_addr)) - struct gfs2_inum { __be64 no_formal_ino; __be64 no_addr; }; +static inline int gfs2_inum_equal(const struct gfs2_inum *ino1, + const struct gfs2_inum *ino2) +{ + return ino1->no_formal_ino == ino2->no_formal_ino && + ino1->no_addr == ino2->no_addr; +} + /* * Generic metadata head structure * Every inplace buffer logged in the journal must start with this. diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 3b507bf05d09..f789278a625a 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -29,6 +29,7 @@ extern const char linux_banner[]; #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1)) +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) #define KERN_EMERG "<0>" /* system is unusable */ #define KERN_ALERT "<1>" /* action must be taken immediately */ From b3f58d8f2b1200f1b9abbcfb9dec6c25bc787469 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 28 Feb 2006 11:16:37 -0500 Subject: [PATCH 056/292] [DLM] Pass in lockspace to lkb put function In some cases a lockspace isn't attached to the lkb, so that it needs to be passed directly to the lkb put function. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 54 +++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 80487703d582..85a0e73ba808 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -591,9 +591,11 @@ static void kill_lkb(struct kref *kref) DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb);); } -static int put_lkb(struct dlm_lkb *lkb) +/* __put_lkb() is used when an lkb may not have an rsb attached to + it so we need to provide the lockspace explicitly */ + +static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb) { - struct dlm_ls *ls = lkb->lkb_resource->res_ls; uint16_t bucket = lkb->lkb_id & 0xFFFF; write_lock(&ls->ls_lkbtbl[bucket].lock); @@ -616,7 +618,13 @@ static int put_lkb(struct dlm_lkb *lkb) int dlm_put_lkb(struct dlm_lkb *lkb) { - return put_lkb(lkb); + struct dlm_ls *ls; + + DLM_ASSERT(lkb->lkb_resource, dlm_print_lkb(lkb);); + DLM_ASSERT(lkb->lkb_resource->res_ls, dlm_print_lkb(lkb);); + + ls = lkb->lkb_resource->res_ls; + return __put_lkb(ls, lkb); } /* This is only called to add a reference when the code already holds @@ -1949,7 +1957,7 @@ int dlm_lock(dlm_lockspace_t *lockspace, error = 0; out_put: if (convert || error) - put_lkb(lkb); + __put_lkb(ls, lkb); if (error == -EAGAIN) error = 0; out: @@ -1991,7 +1999,7 @@ int dlm_unlock(dlm_lockspace_t *lockspace, if (error == -DLM_EUNLOCK || error == -DLM_ECANCEL) error = 0; out_put: - put_lkb(lkb); + dlm_put_lkb(lkb); out: unlock_recovery(ls); dlm_put_lockspace(ls); @@ -2442,7 +2450,7 @@ static void receive_request(struct dlm_ls *ls, struct dlm_message *ms) lkb->lkb_flags |= DLM_IFL_MSTCPY; error = receive_request_args(ls, lkb, ms); if (error) { - put_lkb(lkb); + __put_lkb(ls, lkb); goto fail; } @@ -2450,7 +2458,7 @@ static void receive_request(struct dlm_ls *ls, struct dlm_message *ms) error = find_rsb(ls, ms->m_extra, namelen, R_MASTER, &r); if (error) { - put_lkb(lkb); + __put_lkb(ls, lkb); goto fail; } @@ -2466,7 +2474,7 @@ static void receive_request(struct dlm_ls *ls, struct dlm_message *ms) if (error == -EINPROGRESS) error = 0; if (error) - put_lkb(lkb); + dlm_put_lkb(lkb); return; fail: @@ -2502,7 +2510,7 @@ static void receive_convert(struct dlm_ls *ls, struct dlm_message *ms) unlock_rsb(r); put_rsb(r); - put_lkb(lkb); + dlm_put_lkb(lkb); return; fail: @@ -2536,7 +2544,7 @@ static void receive_unlock(struct dlm_ls *ls, struct dlm_message *ms) unlock_rsb(r); put_rsb(r); - put_lkb(lkb); + dlm_put_lkb(lkb); return; fail: @@ -2566,7 +2574,7 @@ static void receive_cancel(struct dlm_ls *ls, struct dlm_message *ms) unlock_rsb(r); put_rsb(r); - put_lkb(lkb); + dlm_put_lkb(lkb); return; fail: @@ -2598,7 +2606,7 @@ static void receive_grant(struct dlm_ls *ls, struct dlm_message *ms) unlock_rsb(r); put_rsb(r); - put_lkb(lkb); + dlm_put_lkb(lkb); } static void receive_bast(struct dlm_ls *ls, struct dlm_message *ms) @@ -2623,7 +2631,7 @@ static void receive_bast(struct dlm_ls *ls, struct dlm_message *ms) unlock_rsb(r); put_rsb(r); - put_lkb(lkb); + dlm_put_lkb(lkb); } static void receive_lookup(struct dlm_ls *ls, struct dlm_message *ms) @@ -2746,7 +2754,7 @@ static void receive_request_reply(struct dlm_ls *ls, struct dlm_message *ms) unlock_rsb(r); put_rsb(r); out: - put_lkb(lkb); + dlm_put_lkb(lkb); } static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, @@ -2813,7 +2821,7 @@ static void receive_convert_reply(struct dlm_ls *ls, struct dlm_message *ms) _receive_convert_reply(lkb, ms); out: - put_lkb(lkb); + dlm_put_lkb(lkb); } static void _receive_unlock_reply(struct dlm_lkb *lkb, struct dlm_message *ms) @@ -2860,7 +2868,7 @@ static void receive_unlock_reply(struct dlm_ls *ls, struct dlm_message *ms) _receive_unlock_reply(lkb, ms); out: - put_lkb(lkb); + dlm_put_lkb(lkb); } static void _receive_cancel_reply(struct dlm_lkb *lkb, struct dlm_message *ms) @@ -2907,7 +2915,7 @@ static void receive_cancel_reply(struct dlm_ls *ls, struct dlm_message *ms) _receive_cancel_reply(lkb, ms); out: - put_lkb(lkb); + dlm_put_lkb(lkb); } static void receive_lookup_reply(struct dlm_ls *ls, struct dlm_message *ms) @@ -2954,7 +2962,7 @@ static void receive_lookup_reply(struct dlm_ls *ls, struct dlm_message *ms) unlock_rsb(r); put_rsb(r); out: - put_lkb(lkb); + dlm_put_lkb(lkb); } int dlm_receive_message(struct dlm_header *hd, int nodeid, int recovery) @@ -3159,7 +3167,7 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls) ls->ls_stub_ms.m_result = -DLM_EUNLOCK; _remove_from_waiters(lkb); _receive_unlock_reply(lkb, &ls->ls_stub_ms); - put_lkb(lkb); + dlm_put_lkb(lkb); break; case DLM_MSG_CANCEL: @@ -3167,7 +3175,7 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls) ls->ls_stub_ms.m_result = -DLM_ECANCEL; _remove_from_waiters(lkb); _receive_cancel_reply(lkb, &ls->ls_stub_ms); - put_lkb(lkb); + dlm_put_lkb(lkb); break; default: @@ -3272,7 +3280,7 @@ static void purge_queue(struct dlm_rsb *r, struct list_head *queue, if (test(ls, lkb)) { del_lkb(r, lkb); /* this put should free the lkb */ - if (!put_lkb(lkb)) + if (!dlm_put_lkb(lkb)) log_error(ls, "purged lkb not released"); } } @@ -3456,7 +3464,7 @@ int dlm_recover_master_copy(struct dlm_ls *ls, struct dlm_rcom *rc) error = receive_rcom_lock_args(ls, lkb, r, rc); if (error) { - put_lkb(lkb); + __put_lkb(ls, lkb); goto out_unlock; } @@ -3518,7 +3526,7 @@ int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc) unlock_rsb(r); put_rsb(r); - put_lkb(lkb); + dlm_put_lkb(lkb); return 0; } From e317ffcb7cc26c5e80cab97160a5e2761a4436ec Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 1 Mar 2006 11:39:37 -0500 Subject: [PATCH 057/292] [GFS2] Remove uneeded memory allocation For every filesystem operation where we need a transaction, we now make one less memory allocation. Signed-off-by: Steven Whitehouse --- fs/gfs2/incore.h | 2 +- fs/gfs2/trans.c | 30 ++++++++++++------------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 2443e9aad598..c741016d07dc 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -360,7 +360,7 @@ struct gfs2_trans { unsigned int tr_revokes; unsigned int tr_reserved; - struct gfs2_holder *tr_t_gh; + struct gfs2_holder tr_t_gh; int tr_touched; diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 2cce68aec134..5d1f4a1e4077 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -53,18 +53,15 @@ int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, sizeof(uint64_t)); INIT_LIST_HEAD(&tr->tr_list_buf); - error = -ENOMEM; - tr->tr_t_gh = gfs2_holder_get(sdp->sd_trans_gl, LM_ST_SHARED, - GL_NEVER_RECURSE, GFP_NOFS); - if (!tr->tr_t_gh) - goto fail; + gfs2_holder_init(sdp->sd_trans_gl, LM_ST_SHARED, + GL_NEVER_RECURSE, &tr->tr_t_gh); - error = gfs2_glock_nq(tr->tr_t_gh); + error = gfs2_glock_nq(&tr->tr_t_gh); if (error) - goto fail_holder_put; + goto fail_holder_uninit; if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { - tr->tr_t_gh->gh_flags |= GL_NOCACHE; + tr->tr_t_gh.gh_flags |= GL_NOCACHE; error = -EROFS; goto fail_gunlock; } @@ -78,12 +75,10 @@ int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, return 0; fail_gunlock: - gfs2_glock_dq(tr->tr_t_gh); + gfs2_glock_dq(&tr->tr_t_gh); - fail_holder_put: - gfs2_holder_put(tr->tr_t_gh); - - fail: + fail_holder_uninit: + gfs2_holder_uninit(&tr->tr_t_gh); kfree(tr); return error; @@ -100,16 +95,15 @@ void gfs2_trans_end(struct gfs2_sbd *sdp) if (gfs2_assert_warn(sdp, tr)) return; - t_gh = tr->tr_t_gh; - tr->tr_t_gh = NULL; + t_gh = &tr->tr_t_gh; if (!tr->tr_touched) { gfs2_log_release(sdp, tr->tr_reserved); - kfree(tr); gfs2_glock_dq(t_gh); - gfs2_holder_put(t_gh); + gfs2_holder_uninit(t_gh); + kfree(tr); return; } @@ -127,7 +121,7 @@ void gfs2_trans_end(struct gfs2_sbd *sdp) gfs2_log_commit(sdp, tr); gfs2_glock_dq(t_gh); - gfs2_holder_put(t_gh); + gfs2_holder_uninit(t_gh); if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS) gfs2_log_flush(sdp); From c9fd43078f5007c6ca6b3a9cd04c51a8f0e44a20 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 1 Mar 2006 15:31:02 -0500 Subject: [PATCH 058/292] [GFS2] Tidy up mount code. We no longer lookup ".gfs2_admin" in the root directory in order to find it, but instead use the inode number given in the superblock. Both the root directory and the admin directory are now looked up using the same routine, so the redundant code is removed. Also, there is no longer a reference to the root inode in the GFS2 super block. When required this can be retreived via sb->s_root->d_inode instead. Assuming that we introduce a metadata filesystem type for GFS, then this is a first step towards that goal. Signed-off-by: Steven Whitehouse --- fs/gfs2/incore.h | 1 - fs/gfs2/inode.c | 13 +++++++------ fs/gfs2/inode.h | 2 +- fs/gfs2/ops_export.c | 4 ++-- fs/gfs2/ops_fstype.c | 40 +++++++++++++++++----------------------- fs/gfs2/ops_super.c | 1 - fs/gfs2/super.c | 19 ------------------- fs/gfs2/super.h | 1 - 8 files changed, 27 insertions(+), 54 deletions(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index c741016d07dc..62f109e553c4 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -532,7 +532,6 @@ struct gfs2_sbd { struct inode *sd_qc_inode; struct inode *sd_rindex; struct inode *sd_quota_inode; - struct inode *sd_root_dir; /* Inum stuff */ diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index ea9e996f3673..cd1de61bff2f 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -288,7 +288,7 @@ int gfs2_inode_refresh(struct gfs2_inode *ip) * Returns: errno */ -static int inode_create(struct gfs2_glock *i_gl, struct gfs2_inum *inum, +static int inode_create(struct gfs2_glock *i_gl, const struct gfs2_inum *inum, struct gfs2_glock *io_gl, unsigned int io_state, struct gfs2_inode **ipp) { @@ -354,8 +354,8 @@ static int inode_create(struct gfs2_glock *i_gl, struct gfs2_inum *inum, * Returns: errno */ -int gfs2_inode_get(struct gfs2_glock *i_gl, struct gfs2_inum *inum, int create, - struct gfs2_inode **ipp) +int gfs2_inode_get(struct gfs2_glock *i_gl, const struct gfs2_inum *inum, + int create, struct gfs2_inode **ipp) { struct gfs2_sbd *sdp = i_gl->gl_sbd; struct gfs2_glock *io_gl; @@ -718,6 +718,7 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, struct inode **inodep) { + struct super_block *sb = dir->i_sb; struct gfs2_inode *ipp; struct gfs2_inode *dip = dir->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; @@ -733,7 +734,7 @@ int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, return -ENAMETOOLONG; if (gfs2_filecmp(name, ".", 1) || - (gfs2_filecmp(name, "..", 2) && dir == sdp->sd_root_dir)) { + (gfs2_filecmp(name, "..", 2) && dir == sb->s_root->d_inode)) { gfs2_inode_hold(dip); ipp = dip; goto done; @@ -1466,8 +1467,8 @@ int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name, int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) { - struct gfs2_sbd *sdp = this->i_sbd; struct inode *dir = to->i_vnode; + struct super_block *sb = dir->i_sb; struct inode *tmp; struct qstr dotdot; int error = 0; @@ -1483,7 +1484,7 @@ int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) error = -EINVAL; break; } - if (dir == sdp->sd_root_dir) { + if (dir == sb->s_root->d_inode) { error = 0; break; } diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index 069f0e21db6d..c3fa6cfce169 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -35,7 +35,7 @@ void gfs2_inode_min_init(struct gfs2_inode *ip, unsigned int type); int gfs2_inode_refresh(struct gfs2_inode *ip); int gfs2_inode_get(struct gfs2_glock *i_gl, - struct gfs2_inum *inum, int create, + const struct gfs2_inum *inum, int create, struct gfs2_inode **ipp); void gfs2_inode_hold(struct gfs2_inode *ip); void gfs2_inode_put(struct gfs2_inode *ip); diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index d149584cff30..a346943363c6 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -64,8 +64,8 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, int connectable) { struct inode *inode = dentry->d_inode; + struct super_block *sb = inode->i_sb; struct gfs2_inode *ip = inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; if (*len < 4 || (connectable && *len < 8)) return 255; @@ -80,7 +80,7 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, fh[3] = cpu_to_be32(fh[3]); *len = 4; - if (!connectable || ip == sdp->sd_root_dir->u.generic_ip) + if (!connectable || inode == sb->s_root->d_inode) return *len; spin_lock(&dentry->d_lock); diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 4c4115f9d960..c3b830bd838b 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -280,27 +280,30 @@ static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, return error; } -int gfs2_lookup_root(struct gfs2_sbd *sdp) +static struct inode *gfs2_lookup_root(struct gfs2_sbd *sdp, + const struct gfs2_inum *inum) { int error; struct gfs2_glock *gl; struct gfs2_inode *ip; + struct inode *inode; - error = gfs2_glock_get(sdp, sdp->sd_sb.sb_root_dir.no_addr, + error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops, CREATE, &gl); if (!error) { - error = gfs2_inode_get(gl, &sdp->sd_sb.sb_root_dir, + error = gfs2_inode_get(gl, inum, CREATE, &ip); if (!error) { if (!error) gfs2_inode_min_init(ip, DT_DIR); - sdp->sd_root_dir = gfs2_ip2v(ip); + inode = gfs2_ip2v(ip); gfs2_inode_put(ip); + return inode; } gfs2_glock_put(gl); } - return error; + return ERR_PTR(error); } static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) @@ -311,7 +314,6 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) int error = 0; if (undo) { - iput(sdp->sd_master_dir); return 0; } @@ -351,35 +353,24 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); /* Get the root inode */ - error = gfs2_lookup_root(sdp); - if (error) { + inode = gfs2_lookup_root(sdp, &sdp->sd_sb.sb_root_dir); + if (IS_ERR(inode)) { + error = PTR_ERR(inode); fs_err(sdp, "can't read in root inode: %d\n", error); goto out; } - /* Get the root inode/dentry */ - inode = sdp->sd_root_dir; - if (!inode) { - fs_err(sdp, "can't get root inode\n"); - error = -ENOMEM; - goto out_rooti; - } - - igrab(inode); sb->s_root = d_alloc_root(inode); if (!sb->s_root) { fs_err(sdp, "can't get root dentry\n"); error = -ENOMEM; - goto out_rooti; + iput(inode); } out: gfs2_glock_dq_uninit(&sb_gh); return error; -out_rooti: - iput(sdp->sd_root_dir); - goto out; } static int init_journal(struct gfs2_sbd *sdp, int undo) @@ -529,15 +520,18 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) { int error = 0; struct gfs2_inode *ip; + struct inode *inode; if (undo) goto fail_qinode; - error = gfs2_lookup_master_dir(sdp); - if (error) { + inode = gfs2_lookup_root(sdp, &sdp->sd_sb.sb_master_dir); + if (IS_ERR(inode)) { + error = PTR_ERR(inode); fs_err(sdp, "can't read in master directory: %d\n", error); goto fail; } + sdp->sd_master_dir = inode; error = init_journal(sdp, undo); if (error) diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 10f70ee12161..f7349c0989a9 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -103,7 +103,6 @@ static void gfs2_put_super(struct super_block *sb) iput(sdp->sd_statfs_inode); iput(sdp->sd_rindex); iput(sdp->sd_quota_inode); - iput(sdp->sd_root_dir); gfs2_glock_put(sdp->sd_rename_gl); gfs2_glock_put(sdp->sd_trans_gl); diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 9ccf0b9c5980..fff5a96f4152 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -447,25 +447,6 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd) return error; } -int gfs2_lookup_master_dir(struct gfs2_sbd *sdp) -{ - struct inode *inode = NULL; - struct gfs2_glock *gl; - int error; - - error = gfs2_glock_get(sdp, - sdp->sd_sb.sb_master_dir.no_addr, - &gfs2_inode_glops, CREATE, &gl); - if (!error) { - error = gfs2_lookup_simple(sdp->sd_root_dir, ".gfs2_admin", - &inode); - sdp->sd_master_dir = inode; - gfs2_glock_put(gl); - } - - return error; -} - /** * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one * @sdp: the filesystem diff --git a/fs/gfs2/super.h b/fs/gfs2/super.h index cc1a3df1949a..6abb7b5c8828 100644 --- a/fs/gfs2/super.h +++ b/fs/gfs2/super.h @@ -33,7 +33,6 @@ void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid); struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp); int gfs2_jdesc_check(struct gfs2_jdesc *jd); -int gfs2_lookup_master_dir(struct gfs2_sbd *sdp); int gfs2_lookup_in_master_dir(struct gfs2_sbd *sdp, char *filename, struct gfs2_inode **ipp); From b4dc72911d149d7d6b7ffb512bd68906f1cbd33a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 1 Mar 2006 17:41:58 -0500 Subject: [PATCH 059/292] [GFS2] Fix some bugs Fix a bug I introduced earlier with a kfree() and usage of a structure in the wrong order. Also try and get the counts of the journaled data buffers "more correct". Still some work to do in this area though. Signed-off-by: Steven Whitehouse --- fs/gfs2/log.c | 2 -- fs/gfs2/lops.c | 1 + fs/gfs2/trans.c | 13 ++++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 32a41a274bf8..e6a84f7a9b71 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -597,8 +597,6 @@ void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) sdp->sd_vfs->s_dirt = 1; unlock_from_trans(sdp); - kfree(tr); - gfs2_log_lock(sdp); if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks)) { gfs2_log_unlock(sdp); diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 430161a05a21..9d40e21f6ead 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -474,6 +474,7 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) gfs2_trans_add_gl(bd->bd_gl); list_add(&bd->bd_list_tr, &tr->tr_list_buf); gfs2_pin(sdp, bd->bd_bh); + tr->tr_num_buf_new++; } gfs2_log_lock(sdp); if (!list_empty(&le->le_list)) { diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 5d1f4a1e4077..63e7fed2bd47 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -87,7 +87,6 @@ int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, void gfs2_trans_end(struct gfs2_sbd *sdp) { struct gfs2_trans *tr; - struct gfs2_holder *t_gh; tr = current->journal_info; current->journal_info = NULL; @@ -95,13 +94,11 @@ void gfs2_trans_end(struct gfs2_sbd *sdp) if (gfs2_assert_warn(sdp, tr)) return; - t_gh = &tr->tr_t_gh; - if (!tr->tr_touched) { gfs2_log_release(sdp, tr->tr_reserved); - gfs2_glock_dq(t_gh); - gfs2_holder_uninit(t_gh); + gfs2_glock_dq(&tr->tr_t_gh); + gfs2_holder_uninit(&tr->tr_t_gh); kfree(tr); return; @@ -120,8 +117,10 @@ void gfs2_trans_end(struct gfs2_sbd *sdp) gfs2_log_commit(sdp, tr); - gfs2_glock_dq(t_gh); - gfs2_holder_uninit(t_gh); + gfs2_glock_dq(&tr->tr_t_gh); + gfs2_holder_uninit(&tr->tr_t_gh); + + kfree(tr); if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS) gfs2_log_flush(sdp); From 419c93e0b6b9eef0bf26b8ad415f2a5bf4300119 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 2 Mar 2006 16:33:41 -0500 Subject: [PATCH 060/292] [GFS2] Add gfs2meta filesystem In order to separate out the filesystem's metadata from "normal" files and directories, a new filesystem type has been created. It is called gfs2meta and mounting it gives access to the files that were previously under .gfs2_admin (well still are until mkfs is altered, which is next on the adgenda). Its not currently possible to mount both gfs2 and gfs2meta on the same block device at the same time. A future patch will allow that to happen. Signed-off-by: Steven Whitehouse --- fs/gfs2/main.c | 9 ++++++- fs/gfs2/ops_fstype.c | 58 +++++++++++++++++++++++++++----------------- fs/gfs2/ops_fstype.h | 1 + 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index c54177790318..c8d17b7ba60b 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -64,11 +64,17 @@ static int __init init_gfs2_fs(void) if (error) goto fail; + error = register_filesystem(&gfs2meta_fs_type); + if (error) + goto fail_unregister; + printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__); return 0; - fail: +fail_unregister: + unregister_filesystem(&gfs2_fs_type); +fail: if (gfs2_bufdata_cachep) kmem_cache_destroy(gfs2_bufdata_cachep); @@ -90,6 +96,7 @@ static int __init init_gfs2_fs(void) static void __exit exit_gfs2_fs(void) { unregister_filesystem(&gfs2_fs_type); + unregister_filesystem(&gfs2meta_fs_type); kmem_cache_destroy(gfs2_bufdata_cachep); kmem_cache_destroy(gfs2_inode_cachep); diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index c3b830bd838b..8d6d94143561 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -113,9 +113,9 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) return sdp; } -static void init_vfs(struct gfs2_sbd *sdp) +static void init_vfs(struct super_block *sb, unsigned noatime) { - struct super_block *sb = sdp->sd_vfs; + struct gfs2_sbd *sdp = sb->s_fs_info; sb->s_magic = GFS2_MAGIC; sb->s_op = &gfs2_super_ops; @@ -123,18 +123,10 @@ static void init_vfs(struct gfs2_sbd *sdp) sb->s_maxbytes = MAX_LFS_FILESIZE; if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME)) - set_bit(SDF_NOATIME, &sdp->sd_flags); + set_bit(noatime, &sdp->sd_flags); /* Don't let the VFS update atimes. GFS2 handles this itself. */ sb->s_flags |= MS_NOATIME | MS_NODIRATIME; - - /* Set up the buffer cache and fill in some fake block size values - to allow us to read-in the on-disk superblock. */ - sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK); - sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; - sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - - GFS2_BASIC_BLOCK_SHIFT; - sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; } static int init_names(struct gfs2_sbd *sdp, int silent) @@ -291,18 +283,16 @@ static struct inode *gfs2_lookup_root(struct gfs2_sbd *sdp, error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops, CREATE, &gl); if (!error) { - error = gfs2_inode_get(gl, inum, - CREATE, &ip); + error = gfs2_inode_get(gl, inum, CREATE, &ip); if (!error) { - if (!error) - gfs2_inode_min_init(ip, DT_DIR); + gfs2_inode_min_init(ip, DT_DIR); inode = gfs2_ip2v(ip); gfs2_inode_put(ip); + gfs2_glock_put(gl); return inode; } gfs2_glock_put(gl); } - return ERR_PTR(error); } @@ -310,6 +300,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) { struct super_block *sb = sdp->sd_vfs; struct gfs2_holder sb_gh; + struct gfs2_inum *inum; struct inode *inode; int error = 0; @@ -332,14 +323,15 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) } /* Set up the buffer cache and SB for real */ - error = -EINVAL; if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) { + error = -EINVAL; fs_err(sdp, "FS block size (%u) is too small for device " "block size (%u)\n", sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev)); goto out; } if (sdp->sd_sb.sb_bsize > PAGE_SIZE) { + error = -EINVAL; fs_err(sdp, "FS block size (%u) is too big for machine " "page size (%u)\n", sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE); @@ -353,7 +345,10 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); /* Get the root inode */ - inode = gfs2_lookup_root(sdp, &sdp->sd_sb.sb_root_dir); + inum = &sdp->sd_sb.sb_root_dir; + if (sb->s_type == &gfs2meta_fs_type) + inum = &sdp->sd_sb.sb_master_dir; + inode = gfs2_lookup_root(sdp, inum); if (IS_ERR(inode)) { error = PTR_ERR(inode); fs_err(sdp, "can't read in root inode: %d\n", error); @@ -366,10 +361,8 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) error = -ENOMEM; iput(inode); } - out: gfs2_glock_dq_uninit(&sb_gh); - return error; } @@ -791,7 +784,15 @@ static int fill_super(struct super_block *sb, void *data, int silent) goto fail; } - init_vfs(sdp); + init_vfs(sb, SDF_NOATIME); + + /* Set up the buffer cache and fill in some fake block size values + to allow us to read-in the on-disk superblock. */ + sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK); + sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; + sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - + GFS2_BASIC_BLOCK_SHIFT; + sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; error = init_names(sdp, silent); if (error) @@ -881,11 +882,24 @@ static struct super_block *gfs2_get_sb(struct file_system_type *fs_type, return get_sb_bdev(fs_type, flags, dev_name, data, fill_super); } +static void gfs2_kill_sb(struct super_block *sb) +{ + kill_block_super(sb); +} + struct file_system_type gfs2_fs_type = { .name = "gfs2", .fs_flags = FS_REQUIRES_DEV, .get_sb = gfs2_get_sb, - .kill_sb = kill_block_super, + .kill_sb = gfs2_kill_sb, + .owner = THIS_MODULE, +}; + +struct file_system_type gfs2meta_fs_type = { + .name = "gfs2meta", + .fs_flags = FS_REQUIRES_DEV, + .get_sb = gfs2_get_sb, + .kill_sb = gfs2_kill_sb, .owner = THIS_MODULE, }; diff --git a/fs/gfs2/ops_fstype.h b/fs/gfs2/ops_fstype.h index 7008364e76ea..c6452874483d 100644 --- a/fs/gfs2/ops_fstype.h +++ b/fs/gfs2/ops_fstype.h @@ -11,5 +11,6 @@ #define __OPS_FSTYPE_DOT_H__ extern struct file_system_type gfs2_fs_type; +extern struct file_system_type gfs2meta_fs_type; #endif /* __OPS_FSTYPE_DOT_H__ */ From c752666c17f870fa8ae9f16804dd457e9e6daaec Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 20 Mar 2006 12:30:04 -0500 Subject: [PATCH 061/292] [GFS2] Fix bug in directory code and tidy up Due to a typo, the dir leaf split operation was (for the first split in a directory) writing the new hash vaules at the wrong offset. This is now fixed. Also some other tidy ups are included: - We use GFS2's hash function for dentries (see ops_dentry.c) so that we don't have to keep recalculating the hash values. - A lot of common code is eliminated between the various directory lookup routines. - Better error checking on directory lookup (previously different routines checked for different errors) - The leaf split operation has a couple of redundant operations removed from it, so it should be faster. There is still further scope for further clean ups in the directory code, and readdir in particular could do with slimming down a bit. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 1362 +++++++++++++---------------------- fs/gfs2/dir.h | 39 +- fs/gfs2/inode.c | 63 +- fs/gfs2/inode.h | 16 +- fs/gfs2/ondisk.c | 13 +- fs/gfs2/ops_dentry.c | 21 +- fs/gfs2/ops_export.c | 13 +- fs/gfs2/ops_fstype.c | 56 +- fs/gfs2/ops_inode.c | 72 +- fs/gfs2/super.c | 11 +- include/linux/gfs2_ondisk.h | 3 +- 11 files changed, 684 insertions(+), 985 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 37f70ca558cc..f31f163da1a1 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -130,7 +130,7 @@ static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf, return error; gfs2_trans_add_bh(ip->i_gl, dibh, 1); - memcpy(dibh->b_data + offset + sizeof(struct gfs2_inode), buf, size); + memcpy(dibh->b_data + offset + sizeof(struct gfs2_dinode), buf, size); if (ip->i_di.di_size < offset + size) ip->i_di.di_size = offset + size; ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); @@ -177,7 +177,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, if (gfs2_is_stuffed(ip)) { error = gfs2_unstuff_dinode(ip, NULL, NULL); if (error) - return error; + return error; } lblock = offset; @@ -244,7 +244,7 @@ fail: } static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf, - unsigned int offset, unsigned int size) + unsigned int offset, unsigned int size) { struct buffer_head *dibh; int error; @@ -343,26 +343,159 @@ fail: return (copied) ? copied : error; } -/** - * int gfs2_filecmp - Compare two filenames - * @file1: The first filename - * @file2: The second filename - * @len_of_file2: The length of the second file - * - * This routine compares two filenames and returns 1 if they are equal. - * - * Returns: 1 if the files are the same, otherwise 0. - */ +typedef int (*gfs2_dscan_t)(const struct gfs2_dirent *dent, + const struct qstr *name); -int gfs2_filecmp(struct qstr *file1, char *file2, int len_of_file2) +static inline int __gfs2_dirent_find(const struct gfs2_dirent *dent, + const struct qstr *name, int ret) { - if (file1->len != len_of_file2) - return 0; - if (memcmp(file1->name, file2, file1->len)) - return 0; - return 1; + if (dent->de_inum.no_addr != 0 && + be32_to_cpu(dent->de_hash) == name->hash && + be16_to_cpu(dent->de_name_len) == name->len && + memcmp((char *)(dent+1), name->name, name->len) == 0) + return ret; + return 0; } +static int gfs2_dirent_find(const struct gfs2_dirent *dent, + const struct qstr *name) +{ + return __gfs2_dirent_find(dent, name, 1); +} + +static int gfs2_dirent_prev(const struct gfs2_dirent *dent, + const struct qstr *name) +{ + return __gfs2_dirent_find(dent, name, 2); +} + +/* + * name->name holds ptr to start of block. + * name->len holds size of block. + */ +static int gfs2_dirent_last(const struct gfs2_dirent *dent, + const struct qstr *name) +{ + const char *start = name->name; + const char *end = (const char *)dent + be16_to_cpu(dent->de_rec_len); + if (name->len == (end - start)) + return 1; + return 0; +} + +static int gfs2_dirent_find_space(const struct gfs2_dirent *dent, + const struct qstr *name) +{ + unsigned required = GFS2_DIRENT_SIZE(name->len); + unsigned actual = GFS2_DIRENT_SIZE(be16_to_cpu(dent->de_name_len)); + unsigned totlen = be16_to_cpu(dent->de_rec_len); + + if ((totlen - actual) >= required) + return 1; + return 0; +} + +/* + * Other possible things to check: + * - Inode located within filesystem size (and on valid block) + * - Valid directory entry type + * Not sure how heavy-weight we want to make this... could also check + * hash is correct for example, but that would take a lot of extra time. + * For now the most important thing is to check that the various sizes + * are correct. + */ +static int gfs2_check_dirent(struct gfs2_dirent *dent, unsigned int offset, + unsigned int size, unsigned int len, int first) +{ + const char *msg = "gfs2_dirent too small"; + if (unlikely(size < sizeof(struct gfs2_dirent))) + goto error; + msg = "gfs2_dirent misaligned"; + if (unlikely(offset & 0x7)) + goto error; + msg = "gfs2_dirent points beyond end of block"; + if (unlikely(offset + size > len)) + goto error; + msg = "zero inode number"; + if (unlikely(!first && !dent->de_inum.no_addr)) + goto error; + msg = "name length is greater than space in dirent"; + if (dent->de_inum.no_addr && + unlikely(sizeof(struct gfs2_dirent)+be16_to_cpu(dent->de_name_len) > + size)) + goto error; + return 0; +error: + printk(KERN_WARNING "gfs2_check_dirent: %s (%s)\n", msg, + first ? "first in block" : "not first in block"); + return -EIO; +} + +static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, + void *buf, + unsigned int len, gfs2_dscan_t scan, + const struct qstr *name) +{ + struct gfs2_meta_header *h = buf; + struct gfs2_dirent *dent, *prev; + unsigned offset; + unsigned size; + int ret = 0; + + BUG_ON(buf == NULL); + BUG_ON(name == NULL); + + switch(be16_to_cpu(h->mh_type)) { + case GFS2_METATYPE_LF: + offset = sizeof(struct gfs2_leaf); + break; + case GFS2_METATYPE_DI: + offset = sizeof(struct gfs2_dinode); + break; + default: + goto wrong_type; + } + + prev = NULL; + dent = (struct gfs2_dirent *)(buf + offset); + size = be16_to_cpu(dent->de_rec_len); + if (gfs2_check_dirent(dent, offset, size, len, 1)) + goto consist_inode; + do { + ret = scan(dent, name); + if (ret) + break; + offset += size; + if (offset == len) + break; + prev = dent; + dent = (struct gfs2_dirent *)(buf + offset); + size = be16_to_cpu(dent->de_rec_len); + if (gfs2_check_dirent(dent, offset, size, len, 0)) + goto consist_inode; + } while(1); + + switch(ret) { + case 0: + return NULL; + case 1: + return dent; + case 2: + return prev ? prev : dent; + default: + BUG_ON(ret > 0); + return ERR_PTR(ret); + } + +wrong_type: + printk(KERN_WARNING "gfs2_scan_dirent: %p wrong block type %u\n", scan, + be16_to_cpu(h->mh_type)); +consist_inode: + gfs2_consist_inode(inode->u.generic_ip); + return ERR_PTR(-EIO); +} + + /** * dirent_first - Return the first dirent * @dip: the directory @@ -489,180 +622,39 @@ static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh, prev->de_rec_len = cpu_to_be16(prev_rec_len); } -/** - * gfs2_dirent_alloc - Allocate a directory entry - * @dip: The GFS2 inode - * @bh: The buffer - * @name_len: The length of the name - * @dent_out: Pointer to list of dirents - * - * Returns: 0 on success, error code otherwise +/* + * Takes a dent from which to grab space as an argument. Returns the + * newly created dent. */ - -int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, - int name_len, struct gfs2_dirent **dent_out) +struct gfs2_dirent *gfs2_init_dirent(struct inode *inode, + struct gfs2_dirent *dent, + const struct qstr *name, + struct buffer_head *bh) { - struct gfs2_dirent *dent, *new; - unsigned int rec_len = GFS2_DIRENT_SIZE(name_len); - unsigned int entries = 0, offset = 0; - int type; + struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_dirent *ndent; + unsigned offset = 0, totlen; - type = dirent_first(dip, bh, &dent); - if (type < 0) - return type; - - if (type == IS_LEAF) { - struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data; - entries = be16_to_cpu(leaf->lf_entries); - offset = sizeof(struct gfs2_leaf); - } else { - struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data; - entries = be32_to_cpu(dinode->di_entries); - offset = sizeof(struct gfs2_dinode); - } - - if (!entries) { - if (dent->de_inum.no_addr) { - gfs2_consist_inode(dip); - return -EIO; - } - - gfs2_trans_add_bh(dip->i_gl, bh, 1); - - dent->de_rec_len = cpu_to_be16(bh->b_size - offset); - dent->de_name_len = cpu_to_be16(name_len); - - *dent_out = dent; - return 0; - } - - do { - uint16_t cur_rec_len; - uint16_t cur_name_len; - - cur_rec_len = be16_to_cpu(dent->de_rec_len); - cur_name_len = be16_to_cpu(dent->de_name_len); - - if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || - (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) { - gfs2_trans_add_bh(dip->i_gl, bh, 1); - - if (dent->de_inum.no_addr) { - new = (struct gfs2_dirent *)((char *)dent + - GFS2_DIRENT_SIZE(cur_name_len)); - memset(new, 0, sizeof(struct gfs2_dirent)); - - new->de_rec_len = cpu_to_be16(cur_rec_len - - GFS2_DIRENT_SIZE(cur_name_len)); - new->de_name_len = cpu_to_be16(name_len); - - dent->de_rec_len = cpu_to_be16(cur_rec_len - - be16_to_cpu(new->de_rec_len)); - - *dent_out = new; - return 0; - } - - dent->de_name_len = cpu_to_be16(name_len); - - *dent_out = dent; - return 0; - } - } while (dirent_next(dip, bh, &dent) == 0); - - return -ENOSPC; + if (dent->de_inum.no_addr) + offset = GFS2_DIRENT_SIZE(be16_to_cpu(dent->de_name_len)); + totlen = be16_to_cpu(dent->de_rec_len); + BUG_ON(offset + name->len > totlen); + gfs2_trans_add_bh(ip->i_gl, bh, 1); + ndent = (struct gfs2_dirent *)((char *)dent + offset); + dent->de_rec_len = cpu_to_be16(offset); + gfs2_qstr2dirent(name, totlen - offset, ndent); + return ndent; } -/** - * dirent_fits - See if we can fit a entry in this buffer - * @dip: The GFS2 inode - * @bh: The buffer - * @name_len: The length of the name - * - * Returns: 1 if it can fit, 0 otherwise - */ - -static int dirent_fits(struct gfs2_inode *dip, struct buffer_head *bh, - int name_len) +static struct gfs2_dirent *gfs2_dirent_alloc(struct inode *inode, + struct buffer_head *bh, + const struct qstr *name) { struct gfs2_dirent *dent; - unsigned int rec_len = GFS2_DIRENT_SIZE(name_len); - unsigned int entries = 0; - int type; - - type = dirent_first(dip, bh, &dent); - if (type < 0) - return type; - - if (type == IS_LEAF) { - struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data; - entries = be16_to_cpu(leaf->lf_entries); - } else { - struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data; - entries = be32_to_cpu(dinode->di_entries); - } - - if (!entries) - return 1; - - do { - uint16_t cur_rec_len; - uint32_t cur_name_len; - - cur_rec_len = be16_to_cpu(dent->de_rec_len); - cur_name_len = be16_to_cpu(dent->de_name_len); - - if ((!dent->de_inum.no_addr && cur_rec_len >= rec_len) || - (cur_rec_len >= GFS2_DIRENT_SIZE(cur_name_len) + rec_len)) - return 1; - } while (dirent_next(dip, bh, &dent) == 0); - - return 0; -} - -static int leaf_search(struct gfs2_inode *dip, struct buffer_head *bh, - struct qstr *filename, struct gfs2_dirent **dent_out, - struct gfs2_dirent **dent_prev) -{ - uint32_t hash; - struct gfs2_dirent *dent, *prev = NULL; - unsigned int entries = 0; - int type; - - type = dirent_first(dip, bh, &dent); - if (type < 0) - return type; - - if (type == IS_LEAF) { - struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data; - entries = be16_to_cpu(leaf->lf_entries); - } else if (type == IS_DINODE) { - struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data; - entries = be32_to_cpu(dinode->di_entries); - } - - hash = gfs2_disk_hash(filename->name, filename->len); - - do { - if (!dent->de_inum.no_addr) { - prev = dent; - continue; - } - - if (be32_to_cpu(dent->de_hash) == hash && - gfs2_filecmp(filename, (char *)(dent + 1), - be16_to_cpu(dent->de_name_len))) { - *dent_out = dent; - if (dent_prev) - *dent_prev = prev; - - return 0; - } - - prev = dent; - } while (dirent_next(dip, bh, &dent) == 0); - - return -ENOENT; + dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, gfs2_dirent_find_space, name); + if (!dent || IS_ERR(dent)) + return dent; + return gfs2_init_dirent(inode, dent, name, bh); } static int get_leaf(struct gfs2_inode *dip, uint64_t leaf_no, @@ -716,75 +708,81 @@ static int get_first_leaf(struct gfs2_inode *dip, uint32_t index, return error; } -static int get_next_leaf(struct gfs2_inode *dip, struct buffer_head *bh_in, - struct buffer_head **bh_out) +static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, + const struct qstr *name, + gfs2_dscan_t scan, + struct buffer_head **pbh) { - struct gfs2_leaf *leaf; + struct buffer_head *bh; + struct gfs2_dirent *dent; + struct gfs2_inode *ip = inode->u.generic_ip; int error; - leaf = (struct gfs2_leaf *)bh_in->b_data; - - if (!leaf->lf_next) - error = -ENOENT; - else - error = get_leaf(dip, be64_to_cpu(leaf->lf_next), bh_out); - - return error; -} - -static int linked_leaf_search(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_dirent **dent_out, - struct gfs2_dirent **dent_prev, - struct buffer_head **bh_out) -{ - struct buffer_head *bh = NULL, *bh_next; - uint32_t hsize, index; - uint32_t hash; - int error; - - hsize = 1 << dip->i_di.di_depth; - if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { - gfs2_consist_inode(dip); - return -EIO; - } - - /* Figure out the address of the leaf node. */ - - hash = gfs2_disk_hash(filename->name, filename->len); - index = hash >> (32 - dip->i_di.di_depth); - - error = get_first_leaf(dip, index, &bh_next); - if (error) - return error; - - /* Find the entry */ - - do { - brelse(bh); - - bh = bh_next; - - error = leaf_search(dip, bh, filename, dent_out, dent_prev); - switch (error) { - case 0: - *bh_out = bh; - return 0; - - case -ENOENT: - break; - - default: - brelse(bh); - return error; + if (ip->i_di.di_flags & GFS2_DIF_EXHASH) { + struct gfs2_leaf *leaf; + unsigned hsize = 1 << ip->i_di.di_depth; + unsigned index; + u64 ln; + if (hsize * sizeof(u64) != ip->i_di.di_size) { + gfs2_consist_inode(ip); + return ERR_PTR(-EIO); } - error = get_next_leaf(dip, bh, &bh_next); + index = name->hash >> (32 - ip->i_di.di_depth); + error = get_first_leaf(ip, index, &bh); + if (error) + return ERR_PTR(error); + do { + dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, + scan, name); + if (dent) + goto got_dent; + leaf = (struct gfs2_leaf *)bh->b_data; + ln = be64_to_cpu(leaf->lf_next); + brelse(bh); + if (!ln) + break; + error = get_leaf(ip, ln, &bh); + } while(!error); + + return error ? ERR_PTR(error) : NULL; } - while (!error); - brelse(bh); + error = gfs2_meta_inode_buffer(ip, &bh); + if (error) + return ERR_PTR(error); + dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, scan, name); +got_dent: + *pbh = bh; + return dent; +} - return error; +static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, u16 depth) +{ + struct gfs2_inode *ip = inode->u.generic_ip; + u64 bn = gfs2_alloc_meta(ip); + struct buffer_head *bh = gfs2_meta_new(ip->i_gl, bn); + struct gfs2_leaf *leaf; + struct gfs2_dirent *dent; + if (!bh) + return NULL; + gfs2_trans_add_bh(ip->i_gl, bh, 1); + gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); + leaf = (struct gfs2_leaf *)bh->b_data; + leaf->lf_depth = cpu_to_be16(depth); + leaf->lf_entries = cpu_to_be16(0); + leaf->lf_dirent_format = cpu_to_be16(GFS2_FORMAT_DE); + leaf->lf_next = cpu_to_be64(0); + memset(leaf->lf_reserved, 0, sizeof(leaf->lf_reserved)); + dent = (struct gfs2_dirent *)(leaf+1); + dent->de_inum.no_formal_ino = cpu_to_be64(0); + dent->de_inum.no_addr = cpu_to_be64(0); + dent->de_hash = cpu_to_be32(0); + dent->de_rec_len = cpu_to_be16(bh->b_size - sizeof(struct gfs2_leaf)); + dent->de_name_len = cpu_to_be16(0); + dent->de_type = cpu_to_be16(0); + *pbh = bh; + return leaf; } /** @@ -794,10 +792,12 @@ static int linked_leaf_search(struct gfs2_inode *dip, struct qstr *filename, * Returns: 0 on success, error code otherwise */ -static int dir_make_exhash(struct gfs2_inode *dip) +static int dir_make_exhash(struct inode *inode) { + struct gfs2_inode *dip = inode->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; struct gfs2_dirent *dent; + struct qstr args; struct buffer_head *bh, *dibh; struct gfs2_leaf *leaf; int y; @@ -809,24 +809,14 @@ static int dir_make_exhash(struct gfs2_inode *dip) if (error) return error; - /* Allocate a new block for the first leaf node */ - - bn = gfs2_alloc_meta(dip); - /* Turn over a new leaf */ - bh = gfs2_meta_new(dip->i_gl, bn); - gfs2_trans_add_bh(dip->i_gl, bh, 1); - gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); - gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); - - /* Fill in the leaf structure */ - - leaf = (struct gfs2_leaf *)bh->b_data; + leaf = new_leaf(inode, &bh, 0); + if (!leaf) + return -ENOSPC; + bn = bh->b_blocknr; gfs2_assert(sdp, dip->i_di.di_entries < (1 << 16)); - - leaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE); leaf->lf_entries = cpu_to_be16(dip->i_di.di_entries); /* Copy dirents */ @@ -837,15 +827,21 @@ static int dir_make_exhash(struct gfs2_inode *dip) /* Find last entry */ x = 0; - dirent_first(dip, bh, &dent); - - do { - if (!dent->de_inum.no_addr) - continue; - if (++x == dip->i_di.di_entries) - break; + args.len = bh->b_size - sizeof(struct gfs2_dinode) + + sizeof(struct gfs2_leaf); + args.name = bh->b_data; + dent = gfs2_dirent_scan(dip->i_vnode, bh->b_data, bh->b_size, + gfs2_dirent_last, &args); + if (!dent) { + brelse(bh); + brelse(dibh); + return -EIO; + } + if (IS_ERR(dent)) { + brelse(bh); + brelse(dibh); + return PTR_ERR(dent); } - while (dirent_next(dip, bh, &dent) == 0); /* Adjust the last dirent's record length (Remember that dent still points to the last entry.) */ @@ -891,45 +887,39 @@ static int dir_make_exhash(struct gfs2_inode *dip) * Returns: 0 on success, error code on failure */ -static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, - uint64_t leaf_no) +static int dir_split_leaf(struct inode *inode, const struct qstr *name) { + struct gfs2_inode *dip = inode->u.generic_ip; struct buffer_head *nbh, *obh, *dibh; struct gfs2_leaf *nleaf, *oleaf; struct gfs2_dirent *dent, *prev = NULL, *next = NULL, *new; uint32_t start, len, half_len, divider; - uint64_t bn, *lp; - uint32_t name_len; + uint64_t bn, *lp, leaf_no; + uint32_t index; int x, moved = 0; int error; - /* Allocate the new leaf block */ - - bn = gfs2_alloc_meta(dip); - - /* Get the new leaf block */ - - nbh = gfs2_meta_new(dip->i_gl, bn); - gfs2_trans_add_bh(dip->i_gl, nbh, 1); - gfs2_metatype_set(nbh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); - gfs2_buffer_clear_tail(nbh, sizeof(struct gfs2_meta_header)); - - nleaf = (struct gfs2_leaf *)nbh->b_data; - - nleaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE); + index = name->hash >> (32 - dip->i_di.di_depth); + error = get_leaf_nr(dip, index, &leaf_no); + if (error) + return error; /* Get the old leaf block */ - error = get_leaf(dip, leaf_no, &obh); if (error) goto fail; gfs2_trans_add_bh(dip->i_gl, obh, 1); - oleaf = (struct gfs2_leaf *)obh->b_data; - /* Compute the start and len of leaf pointers in the hash table. */ + nleaf = new_leaf(inode, &nbh, be16_to_cpu(oleaf->lf_depth) + 1); + if (!nleaf) { + brelse(obh); + return -ENOSPC; + } + bn = nbh->b_blocknr; + /* Compute the start and len of leaf pointers in the hash table. */ len = 1 << (dip->i_di.di_depth - be16_to_cpu(oleaf->lf_depth)); half_len = len >> 1; if (!half_len) { @@ -943,19 +933,8 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, /* Change the pointers. Don't bother distinguishing stuffed from non-stuffed. This code is complicated enough already. */ - - lp = kcalloc(half_len, sizeof(uint64_t), GFP_KERNEL | __GFP_NOFAIL); - - error = gfs2_dir_read_data(dip, (char *)lp, start * sizeof(uint64_t), - half_len * sizeof(uint64_t)); - if (error != half_len * sizeof(uint64_t)) { - if (error >= 0) - error = -EIO; - goto fail_lpfree; - } - + lp = kmalloc(half_len * sizeof(uint64_t), GFP_NOFS | __GFP_NOFAIL); /* Change the pointers */ - for (x = 0; x < half_len; x++) lp[x] = cpu_to_be64(bn); @@ -970,11 +949,9 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, kfree(lp); /* Compute the divider */ - divider = (start + half_len) << (32 - dip->i_di.di_depth); /* Copy the entries */ - dirent_first(dip, obh, &dent); do { @@ -984,48 +961,37 @@ static int dir_split_leaf(struct gfs2_inode *dip, uint32_t index, if (dent->de_inum.no_addr && be32_to_cpu(dent->de_hash) < divider) { - name_len = be16_to_cpu(dent->de_name_len); - - gfs2_dirent_alloc(dip, nbh, name_len, &new); + struct qstr str; + str.name = (char*)(dent+1); + str.len = be16_to_cpu(dent->de_name_len); + str.hash = be32_to_cpu(dent->de_hash); + new = gfs2_dirent_alloc(dip->i_vnode, nbh, &str); + if (IS_ERR(new)) { + error = PTR_ERR(new); + break; + } new->de_inum = dent->de_inum; /* No endian worries */ - new->de_hash = dent->de_hash; /* No endian worries */ new->de_type = dent->de_type; /* No endian worries */ - memcpy((char *)(new + 1), (char *)(dent + 1), - name_len); - - nleaf->lf_entries = be16_to_cpu(nleaf->lf_entries)+1; - nleaf->lf_entries = cpu_to_be16(nleaf->lf_entries); + nleaf->lf_entries = cpu_to_be16(be16_to_cpu(nleaf->lf_entries)+1); dirent_del(dip, obh, prev, dent); if (!oleaf->lf_entries) gfs2_consist_inode(dip); - oleaf->lf_entries = be16_to_cpu(oleaf->lf_entries)-1; - oleaf->lf_entries = cpu_to_be16(oleaf->lf_entries); + oleaf->lf_entries = cpu_to_be16(be16_to_cpu(oleaf->lf_entries)-1); if (!prev) prev = dent; moved = 1; - } else + } else { prev = dent; - + } dent = next; - } - while (dent); + } while (dent); - /* If none of the entries got moved into the new leaf, - artificially fill in the first entry. */ - - if (!moved) { - gfs2_dirent_alloc(dip, nbh, 0, &new); - new->de_inum.no_addr = 0; - } - - oleaf->lf_depth = be16_to_cpu(oleaf->lf_depth) + 1; - oleaf->lf_depth = cpu_to_be16(oleaf->lf_depth); - nleaf->lf_depth = oleaf->lf_depth; + oleaf->lf_depth = nleaf->lf_depth; error = gfs2_meta_inode_buffer(dip, &dibh); if (!gfs2_assert_withdraw(dip->i_sbd, !error)) { @@ -1142,12 +1108,10 @@ static int compare_dents(const void *a, const void *b) int ret = 0; dent_a = *(struct gfs2_dirent **)a; - hash_a = dent_a->de_hash; - hash_a = be32_to_cpu(hash_a); + hash_a = be32_to_cpu(dent_a->de_hash); dent_b = *(struct gfs2_dirent **)b; - hash_b = dent_b->de_hash; - hash_b = be32_to_cpu(hash_b); + hash_b = be32_to_cpu(dent_b->de_hash); if (hash_a > hash_b) ret = 1; @@ -1292,8 +1256,7 @@ static int do_filldir_single(struct gfs2_inode *dip, uint64_t *offset, goto out; } darr[e++] = de; - } - while (dirent_next(dip, bh, &de) == 0); + } while (dirent_next(dip, bh, &de) == 0); if (e != entries) { gfs2_consist_inode(dip); @@ -1341,11 +1304,9 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset, leaf = (struct gfs2_leaf *)bh->b_data; entries = be16_to_cpu(leaf->lf_entries); - ln = leaf->lf_next; + ln = be64_to_cpu(leaf->lf_next); while (ln) { - ln = be64_to_cpu(ln); - error = get_leaf(dip, ln, &tmp_bh); if (error) return error; @@ -1355,7 +1316,7 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset, entries += be16_to_cpu(leaf->lf_entries); leaves++; } - ln = leaf->lf_next; + ln = be64_to_cpu(leaf->lf_next); brelse(tmp_bh); } @@ -1387,14 +1348,11 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset, goto out; } darr[e++] = de; - } - while (dirent_next(dip, bh, &de) == 0); + } while (dirent_next(dip, bh, &de) == 0); } - ln = leaf->lf_next; + ln = be64_to_cpu(leaf->lf_next); while (ln) { - ln = be64_to_cpu(ln); - error = get_leaf(dip, ln, &tmp_bh); if (error) goto out; @@ -1411,14 +1369,13 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset, goto out; } darr[e++] = de; - } - while (dirent_next(dip, tmp_bh, &de) == 0); + } while (dirent_next(dip, tmp_bh, &de) == 0); larr[l++] = tmp_bh; - ln = leaf->lf_next; + ln = be64_to_cpu(leaf->lf_next); } else { - ln = leaf->lf_next; + ln = be64_to_cpu(leaf->lf_next); brelse(tmp_bh); } } @@ -1445,207 +1402,6 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset, return error; } -/** - * dir_e_search - Search exhash (leaf) dir for inode matching name - * @dip: The GFS2 inode - * @filename: Filename string - * @inode: If non-NULL, function fills with formal inode # and block address - * @type: If non-NULL, function fills with DT_... dinode type - * - * Returns: - */ - -static int dir_e_search(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_inum *inum, unsigned int *type) -{ - struct buffer_head *bh; - struct gfs2_dirent *dent; - int error; - - error = linked_leaf_search(dip, filename, &dent, NULL, &bh); - if (error) - return error; - - if (inum) - gfs2_inum_in(inum, (char *)&dent->de_inum); - if (type) - *type = be16_to_cpu(dent->de_type); - - brelse(bh); - - return 0; -} - -static int dir_e_add(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_inum *inum, unsigned int type) -{ - struct buffer_head *bh, *nbh, *dibh; - struct gfs2_leaf *leaf, *nleaf; - struct gfs2_dirent *dent; - uint32_t hsize, index; - uint32_t hash; - uint64_t leaf_no, bn; - int error; - - restart: - hsize = 1 << dip->i_di.di_depth; - if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { - gfs2_consist_inode(dip); - return -EIO; - } - - /* Figure out the address of the leaf node. */ - - hash = gfs2_disk_hash(filename->name, filename->len); - index = hash >> (32 - dip->i_di.di_depth); - - error = get_leaf_nr(dip, index, &leaf_no); - if (error) - return error; - - /* Add entry to the leaf */ - - for (;;) { - error = get_leaf(dip, leaf_no, &bh); - if (error) - return error; - - leaf = (struct gfs2_leaf *)bh->b_data; - - if (gfs2_dirent_alloc(dip, bh, filename->len, &dent)) { - - if (be16_to_cpu(leaf->lf_depth) < dip->i_di.di_depth) { - /* Can we split the leaf? */ - - brelse(bh); - - error = dir_split_leaf(dip, index, leaf_no); - if (error) - return error; - - goto restart; - - } else if (dip->i_di.di_depth < GFS2_DIR_MAX_DEPTH) { - /* Can we double the hash table? */ - - brelse(bh); - - error = dir_double_exhash(dip); - if (error) - return error; - - goto restart; - - } else if (leaf->lf_next) { - /* Can we try the next leaf in the list? */ - leaf_no = be64_to_cpu(leaf->lf_next); - brelse(bh); - continue; - - } else { - /* Create a new leaf and add it to the list. */ - - bn = gfs2_alloc_meta(dip); - - nbh = gfs2_meta_new(dip->i_gl, bn); - gfs2_trans_add_bh(dip->i_gl, nbh, 1); - gfs2_metatype_set(nbh, - GFS2_METATYPE_LF, - GFS2_FORMAT_LF); - gfs2_buffer_clear_tail(nbh, - sizeof(struct gfs2_meta_header)); - - gfs2_trans_add_bh(dip->i_gl, bh, 1); - leaf->lf_next = cpu_to_be64(bn); - - nleaf = (struct gfs2_leaf *)nbh->b_data; - nleaf->lf_depth = leaf->lf_depth; - nleaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE); - - gfs2_dirent_alloc(dip, nbh, filename->len, - &dent); - - dip->i_di.di_blocks++; - - brelse(bh); - - bh = nbh; - leaf = nleaf; - } - } - - /* If the gfs2_dirent_alloc() succeeded, it pinned the "bh" */ - - gfs2_inum_out(inum, (char *)&dent->de_inum); - dent->de_hash = cpu_to_be32(hash); - dent->de_type = cpu_to_be16(type); - memcpy((char *)(dent + 1), filename->name, filename->len); - - leaf->lf_entries = be16_to_cpu(leaf->lf_entries) + 1; - leaf->lf_entries = cpu_to_be16(leaf->lf_entries); - - brelse(bh); - - error = gfs2_meta_inode_buffer(dip, &dibh); - if (error) - return error; - - dip->i_di.di_entries++; - dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); - - gfs2_trans_add_bh(dip->i_gl, dibh, 1); - gfs2_dinode_out(&dip->i_di, dibh->b_data); - brelse(dibh); - - return 0; - } - - return -ENOENT; -} - -static int dir_e_del(struct gfs2_inode *dip, struct qstr *filename) -{ - struct buffer_head *bh, *dibh; - struct gfs2_dirent *dent, *prev; - struct gfs2_leaf *leaf; - unsigned int entries; - int error; - - error = linked_leaf_search(dip, filename, &dent, &prev, &bh); - if (error == -ENOENT) { - gfs2_consist_inode(dip); - return -EIO; - } - if (error) - return error; - - dirent_del(dip, bh, prev, dent); /* Pins bh */ - - leaf = (struct gfs2_leaf *)bh->b_data; - entries = be16_to_cpu(leaf->lf_entries); - if (!entries) - gfs2_consist_inode(dip); - entries--; - leaf->lf_entries = cpu_to_be16(entries); - - brelse(bh); - - error = gfs2_meta_inode_buffer(dip, &dibh); - if (error) - return error; - - if (!dip->i_di.di_entries) - gfs2_consist_inode(dip); - dip->i_di.di_entries--; - dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); - - gfs2_trans_add_bh(dip->i_gl, dibh, 1); - gfs2_dinode_out(&dip->i_di, dibh->b_data); - brelse(dibh); - - return 0; -} - /** * dir_e_read - Reads the entries from a directory into a filldir buffer * @dip: dinode pointer @@ -1661,7 +1417,7 @@ static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, { struct gfs2_sbd *sdp = dip->i_sbd; struct buffer_head *bh; - struct gfs2_leaf leaf; + struct gfs2_leaf *leaf; uint32_t hsize, len; uint32_t ht_offset, lp_offset, ht_offset_cur = -1; uint32_t hash, index; @@ -1702,14 +1458,15 @@ static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, if (error) goto out; - gfs2_leaf_in(&leaf, bh->b_data); - - if (leaf.lf_next) + leaf = (struct gfs2_leaf *)bh->b_data; + if (leaf->lf_next) error = do_filldir_multi(dip, offset, opaque, filldir, bh, &copied); else error = do_filldir_single(dip, offset, opaque, filldir, - bh, leaf.lf_entries, &copied); + bh, + be16_to_cpu(leaf->lf_entries), + &copied); brelse(bh); @@ -1719,7 +1476,7 @@ static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, goto out; } - len = 1 << (dip->i_di.di_depth - leaf.lf_depth); + len = 1 << (dip->i_di.di_depth - be16_to_cpu(leaf->lf_depth)); index = (index & ~(len - 1)) + len; } @@ -1729,165 +1486,6 @@ static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, return error; } -static int dir_e_mvino(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_inum *inum, unsigned int new_type) -{ - struct buffer_head *bh, *dibh; - struct gfs2_dirent *dent; - int error; - - error = linked_leaf_search(dip, filename, &dent, NULL, &bh); - if (error == -ENOENT) { - gfs2_consist_inode(dip); - return -EIO; - } - if (error) - return error; - - gfs2_trans_add_bh(dip->i_gl, bh, 1); - - gfs2_inum_out(inum, (char *)&dent->de_inum); - dent->de_type = cpu_to_be16(new_type); - - brelse(bh); - - error = gfs2_meta_inode_buffer(dip, &dibh); - if (error) - return error; - - dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); - - gfs2_trans_add_bh(dip->i_gl, dibh, 1); - gfs2_dinode_out(&dip->i_di, dibh->b_data); - brelse(dibh); - - return 0; -} - -/** - * dir_l_search - Search linear (stuffed dinode) dir for inode matching name - * @dip: The GFS2 inode - * @filename: Filename string - * @inode: If non-NULL, function fills with formal inode # and block address - * @type: If non-NULL, function fills with DT_... dinode type - * - * Returns: - */ - -static int dir_l_search(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_inum *inum, unsigned int *type) -{ - struct buffer_head *dibh; - struct gfs2_dirent *dent; - int error; - - if (!gfs2_is_stuffed(dip)) { - gfs2_consist_inode(dip); - return -EIO; - } - - error = gfs2_meta_inode_buffer(dip, &dibh); - if (error) - return error; - - error = leaf_search(dip, dibh, filename, &dent, NULL); - if (!error) { - if (inum) - gfs2_inum_in(inum, (char *)&dent->de_inum); - if (type) - *type = be16_to_cpu(dent->de_type); - } - - brelse(dibh); - - return error; -} - -static int dir_l_add(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_inum *inum, unsigned int type) -{ - struct buffer_head *dibh; - struct gfs2_dirent *dent; - int error; - - if (!gfs2_is_stuffed(dip)) { - gfs2_consist_inode(dip); - return -EIO; - } - - error = gfs2_meta_inode_buffer(dip, &dibh); - if (error) - return error; - - if (gfs2_dirent_alloc(dip, dibh, filename->len, &dent)) { - brelse(dibh); - - error = dir_make_exhash(dip); - if (!error) - error = dir_e_add(dip, filename, inum, type); - - return error; - } - - /* gfs2_dirent_alloc() pins */ - - gfs2_inum_out(inum, (char *)&dent->de_inum); - dent->de_hash = gfs2_disk_hash(filename->name, filename->len); - dent->de_hash = cpu_to_be32(dent->de_hash); - dent->de_type = cpu_to_be16(type); - memcpy((char *)(dent + 1), filename->name, filename->len); - - dip->i_di.di_entries++; - dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); - - gfs2_dinode_out(&dip->i_di, dibh->b_data); - brelse(dibh); - - return 0; -} - -static int dir_l_del(struct gfs2_inode *dip, struct qstr *filename) -{ - struct buffer_head *dibh; - struct gfs2_dirent *dent, *prev; - int error; - - if (!gfs2_is_stuffed(dip)) { - gfs2_consist_inode(dip); - return -EIO; - } - - error = gfs2_meta_inode_buffer(dip, &dibh); - if (error) - return error; - - error = leaf_search(dip, dibh, filename, &dent, &prev); - if (error == -ENOENT) { - gfs2_consist_inode(dip); - error = -EIO; - goto out; - } - if (error) - goto out; - - dirent_del(dip, dibh, prev, dent); - - /* dirent_del() pins */ - - if (!dip->i_di.di_entries) - gfs2_consist_inode(dip); - dip->i_di.di_entries--; - - dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); - - gfs2_dinode_out(&dip->i_di, dibh->b_data); - - out: - brelse(dibh); - - return error; -} - static int dir_l_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, gfs2_filldir_t filldir) { @@ -1919,46 +1517,6 @@ static int dir_l_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, return error; } -static int dir_l_mvino(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_inum *inum, unsigned int new_type) -{ - struct buffer_head *dibh; - struct gfs2_dirent *dent; - int error; - - if (!gfs2_is_stuffed(dip)) { - gfs2_consist_inode(dip); - return -EIO; - } - - error = gfs2_meta_inode_buffer(dip, &dibh); - if (error) - return error; - - error = leaf_search(dip, dibh, filename, &dent, NULL); - if (error == -ENOENT) { - gfs2_consist_inode(dip); - error = -EIO; - goto out; - } - if (error) - goto out; - - gfs2_trans_add_bh(dip->i_gl, dibh, 1); - - gfs2_inum_out(inum, (char *)&dent->de_inum); - dent->de_type = cpu_to_be16(new_type); - - dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); - - gfs2_dinode_out(&dip->i_di, dibh->b_data); - - out: - brelse(dibh); - - return error; -} - /** * gfs2_dir_search - Search a directory * @dip: The GFS2 inode @@ -1971,17 +1529,69 @@ static int dir_l_mvino(struct gfs2_inode *dip, struct qstr *filename, * Returns: errno */ -int gfs2_dir_search(struct gfs2_inode *dip, struct qstr *filename, +int gfs2_dir_search(struct inode *dir, const struct qstr *name, struct gfs2_inum *inum, unsigned int *type) { + struct buffer_head *bh; + struct gfs2_dirent *dent; + + dent = gfs2_dirent_search(dir, name, gfs2_dirent_find, &bh); + if (dent) { + if (IS_ERR(dent)) + return PTR_ERR(dent); + if (inum) + gfs2_inum_in(inum, (char *)&dent->de_inum); + if (type) + *type = be16_to_cpu(dent->de_type); + brelse(bh); + return 0; + } + return -ENOENT; +} + +static int dir_new_leaf(struct inode *inode, const struct qstr *name) +{ + struct buffer_head *bh, *obh; + struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_leaf *leaf, *oleaf; int error; + u32 index; + u64 bn; - if (dip->i_di.di_flags & GFS2_DIF_EXHASH) - error = dir_e_search(dip, filename, inum, type); - else - error = dir_l_search(dip, filename, inum, type); + index = name->hash >> (32 - ip->i_di.di_depth); + error = get_first_leaf(ip, index, &obh); + if (error) + return error; + do { + oleaf = (struct gfs2_leaf *)obh->b_data; + bn = be64_to_cpu(oleaf->lf_next); + if (!bn) + break; + brelse(obh); + error = get_leaf(ip, bn, &obh); + if (error) + return error; + } while(1); - return error; + gfs2_trans_add_bh(ip->i_gl, obh, 1); + + leaf = new_leaf(inode, &bh, be16_to_cpu(oleaf->lf_depth)); + if (!leaf) { + brelse(obh); + return -ENOSPC; + } + oleaf->lf_next = cpu_to_be64(bn); + brelse(bh); + brelse(obh); + + error = gfs2_meta_inode_buffer(ip, &bh); + if (error) + return error; + gfs2_trans_add_bh(ip->i_gl, bh, 1); + ip->i_di.di_blocks++; + gfs2_dinode_out(&ip->i_di, bh->b_data); + brelse(bh); + return 0; } /** @@ -1994,19 +1604,70 @@ int gfs2_dir_search(struct gfs2_inode *dip, struct qstr *filename, * Returns: 0 on success, error code on failure */ -int gfs2_dir_add(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_inum *inum, unsigned int type) +int gfs2_dir_add(struct inode *inode, const struct qstr *name, + const struct gfs2_inum *inum, unsigned type) { + struct gfs2_inode *ip = inode->u.generic_ip; + struct buffer_head *bh; + struct gfs2_dirent *dent; + struct gfs2_leaf *leaf; int error; - if (dip->i_di.di_flags & GFS2_DIF_EXHASH) - error = dir_e_add(dip, filename, inum, type); - else - error = dir_l_add(dip, filename, inum, type); - + while(1) { + dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, + &bh); + if (dent) { + if (IS_ERR(dent)) + return PTR_ERR(dent); + dent = gfs2_init_dirent(inode, dent, name, bh); + gfs2_inum_out(inum, (char *)&dent->de_inum); + dent->de_type = cpu_to_be16(type); + if (ip->i_di.di_flags & GFS2_DIF_EXHASH) { + leaf = (struct gfs2_leaf *)bh->b_data; + leaf->lf_entries = cpu_to_be16(be16_to_cpu(leaf->lf_entries) + 1); + } + brelse(bh); + error = gfs2_meta_inode_buffer(ip, &bh); + if (error) + break; + gfs2_trans_add_bh(ip->i_gl, bh, 1); + ip->i_di.di_entries++; + ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); + gfs2_dinode_out(&ip->i_di, bh->b_data); + brelse(bh); + error = 0; + break; + } + if (!(ip->i_di.di_flags & GFS2_DIF_EXHASH)) { + error = dir_make_exhash(inode); + if (error) + break; + continue; + } + error = dir_split_leaf(inode, name); + if (error == 0) + continue; + if (error != -ENOSPC) + break; + if (ip->i_di.di_depth < GFS2_DIR_MAX_DEPTH) { + error = dir_double_exhash(ip); + if (error) + break; + error = dir_split_leaf(inode, name); + if (error) + break; + continue; + } + error = dir_new_leaf(inode, name); + if (!error) + continue; + error = -ENOSPC; + break; + } return error; } + /** * gfs2_dir_del - Delete a directory entry * @dip: The GFS2 inode @@ -2015,14 +1676,50 @@ int gfs2_dir_add(struct gfs2_inode *dip, struct qstr *filename, * Returns: 0 on success, error code on failure */ -int gfs2_dir_del(struct gfs2_inode *dip, struct qstr *filename) +int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name) { + struct gfs2_dirent *dent, *prev = NULL; + struct buffer_head *bh; int error; - if (dip->i_di.di_flags & GFS2_DIF_EXHASH) - error = dir_e_del(dip, filename); - else - error = dir_l_del(dip, filename); + /* Returns _either_ the entry (if its first in block) or the + previous entry otherwise */ + dent = gfs2_dirent_search(dip->i_vnode, name, gfs2_dirent_prev, &bh); + if (!dent) { + gfs2_consist_inode(dip); + return -EIO; + } + if (IS_ERR(dent)) { + gfs2_consist_inode(dip); + return PTR_ERR(dent); + } + /* If not first in block, adjust pointers accordingly */ + if (gfs2_dirent_find(dent, name) == 0) { + prev = dent; + dent = (struct gfs2_dirent *)((char *)dent + be16_to_cpu(prev->de_rec_len)); + } + + dirent_del(dip, bh, prev, dent); + if (dip->i_di.di_flags & GFS2_DIF_EXHASH) { + struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data; + u16 entries = be16_to_cpu(leaf->lf_entries); + if (!entries) + gfs2_consist_inode(dip); + leaf->lf_entries = cpu_to_be16(--entries); + brelse(bh); + } + + error = gfs2_meta_inode_buffer(dip, &bh); + if (error) + return error; + + if (!dip->i_di.di_entries) + gfs2_consist_inode(dip); + gfs2_trans_add_bh(dip->i_gl, bh, 1); + dip->i_di.di_entries--; + dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); + gfs2_dinode_out(&dip->i_di, bh->b_data); + brelse(bh); return error; } @@ -2053,17 +1750,37 @@ int gfs2_dir_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, * Returns: errno */ -int gfs2_dir_mvino(struct gfs2_inode *dip, struct qstr *filename, +int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, struct gfs2_inum *inum, unsigned int new_type) { + struct buffer_head *bh; + struct gfs2_dirent *dent; int error; - if (dip->i_di.di_flags & GFS2_DIF_EXHASH) - error = dir_e_mvino(dip, filename, inum, new_type); - else - error = dir_l_mvino(dip, filename, inum, new_type); + dent = gfs2_dirent_search(dip->i_vnode, filename, gfs2_dirent_find, &bh); + if (!dent) { + gfs2_consist_inode(dip); + return -EIO; + } + if (IS_ERR(dent)) + return PTR_ERR(dent); - return error; + gfs2_trans_add_bh(dip->i_gl, bh, 1); + gfs2_inum_out(inum, (char *)&dent->de_inum); + dent->de_type = cpu_to_be16(new_type); + + if (dip->i_di.di_flags & GFS2_DIF_EXHASH) { + brelse(bh); + error = gfs2_meta_inode_buffer(dip, &bh); + if (error) + return error; + gfs2_trans_add_bh(dip->i_gl, bh, 1); + } + + dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); + gfs2_dinode_out(&dip->i_di, bh->b_data); + brelse(bh); + return 0; } /** @@ -2079,7 +1796,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) { struct gfs2_sbd *sdp = dip->i_sbd; struct buffer_head *bh; - struct gfs2_leaf leaf; + struct gfs2_leaf *leaf; uint32_t hsize, len; uint32_t ht_offset, lp_offset, ht_offset_cur = -1; uint32_t index = 0; @@ -2118,10 +1835,10 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) error = get_leaf(dip, leaf_no, &bh); if (error) goto out; - gfs2_leaf_in(&leaf, bh->b_data); + leaf = (struct gfs2_leaf *)bh->b_data; brelse(bh); - len = 1 << (dip->i_di.di_depth - leaf.lf_depth); + len = 1 << (dip->i_di.di_depth - be16_to_cpu(leaf->lf_depth)); error = lc(dip, index, len, leaf_no, data); if (error) @@ -2158,10 +1875,10 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, uint64_t leaf_no, void *data) { struct gfs2_sbd *sdp = dip->i_sbd; - struct gfs2_leaf tmp_leaf; + struct gfs2_leaf *tmp_leaf; struct gfs2_rgrp_list rlist; struct buffer_head *bh, *dibh; - uint64_t blk; + uint64_t blk, nblk; unsigned int rg_blocks = 0, l_blocks = 0; char *ht; unsigned int x, size = len * sizeof(uint64_t); @@ -2185,11 +1902,12 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, /* Count the number of leaves */ - for (blk = leaf_no; blk; blk = tmp_leaf.lf_next) { + for (blk = leaf_no; blk; blk = nblk) { error = get_leaf(dip, blk, &bh); if (error) goto out_rlist; - gfs2_leaf_in(&tmp_leaf, (bh)->b_data); + tmp_leaf = (struct gfs2_leaf *)bh->b_data; + nblk = be64_to_cpu(tmp_leaf->lf_next); brelse(bh); gfs2_rlist_add(sdp, &rlist, blk); @@ -2214,11 +1932,12 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, if (error) goto out_rg_gunlock; - for (blk = leaf_no; blk; blk = tmp_leaf.lf_next) { + for (blk = leaf_no; blk; blk = nblk) { error = get_leaf(dip, blk, &bh); if (error) goto out_end_trans; - gfs2_leaf_in(&tmp_leaf, bh->b_data); + tmp_leaf = (struct gfs2_leaf *)bh->b_data; + nblk = be64_to_cpu(tmp_leaf->lf_next); brelse(bh); gfs2_free_meta(dip, blk, 1); @@ -2308,63 +2027,22 @@ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip) * gfs2_diradd_alloc_required - find if adding entry will require an allocation * @ip: the file being written to * @filname: the filename that's going to be added - * @alloc_required: set to 1 if an alloc is required, 0 otherwise * - * Returns: errno + * Returns: 1 if alloc required, 0 if not, -ve on error */ -int gfs2_diradd_alloc_required(struct gfs2_inode *dip, struct qstr *filename, - int *alloc_required) +int gfs2_diradd_alloc_required(struct inode *inode, + const struct qstr *name) { - struct buffer_head *bh = NULL, *bh_next; - uint32_t hsize, hash, index; - int error = 0; + struct gfs2_dirent *dent; + struct buffer_head *bh; - *alloc_required = 0; - - if (dip->i_di.di_flags & GFS2_DIF_EXHASH) { - hsize = 1 << dip->i_di.di_depth; - if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { - gfs2_consist_inode(dip); - return -EIO; - } - - hash = gfs2_disk_hash(filename->name, filename->len); - index = hash >> (32 - dip->i_di.di_depth); - - error = get_first_leaf(dip, index, &bh_next); - if (error) - return error; - - do { - brelse(bh); - - bh = bh_next; - - if (dirent_fits(dip, bh, filename->len)) - break; - - error = get_next_leaf(dip, bh, &bh_next); - if (error == -ENOENT) { - *alloc_required = 1; - error = 0; - break; - } - } - while (!error); - - brelse(bh); - } else { - error = gfs2_meta_inode_buffer(dip, &bh); - if (error) - return error; - - if (!dirent_fits(dip, bh, filename->len)) - *alloc_required = 1; - - brelse(bh); - } - - return error; + dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh); + if (!dent) + return 1; + if (IS_ERR(dent)) + return PTR_ERR(dent); + brelse(bh); + return 0; } diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h index 5b01497b3ab3..8fd4dc0f700e 100644 --- a/fs/gfs2/dir.h +++ b/fs/gfs2/dir.h @@ -27,25 +27,34 @@ typedef int (*gfs2_filldir_t) (void *opaque, uint64_t offset, struct gfs2_inum *inum, unsigned int type); -int gfs2_filecmp(struct qstr *file1, char *file2, int len_of_file2); -int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh, - int name_len, struct gfs2_dirent **dent_out); - -int gfs2_dir_search(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_inum *inum, unsigned int *type); -int gfs2_dir_add(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_inum *inum, unsigned int type); -int gfs2_dir_del(struct gfs2_inode *dip, struct qstr *filename); +int gfs2_dir_search(struct inode *dir, const struct qstr *filename, + struct gfs2_inum *inum, unsigned int *type); +int gfs2_dir_add(struct inode *inode, const struct qstr *filename, + const struct gfs2_inum *inum, unsigned int type); +int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *filename); int gfs2_dir_read(struct gfs2_inode *dip, uint64_t * offset, void *opaque, - gfs2_filldir_t filldir); -int gfs2_dir_mvino(struct gfs2_inode *dip, struct qstr *filename, - struct gfs2_inum *new_inum, unsigned int new_type); + gfs2_filldir_t filldir); +int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, + struct gfs2_inum *new_inum, unsigned int new_type); int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip); -int gfs2_diradd_alloc_required(struct gfs2_inode *dip, struct qstr *filename, - int *alloc_required); +int gfs2_diradd_alloc_required(struct inode *dir, + const struct qstr *filename); int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, - struct buffer_head **bhp); + struct buffer_head **bhp); + +/* N.B. This probably ought to take inum & type as args as well */ +static inline void gfs2_qstr2dirent(const struct qstr *name, u16 reclen, struct gfs2_dirent *dent) +{ + dent->de_inum.no_addr = cpu_to_be64(0); + dent->de_inum.no_formal_ino = cpu_to_be64(0); + dent->de_hash = cpu_to_be32(name->hash); + dent->de_rec_len = cpu_to_be16(reclen); + dent->de_name_len = cpu_to_be16(name->len); + dent->de_type = cpu_to_be16(0); + memset(dent->__pad, 0, sizeof(dent->__pad)); + memcpy((char*)(dent+1), name->name, name->len); +} #endif /* __DIR_DOT_H__ */ diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index cd1de61bff2f..d403d51d5b0f 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -228,12 +228,10 @@ struct inode *gfs2_iget(struct super_block *sb, struct gfs2_inum *inum) void gfs2_inode_min_init(struct gfs2_inode *ip, unsigned int type) { - spin_lock(&ip->i_spin); if (!test_and_set_bit(GIF_MIN_INIT, &ip->i_flags)) { ip->i_di.di_nlink = 1; ip->i_di.di_mode = DT2IF(type); } - spin_unlock(&ip->i_spin); } /** @@ -257,10 +255,8 @@ int gfs2_inode_refresh(struct gfs2_inode *ip) return -EIO; } - spin_lock(&ip->i_spin); gfs2_dinode_in(&ip->i_di, dibh->b_data); set_bit(GIF_MIN_INIT, &ip->i_flags); - spin_unlock(&ip->i_spin); brelse(dibh); @@ -702,6 +698,16 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) return 0; } +struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) +{ + struct qstr qstr; + qstr.name = name; + qstr.len = strlen(name); + qstr.hash = gfs2_disk_hash(qstr.name, qstr.len); + return gfs2_lookupi(dip, &qstr, 1, NULL); +} + + /** * gfs2_lookupi - Look up a filename in a directory and return its inode * @d_gh: An initialized holder for the directory glock @@ -715,8 +721,9 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) * Returns: errno */ -int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, - struct inode **inodep) +struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, + struct nameidata *nd) + { struct super_block *sb = dir->i_sb; struct gfs2_inode *ipp; @@ -727,14 +734,14 @@ int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, unsigned int type; struct gfs2_glock *gl; int error = 0; - - *inodep = NULL; + struct inode *inode = NULL; if (!name->len || name->len > GFS2_FNAMESIZE) - return -ENAMETOOLONG; + return ERR_PTR(-ENAMETOOLONG); - if (gfs2_filecmp(name, ".", 1) || - (gfs2_filecmp(name, "..", 2) && dir == sb->s_root->d_inode)) { + if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) || + (name->len == 2 && memcmp(name->name, "..", 2) == 0 && + dir == sb->s_root->d_inode)) { gfs2_inode_hold(dip); ipp = dip; goto done; @@ -742,7 +749,7 @@ int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); if (error) - return error; + return ERR_PTR(error); if (!is_root) { error = gfs2_repermission(dip->i_vnode, MAY_EXEC, NULL); @@ -750,7 +757,7 @@ int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, goto out; } - error = gfs2_dir_search(dip, name, &inum, &type); + error = gfs2_dir_search(dir, name, &inum, &type); if (error) goto out; @@ -768,13 +775,16 @@ int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, out: gfs2_glock_dq_uninit(&d_gh); done: + if (error == -ENOENT) + return NULL; if (error == 0) { - *inodep = gfs2_ip2v(ipp); - if (!*inodep) - error = -ENOMEM; + inode = gfs2_ip2v(ipp); gfs2_inode_put(ipp); + if (!inode) + return ERR_PTR(-ENOMEM); + return inode; } - return error; + return ERR_PTR(error); } static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) @@ -918,7 +928,7 @@ static int create_ok(struct gfs2_inode *dip, struct qstr *name, if (!dip->i_di.di_nlink) return -EPERM; - error = gfs2_dir_search(dip, name, NULL, NULL); + error = gfs2_dir_search(dip->i_vnode, name, NULL, NULL); switch (error) { case -ENOENT: error = 0; @@ -1116,7 +1126,9 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name, if (error) goto fail; - error = gfs2_diradd_alloc_required(dip, name, &alloc_required); + error = alloc_required = gfs2_diradd_alloc_required(dip->i_vnode, name); + if (alloc_required < 0) + goto fail; if (alloc_required) { error = gfs2_quota_check(dip, dip->i_di.di_uid, dip->i_di.di_gid); @@ -1145,7 +1157,7 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name, goto fail_quota_locks; } - error = gfs2_dir_add(dip, name, &ip->i_num, IF2DT(ip->i_di.di_mode)); + error = gfs2_dir_add(dip->i_vnode, name, &ip->i_num, IF2DT(ip->i_di.di_mode)); if (error) goto fail_end_trans; @@ -1379,12 +1391,14 @@ int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, dotname.len = 1; dotname.name = "."; + dotname.hash = gfs2_disk_hash(dotname.name, dotname.len); error = gfs2_dir_del(ip, &dotname); if (error) return error; dotname.len = 2; dotname.name = ".."; + dotname.hash = gfs2_disk_hash(dotname.name, dotname.len); error = gfs2_dir_del(ip, &dotname); if (error) return error; @@ -1439,7 +1453,7 @@ int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name, if (error) return error; - error = gfs2_dir_search(dip, name, &inum, &type); + error = gfs2_dir_search(dip->i_vnode, name, &inum, &type); if (error) return error; @@ -1476,6 +1490,7 @@ int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) memset(&dotdot, 0, sizeof(struct qstr)); dotdot.name = ".."; dotdot.len = 2; + dotdot.hash = gfs2_disk_hash(dotdot.name, dotdot.len); igrab(dir); @@ -1489,9 +1504,11 @@ int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) break; } - error = gfs2_lookupi(dir, &dotdot, 1, &tmp); - if (error) + tmp = gfs2_lookupi(dir, &dotdot, 1, NULL); + if (IS_ERR(tmp)) { + error = PTR_ERR(tmp); break; + } iput(dir); dir = tmp; diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index c3fa6cfce169..0dd2a26626ec 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -44,8 +44,8 @@ void gfs2_inode_destroy(struct gfs2_inode *ip); int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); int gfs2_change_nlink(struct gfs2_inode *ip, int diff); -int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, - struct inode **ipp); +struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, + struct nameidata *nd); struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, unsigned int mode); int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name, @@ -66,17 +66,7 @@ int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr); int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd); -static inline int gfs2_lookup_simple(struct inode *dip, char *name, - struct inode **ipp) -{ - struct qstr qstr; - int err; - memset(&qstr, 0, sizeof(struct qstr)); - qstr.name = name; - qstr.len = strlen(name); - err = gfs2_lookupi(dip, &qstr, 1, ipp); - return err; -} +struct inode *gfs2_lookup_simple(struct inode *dip, const char *name); #endif /* __INODE_DOT_H__ */ diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index 5a0bdc22a1f4..3be060f1cbe7 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -64,7 +64,7 @@ void gfs2_inum_in(struct gfs2_inum *no, char *buf) no->no_addr = be64_to_cpu(str->no_addr); } -void gfs2_inum_out(struct gfs2_inum *no, char *buf) +void gfs2_inum_out(const struct gfs2_inum *no, char *buf) { struct gfs2_inum *str = (struct gfs2_inum *)buf; @@ -342,17 +342,6 @@ void gfs2_dirent_print(struct gfs2_dirent *de, char *name) printk(KERN_INFO " name = %s\n", buf); } -void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf) -{ - struct gfs2_leaf *str = (struct gfs2_leaf *)buf; - - gfs2_meta_header_in(&lf->lf_header, buf); - lf->lf_depth = be16_to_cpu(str->lf_depth); - lf->lf_entries = be16_to_cpu(str->lf_entries); - lf->lf_dirent_format = be32_to_cpu(str->lf_dirent_format); - lf->lf_next = be64_to_cpu(str->lf_next); -} - void gfs2_leaf_print(struct gfs2_leaf *lf) { gfs2_meta_header_print(&lf->lf_header); diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index 7f6139288519..b54608f9df50 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -38,25 +38,26 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) { struct dentry *parent = dget_parent(dentry); + struct gfs2_sbd *sdp = parent->d_inode->i_sb->s_fs_info; struct gfs2_inode *dip = parent->d_inode->u.generic_ip; - struct inode *inode; + struct inode *inode = dentry->d_inode; struct gfs2_holder d_gh; struct gfs2_inode *ip; struct gfs2_inum inum; unsigned int type; int error; - lock_kernel(); - - inode = dentry->d_inode; if (inode && is_bad_inode(inode)) goto invalid; + if (sdp->sd_args.ar_localcaching) + goto valid; + error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); if (error) goto fail; - error = gfs2_dir_search(dip, &dentry->d_name, &inum, &type); + error = gfs2_dir_search(parent->d_inode, &dentry->d_name, &inum, &type); switch (error) { case 0: if (!inode) @@ -84,7 +85,6 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) gfs2_glock_dq_uninit(&d_gh); valid: - unlock_kernel(); dput(parent); return 1; @@ -99,7 +99,6 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) } d_drop(dentry); - unlock_kernel(); dput(parent); return 0; @@ -107,12 +106,18 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) gfs2_glock_dq_uninit(&d_gh); fail: - unlock_kernel(); dput(parent); return 0; } +static int gfs2_dhash(struct dentry *dentry, struct qstr *str) +{ + str->hash = gfs2_disk_hash(str->name, str->len); + return 0; +} + struct dentry_operations gfs2_dops = { .d_revalidate = gfs2_drevalidate, + .d_hash = gfs2_dhash, }; diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index a346943363c6..b27bce74a795 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -24,6 +24,7 @@ #include "inode.h" #include "ops_export.h" #include "rgrp.h" +#include "util.h" static struct dentry *gfs2_decode_fh(struct super_block *sb, __u32 *fh, @@ -167,11 +168,15 @@ static struct dentry *gfs2_get_parent(struct dentry *child) struct qstr dotdot = { .name = "..", .len = 2 }; struct inode *inode; struct dentry *dentry; - int error; - error = gfs2_lookupi(child->d_inode, &dotdot, 1, &inode); - if (error) - return ERR_PTR(error); + dotdot.hash = gfs2_disk_hash(dotdot.name, dotdot.len); + + inode = gfs2_lookupi(child->d_inode, &dotdot, 1, NULL); + + if (!inode) + return ERR_PTR(-ENOENT); + if (IS_ERR(inode)) + return ERR_PTR(PTR_ERR(inode)); dentry = d_alloc_anon(inode); if (!dentry) { diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 8d6d94143561..8d2c557b3ff4 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -379,11 +379,10 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) goto fail_recoverd; } - error = gfs2_lookup_simple(sdp->sd_master_dir, "jindex", - &sdp->sd_jindex); - if (error) { + sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex"); + if (IS_ERR(sdp->sd_jindex)) { fs_err(sdp, "can't lookup journal index: %d\n", error); - return error; + return PTR_ERR(sdp->sd_jindex); } ip = sdp->sd_jindex->u.generic_ip; set_bit(GLF_STICKY, &ip->i_gl->gl_flags); @@ -531,26 +530,26 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) goto fail_master; /* Read in the master inode number inode */ - error = gfs2_lookup_simple(sdp->sd_master_dir, "inum", - &sdp->sd_inum_inode); - if (error) { + sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum"); + if (IS_ERR(sdp->sd_inum_inode)) { + error = PTR_ERR(sdp->sd_inum_inode); fs_err(sdp, "can't read in inum inode: %d\n", error); goto fail_journal; } /* Read in the master statfs inode */ - error = gfs2_lookup_simple(sdp->sd_master_dir, "statfs", - &sdp->sd_statfs_inode); - if (error) { + sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs"); + if (IS_ERR(sdp->sd_statfs_inode)) { + error = PTR_ERR(sdp->sd_statfs_inode); fs_err(sdp, "can't read in statfs inode: %d\n", error); goto fail_inum; } /* Read in the resource index inode */ - error = gfs2_lookup_simple(sdp->sd_master_dir, "rindex", - &sdp->sd_rindex); - if (error) { + sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex"); + if (IS_ERR(sdp->sd_rindex)) { + error = PTR_ERR(sdp->sd_rindex); fs_err(sdp, "can't get resource index inode: %d\n", error); goto fail_statfs; } @@ -559,9 +558,9 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1; /* Read in the quota inode */ - error = gfs2_lookup_simple(sdp->sd_master_dir, "quota", - &sdp->sd_quota_inode); - if (error) { + sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota"); + if (IS_ERR(sdp->sd_quota_inode)) { + error = PTR_ERR(sdp->sd_quota_inode); fs_err(sdp, "can't get quota file inode: %d\n", error); goto fail_rindex; } @@ -600,36 +599,41 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) if (undo) goto fail_qc_gh; - error = gfs2_lookup_simple(sdp->sd_master_dir, "per_node", &pn); - if (error) { + pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node"); + if (IS_ERR(pn)) { + error = PTR_ERR(pn); fs_err(sdp, "can't find per_node directory: %d\n", error); return error; } sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid); - error = gfs2_lookup_simple(pn, buf, &sdp->sd_ir_inode); - if (error) { + sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf); + if (IS_ERR(sdp->sd_ir_inode)) { + error = PTR_ERR(sdp->sd_ir_inode); fs_err(sdp, "can't find local \"ir\" file: %d\n", error); goto fail; } sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid); - error = gfs2_lookup_simple(pn, buf, &sdp->sd_sc_inode); - if (error) { + sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf); + if (IS_ERR(sdp->sd_sc_inode)) { + error = PTR_ERR(sdp->sd_sc_inode); fs_err(sdp, "can't find local \"sc\" file: %d\n", error); goto fail_ir_i; } sprintf(buf, "unlinked_tag%u", sdp->sd_jdesc->jd_jid); - error = gfs2_lookup_simple(pn, buf, &sdp->sd_ut_inode); - if (error) { + sdp->sd_ut_inode = gfs2_lookup_simple(pn, buf); + if (IS_ERR(sdp->sd_ut_inode)) { + error = PTR_ERR(sdp->sd_ut_inode); fs_err(sdp, "can't find local \"ut\" file: %d\n", error); goto fail_sc_i; } sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid); - error = gfs2_lookup_simple(pn, buf, &sdp->sd_qc_inode); - if (error) { + sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf); + if (IS_ERR(sdp->sd_qc_inode)) { + error = PTR_ERR(sdp->sd_qc_inode); fs_err(sdp, "can't find local \"qc\" file: %d\n", error); goto fail_ut_i; } diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 7633a8584b0d..e8ab9d254b76 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -58,7 +58,6 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, struct gfs2_holder ghs[2]; struct inode *inode; int new = 1; - int error; gfs2_holder_init(dip->i_gl, 0, 0, ghs); @@ -78,14 +77,16 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, return PTR_ERR(inode); } - error = gfs2_lookupi(dir, &dentry->d_name, 0, &inode); - if (!error) { - new = 0; - gfs2_holder_uninit(ghs); - break; - } else if (error != -ENOENT) { - gfs2_holder_uninit(ghs); - return error; + inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd); + if (inode) { + if (!IS_ERR(inode)) { + new = 0; + gfs2_holder_uninit(ghs); + break; + } else { + gfs2_holder_uninit(ghs); + return PTR_ERR(inode); + } } } @@ -110,17 +111,13 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) { - struct gfs2_inode *dip = dir->u.generic_ip; - struct gfs2_sbd *sdp = dip->i_sbd; struct inode *inode = NULL; - int error; - if (!sdp->sd_args.ar_localcaching) - dentry->d_op = &gfs2_dops; + dentry->d_op = &gfs2_dops; - error = gfs2_lookupi(dir, &dentry->d_name, 0, &inode); - if (error && error != -ENOENT) - return ERR_PTR(error); + inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd); + if (inode && IS_ERR(inode)) + return ERR_PTR(PTR_ERR(inode)); if (inode) return d_splice_alias(inode, dentry); @@ -166,7 +163,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, if (error) goto out_gunlock; - error = gfs2_dir_search(dip, &dentry->d_name, NULL, NULL); + error = gfs2_dir_search(dir, &dentry->d_name, NULL, NULL); switch (error) { case -ENOENT: break; @@ -192,10 +189,10 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, if (ip->i_di.di_nlink == (uint32_t)-1) goto out_gunlock; - error = gfs2_diradd_alloc_required(dip, &dentry->d_name, - &alloc_required); - if (error) + alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name); + if (error < 0) goto out_gunlock; + error = 0; if (alloc_required) { struct gfs2_alloc *al = gfs2_alloc_get(dip); @@ -228,7 +225,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, goto out_ipres; } - error = gfs2_dir_add(dip, &dentry->d_name, &ip->i_num, + error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num, IF2DT(ip->i_di.di_mode)); if (error) goto out_end_trans; @@ -419,24 +416,24 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) if (!gfs2_assert_withdraw(sdp, !error)) { struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data; - struct gfs2_dirent *dent; - - gfs2_dirent_alloc(ip, dibh, 1, &dent); + struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1); + struct qstr str = { .name = ".", .len = 1 }; + str.hash = gfs2_disk_hash(str.name, str.len); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); + gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent); dent->de_inum = di->di_num; /* already GFS2 endian */ - dent->de_hash = gfs2_disk_hash(".", 1); - dent->de_hash = cpu_to_be32(dent->de_hash); dent->de_type = DT_DIR; - memcpy((char *) (dent + 1), ".", 1); di->di_entries = cpu_to_be32(1); - gfs2_dirent_alloc(ip, dibh, 2, &dent); + str.name = ".."; + str.len = 2; + str.hash = gfs2_disk_hash(str.name, str.len); + dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1)); + gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent); gfs2_inum_out(&dip->i_num, (char *) &dent->de_inum); - dent->de_hash = gfs2_disk_hash("..", 2); - dent->de_hash = cpu_to_be32(dent->de_hash); dent->de_type = DT_DIR; - memcpy((char *) (dent + 1), "..", 2); gfs2_dinode_out(&ip->i_di, (char *)di); @@ -687,7 +684,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, if (error) goto out_gunlock; - error = gfs2_dir_search(ndip, &ndentry->d_name, NULL, NULL); + error = gfs2_dir_search(ndir, &ndentry->d_name, NULL, NULL); switch (error) { case -ENOENT: error = 0; @@ -723,10 +720,10 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, goto out_gunlock; } - error = gfs2_diradd_alloc_required(ndip, &ndentry->d_name, - &alloc_required); - if (error) + alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name); + if (error < 0) goto out_gunlock; + error = 0; if (alloc_required) { struct gfs2_alloc *al = gfs2_alloc_get(ndip); @@ -777,6 +774,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, struct qstr name; name.len = 2; name.name = ".."; + name.hash = gfs2_disk_hash(name.name, name.len); error = gfs2_change_nlink(ndip, +1); if (error) @@ -803,7 +801,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, if (error) goto out_end_trans; - error = gfs2_dir_add(ndip, &ndentry->d_name, &ip->i_num, + error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num, IF2DT(ip->i_di.di_mode)); if (error) goto out_end_trans; diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index fff5a96f4152..71cca7629403 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -299,8 +299,9 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) break; name.len = sprintf(buf, "journal%u", sdp->sd_journals); + name.hash = gfs2_disk_hash(name.name, name.len); - error = gfs2_dir_search(sdp->sd_jindex->u.generic_ip, + error = gfs2_dir_search(sdp->sd_jindex, &name, NULL, NULL); if (error == -ENOENT) { error = 0; @@ -317,8 +318,12 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) if (!jd) break; - error = gfs2_lookupi(sdp->sd_jindex, &name, 1, &jd->jd_inode); - if (error) { + jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1, NULL); + if (!jd->jd_inode || IS_ERR(jd->jd_inode)) { + if (!jd->jd_inode) + error = -ENOENT; + else + error = PTR_ERR(jd->jd_inode); kfree(jd); break; } diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index 8d4f0445df47..a5fb4f99aa45 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -411,7 +411,7 @@ struct gfs2_quota_change { /* Translation functions */ extern void gfs2_inum_in(struct gfs2_inum *no, char *buf); -extern void gfs2_inum_out(struct gfs2_inum *no, char *buf); +extern void gfs2_inum_out(const struct gfs2_inum *no, char *buf); extern void gfs2_sb_in(struct gfs2_sb *sb, char *buf); extern void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf); extern void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf); @@ -421,7 +421,6 @@ extern void gfs2_quota_in(struct gfs2_quota *qu, char *buf); extern void gfs2_quota_out(struct gfs2_quota *qu, char *buf); extern void gfs2_dinode_in(struct gfs2_dinode *di, char *buf); extern void gfs2_dinode_out(struct gfs2_dinode *di, char *buf); -extern void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf); extern void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf); extern void gfs2_ea_header_out(struct gfs2_ea_header *ea, char *buf); extern void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf); From 94aabbd99370f738da4f6cb4ea0b94cd9024002f Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 21 Mar 2006 11:29:00 -0500 Subject: [PATCH 062/292] [GFS2] Remove ioctl support The various flags on inodes will in future be set and queried via the extended attributes interface, so this interface is no longer required. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 95 -------------------------------------- include/linux/gfs2_ioctl.h | 17 ------- 2 files changed, 112 deletions(-) delete mode 100644 include/linux/gfs2_ioctl.h diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index d30c6db46241..6333a14cf77a 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -532,98 +531,6 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) return error; } -static int gfs2_ioctl_flags(struct gfs2_inode *ip, unsigned int cmd, - unsigned long arg) -{ - unsigned int lmode = (cmd == GFS2_IOCTL_SETFLAGS) ? - LM_ST_EXCLUSIVE : LM_ST_SHARED; - struct buffer_head *dibh; - struct gfs2_holder i_gh; - int error; - __u32 flags = 0, change; - - if (cmd == GFS2_IOCTL_SETFLAGS) { - error = get_user(flags, (__u32 __user *)arg); - if (error) - return -EFAULT; - } - - error = gfs2_glock_nq_init(ip->i_gl, lmode, 0, &i_gh); - if (error) - return error; - - if (cmd == GFS2_IOCTL_SETFLAGS) { - change = flags ^ ip->i_di.di_flags; - error = -EPERM; - if (change & (GFS2_DIF_IMMUTABLE|GFS2_DIF_APPENDONLY)) { - if (!capable(CAP_LINUX_IMMUTABLE)) - goto out; - } - error = -EINVAL; - if (flags & (GFS2_DIF_JDATA|GFS2_DIF_DIRECTIO)) { - if (!S_ISREG(ip->i_di.di_mode)) - goto out; - } - if (flags & - (GFS2_DIF_INHERIT_JDATA|GFS2_DIF_INHERIT_DIRECTIO)) { - if (!S_ISDIR(ip->i_di.di_mode)) - goto out; - } - - error = gfs2_trans_begin(ip->i_sbd, RES_DINODE, 0); - if (error) - goto out; - - error = gfs2_meta_inode_buffer(ip, &dibh); - if (error) - goto out_trans_end; - - ip->i_di.di_flags = flags; - - gfs2_trans_add_bh(ip->i_gl, dibh, 1); - gfs2_dinode_out(&ip->i_di, dibh->b_data); - - brelse(dibh); - -out_trans_end: - gfs2_trans_end(ip->i_sbd); - } else { - flags = ip->i_di.di_flags; - } -out: - gfs2_glock_dq_uninit(&i_gh); - if (cmd == GFS2_IOCTL_GETFLAGS) { - if (put_user(flags, (__u32 __user *)arg)) - return -EFAULT; - } - return error; -} - -/** - * gfs2_ioctl - do an ioctl on a file - * @inode: the inode - * @file: the file pointer - * @cmd: the ioctl command - * @arg: the argument - * - * Returns: errno - */ - -static int gfs2_ioctl(struct inode *inode, struct file *file, unsigned int cmd, - unsigned long arg) -{ - struct gfs2_inode *ip = inode->u.generic_ip; - - switch (cmd) { - case GFS2_IOCTL_SETFLAGS: - case GFS2_IOCTL_GETFLAGS: - return gfs2_ioctl_flags(ip, cmd, arg); - - default: - return -ENOTTY; - } -} - /** * gfs2_mmap - * @file: The file to map @@ -925,7 +832,6 @@ struct file_operations gfs2_file_fops = { .write = generic_file_write, .writev = generic_file_writev, .aio_write = generic_file_aio_write, - .ioctl = gfs2_ioctl, .mmap = gfs2_mmap, .open = gfs2_open, .release = gfs2_close, @@ -937,7 +843,6 @@ struct file_operations gfs2_file_fops = { struct file_operations gfs2_dir_fops = { .readdir = gfs2_readdir, - .ioctl = gfs2_ioctl, .open = gfs2_open, .release = gfs2_close, .fsync = gfs2_fsync, diff --git a/include/linux/gfs2_ioctl.h b/include/linux/gfs2_ioctl.h deleted file mode 100644 index fb7c0cf72c56..000000000000 --- a/include/linux/gfs2_ioctl.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#ifndef __GFS2_IOCTL_DOT_H__ -#define __GFS2_IOCTL_DOT_H__ - -#define GFS2_IOCTL_SETFLAGS _IOW('g', 3, long) -#define GFS2_IOCTL_GETFLAGS _IOR('g', 4, long) - -#endif /* ___GFS2_IOCTL_DOT_H__ */ - From 71b86f562b5eb6f94ea00bba060caa64d0137969 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 28 Mar 2006 14:14:04 -0500 Subject: [PATCH 063/292] [GFS2] Further updates to dir and logging code This reduces the size of the directory code by about 3k and gets readdir() to use the functions which were introduced in the previous directory code update. Two memory allocations are merged into one. Eliminates zeroing of some buffers which were never used before they were initialised by other data. There is still scope for further improvement in the directory code. On the logging side, a hand created mutex has been replaced by a standard Linux mutex in the log allocation code. Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 1 + fs/gfs2/dir.c | 412 +++++++++++++++++-------------------------- fs/gfs2/dir.h | 15 +- fs/gfs2/incore.h | 3 +- fs/gfs2/inode.c | 14 +- fs/gfs2/log.c | 34 +--- fs/gfs2/ops_dentry.c | 1 + fs/gfs2/ops_export.c | 8 +- fs/gfs2/ops_file.c | 219 ++++++++++++++++++++++- fs/gfs2/ops_fstype.c | 4 +- fs/gfs2/ops_inode.c | 13 +- fs/gfs2/recovery.c | 2 + fs/gfs2/super.c | 1 + fs/gfs2/util.c | 5 - fs/gfs2/util.h | 2 - 15 files changed, 416 insertions(+), 318 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index cd5e4d863ce2..c7723119acb6 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "gfs2.h" diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index f31f163da1a1..ba3438553f33 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -60,6 +60,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -344,7 +345,8 @@ fail: } typedef int (*gfs2_dscan_t)(const struct gfs2_dirent *dent, - const struct qstr *name); + const struct qstr *name, + void *opaque); static inline int __gfs2_dirent_find(const struct gfs2_dirent *dent, const struct qstr *name, int ret) @@ -358,13 +360,15 @@ static inline int __gfs2_dirent_find(const struct gfs2_dirent *dent, } static int gfs2_dirent_find(const struct gfs2_dirent *dent, - const struct qstr *name) + const struct qstr *name, + void *opaque) { return __gfs2_dirent_find(dent, name, 1); } static int gfs2_dirent_prev(const struct gfs2_dirent *dent, - const struct qstr *name) + const struct qstr *name, + void *opaque) { return __gfs2_dirent_find(dent, name, 2); } @@ -374,7 +378,8 @@ static int gfs2_dirent_prev(const struct gfs2_dirent *dent, * name->len holds size of block. */ static int gfs2_dirent_last(const struct gfs2_dirent *dent, - const struct qstr *name) + const struct qstr *name, + void *opaque) { const char *start = name->name; const char *end = (const char *)dent + be16_to_cpu(dent->de_rec_len); @@ -384,17 +389,36 @@ static int gfs2_dirent_last(const struct gfs2_dirent *dent, } static int gfs2_dirent_find_space(const struct gfs2_dirent *dent, - const struct qstr *name) + const struct qstr *name, + void *opaque) { unsigned required = GFS2_DIRENT_SIZE(name->len); unsigned actual = GFS2_DIRENT_SIZE(be16_to_cpu(dent->de_name_len)); unsigned totlen = be16_to_cpu(dent->de_rec_len); + if (!dent->de_inum.no_addr) + actual = GFS2_DIRENT_SIZE(0); if ((totlen - actual) >= required) return 1; return 0; } +struct dirent_gather { + const struct gfs2_dirent **pdent; + unsigned offset; +}; + +static int gfs2_dirent_gather(const struct gfs2_dirent *dent, + const struct qstr *name, + void *opaque) +{ + struct dirent_gather *g = opaque; + if (dent->de_inum.no_addr) { + g->pdent[g->offset++] = dent; + } + return 0; +} + /* * Other possible things to check: * - Inode located within filesystem size (and on valid block) @@ -431,19 +455,12 @@ error: return -EIO; } -static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, - void *buf, - unsigned int len, gfs2_dscan_t scan, - const struct qstr *name) +static int gfs2_dirent_offset(const void *buf) { - struct gfs2_meta_header *h = buf; - struct gfs2_dirent *dent, *prev; - unsigned offset; - unsigned size; - int ret = 0; + const struct gfs2_meta_header *h = buf; + int offset; BUG_ON(buf == NULL); - BUG_ON(name == NULL); switch(be16_to_cpu(h->mh_type)) { case GFS2_METATYPE_LF: @@ -455,14 +472,36 @@ static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, default: goto wrong_type; } + return offset; +wrong_type: + printk(KERN_WARNING "gfs2_scan_dirent: wrong block type %u\n", + be16_to_cpu(h->mh_type)); + return -1; +} +static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, + void *buf, + unsigned int len, gfs2_dscan_t scan, + const struct qstr *name, + void *opaque) +{ + struct gfs2_dirent *dent, *prev; + unsigned offset; + unsigned size; + int ret = 0; + + ret = gfs2_dirent_offset(buf); + if (ret < 0) + goto consist_inode; + + offset = ret; prev = NULL; dent = (struct gfs2_dirent *)(buf + offset); size = be16_to_cpu(dent->de_rec_len); if (gfs2_check_dirent(dent, offset, size, len, 1)) goto consist_inode; do { - ret = scan(dent, name); + ret = scan(dent, name, opaque); if (ret) break; offset += size; @@ -487,9 +526,6 @@ static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, return ERR_PTR(ret); } -wrong_type: - printk(KERN_WARNING "gfs2_scan_dirent: %p wrong block type %u\n", scan, - be16_to_cpu(h->mh_type)); consist_inode: gfs2_consist_inode(inode->u.generic_ip); return ERR_PTR(-EIO); @@ -651,7 +687,8 @@ static struct gfs2_dirent *gfs2_dirent_alloc(struct inode *inode, const struct qstr *name) { struct gfs2_dirent *dent; - dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, gfs2_dirent_find_space, name); + dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, + gfs2_dirent_find_space, name, NULL); if (!dent || IS_ERR(dent)) return dent; return gfs2_init_dirent(inode, dent, name, bh); @@ -734,7 +771,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, return ERR_PTR(error); do { dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, - scan, name); + scan, name, NULL); if (dent) goto got_dent; leaf = (struct gfs2_leaf *)bh->b_data; @@ -751,7 +788,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, error = gfs2_meta_inode_buffer(ip, &bh); if (error) return ERR_PTR(error); - dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, scan, name); + dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, scan, name, NULL); got_dent: *pbh = bh; return dent; @@ -764,6 +801,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, struct buffer_head *bh = gfs2_meta_new(ip->i_gl, bn); struct gfs2_leaf *leaf; struct gfs2_dirent *dent; + struct qstr name = { .name = "", .len = 0, .hash = 0 }; if (!bh) return NULL; gfs2_trans_add_bh(ip->i_gl, bh, 1); @@ -775,12 +813,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, leaf->lf_next = cpu_to_be64(0); memset(leaf->lf_reserved, 0, sizeof(leaf->lf_reserved)); dent = (struct gfs2_dirent *)(leaf+1); - dent->de_inum.no_formal_ino = cpu_to_be64(0); - dent->de_inum.no_addr = cpu_to_be64(0); - dent->de_hash = cpu_to_be32(0); - dent->de_rec_len = cpu_to_be16(bh->b_size - sizeof(struct gfs2_leaf)); - dent->de_name_len = cpu_to_be16(0); - dent->de_type = cpu_to_be16(0); + gfs2_qstr2dirent(&name, bh->b_size - sizeof(struct gfs2_leaf), dent); *pbh = bh; return leaf; } @@ -831,7 +864,7 @@ static int dir_make_exhash(struct inode *inode) sizeof(struct gfs2_leaf); args.name = bh->b_data; dent = gfs2_dirent_scan(dip->i_vnode, bh->b_data, bh->b_size, - gfs2_dirent_last, &args); + gfs2_dirent_last, &args, NULL); if (!dent) { brelse(bh); brelse(dibh); @@ -939,7 +972,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) lp[x] = cpu_to_be64(bn); error = gfs2_dir_write_data(dip, (char *)lp, start * sizeof(uint64_t), - half_len * sizeof(uint64_t)); + half_len * sizeof(uint64_t)); if (error != half_len * sizeof(uint64_t)) { if (error >= 0) error = -EIO; @@ -965,7 +998,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) str.name = (char*)(dent+1); str.len = be16_to_cpu(dent->de_name_len); str.hash = be32_to_cpu(dent->de_hash); - new = gfs2_dirent_alloc(dip->i_vnode, nbh, &str); + new = gfs2_dirent_alloc(inode, nbh, &str); if (IS_ERR(new)) { error = PTR_ERR(new); break; @@ -1154,10 +1187,10 @@ static int compare_dents(const void *a, const void *b) static int do_filldir_main(struct gfs2_inode *dip, uint64_t *offset, void *opaque, gfs2_filldir_t filldir, - struct gfs2_dirent **darr, uint32_t entries, + const struct gfs2_dirent **darr, uint32_t entries, int *copied) { - struct gfs2_dirent *dent, *dent_next; + const struct gfs2_dirent *dent, *dent_next; struct gfs2_inum inum; uint64_t off, off_next; unsigned int x, y; @@ -1216,189 +1249,74 @@ static int do_filldir_main(struct gfs2_inode *dip, uint64_t *offset, return 0; } -/** - * do_filldir_single - Read directory entries out of a single block - * @dip: The GFS2 inode - * @offset: The offset in the file to read from - * @opaque: opaque data to pass to filldir - * @filldir: The function to pass entries to - * @bh: the block - * @entries: the number of entries in the block - * @copied: pointer to int that's non-zero if a entry has been copied out - * - * Returns: errno, >0 on exception from filldir - */ - -static int do_filldir_single(struct gfs2_inode *dip, uint64_t *offset, - void *opaque, gfs2_filldir_t filldir, - struct buffer_head *bh, uint32_t entries, - int *copied) +static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque, + gfs2_filldir_t filldir, int *copied, + unsigned *depth, u64 leaf_no) { - struct gfs2_dirent **darr; - struct gfs2_dirent *de; - unsigned int e = 0; - int error; + struct gfs2_inode *ip = inode->u.generic_ip; + struct buffer_head *bh; + struct gfs2_leaf *lf; + unsigned entries = 0; + unsigned leaves = 0; + const struct gfs2_dirent **darr, *dent; + struct dirent_gather g; + struct buffer_head **larr; + int leaf = 0; + int error, i; + u64 lfn = leaf_no; - if (!entries) - return 0; - - darr = kcalloc(entries, sizeof(struct gfs2_dirent *), GFP_KERNEL); - if (!darr) - return -ENOMEM; - - dirent_first(dip, bh, &de); do { - if (!de->de_inum.no_addr) - continue; - if (e >= entries) { - gfs2_consist_inode(dip); - error = -EIO; - goto out; - } - darr[e++] = de; - } while (dirent_next(dip, bh, &de) == 0); - - if (e != entries) { - gfs2_consist_inode(dip); - error = -EIO; - goto out; - } - - error = do_filldir_main(dip, offset, opaque, filldir, darr, - entries, copied); - - out: - kfree(darr); - - return error; -} - -/** - * do_filldir_multi - Read directory entries out of a linked leaf list - * @dip: The GFS2 inode - * @offset: The offset in the file to read from - * @opaque: opaque data to pass to filldir - * @filldir: The function to pass entries to - * @bh: the first leaf in the list - * @copied: pointer to int that's non-zero if a entry has been copied out - * - * Returns: errno, >0 on exception from filldir - */ - -static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset, - void *opaque, gfs2_filldir_t filldir, - struct buffer_head *bh, int *copied) -{ - struct buffer_head **larr = NULL; - struct gfs2_dirent **darr; - struct gfs2_leaf *leaf; - struct buffer_head *tmp_bh; - struct gfs2_dirent *de; - unsigned int entries, e = 0; - unsigned int leaves = 0, l = 0; - unsigned int x; - uint64_t ln; - int error = 0; - - /* Count leaves and entries */ - - leaf = (struct gfs2_leaf *)bh->b_data; - entries = be16_to_cpu(leaf->lf_entries); - ln = be64_to_cpu(leaf->lf_next); - - while (ln) { - error = get_leaf(dip, ln, &tmp_bh); + error = get_leaf(ip, lfn, &bh); if (error) - return error; - - leaf = (struct gfs2_leaf *)tmp_bh->b_data; - if (leaf->lf_entries) { - entries += be16_to_cpu(leaf->lf_entries); - leaves++; - } - ln = be64_to_cpu(leaf->lf_next); - - brelse(tmp_bh); - } + goto out; + lf = (struct gfs2_leaf *)bh->b_data; + if (leaves == 0) + *depth = be16_to_cpu(lf->lf_depth); + entries += be16_to_cpu(lf->lf_entries); + leaves++; + lfn = be64_to_cpu(lf->lf_next); + brelse(bh); + } while(lfn); if (!entries) return 0; - if (leaves) { - larr = kcalloc(leaves, sizeof(struct buffer_head *),GFP_KERNEL); - if (!larr) - return -ENOMEM; - } + error = -ENOMEM; + larr = kmalloc((leaves + entries) * sizeof(void*), GFP_KERNEL); + if (!larr) + goto out; + darr = (const struct gfs2_dirent **)(larr + leaves); + g.pdent = darr; + g.offset = 0; + lfn = leaf_no; - darr = kcalloc(entries, sizeof(struct gfs2_dirent *), GFP_KERNEL); - if (!darr) { - kfree(larr); - return -ENOMEM; - } - - leaf = (struct gfs2_leaf *)bh->b_data; - if (leaf->lf_entries) { - dirent_first(dip, bh, &de); - do { - if (!de->de_inum.no_addr) - continue; - if (e >= entries) { - gfs2_consist_inode(dip); - error = -EIO; - goto out; - } - darr[e++] = de; - } while (dirent_next(dip, bh, &de) == 0); - } - ln = be64_to_cpu(leaf->lf_next); - - while (ln) { - error = get_leaf(dip, ln, &tmp_bh); + do { + error = get_leaf(ip, lfn, &bh); if (error) - goto out; - - leaf = (struct gfs2_leaf *)tmp_bh->b_data; - if (leaf->lf_entries) { - dirent_first(dip, tmp_bh, &de); - do { - if (!de->de_inum.no_addr) - continue; - if (e >= entries) { - gfs2_consist_inode(dip); - error = -EIO; - goto out; - } - darr[e++] = de; - } while (dirent_next(dip, tmp_bh, &de) == 0); - - larr[l++] = tmp_bh; - - ln = be64_to_cpu(leaf->lf_next); + goto out_kfree; + lf = (struct gfs2_leaf *)bh->b_data; + lfn = be64_to_cpu(lf->lf_next); + if (lf->lf_entries) { + dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, + gfs2_dirent_gather, NULL, &g); + error = PTR_ERR(dent); + if (IS_ERR(dent)) { + goto out_kfree; + } + error = 0; + larr[leaf++] = bh; } else { - ln = be64_to_cpu(leaf->lf_next); - brelse(tmp_bh); + brelse(bh); } - } + } while(lfn); - if (gfs2_assert_withdraw(dip->i_sbd, l == leaves)) { - error = -EIO; - goto out; - } - if (e != entries) { - gfs2_consist_inode(dip); - error = -EIO; - goto out; - } - - error = do_filldir_main(dip, offset, opaque, filldir, darr, + error = do_filldir_main(ip, offset, opaque, filldir, darr, entries, copied); - - out: - kfree(darr); - for (x = 0; x < l; x++) - brelse(larr[x]); +out_kfree: + for(i = 0; i < leaf; i++) + brelse(larr[i]); kfree(larr); - +out: return error; } @@ -1412,18 +1330,18 @@ static int do_filldir_multi(struct gfs2_inode *dip, uint64_t *offset, * Returns: errno */ -static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, +static int dir_e_read(struct inode *inode, uint64_t *offset, void *opaque, gfs2_filldir_t filldir) { + struct gfs2_inode *dip = inode->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; - struct buffer_head *bh; - struct gfs2_leaf *leaf; - uint32_t hsize, len; + uint32_t hsize, len = 0; uint32_t ht_offset, lp_offset, ht_offset_cur = -1; uint32_t hash, index; uint64_t *lp; int copied = 0; int error = 0; + unsigned depth; hsize = 1 << dip->i_di.di_depth; if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { @@ -1454,61 +1372,66 @@ static int dir_e_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, ht_offset_cur = ht_offset; } - error = get_leaf(dip, be64_to_cpu(lp[lp_offset]), &bh); + error = gfs2_dir_read_leaf(inode, offset, opaque, filldir, + &copied, &depth, + be64_to_cpu(lp[lp_offset])); if (error) - goto out; + break; - leaf = (struct gfs2_leaf *)bh->b_data; - if (leaf->lf_next) - error = do_filldir_multi(dip, offset, opaque, filldir, - bh, &copied); - else - error = do_filldir_single(dip, offset, opaque, filldir, - bh, - be16_to_cpu(leaf->lf_entries), - &copied); - - brelse(bh); - - if (error) { - if (error > 0) - error = 0; - goto out; - } - - len = 1 << (dip->i_di.di_depth - be16_to_cpu(leaf->lf_depth)); + len = 1 << (dip->i_di.di_depth - depth); index = (index & ~(len - 1)) + len; } - out: +out: kfree(lp); - + if (error > 0) + error = 0; return error; } -static int dir_l_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, - gfs2_filldir_t filldir) +int gfs2_dir_read(struct inode *inode, uint64_t *offset, void *opaque, + gfs2_filldir_t filldir) { + struct gfs2_inode *dip = inode->u.generic_ip; + struct dirent_gather g; + const struct gfs2_dirent **darr, *dent; struct buffer_head *dibh; int copied = 0; int error; + if (!dip->i_di.di_entries) + return 0; + + if (dip->i_di.di_flags & GFS2_DIF_EXHASH) + return dir_e_read(inode, offset, opaque, filldir); + if (!gfs2_is_stuffed(dip)) { gfs2_consist_inode(dip); return -EIO; } - if (!dip->i_di.di_entries) - return 0; - error = gfs2_meta_inode_buffer(dip, &dibh); if (error) return error; - error = do_filldir_single(dip, offset, - opaque, filldir, - dibh, dip->i_di.di_entries, - &copied); + error = -ENOMEM; + darr = kmalloc(dip->i_di.di_entries * sizeof(struct gfs2_dirent *), + GFP_KERNEL); + if (darr) { + g.pdent = darr; + g.offset = 0; + dent = gfs2_dirent_scan(inode, dibh->b_data, dibh->b_size, + gfs2_dirent_gather, NULL, &g); + if (IS_ERR(dent)) { + error = PTR_ERR(dent); + goto out; + } + error = do_filldir_main(dip, offset, opaque, filldir, darr, + dip->i_di.di_entries, &copied); +out: + kfree(darr); + } + if (error > 0) error = 0; @@ -1694,7 +1617,7 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name) return PTR_ERR(dent); } /* If not first in block, adjust pointers accordingly */ - if (gfs2_dirent_find(dent, name) == 0) { + if (gfs2_dirent_find(dent, name, NULL) == 0) { prev = dent; dent = (struct gfs2_dirent *)((char *)dent + be16_to_cpu(prev->de_rec_len)); } @@ -1724,19 +1647,6 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name) return error; } -int gfs2_dir_read(struct gfs2_inode *dip, uint64_t *offset, void *opaque, - gfs2_filldir_t filldir) -{ - int error; - - if (dip->i_di.di_flags & GFS2_DIF_EXHASH) - error = dir_e_read(dip, offset, opaque, filldir); - else - error = dir_l_read(dip, offset, opaque, filldir); - - return error; -} - /** * gfs2_dir_mvino - Change inode number of directory entry * @dip: The GFS2 inode diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h index 8fd4dc0f700e..42b3a1f34deb 100644 --- a/fs/gfs2/dir.h +++ b/fs/gfs2/dir.h @@ -32,7 +32,7 @@ int gfs2_dir_search(struct inode *dir, const struct qstr *filename, int gfs2_dir_add(struct inode *inode, const struct qstr *filename, const struct gfs2_inum *inum, unsigned int type); int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *filename); -int gfs2_dir_read(struct gfs2_inode *dip, uint64_t * offset, void *opaque, +int gfs2_dir_read(struct inode *inode, uint64_t * offset, void *opaque, gfs2_filldir_t filldir); int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, struct gfs2_inum *new_inum, unsigned int new_type); @@ -44,6 +44,19 @@ int gfs2_diradd_alloc_required(struct inode *dir, int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, struct buffer_head **bhp); +static inline uint32_t gfs2_disk_hash(const char *data, int len) +{ + return crc32_le(0xFFFFFFFF, data, len) ^ 0xFFFFFFFF; +} + + +static inline void gfs2_str2qstr(struct qstr *name, const char *fname) +{ + name->name = fname; + name->len = strlen(fname); + name->hash = gfs2_disk_hash(name->name, name->len); +} + /* N.B. This probably ought to take inum & type as args as well */ static inline void gfs2_qstr2dirent(const struct qstr *name, u16 reclen, struct gfs2_dirent *dent) { diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 62f109e553c4..be307185f492 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -634,8 +634,7 @@ struct gfs2_sbd { struct list_head sd_log_le_databuf; unsigned int sd_log_blks_free; - struct list_head sd_log_blks_list; - wait_queue_head_t sd_log_blks_wait; + struct mutex sd_log_reserve_mutex; uint64_t sd_log_sequence; unsigned int sd_log_head; diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index d403d51d5b0f..6140c2434e85 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -701,9 +702,7 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) { struct qstr qstr; - qstr.name = name; - qstr.len = strlen(name); - qstr.hash = gfs2_disk_hash(qstr.name, qstr.len); + gfs2_str2qstr(&qstr, name); return gfs2_lookupi(dip, &qstr, 1, NULL); } @@ -1389,9 +1388,7 @@ int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, if (error) return error; - dotname.len = 1; - dotname.name = "."; - dotname.hash = gfs2_disk_hash(dotname.name, dotname.len); + gfs2_str2qstr(&dotname, "."); error = gfs2_dir_del(ip, &dotname); if (error) return error; @@ -1487,10 +1484,7 @@ int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) struct qstr dotdot; int error = 0; - memset(&dotdot, 0, sizeof(struct qstr)); - dotdot.name = ".."; - dotdot.len = 2; - dotdot.hash = gfs2_disk_hash(dotdot.name, dotdot.len); + gfs2_str2qstr(&dotdot, ".."); igrab(dir); diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index e6a84f7a9b71..16c14441a371 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -24,18 +25,13 @@ #include "lops.h" #include "meta_io.h" #include "util.h" +#include "dir.h" #define PULL 1 -static void do_lock_wait(struct gfs2_sbd *sdp, wait_queue_head_t *wq, - atomic_t *a) -{ - wait_event(*wq, atomic_read(a) ? 0 : 1); -} - static void lock_for_trans(struct gfs2_sbd *sdp) { - do_lock_wait(sdp, &sdp->sd_log_trans_wq, &sdp->sd_log_flush_count); + wait_event(sdp->sd_log_trans_wq, atomic_read(&sdp->sd_log_flush_count) ? 0 : 1); atomic_inc(&sdp->sd_log_trans_count); } @@ -49,7 +45,7 @@ static void unlock_from_trans(struct gfs2_sbd *sdp) static void gfs2_lock_for_flush(struct gfs2_sbd *sdp) { atomic_inc(&sdp->sd_log_flush_count); - do_lock_wait(sdp, &sdp->sd_log_flush_wq, &sdp->sd_log_trans_count); + wait_event(sdp->sd_log_flush_wq, atomic_read(&sdp->sd_log_trans_count) ? 0 : 1); } static void gfs2_unlock_from_flush(struct gfs2_sbd *sdp) @@ -191,37 +187,19 @@ static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) { - LIST_HEAD(list); unsigned int try = 0; if (gfs2_assert_warn(sdp, blks) || gfs2_assert_warn(sdp, blks <= sdp->sd_jdesc->jd_blocks)) return -EINVAL; + mutex_lock(&sdp->sd_log_reserve_mutex); for (;;) { gfs2_log_lock(sdp); - if (list_empty(&list)) { - list_add_tail(&list, &sdp->sd_log_blks_list); - while (sdp->sd_log_blks_list.next != &list) { - DECLARE_WAITQUEUE(__wait_chan, current); - set_current_state(TASK_UNINTERRUPTIBLE); - add_wait_queue(&sdp->sd_log_blks_wait, - &__wait_chan); - gfs2_log_unlock(sdp); - schedule(); - gfs2_log_lock(sdp); - remove_wait_queue(&sdp->sd_log_blks_wait, - &__wait_chan); - set_current_state(TASK_RUNNING); - } - } - /* Never give away the last block so we can - always pull the tail if we need to. */ if (sdp->sd_log_blks_free > blks) { sdp->sd_log_blks_free -= blks; - list_del(&list); gfs2_log_unlock(sdp); - wake_up(&sdp->sd_log_blks_wait); + mutex_unlock(&sdp->sd_log_reserve_mutex); break; } diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index b54608f9df50..958371076093 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "gfs2.h" diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index b27bce74a795..be16c68263d1 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -153,7 +154,7 @@ static int gfs2_get_name(struct dentry *parent, char *name, if (error) return error; - error = gfs2_dir_read(dip, &offset, &gnfd, get_name_filldir); + error = gfs2_dir_read(dir, &offset, &gnfd, get_name_filldir); gfs2_glock_dq_uninit(&gh); @@ -165,12 +166,11 @@ static int gfs2_get_name(struct dentry *parent, char *name, static struct dentry *gfs2_get_parent(struct dentry *child) { - struct qstr dotdot = { .name = "..", .len = 2 }; + struct qstr dotdot; struct inode *inode; struct dentry *dentry; - dotdot.hash = gfs2_disk_hash(dotdot.name, dotdot.len); - + gfs2_str2qstr(&dotdot, ".."); inode = gfs2_lookupi(child->d_inode, &dotdot, 1, NULL); if (!inode) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 6333a14cf77a..ac8e1238cb6f 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -39,6 +41,7 @@ #include "rgrp.h" #include "trans.h" #include "util.h" +#include "eaops.h" /* "bad" is for NFS support */ struct filldir_bad_entry { @@ -357,7 +360,8 @@ static int filldir_reg_func(void *opaque, const char *name, unsigned int length, static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) { - struct gfs2_inode *dip = file->f_mapping->host->u.generic_ip; + struct inode *dir = file->f_mapping->host; + struct gfs2_inode *dip = dir->u.generic_ip; struct filldir_reg fdr; struct gfs2_holder d_gh; uint64_t offset = file->f_pos; @@ -375,7 +379,7 @@ static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) return error; } - error = gfs2_dir_read(dip, &offset, &fdr, filldir_reg_func); + error = gfs2_dir_read(dir, &offset, &fdr, filldir_reg_func); gfs2_glock_dq_uninit(&d_gh); @@ -446,7 +450,8 @@ static int filldir_bad_func(void *opaque, const char *name, unsigned int length, static int readdir_bad(struct file *file, void *dirent, filldir_t filldir) { - struct gfs2_inode *dip = file->f_mapping->host->u.generic_ip; + struct inode *dir = file->f_mapping->host; + struct gfs2_inode *dip = dir->u.generic_ip; struct gfs2_sbd *sdp = dip->i_sbd; struct filldir_reg fdr; unsigned int entries, size; @@ -479,7 +484,7 @@ static int readdir_bad(struct file *file, void *dirent, filldir_t filldir) goto out; } - error = gfs2_dir_read(dip, &offset, fdb, filldir_bad_func); + error = gfs2_dir_read(dir, &offset, fdb, filldir_bad_func); gfs2_glock_dq_uninit(&d_gh); @@ -531,6 +536,210 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) return error; } +const struct gfs2_flag_eattr { + u32 flag; + u32 ext2; +} gfs2_flag_eattrs[] = { + { + .flag = GFS2_DIF_IMMUTABLE, + .ext2 = EXT2_IMMUTABLE_FL, + }, { + .flag = GFS2_DIF_APPENDONLY, + .ext2 = EXT2_APPEND_FL, + }, { + .flag = GFS2_DIF_JDATA, + .ext2 = EXT2_JOURNAL_DATA_FL, + }, { + .flag = GFS2_DIF_EXHASH, + .ext2 = EXT2_INDEX_FL, + }, { + .flag = GFS2_DIF_EA_INDIRECT, + }, { + .flag = GFS2_DIF_DIRECTIO, + }, { + .flag = GFS2_DIF_NOATIME, + .ext2 = EXT2_NOATIME_FL, + }, { + .flag = GFS2_DIF_SYNC, + .ext2 = EXT2_SYNC_FL, + }, { + .flag = GFS2_DIF_SYSTEM, + }, { + .flag = GFS2_DIF_TRUNC_IN_PROG, + }, { + .flag = GFS2_DIF_INHERIT_JDATA, + }, { + .flag = GFS2_DIF_INHERIT_DIRECTIO, + }, { + }, +}; + +static const struct gfs2_flag_eattr *get_by_ext2(u32 ext2) +{ + const struct gfs2_flag_eattr *p = gfs2_flag_eattrs; + for(; p->flag; p++) { + if (ext2 == p->ext2) + return p; + } + return NULL; +} + +static const struct gfs2_flag_eattr *get_by_gfs2(u32 gfs2) +{ + const struct gfs2_flag_eattr *p = gfs2_flag_eattrs; + for(; p->flag; p++) { + if (gfs2 == p->flag) + return p; + } + return NULL; +} + +static u32 gfs2_flags_to_ext2(u32 gfs2) +{ + const struct gfs2_flag_eattr *ea; + u32 ext2 = 0; + u32 mask = 1; + + for(; mask != 0; mask <<=1) { + if (mask & gfs2) { + ea = get_by_gfs2(mask); + if (ea) + ext2 |= ea->ext2; + } + } + return ext2; +} + +static int gfs2_flags_from_ext2(u32 *gfs2, u32 ext2) +{ + const struct gfs2_flag_eattr *ea; + u32 mask = 1; + + for(; mask != 0; mask <<= 1) { + if (mask & ext2) { + ea = get_by_ext2(mask); + if (ea == NULL) + return -EINVAL; + *gfs2 |= ea->flag; + } + } + return 0; +} + +static int get_ext2_flags(struct inode *inode, u32 __user *ptr) +{ + struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_holder gh; + int error; + u32 ext2; + + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); + error = gfs2_glock_nq_m_atime(1, &gh); + if (error) + return error; + + ext2 = gfs2_flags_to_ext2(ip->i_di.di_flags); + if (put_user(ext2, ptr)) + error = -EFAULT; + + gfs2_glock_dq_m(1, &gh); + gfs2_holder_uninit(&gh); + return error; +} + +/* Flags that can be set by user space */ +#define GFS2_FLAGS_USER_SET (GFS2_DIF_JDATA| \ + GFS2_DIF_DIRECTIO| \ + GFS2_DIF_IMMUTABLE| \ + GFS2_DIF_APPENDONLY| \ + GFS2_DIF_NOATIME| \ + GFS2_DIF_SYNC| \ + GFS2_DIF_SYSTEM| \ + GFS2_DIF_INHERIT_DIRECTIO| \ + GFS2_DIF_INHERIT_JDATA) + +/** + * gfs2_set_flags - set flags on an inode + * @inode: The inode + * @flags: The flags to set + * @mask: Indicates which flags are valid + * + */ +static int gfs2_set_flags(struct inode *inode, u32 flags, u32 mask) +{ + struct gfs2_inode *ip = inode->u.generic_ip; + struct buffer_head *bh; + struct gfs2_holder gh; + int error; + u32 new_flags; + + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); + if (error) + return error; + + new_flags = (ip->i_di.di_flags & ~mask) | (flags & mask); + if ((new_flags ^ flags) == 0) + goto out; + + error = -EINVAL; + if ((new_flags ^ flags) & ~GFS2_FLAGS_USER_SET) + goto out; + + if (S_ISDIR(inode->i_mode)) { + if ((new_flags ^ flags) & (GFS2_DIF_JDATA | GFS2_DIF_DIRECTIO)) + goto out; + } else if (S_ISREG(inode->i_mode)) { + if ((new_flags ^ flags) & (GFS2_DIF_INHERIT_DIRECTIO| + GFS2_DIF_INHERIT_JDATA)) + goto out; + } else + goto out; + + error = -EPERM; + if (IS_IMMUTABLE(inode) && (new_flags & GFS2_DIF_IMMUTABLE)) + goto out; + if (IS_APPEND(inode) && (new_flags & GFS2_DIF_APPENDONLY)) + goto out; + error = gfs2_repermission(inode, MAY_WRITE, NULL); + if (error) + goto out; + + error = gfs2_meta_inode_buffer(ip, &bh); + if (error) + goto out; + gfs2_trans_add_bh(ip->i_gl, bh, 1); + ip->i_di.di_flags = new_flags; + gfs2_dinode_out(&ip->i_di, bh->b_data); + brelse(bh); +out: + gfs2_glock_dq_uninit(&gh); + return error; +} + +static int set_ext2_flags(struct inode *inode, u32 __user *ptr) +{ + u32 ext2, gfs2; + if (get_user(ext2, ptr)) + return -EFAULT; + if (gfs2_flags_from_ext2(&gfs2, ext2)) + return -EINVAL; + return gfs2_set_flags(inode, gfs2, ~0); +} + +int gfs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, + unsigned long arg) +{ + switch(cmd) { + case EXT2_IOC_GETFLAGS: + return get_ext2_flags(inode, (u32 __user *)arg); + case EXT2_IOC_SETFLAGS: + return set_ext2_flags(inode, (u32 __user *)arg); + } + return -ENOTTY; +} + + /** * gfs2_mmap - * @file: The file to map @@ -832,6 +1041,7 @@ struct file_operations gfs2_file_fops = { .write = generic_file_write, .writev = generic_file_writev, .aio_write = generic_file_aio_write, + .ioctl = gfs2_ioctl, .mmap = gfs2_mmap, .open = gfs2_open, .release = gfs2_close, @@ -843,6 +1053,7 @@ struct file_operations gfs2_file_fops = { struct file_operations gfs2_dir_fops = { .readdir = gfs2_readdir, + .ioctl = gfs2_ioctl, .open = gfs2_open, .release = gfs2_close, .fsync = gfs2_fsync, diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 8d2c557b3ff4..2628bf326334 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -97,9 +97,7 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) INIT_LIST_HEAD(&sdp->sd_log_le_rg); INIT_LIST_HEAD(&sdp->sd_log_le_databuf); - INIT_LIST_HEAD(&sdp->sd_log_blks_list); - init_waitqueue_head(&sdp->sd_log_blks_wait); - + mutex_init(&sdp->sd_log_reserve_mutex); INIT_LIST_HEAD(&sdp->sd_ail1_list); INIT_LIST_HEAD(&sdp->sd_ail2_list); diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index e8ab9d254b76..1e2b709711ae 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -417,18 +418,16 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) if (!gfs2_assert_withdraw(sdp, !error)) { struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data; struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1); - struct qstr str = { .name = ".", .len = 1 }; - str.hash = gfs2_disk_hash(str.name, str.len); + struct qstr str; + gfs2_str2qstr(&str, "."); gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent); dent->de_inum = di->di_num; /* already GFS2 endian */ dent->de_type = DT_DIR; di->di_entries = cpu_to_be32(1); - str.name = ".."; - str.len = 2; - str.hash = gfs2_disk_hash(str.name, str.len); + gfs2_str2qstr(&str, ".."); dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1)); gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent); @@ -772,9 +771,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, if (dir_rename) { struct qstr name; - name.len = 2; - name.name = ".."; - name.hash = gfs2_disk_hash(name.name, name.len); + gfs2_str2qstr(&name, ".."); error = gfs2_change_nlink(ndip, +1); if (error) diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 2df450e2f433..6c7e2e880e32 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -27,6 +28,7 @@ #include "recovery.h" #include "super.h" #include "util.h" +#include "dir.h" int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, struct buffer_head **bh) diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 71cca7629403..a4da649d086f 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 8b22fa91bd14..7cd9e25639c4 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -28,11 +28,6 @@ kmem_cache_t *gfs2_glock_cachep __read_mostly; kmem_cache_t *gfs2_inode_cachep __read_mostly; kmem_cache_t *gfs2_bufdata_cachep __read_mostly; -uint32_t gfs2_disk_hash(const char *data, int len) -{ - return crc32_le(0xFFFFFFFF, data, len) ^ 0xFFFFFFFF; -} - void gfs2_assert_i(struct gfs2_sbd *sdp) { printk(KERN_EMERG "GFS2: fsid=%s: fatal assertion failed\n", diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index 8d6eba3bdf0a..addbe304993e 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -10,8 +10,6 @@ #ifndef __UTIL_DOT_H__ #define __UTIL_DOT_H__ -uint32_t gfs2_disk_hash(const char *data, int len); - #define fs_printk(level, fs, fmt, arg...) \ printk(level "GFS2: fsid=%s: " fmt , (fs)->sd_fsname , ## arg) From 7aabffcab47a0f881c7640f5c108e8d3f2e35ebf Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 28 Mar 2006 14:20:58 -0500 Subject: [PATCH 064/292] [DLM] Look for "nodir" in the lockspace mount options Look for "nodir" in the hostdata mount option which is used to set the NODIR flag in dlm_new_lockspace(). Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/mount.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c index 042f3a75c441..026f05ce168d 100644 --- a/fs/gfs2/locking/dlm/mount.c +++ b/fs/gfs2/locking/dlm/mount.c @@ -60,7 +60,7 @@ static struct gdlm_ls *init_gdlm(lm_callback_t cb, lm_fsdata_t *fsdata, return ls; } -static int make_args(struct gdlm_ls *ls, char *data_arg) +static int make_args(struct gdlm_ls *ls, char *data_arg, int *nodir) { char data[256]; char *options, *x, *y; @@ -101,6 +101,14 @@ static int make_args(struct gdlm_ls *ls, char *data_arg) } sscanf(y, "%u", &ls->id); + } else if (!strcmp(x, "nodir")) { + if (!y) { + log_error("need argument to nodir"); + error = -EINVAL; + break; + } + sscanf(y, "%u", nodir); + } else { log_error("unkonwn option: %s", x); error = -EINVAL; @@ -118,7 +126,7 @@ static int gdlm_mount(char *table_name, char *host_data, struct kobject *fskobj) { struct gdlm_ls *ls; - int error = -ENOMEM; + int error = -ENOMEM, nodir = 0; if (min_lvb_size > GDLM_LVB_SIZE) goto out; @@ -127,12 +135,18 @@ static int gdlm_mount(char *table_name, char *host_data, if (!ls) goto out; + error = make_args(ls, host_data, &nodir); + if (error) + goto out; + error = gdlm_init_threads(ls); if (error) goto out_free; error = dlm_new_lockspace(ls->fsname, strlen(ls->fsname), - &ls->dlm_lockspace, 0, GDLM_LVB_SIZE); + &ls->dlm_lockspace, + nodir ? DLM_LSFL_NODIR : 0, + GDLM_LVB_SIZE); if (error) { log_error("dlm_new_lockspace error %d", error); goto out_thread; @@ -142,10 +156,6 @@ static int gdlm_mount(char *table_name, char *host_data, if (error) goto out_dlm; - error = make_args(ls, host_data); - if (error) - goto out_sysfs; - lockstruct->ls_jid = ls->jid; lockstruct->ls_first = ls->first; lockstruct->ls_lockspace = ls; @@ -154,8 +164,6 @@ static int gdlm_mount(char *table_name, char *host_data, lockstruct->ls_lvb_size = GDLM_LVB_SIZE; return 0; - out_sysfs: - gdlm_kobject_release(ls); out_dlm: dlm_release_lockspace(ls->dlm_lockspace, 2); out_thread: From 484adff8a06cb5d952832f5487ae863f54c0fb69 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 29 Mar 2006 09:12:12 -0500 Subject: [PATCH 065/292] [GFS2] Update locking in log.c Replace the lock_for_trans()/lock_for_flush() functions with an rwsem. In fact the sd_log_flush_lock becomes an rwsem (the write part of it) and is extended slightly to cover everything that the lock_for_flush() used to cover. The read part of the lock is instead of lock_for_trans(). This corrects the races in the original code and reduces the code size. Signed-off-by: Steven Whitehouse --- fs/gfs2/incore.h | 6 +--- fs/gfs2/log.c | 67 ++++++++++++-------------------------------- fs/gfs2/ops_fstype.c | 4 +-- fs/gfs2/trans.c | 4 +-- 4 files changed, 22 insertions(+), 59 deletions(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index be307185f492..35163b562460 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -611,10 +611,6 @@ struct gfs2_sbd { /* Log stuff */ spinlock_t sd_log_lock; - atomic_t sd_log_trans_count; - wait_queue_head_t sd_log_trans_wq; - atomic_t sd_log_flush_count; - wait_queue_head_t sd_log_flush_wq; unsigned int sd_log_blks_reserved; unsigned int sd_log_commited_buf; @@ -643,7 +639,7 @@ struct gfs2_sbd { int sd_log_idle; unsigned long sd_log_flush_time; - struct mutex sd_log_flush_lock; + struct rw_semaphore sd_log_flush_lock; struct list_head sd_log_flush_list; unsigned int sd_log_flush_head; diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 16c14441a371..b103d9acf40d 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -29,32 +29,6 @@ #define PULL 1 -static void lock_for_trans(struct gfs2_sbd *sdp) -{ - wait_event(sdp->sd_log_trans_wq, atomic_read(&sdp->sd_log_flush_count) ? 0 : 1); - atomic_inc(&sdp->sd_log_trans_count); -} - -static void unlock_from_trans(struct gfs2_sbd *sdp) -{ - gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_trans_count)); - if (atomic_dec_and_test(&sdp->sd_log_trans_count)) - wake_up(&sdp->sd_log_flush_wq); -} - -static void gfs2_lock_for_flush(struct gfs2_sbd *sdp) -{ - atomic_inc(&sdp->sd_log_flush_count); - wait_event(sdp->sd_log_flush_wq, atomic_read(&sdp->sd_log_trans_count) ? 0 : 1); -} - -static void gfs2_unlock_from_flush(struct gfs2_sbd *sdp) -{ - gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_flush_count)); - if (atomic_dec_and_test(&sdp->sd_log_flush_count)) - wake_up(&sdp->sd_log_trans_wq); -} - /** * gfs2_struct2blk - compute stuff * @sdp: the filesystem @@ -109,9 +83,8 @@ void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags) first = NULL; for (;;) { - if (first && - (head->prev != first || - gfs2_ail1_empty_one(sdp, first_ai, 0))) + if (first && (head->prev != first || + gfs2_ail1_empty_one(sdp, first_ai, 0))) break; for (tmp = head->prev; tmp != head; tmp = tmp->prev) { @@ -194,23 +167,21 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) return -EINVAL; mutex_lock(&sdp->sd_log_reserve_mutex); - for (;;) { - gfs2_log_lock(sdp); - if (sdp->sd_log_blks_free > blks) { - sdp->sd_log_blks_free -= blks; - gfs2_log_unlock(sdp); - mutex_unlock(&sdp->sd_log_reserve_mutex); - break; - } - + gfs2_log_lock(sdp); + while(sdp->sd_log_blks_free <= blks) { gfs2_log_unlock(sdp); gfs2_ail1_empty(sdp, 0); gfs2_log_flush(sdp); if (try++) gfs2_ail1_start(sdp, 0); + gfs2_log_lock(sdp); } - lock_for_trans(sdp); + sdp->sd_log_blks_free -= blks; + gfs2_log_unlock(sdp); + mutex_unlock(&sdp->sd_log_reserve_mutex); + + down_read(&sdp->sd_log_flush_lock); return 0; } @@ -224,7 +195,7 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) { - unlock_from_trans(sdp); + up_read(&sdp->sd_log_flush_lock); gfs2_log_lock(sdp); sdp->sd_log_blks_free += blks; @@ -474,20 +445,20 @@ void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); INIT_LIST_HEAD(&ai->ai_ail1_list); INIT_LIST_HEAD(&ai->ai_ail2_list); - gfs2_lock_for_flush(sdp); + + down_write(&sdp->sd_log_flush_lock); if (gl) { gfs2_log_lock(sdp); if (list_empty(&gl->gl_le.le_list)) { gfs2_log_unlock(sdp); - gfs2_unlock_from_flush(sdp); + up_write(&sdp->sd_log_flush_lock); kfree(ai); return; } gfs2_log_unlock(sdp); } - mutex_lock(&sdp->sd_log_flush_lock); gfs2_assert_withdraw(sdp, sdp->sd_log_num_buf == sdp->sd_log_commited_buf); @@ -519,9 +490,8 @@ void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) } gfs2_log_unlock(sdp); - mutex_unlock(&sdp->sd_log_flush_lock); sdp->sd_vfs->s_dirt = 0; - gfs2_unlock_from_flush(sdp); + up_write(&sdp->sd_log_flush_lock); kfree(ai); } @@ -573,7 +543,7 @@ void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) lops_incore_commit(sdp, tr); sdp->sd_vfs->s_dirt = 1; - unlock_from_trans(sdp); + up_read(&sdp->sd_log_flush_lock); gfs2_log_lock(sdp); if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks)) { @@ -591,9 +561,8 @@ void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) void gfs2_log_shutdown(struct gfs2_sbd *sdp) { - mutex_lock(&sdp->sd_log_flush_lock); + down_write(&sdp->sd_log_flush_lock); - gfs2_assert_withdraw(sdp, !atomic_read(&sdp->sd_log_trans_count)); gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); gfs2_assert_withdraw(sdp, !sdp->sd_log_num_gl); gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf); @@ -618,6 +587,6 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp) sdp->sd_log_wraps++; sdp->sd_log_tail = sdp->sd_log_head; - mutex_unlock(&sdp->sd_log_flush_lock); + up_write(&sdp->sd_log_flush_lock); } diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 2628bf326334..5166455b9fdd 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -88,8 +88,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) mutex_init(&sdp->sd_quota_mutex); spin_lock_init(&sdp->sd_log_lock); - init_waitqueue_head(&sdp->sd_log_trans_wq); - init_waitqueue_head(&sdp->sd_log_flush_wq); INIT_LIST_HEAD(&sdp->sd_log_le_gl); INIT_LIST_HEAD(&sdp->sd_log_le_buf); @@ -101,7 +99,7 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) INIT_LIST_HEAD(&sdp->sd_ail1_list); INIT_LIST_HEAD(&sdp->sd_ail2_list); - mutex_init(&sdp->sd_log_flush_lock); + init_rwsem(&sdp->sd_log_flush_lock); INIT_LIST_HEAD(&sdp->sd_log_flush_list); INIT_LIST_HEAD(&sdp->sd_revoke_list); diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 63e7fed2bd47..aa1a619f0854 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -74,10 +74,10 @@ int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, return 0; - fail_gunlock: +fail_gunlock: gfs2_glock_dq(&tr->tr_t_gh); - fail_holder_uninit: +fail_holder_uninit: gfs2_holder_uninit(&tr->tr_t_gh); kfree(tr); From d0dc80dbafb5c10ad2084831a61bbf945484a139 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 29 Mar 2006 14:36:49 -0500 Subject: [PATCH 066/292] [GFS2] Update debugging code Update the debugging code in trans.c and at the same time improve the debugging code for gfs2_holders. The new code should be pretty fast during the normal case and provide just as much information in case of errors (or more). One small function from glock.c has moved to glock.h as a static inline so that its return address won't get in the way of the debugging. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 34 +++++++++------------------------- fs/gfs2/glock.h | 27 +++++++++++++++++++++++++-- fs/gfs2/incore.h | 4 ++-- fs/gfs2/trans.c | 32 ++++++++++++++------------------ fs/gfs2/trans.h | 8 ++------ 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 81b06812b329..6a1b42cf4df4 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -357,6 +358,7 @@ void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, int flags, { INIT_LIST_HEAD(&gh->gh_list); gh->gh_gl = gl; + gh->gh_ip = (unsigned long)__builtin_return_address(0); gh->gh_owner = (flags & GL_NEVER_RECURSE) ? NULL : current; gh->gh_state = state; gh->gh_flags = flags; @@ -388,6 +390,7 @@ void gfs2_holder_reinit(unsigned int state, int flags, struct gfs2_holder *gh) gh->gh_flags |= GL_LOCAL_EXCL; gh->gh_iflags &= 1 << HIF_ALLOCED; + gh->gh_ip = (unsigned long)__builtin_return_address(0); } /** @@ -400,6 +403,7 @@ void gfs2_holder_uninit(struct gfs2_holder *gh) { gfs2_glock_put(gh->gh_gl); gh->gh_gl = NULL; + gh->gh_ip = 0; } /** @@ -427,7 +431,7 @@ struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl, unsigned int state, gfs2_holder_init(gl, state, flags, gh); set_bit(HIF_ALLOCED, &gh->gh_iflags); - + gh->gh_ip = (unsigned long)__builtin_return_address(0); return gh; } @@ -1238,6 +1242,9 @@ static int recurse_check(struct gfs2_holder *existing, struct gfs2_holder *new, return 0; fail: + print_symbol(KERN_WARNING "GFS2: Existing holder from %s\n", + existing->gh_ip); + print_symbol(KERN_WARNING "GFS2: New holder from %s\n", new->gh_ip); set_bit(HIF_ABORTED, &new->gh_iflags); return -EINVAL; } @@ -1543,30 +1550,6 @@ int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time) return 0; } -/** - * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock - * @gl: the glock - * @state: the state we're requesting - * @flags: the modifier flags - * @gh: the holder structure - * - * Returns: 0, GLR_*, or errno - */ - -int gfs2_glock_nq_init(struct gfs2_glock *gl, unsigned int state, int flags, - struct gfs2_holder *gh) -{ - int error; - - gfs2_holder_init(gl, state, flags, gh); - - error = gfs2_glock_nq(gh); - if (error) - gfs2_holder_uninit(gh); - - return error; -} - /** * gfs2_glock_dq_uninit - dequeue a holder from a glock and initialize it * @gh: the holder structure @@ -2334,6 +2317,7 @@ static int dump_holder(char *str, struct gfs2_holder *gh) if (test_bit(x, &gh->gh_iflags)) printk(" %u", x); printk(" \n"); + print_symbol(KERN_INFO " initialized at: %s\n", gh->gh_ip); error = 0; diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 06847ebebdee..560029de8d07 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -106,8 +106,6 @@ void gfs2_glock_force_drop(struct gfs2_glock *gl); int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time); -int gfs2_glock_nq_init(struct gfs2_glock *gl, unsigned int state, int flags, - struct gfs2_holder *gh); void gfs2_glock_dq_uninit(struct gfs2_holder *gh); int gfs2_glock_nq_num(struct gfs2_sbd *sdp, uint64_t number, struct gfs2_glock_operations *glops, @@ -121,6 +119,31 @@ void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number, struct gfs2_glock_operations *glops, unsigned int state, int flags); +/** + * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock + * @gl: the glock + * @state: the state we're requesting + * @flags: the modifier flags + * @gh: the holder structure + * + * Returns: 0, GLR_*, or errno + */ + +static inline int gfs2_glock_nq_init(struct gfs2_glock *gl, + unsigned int state, int flags, + struct gfs2_holder *gh) +{ + int error; + + gfs2_holder_init(gl, state, flags, gh); + + error = gfs2_glock_nq(gh); + if (error) + gfs2_holder_uninit(gh); + + return error; +} + /* Lock Value Block functions */ int gfs2_lvb_hold(struct gfs2_glock *gl); diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 35163b562460..b5a994d1b5f7 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -161,6 +161,7 @@ struct gfs2_holder { int gh_error; unsigned long gh_iflags; struct completion gh_wait; + unsigned long gh_ip; }; enum { @@ -353,8 +354,7 @@ struct gfs2_log_buf { }; struct gfs2_trans { - char *tr_file; - unsigned int tr_line; + unsigned long tr_ip; unsigned int tr_blocks; unsigned int tr_revokes; diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index aa1a619f0854..3fae3d4e9ae4 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -25,24 +26,20 @@ #include "trans.h" #include "util.h" -int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks, - unsigned int revokes, char *file, unsigned int line) +int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks, + unsigned int revokes) { struct gfs2_trans *tr; int error; - if (gfs2_assert_warn(sdp, !current->journal_info) || - gfs2_assert_warn(sdp, blocks || revokes)) { - fs_warn(sdp, "(%s, %u)\n", file, line); - return -EINVAL; - } + BUG_ON(current->journal_info); + BUG_ON(blocks == 0 && revokes == 0); tr = kzalloc(sizeof(struct gfs2_trans), GFP_NOFS); if (!tr) return -ENOMEM; - tr->tr_file = file; - tr->tr_line = line; + tr->tr_ip = (unsigned long)__builtin_return_address(0); tr->tr_blocks = blocks; tr->tr_revokes = revokes; tr->tr_reserved = 1; @@ -104,16 +101,15 @@ void gfs2_trans_end(struct gfs2_sbd *sdp) return; } - if (gfs2_assert_withdraw(sdp, tr->tr_num_buf <= tr->tr_blocks)) - fs_err(sdp, "tr_num_buf = %u, tr_blocks = %u " - "tr_file = %s, tr_line = %u\n", - tr->tr_num_buf, tr->tr_blocks, - tr->tr_file, tr->tr_line); + if (gfs2_assert_withdraw(sdp, tr->tr_num_buf <= tr->tr_blocks)) { + fs_err(sdp, "tr_num_buf = %u, tr_blocks = %u ", + tr->tr_num_buf, tr->tr_blocks); + print_symbol(KERN_WARNING "GFS2: Transaction created at: %s\n", tr->tr_ip); + } if (gfs2_assert_withdraw(sdp, tr->tr_num_revoke <= tr->tr_revokes)) - fs_err(sdp, "tr_num_revoke = %u, tr_revokes = %u " - "tr_file = %s, tr_line = %u\n", - tr->tr_num_revoke, tr->tr_revokes, - tr->tr_file, tr->tr_line); + fs_err(sdp, "tr_num_revoke = %u, tr_revokes = %u ", + tr->tr_num_revoke, tr->tr_revokes); + print_symbol(KERN_WARNING "GFS2: Transaction created at: %s\n", tr->tr_ip); gfs2_log_commit(sdp, tr); diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h index f7f3e2a3d590..6b5e9e8bf561 100644 --- a/fs/gfs2/trans.h +++ b/fs/gfs2/trans.h @@ -21,12 +21,8 @@ #define RES_STATFS 1 #define RES_QUOTA 2 -#define gfs2_trans_begin(sdp, blocks, revokes) \ -gfs2_trans_begin_i((sdp), (blocks), (revokes), __FILE__, __LINE__) - -int gfs2_trans_begin_i(struct gfs2_sbd *sdp, - unsigned int blocks, unsigned int revokes, - char *file, unsigned int line); +int gfs2_trans_begin(struct gfs2_sbd *sdp, + unsigned int blocks, unsigned int revokes); void gfs2_trans_end(struct gfs2_sbd *sdp); From e90deff5336ac500c65f873484c326cfa8a9d379 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 29 Mar 2006 19:02:15 -0500 Subject: [PATCH 067/292] [GFS2] Fix bug in directory expansion code We didn't properly check that leaf splitting was allowed. We do now. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index ba3438553f33..9f17e7d05af1 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -940,10 +940,15 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) /* Get the old leaf block */ error = get_leaf(dip, leaf_no, &obh); if (error) - goto fail; + return error; + + oleaf = (struct gfs2_leaf *)obh->b_data; + if (dip->i_di.di_depth == be16_to_cpu(oleaf->lf_depth)) { + brelse(obh); + return 1; /* can't split */ + } gfs2_trans_add_bh(dip->i_gl, obh, 1); - oleaf = (struct gfs2_leaf *)obh->b_data; nleaf = new_leaf(inode, &nbh, be16_to_cpu(oleaf->lf_depth) + 1); if (!nleaf) { @@ -956,6 +961,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) len = 1 << (dip->i_di.di_depth - be16_to_cpu(oleaf->lf_depth)); half_len = len >> 1; if (!half_len) { + printk(KERN_WARNING "di_depth %u lf_depth %u index %u\n", dip->i_di.di_depth, be16_to_cpu(oleaf->lf_depth), index); gfs2_consist_inode(dip); error = -EIO; goto fail_brelse; @@ -1038,13 +1044,11 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) return error; - fail_lpfree: +fail_lpfree: kfree(lp); - fail_brelse: +fail_brelse: brelse(obh); - - fail: brelse(nbh); return error; } @@ -1570,16 +1574,17 @@ int gfs2_dir_add(struct inode *inode, const struct qstr *name, error = dir_split_leaf(inode, name); if (error == 0) continue; - if (error != -ENOSPC) + if (error < 0) break; if (ip->i_di.di_depth < GFS2_DIR_MAX_DEPTH) { error = dir_double_exhash(ip); if (error) break; error = dir_split_leaf(inode, name); - if (error) + if (error < 0) break; - continue; + if (error == 0) + continue; } error = dir_new_leaf(inode, name); if (!error) From cd45697f0ddbb58f3f83c29fe164713ee7765e21 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 30 Mar 2006 11:10:12 -0500 Subject: [PATCH 068/292] [GFS2] Add missing {} in trans.c A conditional had missing {} around the two following statements. Now added. Signed-off-by: Steven Whitehouse --- fs/gfs2/trans.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 3fae3d4e9ae4..d72f79e67c94 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -106,10 +106,11 @@ void gfs2_trans_end(struct gfs2_sbd *sdp) tr->tr_num_buf, tr->tr_blocks); print_symbol(KERN_WARNING "GFS2: Transaction created at: %s\n", tr->tr_ip); } - if (gfs2_assert_withdraw(sdp, tr->tr_num_revoke <= tr->tr_revokes)) + if (gfs2_assert_withdraw(sdp, tr->tr_num_revoke <= tr->tr_revokes)) { fs_err(sdp, "tr_num_revoke = %u, tr_revokes = %u ", tr->tr_num_revoke, tr->tr_revokes); print_symbol(KERN_WARNING "GFS2: Transaction created at: %s\n", tr->tr_ip); + } gfs2_log_commit(sdp, tr); From e3167ded1f1b16424bc14d5673cdc5414f179970 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 30 Mar 2006 15:46:23 -0500 Subject: [PATCH 069/292] [GFS] Fix bug in endian conversion for metadata header In some cases 16 bit functions were being used rather than 32 bit functions. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 6 +++--- fs/gfs2/log.c | 4 ++-- fs/gfs2/lops.c | 16 ++++++++-------- fs/gfs2/ondisk.c | 8 ++++---- fs/gfs2/recovery.c | 4 ++-- fs/gfs2/util.h | 7 +++---- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 9f17e7d05af1..66917f2c64aa 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -462,7 +462,7 @@ static int gfs2_dirent_offset(const void *buf) BUG_ON(buf == NULL); - switch(be16_to_cpu(h->mh_type)) { + switch(be32_to_cpu(h->mh_type)) { case GFS2_METATYPE_LF: offset = sizeof(struct gfs2_leaf); break; @@ -475,7 +475,7 @@ static int gfs2_dirent_offset(const void *buf) return offset; wrong_type: printk(KERN_WARNING "gfs2_scan_dirent: wrong block type %u\n", - be16_to_cpu(h->mh_type)); + be32_to_cpu(h->mh_type)); return -1; } @@ -548,7 +548,7 @@ static int dirent_first(struct gfs2_inode *dip, struct buffer_head *bh, { struct gfs2_meta_header *h = (struct gfs2_meta_header *)bh->b_data; - if (be16_to_cpu(h->mh_type) == GFS2_METATYPE_LF) { + if (be32_to_cpu(h->mh_type) == GFS2_METATYPE_LF) { if (gfs2_meta_check(dip->i_sbd, bh)) return -EIO; *dent = (struct gfs2_dirent *)(bh->b_data + diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index b103d9acf40d..ea69376c00d8 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -377,8 +377,8 @@ static void log_write_header(struct gfs2_sbd *sdp, uint32_t flags, int pull) lh = (struct gfs2_log_header *)bh->b_data; memset(lh, 0, sizeof(struct gfs2_log_header)); lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); - lh->lh_header.mh_type = cpu_to_be16(GFS2_METATYPE_LH); - lh->lh_header.mh_format = cpu_to_be16(GFS2_FORMAT_LH); + lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH); + lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH); lh->lh_sequence = be64_to_cpu(sdp->sd_log_sequence++); lh->lh_flags = be32_to_cpu(flags); lh->lh_tail = be32_to_cpu(tail); diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 9d40e21f6ead..689c9101c0fb 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -133,8 +133,8 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp) ld = (struct gfs2_log_descriptor *)bh->b_data; ptr = (__be64 *)(bh->b_data + offset); ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC); - ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD); - ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD); + ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD); + ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD); ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_METADATA); ld->ld_length = cpu_to_be32(num + 1); ld->ld_data1 = cpu_to_be32(num); @@ -291,8 +291,8 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp) bh = gfs2_log_get_buf(sdp); ld = (struct gfs2_log_descriptor *)bh->b_data; ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC); - ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD); - ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD); + ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD); + ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD); ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_REVOKE); ld->ld_length = cpu_to_be32(gfs2_struct2blk(sdp, sdp->sd_log_num_revoke, sizeof(uint64_t))); @@ -313,8 +313,8 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp) bh = gfs2_log_get_buf(sdp); mh = (struct gfs2_meta_header *)bh->b_data; mh->mh_magic = cpu_to_be32(GFS2_MAGIC); - mh->mh_type = cpu_to_be16(GFS2_METATYPE_LB); - mh->mh_format = cpu_to_be16(GFS2_FORMAT_LB); + mh->mh_type = cpu_to_be32(GFS2_METATYPE_LB); + mh->mh_format = cpu_to_be32(GFS2_FORMAT_LB); offset = sizeof(struct gfs2_meta_header); } @@ -576,9 +576,9 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC); ld->ld_header.mh_type = - cpu_to_be16(GFS2_METATYPE_LD); + cpu_to_be32(GFS2_METATYPE_LD); ld->ld_header.mh_format = - cpu_to_be16(GFS2_FORMAT_LD); + cpu_to_be32(GFS2_FORMAT_LD); ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_JDATA); ld->ld_length = cpu_to_be32(num + 1); diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index 3be060f1cbe7..acfc944ce13e 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -83,8 +83,8 @@ static void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf) struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf; mh->mh_magic = be32_to_cpu(str->mh_magic); - mh->mh_type = be16_to_cpu(str->mh_type); - mh->mh_format = be16_to_cpu(str->mh_format); + mh->mh_type = be32_to_cpu(str->mh_type); + mh->mh_format = be32_to_cpu(str->mh_format); } static void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf) @@ -92,8 +92,8 @@ static void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf) struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf; str->mh_magic = cpu_to_be32(mh->mh_magic); - str->mh_type = cpu_to_be16(mh->mh_type); - str->mh_format = cpu_to_be16(mh->mh_format); + str->mh_type = cpu_to_be32(mh->mh_type); + str->mh_format = cpu_to_be32(mh->mh_format); } void gfs2_meta_header_print(struct gfs2_meta_header *mh) diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 6c7e2e880e32..68c85610fb5b 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -324,7 +324,7 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, ld = (struct gfs2_log_descriptor *)bh->b_data; length = be32_to_cpu(ld->ld_length); - if (be16_to_cpu(ld->ld_header.mh_type) == GFS2_METATYPE_LH) { + if (be32_to_cpu(ld->ld_header.mh_type) == GFS2_METATYPE_LH) { struct gfs2_log_header lh; error = get_log_header(jd, start, &lh); if (!error) { @@ -400,7 +400,7 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) memset(lh, 0, sizeof(struct gfs2_log_header)); lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); lh->lh_header.mh_type = cpu_to_be16(GFS2_METATYPE_LH); - lh->lh_header.mh_format = cpu_to_be16(GFS2_FORMAT_LH); + lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH); lh->lh_sequence = cpu_to_be64(head->lh_sequence + 1); lh->lh_flags = cpu_to_be32(GFS2_LOG_HEAD_UNMOUNT); lh->lh_blkno = cpu_to_be32(lblock); diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index addbe304993e..4532dbab0a2c 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -107,12 +107,11 @@ static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp, { struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; uint32_t magic = mh->mh_magic; - uint16_t t = mh->mh_type; + uint16_t t = be32_to_cpu(mh->mh_type); magic = be32_to_cpu(magic); if (unlikely(magic != GFS2_MAGIC)) return gfs2_meta_check_ii(sdp, bh, "magic number", function, file, line); - t = be16_to_cpu(t); if (unlikely(t != type)) return gfs2_metatype_check_ii(sdp, bh, type, t, function, file, line); @@ -127,8 +126,8 @@ static inline void gfs2_metatype_set(struct buffer_head *bh, uint16_t type, { struct gfs2_meta_header *mh; mh = (struct gfs2_meta_header *)bh->b_data; - mh->mh_type = cpu_to_be16(type); - mh->mh_format = cpu_to_be16(format); + mh->mh_type = cpu_to_be32(type); + mh->mh_format = cpu_to_be32(format); } From 7ea9ea832212c4a755650f7c7cc1ff0b63292a41 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 31 Mar 2006 15:01:28 -0500 Subject: [PATCH 070/292] [GFS2] Update ioctl() to new interface This is designed as a fs independent way to set flags on a particular inode. The values of the ioctl() and flags are designed to be identical to the ext2/3 values. Assuming that this plan is acceptable to people in general, the plan is to then move other fs across to using the same set of #defines, etc. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 138 ++++++++++-------------------------- include/linux/gfs2_ondisk.h | 16 +++++ include/linux/iflags.h | 104 +++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 102 deletions(-) create mode 100644 include/linux/iflags.h diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index ac8e1238cb6f..db4484a3efcc 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -536,110 +537,44 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) return error; } -const struct gfs2_flag_eattr { - u32 flag; - u32 ext2; -} gfs2_flag_eattrs[] = { - { - .flag = GFS2_DIF_IMMUTABLE, - .ext2 = EXT2_IMMUTABLE_FL, - }, { - .flag = GFS2_DIF_APPENDONLY, - .ext2 = EXT2_APPEND_FL, - }, { - .flag = GFS2_DIF_JDATA, - .ext2 = EXT2_JOURNAL_DATA_FL, - }, { - .flag = GFS2_DIF_EXHASH, - .ext2 = EXT2_INDEX_FL, - }, { - .flag = GFS2_DIF_EA_INDIRECT, - }, { - .flag = GFS2_DIF_DIRECTIO, - }, { - .flag = GFS2_DIF_NOATIME, - .ext2 = EXT2_NOATIME_FL, - }, { - .flag = GFS2_DIF_SYNC, - .ext2 = EXT2_SYNC_FL, - }, { - .flag = GFS2_DIF_SYSTEM, - }, { - .flag = GFS2_DIF_TRUNC_IN_PROG, - }, { - .flag = GFS2_DIF_INHERIT_JDATA, - }, { - .flag = GFS2_DIF_INHERIT_DIRECTIO, - }, { - }, +static const u32 iflags_to_gfs2[32] = { + [iflag_Sync] = GFS2_DIF_SYNC, + [iflag_Immutable] = GFS2_DIF_IMMUTABLE, + [iflag_Append] = GFS2_DIF_APPENDONLY, + [iflag_NoAtime] = GFS2_DIF_NOATIME, + [iflag_Index] = GFS2_DIF_EXHASH, + [iflag_JournalData] = GFS2_DIF_JDATA, + [iflag_DirectIO] = GFS2_DIF_DIRECTIO, + [iflag_InheritDirectIO] = GFS2_DIF_INHERIT_DIRECTIO, + [iflag_InheritJdata] = GFS2_DIF_INHERIT_JDATA, }; -static const struct gfs2_flag_eattr *get_by_ext2(u32 ext2) -{ - const struct gfs2_flag_eattr *p = gfs2_flag_eattrs; - for(; p->flag; p++) { - if (ext2 == p->ext2) - return p; - } - return NULL; -} +static const u32 gfs2_to_iflags[32] = { + [gfs2fl_Sync] = IFLAG_SYNC, + [gfs2fl_Immutable] = IFLAG_IMMUTABLE, + [gfs2fl_AppendOnly] = IFLAG_APPEND, + [gfs2fl_NoAtime] = IFLAG_NOATIME, + [gfs2fl_ExHash] = IFLAG_INDEX, + [gfs2fl_Jdata] = IFLAG_JOURNAL_DATA, + [gfs2fl_Directio] = IFLAG_DIRECTIO, + [gfs2fl_InheritDirectio] = IFLAG_INHERITDIRECTIO, + [gfs2fl_InheritJdata] = IFLAG_INHERITJDATA, +}; -static const struct gfs2_flag_eattr *get_by_gfs2(u32 gfs2) -{ - const struct gfs2_flag_eattr *p = gfs2_flag_eattrs; - for(; p->flag; p++) { - if (gfs2 == p->flag) - return p; - } - return NULL; -} - -static u32 gfs2_flags_to_ext2(u32 gfs2) -{ - const struct gfs2_flag_eattr *ea; - u32 ext2 = 0; - u32 mask = 1; - - for(; mask != 0; mask <<=1) { - if (mask & gfs2) { - ea = get_by_gfs2(mask); - if (ea) - ext2 |= ea->ext2; - } - } - return ext2; -} - -static int gfs2_flags_from_ext2(u32 *gfs2, u32 ext2) -{ - const struct gfs2_flag_eattr *ea; - u32 mask = 1; - - for(; mask != 0; mask <<= 1) { - if (mask & ext2) { - ea = get_by_ext2(mask); - if (ea == NULL) - return -EINVAL; - *gfs2 |= ea->flag; - } - } - return 0; -} - -static int get_ext2_flags(struct inode *inode, u32 __user *ptr) +static int gfs2_get_flags(struct inode *inode, u32 __user *ptr) { struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_holder gh; int error; - u32 ext2; + u32 iflags; gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); error = gfs2_glock_nq_m_atime(1, &gh); if (error) return error; - ext2 = gfs2_flags_to_ext2(ip->i_di.di_flags); - if (put_user(ext2, ptr)) + iflags = iflags_cvt(gfs2_to_iflags, ip->i_di.di_flags); + if (put_user(iflags, ptr)) error = -EFAULT; gfs2_glock_dq_m(1, &gh); @@ -665,7 +600,7 @@ static int get_ext2_flags(struct inode *inode, u32 __user *ptr) * @mask: Indicates which flags are valid * */ -static int gfs2_set_flags(struct inode *inode, u32 flags, u32 mask) +static int do_gfs2_set_flags(struct inode *inode, u32 flags, u32 mask) { struct gfs2_inode *ip = inode->u.generic_ip; struct buffer_head *bh; @@ -717,24 +652,23 @@ out: return error; } -static int set_ext2_flags(struct inode *inode, u32 __user *ptr) +static int gfs2_set_flags(struct inode *inode, u32 __user *ptr) { - u32 ext2, gfs2; - if (get_user(ext2, ptr)) + u32 iflags, gfsflags; + if (get_user(iflags, ptr)) return -EFAULT; - if (gfs2_flags_from_ext2(&gfs2, ext2)) - return -EINVAL; - return gfs2_set_flags(inode, gfs2, ~0); + gfsflags = iflags_cvt(iflags_to_gfs2, iflags); + return do_gfs2_set_flags(inode, gfsflags, ~0); } int gfs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { switch(cmd) { - case EXT2_IOC_GETFLAGS: - return get_ext2_flags(inode, (u32 __user *)arg); - case EXT2_IOC_SETFLAGS: - return set_ext2_flags(inode, (u32 __user *)arg); + case IFLAGS_GET_IOC: + return gfs2_get_flags(inode, (u32 __user *)arg); + case IFLAGS_SET_IOC: + return gfs2_set_flags(inode, (u32 __user *)arg); } return -ENOTTY; } diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index a5fb4f99aa45..3ab40917383f 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -197,6 +197,22 @@ struct gfs2_quota { #define DT2IF(dt) (((dt) << 12) & S_IFMT) #define IF2DT(sif) (((sif) & S_IFMT) >> 12) +enum { + gfs2fl_Jdata = 0, + gfs2fl_ExHash = 1, + gfs2fl_Unused = 2, + gfs2fl_EaIndirect = 3, + gfs2fl_Directio = 4, + gfs2fl_Immutable = 5, + gfs2fl_AppendOnly = 6, + gfs2fl_NoAtime = 7, + gfs2fl_Sync = 8, + gfs2fl_System = 9, + gfs2fl_TruncInProg = 29, + gfs2fl_InheritDirectio = 30, + gfs2fl_InheritJdata = 31, +}; + /* Dinode flags */ #define GFS2_DIF_JDATA 0x00000001 #define GFS2_DIF_EXHASH 0x00000002 diff --git a/include/linux/iflags.h b/include/linux/iflags.h new file mode 100644 index 000000000000..1b4d9ef5d62b --- /dev/null +++ b/include/linux/iflags.h @@ -0,0 +1,104 @@ +#ifndef _LINUX_IFLAGS_H +#define _LINUX_IFLAGS_H + +/* + * A universal set of inode flags. + * + * Originally taken from ext2/3 with additions for other filesystems. + * Filesystems supporting this interface should interoperate with + * the lsattr and chattr command line tools. + * + * This interface is supported in whole or in part by: + * ext2 + * ext3 + * xfs + * jfs + * gfs2 + * + */ + +#define IFLAGS_GET_IOC _IOR('f', 1, long) +#define IFLAGS_SET_IOC _IOW('f', 2, long) + +/* + * These values are provided for use as indices of an array + * for use with the iflags_cvt function below + */ +enum { + iflag_SecureRm = 0, /* Secure deletion */ + iflag_Unrm = 1, /* Undelete */ + iflag_Compress = 2, /* Compress file */ + iflag_Sync = 3, /* Synchronous updates */ + iflag_Immutable = 4, /* Immutable */ + iflag_Append = 5, /* Append */ + iflag_NoDump = 6, /* Don't dump file */ + iflag_NoAtime = 7, /* No atime updates */ + /* Reserved for compression usage */ + iflag_Dirty = 8, + iflag_ComprBlk = 9, /* One or more compressed clusters */ + iflag_NoComp = 10, /* Don't compress */ + iflag_Ecompr = 11, /* Compression error */ + /* End of compression flags */ + iflag_Btree = 12, /* btree format dir */ + iflag_Index = 12, /* hash-indexed directory */ + iflag_Imagic = 13, /* AFS directory */ + iflag_JournalData = 14, /* file data should be journaled */ + iflag_NoTail = 15, /* file tail should not be merged */ + iflag_DirSync = 16, /* dirsync behaviour */ + iflag_TopDir = 17, /* Top of directory hierarchies */ + iflag_DirectIO = 18, /* Always use direct I/O on this file */ + iflag_InheritDirectIO = 19, /* Set DirectIO on new files in dir */ + iflag_InheritJdata = 20, /* Set JournalData on create in dir */ + iflag_Reserved = 31 /* reserved for ext2/3 lib */ +}; + +#define __IFL(x) (1<<(iflag_##x)) +#define IFLAG_SECRM __IFL(SecureRm) /* 0x00000001 */ +#define IFLAG_UNRM __IFL(Unrm) /* 0x00000002 */ +#define IFLAG_COMPR __IFL(Compr) /* 0x00000004 */ +#define IFLAG_SYNC __IFL(Sync) /* 0x00000008 */ +#define IFLAG_IMMUTABLE __IFL(Immutable) /* 0x00000010 */ +#define IFLAG_APPEND __IFL(Append) /* 0x00000020 */ +#define IFLAG_NODUMP __IFL(NoDump) /* 0x00000040 */ +#define IFLAG_NOATIME __IFL(NoAtime) /* 0x00000080 */ +#define IFLAG_DIRTY __IFL(Dirty) /* 0x00000100 */ +#define IFLAG_COMPRBLK __IFL(ComprBlk) /* 0x00000200 */ +#define IFLAG_NOCOMP __IFL(NoComp) /* 0x00000400 */ +#define IFLAG_ECOMPR __IFL(Ecompr) /* 0x00000800 */ +#define IFLAG_BTREE __IFL(Btree) /* 0x00001000 */ +#define IFLAG_INDEX __IFL(Index) /* 0x00001000 */ +#define IFLAG_IMAGIC __IFL(Imagic) /* 0x00002000 */ +#define IFLAG_JOURNAL_DATA __IFL(JournalData) /* 0x00004000 */ +#define IFLAG_NOTAIL __IFL(NoTail) /* 0x00008000 */ +#define IFLAG_DIRSYNC __IFL(DirSync) /* 0x00010000 */ +#define IFLAG_TOPDIR __IFL(TopDir) /* 0x00020000 */ +#define IFLAG_DIRECTIO __IFL(DirectIO) /* 0x00040000 */ +#define IFLAG_INHERITDIRECTIO __IFL(InheritDirectIO) /* 0x00080000 */ +#define IFLAG_INHERITJDATA __IFL(InheritJdata) /* 0x00100000 */ +#define IFLAG_RESERVED __IFL(Reserved) /* 0x80000000 */ + +#ifdef __KERNEL__ +/** + * iflags_cvt + * @table: A table of 32 u32 flags + * @val: a 32 bit value to convert + * + * This function can be used to convert between IFLAGS values and + * the filesystem's own flags values. + * + * Returns: the converted flags + */ +static inline u32 iflags_cvt(const u32 *table, u32 val) +{ + u32 res = 0; + while(val) { + if (val & 1) + res |= *table; + table++; + val >>= 1; + } + return res; +} +#endif /* __KERNEL__ */ + +#endif /* _LINUX_IFLAGS_H */ From 8628de0583504138551a05ad44ca388467f0f552 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 31 Mar 2006 16:48:41 -0500 Subject: [PATCH 071/292] [GFS2] Update GFS2 for the recent pull from Linus Some interfaces have changed. In particular one of the posix locking functions has changed prototype, along with the address space operation invalidatepage and the block getting callback to the direct IO function. In addition add the splice file operations. These will need to be updated to support AOP_TRUNCATED_PAGE before they will be of much use to us. Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/nolock/main.c | 15 +++----- fs/gfs2/ops_address.c | 66 ++++------------------------------- fs/gfs2/ops_file.c | 19 +++++----- 3 files changed, 19 insertions(+), 81 deletions(-) diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index 9398309f2810..ecd37371eba5 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -176,14 +176,13 @@ static void nolock_sync_lvb(lm_lock_t *lock, char *lvb) static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl) { - struct file_lock *tmp; + struct file_lock tmp; + int ret; - lock_kernel(); - tmp = posix_test_lock(file, fl); + ret = posix_test_lock(file, fl, &tmp); fl->fl_type = F_UNLCK; - if (tmp) - memcpy(fl, tmp, sizeof(struct file_lock)); - unlock_kernel(); + if (ret) + memcpy(fl, &tmp, sizeof(struct file_lock)); return 0; } @@ -192,9 +191,7 @@ static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, struct file *file, int cmd, struct file_lock *fl) { int error; - lock_kernel(); error = posix_lock_file_wait(file, fl); - unlock_kernel(); return error; } @@ -202,9 +199,7 @@ static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl) { int error; - lock_kernel(); error = posix_lock_file_wait(file, fl); - unlock_kernel(); return error; } diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 01aa4a9b48c3..3fd8c6ec256c 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -96,59 +96,6 @@ static int get_block_noalloc(struct inode *inode, sector_t lblock, return error; } -static int get_blocks(struct inode *inode, sector_t lblock, - unsigned long max_blocks, struct buffer_head *bh_result, - int create) -{ - struct gfs2_inode *ip = inode->u.generic_ip; - int new = create; - uint64_t dblock; - uint32_t extlen; - int error; - - error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); - if (error) - return error; - - if (!dblock) - return 0; - - map_bh(bh_result, inode->i_sb, dblock); - if (new) - set_buffer_new(bh_result); - - if (extlen > max_blocks) - extlen = max_blocks; - bh_result->b_size = extlen << inode->i_blkbits; - - return 0; -} - -static int get_blocks_noalloc(struct inode *inode, sector_t lblock, - unsigned long max_blocks, - struct buffer_head *bh_result, int create) -{ - struct gfs2_inode *ip = inode->u.generic_ip; - int new = 0; - uint64_t dblock; - uint32_t extlen; - int error; - - error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); - if (error) - return error; - - if (dblock) { - map_bh(bh_result, inode->i_sb, dblock); - if (extlen > max_blocks) - extlen = max_blocks; - bh_result->b_size = extlen << inode->i_blkbits; - } else if (gfs2_assert_withdraw(ip->i_sbd, !create)) - error = -EIO; - - return error; -} - /** * gfs2_writepage - Write complete page * @page: Page to write @@ -527,16 +474,15 @@ static void discard_buffer(struct gfs2_sbd *sdp, struct buffer_head *bh) unlock_buffer(bh); } -static int gfs2_invalidatepage(struct page *page, unsigned long offset) +static void gfs2_invalidatepage(struct page *page, unsigned long offset) { struct gfs2_sbd *sdp = page->mapping->host->i_sb->s_fs_info; struct buffer_head *head, *bh, *next; unsigned int curr_off = 0; - int ret = 1; BUG_ON(!PageLocked(page)); if (!page_has_buffers(page)) - return 1; + return; bh = head = page_buffers(page); do { @@ -551,9 +497,9 @@ static int gfs2_invalidatepage(struct page *page, unsigned long offset) } while (bh != head); if (!offset) - ret = try_to_release_page(page, 0); + try_to_release_page(page, 0); - return ret; + return; } static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov, @@ -587,7 +533,7 @@ static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov, goto out; rv = __blockdev_direct_IO(WRITE, iocb, inode, inode->i_sb->s_bdev, - iov, offset, nr_segs, get_blocks_noalloc, + iov, offset, nr_segs, gfs2_get_block, NULL, DIO_OWN_LOCKING); out: gfs2_glock_dq_m(1, &gh); @@ -619,7 +565,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, return -EINVAL; return __blockdev_direct_IO(READ, iocb, inode, inode->i_sb->s_bdev, iov, - offset, nr_segs, get_blocks, NULL, + offset, nr_segs, gfs2_get_block, NULL, DIO_OWN_LOCKING); } diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index db4484a3efcc..c44225fa758b 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -833,20 +833,15 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) if (sdp->sd_args.ar_localflocks) { if (IS_GETLK(cmd)) { - struct file_lock *tmp; - lock_kernel(); - tmp = posix_test_lock(file, fl); + struct file_lock tmp; + int ret; + ret = posix_test_lock(file, fl, &tmp); fl->fl_type = F_UNLCK; - if (tmp) - memcpy(fl, tmp, sizeof(struct file_lock)); - unlock_kernel(); + if (ret) + memcpy(fl, &tmp, sizeof(struct file_lock)); return 0; } else { - int error; - lock_kernel(); - error = posix_lock_file_wait(file, fl); - unlock_kernel(); - return error; + return posix_lock_file_wait(file, fl); } } @@ -983,6 +978,8 @@ struct file_operations gfs2_file_fops = { .lock = gfs2_lock, .sendfile = gfs2_sendfile, .flock = gfs2_flock, + .splice_read = generic_file_splice_read, + .splice_write = generic_file_splice_write, }; struct file_operations gfs2_dir_fops = { From 55eccc6d00cea224bf634d44e9871cfe83200ff2 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 4 Apr 2006 14:29:30 -0400 Subject: [PATCH 072/292] [GFS2] Finish off ioctl support This puts the finishing touches to the ioctl support and also removes a couple of unused fields from GFS2's private per file structure. Signed-off-by: Steven Whitehouse --- fs/gfs2/incore.h | 4 ---- fs/gfs2/ops_file.c | 22 +++++++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index b5a994d1b5f7..423cfa72b4c7 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -277,12 +277,8 @@ enum { struct gfs2_file { unsigned long f_flags; /* GFF_... */ - struct mutex f_fl_mutex; struct gfs2_holder f_fl_gh; - - struct gfs2_inode *f_inode; - struct file *f_vfile; }; struct gfs2_revoke { diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index c44225fa758b..9bb296717086 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -572,7 +572,7 @@ static int gfs2_get_flags(struct inode *inode, u32 __user *ptr) error = gfs2_glock_nq_m_atime(1, &gh); if (error) return error; - + iflags = iflags_cvt(gfs2_to_iflags, ip->i_di.di_flags); if (put_user(iflags, ptr)) error = -EFAULT; @@ -600,20 +600,22 @@ static int gfs2_get_flags(struct inode *inode, u32 __user *ptr) * @mask: Indicates which flags are valid * */ -static int do_gfs2_set_flags(struct inode *inode, u32 flags, u32 mask) +static int do_gfs2_set_flags(struct inode *inode, u32 reqflags, u32 mask) { struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; struct buffer_head *bh; struct gfs2_holder gh; int error; - u32 new_flags; + u32 new_flags, flags; gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); if (error) return error; - new_flags = (ip->i_di.di_flags & ~mask) | (flags & mask); + flags = ip->i_di.di_flags; + new_flags = (flags & ~mask) | (reqflags & mask); if ((new_flags ^ flags) == 0) goto out; @@ -640,13 +642,18 @@ static int do_gfs2_set_flags(struct inode *inode, u32 flags, u32 mask) if (error) goto out; - error = gfs2_meta_inode_buffer(ip, &bh); + error = gfs2_trans_begin(sdp, RES_DINODE, 0); if (error) goto out; + error = gfs2_meta_inode_buffer(ip, &bh); + if (error) + goto out_trans_end; gfs2_trans_add_bh(ip->i_gl, bh, 1); ip->i_di.di_flags = new_flags; gfs2_dinode_out(&ip->i_di, bh->b_data); brelse(bh); +out_trans_end: + gfs2_trans_end(sdp); out: gfs2_glock_dq_uninit(&gh); return error; @@ -730,9 +737,6 @@ static int gfs2_open(struct inode *inode, struct file *file) mutex_init(&fp->f_fl_mutex); - fp->f_inode = ip; - fp->f_vfile = file; - gfs2_assert_warn(ip->i_sbd, !file->private_data); file->private_data = fp; @@ -875,7 +879,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) { struct gfs2_file *fp = file->private_data; struct gfs2_holder *fl_gh = &fp->f_fl_gh; - struct gfs2_inode *ip = fp->f_inode; + struct gfs2_inode *ip = file->f_dentry->d_inode->u.generic_ip; struct gfs2_glock *gl; unsigned int state; int flags; From b09e593d799560f1a0782c20ac5900058390a26f Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 7 Apr 2006 11:17:32 -0400 Subject: [PATCH 073/292] [GFS2] Fix a ref count bug and other clean ups This fixes a ref count bug that sometimes showed up a umount time (causing it to hang) but it otherwise mostly harmless. At the same time there are some clean ups including making the log operations structures const, moving a memory allocation so that its not done in the fast path of checking to see if there is an outstanding transaction related to a particular glock. Removes the sd_log_wrap varaible which was updated, but never actually used anywhere. Updates the gfs2 ioctl() to run without the kernel lock (which it never needed anyway). Removes the "invalidate inodes" loop from GFS2's put_super routine. This is done in kill super anyway so we don't need to do it here. The loop was also bogus in that if there are any inodes "stuck" at this point its a bug and we need to know about it rather than hide it by hanging forever. Signed-off-by: Steven Whitehouse --- fs/gfs2/daemon.c | 2 +- fs/gfs2/dir.c | 2 ++ fs/gfs2/glops.c | 6 +++--- fs/gfs2/incore.h | 6 +++--- fs/gfs2/log.c | 33 ++++++++++++++++++--------------- fs/gfs2/log.h | 6 +----- fs/gfs2/lops.c | 14 ++++++++------ fs/gfs2/lops.h | 14 +++++++------- fs/gfs2/meta_io.c | 10 +++++----- fs/gfs2/ops_file.c | 23 ++++++++++++----------- fs/gfs2/ops_fstype.c | 4 ++-- fs/gfs2/ops_super.c | 12 +++--------- fs/gfs2/quota.c | 2 +- fs/gfs2/trans.c | 2 +- 14 files changed, 67 insertions(+), 69 deletions(-) diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c index 94317dc7e42c..b3830b92d78c 100644 --- a/fs/gfs2/daemon.c +++ b/fs/gfs2/daemon.c @@ -129,7 +129,7 @@ int gfs2_logd(void *data) gfs2_ail1_empty(sdp, DIO_ALL); if (time_after_eq(jiffies, t)) { - gfs2_log_flush(sdp); + gfs2_log_flush(sdp, NULL); sdp->sd_log_flush_time = jiffies; } diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 66917f2c64aa..316eed688f8e 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -789,6 +789,8 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, if (error) return ERR_PTR(error); dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, scan, name, NULL); + brelse(bh); + got_dent: *pbh = bh; return dent; diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index d9334eb72df8..d180c89dd567 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -45,7 +45,7 @@ static void meta_go_sync(struct gfs2_glock *gl, int flags) return; if (test_and_clear_bit(GLF_DIRTY, &gl->gl_flags)) { - gfs2_log_flush_glock(gl); + gfs2_log_flush(gl->gl_sbd, gl); gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); if (flags & DIO_RELEASE) gfs2_ail_empty_gl(gl); @@ -149,12 +149,12 @@ static void inode_go_sync(struct gfs2_glock *gl, int flags) if (test_bit(GLF_DIRTY, &gl->gl_flags)) { if (meta && data) { gfs2_page_sync(gl, flags | DIO_START); - gfs2_log_flush_glock(gl); + gfs2_log_flush(gl->gl_sbd, gl); gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); gfs2_page_sync(gl, flags | DIO_WAIT); clear_bit(GLF_DIRTY, &gl->gl_flags); } else if (meta) { - gfs2_log_flush_glock(gl); + gfs2_log_flush(gl->gl_sbd, gl); gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); } else if (data) gfs2_page_sync(gl, flags | DIO_START | DIO_WAIT); diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 423cfa72b4c7..dfed83b37ab7 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -62,12 +62,12 @@ struct gfs2_log_operations { struct gfs2_log_descriptor *ld, __be64 *ptr, int pass); void (*lo_after_scan) (struct gfs2_jdesc *jd, int error, int pass); - char *lo_name; + const char *lo_name; }; struct gfs2_log_element { struct list_head le_list; - struct gfs2_log_operations *le_ops; + const struct gfs2_log_operations *le_ops; }; struct gfs2_bitmap { @@ -618,6 +618,7 @@ struct gfs2_sbd { unsigned int sd_log_num_rg; unsigned int sd_log_num_databuf; unsigned int sd_log_num_jdata; + unsigned int sd_log_num_hdrs; struct list_head sd_log_le_gl; struct list_head sd_log_le_buf; @@ -631,7 +632,6 @@ struct gfs2_sbd { uint64_t sd_log_sequence; unsigned int sd_log_head; unsigned int sd_log_tail; - uint64_t sd_log_wraps; int sd_log_idle; unsigned long sd_log_flush_time; diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index ea69376c00d8..cadfef193e55 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -171,13 +171,14 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) while(sdp->sd_log_blks_free <= blks) { gfs2_log_unlock(sdp); gfs2_ail1_empty(sdp, 0); - gfs2_log_flush(sdp); + gfs2_log_flush(sdp, NULL); if (try++) gfs2_ail1_start(sdp, 0); gfs2_log_lock(sdp); } sdp->sd_log_blks_free -= blks; + /* printk(KERN_INFO "reserved %u blocks (%u left)\n", blks, sdp->sd_log_blks_free); */ gfs2_log_unlock(sdp); mutex_unlock(&sdp->sd_log_reserve_mutex); @@ -199,6 +200,7 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) gfs2_log_lock(sdp); sdp->sd_log_blks_free += blks; + /* printk(KERN_INFO "released %u blocks (%u left)\n", blks, sdp->sd_log_blks_free); */ gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); gfs2_log_unlock(sdp); @@ -342,6 +344,7 @@ static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail, int pull) gfs2_log_lock(sdp); sdp->sd_log_blks_free += dist - ((pull) ? 1 : 0); + /* printk(KERN_INFO "pull tail refunding %u blocks (%u left) pull=%d\n", dist - ((pull) ? 1 : 0), sdp->sd_log_blks_free, pull); */ gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); gfs2_log_unlock(sdp); @@ -364,6 +367,8 @@ static void log_write_header(struct gfs2_sbd *sdp, uint32_t flags, int pull) unsigned int tail; uint32_t hash; + /* printk(KERN_INFO "log write header start (flags=%08x, pull=%d)\n", flags, pull); */ + bh = sb_getblk(sdp->sd_vfs, blkno); lock_buffer(bh); memset(bh->b_data, 0, bh->b_size); @@ -398,6 +403,8 @@ static void log_write_header(struct gfs2_sbd *sdp, uint32_t flags, int pull) sdp->sd_log_idle = (tail == sdp->sd_log_flush_head); log_incr_head(sdp); + + /* printk(KERN_INFO "log write header out\n"); */ } static void log_flush_commit(struct gfs2_sbd *sdp) @@ -432,20 +439,16 @@ static void log_flush_commit(struct gfs2_sbd *sdp) } /** - * gfs2_log_flush_i - flush incore transaction(s) + * gfs2_log_flush - flush incore transaction(s) * @sdp: the filesystem * @gl: The glock structure to flush. If NULL, flush the whole incore log * */ -void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) +void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) { struct gfs2_ail *ai; - ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); - INIT_LIST_HEAD(&ai->ai_ail1_list); - INIT_LIST_HEAD(&ai->ai_ail2_list); - down_write(&sdp->sd_log_flush_lock); if (gl) { @@ -453,12 +456,14 @@ void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) if (list_empty(&gl->gl_le.le_list)) { gfs2_log_unlock(sdp); up_write(&sdp->sd_log_flush_lock); - kfree(ai); return; } gfs2_log_unlock(sdp); } + ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); + INIT_LIST_HEAD(&ai->ai_ail1_list); + INIT_LIST_HEAD(&ai->ai_ail2_list); gfs2_assert_withdraw(sdp, sdp->sd_log_num_buf == sdp->sd_log_commited_buf); @@ -476,11 +481,12 @@ void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl) log_write_header(sdp, 0, PULL); lops_after_commit(sdp, ai); sdp->sd_log_head = sdp->sd_log_flush_head; - if (sdp->sd_log_flush_wrapped) - sdp->sd_log_wraps++; + + /* printk(KERN_INFO "sd_log_num_hdrs %u\n", sdp->sd_log_num_hdrs); */ sdp->sd_log_blks_reserved = sdp->sd_log_commited_buf = + sdp->sd_log_num_hdrs = sdp->sd_log_commited_revoke = 0; gfs2_log_lock(sdp); @@ -519,8 +525,7 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) sdp->sd_log_blks_free += tr->tr_reserved - (reserved - sdp->sd_log_blks_reserved); - gfs2_assert_withdraw(sdp, - sdp->sd_log_blks_free >= old); + gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free >= old); gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); @@ -548,7 +553,7 @@ void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) gfs2_log_lock(sdp); if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks)) { gfs2_log_unlock(sdp); - gfs2_log_flush(sdp); + gfs2_log_flush(sdp, NULL); } else gfs2_log_unlock(sdp); } @@ -583,8 +588,6 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp) gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail2_list)); sdp->sd_log_head = sdp->sd_log_flush_head; - if (sdp->sd_log_flush_wrapped) - sdp->sd_log_wraps++; sdp->sd_log_tail = sdp->sd_log_head; up_write(&sdp->sd_log_flush_lock); diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h index e7a6a65c530f..84a3e902e848 100644 --- a/fs/gfs2/log.h +++ b/fs/gfs2/log.h @@ -37,7 +37,6 @@ static inline void gfs2_log_pointers_init(struct gfs2_sbd *sdp, { if (++value == sdp->sd_jdesc->jd_blocks) { value = 0; - sdp->sd_log_wraps++; } sdp->sd_log_head = sdp->sd_log_tail = value; } @@ -54,10 +53,7 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks); struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp); struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, struct buffer_head *real); - -#define gfs2_log_flush(sdp) gfs2_log_flush_i((sdp), NULL) -#define gfs2_log_flush_glock(gl) gfs2_log_flush_i((gl)->gl_sbd, (gl)) -void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl); +void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl); void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans); void gfs2_log_shutdown(struct gfs2_sbd *sdp); diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 689c9101c0fb..4d90eb311497 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -130,6 +130,7 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp) if (total > limit) num = limit; bh = gfs2_log_get_buf(sdp); + sdp->sd_log_num_hdrs++; ld = (struct gfs2_log_descriptor *)bh->b_data; ptr = (__be64 *)(bh->b_data + offset); ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC); @@ -570,6 +571,7 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) gfs2_log_unlock(sdp); if (!bh) { bh = gfs2_log_get_buf(sdp); + sdp->sd_log_num_hdrs++; ld = (struct gfs2_log_descriptor *) bh->b_data; ptr = (__be64 *)(bh->b_data + offset); @@ -750,13 +752,13 @@ static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) } -struct gfs2_log_operations gfs2_glock_lops = { +const struct gfs2_log_operations gfs2_glock_lops = { .lo_add = glock_lo_add, .lo_after_commit = glock_lo_after_commit, .lo_name = "glock" }; -struct gfs2_log_operations gfs2_buf_lops = { +const struct gfs2_log_operations gfs2_buf_lops = { .lo_add = buf_lo_add, .lo_incore_commit = buf_lo_incore_commit, .lo_before_commit = buf_lo_before_commit, @@ -767,7 +769,7 @@ struct gfs2_log_operations gfs2_buf_lops = { .lo_name = "buf" }; -struct gfs2_log_operations gfs2_revoke_lops = { +const struct gfs2_log_operations gfs2_revoke_lops = { .lo_add = revoke_lo_add, .lo_before_commit = revoke_lo_before_commit, .lo_before_scan = revoke_lo_before_scan, @@ -776,13 +778,13 @@ struct gfs2_log_operations gfs2_revoke_lops = { .lo_name = "revoke" }; -struct gfs2_log_operations gfs2_rg_lops = { +const struct gfs2_log_operations gfs2_rg_lops = { .lo_add = rg_lo_add, .lo_after_commit = rg_lo_after_commit, .lo_name = "rg" }; -struct gfs2_log_operations gfs2_databuf_lops = { +const struct gfs2_log_operations gfs2_databuf_lops = { .lo_add = databuf_lo_add, .lo_incore_commit = buf_lo_incore_commit, .lo_before_commit = databuf_lo_before_commit, @@ -792,7 +794,7 @@ struct gfs2_log_operations gfs2_databuf_lops = { .lo_name = "databuf" }; -struct gfs2_log_operations *gfs2_log_ops[] = { +const struct gfs2_log_operations *gfs2_log_ops[] = { &gfs2_glock_lops, &gfs2_buf_lops, &gfs2_revoke_lops, diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h index 417f5aade4b1..0c78d222d6f2 100644 --- a/fs/gfs2/lops.h +++ b/fs/gfs2/lops.h @@ -10,16 +10,16 @@ #ifndef __LOPS_DOT_H__ #define __LOPS_DOT_H__ -extern struct gfs2_log_operations gfs2_glock_lops; -extern struct gfs2_log_operations gfs2_buf_lops; -extern struct gfs2_log_operations gfs2_revoke_lops; -extern struct gfs2_log_operations gfs2_rg_lops; -extern struct gfs2_log_operations gfs2_databuf_lops; +extern const struct gfs2_log_operations gfs2_glock_lops; +extern const struct gfs2_log_operations gfs2_buf_lops; +extern const struct gfs2_log_operations gfs2_revoke_lops; +extern const struct gfs2_log_operations gfs2_rg_lops; +extern const struct gfs2_log_operations gfs2_databuf_lops; -extern struct gfs2_log_operations *gfs2_log_ops[]; +extern const struct gfs2_log_operations *gfs2_log_ops[]; static inline void lops_init_le(struct gfs2_log_element *le, - struct gfs2_log_operations *lops) + const struct gfs2_log_operations *lops) { INIT_LIST_HEAD(&le->le_list); le->le_ops = lops; diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index b85fa2464666..4a6aacf294d5 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -59,11 +59,12 @@ static int gfs2_aspace_writepage(struct page *page, static void stuck_releasepage(struct buffer_head *bh) { - struct gfs2_sbd *sdp = bh->b_page->mapping->host->i_sb->s_fs_info; + struct inode *inode = bh->b_page->mapping->host; + struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; struct gfs2_bufdata *bd = bh->b_private; struct gfs2_glock *gl; - fs_warn(sdp, "stuck in gfs2_releasepage()\n"); + fs_warn(sdp, "stuck in gfs2_releasepage() %p\n", inode); fs_warn(sdp, "blkno = %llu, bh->b_count = %d\n", (uint64_t)bh->b_blocknr, atomic_read(&bh->b_count)); fs_warn(sdp, "pinned = %u\n", buffer_pinned(bh)); @@ -191,7 +192,6 @@ struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp) aspace->u.generic_ip = NULL; insert_inode_hash(aspace); } - return aspace; } @@ -353,7 +353,7 @@ void gfs2_ail_empty_gl(struct gfs2_glock *gl) gfs2_log_unlock(sdp); gfs2_trans_end(sdp); - gfs2_log_flush(sdp); + gfs2_log_flush(sdp, NULL); } /** @@ -876,7 +876,7 @@ void gfs2_meta_ra(struct gfs2_glock *gl, uint64_t dblock, uint32_t extlen) void gfs2_meta_syncfs(struct gfs2_sbd *sdp) { - gfs2_log_flush(sdp); + gfs2_log_flush(sdp, NULL); for (;;) { gfs2_ail1_start(sdp, DIO_ALL); if (gfs2_ail1_empty(sdp, DIO_ALL)) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 9bb296717086..3fb1a29f88a6 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -561,8 +561,9 @@ static const u32 gfs2_to_iflags[32] = { [gfs2fl_InheritJdata] = IFLAG_INHERITJDATA, }; -static int gfs2_get_flags(struct inode *inode, u32 __user *ptr) +static int gfs2_get_flags(struct file *filp, u32 __user *ptr) { + struct inode *inode = filp->f_dentry->d_inode; struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_holder gh; int error; @@ -600,8 +601,9 @@ static int gfs2_get_flags(struct inode *inode, u32 __user *ptr) * @mask: Indicates which flags are valid * */ -static int do_gfs2_set_flags(struct inode *inode, u32 reqflags, u32 mask) +static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) { + struct inode *inode = filp->f_dentry->d_inode; struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; struct buffer_head *bh; @@ -659,23 +661,22 @@ out: return error; } -static int gfs2_set_flags(struct inode *inode, u32 __user *ptr) +static int gfs2_set_flags(struct file *filp, u32 __user *ptr) { u32 iflags, gfsflags; if (get_user(iflags, ptr)) return -EFAULT; gfsflags = iflags_cvt(iflags_to_gfs2, iflags); - return do_gfs2_set_flags(inode, gfsflags, ~0); + return do_gfs2_set_flags(filp, gfsflags, ~0); } -int gfs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, - unsigned long arg) +static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { switch(cmd) { case IFLAGS_GET_IOC: - return gfs2_get_flags(inode, (u32 __user *)arg); + return gfs2_get_flags(filp, (u32 __user *)arg); case IFLAGS_SET_IOC: - return gfs2_set_flags(inode, (u32 __user *)arg); + return gfs2_set_flags(filp, (u32 __user *)arg); } return -ENOTTY; } @@ -808,7 +809,7 @@ static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) { struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; - gfs2_log_flush_glock(ip->i_gl); + gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); return 0; } @@ -974,7 +975,7 @@ struct file_operations gfs2_file_fops = { .write = generic_file_write, .writev = generic_file_writev, .aio_write = generic_file_aio_write, - .ioctl = gfs2_ioctl, + .unlocked_ioctl = gfs2_ioctl, .mmap = gfs2_mmap, .open = gfs2_open, .release = gfs2_close, @@ -988,7 +989,7 @@ struct file_operations gfs2_file_fops = { struct file_operations gfs2_dir_fops = { .readdir = gfs2_readdir, - .ioctl = gfs2_ioctl, + .unlocked_ioctl = gfs2_ioctl, .open = gfs2_open, .release = gfs2_close, .fsync = gfs2_fsync, diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 5166455b9fdd..4538a1e621e8 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -276,8 +276,8 @@ static struct inode *gfs2_lookup_root(struct gfs2_sbd *sdp, struct gfs2_inode *ip; struct inode *inode; - error = gfs2_glock_get(sdp, inum->no_addr, - &gfs2_inode_glops, CREATE, &gl); + error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops, + CREATE, &gl); if (!error) { error = gfs2_inode_get(gl, inum, CREATE, &ip); if (!error) { diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index f7349c0989a9..80ce40c1dfb6 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -53,7 +53,7 @@ static int gfs2_write_inode(struct inode *inode, int sync) if (current->flags & PF_MEMALLOC) return 0; if (ip && sync) - gfs2_log_flush_glock(ip->i_gl); + gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); return 0; } @@ -121,10 +121,8 @@ static void gfs2_put_super(struct super_block *sb) } gfs2_glock_dq_uninit(&sdp->sd_live_gh); - gfs2_clear_rgrpd(sdp); gfs2_jindex_free(sdp); - /* Take apart glock structures and buffer lists */ gfs2_gl_hash_clear(sdp, WAIT); @@ -135,10 +133,6 @@ static void gfs2_put_super(struct super_block *sb) gfs2_sys_fs_del(sdp); - /* Get rid of any extra inodes */ - while (invalidate_inodes(sb)) - yield(); - vfree(sdp); sb->s_fs_info = NULL; @@ -149,13 +143,13 @@ static void gfs2_put_super(struct super_block *sb) * @sb: the filesystem * * This function is called every time sync(2) is called. - * After this exits, all dirty buffers and synced. + * After this exits, all dirty buffers are synced. */ static void gfs2_write_super(struct super_block *sb) { struct gfs2_sbd *sdp = sb->s_fs_info; - gfs2_log_flush(sdp); + gfs2_log_flush(sdp, NULL); } /** diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index c57b5cf1d583..90e32a3dc50d 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -749,7 +749,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) while (qx--) gfs2_glock_dq_uninit(&ghs[qx]); kfree(ghs); - gfs2_log_flush_glock(ip->i_gl); + gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); return error; } diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index d72f79e67c94..061f4a9a1db4 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -120,7 +120,7 @@ void gfs2_trans_end(struct gfs2_sbd *sdp) kfree(tr); if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS) - gfs2_log_flush(sdp); + gfs2_log_flush(sdp, NULL); } void gfs2_trans_add_gl(struct gfs2_glock *gl) From ed3865079b573ef55dc13ab0bfb242ed5ebab4c1 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 7 Apr 2006 16:28:07 -0400 Subject: [PATCH 074/292] [GFS2] Finally get ref counting correct The last patch missed some other instances of incorrect ref counting, this fixes all of those too. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 17 ++++++++++++----- fs/gfs2/log.c | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 316eed688f8e..100672d2c6c5 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -776,9 +776,9 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, goto got_dent; leaf = (struct gfs2_leaf *)bh->b_data; ln = be64_to_cpu(leaf->lf_next); - brelse(bh); if (!ln) break; + brelse(bh); error = get_leaf(ip, ln, &bh); } while(!error); @@ -789,9 +789,11 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, if (error) return ERR_PTR(error); dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, scan, name, NULL); - brelse(bh); - got_dent: + if (unlikely(IS_ERR(dent))) { + brelse(bh); + bh = NULL; + } *pbh = bh; return dent; } @@ -1475,6 +1477,7 @@ int gfs2_dir_search(struct inode *dir, const struct qstr *name, brelse(bh); return 0; } + brelse(bh); return -ENOENT; } @@ -1616,6 +1619,7 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name) previous entry otherwise */ dent = gfs2_dirent_search(dip->i_vnode, name, gfs2_dirent_prev, &bh); if (!dent) { + brelse(bh); gfs2_consist_inode(dip); return -EIO; } @@ -1636,8 +1640,8 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name) if (!entries) gfs2_consist_inode(dip); leaf->lf_entries = cpu_to_be16(--entries); - brelse(bh); } + brelse(bh); error = gfs2_meta_inode_buffer(dip, &bh); if (error) @@ -1676,6 +1680,7 @@ int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, dent = gfs2_dirent_search(dip->i_vnode, filename, gfs2_dirent_find, &bh); if (!dent) { + brelse(bh); gfs2_consist_inode(dip); return -EIO; } @@ -1955,8 +1960,10 @@ int gfs2_diradd_alloc_required(struct inode *inode, struct buffer_head *bh; dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh); - if (!dent) + if (!dent) { + brelse(bh); return 1; + } if (IS_ERR(dent)) return PTR_ERR(dent); brelse(bh); diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index cadfef193e55..0b26d6a74118 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -196,7 +196,6 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) { - up_read(&sdp->sd_log_flush_lock); gfs2_log_lock(sdp); sdp->sd_log_blks_free += blks; @@ -204,6 +203,7 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); gfs2_log_unlock(sdp); + up_read(&sdp->sd_log_flush_lock); } static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) From f4154ea039bbf45c52840b30c68143a2dc28d4b4 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 11 Apr 2006 14:49:06 -0400 Subject: [PATCH 075/292] [GFS2] Update journal accounting code. A small update to the journaling code to change the way that the "extra" blocks are accounted for in the journal. These are used at a rate of one per 503 metadata blocks or one per 251 journaled data blocks (or just one if the total number of journaled blocks in the transaction is smaller). Since we are using them at two different rates the old method of accounting for them no longer works and we count them up as required. Since the "per transaction" accounting can't handle this (there is no fixed number of header blocks per transaction) we have to account for it in the general journal code. We now require that each transaction reserves more blocks than it actually needs to take account of the possible extra blocks. Also a final fix to dir.c to ensure that all ref counts are handled correctly. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 8 ++------ fs/gfs2/log.c | 10 +++++++--- fs/gfs2/trans.c | 13 +++---------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 100672d2c6c5..01f89c727cc8 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -776,9 +776,9 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, goto got_dent; leaf = (struct gfs2_leaf *)bh->b_data; ln = be64_to_cpu(leaf->lf_next); + brelse(bh); if (!ln) break; - brelse(bh); error = get_leaf(ip, ln, &bh); } while(!error); @@ -790,7 +790,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, return ERR_PTR(error); dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, scan, name, NULL); got_dent: - if (unlikely(IS_ERR(dent))) { + if (unlikely(dent == NULL || IS_ERR(dent))) { brelse(bh); bh = NULL; } @@ -1477,7 +1477,6 @@ int gfs2_dir_search(struct inode *dir, const struct qstr *name, brelse(bh); return 0; } - brelse(bh); return -ENOENT; } @@ -1619,7 +1618,6 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name) previous entry otherwise */ dent = gfs2_dirent_search(dip->i_vnode, name, gfs2_dirent_prev, &bh); if (!dent) { - brelse(bh); gfs2_consist_inode(dip); return -EIO; } @@ -1680,7 +1678,6 @@ int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, dent = gfs2_dirent_search(dip->i_vnode, filename, gfs2_dirent_find, &bh); if (!dent) { - brelse(bh); gfs2_consist_inode(dip); return -EIO; } @@ -1961,7 +1958,6 @@ int gfs2_diradd_alloc_required(struct inode *inode, dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh); if (!dent) { - brelse(bh); return 1; } if (IS_ERR(dent)) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 0b26d6a74118..b0dd0b9ad79b 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -412,11 +412,13 @@ static void log_flush_commit(struct gfs2_sbd *sdp) struct list_head *head = &sdp->sd_log_flush_list; struct gfs2_log_buf *lb; struct buffer_head *bh; +#if 0 unsigned int d; d = log_distance(sdp, sdp->sd_log_flush_head, sdp->sd_log_head); gfs2_assert_withdraw(sdp, d + 1 == sdp->sd_log_blks_reserved); +#endif while (!list_empty(head)) { lb = list_entry(head->next, struct gfs2_log_buf, lb_list); @@ -483,6 +485,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) sdp->sd_log_head = sdp->sd_log_flush_head; /* printk(KERN_INFO "sd_log_num_hdrs %u\n", sdp->sd_log_num_hdrs); */ + sdp->sd_log_blks_free -= sdp->sd_log_num_hdrs; sdp->sd_log_blks_reserved = sdp->sd_log_commited_buf = @@ -515,8 +518,7 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0); if (sdp->sd_log_commited_buf) - reserved += 1 + sdp->sd_log_commited_buf + - sdp->sd_log_commited_buf/503; + reserved += sdp->sd_log_commited_buf; if (sdp->sd_log_commited_revoke) reserved += gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke, sizeof(uint64_t)); @@ -527,7 +529,8 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free >= old); gfs2_assert_withdraw(sdp, - sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); + sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks + + sdp->sd_log_num_hdrs); sdp->sd_log_blks_reserved = reserved; @@ -582,6 +585,7 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp) log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT, 0); + /* printk(KERN_INFO "sd_log_blks_free %u, sd_jdesc->jd_blocks %u\n", sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); */ gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free == sdp->sd_jdesc->jd_blocks); gfs2_assert_withdraw(sdp, sdp->sd_log_head == sdp->sd_log_tail); diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 061f4a9a1db4..6b02d8c38f0f 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -44,7 +44,7 @@ int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks, tr->tr_revokes = revokes; tr->tr_reserved = 1; if (blocks) - tr->tr_reserved += 1 + blocks; + tr->tr_reserved += 6 + blocks; if (revokes) tr->tr_reserved += gfs2_struct2blk(sdp, revokes, sizeof(uint64_t)); @@ -83,20 +83,15 @@ fail_holder_uninit: void gfs2_trans_end(struct gfs2_sbd *sdp) { - struct gfs2_trans *tr; + struct gfs2_trans *tr = current->journal_info; - tr = current->journal_info; + BUG_ON(!tr); current->journal_info = NULL; - if (gfs2_assert_warn(sdp, tr)) - return; - if (!tr->tr_touched) { gfs2_log_release(sdp, tr->tr_reserved); - gfs2_glock_dq(&tr->tr_t_gh); gfs2_holder_uninit(&tr->tr_t_gh); - kfree(tr); return; } @@ -113,10 +108,8 @@ void gfs2_trans_end(struct gfs2_sbd *sdp) } gfs2_log_commit(sdp, tr); - gfs2_glock_dq(&tr->tr_t_gh); gfs2_holder_uninit(&tr->tr_t_gh); - kfree(tr); if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS) From 4d8012b60e0f0e0217e65f67da7d97276d1824e9 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 12 Apr 2006 17:39:45 -0400 Subject: [PATCH 076/292] [GFS2] Fix bug which was causing postmark to fail A typo in the directory code was causing postmark to fail somewhere in the allocation code, since it was unable to find newly allocated directory leaf blocks under certain circumstances. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 01f89c727cc8..fe6c5adc5df0 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -1511,7 +1511,7 @@ static int dir_new_leaf(struct inode *inode, const struct qstr *name) brelse(obh); return -ENOSPC; } - oleaf->lf_next = cpu_to_be64(bn); + oleaf->lf_next = cpu_to_be64(bh->b_blocknr); brelse(bh); brelse(obh); @@ -1950,8 +1950,7 @@ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip) * Returns: 1 if alloc required, 0 if not, -ve on error */ -int gfs2_diradd_alloc_required(struct inode *inode, - const struct qstr *name) +int gfs2_diradd_alloc_required(struct inode *inode, const struct qstr *name) { struct gfs2_dirent *dent; struct buffer_head *bh; From fe1bdedc6c16adedc6fd3636185ea91596b1d6eb Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 18 Apr 2006 10:09:15 -0400 Subject: [PATCH 077/292] [GFS2] Use vmalloc() in dir code When allocating memory to sort directory entries, use vmalloc() rather than kmalloc() since for larger directories, the required size can easily be graeter than the 128k maximum of kmalloc(). Also adding the first steps towards getting the AOP_TRUNCATED_PAGE return code get in the glock code by flagging all places where we request a glock and we are holding a page lock. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 5 +++-- fs/gfs2/glock.c | 3 +++ fs/gfs2/glock.h | 1 + fs/gfs2/incore.h | 2 +- fs/gfs2/meta_io.c | 2 +- fs/gfs2/ops_address.c | 4 ++-- fs/gfs2/ops_inode.c | 3 +-- fs/gfs2/ops_super.c | 2 -- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index fe6c5adc5df0..eb68cdd41d48 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -61,6 +61,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -1290,7 +1291,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque, return 0; error = -ENOMEM; - larr = kmalloc((leaves + entries) * sizeof(void*), GFP_KERNEL); + larr = vmalloc((leaves + entries) * sizeof(void*)); if (!larr) goto out; darr = (const struct gfs2_dirent **)(larr + leaves); @@ -1323,7 +1324,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque, out_kfree: for(i = 0; i < leaf; i++) brelse(larr[i]); - kfree(larr); + vfree(larr); out: return error; } diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 6a1b42cf4df4..4ed13787b7ec 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -461,6 +461,9 @@ static void handle_recurse(struct gfs2_holder *gh) struct gfs2_holder *tmp_gh, *safe; int found = 0; + printk(KERN_INFO "recursion %016llx, %u\n", gl->gl_name.ln_number, + gl->gl_name.ln_type); + if (gfs2_assert_warn(sdp, gh->gh_owner)) return; diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 560029de8d07..b6646e7fed15 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -27,6 +27,7 @@ #define GL_SYNC 0x00000800 #define GL_NOCANCEL 0x00001000 #define GL_NEVER_RECURSE 0x00002000 +#define GL_AOP 0x00004000 #define GLR_TRYFAILED 13 #define GLR_CANCELED 14 diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index dfed83b37ab7..761f00153d43 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -156,7 +156,7 @@ struct gfs2_holder { struct gfs2_glock *gh_gl; struct task_struct *gh_owner; unsigned int gh_state; - int gh_flags; + unsigned gh_flags; int gh_error; unsigned long gh_iflags; diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 4a6aacf294d5..74cf28e77b47 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -881,7 +881,7 @@ void gfs2_meta_syncfs(struct gfs2_sbd *sdp) gfs2_ail1_start(sdp, DIO_ALL); if (gfs2_ail1_empty(sdp, DIO_ALL)) break; - msleep(100); + msleep(10); } } diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 3fd8c6ec256c..005c2522a879 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -216,7 +216,7 @@ static int gfs2_readpage(struct file *file, struct page *page) int error; if (file != &gfs2_internal_file_sentinal) { - gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|GL_AOP, &gh); error = gfs2_glock_nq_m_atime(1, &gh); if (error) goto out_unlock; @@ -267,7 +267,7 @@ static int gfs2_prepare_write(struct file *file, struct page *page, loff_t end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to; struct gfs2_alloc *al; - gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ATIME, &ip->i_gh); + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ATIME|GL_AOP, &ip->i_gh); error = gfs2_glock_nq_m_atime(1, &ip->i_gh); if (error) goto out_uninit; diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 1e2b709711ae..62a12a59d91b 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -742,8 +742,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, if (error) goto out_gunlock_q; - error = gfs2_trans_begin(sdp, - sdp->sd_max_dirres + + error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + al->al_rgd->rd_ri.ri_length + 4 * RES_DINODE + 4 * RES_LEAF + RES_UNLINKED + RES_STATFS + diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 80ce40c1dfb6..60bf2563c7b4 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -132,9 +132,7 @@ static void gfs2_put_super(struct super_block *sb) /* At this point, we're through participating in the lockspace */ gfs2_sys_fs_del(sdp); - vfree(sdp); - sb->s_fs_info = NULL; } From 190562bd84a484bf6590425aa2bb4d6d611c112b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 20 Apr 2006 16:57:23 -0400 Subject: [PATCH 078/292] [GFS2] Fix a bug: scheduling under a spinlock At some stage, a mutex was added to gfs2_glock_put() without checking all its call sites. Two of them were called from under a spinlock causing random delays at various points and crashes. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 30 ++++++++++++++++++++---------- fs/gfs2/glock.h | 6 +++--- fs/gfs2/inode.c | 2 +- fs/gfs2/log.c | 1 + fs/gfs2/meta_io.c | 2 ++ 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 4ed13787b7ec..32cc4005307d 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -158,6 +158,7 @@ int gfs2_glock_put(struct gfs2_glock *gl) if (kref_put(&gl->gl_ref, kill_glock)) { list_del_init(&gl->gl_list); write_unlock(&bucket->hb_lock); + BUG_ON(spin_is_locked(&gl->gl_spin)); glock_free(gl); rv = 1; goto out; @@ -353,13 +354,14 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, * */ -void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, int flags, +void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags, struct gfs2_holder *gh) { + flags |= GL_NEVER_RECURSE; INIT_LIST_HEAD(&gh->gh_list); gh->gh_gl = gl; gh->gh_ip = (unsigned long)__builtin_return_address(0); - gh->gh_owner = (flags & GL_NEVER_RECURSE) ? NULL : current; + gh->gh_owner = current; gh->gh_state = state; gh->gh_flags = flags; gh->gh_error = 0; @@ -382,10 +384,10 @@ void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, int flags, * */ -void gfs2_holder_reinit(unsigned int state, int flags, struct gfs2_holder *gh) +void gfs2_holder_reinit(unsigned int state, unsigned flags, struct gfs2_holder *gh) { gh->gh_state = state; - gh->gh_flags = flags; + gh->gh_flags = flags | GL_NEVER_RECURSE; if (gh->gh_state == LM_ST_EXCLUSIVE) gh->gh_flags |= GL_LOCAL_EXCL; @@ -461,6 +463,8 @@ static void handle_recurse(struct gfs2_holder *gh) struct gfs2_holder *tmp_gh, *safe; int found = 0; + BUG_ON(!spin_is_locked(&gl->gl_spin)); + printk(KERN_INFO "recursion %016llx, %u\n", gl->gl_name.ln_number, gl->gl_name.ln_type); @@ -502,6 +506,8 @@ static void do_unrecurse(struct gfs2_holder *gh) struct gfs2_holder *tmp_gh, *last_gh = NULL; int found = 0; + BUG_ON(!spin_is_locked(&gl->gl_spin)); + if (gfs2_assert_warn(sdp, gh->gh_owner)) return; @@ -676,7 +682,6 @@ static int rq_greedy(struct gfs2_holder *gh) * @gl: the glock * */ - static void run_queue(struct gfs2_glock *gl) { struct gfs2_holder *gh; @@ -779,6 +784,7 @@ void gfs2_glmutex_unlock(struct gfs2_glock *gl) spin_lock(&gl->gl_spin); clear_bit(GLF_LOCK, &gl->gl_flags); run_queue(gl); + BUG_ON(!spin_is_locked(&gl->gl_spin)); spin_unlock(&gl->gl_spin); } @@ -1244,7 +1250,7 @@ static int recurse_check(struct gfs2_holder *existing, struct gfs2_holder *new, return 0; - fail: +fail: print_symbol(KERN_WARNING "GFS2: Existing holder from %s\n", existing->gh_ip); print_symbol(KERN_WARNING "GFS2: New holder from %s\n", new->gh_ip); @@ -1263,6 +1269,8 @@ static void add_to_queue(struct gfs2_holder *gh) struct gfs2_glock *gl = gh->gh_gl; struct gfs2_holder *existing; + BUG_ON(!gh->gh_owner); + if (!gh->gh_owner) goto out; @@ -1331,7 +1339,7 @@ int gfs2_glock_nq(struct gfs2_holder *gh) if (!(gh->gh_flags & GL_ASYNC)) { error = glock_wait_internal(gh); if (error == GLR_CANCELED) { - msleep(1000); + msleep(100); goto restart; } } @@ -1360,7 +1368,7 @@ int gfs2_glock_poll(struct gfs2_holder *gh) else if (list_empty(&gh->gh_list)) { if (gh->gh_error == GLR_CANCELED) { spin_unlock(&gl->gl_spin); - msleep(1000); + msleep(100); if (gfs2_glock_nq(gh)) return 1; return 0; @@ -1386,7 +1394,7 @@ int gfs2_glock_wait(struct gfs2_holder *gh) error = glock_wait_internal(gh); if (error == GLR_CANCELED) { - msleep(1000); + msleep(100); gh->gh_flags &= ~GL_ASYNC; error = gfs2_glock_nq(gh); } @@ -2217,10 +2225,12 @@ static void clear_glock(struct gfs2_glock *gl) if (!list_empty(&gl->gl_reclaim)) { list_del_init(&gl->gl_reclaim); atomic_dec(&sdp->sd_reclaim_count); + spin_unlock(&sdp->sd_reclaim_lock); released = gfs2_glock_put(gl); gfs2_assert(sdp, !released); + } else { + spin_unlock(&sdp->sd_reclaim_lock); } - spin_unlock(&sdp->sd_reclaim_lock); if (gfs2_glmutex_trylock(gl)) { if (gl->gl_ops == &gfs2_inode_glops) { diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index b6646e7fed15..ed5bc3e65397 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -81,10 +81,10 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, int create, struct gfs2_glock **glp); void gfs2_glock_hold(struct gfs2_glock *gl); int gfs2_glock_put(struct gfs2_glock *gl); - -void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, int flags, +void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags, struct gfs2_holder *gh); -void gfs2_holder_reinit(unsigned int state, int flags, struct gfs2_holder *gh); +void gfs2_holder_reinit(unsigned int state, unsigned flags, + struct gfs2_holder *gh); void gfs2_holder_uninit(struct gfs2_holder *gh); struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl, unsigned int state, int flags, gfp_t gfp_flags); diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 6140c2434e85..fb5a4d06e926 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -409,8 +409,8 @@ void gfs2_inode_destroy(struct gfs2_inode *ip) spin_lock(&io_gl->gl_spin); io_gl->gl_object = NULL; - gfs2_glock_put(i_gl); spin_unlock(&io_gl->gl_spin); + gfs2_glock_put(i_gl); gfs2_glock_dq_uninit(&ip->i_iopen_gh); diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index b0dd0b9ad79b..9e32e0faaf20 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -578,6 +578,7 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp) gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg); gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf); + gfs2_assert_withdraw(sdp, !sdp->sd_log_num_hdrs); gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list)); sdp->sd_log_flush_head = sdp->sd_log_head; diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 74cf28e77b47..da49973a90d1 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -214,6 +214,8 @@ void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) struct buffer_head *bh; int retry; + BUG_ON(!spin_is_locked(&sdp->sd_log_lock)); + do { retry = 0; From c63e31c2cc1ec67372920b5e1aff8204d04dd172 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 20 Apr 2006 17:03:48 -0400 Subject: [PATCH 079/292] [GFS2] journal recovery patch This is one of the changes related to journal recovery I mentioned a couple weeks ago. We can get into a situation where there are only readonly nodes currently mounting the fs, but there are journals that need to be recovered. Since the readonly nodes can't recover journals, the next rw mounter needs to go through and check all journals and recover any that are dirty (i.e. what the first node to mount the fs does). This rw mounter needs to skip the journals held by the existing readonly nodes. Skipping those journals amounts to using the TRY flag on the journal locks so acquiring the lock of a journal held by a readonly node will fail instead of blocking indefinately. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_fstype.c | 5 ++--- fs/gfs2/recovery.c | 13 +++++-------- fs/gfs2/recovery.h | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 4538a1e621e8..70745f3561a6 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -444,8 +444,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) if (sdp->sd_lockstruct.ls_first) { unsigned int x; for (x = 0; x < sdp->sd_journals; x++) { - error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x), - WAIT); + error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x)); if (error) { fs_err(sdp, "error recovering journal %u: %d\n", x, error); @@ -455,7 +454,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) gfs2_lm_others_may_mount(sdp); } else if (!sdp->sd_args.ar_spectator) { - error = gfs2_recover_journal(sdp->sd_jdesc, WAIT); + error = gfs2_recover_journal(sdp->sd_jdesc); if (error) { fs_err(sdp, "error recovering my journal: %d\n", error); goto fail_jinode_gh; diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 68c85610fb5b..e91c2bda6c32 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -418,7 +418,6 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) /** * gfs2_recover_journal - recovery a given journal * @jd: the struct gfs2_jdesc describing the journal - * @wait: Don't return until the journal is clean (or an error is encountered) * * Acquire the journal's lock, check to see if the journal is clean, and * do recovery if necessary. @@ -426,7 +425,7 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) * Returns: errno */ -int gfs2_recover_journal(struct gfs2_jdesc *jd, int wait) +int gfs2_recover_journal(struct gfs2_jdesc *jd) { struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; @@ -441,12 +440,10 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd, int wait) /* Aquire the journal lock so we can do recovery */ - error = gfs2_glock_nq_num(sdp, - jd->jd_jid, &gfs2_journal_glops, + error = gfs2_glock_nq_num(sdp, jd->jd_jid, &gfs2_journal_glops, LM_ST_EXCLUSIVE, - LM_FLAG_NOEXP | - ((wait) ? 0 : LM_FLAG_TRY) | - GL_NOCACHE, &j_gh); + LM_FLAG_NOEXP | LM_FLAG_TRY | GL_NOCACHE, + &j_gh); switch (error) { case 0: break; @@ -574,7 +571,7 @@ void gfs2_check_journals(struct gfs2_sbd *sdp) break; if (jd != sdp->sd_jdesc) - gfs2_recover_journal(jd, NO_WAIT); + gfs2_recover_journal(jd); } } diff --git a/fs/gfs2/recovery.h b/fs/gfs2/recovery.h index 50d7eb57881c..248481189300 100644 --- a/fs/gfs2/recovery.h +++ b/fs/gfs2/recovery.h @@ -25,7 +25,7 @@ void gfs2_revoke_clean(struct gfs2_sbd *sdp); int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header *head); -int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd, int wait); +int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd); void gfs2_check_journals(struct gfs2_sbd *sdp); #endif /* __RECOVERY_DOT_H__ */ From a74604bee27da7c9506114e5710f91f388e98296 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 21 Apr 2006 15:10:46 -0400 Subject: [PATCH 080/292] [GFS2] sem -> mutex conversion in locking.c Convert a semaphore to a mutex in locking.c and also tidy up one or two loose ends. Signed-off-by: Steven Whitehouse --- fs/gfs2/locking.c | 34 +++++++++++++++++----------------- fs/gfs2/log.c | 7 +++---- fs/gfs2/util.h | 1 - 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c index 0f4c50ebcbad..6a78aacb26af 100644 --- a/fs/gfs2/locking.c +++ b/fs/gfs2/locking.c @@ -28,7 +28,7 @@ struct lmh_wrapper { of them by name at mount time, e.g. lock_nolock, lock_dlm. */ static struct list_head lmh_list; -static struct semaphore lmh_lock; +static struct mutex lmh_lock; /** * gfs_register_lockproto - Register a low-level locking protocol @@ -41,11 +41,11 @@ int gfs_register_lockproto(struct lm_lockops *proto) { struct lmh_wrapper *lw; - down(&lmh_lock); + mutex_lock(&lmh_lock); list_for_each_entry(lw, &lmh_list, lw_list) { if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) { - up(&lmh_lock); + mutex_unlock(&lmh_lock); printk(KERN_INFO "GFS2: protocol %s already exists\n", proto->lm_proto_name); return -EEXIST; @@ -54,14 +54,14 @@ int gfs_register_lockproto(struct lm_lockops *proto) lw = kzalloc(sizeof(struct lmh_wrapper), GFP_KERNEL); if (!lw) { - up(&lmh_lock); + mutex_unlock(&lmh_lock); return -ENOMEM; } lw->lw_ops = proto; list_add(&lw->lw_list, &lmh_list); - up(&lmh_lock); + mutex_unlock(&lmh_lock); return 0; } @@ -76,18 +76,18 @@ void gfs_unregister_lockproto(struct lm_lockops *proto) { struct lmh_wrapper *lw; - down(&lmh_lock); + mutex_lock(&lmh_lock); list_for_each_entry(lw, &lmh_list, lw_list) { if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) { list_del(&lw->lw_list); - up(&lmh_lock); + mutex_unlock(&lmh_lock); kfree(lw); return; } } - up(&lmh_lock); + mutex_unlock(&lmh_lock); printk(KERN_WARNING "GFS2: can't unregister lock protocol %s\n", proto->lm_proto_name); @@ -118,7 +118,7 @@ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, int error, found; retry: - down(&lmh_lock); + mutex_lock(&lmh_lock); found = 0; list_for_each_entry(lw, &lmh_list, lw_list) { @@ -131,7 +131,7 @@ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, if (!found) { if (!try && capable(CAP_SYS_MODULE)) { try = 1; - up(&lmh_lock); + mutex_unlock(&lmh_lock); request_module(proto_name); goto retry; } @@ -142,7 +142,7 @@ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, if (!try_module_get(lw->lw_ops->lm_owner)) { try = 0; - up(&lmh_lock); + mutex_unlock(&lmh_lock); msleep(1000); goto retry; } @@ -152,17 +152,17 @@ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, if (error) module_put(lw->lw_ops->lm_owner); out: - up(&lmh_lock); + mutex_unlock(&lmh_lock); return error; } void gfs2_unmount_lockproto(struct lm_lockstruct *lockstruct) { - down(&lmh_lock); + mutex_lock(&lmh_lock); lockstruct->ls_ops->lm_unmount(lockstruct->ls_lockspace); if (lockstruct->ls_ops->lm_owner) module_put(lockstruct->ls_ops->lm_owner); - up(&lmh_lock); + mutex_unlock(&lmh_lock); } /** @@ -173,16 +173,16 @@ void gfs2_unmount_lockproto(struct lm_lockstruct *lockstruct) void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct) { - down(&lmh_lock); + mutex_lock(&lmh_lock); lockstruct->ls_ops->lm_withdraw(lockstruct->ls_lockspace); if (lockstruct->ls_ops->lm_owner) module_put(lockstruct->ls_ops->lm_owner); - up(&lmh_lock); + mutex_unlock(&lmh_lock); } void __init gfs2_init_lmh(void) { - init_MUTEX(&lmh_lock); + mutex_init(&lmh_lock); INIT_LIST_HEAD(&lmh_list); } diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 9e32e0faaf20..134fc57e21d3 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -587,10 +587,9 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp) log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT, 0); /* printk(KERN_INFO "sd_log_blks_free %u, sd_jdesc->jd_blocks %u\n", sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); */ - gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free == - sdp->sd_jdesc->jd_blocks); - gfs2_assert_withdraw(sdp, sdp->sd_log_head == sdp->sd_log_tail); - gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail2_list)); + gfs2_assert_warn(sdp, sdp->sd_log_blks_free == sdp->sd_jdesc->jd_blocks); + gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail); + gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list)); sdp->sd_log_head = sdp->sd_log_flush_head; sdp->sd_log_tail = sdp->sd_log_head; diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index 4532dbab0a2c..c9624c30cad6 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -30,7 +30,6 @@ void gfs2_assert_i(struct gfs2_sbd *sdp); do { \ if (unlikely(!(assertion))) { \ gfs2_assert_i(sdp); \ - BUG(); \ } \ } while (0) From 1dde2dbfc70001e2f86b6581baac2f48900b80ed Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 21 Apr 2006 15:39:02 -0400 Subject: [PATCH 081/292] [GFS2] Add back missing BUG() Signed-off-by: Steven Whitehouse --- fs/gfs2/util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 7cd9e25639c4..2fc110208d00 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -32,6 +32,7 @@ void gfs2_assert_i(struct gfs2_sbd *sdp) { printk(KERN_EMERG "GFS2: fsid=%s: fatal assertion failed\n", sdp->sd_fsname); + BUG(); } /** From 1e09ae544eb1a2d11b04c6924f738a310c7a7a2b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 21 Apr 2006 15:52:46 -0400 Subject: [PATCH 082/292] [GFS2] Move BUG() back into the header file In order to make the file and line number reporting work correctly, this has been moved back into the header file. Signed-off-by: Steven Whitehouse --- fs/gfs2/util.c | 1 - fs/gfs2/util.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 2fc110208d00..7cd9e25639c4 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -32,7 +32,6 @@ void gfs2_assert_i(struct gfs2_sbd *sdp) { printk(KERN_EMERG "GFS2: fsid=%s: fatal assertion failed\n", sdp->sd_fsname); - BUG(); } /** diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index c9624c30cad6..4532dbab0a2c 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -30,6 +30,7 @@ void gfs2_assert_i(struct gfs2_sbd *sdp); do { \ if (unlikely(!(assertion))) { \ gfs2_assert_i(sdp); \ + BUG(); \ } \ } while (0) From 61e085a88cb59232eb8ff5b446d70491c7bf2c68 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 24 Apr 2006 10:07:13 -0400 Subject: [PATCH 083/292] [GFS2] Tidy up dir code as per Christoph Hellwig's comments 1. Comment whitespace fix 2. Removed unused header files from dir.c 3. Split the gfs2_dir_get_buffer() function into two functions Cc: Christoph Hellwig Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 2 +- fs/gfs2/dir.c | 144 +++++++++++++++++++++++++------------------------ fs/gfs2/dir.h | 4 +- 3 files changed, 78 insertions(+), 72 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index c7723119acb6..68bc3be09c98 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -111,7 +111,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, if (isdir) { block = gfs2_alloc_meta(ip); - error = gfs2_dir_get_buffer(ip, block, 1, &bh); + error = gfs2_dir_get_new_buffer(ip, block, &bh); if (error) goto out_brelse; gfs2_buffer_copy_tail(bh, diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index eb68cdd41d48..ffc1beff6703 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -8,61 +8,59 @@ */ /* -* Implements Extendible Hashing as described in: -* "Extendible Hashing" by Fagin, et al in -* __ACM Trans. on Database Systems__, Sept 1979. -* -* -* Here's the layout of dirents which is essentially the same as that of ext2 -* within a single block. The field de_name_len is the number of bytes -* actually required for the name (no null terminator). The field de_rec_len -* is the number of bytes allocated to the dirent. The offset of the next -* dirent in the block is (dirent + dirent->de_rec_len). When a dirent is -* deleted, the preceding dirent inherits its allocated space, ie -* prev->de_rec_len += deleted->de_rec_len. Since the next dirent is obtained -* by adding de_rec_len to the current dirent, this essentially causes the -* deleted dirent to get jumped over when iterating through all the dirents. -* -* When deleting the first dirent in a block, there is no previous dirent so -* the field de_ino is set to zero to designate it as deleted. When allocating -* a dirent, gfs2_dirent_alloc iterates through the dirents in a block. If the -* first dirent has (de_ino == 0) and de_rec_len is large enough, this first -* dirent is allocated. Otherwise it must go through all the 'used' dirents -* searching for one in which the amount of total space minus the amount of -* used space will provide enough space for the new dirent. -* -* There are two types of blocks in which dirents reside. In a stuffed dinode, -* the dirents begin at offset sizeof(struct gfs2_dinode) from the beginning of -* the block. In leaves, they begin at offset sizeof(struct gfs2_leaf) from the -* beginning of the leaf block. The dirents reside in leaves when -* -* dip->i_di.di_flags & GFS2_DIF_EXHASH is true -* -* Otherwise, the dirents are "linear", within a single stuffed dinode block. -* -* When the dirents are in leaves, the actual contents of the directory file are -* used as an array of 64-bit block pointers pointing to the leaf blocks. The -* dirents are NOT in the directory file itself. There can be more than one block -* pointer in the array that points to the same leaf. In fact, when a directory -* is first converted from linear to exhash, all of the pointers point to the -* same leaf. -* -* When a leaf is completely full, the size of the hash table can be -* doubled unless it is already at the maximum size which is hard coded into -* GFS2_DIR_MAX_DEPTH. After that, leaves are chained together in a linked list, -* but never before the maximum hash table size has been reached. -*/ + * Implements Extendible Hashing as described in: + * "Extendible Hashing" by Fagin, et al in + * __ACM Trans. on Database Systems__, Sept 1979. + * + * + * Here's the layout of dirents which is essentially the same as that of ext2 + * within a single block. The field de_name_len is the number of bytes + * actually required for the name (no null terminator). The field de_rec_len + * is the number of bytes allocated to the dirent. The offset of the next + * dirent in the block is (dirent + dirent->de_rec_len). When a dirent is + * deleted, the preceding dirent inherits its allocated space, ie + * prev->de_rec_len += deleted->de_rec_len. Since the next dirent is obtained + * by adding de_rec_len to the current dirent, this essentially causes the + * deleted dirent to get jumped over when iterating through all the dirents. + * + * When deleting the first dirent in a block, there is no previous dirent so + * the field de_ino is set to zero to designate it as deleted. When allocating + * a dirent, gfs2_dirent_alloc iterates through the dirents in a block. If the + * first dirent has (de_ino == 0) and de_rec_len is large enough, this first + * dirent is allocated. Otherwise it must go through all the 'used' dirents + * searching for one in which the amount of total space minus the amount of + * used space will provide enough space for the new dirent. + * + * There are two types of blocks in which dirents reside. In a stuffed dinode, + * the dirents begin at offset sizeof(struct gfs2_dinode) from the beginning of + * the block. In leaves, they begin at offset sizeof(struct gfs2_leaf) from the + * beginning of the leaf block. The dirents reside in leaves when + * + * dip->i_di.di_flags & GFS2_DIF_EXHASH is true + * + * Otherwise, the dirents are "linear", within a single stuffed dinode block. + * + * When the dirents are in leaves, the actual contents of the directory file are + * used as an array of 64-bit block pointers pointing to the leaf blocks. The + * dirents are NOT in the directory file itself. There can be more than one + * block pointer in the array that points to the same leaf. In fact, when a + * directory is first converted from linear to exhash, all of the pointers + * point to the same leaf. + * + * When a leaf is completely full, the size of the hash table can be + * doubled unless it is already at the maximum size which is hard coded into + * GFS2_DIR_MAX_DEPTH. After that, leaves are chained together in a linked list, + * but never before the maximum hash table size has been reached. + */ #include #include #include -#include #include #include #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" @@ -92,33 +90,36 @@ typedef int (*leaf_call_t) (struct gfs2_inode *dip, uint32_t index, uint32_t len, uint64_t leaf_no, void *data); -int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, - struct buffer_head **bhp) + +int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, uint64_t block, + struct buffer_head **bhp) { struct buffer_head *bh; - int error = 0; - - if (new) { - bh = gfs2_meta_new(ip->i_gl, block); - gfs2_trans_add_bh(ip->i_gl, bh, 1); - gfs2_metatype_set(bh, GFS2_METATYPE_JD, GFS2_FORMAT_JD); - gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); - } else { - error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT, - &bh); - if (error) - return error; - if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_JD)) { - brelse(bh); - return -EIO; - } - } + bh = gfs2_meta_new(ip->i_gl, block); + gfs2_trans_add_bh(ip->i_gl, bh, 1); + gfs2_metatype_set(bh, GFS2_METATYPE_JD, GFS2_FORMAT_JD); + gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); *bhp = bh; return 0; } +static int gfs2_dir_get_existing_buffer(struct gfs2_inode *ip, uint64_t block, + struct buffer_head **bhp) +{ + struct buffer_head *bh; + int error; + error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT, &bh); + if (error) + return error; + if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_JD)) { + brelse(bh); + return -EIO; + } + *bhp = bh; + return 0; +} static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf, unsigned int offset, unsigned int size) @@ -205,9 +206,11 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, goto fail; } - error = gfs2_dir_get_buffer(ip, dblock, - (amount == sdp->sd_jbsize) ? - 1 : new, &bh); + if (amount == sdp->sd_jbsize || new) + error = gfs2_dir_get_new_buffer(ip, dblock, &bh); + else + error = gfs2_dir_get_existing_buffer(ip, dblock, &bh); + if (error) goto fail; @@ -321,7 +324,10 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, gfs2_meta_ra(ip->i_gl, dblock, extlen); if (dblock) { - error = gfs2_dir_get_buffer(ip, dblock, new, &bh); + if (new) + error = gfs2_dir_get_new_buffer(ip, dblock, &bh); + else + error = gfs2_dir_get_existing_buffer(ip, dblock, &bh); if (error) goto fail; dblock++; diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h index 42b3a1f34deb..d209f1fcb8ac 100644 --- a/fs/gfs2/dir.h +++ b/fs/gfs2/dir.h @@ -41,8 +41,8 @@ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip); int gfs2_diradd_alloc_required(struct inode *dir, const struct qstr *filename); -int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new, - struct buffer_head **bhp); +int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, uint64_t block, + struct buffer_head **bhp); static inline uint32_t gfs2_disk_hash(const char *data, int len) { From b800a1cb3940f216c4e5c963007a1f72fca0f15f Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 24 Apr 2006 13:13:56 -0400 Subject: [PATCH 084/292] [GFS2] Tidy up daemon.c As per Andrew Morton's comments, remove uneeded casts and use wait_event_interruptible() rather than open code the wait. Cc: Andrew Morton Signed-off-by: Steven Whitehouse --- fs/gfs2/daemon.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c index b3830b92d78c..c2b5d69044c6 100644 --- a/fs/gfs2/daemon.c +++ b/fs/gfs2/daemon.c @@ -45,7 +45,7 @@ int gfs2_scand(void *data) { - struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + struct gfs2_sbd *sdp = data; unsigned long t; while (!kthread_should_stop()) { @@ -67,20 +67,15 @@ int gfs2_scand(void *data) int gfs2_glockd(void *data) { - struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; - DECLARE_WAITQUEUE(wait_chan, current); + struct gfs2_sbd *sdp = data; while (!kthread_should_stop()) { while (atomic_read(&sdp->sd_reclaim_count)) gfs2_reclaim_glock(sdp); - set_current_state(TASK_INTERRUPTIBLE); - add_wait_queue(&sdp->sd_reclaim_wq, &wait_chan); - if (!atomic_read(&sdp->sd_reclaim_count) && - !kthread_should_stop()) - schedule(); - remove_wait_queue(&sdp->sd_reclaim_wq, &wait_chan); - set_current_state(TASK_RUNNING); + wait_event_interruptible(sdp->sd_reclaim_wq, + (atomic_read(&sdp->sd_reclaim_count) || + kthread_should_stop())); } return 0; @@ -94,7 +89,7 @@ int gfs2_glockd(void *data) int gfs2_recoverd(void *data) { - struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + struct gfs2_sbd *sdp = data; unsigned long t; while (!kthread_should_stop()) { @@ -116,7 +111,7 @@ int gfs2_recoverd(void *data) int gfs2_logd(void *data) { - struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + struct gfs2_sbd *sdp = data; struct gfs2_holder ji_gh; unsigned long t; @@ -159,7 +154,7 @@ int gfs2_logd(void *data) int gfs2_quotad(void *data) { - struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + struct gfs2_sbd *sdp = data; unsigned long t; int error; @@ -209,7 +204,7 @@ int gfs2_quotad(void *data) int gfs2_inoded(void *data) { - struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; + struct gfs2_sbd *sdp = data; unsigned long t; int error; From b5ea3e1ef307548bdd40fff6aba5fc96b002f284 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 24 Apr 2006 14:14:42 -0400 Subject: [PATCH 085/292] [GFS2] Tidy up Makefile & Kconfig Remove select of SYSFS as requested by Greg KH. Change whitespace to tabs rather than spaces in places where it was incorrect and removed 'default m' as suggested by Adrian Bunk. Reorganised Makefile as suggested by Sam Ravnborg. Cc: Sam Ravnborg Cc: Adrian Bunk Cc: Greg KH Signed-off-by: Steven Whitehouse --- fs/gfs2/Kconfig | 24 +++++++++++------------- fs/gfs2/Makefile | 42 +++++------------------------------------- 2 files changed, 16 insertions(+), 50 deletions(-) diff --git a/fs/gfs2/Kconfig b/fs/gfs2/Kconfig index 17cb44bea1c0..115f30d8c22e 100644 --- a/fs/gfs2/Kconfig +++ b/fs/gfs2/Kconfig @@ -1,19 +1,17 @@ config GFS2_FS - tristate "GFS2 file system support" - default m + tristate "GFS2 file system support" depends on EXPERIMENTAL - select FS_POSIX_ACL - select SYSFS - help - A cluster filesystem. + select FS_POSIX_ACL + help + A cluster filesystem. - Allows a cluster of computers to simultaneously use a block device - that is shared between them (with FC, iSCSI, NBD, etc...). GFS reads - and writes to the block device like a local filesystem, but also uses - a lock module to allow the computers coordinate their I/O so - filesystem consistency is maintained. One of the nifty features of - GFS is perfect consistency -- changes made to the filesystem on one - machine show up immediately on all other machines in the cluster. + Allows a cluster of computers to simultaneously use a block device + that is shared between them (with FC, iSCSI, NBD, etc...). GFS reads + and writes to the block device like a local filesystem, but also uses + a lock module to allow the computers coordinate their I/O so + filesystem consistency is maintained. One of the nifty features of + GFS is perfect consistency -- changes made to the filesystem on one + machine show up immediately on all other machines in the cluster. To use the GFS2 filesystem, you will need to enable one or more of the below locking modules. Documentation and utilities for GFS2 can diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile index 88f927948113..66de2cc7bb5a 100644 --- a/fs/gfs2/Makefile +++ b/fs/gfs2/Makefile @@ -1,41 +1,9 @@ obj-$(CONFIG_GFS2_FS) += gfs2.o -gfs2-y := \ - acl.o \ - bits.o \ - bmap.o \ - daemon.o \ - dir.o \ - eaops.o \ - eattr.o \ - glock.o \ - glops.o \ - inode.o \ - lm.o \ - log.o \ - lops.o \ - locking.o \ - lvb.o \ - main.o \ - meta_io.o \ - mount.o \ - ondisk.o \ - ops_address.o \ - ops_dentry.o \ - ops_export.o \ - ops_file.o \ - ops_fstype.o \ - ops_inode.o \ - ops_super.o \ - ops_vm.o \ - page.o \ - quota.o \ - recovery.o \ - rgrp.o \ - super.o \ - sys.o \ - trans.o \ - unlinked.o \ - util.o +gfs2-y := acl.o bits.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \ + glops.o inode.o lm.o log.o lops.o locking.o lvb.o main.o meta_io.o \ + mount.o ondisk.o ops_address.o ops_dentry.o ops_export.o ops_file.o \ + ops_fstype.o ops_inode.o ops_super.o ops_vm.o page.o quota.o \ + recovery.o rgrp.o super.o sys.o trans.o unlinked.o util.o obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += locking/nolock/ obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += locking/dlm/ From 4bcf7091f9da595016f9d1175aa1bea8e736566f Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 25 Apr 2006 13:20:27 -0400 Subject: [PATCH 086/292] [GFS2] Remove inherited flags from exported flags. We don't need the inherited flags since this action can be implied by setting the flags on directories where they wouldn't otherwise make sense. It reduces the number of extra flags by two. Also updated the list of flags to take account of one extra ext2/3 flag. Cc: Andreas Dilger Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 23 +++++++++-------------- include/linux/iflags.h | 10 ++++------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 3fb1a29f88a6..c2dbc300a50c 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -545,8 +545,6 @@ static const u32 iflags_to_gfs2[32] = { [iflag_Index] = GFS2_DIF_EXHASH, [iflag_JournalData] = GFS2_DIF_JDATA, [iflag_DirectIO] = GFS2_DIF_DIRECTIO, - [iflag_InheritDirectIO] = GFS2_DIF_INHERIT_DIRECTIO, - [iflag_InheritJdata] = GFS2_DIF_INHERIT_JDATA, }; static const u32 gfs2_to_iflags[32] = { @@ -557,8 +555,8 @@ static const u32 gfs2_to_iflags[32] = { [gfs2fl_ExHash] = IFLAG_INDEX, [gfs2fl_Jdata] = IFLAG_JOURNAL_DATA, [gfs2fl_Directio] = IFLAG_DIRECTIO, - [gfs2fl_InheritDirectio] = IFLAG_INHERITDIRECTIO, - [gfs2fl_InheritJdata] = IFLAG_INHERITJDATA, + [gfs2fl_InheritDirectio] = IFLAG_DIRECTIO, + [gfs2fl_InheritJdata] = IFLAG_JOURNAL_DATA, }; static int gfs2_get_flags(struct file *filp, u32 __user *ptr) @@ -621,20 +619,17 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) if ((new_flags ^ flags) == 0) goto out; + if (S_ISDIR(inode->i_mode)) { + if ((new_flags ^ flags) & GFS2_DIF_JDATA) + new_flags ^= (GFS2_DIF_JDATA|GFS2_DIF_INHERIT_JDATA); + if ((new_flags ^ flags) & GFS2_DIF_DIRECTIO) + new_flags ^= (GFS2_DIF_DIRECTIO|GFS2_DIF_INHERIT_DIRECTIO); + } + error = -EINVAL; if ((new_flags ^ flags) & ~GFS2_FLAGS_USER_SET) goto out; - if (S_ISDIR(inode->i_mode)) { - if ((new_flags ^ flags) & (GFS2_DIF_JDATA | GFS2_DIF_DIRECTIO)) - goto out; - } else if (S_ISREG(inode->i_mode)) { - if ((new_flags ^ flags) & (GFS2_DIF_INHERIT_DIRECTIO| - GFS2_DIF_INHERIT_JDATA)) - goto out; - } else - goto out; - error = -EPERM; if (IS_IMMUTABLE(inode) && (new_flags & GFS2_DIF_IMMUTABLE)) goto out; diff --git a/include/linux/iflags.h b/include/linux/iflags.h index 1b4d9ef5d62b..5b27102dfeaf 100644 --- a/include/linux/iflags.h +++ b/include/linux/iflags.h @@ -46,9 +46,8 @@ enum { iflag_NoTail = 15, /* file tail should not be merged */ iflag_DirSync = 16, /* dirsync behaviour */ iflag_TopDir = 17, /* Top of directory hierarchies */ - iflag_DirectIO = 18, /* Always use direct I/O on this file */ - iflag_InheritDirectIO = 19, /* Set DirectIO on new files in dir */ - iflag_InheritJdata = 20, /* Set JournalData on create in dir */ + iflag_Extent = 19, /* Extents */ + iflag_DirectIO = 20, /* Always use direct I/O on this file */ iflag_Reserved = 31 /* reserved for ext2/3 lib */ }; @@ -72,9 +71,8 @@ enum { #define IFLAG_NOTAIL __IFL(NoTail) /* 0x00008000 */ #define IFLAG_DIRSYNC __IFL(DirSync) /* 0x00010000 */ #define IFLAG_TOPDIR __IFL(TopDir) /* 0x00020000 */ -#define IFLAG_DIRECTIO __IFL(DirectIO) /* 0x00040000 */ -#define IFLAG_INHERITDIRECTIO __IFL(InheritDirectIO) /* 0x00080000 */ -#define IFLAG_INHERITJDATA __IFL(InheritJdata) /* 0x00100000 */ +#define IFLAG_EXTENT __IFL(Extent) /* 0x00080000 */ +#define IFLAG_DIRECTIO __IFL(DirectIO) /* 0x00100000 */ #define IFLAG_RESERVED __IFL(Reserved) /* 0x80000000 */ #ifdef __KERNEL__ From 96c2c0083d76ca80d546a53089c86e74fbfbe791 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 25 Apr 2006 13:23:09 -0400 Subject: [PATCH 087/292] [DLM] Update Kconfig in the light of comments on lkml We now depend on user selectable options rather than select them. There is no dependancy on SYSFS since this selection is independant of the DLM (even though it wouldn't be sensible to build the DLM without it) Signed-off-by: Steven Whitehouse --- fs/dlm/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/dlm/Kconfig b/fs/dlm/Kconfig index d01f735e6e06..09e78bf6e7a4 100644 --- a/fs/dlm/Kconfig +++ b/fs/dlm/Kconfig @@ -3,9 +3,8 @@ menu "Distributed Lock Manager" config DLM tristate "Distributed Lock Manager (DLM)" - depends on SYSFS depends on IPV6 || IPV6=n - select IP_SCTP + depends on IP_SCTP select CONFIGFS_FS help A general purpose distributed lock manager for kernel or userspace From 714dc65c34385afbc21342f5bee8d0d25027ac9a Mon Sep 17 00:00:00 2001 From: Patrick Caulfield Date: Tue, 25 Apr 2006 14:49:01 -0400 Subject: [PATCH 088/292] [DLM] Convert a semaphore to a completion Convert a semaphore into a completion in device.c. Cc: David Teigland Cc: Andrew Morton Signed-off-by: Patrick Caulfield Signed-off-by: Steven Whitehouse --- fs/dlm/device.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/fs/dlm/device.c b/fs/dlm/device.c index 99d8b6b07fba..5da4b2ed988d 100644 --- a/fs/dlm/device.c +++ b/fs/dlm/device.c @@ -79,7 +79,7 @@ struct lock_info { struct list_head li_ownerqueue; struct file_info *li_file; struct dlm_lksb __user *li_user_lksb; - struct semaphore li_firstlock; + struct completion li_firstcomp; }; /* A queued AST no less */ @@ -376,8 +376,7 @@ static void ast_routine(void *param) li->li_lksb.sb_status != 0) { /* Wait till dlm_lock() has finished */ - down(&li->li_firstlock); - up(&li->li_firstlock); + wait_for_completion(&li->li_firstcomp); spin_lock(&li->li_file->fi_li_lock); list_del(&li->li_ownerqueue); @@ -808,10 +807,10 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, li->li_castaddr = kparams->castaddr; li->li_castparam = kparams->castparam; - /* OK, this isn;t exactly a FIRSTLOCK but it is the + /* OK, this isn't exactly a FIRSTLOCK but it is the first time we've used this lockinfo, and if things fail we want rid of it */ - init_MUTEX_LOCKED(&li->li_firstlock); + init_completion(&li->li_firstcomp); set_bit(LI_FLAG_FIRSTLOCK, &li->li_flags); add_lockinfo(li); @@ -839,10 +838,10 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, if (!li) return -ENOMEM; - /* semaphore to allow us to complete our work before + /* Allow us to complete our work before the AST routine runs. In fact we only need (and use) this when the initial lock fails */ - init_MUTEX_LOCKED(&li->li_firstlock); + init_completion(&li->li_firstcomp); set_bit(LI_FLAG_FIRSTLOCK, &li->li_flags); } @@ -892,7 +891,7 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, if (add_lockinfo(li)) printk(KERN_WARNING "Add lockinfo failed\n"); - up(&li->li_firstlock); + complete(&li->li_firstcomp); } /* Return the lockid as the user needs it /now/ */ @@ -936,8 +935,7 @@ static int do_user_unlock(struct file_info *fi, uint8_t cmd, /* Wait until dlm_lock() has completed */ if (!test_bit(LI_FLAG_ONLIST, &li->li_flags)) { - down(&li->li_firstlock); - up(&li->li_firstlock); + wait_for_completion(&li->li_firstcomp); } /* dlm_unlock() passes a 0 for castaddr which means don't overwrite From 373b5a453255b6a013b9d20116918f09a1ceeccc Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 25 Apr 2006 15:44:04 -0400 Subject: [PATCH 089/292] [GFS2] Update documentation Updated information on the GFS2 tools Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- Documentation/filesystems/gfs2.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Documentation/filesystems/gfs2.txt b/Documentation/filesystems/gfs2.txt index a20ba19e9fe5..593004b6bbab 100644 --- a/Documentation/filesystems/gfs2.txt +++ b/Documentation/filesystems/gfs2.txt @@ -34,11 +34,10 @@ needed, simply: GFS2 is not on-disk compatible with previous versions of GFS. The following man pages can be found at the URL above: - gfs2_mkfs to make a filesystem gfs2_fsck to repair a filesystem gfs2_grow to expand a filesystem online gfs2_jadd to add journals to a filesystem online gfs2_tool to manipulate, examine and tune a filesystem gfs2_quota to examine and change quota values in a filesystem - mount.gfs2 to find mount options - + mount.gfs2 to help mount(8) mount a filesystem + mkfs.gfs2 to make a filesystem From 3a2a9c96ac129d17aad1a5c46988ad28f72564b0 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 25 Apr 2006 15:45:51 -0400 Subject: [PATCH 090/292] [GFS2] Update plock code in DLM locking module We should be using fl_pid not fl_owner. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/plock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c index f7ac5821def9..86312d96147b 100644 --- a/fs/gfs2/locking/dlm/plock.c +++ b/fs/gfs2/locking/dlm/plock.c @@ -70,7 +70,7 @@ int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, return -ENOMEM; op->info.optype = GDLM_PLOCK_OP_LOCK; - op->info.pid = (uint32_t) fl->fl_owner; + op->info.pid = fl->fl_pid; op->info.ex = (fl->fl_type == F_WRLCK); op->info.wait = IS_SETLKW(cmd); op->info.fsid = ls->id; @@ -116,7 +116,7 @@ int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, name->ln_type, name->ln_number); op->info.optype = GDLM_PLOCK_OP_UNLOCK; - op->info.pid = (uint32_t) fl->fl_owner; + op->info.pid = fl->fl_pid; op->info.fsid = ls->id; op->info.number = name->ln_number; op->info.start = fl->fl_start; @@ -150,7 +150,7 @@ int gdlm_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, return -ENOMEM; op->info.optype = GDLM_PLOCK_OP_GET; - op->info.pid = (uint32_t) fl->fl_owner; + op->info.pid = fl->fl_pid; op->info.ex = (fl->fl_type == F_WRLCK); op->info.fsid = ls->id; op->info.number = name->ln_number; From 5965b1f4792a1a9364b4e1ed6be8778a50eb981b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 26 Apr 2006 13:21:55 -0400 Subject: [PATCH 091/292] [GFS2] Don't do recursive locking in glock layer This patch changes the last user of recursive locking so that it no longer needs this feature and removes it from the glock layer. This makes the glock code a lot simpler and easier to understand. Its also a prerequsite to adding support for the AOP_TRUNCATED_PAGE return code (or at least it is if you don't want your brain to melt in the process) I've left in a couple of checks just in case there is some place else in the code which is still using this feature that I didn't spot yet, but they can probably be removed long term. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 162 ++------------------------------------------- fs/gfs2/incore.h | 1 - fs/gfs2/recovery.c | 79 +++++++++++----------- 3 files changed, 46 insertions(+), 196 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 32cc4005307d..0f317155915d 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -449,86 +449,6 @@ void gfs2_holder_put(struct gfs2_holder *gh) kfree(gh); } -/** - * handle_recurse - put other holder structures (marked recursive) - * into the holders list - * @gh: the holder structure - * - */ - -static void handle_recurse(struct gfs2_holder *gh) -{ - struct gfs2_glock *gl = gh->gh_gl; - struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_holder *tmp_gh, *safe; - int found = 0; - - BUG_ON(!spin_is_locked(&gl->gl_spin)); - - printk(KERN_INFO "recursion %016llx, %u\n", gl->gl_name.ln_number, - gl->gl_name.ln_type); - - if (gfs2_assert_warn(sdp, gh->gh_owner)) - return; - - list_for_each_entry_safe(tmp_gh, safe, &gl->gl_waiters3, gh_list) { - if (tmp_gh->gh_owner != gh->gh_owner) - continue; - - gfs2_assert_warn(sdp, - test_bit(HIF_RECURSE, &tmp_gh->gh_iflags)); - - list_move_tail(&tmp_gh->gh_list, &gl->gl_holders); - tmp_gh->gh_error = 0; - set_bit(HIF_HOLDER, &tmp_gh->gh_iflags); - - complete(&tmp_gh->gh_wait); - - found = 1; - } - - gfs2_assert_warn(sdp, found); -} - -/** - * do_unrecurse - a recursive holder was just dropped of the waiters3 list - * @gh: the holder - * - * If there is only one other recursive holder, clear its HIF_RECURSE bit. - * If there is more than one, leave them alone. - * - */ - -static void do_unrecurse(struct gfs2_holder *gh) -{ - struct gfs2_glock *gl = gh->gh_gl; - struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_holder *tmp_gh, *last_gh = NULL; - int found = 0; - - BUG_ON(!spin_is_locked(&gl->gl_spin)); - - if (gfs2_assert_warn(sdp, gh->gh_owner)) - return; - - list_for_each_entry(tmp_gh, &gl->gl_waiters3, gh_list) { - if (tmp_gh->gh_owner != gh->gh_owner) - continue; - - gfs2_assert_warn(sdp, - test_bit(HIF_RECURSE, &tmp_gh->gh_iflags)); - - if (found) - return; - - found = 1; - last_gh = tmp_gh; - } - - if (!gfs2_assert_warn(sdp, found)) - clear_bit(HIF_RECURSE, &last_gh->gh_iflags); -} - /** * rq_mutex - process a mutex request in the queue * @gh: the glock holder @@ -562,7 +482,6 @@ static int rq_promote(struct gfs2_holder *gh) struct gfs2_glock *gl = gh->gh_gl; struct gfs2_sbd *sdp = gl->gl_sbd; struct gfs2_glock_operations *glops = gl->gl_ops; - int recurse; if (!relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) { if (list_empty(&gl->gl_holders)) { @@ -588,7 +507,6 @@ static int rq_promote(struct gfs2_holder *gh) if (list_empty(&gl->gl_holders)) { set_bit(HIF_FIRST, &gh->gh_iflags); set_bit(GLF_LOCK, &gl->gl_flags); - recurse = 0; } else { struct gfs2_holder *next_gh; if (gh->gh_flags & GL_LOCAL_EXCL) @@ -597,16 +515,12 @@ static int rq_promote(struct gfs2_holder *gh) gh_list); if (next_gh->gh_flags & GL_LOCAL_EXCL) return 1; - recurse = test_bit(HIF_RECURSE, &gh->gh_iflags); } list_move_tail(&gh->gh_list, &gl->gl_holders); gh->gh_error = 0; set_bit(HIF_HOLDER, &gh->gh_iflags); - if (recurse) - handle_recurse(gh); - complete(&gh->gh_wait); return 0; @@ -897,8 +811,6 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret) spin_lock(&gl->gl_spin); list_del_init(&gh->gh_list); gh->gh_error = -EIO; - if (test_bit(HIF_RECURSE, &gh->gh_iflags)) - do_unrecurse(gh); spin_unlock(&gl->gl_spin); } else if (test_bit(HIF_DEMOTE, &gh->gh_iflags)) { @@ -922,8 +834,6 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret) spin_lock(&gl->gl_spin); list_del_init(&gh->gh_list); gh->gh_error = GLR_CANCELED; - if (test_bit(HIF_RECURSE, &gh->gh_iflags)) - do_unrecurse(gh); spin_unlock(&gl->gl_spin); } else if (relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) { @@ -941,8 +851,6 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret) spin_lock(&gl->gl_spin); list_del_init(&gh->gh_list); gh->gh_error = GLR_TRYFAILED; - if (test_bit(HIF_RECURSE, &gh->gh_iflags)) - do_unrecurse(gh); spin_unlock(&gl->gl_spin); } else { @@ -1161,8 +1069,6 @@ static int glock_wait_internal(struct gfs2_holder *gh) !list_empty(&gh->gh_list)) { list_del_init(&gh->gh_list); gh->gh_error = GLR_TRYFAILED; - if (test_bit(HIF_RECURSE, &gh->gh_iflags)) - do_unrecurse(gh); run_queue(gl); spin_unlock(&gl->gl_spin); return gh->gh_error; @@ -1191,9 +1097,6 @@ static int glock_wait_internal(struct gfs2_holder *gh) if (gh->gh_error) { spin_lock(&gl->gl_spin); list_del_init(&gh->gh_list); - if (test_and_clear_bit(HIF_RECURSE, - &gh->gh_iflags)) - do_unrecurse(gh); spin_unlock(&gl->gl_spin); } } @@ -1202,8 +1105,6 @@ static int glock_wait_internal(struct gfs2_holder *gh) gl->gl_req_gh = NULL; gl->gl_req_bh = NULL; clear_bit(GLF_LOCK, &gl->gl_flags); - if (test_bit(HIF_RECURSE, &gh->gh_iflags)) - handle_recurse(gh); run_queue(gl); spin_unlock(&gl->gl_spin); } @@ -1224,40 +1125,6 @@ find_holder_by_owner(struct list_head *head, struct task_struct *owner) return NULL; } -/** - * recurse_check - - * - * Make sure the new holder is compatible with the pre-existing one. - * - */ - -static int recurse_check(struct gfs2_holder *existing, struct gfs2_holder *new, - unsigned int state) -{ - struct gfs2_sbd *sdp = existing->gh_gl->gl_sbd; - - if (gfs2_assert_warn(sdp, (new->gh_flags & LM_FLAG_ANY) || - !(existing->gh_flags & LM_FLAG_ANY))) - goto fail; - - if (gfs2_assert_warn(sdp, (existing->gh_flags & GL_LOCAL_EXCL) || - !(new->gh_flags & GL_LOCAL_EXCL))) - goto fail; - - if (gfs2_assert_warn(sdp, relaxed_state_ok(state, new->gh_state, - new->gh_flags))) - goto fail; - - return 0; - -fail: - print_symbol(KERN_WARNING "GFS2: Existing holder from %s\n", - existing->gh_ip); - print_symbol(KERN_WARNING "GFS2: New holder from %s\n", new->gh_ip); - set_bit(HIF_ABORTED, &new->gh_iflags); - return -EINVAL; -} - /** * add_to_queue - Add a holder to the wait queue (but look for recursion) * @gh: the holder structure to add @@ -1271,37 +1138,20 @@ static void add_to_queue(struct gfs2_holder *gh) BUG_ON(!gh->gh_owner); - if (!gh->gh_owner) - goto out; - existing = find_holder_by_owner(&gl->gl_holders, gh->gh_owner); if (existing) { - if (recurse_check(existing, gh, gl->gl_state)) - return; - - list_add_tail(&gh->gh_list, &gl->gl_holders); - set_bit(HIF_HOLDER, &gh->gh_iflags); - - gh->gh_error = 0; - complete(&gh->gh_wait); - - return; + print_symbol(KERN_WARNING "original: %s\n", existing->gh_ip); + print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip); + BUG(); } existing = find_holder_by_owner(&gl->gl_waiters3, gh->gh_owner); if (existing) { - if (recurse_check(existing, gh, existing->gh_state)) - return; - - set_bit(HIF_RECURSE, &gh->gh_iflags); - set_bit(HIF_RECURSE, &existing->gh_iflags); - - list_add_tail(&gh->gh_list, &gl->gl_waiters3); - - return; + print_symbol(KERN_WARNING "original: %s\n", existing->gh_ip); + print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip); + BUG(); } - out: if (gh->gh_flags & LM_FLAG_PRIORITY) list_add(&gh->gh_list, &gl->gl_waiters3); else diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 761f00153d43..84dd2f579e62 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -146,7 +146,6 @@ enum { HIF_DEALLOC = 5, HIF_HOLDER = 6, HIF_FIRST = 7, - HIF_RECURSE = 8, HIF_ABORTED = 9, }; diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index e91c2bda6c32..7d467966f92c 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -436,30 +436,35 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd) unsigned int pass; int error; - fs_info(sdp, "jid=%u: Trying to acquire journal lock...\n", jd->jd_jid); + if (jd->jd_jid != sdp->sd_lockstruct.ls_jid) { + fs_info(sdp, "jid=%u: Trying to acquire journal lock...\n", + jd->jd_jid); - /* Aquire the journal lock so we can do recovery */ + /* Aquire the journal lock so we can do recovery */ - error = gfs2_glock_nq_num(sdp, jd->jd_jid, &gfs2_journal_glops, - LM_ST_EXCLUSIVE, - LM_FLAG_NOEXP | LM_FLAG_TRY | GL_NOCACHE, - &j_gh); - switch (error) { - case 0: - break; + error = gfs2_glock_nq_num(sdp, jd->jd_jid, &gfs2_journal_glops, + LM_ST_EXCLUSIVE, + LM_FLAG_NOEXP | LM_FLAG_TRY | GL_NOCACHE, + &j_gh); + switch (error) { + case 0: + break; + + case GLR_TRYFAILED: + fs_info(sdp, "jid=%u: Busy\n", jd->jd_jid); + error = 0; + + default: + goto fail; + }; - case GLR_TRYFAILED: - fs_info(sdp, "jid=%u: Busy\n", jd->jd_jid); - error = 0; - - default: - goto fail; - }; - - error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, - LM_FLAG_NOEXP, &ji_gh); - if (error) - goto fail_gunlock_j; + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, + LM_FLAG_NOEXP, &ji_gh); + if (error) + goto fail_gunlock_j; + } else { + fs_info(sdp, "jid=%u, already locked for use\n", jd->jd_jid); + } fs_info(sdp, "jid=%u: Looking at journal...\n", jd->jd_jid); @@ -481,10 +486,8 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd) error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, - LM_FLAG_NOEXP | - LM_FLAG_PRIORITY | - GL_NEVER_RECURSE | - GL_NOCANCEL | + LM_FLAG_NOEXP | LM_FLAG_PRIORITY | + GL_NEVER_RECURSE | GL_NOCANCEL | GL_NOCACHE, &t_gh); if (error) @@ -521,37 +524,35 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd) goto fail_gunlock_tr; gfs2_glock_dq_uninit(&t_gh); - t = DIV_ROUND_UP(jiffies - t, HZ); - fs_info(sdp, "jid=%u: Journal replayed in %lus\n", jd->jd_jid, t); } - gfs2_glock_dq_uninit(&ji_gh); + if (jd->jd_jid != sdp->sd_lockstruct.ls_jid) + gfs2_glock_dq_uninit(&ji_gh); gfs2_lm_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS); - gfs2_glock_dq_uninit(&j_gh); + if (jd->jd_jid != sdp->sd_lockstruct.ls_jid) + gfs2_glock_dq_uninit(&j_gh); fs_info(sdp, "jid=%u: Done\n", jd->jd_jid); - return 0; - fail_gunlock_tr: +fail_gunlock_tr: gfs2_glock_dq_uninit(&t_gh); - - fail_gunlock_ji: - gfs2_glock_dq_uninit(&ji_gh); - - fail_gunlock_j: - gfs2_glock_dq_uninit(&j_gh); +fail_gunlock_ji: + if (jd->jd_jid != sdp->sd_lockstruct.ls_jid) { + gfs2_glock_dq_uninit(&ji_gh); +fail_gunlock_j: + gfs2_glock_dq_uninit(&j_gh); + } fs_info(sdp, "jid=%u: %s\n", jd->jd_jid, (error) ? "Failed" : "Done"); - fail: +fail: gfs2_lm_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP); - return error; } From 579b78a43b366d51f9c888afaf1eab1f4ea599fa Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 26 Apr 2006 14:58:26 -0400 Subject: [PATCH 092/292] [GFS2] Remove GL_NEVER_RECURSE flag There is no point in keeping this flag since recursion is not now allowed for any glock. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 10 ++++------ fs/gfs2/glock.h | 1 - fs/gfs2/ops_fstype.c | 10 +++++----- fs/gfs2/recovery.c | 3 +-- fs/gfs2/super.c | 6 +++--- fs/gfs2/trans.c | 3 +-- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 0f317155915d..67e3f2a4d109 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -357,7 +357,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags, struct gfs2_holder *gh) { - flags |= GL_NEVER_RECURSE; INIT_LIST_HEAD(&gh->gh_list); gh->gh_gl = gl; gh->gh_ip = (unsigned long)__builtin_return_address(0); @@ -387,7 +386,7 @@ void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags, void gfs2_holder_reinit(unsigned int state, unsigned flags, struct gfs2_holder *gh) { gh->gh_state = state; - gh->gh_flags = flags | GL_NEVER_RECURSE; + gh->gh_flags = flags; if (gh->gh_state == LM_ST_EXCLUSIVE) gh->gh_flags |= GL_LOCAL_EXCL; @@ -731,8 +730,7 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state) } else { spin_unlock(&gl->gl_spin); - new_gh = gfs2_holder_get(gl, state, - LM_FLAG_TRY | GL_NEVER_RECURSE, + new_gh = gfs2_holder_get(gl, state, LM_FLAG_TRY, GFP_KERNEL | __GFP_NOFAIL), set_bit(HIF_DEMOTE, &new_gh->gh_iflags); set_bit(HIF_DEALLOC, &new_gh->gh_iflags); @@ -1336,7 +1334,7 @@ void gfs2_glock_force_drop(struct gfs2_glock *gl) { struct gfs2_holder gh; - gfs2_holder_init(gl, LM_ST_UNLOCKED, GL_NEVER_RECURSE, &gh); + gfs2_holder_init(gl, LM_ST_UNLOCKED, 0, &gh); set_bit(HIF_DEMOTE, &gh.gh_iflags); spin_lock(&gl->gl_spin); @@ -1401,7 +1399,7 @@ int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time) } gh = &gr->gr_gh; - gfs2_holder_init(gl, 0, GL_NEVER_RECURSE, gh); + gfs2_holder_init(gl, 0, 0, gh); set_bit(HIF_GREEDY, &gh->gh_iflags); INIT_WORK(&gr->gr_work, greedy_work, gr); diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index ed5bc3e65397..6f9c88ed5383 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -26,7 +26,6 @@ #define GL_NOCACHE 0x00000400 #define GL_SYNC 0x00000800 #define GL_NOCANCEL 0x00001000 -#define GL_NEVER_RECURSE 0x00002000 #define GL_AOP 0x00004000 #define GLR_TRYFAILED 13 diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 70745f3561a6..d19d98766aa5 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -223,7 +223,7 @@ static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, error = gfs2_glock_nq_num(sdp, GFS2_LIVE_LOCK, &gfs2_nondisk_glops, LM_ST_SHARED, - LM_FLAG_NOEXP | GL_EXACT | GL_NEVER_RECURSE, + LM_FLAG_NOEXP | GL_EXACT, &sdp->sd_live_gh); if (error) { fs_err(sdp, "can't acquire live glock: %d\n", error); @@ -638,7 +638,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) ip = sdp->sd_ir_inode->u.generic_ip; error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, + LM_ST_EXCLUSIVE, 0, &sdp->sd_ir_gh); if (error) { fs_err(sdp, "can't lock local \"ir\" file: %d\n", error); @@ -647,7 +647,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) ip = sdp->sd_sc_inode->u.generic_ip; error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, + LM_ST_EXCLUSIVE, 0, &sdp->sd_sc_gh); if (error) { fs_err(sdp, "can't lock local \"sc\" file: %d\n", error); @@ -656,7 +656,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) ip = sdp->sd_ut_inode->u.generic_ip; error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, + LM_ST_EXCLUSIVE, 0, &sdp->sd_ut_gh); if (error) { fs_err(sdp, "can't lock local \"ut\" file: %d\n", error); @@ -665,7 +665,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) ip = sdp->sd_qc_inode->u.generic_ip; error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_EXCLUSIVE, GL_NEVER_RECURSE, + LM_ST_EXCLUSIVE, 0, &sdp->sd_qc_gh); if (error) { fs_err(sdp, "can't lock local \"qc\" file: %d\n", error); diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 7d467966f92c..d916817fb6e3 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -487,8 +487,7 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd) error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, LM_FLAG_NOEXP | LM_FLAG_PRIORITY | - GL_NEVER_RECURSE | GL_NOCANCEL | - GL_NOCACHE, + GL_NOCANCEL | GL_NOCACHE, &t_gh); if (error) goto fail_gunlock_ji; diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index a4da649d086f..f0dbd2d7aadc 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -469,7 +469,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp) int error; error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, - GL_LOCAL_EXCL | GL_NEVER_RECURSE, &t_gh); + GL_LOCAL_EXCL, &t_gh); if (error) return error; @@ -530,7 +530,7 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp) gfs2_statfs_sync(sdp); error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, - GL_LOCAL_EXCL | GL_NEVER_RECURSE | GL_NOCACHE, + GL_LOCAL_EXCL | GL_NOCACHE, &t_gh); if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) return error; @@ -869,7 +869,7 @@ int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh) } error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_DEFERRED, - LM_FLAG_PRIORITY | GL_NEVER_RECURSE | GL_NOCACHE, + LM_FLAG_PRIORITY | GL_NOCACHE, t_gh); list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 6b02d8c38f0f..18c606d07126 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -50,8 +50,7 @@ int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks, sizeof(uint64_t)); INIT_LIST_HEAD(&tr->tr_list_buf); - gfs2_holder_init(sdp->sd_trans_gl, LM_ST_SHARED, - GL_NEVER_RECURSE, &tr->tr_t_gh); + gfs2_holder_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &tr->tr_t_gh); error = gfs2_glock_nq(&tr->tr_t_gh); if (error) From 6bd70aba5ab453459bb53b1e29f0e0650d6c311f Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 26 Apr 2006 15:56:35 -0400 Subject: [PATCH 093/292] [DLM] lock_dlm recover_status patch This saves the journal recovery result and makes it visible through sysfs. User space needs to know if the node actually recovered the journal or tried and gave up. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/lock_dlm.h | 1 + fs/gfs2/locking/dlm/mount.c | 1 + fs/gfs2/locking/dlm/sysfs.c | 25 ++++++++++++++++--------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h index 6d76146953ce..e6c1e4786fec 100644 --- a/fs/gfs2/locking/dlm/lock_dlm.h +++ b/fs/gfs2/locking/dlm/lock_dlm.h @@ -70,6 +70,7 @@ struct gdlm_ls { lm_fsdata_t *fsdata; int recover_jid; int recover_jid_done; + int recover_jid_status; spinlock_t async_lock; struct list_head complete; struct list_head blocking; diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c index 026f05ce168d..aa79fbecaf6a 100644 --- a/fs/gfs2/locking/dlm/mount.c +++ b/fs/gfs2/locking/dlm/mount.c @@ -203,6 +203,7 @@ static void gdlm_recovery_done(lm_lockspace_t *lockspace, unsigned int jid, { struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; ls->recover_jid_done = jid; + ls->recover_jid_status = message; kobject_uevent(&ls->kobj, KOBJ_CHANGE); } diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c index e1e5186c97c9..0d8bd0806dba 100644 --- a/fs/gfs2/locking/dlm/sysfs.c +++ b/fs/gfs2/locking/dlm/sysfs.c @@ -110,6 +110,11 @@ static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf) return sprintf(buf, "%d\n", ls->recover_jid_done); } +static ssize_t recover_status_show(struct gdlm_ls *ls, char *buf) +{ + return sprintf(buf, "%d\n", ls->recover_jid_status); +} + struct gdlm_attr { struct attribute attr; ssize_t (*show)(struct gdlm_ls *, char *); @@ -119,15 +124,16 @@ struct gdlm_attr { #define GDLM_ATTR(_name,_mode,_show,_store) \ static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store) -GDLM_ATTR(proto_name, 0444, proto_name_show, NULL); -GDLM_ATTR(block, 0644, block_show, block_store); -GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store); -GDLM_ATTR(id, 0444, id_show, NULL); -GDLM_ATTR(jid, 0444, jid_show, NULL); -GDLM_ATTR(first, 0444, first_show, NULL); -GDLM_ATTR(first_done, 0444, first_done_show, NULL); -GDLM_ATTR(recover, 0644, recover_show, recover_store); -GDLM_ATTR(recover_done, 0444, recover_done_show, NULL); +GDLM_ATTR(proto_name, 0444, proto_name_show, NULL); +GDLM_ATTR(block, 0644, block_show, block_store); +GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store); +GDLM_ATTR(id, 0444, id_show, NULL); +GDLM_ATTR(jid, 0444, jid_show, NULL); +GDLM_ATTR(first, 0444, first_show, NULL); +GDLM_ATTR(first_done, 0444, first_done_show, NULL); +GDLM_ATTR(recover, 0644, recover_show, recover_store); +GDLM_ATTR(recover_done, 0444, recover_done_show, NULL); +GDLM_ATTR(recover_status, 0444, recover_status_show, NULL); static struct attribute *gdlm_attrs[] = { &gdlm_attr_proto_name.attr, @@ -139,6 +145,7 @@ static struct attribute *gdlm_attrs[] = { &gdlm_attr_first_done.attr, &gdlm_attr_recover.attr, &gdlm_attr_recover_done.attr, + &gdlm_attr_recover_status.attr, NULL, }; From e7f5c01caddbad150dcf003f76cd5aac413f4c50 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 27 Apr 2006 11:25:45 -0400 Subject: [PATCH 094/292] [GFS2] Remove redundant casts to/from void Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 11 +++++------ fs/gfs2/locking/dlm/lock.c | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 67e3f2a4d109..17d474fab5ab 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1348,7 +1348,7 @@ void gfs2_glock_force_drop(struct gfs2_glock *gl) static void greedy_work(void *data) { - struct greedy *gr = (struct greedy *)data; + struct greedy *gr = data; struct gfs2_holder *gh = &gr->gr_gh; struct gfs2_glock *gl = gh->gh_gl; struct gfs2_glock_operations *glops = gl->gl_ops; @@ -1745,19 +1745,19 @@ void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data) switch (type) { case LM_CB_NEED_E: - blocking_cb(sdp, (struct lm_lockname *)data, LM_ST_UNLOCKED); + blocking_cb(sdp, data, LM_ST_UNLOCKED); return; case LM_CB_NEED_D: - blocking_cb(sdp, (struct lm_lockname *)data, LM_ST_DEFERRED); + blocking_cb(sdp, data, LM_ST_DEFERRED); return; case LM_CB_NEED_S: - blocking_cb(sdp, (struct lm_lockname *)data, LM_ST_SHARED); + blocking_cb(sdp, data, LM_ST_SHARED); return; case LM_CB_ASYNC: { - struct lm_async_cb *async = (struct lm_async_cb *)data; + struct lm_async_cb *async = data; struct gfs2_glock *gl; gl = gfs2_glock_find(sdp, &async->lc_name); @@ -1766,7 +1766,6 @@ void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data) if (!gfs2_assert_warn(sdp, gl->gl_req_bh)) gl->gl_req_bh(gl, async->lc_ret); gfs2_glock_put(gl); - return; } diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index 1799d2237e7e..a309b799dff1 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -25,7 +25,7 @@ static void queue_complete(struct gdlm_lock *lp) static inline void gdlm_ast(void *astarg) { - queue_complete((struct gdlm_lock *) astarg); + queue_complete(astarg); } static inline void gdlm_bast(void *astarg, int mode) @@ -257,7 +257,7 @@ unsigned int gdlm_do_lock(struct gdlm_lock *lp) lp->cur, lp->req, lp->lkf); error = dlm_lock(ls->dlm_lockspace, lp->req, &lp->lksb, lp->lkf, - str.name, str.namelen, 0, gdlm_ast, (void *) lp, + str.name, str.namelen, 0, gdlm_ast, lp, bast ? gdlm_bast : NULL); if ((error == -EAGAIN) && (lp->lkf & DLM_LKF_NOQUEUE)) { From 363275216c1a1b0b82c8419310c194b8c26b9c27 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 28 Apr 2006 10:46:21 -0400 Subject: [PATCH 095/292] [GFS2] Reordering in deallocation to avoid recursive locking Despite my earlier careful search, there was a recursive lock left in the deallocation code. This removes it. It also should speed up deallocation be reducing the number of locking operations which take place by using two "try lock" operations on the two locks involved in inode deallocation which allows us to grab the locks out of order (compared with NFS which grabs the inode lock first and the iopen lock later). It is ok for us to fail while doing this since if it does fail it means that someone else is still using the inode and thus it wouldn't be possible to deallocate anyway. This fixes the bug reported to me by Rob Kenna. Cc: Rob Kenna Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 6 ++-- fs/gfs2/inode.c | 95 +++++++++++++++++++++++-------------------------- fs/gfs2/inode.h | 2 +- 3 files changed, 49 insertions(+), 54 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 17d474fab5ab..f82ecc0cc8fb 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1814,7 +1814,7 @@ void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum) if (atomic_read(&ip->i_count)) goto out_unlock; - gfs2_inode_destroy(ip); + gfs2_inode_destroy(ip, 1); out_unlock: gfs2_glmutex_unlock(gl); @@ -1940,7 +1940,7 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp) if (gl->gl_ops == &gfs2_inode_glops) { struct gfs2_inode *ip = gl->gl_object; if (ip && !atomic_read(&ip->i_count)) - gfs2_inode_destroy(ip); + gfs2_inode_destroy(ip, 1); } if (queue_empty(gl, &gl->gl_holders) && gl->gl_state != LM_ST_UNLOCKED && @@ -2083,7 +2083,7 @@ static void clear_glock(struct gfs2_glock *gl) if (gl->gl_ops == &gfs2_inode_glops) { struct gfs2_inode *ip = gl->gl_object; if (ip && !atomic_read(&ip->i_count)) - gfs2_inode_destroy(ip); + gfs2_inode_destroy(ip, 1); } if (queue_empty(gl, &gl->gl_holders) && gl->gl_state != LM_ST_UNLOCKED) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index fb5a4d06e926..9084d6037a0c 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -287,7 +287,7 @@ int gfs2_inode_refresh(struct gfs2_inode *ip) static int inode_create(struct gfs2_glock *i_gl, const struct gfs2_inum *inum, struct gfs2_glock *io_gl, unsigned int io_state, - struct gfs2_inode **ipp) + struct gfs2_inode **ipp, int need_lock) { struct gfs2_sbd *sdp = i_gl->gl_sbd; struct gfs2_inode *ip; @@ -312,11 +312,13 @@ static int inode_create(struct gfs2_glock *i_gl, const struct gfs2_inum *inum, ip->i_greedy = gfs2_tune_get(sdp, gt_greedy_default); - error = gfs2_glock_nq_init(io_gl, - io_state, GL_LOCAL_EXCL | GL_EXACT, - &ip->i_iopen_gh); - if (error) - goto fail; + if (need_lock) { + error = gfs2_glock_nq_init(io_gl, + io_state, GL_LOCAL_EXCL | GL_EXACT, + &ip->i_iopen_gh); + if (error) + goto fail; + } ip->i_iopen_gh.gh_owner = NULL; spin_lock(&io_gl->gl_spin); @@ -376,7 +378,7 @@ int gfs2_inode_get(struct gfs2_glock *i_gl, const struct gfs2_inum *inum, error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_iopen_glops, CREATE, &io_gl); if (!error) { - error = inode_create(i_gl, inum, io_gl, LM_ST_SHARED, ipp); + error = inode_create(i_gl, inum, io_gl, LM_ST_SHARED, ipp, 1); gfs2_glock_put(io_gl); } @@ -398,21 +400,23 @@ void gfs2_inode_put(struct gfs2_inode *ip) atomic_dec(&ip->i_count); } -void gfs2_inode_destroy(struct gfs2_inode *ip) +void gfs2_inode_destroy(struct gfs2_inode *ip, int unlock) { struct gfs2_sbd *sdp = ip->i_sbd; - struct gfs2_glock *io_gl = ip->i_iopen_gh.gh_gl; struct gfs2_glock *i_gl = ip->i_gl; gfs2_assert_warn(sdp, !atomic_read(&ip->i_count)); - gfs2_assert(sdp, io_gl->gl_object == i_gl); - - spin_lock(&io_gl->gl_spin); - io_gl->gl_object = NULL; - spin_unlock(&io_gl->gl_spin); - gfs2_glock_put(i_gl); - - gfs2_glock_dq_uninit(&ip->i_iopen_gh); + if (unlock) { + struct gfs2_glock *io_gl = ip->i_iopen_gh.gh_gl; + gfs2_assert(sdp, io_gl->gl_object == i_gl); + + spin_lock(&io_gl->gl_spin); + io_gl->gl_object = NULL; + spin_unlock(&io_gl->gl_spin); + gfs2_glock_put(i_gl); + + gfs2_glock_dq_uninit(&ip->i_iopen_gh); + } gfs2_meta_cache_flush(ip); kmem_cache_free(gfs2_inode_cachep, ip); @@ -493,6 +497,13 @@ static int dinode_dealloc(struct gfs2_inode *ip, struct gfs2_unlinked *ul) * @inum: the inode number to deallocate * @io_gh: a holder for the iopen glock for this inode * + * N.B. When we enter this we already hold the iopen glock and getting + * the glock for the inode means that we are grabbing the locks in the + * "wrong" order so we must only so a try lock operation and fail if we + * don't get the lock. Thats ok, since if we fail it means someone else + * is using the inode still and thus we shouldn't be deallocating it + * anyway. + * * Returns: errno */ @@ -503,33 +514,21 @@ static int inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul, struct gfs2_holder i_gh; int error; - error = gfs2_glock_nq_num(sdp, - ul->ul_ut.ut_inum.no_addr, &gfs2_inode_glops, - LM_ST_EXCLUSIVE, 0, &i_gh); - if (error) - return error; - - /* We reacquire the iopen lock here to avoid a race with the NFS server - calling gfs2_read_inode() with the inode number of a inode we're in - the process of deallocating. And we can't keep our hold on the lock - from inode_dealloc_init() for deadlock reasons. */ - - gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY, io_gh); - error = gfs2_glock_nq(io_gh); - switch (error) { + error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, + &gfs2_inode_glops, LM_ST_EXCLUSIVE, + LM_FLAG_TRY_1CB, &i_gh); + switch(error) { case 0: break; case GLR_TRYFAILED: - error = 1; + return 1; /* or back off and relock in different order? */ default: - goto out; + return error; } gfs2_assert_warn(sdp, !i_gh.gh_gl->gl_object); error = inode_create(i_gh.gh_gl, &ul->ul_ut.ut_inum, io_gh->gh_gl, - LM_ST_EXCLUSIVE, &ip); - - gfs2_glock_dq(io_gh); + LM_ST_EXCLUSIVE, &ip, 0); if (error) goto out; @@ -568,13 +567,13 @@ static int inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul, if (error) goto out_iput; - out_iput: +out_iput: gfs2_glmutex_lock(i_gh.gh_gl); gfs2_inode_put(ip); - gfs2_inode_destroy(ip); + gfs2_inode_destroy(ip, 0); gfs2_glmutex_unlock(i_gh.gh_gl); - out: +out: gfs2_glock_dq_uninit(&i_gh); return error; @@ -589,14 +588,13 @@ static int inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul, static int try_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) { - struct gfs2_holder io_gh; int error = 0; + struct gfs2_holder iogh; gfs2_try_toss_inode(sdp, &ul->ul_ut.ut_inum); - - error = gfs2_glock_nq_num(sdp, - ul->ul_ut.ut_inum.no_addr, &gfs2_iopen_glops, - LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB, &io_gh); + error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, + &gfs2_iopen_glops, LM_ST_EXCLUSIVE, + LM_FLAG_TRY_1CB, &iogh); switch (error) { case 0: break; @@ -606,9 +604,8 @@ static int try_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) return error; } - gfs2_glock_dq(&io_gh); - error = inode_dealloc(sdp, ul, &io_gh); - gfs2_holder_uninit(&io_gh); + error = inode_dealloc(sdp, ul, &iogh); + gfs2_glock_dq_uninit(&iogh); return error; } @@ -634,9 +631,7 @@ static int inode_dealloc_uninit(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) if (error) goto out; - error = gfs2_trans_begin(sdp, - RES_RG_BIT + RES_UNLINKED + RES_STATFS, - 0); + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_UNLINKED + RES_STATFS, 0); if (error) goto out_gunlock; diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index 0dd2a26626ec..13bc4eacac6b 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -39,7 +39,7 @@ int gfs2_inode_get(struct gfs2_glock *i_gl, struct gfs2_inode **ipp); void gfs2_inode_hold(struct gfs2_inode *ip); void gfs2_inode_put(struct gfs2_inode *ip); -void gfs2_inode_destroy(struct gfs2_inode *ip); +void gfs2_inode_destroy(struct gfs2_inode *ip, int unlock); int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); From ae118962b9f8572b5ff00e85c053dbeede2314db Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 28 Apr 2006 10:48:59 -0400 Subject: [PATCH 096/292] [DLM] PATCH 1/3 dlm: force free user lockspace Lockspaces created from user space should be forcibly freed without requiring any further user space interaction. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/dlm/device.c b/fs/dlm/device.c index 5da4b2ed988d..49a20d549216 100644 --- a/fs/dlm/device.c +++ b/fs/dlm/device.c @@ -626,7 +626,7 @@ static int do_user_remove_lockspace(struct file_info *fi, uint8_t cmd, } if (kparams->flags & DLM_USER_LSFLG_FORCEFREE) - force = 2; + force = 3; status = unregister_lockspace(lsinfo, force); mutex_unlock(&user_ls_lock); From 1c032c03117c014512195f2e33c3af999f132146 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 28 Apr 2006 10:50:41 -0400 Subject: [PATCH 097/292] [DLM] PATCH 2/3 dlm: lowcomms close When a node is removed from a lockspace configuration, close our connection to it, clearing any remaining messages for it. Signed-off-by: David Teigland Signed-off-by: Patrick Caulfield Signed-off-by: Steven Whitehouse --- fs/dlm/config.c | 2 ++ fs/dlm/lowcomms.c | 21 +++++++++++++++++++++ fs/dlm/lowcomms.h | 1 + fs/dlm/member.c | 1 - 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fs/dlm/config.c b/fs/dlm/config.c index 87df9616415e..88553054bbfa 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c @@ -17,6 +17,7 @@ #include #include "config.h" +#include "lowcomms.h" /* * /config/dlm//spaces//nodes//nodeid @@ -429,6 +430,7 @@ static void drop_comm(struct config_group *g, struct config_item *i) struct comm *cm = to_comm(i); if (local_comm == cm) local_comm = NULL; + dlm_lowcomms_close(cm->nodeid); while (cm->addr_count--) kfree(cm->addr[cm->addr_count]); config_item_put(i); diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index 09b0124f7fc4..cdd168e4bf45 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -1063,6 +1063,27 @@ static void dealloc_nodeinfo(void) } } +int dlm_lowcomms_close(int nodeid) +{ + struct nodeinfo *ni; + + ni = nodeid2nodeinfo(nodeid, 0); + if (!ni) + return -1; + + spin_lock(&ni->lock); + if (ni->assoc_id) { + ni->assoc_id = 0; + /* Don't send shutdown here, sctp will just queue it + till the node comes back up! */ + } + spin_unlock(&ni->lock); + + clean_one_writequeue(ni); + clear_bit(NI_INIT_PENDING, &ni->flags); + return 0; +} + static int write_list_empty(void) { int status; diff --git a/fs/dlm/lowcomms.h b/fs/dlm/lowcomms.h index 3af8035ff12f..6c04bb09cfa8 100644 --- a/fs/dlm/lowcomms.h +++ b/fs/dlm/lowcomms.h @@ -18,6 +18,7 @@ int dlm_lowcomms_init(void); void dlm_lowcomms_exit(void); int dlm_lowcomms_start(void); void dlm_lowcomms_stop(void); +int dlm_lowcomms_close(int nodeid); void *dlm_lowcomms_get_buffer(int nodeid, int len, int allocation, char **ppc); void dlm_lowcomms_commit_buffer(void *mh); diff --git a/fs/dlm/member.c b/fs/dlm/member.c index 926cd0cb6bff..cd0c51e724e0 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -15,7 +15,6 @@ #include "member.h" #include "recoverd.h" #include "recover.h" -#include "lowcomms.h" #include "rcom.h" #include "config.h" From c56b39cd2c55d521597f04bbd872a08d1c4373ca Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 28 Apr 2006 10:51:53 -0400 Subject: [PATCH 098/292] [DLM] PATCH 3/3 dlm: show recover state Expose the current recovery state in sysfs to help in debugging. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lockspace.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index d2ff505d51cd..9ed4b70348fb 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -21,6 +21,7 @@ #include "config.h" #include "memory.h" #include "lock.h" +#include "recover.h" #ifdef CONFIG_DLM_DEBUG int dlm_create_debug_file(struct dlm_ls *ls); @@ -74,6 +75,12 @@ static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len) return len; } +static ssize_t dlm_recover_status_show(struct dlm_ls *ls, char *buf) +{ + uint32_t status = dlm_recover_status(ls); + return sprintf(buf, "%x\n", status); +} + struct dlm_attr { struct attribute attr; ssize_t (*show)(struct dlm_ls *, char *); @@ -96,10 +103,16 @@ static struct dlm_attr dlm_attr_id = { .store = dlm_id_store }; +static struct dlm_attr dlm_attr_recover_status = { + .attr = {.name = "recover_status", .mode = S_IRUGO}, + .show = dlm_recover_status_show +}; + static struct attribute *dlm_attrs[] = { &dlm_attr_control.attr, &dlm_attr_event.attr, &dlm_attr_id.attr, + &dlm_attr_recover_status.attr, NULL, }; From 08bc2dbc7327e89b9d5b9c8ef9401d1df2622fca Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Fri, 28 Apr 2006 10:59:12 -0400 Subject: [PATCH 099/292] [GFS2] [-mm patch] fs/gfs2/: possible cleanups This patch contains the following possible cleanups: - make needlessly global code static - #if 0 unused functions - remove the following global function that was both unused and unimplemented: - super.c: gfs2_do_upgrade() Signed-off-by: Adrian Bunk Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 3 ++- fs/gfs2/bmap.h | 2 -- fs/gfs2/dir.c | 8 +++---- fs/gfs2/eaops.c | 2 +- fs/gfs2/eaops.h | 1 - fs/gfs2/eattr.c | 3 +++ fs/gfs2/eattr.h | 2 -- fs/gfs2/glock.c | 25 ++++++++++++++-------- fs/gfs2/glock.h | 12 ----------- fs/gfs2/lm.c | 2 ++ fs/gfs2/lm.h | 1 - fs/gfs2/locking/dlm/lock.c | 10 ++++----- fs/gfs2/locking/dlm/lock_dlm.h | 4 ---- fs/gfs2/locking/dlm/main.c | 4 ++-- fs/gfs2/locking/nolock/main.c | 8 +++---- fs/gfs2/lvb.c | 2 ++ fs/gfs2/lvb.h | 1 - fs/gfs2/ondisk.c | 38 ++++++++++++++++++++++++++++++---- fs/gfs2/quota.c | 2 ++ fs/gfs2/quota.h | 2 -- fs/gfs2/super.c | 8 ++----- fs/gfs2/super.h | 2 -- include/linux/gfs2_ondisk.h | 14 ------------- 23 files changed, 79 insertions(+), 77 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 68bc3be09c98..f570d8caef68 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -59,7 +59,7 @@ struct strip_mine { * * Returns: errno */ - +#if 0 int gfs2_unstuffer_sync(struct gfs2_inode *ip, struct buffer_head *dibh, uint64_t block, void *private) { @@ -77,6 +77,7 @@ int gfs2_unstuffer_sync(struct gfs2_inode *ip, struct buffer_head *dibh, return error; } +#endif /* 0 */ /** * gfs2_unstuff_dinode - Unstuff a dinode when the data has grown too big diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index ee9ec8d7515c..23fb6589d5e3 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -13,8 +13,6 @@ typedef int (*gfs2_unstuffer_t) (struct gfs2_inode * ip, struct buffer_head * dibh, uint64_t block, void *private); -int gfs2_unstuffer_sync(struct gfs2_inode *ip, struct buffer_head *dibh, - uint64_t block, void *private); int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, void *private); diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index ffc1beff6703..0404783f39b3 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -669,10 +669,10 @@ static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh, * Takes a dent from which to grab space as an argument. Returns the * newly created dent. */ -struct gfs2_dirent *gfs2_init_dirent(struct inode *inode, - struct gfs2_dirent *dent, - const struct qstr *name, - struct buffer_head *bh) +static struct gfs2_dirent *gfs2_init_dirent(struct inode *inode, + struct gfs2_dirent *dent, + const struct qstr *name, + struct buffer_head *bh) { struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_dirent *ndent; diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index 4b9f6cff7a34..1b376eceb6af 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -167,7 +167,7 @@ static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) return gfs2_ea_remove_i(ip, er); } -struct gfs2_eattr_operations gfs2_user_eaops = { +static struct gfs2_eattr_operations gfs2_user_eaops = { .eo_get = user_eo_get, .eo_set = user_eo_set, .eo_remove = user_eo_remove, diff --git a/fs/gfs2/eaops.h b/fs/gfs2/eaops.h index f83c497eddca..30ec6a09bfd0 100644 --- a/fs/gfs2/eaops.h +++ b/fs/gfs2/eaops.h @@ -21,7 +21,6 @@ struct gfs2_eattr_operations { unsigned int gfs2_ea_name2type(const char *name, char **truncated_name); -extern struct gfs2_eattr_operations gfs2_user_eaops; extern struct gfs2_eattr_operations gfs2_system_eaops; extern struct gfs2_eattr_operations *gfs2_ea_ops[]; diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 8219d471f06c..d3316cab2be4 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -358,6 +358,7 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, return error; } +#if 0 static int gfs2_ea_repack_i(struct gfs2_inode *ip) { @@ -382,6 +383,8 @@ int gfs2_ea_repack(struct gfs2_inode *ip) return error; } +#endif /* 0 */ + struct ea_list { struct gfs2_ea_request *ei_er; unsigned int ei_size; diff --git a/fs/gfs2/eattr.h b/fs/gfs2/eattr.h index 2b4152b1fcbe..ffd56686225b 100644 --- a/fs/gfs2/eattr.h +++ b/fs/gfs2/eattr.h @@ -61,8 +61,6 @@ struct gfs2_ea_location { struct gfs2_ea_header *el_prev; }; -int gfs2_ea_repack(struct gfs2_inode *ip); - int gfs2_ea_get_i(struct gfs2_inode *ip, struct gfs2_ea_request *er); int gfs2_ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er); int gfs2_ea_remove_i(struct gfs2_inode *ip, struct gfs2_ea_request *er); diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index f82ecc0cc8fb..0a5a0e87b0a6 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -47,6 +47,8 @@ struct greedy { typedef void (*glock_examiner) (struct gfs2_glock * gl); +static int gfs2_dump_lockstate(struct gfs2_sbd *sdp); + /** * relaxed_state_ok - is a requested lock compatible with the current lock mode? * @actual: the current state of the lock @@ -228,8 +230,8 @@ static struct gfs2_glock *search_bucket(struct gfs2_gl_hash_bucket *bucket, * Returns: NULL, or the struct gfs2_glock with the requested number */ -struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, - struct lm_lockname *name) +static struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, + struct lm_lockname *name) { struct gfs2_gl_hash_bucket *bucket = &sdp->sd_gl_hash[gl_hash(name)]; struct gfs2_glock *gl; @@ -421,8 +423,9 @@ void gfs2_holder_uninit(struct gfs2_holder *gh) * Returns: the holder structure, NULL on ENOMEM */ -struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl, unsigned int state, - int flags, gfp_t gfp_flags) +static struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl, + unsigned int state, + int flags, gfp_t gfp_flags) { struct gfs2_holder *gh; @@ -442,7 +445,7 @@ struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl, unsigned int state, * */ -void gfs2_holder_put(struct gfs2_holder *gh) +static void gfs2_holder_put(struct gfs2_holder *gh) { gfs2_holder_uninit(gh); kfree(gh); @@ -674,7 +677,7 @@ void gfs2_glmutex_lock(struct gfs2_glock *gl) * Returns: 1 if the glock is acquired */ -int gfs2_glmutex_trylock(struct gfs2_glock *gl) +static int gfs2_glmutex_trylock(struct gfs2_glock *gl) { int acquired = 1; @@ -1301,7 +1304,8 @@ void gfs2_glock_dq(struct gfs2_holder *gh) * */ -void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, int flags) +static void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, + int flags) { struct gfs2_glock_operations *glops = gl->gl_ops; @@ -1329,7 +1333,7 @@ void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, int flags) * @gl: the glock * */ - +#if 0 void gfs2_glock_force_drop(struct gfs2_glock *gl) { struct gfs2_holder gh; @@ -1345,6 +1349,7 @@ void gfs2_glock_force_drop(struct gfs2_glock *gl) wait_for_completion(&gh.gh_wait); gfs2_holder_uninit(&gh); } +#endif /* 0 */ static void greedy_work(void *data) { @@ -1697,6 +1702,7 @@ void gfs2_lvb_unhold(struct gfs2_glock *gl) gfs2_glock_put(gl); } +#if 0 void gfs2_lvb_sync(struct gfs2_glock *gl) { gfs2_glmutex_lock(gl); @@ -1707,6 +1713,7 @@ void gfs2_lvb_sync(struct gfs2_glock *gl) gfs2_glmutex_unlock(gl); } +#endif /* 0 */ static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name, unsigned int state) @@ -2307,7 +2314,7 @@ static int dump_glock(struct gfs2_glock *gl) * */ -int gfs2_dump_lockstate(struct gfs2_sbd *sdp) +static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) { struct gfs2_gl_hash_bucket *bucket; struct gfs2_glock *gl; diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 6f9c88ed5383..a36b26585fb8 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -73,8 +73,6 @@ static inline int gfs2_glock_is_blocking(struct gfs2_glock *gl) return ret; } -struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, - struct lm_lockname *name); int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, struct gfs2_glock_operations *glops, int create, struct gfs2_glock **glp); @@ -85,15 +83,11 @@ void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags, void gfs2_holder_reinit(unsigned int state, unsigned flags, struct gfs2_holder *gh); void gfs2_holder_uninit(struct gfs2_holder *gh); -struct gfs2_holder *gfs2_holder_get(struct gfs2_glock *gl, unsigned int state, - int flags, gfp_t gfp_flags); -void gfs2_holder_put(struct gfs2_holder *gh); void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags); void gfs2_glock_drop_th(struct gfs2_glock *gl); void gfs2_glmutex_lock(struct gfs2_glock *gl); -int gfs2_glmutex_trylock(struct gfs2_glock *gl); void gfs2_glmutex_unlock(struct gfs2_glock *gl); int gfs2_glock_nq(struct gfs2_holder *gh); @@ -101,9 +95,6 @@ int gfs2_glock_poll(struct gfs2_holder *gh); int gfs2_glock_wait(struct gfs2_holder *gh); void gfs2_glock_dq(struct gfs2_holder *gh); -void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, int flags); -void gfs2_glock_force_drop(struct gfs2_glock *gl); - int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time); void gfs2_glock_dq_uninit(struct gfs2_holder *gh); @@ -148,7 +139,6 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl, int gfs2_lvb_hold(struct gfs2_glock *gl); void gfs2_lvb_unhold(struct gfs2_glock *gl); -void gfs2_lvb_sync(struct gfs2_glock *gl); void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data); @@ -161,6 +151,4 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp); void gfs2_scand_internal(struct gfs2_sbd *sdp); void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait); -int gfs2_dump_lockstate(struct gfs2_sbd *sdp); - #endif /* __GLOCK_DOT_H__ */ diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index 5b3c56d2df2f..06a785e9b582 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -188,11 +188,13 @@ void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb); } +#if 0 void gfs2_lm_sync_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) { if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) sdp->sd_lockstruct.ls_ops->lm_sync_lvb(lock, lvb); } +#endif /* 0 */ int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, struct file *file, struct file_lock *fl) diff --git a/fs/gfs2/lm.h b/fs/gfs2/lm.h index ec812424fdec..4ee5c34434bc 100644 --- a/fs/gfs2/lm.h +++ b/fs/gfs2/lm.h @@ -26,7 +26,6 @@ unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock); int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp); void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb); -void gfs2_lm_sync_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb); int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, struct file *file, struct file_lock *fl); diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index a309b799dff1..3b0dfd7ae26e 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -158,8 +158,8 @@ static inline void make_strname(struct lm_lockname *lockname, str->namelen = GDLM_STRNAME_BYTES; } -int gdlm_create_lp(struct gdlm_ls *ls, struct lm_lockname *name, - struct gdlm_lock **lpp) +static int gdlm_create_lp(struct gdlm_ls *ls, struct lm_lockname *name, + struct gdlm_lock **lpp) { struct gdlm_lock *lp; @@ -276,7 +276,7 @@ unsigned int gdlm_do_lock(struct gdlm_lock *lp) return LM_OUT_ASYNC; } -unsigned int gdlm_do_unlock(struct gdlm_lock *lp) +static unsigned int gdlm_do_unlock(struct gdlm_lock *lp) { struct gdlm_ls *ls = lp->ls; unsigned int lkf = 0; @@ -378,7 +378,7 @@ void gdlm_cancel(lm_lock_t *lock) clear_bit(LFL_DLM_CANCEL, &lp->flags); } -int gdlm_add_lvb(struct gdlm_lock *lp) +static int gdlm_add_lvb(struct gdlm_lock *lp) { char *lvb; @@ -391,7 +391,7 @@ int gdlm_add_lvb(struct gdlm_lock *lp) return 0; } -void gdlm_del_lvb(struct gdlm_lock *lp) +static void gdlm_del_lvb(struct gdlm_lock *lp) { kfree(lp->lvb); lp->lvb = NULL; diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h index e6c1e4786fec..530c2f542584 100644 --- a/fs/gfs2/locking/dlm/lock_dlm.h +++ b/fs/gfs2/locking/dlm/lock_dlm.h @@ -162,12 +162,8 @@ int16_t gdlm_make_lmstate(int16_t); void gdlm_queue_delayed(struct gdlm_lock *); void gdlm_submit_delayed(struct gdlm_ls *); int gdlm_release_all_locks(struct gdlm_ls *); -int gdlm_create_lp(struct gdlm_ls *, struct lm_lockname *, struct gdlm_lock **); void gdlm_delete_lp(struct gdlm_lock *); -int gdlm_add_lvb(struct gdlm_lock *); -void gdlm_del_lvb(struct gdlm_lock *); unsigned int gdlm_do_lock(struct gdlm_lock *); -unsigned int gdlm_do_unlock(struct gdlm_lock *); int gdlm_get_lock(lm_lockspace_t *, struct lm_lockname *, lm_lock_t **); void gdlm_put_lock(lm_lock_t *); diff --git a/fs/gfs2/locking/dlm/main.c b/fs/gfs2/locking/dlm/main.c index 3c9adf18fd9c..89728c91665f 100644 --- a/fs/gfs2/locking/dlm/main.c +++ b/fs/gfs2/locking/dlm/main.c @@ -16,7 +16,7 @@ extern int gdlm_drop_period; extern struct lm_lockops gdlm_ops; -int __init init_lock_dlm(void) +static int __init init_lock_dlm(void) { int error; @@ -48,7 +48,7 @@ int __init init_lock_dlm(void) return 0; } -void __exit exit_lock_dlm(void) +static void __exit exit_lock_dlm(void) { gdlm_plock_exit(); gdlm_sysfs_exit(); diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index ecd37371eba5..97ffac5cdefb 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -21,7 +21,7 @@ struct nolock_lockspace { unsigned int nl_lvb_size; }; -struct lm_lockops nolock_ops; +static struct lm_lockops nolock_ops; static int nolock_mount(char *table_name, char *host_data, lm_callback_t cb, lm_fsdata_t *fsdata, @@ -208,7 +208,7 @@ static void nolock_recovery_done(lm_lockspace_t *lockspace, unsigned int jid, { } -struct lm_lockops nolock_ops = { +static struct lm_lockops nolock_ops = { .lm_proto_name = "lock_nolock", .lm_mount = nolock_mount, .lm_others_may_mount = nolock_others_may_mount, @@ -229,7 +229,7 @@ struct lm_lockops nolock_ops = { .lm_owner = THIS_MODULE, }; -int __init init_nolock(void) +static int __init init_nolock(void) { int error; @@ -245,7 +245,7 @@ int __init init_nolock(void) return 0; } -void __exit exit_nolock(void) +static void __exit exit_nolock(void) { gfs_unregister_lockproto(&nolock_ops); } diff --git a/fs/gfs2/lvb.c b/fs/gfs2/lvb.c index 63b815dad8e7..9d72872c6f73 100644 --- a/fs/gfs2/lvb.c +++ b/fs/gfs2/lvb.c @@ -43,6 +43,7 @@ void gfs2_quota_lvb_out(struct gfs2_quota_lvb *qb, char *lvb) str->qb_value = cpu_to_be64(qb->qb_value); } +#if 0 void gfs2_quota_lvb_print(struct gfs2_quota_lvb *qb) { pv(qb, qb_magic, "%u"); @@ -50,4 +51,5 @@ void gfs2_quota_lvb_print(struct gfs2_quota_lvb *qb) pv(qb, qb_warn, "%llu"); pv(qb, qb_value, "%lld"); } +#endif /* 0 */ diff --git a/fs/gfs2/lvb.h b/fs/gfs2/lvb.h index 1b9eb69b9534..3c4c17405e9a 100644 --- a/fs/gfs2/lvb.h +++ b/fs/gfs2/lvb.h @@ -14,7 +14,6 @@ void gfs2_quota_lvb_in(struct gfs2_quota_lvb *qb, char *lvb); void gfs2_quota_lvb_out(struct gfs2_quota_lvb *qb, char *lvb); -void gfs2_quota_lvb_print(struct gfs2_quota_lvb *qb); #endif /* __LVB_DOT_H__ */ diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index acfc944ce13e..b11e659bdd9e 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -28,7 +28,7 @@ * @count: the number of bytes * */ - +#if 0 static void print_array(char *title, char *buf, int count) { int x; @@ -42,6 +42,7 @@ static void print_array(char *title, char *buf, int count) if (x % 16) printk("\n"); } +#endif /* 0 */ /* * gfs2_xxx_in - read in an xxx struct @@ -72,7 +73,7 @@ void gfs2_inum_out(const struct gfs2_inum *no, char *buf) str->no_addr = cpu_to_be64(no->no_addr); } -void gfs2_inum_print(struct gfs2_inum *no) +static void gfs2_inum_print(struct gfs2_inum *no) { pv(no, no_formal_ino, "%llu"); pv(no, no_addr, "%llu"); @@ -96,7 +97,7 @@ static void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf) str->mh_format = cpu_to_be32(mh->mh_format); } -void gfs2_meta_header_print(struct gfs2_meta_header *mh) +static void gfs2_meta_header_print(struct gfs2_meta_header *mh) { pv(mh, mh_magic, "0x%.8X"); pv(mh, mh_type, "%u"); @@ -121,6 +122,7 @@ void gfs2_sb_in(struct gfs2_sb *sb, char *buf) memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN); } +#if 0 void gfs2_sb_print(struct gfs2_sb *sb) { gfs2_meta_header_print(&sb->sb_header); @@ -136,6 +138,7 @@ void gfs2_sb_print(struct gfs2_sb *sb) pv(sb, sb_lockproto, "%s"); pv(sb, sb_locktable, "%s"); } +#endif /* 0 */ void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf) { @@ -149,6 +152,7 @@ void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf) } +#if 0 void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf) { struct gfs2_rindex *str = (struct gfs2_rindex *)buf; @@ -163,6 +167,8 @@ void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf) memset(str->ri_reserved, 0, sizeof(str->ri_reserved)); } +#endif /* 0 */ + void gfs2_rindex_print(struct gfs2_rindex *ri) { pv(ri, ri_addr, "%llu"); @@ -196,6 +202,7 @@ void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf) memset(&str->rg_reserved, 0, sizeof(str->rg_reserved)); } +#if 0 void gfs2_rgrp_print(struct gfs2_rgrp *rg) { gfs2_meta_header_print(&rg->rg_header); @@ -205,6 +212,7 @@ void gfs2_rgrp_print(struct gfs2_rgrp *rg) pa(rg, rg_reserved, 36); } +#endif /* 0 */ void gfs2_quota_in(struct gfs2_quota *qu, char *buf) { @@ -215,6 +223,8 @@ void gfs2_quota_in(struct gfs2_quota *qu, char *buf) qu->qu_value = be64_to_cpu(str->qu_value); } +#if 0 + void gfs2_quota_out(struct gfs2_quota *qu, char *buf) { struct gfs2_quota *str = (struct gfs2_quota *)buf; @@ -231,6 +241,8 @@ void gfs2_quota_print(struct gfs2_quota *qu) pv(qu, qu_value, "%lld"); } +#endif /* 0 */ + void gfs2_dinode_in(struct gfs2_dinode *di, char *buf) { struct gfs2_dinode *str = (struct gfs2_dinode *)buf; @@ -327,6 +339,8 @@ void gfs2_dinode_print(struct gfs2_dinode *di) pv(di, di_eattr, "%llu"); } +#if 0 + void gfs2_dirent_print(struct gfs2_dirent *de, char *name) { char buf[GFS2_FNAMESIZE + 1]; @@ -394,6 +408,8 @@ void gfs2_ea_header_print(struct gfs2_ea_header *ea, char *name) printk(KERN_INFO " name = %s\n", buf); } +#endif /* 0 */ + void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf) { struct gfs2_log_header *str = (struct gfs2_log_header *)buf; @@ -406,6 +422,8 @@ void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf) lh->lh_hash = be32_to_cpu(str->lh_hash); } +#if 0 + void gfs2_log_header_print(struct gfs2_log_header *lh) { gfs2_meta_header_print(&lh->lh_header); @@ -427,6 +445,8 @@ void gfs2_log_descriptor_print(struct gfs2_log_descriptor *ld) pa(ld, ld_reserved, 32); } +#endif /* 0 */ + void gfs2_inum_range_in(struct gfs2_inum_range *ir, char *buf) { struct gfs2_inum_range *str = (struct gfs2_inum_range *)buf; @@ -443,11 +463,13 @@ void gfs2_inum_range_out(struct gfs2_inum_range *ir, char *buf) str->ir_length = cpu_to_be64(ir->ir_length); } +#if 0 void gfs2_inum_range_print(struct gfs2_inum_range *ir) { pv(ir, ir_start, "%llu"); pv(ir, ir_length, "%llu"); } +#endif /* 0 */ void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, char *buf) { @@ -467,12 +489,14 @@ void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf) str->sc_dinodes = cpu_to_be64(sc->sc_dinodes); } +#if 0 void gfs2_statfs_change_print(struct gfs2_statfs_change *sc) { pv(sc, sc_total, "%lld"); pv(sc, sc_free, "%lld"); pv(sc, sc_dinodes, "%lld"); } +#endif /* 0 */ void gfs2_unlinked_tag_in(struct gfs2_unlinked_tag *ut, char *buf) { @@ -491,12 +515,16 @@ void gfs2_unlinked_tag_out(struct gfs2_unlinked_tag *ut, char *buf) str->__pad = 0; } +#if 0 + void gfs2_unlinked_tag_print(struct gfs2_unlinked_tag *ut) { gfs2_inum_print(&ut->ut_inum); pv(ut, ut_flags, "%u"); } +#endif /* 0 */ + void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf) { struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf; @@ -506,6 +534,8 @@ void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf) qc->qc_id = be32_to_cpu(str->qc_id); } +#if 0 + void gfs2_quota_change_print(struct gfs2_quota_change *qc) { pv(qc, qc_change, "%lld"); @@ -513,5 +543,5 @@ void gfs2_quota_change_print(struct gfs2_quota_change *qc) pv(qc, qc_id, "%u"); } - +#endif /* 0 */ diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 90e32a3dc50d..942c4c8b9f56 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -1086,6 +1086,7 @@ int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, uint32_t id) return error; } +#if 0 int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, struct gfs2_quota *q) { @@ -1121,6 +1122,7 @@ int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, return error; } +#endif /* 0 */ int gfs2_quota_init(struct gfs2_sbd *sdp) { diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h index 005529f6895d..1baeeb23d232 100644 --- a/fs/gfs2/quota.h +++ b/fs/gfs2/quota.h @@ -24,8 +24,6 @@ void gfs2_quota_change(struct gfs2_inode *ip, int64_t change, int gfs2_quota_sync(struct gfs2_sbd *sdp); int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, uint32_t id); -int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, - struct gfs2_quota *q); int gfs2_quota_init(struct gfs2_sbd *sdp); void gfs2_quota_scan(struct gfs2_sbd *sdp); diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index f0dbd2d7aadc..75a8def8d0bc 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -264,11 +264,6 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) return 0; } -int gfs2_do_upgrade(struct gfs2_sbd *sdp, struct gfs2_glock *sb_gl) -{ - return 0; -} - /** * gfs2_jindex_hold - Grab a lock on the jindex * @sdp: The GFS2 superblock @@ -837,7 +832,8 @@ struct lfcc { * Returns: errno */ -int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh) +static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, + struct gfs2_holder *t_gh) { struct gfs2_inode *ip; struct gfs2_holder ji_gh; diff --git a/fs/gfs2/super.h b/fs/gfs2/super.h index 6abb7b5c8828..175afdde43bb 100644 --- a/fs/gfs2/super.h +++ b/fs/gfs2/super.h @@ -14,7 +14,6 @@ void gfs2_tune_init(struct gfs2_tune *gt); int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent); int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent); -int gfs2_do_upgrade(struct gfs2_sbd *sdp, struct gfs2_glock *gl_sb); static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp) { @@ -46,7 +45,6 @@ int gfs2_statfs_sync(struct gfs2_sbd *sdp); int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc); int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc); -int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh); int gfs2_freeze_fs(struct gfs2_sbd *sdp); void gfs2_unfreeze_fs(struct gfs2_sbd *sdp); diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index 3ab40917383f..4356e3864643 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -450,22 +450,8 @@ extern void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf); /* Printing functions */ -extern void gfs2_inum_print(struct gfs2_inum *no); -extern void gfs2_meta_header_print(struct gfs2_meta_header *mh); -extern void gfs2_sb_print(struct gfs2_sb *sb); extern void gfs2_rindex_print(struct gfs2_rindex *ri); -extern void gfs2_rgrp_print(struct gfs2_rgrp *rg); -extern void gfs2_quota_print(struct gfs2_quota *qu); extern void gfs2_dinode_print(struct gfs2_dinode *di); -extern void gfs2_dirent_print(struct gfs2_dirent *de, char *name); -extern void gfs2_leaf_print(struct gfs2_leaf *lf); -extern void gfs2_ea_header_print(struct gfs2_ea_header *ea, char *name); -extern void gfs2_log_header_print(struct gfs2_log_header *lh); -extern void gfs2_log_descriptor_print(struct gfs2_log_descriptor *ld); -extern void gfs2_inum_range_print(struct gfs2_inum_range *ir); -extern void gfs2_statfs_change_print(struct gfs2_statfs_change *sc); -extern void gfs2_unlinked_tag_print(struct gfs2_unlinked_tag *ut); -extern void gfs2_quota_change_print(struct gfs2_quota_change *qc); #endif /* __KERNEL__ */ From 5be7b50f3227577d651eb6788ffea8272d215b63 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 28 Apr 2006 11:27:32 -0400 Subject: [PATCH 100/292] [GFS2] Add suitable Maintainers entries As suggested by Adrian Bunk Signed-off-by: Steven Whithouse --- MAINTAINERS | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index d6a8e5b434ec..f4bd145c007e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -819,6 +819,16 @@ M: jack@suse.cz L: linux-kernel@vger.kernel.org S: Maintained +DISTRIBUTED LOCK MANAGER +P: Patrick Caulfield +M: pcaulfie@redhat.com +P: David Teigland +M: teigland@redhat.com +L: linux-cluster@redhat.com +W: http://sources.redhat.com/cluster/ +T: git kernel.org:/pub/scm/linux/kernel/git/steve/gfs-2.6.git +S: Supported + DAVICOM FAST ETHERNET (DMFE) NETWORK DRIVER P: Tobias Ringstrom M: tori@unhappy.mine.nu @@ -1069,6 +1079,14 @@ M: khc@pm.waw.pl W: http://www.kernel.org/pub/linux/utils/net/hdlc/ S: Maintained +GFS2 FILE SYSTEM +P: Steven Whitehouse +M: swhiteho@redhat.com +L: linux-cluster@redhat.com +W: http://sources.redhat.com/cluster/ +T: git kernel.org:/pub/scm/linux/kernel/git/steve/gfs-2.6.git +S: Supported + GIGASET ISDN DRIVERS P: Hansjoerg Lipp M: hjlipp@web.de From bac1e07926ae514739e6a12218c8b6ce8ce04514 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 28 Apr 2006 11:29:48 -0400 Subject: [PATCH 101/292] [GFS2] Update my Credits file entry Signed-off-by: Steven Whitehouse --- CREDITS | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CREDITS b/CREDITS index 787564bc248b..529534b61fe9 100644 --- a/CREDITS +++ b/CREDITS @@ -3551,11 +3551,11 @@ S: Fargo, North Dakota 58122 S: USA N: Steven Whitehouse -E: SteveW@ACM.org +E: steve@chygwyn.com W: http://www.chygwyn.com/~steve -D: Linux DECnet project: http://www.sucs.swan.ac.uk/~rohan/DECnet/index.html +D: Linux DECnet project D: Minor debugging of other networking protocols. -D: Misc bug fixes and filesystem development +D: Misc bug fixes and GFS2 filesystem development N: Hans-Joachim Widmaier E: hjw@zvw.de From 56409abbf8a9e3754d752d0189f9b9a609ec78de Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 28 Apr 2006 11:48:45 -0400 Subject: [PATCH 102/292] [GFS2] Remove some unused code Remove some of the unused code flagged up by Adrian Bunk. Cc: Adrian Bunk Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 31 ------- fs/gfs2/eattr.c | 27 ------ fs/gfs2/glock.c | 23 ----- fs/gfs2/lvb.c | 9 -- fs/gfs2/ondisk.c | 225 ----------------------------------------------- 5 files changed, 315 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index f570d8caef68..cfe1a428c668 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -48,37 +48,6 @@ struct strip_mine { unsigned int sm_height; }; -/** - * @gfs2_unstuffer_sync - Synchronously unstuff a dinode - * @ip: - * @dibh: - * @block: - * @private: - * - * Cheat and use a metadata buffer instead of a data page. - * - * Returns: errno - */ -#if 0 -int gfs2_unstuffer_sync(struct gfs2_inode *ip, struct buffer_head *dibh, - uint64_t block, void *private) -{ - struct buffer_head *bh; - int error; - - bh = gfs2_meta_new(ip->i_gl, block); - - gfs2_buffer_copy_tail(bh, 0, dibh, sizeof(struct gfs2_dinode)); - - set_buffer_dirty(bh); - error = sync_dirty_buffer(bh); - - brelse(bh); - - return error; -} -#endif /* 0 */ - /** * gfs2_unstuff_dinode - Unstuff a dinode when the data has grown too big * @ip: The GFS2 inode to unstuff diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index d3316cab2be4..af4f1c3f5929 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -358,33 +358,6 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, return error; } -#if 0 - -static int gfs2_ea_repack_i(struct gfs2_inode *ip) -{ - return -EOPNOTSUPP; -} - -int gfs2_ea_repack(struct gfs2_inode *ip) -{ - struct gfs2_holder gh; - int error; - - error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); - if (error) - return error; - - /* Some sort of permissions checking would be nice */ - - error = gfs2_ea_repack_i(ip); - - gfs2_glock_dq_uninit(&gh); - - return error; -} - -#endif /* 0 */ - struct ea_list { struct gfs2_ea_request *ei_er; unsigned int ei_size; diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 0a5a0e87b0a6..4fb8066dc745 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1328,29 +1328,6 @@ static void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, glops->go_xmote_th(gl, state, flags); } -/** - * gfs2_glock_force_drop - Force a glock to be uncached - * @gl: the glock - * - */ -#if 0 -void gfs2_glock_force_drop(struct gfs2_glock *gl) -{ - struct gfs2_holder gh; - - gfs2_holder_init(gl, LM_ST_UNLOCKED, 0, &gh); - set_bit(HIF_DEMOTE, &gh.gh_iflags); - - spin_lock(&gl->gl_spin); - list_add_tail(&gh.gh_list, &gl->gl_waiters2); - run_queue(gl); - spin_unlock(&gl->gl_spin); - - wait_for_completion(&gh.gh_wait); - gfs2_holder_uninit(&gh); -} -#endif /* 0 */ - static void greedy_work(void *data) { struct greedy *gr = data; diff --git a/fs/gfs2/lvb.c b/fs/gfs2/lvb.c index 9d72872c6f73..47867db92ea1 100644 --- a/fs/gfs2/lvb.c +++ b/fs/gfs2/lvb.c @@ -43,13 +43,4 @@ void gfs2_quota_lvb_out(struct gfs2_quota_lvb *qb, char *lvb) str->qb_value = cpu_to_be64(qb->qb_value); } -#if 0 -void gfs2_quota_lvb_print(struct gfs2_quota_lvb *qb) -{ - pv(qb, qb_magic, "%u"); - pv(qb, qb_limit, "%llu"); - pv(qb, qb_warn, "%llu"); - pv(qb, qb_value, "%lld"); -} -#endif /* 0 */ diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index b11e659bdd9e..f6aba3b156c2 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -19,30 +19,6 @@ #define pv(struct, member, fmt) printk(KERN_INFO " "#member" = "fmt"\n", \ struct->member); -#define pa(struct, member, count) print_array(#member, struct->member, count); - -/** - * print_array - Print out an array of bytes - * @title: what to print before the array - * @buf: the array - * @count: the number of bytes - * - */ -#if 0 -static void print_array(char *title, char *buf, int count) -{ - int x; - - printk(KERN_INFO " %s =\n" KERN_INFO, title); - for (x = 0; x < count; x++) { - printk("%.2X ", (unsigned char)buf[x]); - if (x % 16 == 15) - printk("\n" KERN_INFO); - } - if (x % 16) - printk("\n"); -} -#endif /* 0 */ /* * gfs2_xxx_in - read in an xxx struct @@ -122,24 +98,6 @@ void gfs2_sb_in(struct gfs2_sb *sb, char *buf) memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN); } -#if 0 -void gfs2_sb_print(struct gfs2_sb *sb) -{ - gfs2_meta_header_print(&sb->sb_header); - - pv(sb, sb_fs_format, "%u"); - pv(sb, sb_multihost_format, "%u"); - - pv(sb, sb_bsize, "%u"); - pv(sb, sb_bsize_shift, "%u"); - - gfs2_inum_print(&sb->sb_master_dir); - - pv(sb, sb_lockproto, "%s"); - pv(sb, sb_locktable, "%s"); -} -#endif /* 0 */ - void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf) { struct gfs2_rindex *str = (struct gfs2_rindex *)buf; @@ -152,23 +110,6 @@ void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf) } -#if 0 -void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf) -{ - struct gfs2_rindex *str = (struct gfs2_rindex *)buf; - - str->ri_addr = cpu_to_be64(ri->ri_addr); - str->ri_length = cpu_to_be32(ri->ri_length); - str->__pad = 0; - - str->ri_data0 = cpu_to_be64(ri->ri_data0); - str->ri_data = cpu_to_be32(ri->ri_data); - str->ri_bitbytes = cpu_to_be32(ri->ri_bitbytes); - memset(str->ri_reserved, 0, sizeof(str->ri_reserved)); -} - -#endif /* 0 */ - void gfs2_rindex_print(struct gfs2_rindex *ri) { pv(ri, ri_addr, "%llu"); @@ -202,18 +143,6 @@ void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf) memset(&str->rg_reserved, 0, sizeof(str->rg_reserved)); } -#if 0 -void gfs2_rgrp_print(struct gfs2_rgrp *rg) -{ - gfs2_meta_header_print(&rg->rg_header); - pv(rg, rg_flags, "%u"); - pv(rg, rg_free, "%u"); - pv(rg, rg_dinodes, "%u"); - - pa(rg, rg_reserved, 36); -} -#endif /* 0 */ - void gfs2_quota_in(struct gfs2_quota *qu, char *buf) { struct gfs2_quota *str = (struct gfs2_quota *)buf; @@ -223,26 +152,6 @@ void gfs2_quota_in(struct gfs2_quota *qu, char *buf) qu->qu_value = be64_to_cpu(str->qu_value); } -#if 0 - -void gfs2_quota_out(struct gfs2_quota *qu, char *buf) -{ - struct gfs2_quota *str = (struct gfs2_quota *)buf; - - str->qu_limit = cpu_to_be64(qu->qu_limit); - str->qu_warn = cpu_to_be64(qu->qu_warn); - str->qu_value = cpu_to_be64(qu->qu_value); -} - -void gfs2_quota_print(struct gfs2_quota *qu) -{ - pv(qu, qu_limit, "%llu"); - pv(qu, qu_warn, "%llu"); - pv(qu, qu_value, "%lld"); -} - -#endif /* 0 */ - void gfs2_dinode_in(struct gfs2_dinode *di, char *buf) { struct gfs2_dinode *str = (struct gfs2_dinode *)buf; @@ -339,77 +248,6 @@ void gfs2_dinode_print(struct gfs2_dinode *di) pv(di, di_eattr, "%llu"); } -#if 0 - -void gfs2_dirent_print(struct gfs2_dirent *de, char *name) -{ - char buf[GFS2_FNAMESIZE + 1]; - - gfs2_inum_print(&de->de_inum); - pv(de, de_hash, "0x%.8X"); - pv(de, de_rec_len, "%u"); - pv(de, de_name_len, "%u"); - pv(de, de_type, "%u"); - - memset(buf, 0, GFS2_FNAMESIZE + 1); - memcpy(buf, name, de->de_name_len); - printk(KERN_INFO " name = %s\n", buf); -} - -void gfs2_leaf_print(struct gfs2_leaf *lf) -{ - gfs2_meta_header_print(&lf->lf_header); - pv(lf, lf_depth, "%u"); - pv(lf, lf_entries, "%u"); - pv(lf, lf_dirent_format, "%u"); - pv(lf, lf_next, "%llu"); - - pa(lf, lf_reserved, 32); -} - -void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf) -{ - struct gfs2_ea_header *str = (struct gfs2_ea_header *)buf; - - ea->ea_rec_len = be32_to_cpu(str->ea_rec_len); - ea->ea_data_len = be32_to_cpu(str->ea_data_len); - ea->ea_name_len = str->ea_name_len; - ea->ea_type = str->ea_type; - ea->ea_flags = str->ea_flags; - ea->ea_num_ptrs = str->ea_num_ptrs; -} - -void gfs2_ea_header_out(struct gfs2_ea_header *ea, char *buf) -{ - struct gfs2_ea_header *str = (struct gfs2_ea_header *)buf; - - str->ea_rec_len = cpu_to_be32(ea->ea_rec_len); - str->ea_data_len = cpu_to_be32(ea->ea_data_len); - str->ea_name_len = ea->ea_name_len; - str->ea_type = ea->ea_type; - str->ea_flags = ea->ea_flags; - str->ea_num_ptrs = ea->ea_num_ptrs; - str->__pad = 0; -} - -void gfs2_ea_header_print(struct gfs2_ea_header *ea, char *name) -{ - char buf[GFS2_EA_MAX_NAME_LEN + 1]; - - pv(ea, ea_rec_len, "%u"); - pv(ea, ea_data_len, "%u"); - pv(ea, ea_name_len, "%u"); - pv(ea, ea_type, "%u"); - pv(ea, ea_flags, "%u"); - pv(ea, ea_num_ptrs, "%u"); - - memset(buf, 0, GFS2_EA_MAX_NAME_LEN + 1); - memcpy(buf, name, ea->ea_name_len); - printk(KERN_INFO " name = %s\n", buf); -} - -#endif /* 0 */ - void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf) { struct gfs2_log_header *str = (struct gfs2_log_header *)buf; @@ -422,31 +260,6 @@ void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf) lh->lh_hash = be32_to_cpu(str->lh_hash); } -#if 0 - -void gfs2_log_header_print(struct gfs2_log_header *lh) -{ - gfs2_meta_header_print(&lh->lh_header); - pv(lh, lh_sequence, "%llu"); - pv(lh, lh_flags, "0x%.8X"); - pv(lh, lh_tail, "%u"); - pv(lh, lh_blkno, "%u"); - pv(lh, lh_hash, "0x%.8X"); -} - -void gfs2_log_descriptor_print(struct gfs2_log_descriptor *ld) -{ - gfs2_meta_header_print(&ld->ld_header); - pv(ld, ld_type, "%u"); - pv(ld, ld_length, "%u"); - pv(ld, ld_data1, "%u"); - pv(ld, ld_data2, "%u"); - - pa(ld, ld_reserved, 32); -} - -#endif /* 0 */ - void gfs2_inum_range_in(struct gfs2_inum_range *ir, char *buf) { struct gfs2_inum_range *str = (struct gfs2_inum_range *)buf; @@ -463,14 +276,6 @@ void gfs2_inum_range_out(struct gfs2_inum_range *ir, char *buf) str->ir_length = cpu_to_be64(ir->ir_length); } -#if 0 -void gfs2_inum_range_print(struct gfs2_inum_range *ir) -{ - pv(ir, ir_start, "%llu"); - pv(ir, ir_length, "%llu"); -} -#endif /* 0 */ - void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, char *buf) { struct gfs2_statfs_change *str = (struct gfs2_statfs_change *)buf; @@ -489,15 +294,6 @@ void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf) str->sc_dinodes = cpu_to_be64(sc->sc_dinodes); } -#if 0 -void gfs2_statfs_change_print(struct gfs2_statfs_change *sc) -{ - pv(sc, sc_total, "%lld"); - pv(sc, sc_free, "%lld"); - pv(sc, sc_dinodes, "%lld"); -} -#endif /* 0 */ - void gfs2_unlinked_tag_in(struct gfs2_unlinked_tag *ut, char *buf) { struct gfs2_unlinked_tag *str = (struct gfs2_unlinked_tag *)buf; @@ -515,16 +311,6 @@ void gfs2_unlinked_tag_out(struct gfs2_unlinked_tag *ut, char *buf) str->__pad = 0; } -#if 0 - -void gfs2_unlinked_tag_print(struct gfs2_unlinked_tag *ut) -{ - gfs2_inum_print(&ut->ut_inum); - pv(ut, ut_flags, "%u"); -} - -#endif /* 0 */ - void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf) { struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf; @@ -534,14 +320,3 @@ void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf) qc->qc_id = be32_to_cpu(str->qc_id); } -#if 0 - -void gfs2_quota_change_print(struct gfs2_quota_change *qc) -{ - pv(qc, qc_change, "%lld"); - pv(qc, qc_flags, "0x%.8X"); - pv(qc, qc_id, "%u"); -} - -#endif /* 0 */ - From d2d7b8a2a756fb520792ca3db3abdeed9214ae5b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 2 May 2006 12:09:42 -0400 Subject: [PATCH 103/292] [GFS2] Fix bug in writepage() As pointed out by Wendy Cheng, the logic in GFS2's writepage() function wasn't quite right with respect to invalidating pages when a file has been truncated. This patch fixes that. CC: Wendy Cheng Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 005c2522a879..afcc12a00a3c 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -126,7 +126,7 @@ static int gfs2_writepage(struct page *page, struct writeback_control *wbc) /* Is the page fully outside i_size? (truncate in progress) */ offset = i_size & (PAGE_CACHE_SIZE-1); - if (page->index >= end_index+1 || !offset) { + if (page->index > end_index || (page->index == end_index && !offset)) { page->mapping->a_ops->invalidatepage(page, 0); unlock_page(page); return 0; /* don't care */ From 97a35d1e5fab9ff8de27814082b78b2fc9ad94f0 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 2 May 2006 13:34:03 -0400 Subject: [PATCH 104/292] [DLM] fix grant_after_purge softlockup In dlm_grant_after_purge() we were holding a hash table read_lock while calling put_rsb() which potentially removes the rsb from the hash table, taking the same lock in write. Fix this by flagging rsb's ahead of time that have been purged. Then iteratively read_lock the hash table, find a flagged rsb, unlock, process rsb. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/dlm_internal.h | 1 + fs/dlm/lock.c | 42 ++++++++++++++++++++++++++++-------------- fs/dlm/lock.h | 2 +- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index c3299020c8f3..149106f2b80f 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -280,6 +280,7 @@ enum rsb_flags { RSB_NEW_MASTER, RSB_NEW_MASTER2, RSB_RECOVER_CONVERT, + RSB_LOCKS_PURGED, }; static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 85a0e73ba808..5f6963904107 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -3278,6 +3278,7 @@ static void purge_queue(struct dlm_rsb *r, struct list_head *queue, list_for_each_entry_safe(lkb, safe, queue, lkb_statequeue) { if (test(ls, lkb)) { + rsb_set_flag(r, RSB_LOCKS_PURGED); del_lkb(r, lkb); /* this put should free the lkb */ if (!dlm_put_lkb(lkb)) @@ -3334,27 +3335,40 @@ int dlm_purge_locks(struct dlm_ls *ls) return 0; } -int dlm_grant_after_purge(struct dlm_ls *ls) +static struct dlm_rsb *find_purged_rsb(struct dlm_ls *ls, int bucket) +{ + struct dlm_rsb *r, *r_ret = NULL; + + read_lock(&ls->ls_rsbtbl[bucket].lock); + list_for_each_entry(r, &ls->ls_rsbtbl[bucket].list, res_hashchain) { + if (!rsb_flag(r, RSB_LOCKS_PURGED)) + continue; + hold_rsb(r); + rsb_clear_flag(r, RSB_LOCKS_PURGED); + r_ret = r; + break; + } + read_unlock(&ls->ls_rsbtbl[bucket].lock); + return r_ret; +} + +void dlm_grant_after_purge(struct dlm_ls *ls) { struct dlm_rsb *r; int i; for (i = 0; i < ls->ls_rsbtbl_size; i++) { - read_lock(&ls->ls_rsbtbl[i].lock); - list_for_each_entry(r, &ls->ls_rsbtbl[i].list, res_hashchain) { - hold_rsb(r); - lock_rsb(r); - if (is_master(r)) { - grant_pending_locks(r); - confirm_master(r, 0); - } - unlock_rsb(r); - put_rsb(r); + r = find_purged_rsb(ls, i); + if (!r) + continue; + lock_rsb(r); + if (is_master(r)) { + grant_pending_locks(r); + confirm_master(r, 0); } - read_unlock(&ls->ls_rsbtbl[i].lock); + unlock_rsb(r); + put_rsb(r); } - - return 0; } static struct dlm_lkb *search_remid_list(struct list_head *head, int nodeid, diff --git a/fs/dlm/lock.h b/fs/dlm/lock.h index bffab9c88b1d..56cdc073b1f6 100644 --- a/fs/dlm/lock.h +++ b/fs/dlm/lock.h @@ -25,7 +25,7 @@ void dlm_scan_rsbs(struct dlm_ls *ls); int dlm_purge_locks(struct dlm_ls *ls); void dlm_purge_mstcpy_locks(struct dlm_rsb *r); -int dlm_grant_after_purge(struct dlm_ls *ls); +void dlm_grant_after_purge(struct dlm_ls *ls); int dlm_recover_waiters_post(struct dlm_ls *ls); void dlm_recover_waiters_pre(struct dlm_ls *ls); int dlm_recover_master_copy(struct dlm_ls *ls, struct dlm_rcom *rc); From 5bb76af1e089ac186c15c6aa792340d22b63d4b4 Mon Sep 17 00:00:00 2001 From: Robert S Peterson Date: Fri, 5 May 2006 16:29:50 -0400 Subject: [PATCH 105/292] [GFS2] Set d_ops for root inode Well, I managed to track down the bug in gfs2 that was causing my grief. Below is a patch for the problem. Please incorporate as you see fit. Or should I say: as you see git. The problem was basically that you never set d_ops for the root inode, so the wrong hash algorithm was being used. But only for the root directory. Turns out that if I used subdirectories, it used the proper hash and my files were found just fine. Signed-off-by: Robert S Peterson Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_fstype.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index d19d98766aa5..f252723b37da 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -40,6 +40,8 @@ #define DO 0 #define UNDO 1 +extern struct dentry_operations gfs2_dops; + static struct gfs2_sbd *init_sbd(struct super_block *sb) { struct gfs2_sbd *sdp; @@ -357,6 +359,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) error = -ENOMEM; iput(inode); } + sb->s_root->d_op = &gfs2_dops; out: gfs2_glock_dq_uninit(&sb_gh); return error; From fd88de569b802c4a04aaa6ee74667775f4aed8c6 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 5 May 2006 16:59:11 -0400 Subject: [PATCH 106/292] [GFS2] Readpages support This adds readpages support (and also corrects a small bug in the readpage error path at the same time). Hopefully this will improve performance by allowing GFS to submit larger lumps of I/O at a time. In order to simplify the setting of BH_Boundary, it currently gets set when we hit the end of a indirect pointer block. There is always a boundary at this point with the current allocation code. It doesn't get all the boundaries right though, so there is still room for improvement in this. See comments in fs/gfs2/ops_address.c for further information about readpages with GFS2. Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 170 +++++++++++++++++++++++++++--------------- fs/gfs2/bmap.h | 5 +- fs/gfs2/dir.c | 8 +- fs/gfs2/glock.c | 2 +- fs/gfs2/inode.c | 5 +- fs/gfs2/log.c | 4 +- fs/gfs2/ops_address.c | 145 ++++++++++++++++++++++++++++------- fs/gfs2/ops_super.c | 3 - fs/gfs2/ops_vm.c | 8 +- fs/gfs2/quota.c | 5 +- fs/gfs2/recovery.c | 8 +- fs/gfs2/rgrp.c | 15 ++-- fs/gfs2/unlinked.c | 5 +- 13 files changed, 254 insertions(+), 129 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index cfe1a428c668..474b9a16f0f5 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -314,13 +314,17 @@ static void find_metapath(struct gfs2_inode *ip, uint64_t block, * metadata tree. */ -static inline uint64_t *metapointer(struct buffer_head *bh, - unsigned int height, struct metapath *mp) +static inline u64 *metapointer(struct buffer_head *bh, int *boundary, + unsigned int height, const struct metapath *mp) { unsigned int head_size = (height > 0) ? sizeof(struct gfs2_meta_header) : sizeof(struct gfs2_dinode); - - return ((uint64_t *)(bh->b_data + head_size)) + mp->mp_list[height]; + u64 *ptr; + *boundary = 0; + ptr = ((u64 *)(bh->b_data + head_size)) + mp->mp_list[height]; + if (ptr + 1 == (u64*)(bh->b_data + bh->b_size)) + *boundary = 1; + return ptr; } /** @@ -339,24 +343,24 @@ static inline uint64_t *metapointer(struct buffer_head *bh, * */ -static void lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, - unsigned int height, struct metapath *mp, int create, - int *new, uint64_t *block) +static int lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, + unsigned int height, struct metapath *mp, int create, + int *new, uint64_t *block) { - uint64_t *ptr = metapointer(bh, height, mp); + int boundary; + uint64_t *ptr = metapointer(bh, &boundary, height, mp); if (*ptr) { *block = be64_to_cpu(*ptr); - return; + return boundary; } *block = 0; if (!create) - return; + return 0; - if (height == ip->i_di.di_height - 1 && - !gfs2_is_dir(ip)) + if (height == ip->i_di.di_height - 1 && !gfs2_is_dir(ip)) *block = gfs2_alloc_data(ip); else *block = gfs2_alloc_meta(ip); @@ -367,15 +371,16 @@ static void lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, ip->i_di.di_blocks++; *new = 1; + return 0; } /** - * gfs2_block_map - Map a block from an inode to a disk block - * @ip: The GFS2 inode + * gfs2_block_pointers - Map a block from an inode to a disk block + * @inode: The inode * @lblock: The logical block number * @new: Value/Result argument (1 = may create/did create new blocks) - * @dblock: the disk block number of the start of an extent - * @extlen: the size of the extent + * @boundary: gets set if we've hit a block boundary + * @mp: metapath to use * * Find the block number on the current device which corresponds to an * inode's block. If the block had to be created, "new" will be set. @@ -383,12 +388,14 @@ static void lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, * Returns: errno */ -int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, - uint64_t *dblock, uint32_t *extlen) +static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock, + int *new, u64 *dblock, + int *boundary, + struct metapath *mp) { + struct gfs2_inode *ip = inode->u.generic_ip; struct gfs2_sbd *sdp = ip->i_sbd; struct buffer_head *bh; - struct metapath mp; int create = *new; unsigned int bsize; unsigned int height; @@ -398,13 +405,6 @@ int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, *new = 0; *dblock = 0; - if (extlen) - *extlen = 0; - - if (create) - down_write(&ip->i_rw_mutex); - else - down_read(&ip->i_rw_mutex); if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) goto out; @@ -421,7 +421,7 @@ int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, goto out; } - find_metapath(ip, lblock, &mp); + find_metapath(ip, lblock, mp); end_of_metadata = ip->i_di.di_height - 1; error = gfs2_meta_inode_buffer(ip, &bh); @@ -429,7 +429,7 @@ int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, goto out; for (x = 0; x < end_of_metadata; x++) { - lookup_block(ip, bh, x, &mp, create, new, dblock); + lookup_block(ip, bh, x, mp, create, new, dblock); brelse(bh); if (!*dblock) goto out; @@ -439,49 +439,95 @@ int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new, goto out; } - lookup_block(ip, bh, end_of_metadata, &mp, create, new, dblock); - - if (extlen && *dblock) { - *extlen = 1; - - if (!*new) { - uint64_t tmp_dblock; - int tmp_new; - unsigned int nptrs; - - nptrs = (end_of_metadata) ? sdp->sd_inptrs : - sdp->sd_diptrs; - - while (++mp.mp_list[end_of_metadata] < nptrs) { - lookup_block(ip, bh, end_of_metadata, &mp, - 0, &tmp_new, &tmp_dblock); - - if (*dblock + *extlen != tmp_dblock) - break; - - (*extlen)++; - } - } - } - - brelse(bh); - + *boundary = lookup_block(ip, bh, end_of_metadata, mp, create, new, dblock); if (*new) { - error = gfs2_meta_inode_buffer(ip, &bh); + struct buffer_head *dibh; + error = gfs2_meta_inode_buffer(ip, &dibh); if (!error) { - gfs2_trans_add_bh(ip->i_gl, bh, 1); - gfs2_dinode_out(&ip->i_di, bh->b_data); - brelse(bh); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); } } + return bh; +out: + return ERR_PTR(error); +} - out: + +static inline void bmap_lock(struct inode *inode, int create) +{ + struct gfs2_inode *ip = inode->u.generic_ip; + if (create) + down_write(&ip->i_rw_mutex); + else + down_read(&ip->i_rw_mutex); +} + +static inline void bmap_unlock(struct inode *inode, int create) +{ + struct gfs2_inode *ip = inode->u.generic_ip; if (create) up_write(&ip->i_rw_mutex); else up_read(&ip->i_rw_mutex); +} - return error; +int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *boundary) +{ + struct metapath mp; + struct buffer_head *bh; + int create = *new; + + bmap_lock(inode, create); + bh = gfs2_block_pointers(inode, lblock, new, dblock, boundary, &mp); + bmap_unlock(inode, create); + if (!bh) + return 0; + if (IS_ERR(bh)) + return PTR_ERR(bh); + brelse(bh); + return 0; +} + +int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen) +{ + struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; + struct metapath mp; + struct buffer_head *bh; + int boundary; + int create = *new; + + BUG_ON(!extlen); + BUG_ON(!dblock); + BUG_ON(!new); + + bmap_lock(inode, create); + bh = gfs2_block_pointers(inode, lblock, new, dblock, &boundary, &mp); + *extlen = 1; + + if (bh && !IS_ERR(bh) && *dblock && !*new) { + u64 tmp_dblock; + int tmp_new; + unsigned int nptrs; + unsigned end_of_metadata = ip->i_di.di_height - 1; + + nptrs = (end_of_metadata) ? sdp->sd_inptrs : sdp->sd_diptrs; + while (++mp.mp_list[end_of_metadata] < nptrs) { + lookup_block(ip, bh, end_of_metadata, &mp, 0, &tmp_new, &tmp_dblock); + if (*dblock + *extlen != tmp_dblock) + break; + (*extlen)++; + } + } + bmap_unlock(inode, create); + if (!bh) + return 0; + if (IS_ERR(bh)) + return PTR_ERR(bh); + brelse(bh); + return 0; } /** @@ -1053,7 +1099,7 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, } for (; lblock < lblock_stop; lblock += extlen) { - error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); + error = gfs2_extent_map(ip->i_vnode, lblock, &new, &dblock, &extlen); if (error) return error; diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index 23fb6589d5e3..bc46c1149120 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -16,9 +16,8 @@ typedef int (*gfs2_unstuffer_t) (struct gfs2_inode * ip, int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, void *private); -int gfs2_block_map(struct gfs2_inode *ip, - uint64_t lblock, int *new, - uint64_t *dblock, uint32_t *extlen); +int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *boundary); +int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen); int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size); int gfs2_truncatei_resume(struct gfs2_inode *ip); diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 0404783f39b3..7f8b27e40916 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -197,8 +197,8 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, if (!extlen) { new = 1; - error = gfs2_block_map(ip, lblock, &new, &dblock, - &extlen); + error = gfs2_extent_map(ip->i_vnode, lblock, &new, + &dblock, &extlen); if (error) goto fail; error = -EIO; @@ -314,8 +314,8 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, if (!extlen) { new = 0; - error = gfs2_block_map(ip, lblock, &new, &dblock, - &extlen); + error = gfs2_extent_map(ip->i_vnode, lblock, &new, + &dblock, &extlen); if (error) goto fail; } diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 4fb8066dc745..9d4ae094fa2d 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -2125,7 +2125,7 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait) mutex_lock(&sdp->sd_invalidate_inodes_mutex); invalidate_inodes(sdp->sd_vfs); mutex_unlock(&sdp->sd_invalidate_inodes_mutex); - yield(); + msleep(10); } } diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 9084d6037a0c..0817f6ede188 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -1606,9 +1606,8 @@ int gfs2_glock_nq_atime(struct gfs2_holder *gh) curtime = get_seconds(); if (curtime - ip->i_di.di_atime >= quantum) { gfs2_glock_dq(gh); - gfs2_holder_reinit(LM_ST_EXCLUSIVE, - gh->gh_flags & ~LM_FLAG_ANY, - gh); + gfs2_holder_reinit(LM_ST_EXCLUSIVE, gh->gh_flags & ~LM_FLAG_ANY, + gh); error = gfs2_glock_nq(gh); if (error) return error; diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 134fc57e21d3..02d31e35f0ca 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -211,9 +211,9 @@ static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) int new = 0; uint64_t dbn; int error; + int bdy; - error = gfs2_block_map(sdp->sd_jdesc->jd_inode->u.generic_ip, - lbn, &new, &dbn, NULL); + error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, &new, &dbn, &bdy); gfs2_assert_withdraw(sdp, !error && dbn); return dbn; diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index afcc12a00a3c..d89179b316fe 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -47,12 +48,12 @@ int gfs2_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { - struct gfs2_inode *ip = inode->u.generic_ip; int new = create; uint64_t dblock; int error; + int boundary; - error = gfs2_block_map(ip, lblock, &new, &dblock, NULL); + error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary); if (error) return error; @@ -62,6 +63,8 @@ int gfs2_get_block(struct inode *inode, sector_t lblock, map_bh(bh_result, inode->i_sb, dblock); if (new) set_buffer_new(bh_result); + if (boundary) + set_buffer_boundary(bh_result); return 0; } @@ -83,8 +86,9 @@ static int get_block_noalloc(struct inode *inode, sector_t lblock, int new = 0; uint64_t dblock; int error; + int boundary; - error = gfs2_block_map(ip, lblock, &new, &dblock, NULL); + error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary); if (error) return error; @@ -92,6 +96,8 @@ static int get_block_noalloc(struct inode *inode, sector_t lblock, map_bh(bh_result, inode->i_sb, dblock); else if (gfs2_assert_withdraw(ip->i_sbd, !create)) error = -EIO; + if (boundary) + set_buffer_boundary(bh_result); return error; } @@ -151,6 +157,19 @@ out_ignore: return 0; } +static int zero_readpage(struct page *page) +{ + void *kaddr; + + kaddr = kmap_atomic(page, KM_USER0); + memset(kaddr, 0, PAGE_CACHE_SIZE); + kunmap_atomic(page, KM_USER0); + + SetPageUptodate(page); + + return 0; +} + /** * stuffed_readpage - Fill in a Linux page with stuffed file data * @ip: the inode @@ -165,17 +184,18 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page) void *kaddr; int error; + /* Only the first page of a stuffed file might contain data */ + if (unlikely(page->index)) + return zero_readpage(page); + error = gfs2_meta_inode_buffer(ip, &dibh); if (error) return error; kaddr = kmap_atomic(page, KM_USER0); - memcpy((char *)kaddr, - dibh->b_data + sizeof(struct gfs2_dinode), + memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), ip->i_di.di_size); - memset((char *)kaddr + ip->i_di.di_size, - 0, - PAGE_CACHE_SIZE - ip->i_di.di_size); + memset(kaddr + ip->i_di.di_size, 0, PAGE_CACHE_SIZE - ip->i_di.di_size); kunmap_atomic(page, KM_USER0); brelse(dibh); @@ -185,19 +205,6 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page) return 0; } -static int zero_readpage(struct page *page) -{ - void *kaddr; - - kaddr = kmap_atomic(page, KM_USER0); - memset(kaddr, 0, PAGE_CACHE_SIZE); - kunmap_atomic(page, KM_USER0); - - SetPageUptodate(page); - unlock_page(page); - - return 0; -} /** * gfs2_readpage - readpage with locking @@ -215,19 +222,16 @@ static int gfs2_readpage(struct file *file, struct page *page) struct gfs2_holder gh; int error; - if (file != &gfs2_internal_file_sentinal) { + if (likely(file != &gfs2_internal_file_sentinal)) { gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|GL_AOP, &gh); error = gfs2_glock_nq_m_atime(1, &gh); - if (error) + if (unlikely(error)) goto out_unlock; } if (gfs2_is_stuffed(ip)) { - if (!page->index) { - error = stuffed_readpage(ip, page); - unlock_page(page); - } else - error = zero_readpage(page); + error = stuffed_readpage(ip, page); + unlock_page(page); } else error = mpage_readpage(page, gfs2_get_block); @@ -242,6 +246,90 @@ out: return error; out_unlock: unlock_page(page); + if (file != &gfs2_internal_file_sentinal) + gfs2_holder_uninit(&gh); + goto out; +} + +#define list_to_page(head) (list_entry((head)->prev, struct page, lru)) + +/** + * gfs2_readpages - Read a bunch of pages at once + * + * Some notes: + * 1. This is only for readahead, so we can simply ignore any things + * which are slightly inconvenient (such as locking conflicts between + * the page lock and the glock) and return having done no I/O. Its + * obviously not something we'd want to do on too regular a basis. + * Any I/O we ignore at this time will be done via readpage later. + * 2. We have to handle stuffed files here too. + * 3. mpage_readpages() does most of the heavy lifting in the common case. + * 4. gfs2_get_block() is relied upon to set BH_Boundary in the right places. + * 5. We use LM_FLAG_TRY_1CB here, effectively we then have lock-ahead as + * well as read-ahead. + */ +static int gfs2_readpages(struct file *file, struct address_space *mapping, + struct list_head *pages, unsigned nr_pages) +{ + struct inode *inode = mapping->host; + struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_holder gh; + unsigned page_idx; + int ret; + + if (likely(file != &gfs2_internal_file_sentinal)) { + gfs2_holder_init(ip->i_gl, LM_ST_SHARED, + LM_FLAG_TRY_1CB|GL_ATIME|GL_AOP, &gh); + ret = gfs2_glock_nq_m_atime(1, &gh); + if (ret == GLR_TRYFAILED) + goto out_noerror; + if (unlikely(ret)) + goto out_unlock; + } + + if (gfs2_is_stuffed(ip)) { + struct pagevec lru_pvec; + pagevec_init(&lru_pvec, 0); + for (page_idx = 0; page_idx < nr_pages; page_idx++) { + struct page *page = list_to_page(pages); + list_del(&page->lru); + if (!add_to_page_cache(page, mapping, + page->index, GFP_KERNEL)) { + ret = stuffed_readpage(ip, page); + unlock_page(page); + if (!pagevec_add(&lru_pvec, page)) + __pagevec_lru_add(&lru_pvec); + } + page_cache_release(page); + } + pagevec_lru_add(&lru_pvec); + ret = 0; + } else { + /* What we really want to do .... */ + ret = mpage_readpages(mapping, pages, nr_pages, gfs2_get_block); + } + + if (likely(file != &gfs2_internal_file_sentinal)) { + gfs2_glock_dq_m(1, &gh); + gfs2_holder_uninit(&gh); + } +out: + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + ret = -EIO; + return ret; +out_noerror: + ret = 0; +out_unlock: + /* unlock all pages, we can't do any I/O right now */ + for (page_idx = 0; page_idx < nr_pages; page_idx++) { + struct page *page = list_to_page(pages); + list_del(&page->lru); + unlock_page(page); + page_cache_release(page); + } + if (likely(file != &gfs2_internal_file_sentinal)) + gfs2_holder_uninit(&gh); goto out; } @@ -572,6 +660,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, struct address_space_operations gfs2_file_aops = { .writepage = gfs2_writepage, .readpage = gfs2_readpage, + .readpages = gfs2_readpages, .sync_page = block_sync_page, .prepare_write = gfs2_prepare_write, .commit_write = gfs2_commit_write, diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 60bf2563c7b4..5910c7b5c846 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -92,7 +92,6 @@ static void gfs2_put_super(struct super_block *sb) if (error) gfs2_io_error(sdp); } - /* At this point, we're through modifying the disk */ /* Release stuff */ @@ -125,12 +124,10 @@ static void gfs2_put_super(struct super_block *sb) gfs2_jindex_free(sdp); /* Take apart glock structures and buffer lists */ gfs2_gl_hash_clear(sdp, WAIT); - /* Unmount the locking protocol */ gfs2_lm_unmount(sdp); /* At this point, we're through participating in the lockspace */ - gfs2_sys_fs_del(sdp); vfree(sdp); sb->s_fs_info = NULL; diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index dbc57071e7bb..d67248cae9b9 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -90,8 +90,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) if (error) goto out_gunlock_q; - gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, - &data_blocks, &ind_blocks); + gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks); al->al_requested = data_blocks + ind_blocks; @@ -99,8 +98,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) if (error) goto out_gunlock_q; - error = gfs2_trans_begin(sdp, - al->al_rgd->rd_ri.ri_length + + error = gfs2_trans_begin(sdp, al->al_rgd->rd_ri.ri_length + ind_blocks + RES_DINODE + RES_STATFS + RES_QUOTA, 0); if (error) @@ -117,7 +115,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) unsigned int extlen; int new = 1; - error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen); + error = gfs2_extent_map(ip->i_vnode, lblock, &new, &dblock, &extlen); if (error) goto out_trans; diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 942c4c8b9f56..d49ff43b3a86 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -255,6 +255,7 @@ static int bh_get(struct gfs2_quota_data *qd) int new = 0; struct buffer_head *bh; int error; + int boundary; mutex_lock(&sdp->sd_quota_mutex); @@ -266,7 +267,7 @@ static int bh_get(struct gfs2_quota_data *qd) block = qd->qd_slot / sdp->sd_qc_per_block; offset = qd->qd_slot % sdp->sd_qc_per_block;; - error = gfs2_block_map(ip, block, &new, &dblock, NULL); + error = gfs2_block_map(ip->i_vnode, block, &new, &dblock, &boundary); if (error) goto fail; error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh); @@ -1162,7 +1163,7 @@ int gfs2_quota_init(struct gfs2_sbd *sdp) if (!extlen) { int new = 0; - error = gfs2_block_map(ip, x, &new, &dblock, &extlen); + error = gfs2_extent_map(ip->i_vnode, x, &new, &dblock, &extlen); if (error) goto fail; } diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index d916817fb6e3..87adebea3bc3 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -40,8 +40,7 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, uint32_t extlen; int error; - error = gfs2_block_map(ip, blk, &new, &dblock, - &extlen); + error = gfs2_extent_map(ip->i_vnode, blk, &new, &dblock, &extlen); if (error) return error; if (!dblock) { @@ -378,10 +377,11 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) uint32_t hash; struct buffer_head *bh; int error; - + int boundary; + lblock = head->lh_blkno; gfs2_replay_incr_blk(sdp, &lblock); - error = gfs2_block_map(ip, lblock, &new, &dblock, NULL); + error = gfs2_block_map(ip->i_vnode, lblock, &new, &dblock, &boundary); if (error) return error; if (!dblock) { diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 4ae559694396..15c326ce13d1 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -956,8 +956,7 @@ static uint32_t rgblk_search(struct gfs2_rgrpd *rgd, uint32_t goal, search in the first part of our first-searched bit block. */ for (x = 0; x <= length; x++) { if (bi->bi_clone) - blk = gfs2_bitfit(rgd, - bi->bi_clone + bi->bi_offset, + blk = gfs2_bitfit(rgd, bi->bi_clone + bi->bi_offset, bi->bi_len, goal, old_state); else blk = gfs2_bitfit(rgd, @@ -976,12 +975,10 @@ static uint32_t rgblk_search(struct gfs2_rgrpd *rgd, uint32_t goal, blk = 0; gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); - gfs2_setbit(rgd, - bi->bi_bh->b_data + bi->bi_offset, + gfs2_setbit(rgd, bi->bi_bh->b_data + bi->bi_offset, bi->bi_len, blk, new_state); if (bi->bi_clone) - gfs2_setbit(rgd, - bi->bi_clone + bi->bi_offset, + gfs2_setbit(rgd, bi->bi_clone + bi->bi_offset, bi->bi_len, blk, new_state); return bi->bi_start * GFS2_NBBY + blk; @@ -1064,8 +1061,7 @@ uint64_t gfs2_alloc_data(struct gfs2_inode *ip) else goal = rgd->rd_last_alloc_data; - blk = rgblk_search(rgd, goal, - GFS2_BLKST_FREE, GFS2_BLKST_USED); + blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, GFS2_BLKST_USED); rgd->rd_last_alloc_data = blk; block = rgd->rd_ri.ri_data0 + blk; @@ -1109,8 +1105,7 @@ uint64_t gfs2_alloc_meta(struct gfs2_inode *ip) else goal = rgd->rd_last_alloc_meta; - blk = rgblk_search(rgd, goal, - GFS2_BLKST_FREE, GFS2_BLKST_USED); + blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, GFS2_BLKST_USED); rgd->rd_last_alloc_meta = blk; block = rgd->rd_ri.ri_data0 + blk; diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c index 24b91c23bc2d..0d2314a5252c 100644 --- a/fs/gfs2/unlinked.c +++ b/fs/gfs2/unlinked.c @@ -35,11 +35,12 @@ static int munge_ondisk(struct gfs2_sbd *sdp, unsigned int slot, int new = 0; struct buffer_head *bh; int error; + int boundary; block = slot / sdp->sd_ut_per_block; offset = slot % sdp->sd_ut_per_block; - error = gfs2_block_map(ip, block, &new, &dblock, NULL); + error = gfs2_block_map(ip->i_vnode, block, &new, &dblock, &boundary); if (error) return error; error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh); @@ -354,7 +355,7 @@ int gfs2_unlinked_init(struct gfs2_sbd *sdp) if (!extlen) { int new = 0; - error = gfs2_block_map(ip, x, &new, &dblock, &extlen); + error = gfs2_extent_map(ip->i_vnode, x, &new, &dblock, &extlen); if (error) goto fail; } From e90c01e148b967d30caf59e76accb3a58ca6b74b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 12 May 2006 12:09:15 -0400 Subject: [PATCH 107/292] [GFS2] Reverse block order in build_height The original code ordered the blocks allocated in the build_height routine backwards causing excessive disk seeks during a read of the metadata. This patch reverses the order to try and reduce disk seeks. Example: A five level metadata tree, I = Inode, P = Pointers, D = Data You need to read the blocks in the order: I P5 P4 P3 P2 P1 D in order to read a single data block. The new code now orders the blocks in this way. The old code used to order them as: I P1 P2 P3 P4 P5 D requiring two extra seeks on average. Note that for files which are grown by gradual extension rather than by truncate or by llseek/write at a large offset, this doesn't apply. In the case of writing to a file linearly, this routine will only be called upon to extend the height of the tree by one block at a time, so the ordering is determined by when its called rather than by the internals of the routine itself. Optimising that part of the ordering is a much harder problem. Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 106 ++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 58 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 474b9a16f0f5..31c3e92820e4 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -164,72 +164,62 @@ static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size) * @ip: The GFS2 inode * @height: The height to build to * - * This routine makes sure that the metadata tree is tall enough to hold - * "size" bytes of data. * * Returns: errno */ -static int build_height(struct gfs2_inode *ip, int height) +static int build_height(struct inode *inode, unsigned height) { - struct gfs2_sbd *sdp = ip->i_sbd; - struct buffer_head *bh, *dibh; - uint64_t block = 0, *bp; - unsigned int x; - int new_block; + struct gfs2_inode *ip = inode->u.generic_ip; + unsigned new_height = height - ip->i_di.di_height; + struct buffer_head *dibh; + struct buffer_head *blocks[GFS2_MAX_META_HEIGHT]; int error; + u64 *bp; + u64 bn; + unsigned n; - while (ip->i_di.di_height < height) { - error = gfs2_meta_inode_buffer(ip, &dibh); - if (error) - return error; + if (height <= ip->i_di.di_height) + return 0; - new_block = 0; - bp = (uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)); - for (x = 0; x < sdp->sd_diptrs; x++, bp++) - if (*bp) { - new_block = 1; - break; - } + error = gfs2_meta_inode_buffer(ip, &dibh); + if (error) + return error; - if (new_block) { - /* Get a new block, fill it with the old direct - pointers, and write it out */ - - block = gfs2_alloc_meta(ip); - - bh = gfs2_meta_new(ip->i_gl, block); - gfs2_trans_add_bh(ip->i_gl, bh, 1); - gfs2_metatype_set(bh, - GFS2_METATYPE_IN, - GFS2_FORMAT_IN); - gfs2_buffer_copy_tail(bh, - sizeof(struct gfs2_meta_header), - dibh, sizeof(struct gfs2_dinode)); - - brelse(bh); - } - - /* Set up the new direct pointer and write it out to disk */ - - gfs2_trans_add_bh(ip->i_gl, dibh, 1); - - gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); - - if (new_block) { - *(uint64_t *)(dibh->b_data + - sizeof(struct gfs2_dinode)) = - cpu_to_be64(block); - ip->i_di.di_blocks++; - } - - ip->i_di.di_height++; - - gfs2_dinode_out(&ip->i_di, dibh->b_data); - brelse(dibh); + for(n = 0; n < new_height; n++) { + bn = gfs2_alloc_meta(ip); + blocks[n] = gfs2_meta_new(ip->i_gl, bn); + gfs2_trans_add_bh(ip->i_gl, blocks[n], 1); } - - return 0; + + n = 0; + bn = blocks[0]->b_blocknr; + if (new_height > 1) { + for(; n < new_height-1; n++) { + gfs2_metatype_set(blocks[n], GFS2_METATYPE_IN, + GFS2_FORMAT_IN); + gfs2_buffer_clear_tail(blocks[n], + sizeof(struct gfs2_meta_header)); + bp = (u64 *)(blocks[n]->b_data + + sizeof(struct gfs2_meta_header)); + *bp = cpu_to_be64(blocks[n+1]->b_blocknr); + brelse(blocks[n]); + blocks[n] = NULL; + } + } + gfs2_metatype_set(blocks[n], GFS2_METATYPE_IN, GFS2_FORMAT_IN); + gfs2_buffer_copy_tail(blocks[n], sizeof(struct gfs2_meta_header), + dibh, sizeof(struct gfs2_dinode)); + brelse(blocks[n]); + gfs2_trans_add_bh(ip->i_gl, dibh, 1); + gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); + bp = (u64 *)(dibh->b_data + sizeof(struct gfs2_dinode)); + *bp = cpu_to_be64(bn); + ip->i_di.di_height += new_height; + ip->i_di.di_blocks += new_height; + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + return error; } /** @@ -416,7 +406,7 @@ static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock, if (!create) goto out; - error = build_height(ip, height); + error = build_height(inode, height); if (error) goto out; } @@ -806,7 +796,7 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size) h = calc_tree_height(ip, size); if (ip->i_di.di_height < h) { down_write(&ip->i_rw_mutex); - error = build_height(ip, h); + error = build_height(ip->i_vnode, h); up_write(&ip->i_rw_mutex); if (error) goto out_end_trans; From 9801f6461eb994e4eda29cba97f4596dffafbf32 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 12 May 2006 14:06:02 -0400 Subject: [PATCH 108/292] [GFS2] Remove incorrect initialisation of gh_owner The gh_owner field shouldn't be set or reset outside the glock code. These were left over from when recursive locking was allowed. It isn't any more, so they are not needed. Signed-off-by: Steven Whitehouse --- fs/gfs2/inode.c | 1 - fs/gfs2/ops_fstype.c | 5 ----- 2 files changed, 6 deletions(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 0817f6ede188..5522fa747297 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -319,7 +319,6 @@ static int inode_create(struct gfs2_glock *i_gl, const struct gfs2_inum *inum, if (error) goto fail; } - ip->i_iopen_gh.gh_owner = NULL; spin_lock(&io_gl->gl_spin); gfs2_glock_hold(i_gl); diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index f252723b37da..44c64effc964 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -468,11 +468,6 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) gfs2_glock_dq_uninit(&ji_gh); jindex = 0; - /* Disown my Journal glock */ - - sdp->sd_journal_gh.gh_owner = NULL; - sdp->sd_jinode_gh.gh_owner = NULL; - p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd"); error = IS_ERR(p); if (error) { From b9cb981310bc22f165726e99385c2d85196e2f41 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 12 May 2006 17:07:56 -0400 Subject: [PATCH 109/292] [GFS2] Fix attributes setting logic The attributes logic for immutable was wrong so that there was not way to remove this attribute once set. This fixes the bug. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index c2dbc300a50c..cf724800e0e9 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -611,8 +611,10 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); - if (error) + if (error) { + gfs2_holder_uninit(&gh); return error; + } flags = ip->i_di.di_flags; new_flags = (flags & ~mask) | (reqflags & mask); @@ -635,9 +637,14 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) goto out; if (IS_APPEND(inode) && (new_flags & GFS2_DIF_APPENDONLY)) goto out; - error = gfs2_repermission(inode, MAY_WRITE, NULL); - if (error) + if (((new_flags ^ flags) & GFS2_DIF_IMMUTABLE) && + !capable(CAP_LINUX_IMMUTABLE)) goto out; + if (!IS_IMMUTABLE(inode)) { + error = gfs2_repermission(inode, MAY_WRITE, NULL); + if (error) + goto out; + } error = gfs2_trans_begin(sdp, RES_DINODE, 0); if (error) From 64c14ea73b58e2c3759682d67eeb00d088355f08 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 16 May 2006 13:37:11 -0400 Subject: [PATCH 110/292] [GFS2] Fix ref count bug that used to bite us on umount The ref count of certain glock's got elevated too far during unlink which caused umount to fail. This fixes it. Signed-off-by: Steven Whitehouse --- fs/gfs2/inode.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 5522fa747297..5bc9542c7fcb 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -297,19 +297,13 @@ static int inode_create(struct gfs2_glock *i_gl, const struct gfs2_inum *inum, if (!ip) return -ENOMEM; memset(ip, 0, sizeof(struct gfs2_inode)); - ip->i_num = *inum; - atomic_set(&ip->i_count, 1); - ip->i_vn = i_gl->gl_vn - 1; - ip->i_gl = i_gl; ip->i_sbd = sdp; - spin_lock_init(&ip->i_spin); init_rwsem(&ip->i_rw_mutex); - ip->i_greedy = gfs2_tune_get(sdp, gt_greedy_default); if (need_lock) { @@ -318,27 +312,23 @@ static int inode_create(struct gfs2_glock *i_gl, const struct gfs2_inum *inum, &ip->i_iopen_gh); if (error) goto fail; - } - spin_lock(&io_gl->gl_spin); - gfs2_glock_hold(i_gl); - io_gl->gl_object = i_gl; - spin_unlock(&io_gl->gl_spin); + spin_lock(&io_gl->gl_spin); + gfs2_glock_hold(i_gl); + io_gl->gl_object = i_gl; + spin_unlock(&io_gl->gl_spin); + } gfs2_glock_hold(i_gl); i_gl->gl_object = ip; - atomic_inc(&sdp->sd_inode_count); - *ipp = ip; - return 0; - fail: +fail: gfs2_meta_cache_flush(ip); kmem_cache_free(gfs2_inode_cachep, ip); *ipp = NULL; - return error; } From 88c8ab1fcb53feadb8ebdcb4cda7e6137c6416bd Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 18 May 2006 13:52:39 -0400 Subject: [PATCH 111/292] [GFS2] Merge bits.[ch] into rgrp.c Since they are small and will be inlined by the complier, it makes sense to merge the contents of bits.[ch] into rgrp.c Signed-off-by: Steven Whitehouse --- fs/gfs2/bits.c | 182 ------------------------------------------------- fs/gfs2/bits.h | 28 -------- fs/gfs2/rgrp.c | 162 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 161 insertions(+), 211 deletions(-) delete mode 100644 fs/gfs2/bits.c delete mode 100644 fs/gfs2/bits.h diff --git a/fs/gfs2/bits.c b/fs/gfs2/bits.c deleted file mode 100644 index 49585e3de095..000000000000 --- a/fs/gfs2/bits.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -/* - * These routines are used by the resource group routines (rgrp.c) - * to keep track of block allocation. Each block is represented by two - * bits. One bit indicates whether or not the block is used. (1=used, - * 0=free) The other bit indicates whether or not the block contains a - * dinode or not. (1=dinode, 0=not-dinode) So, each byte represents - * GFS2_NBBY (i.e. 4) blocks. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "gfs2.h" -#include "lm_interface.h" -#include "incore.h" -#include "bits.h" -#include "util.h" - -static const char valid_change[16] = { - /* current */ - /* n */ 0, 1, 0, 1, - /* e */ 1, 0, 0, 0, - /* w */ 0, 0, 0, 0, - 1, 0, 0, 0 -}; - -/** - * gfs2_setbit - Set a bit in the bitmaps - * @buffer: the buffer that holds the bitmaps - * @buflen: the length (in bytes) of the buffer - * @block: the block to set - * @new_state: the new state of the block - * - */ - -void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, uint32_t block, unsigned char new_state) -{ - unsigned char *byte, *end, cur_state; - unsigned int bit; - - byte = buffer + (block / GFS2_NBBY); - bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; - end = buffer + buflen; - - gfs2_assert(rgd->rd_sbd, byte < end); - - cur_state = (*byte >> bit) & GFS2_BIT_MASK; - - if (valid_change[new_state * 4 + cur_state]) { - *byte ^= cur_state << bit; - *byte |= new_state << bit; - } else - gfs2_consist_rgrpd(rgd); -} - -/** - * gfs2_testbit - test a bit in the bitmaps - * @buffer: the buffer that holds the bitmaps - * @buflen: the length (in bytes) of the buffer - * @block: the block to read - * - */ - -unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, uint32_t block) -{ - unsigned char *byte, *end, cur_state; - unsigned int bit; - - byte = buffer + (block / GFS2_NBBY); - bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; - end = buffer + buflen; - - gfs2_assert(rgd->rd_sbd, byte < end); - - cur_state = (*byte >> bit) & GFS2_BIT_MASK; - - return cur_state; -} - -/** - * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing - * a block in a given allocation state. - * @buffer: the buffer that holds the bitmaps - * @buflen: the length (in bytes) of the buffer - * @goal: start search at this block's bit-pair (within @buffer) - * @old_state: GFS2_BLKST_XXX the state of the block we're looking for; - * bit 0 = alloc(1)/free(0), bit 1 = meta(1)/data(0) - * - * Scope of @goal and returned block number is only within this bitmap buffer, - * not entire rgrp or filesystem. @buffer will be offset from the actual - * beginning of a bitmap block buffer, skipping any header structures. - * - * Return: the block number (bitmap buffer scope) that was found - */ - -uint32_t gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, uint32_t goal, - unsigned char old_state) -{ - unsigned char *byte, *end, alloc; - uint32_t blk = goal; - unsigned int bit; - - byte = buffer + (goal / GFS2_NBBY); - bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE; - end = buffer + buflen; - alloc = (old_state & 1) ? 0 : 0x55; - - while (byte < end) { - if ((*byte & 0x55) == alloc) { - blk += (8 - bit) >> 1; - - bit = 0; - byte++; - - continue; - } - - if (((*byte >> bit) & GFS2_BIT_MASK) == old_state) - return blk; - - bit += GFS2_BIT_SIZE; - if (bit >= 8) { - bit = 0; - byte++; - } - - blk++; - } - - return BFITNOENT; -} - -/** - * gfs2_bitcount - count the number of bits in a certain state - * @buffer: the buffer that holds the bitmaps - * @buflen: the length (in bytes) of the buffer - * @state: the state of the block we're looking for - * - * Returns: The number of bits - */ - -uint32_t gfs2_bitcount(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, unsigned char state) -{ - unsigned char *byte = buffer; - unsigned char *end = buffer + buflen; - unsigned char state1 = state << 2; - unsigned char state2 = state << 4; - unsigned char state3 = state << 6; - uint32_t count = 0; - - for (; byte < end; byte++) { - if (((*byte) & 0x03) == state) - count++; - if (((*byte) & 0x0C) == state1) - count++; - if (((*byte) & 0x30) == state2) - count++; - if (((*byte) & 0xC0) == state3) - count++; - } - - return count; -} - diff --git a/fs/gfs2/bits.h b/fs/gfs2/bits.h deleted file mode 100644 index 36ccbdcb1eef..000000000000 --- a/fs/gfs2/bits.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#ifndef __BITS_DOT_H__ -#define __BITS_DOT_H__ - -#define BFITNOENT 0xFFFFFFFF - -void gfs2_setbit(struct gfs2_rgrpd *rgd, - unsigned char *buffer, unsigned int buflen, - uint32_t block, unsigned char new_state); -unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, - unsigned char *buffer, unsigned int buflen, - uint32_t block); -uint32_t gfs2_bitfit(struct gfs2_rgrpd *rgd, - unsigned char *buffer, unsigned int buflen, - uint32_t goal, unsigned char old_state); -uint32_t gfs2_bitcount(struct gfs2_rgrpd *rgd, - unsigned char *buffer, unsigned int buflen, - unsigned char state); - -#endif /* __BITS_DOT_H__ */ diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 15c326ce13d1..5a32d6932978 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -19,7 +19,6 @@ #include "gfs2.h" #include "lm_interface.h" #include "incore.h" -#include "bits.h" #include "glock.h" #include "glops.h" #include "lops.h" @@ -31,6 +30,167 @@ #include "ops_file.h" #include "util.h" +#define BFITNOENT 0xFFFFFFFF + +/* + * These routines are used by the resource group routines (rgrp.c) + * to keep track of block allocation. Each block is represented by two + * bits. One bit indicates whether or not the block is used. (1=used, + * 0=free) The other bit indicates whether or not the block contains a + * dinode or not. (1=dinode, 0=not-dinode) So, each byte represents + * GFS2_NBBY (i.e. 4) blocks. + */ + +static const char valid_change[16] = { + /* current */ + /* n */ 0, 1, 0, 1, + /* e */ 1, 0, 0, 0, + /* w */ 0, 0, 0, 0, + 1, 0, 0, 0 +}; + +/** + * gfs2_setbit - Set a bit in the bitmaps + * @buffer: the buffer that holds the bitmaps + * @buflen: the length (in bytes) of the buffer + * @block: the block to set + * @new_state: the new state of the block + * + */ + +void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, uint32_t block, unsigned char new_state) +{ + unsigned char *byte, *end, cur_state; + unsigned int bit; + + byte = buffer + (block / GFS2_NBBY); + bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; + end = buffer + buflen; + + gfs2_assert(rgd->rd_sbd, byte < end); + + cur_state = (*byte >> bit) & GFS2_BIT_MASK; + + if (valid_change[new_state * 4 + cur_state]) { + *byte ^= cur_state << bit; + *byte |= new_state << bit; + } else + gfs2_consist_rgrpd(rgd); +} + +/** + * gfs2_testbit - test a bit in the bitmaps + * @buffer: the buffer that holds the bitmaps + * @buflen: the length (in bytes) of the buffer + * @block: the block to read + * + */ + +unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, uint32_t block) +{ + unsigned char *byte, *end, cur_state; + unsigned int bit; + + byte = buffer + (block / GFS2_NBBY); + bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; + end = buffer + buflen; + + gfs2_assert(rgd->rd_sbd, byte < end); + + cur_state = (*byte >> bit) & GFS2_BIT_MASK; + + return cur_state; +} + +/** + * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing + * a block in a given allocation state. + * @buffer: the buffer that holds the bitmaps + * @buflen: the length (in bytes) of the buffer + * @goal: start search at this block's bit-pair (within @buffer) + * @old_state: GFS2_BLKST_XXX the state of the block we're looking for; + * bit 0 = alloc(1)/free(0), bit 1 = meta(1)/data(0) + * + * Scope of @goal and returned block number is only within this bitmap buffer, + * not entire rgrp or filesystem. @buffer will be offset from the actual + * beginning of a bitmap block buffer, skipping any header structures. + * + * Return: the block number (bitmap buffer scope) that was found + */ + +uint32_t gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, uint32_t goal, + unsigned char old_state) +{ + unsigned char *byte, *end, alloc; + uint32_t blk = goal; + unsigned int bit; + + byte = buffer + (goal / GFS2_NBBY); + bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE; + end = buffer + buflen; + alloc = (old_state & 1) ? 0 : 0x55; + + while (byte < end) { + if ((*byte & 0x55) == alloc) { + blk += (8 - bit) >> 1; + + bit = 0; + byte++; + + continue; + } + + if (((*byte >> bit) & GFS2_BIT_MASK) == old_state) + return blk; + + bit += GFS2_BIT_SIZE; + if (bit >= 8) { + bit = 0; + byte++; + } + + blk++; + } + + return BFITNOENT; +} + +/** + * gfs2_bitcount - count the number of bits in a certain state + * @buffer: the buffer that holds the bitmaps + * @buflen: the length (in bytes) of the buffer + * @state: the state of the block we're looking for + * + * Returns: The number of bits + */ + +uint32_t gfs2_bitcount(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, unsigned char state) +{ + unsigned char *byte = buffer; + unsigned char *end = buffer + buflen; + unsigned char state1 = state << 2; + unsigned char state2 = state << 4; + unsigned char state3 = state << 6; + uint32_t count = 0; + + for (; byte < end; byte++) { + if (((*byte) & 0x03) == state) + count++; + if (((*byte) & 0x0C) == state1) + count++; + if (((*byte) & 0x30) == state2) + count++; + if (((*byte) & 0xC0) == state3) + count++; + } + + return count; +} + /** * gfs2_rgrp_verify - Verify that a resource group is consistent * @sdp: the filesystem From 3efd7534a84a3eacb9d43e7f02fadeec4a5b79ff Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 18 May 2006 14:02:52 -0400 Subject: [PATCH 112/292] [GFS2] Make newly moved functions static The functions moved from bits.c can now be made static. Signed-off-by: Steven Whitehouse --- fs/gfs2/rgrp.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 5a32d6932978..6d918a7c6222 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -58,8 +58,9 @@ static const char valid_change[16] = { * */ -void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, uint32_t block, unsigned char new_state) +static void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, uint32_t block, + unsigned char new_state) { unsigned char *byte, *end, cur_state; unsigned int bit; @@ -87,8 +88,8 @@ void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, * */ -unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, uint32_t block) +static unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, uint32_t block) { unsigned char *byte, *end, cur_state; unsigned int bit; @@ -120,9 +121,9 @@ unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, * Return: the block number (bitmap buffer scope) that was found */ -uint32_t gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, uint32_t goal, - unsigned char old_state) +static uint32_t gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, uint32_t goal, + unsigned char old_state) { unsigned char *byte, *end, alloc; uint32_t blk = goal; @@ -167,8 +168,8 @@ uint32_t gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, * Returns: The number of bits */ -uint32_t gfs2_bitcount(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, unsigned char state) +static uint32_t gfs2_bitcount(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, unsigned char state) { unsigned char *byte = buffer; unsigned char *end = buffer + buflen; From 02f211f4d0e67794020ba1babbdaf7c45d56db45 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 18 May 2006 14:03:43 -0400 Subject: [PATCH 113/292] [GFS2] Remove bits.c from the Makefile Signed-off-by: Steven Whitehouse --- fs/gfs2/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile index 66de2cc7bb5a..9974201aa16c 100644 --- a/fs/gfs2/Makefile +++ b/fs/gfs2/Makefile @@ -1,5 +1,5 @@ obj-$(CONFIG_GFS2_FS) += gfs2.o -gfs2-y := acl.o bits.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \ +gfs2-y := acl.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \ glops.o inode.o lm.o log.o lops.o locking.o lvb.o main.o meta_io.o \ mount.o ondisk.o ops_address.o ops_dentry.o ops_export.o ops_file.o \ ops_fstype.o ops_inode.o ops_super.o ops_vm.o page.o quota.o \ From 1b50259bc33f2adfcb4c5fba4b740bf80789df22 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 18 May 2006 14:10:52 -0400 Subject: [PATCH 114/292] [GFS2] Drop log lock on I/O error & tidy up This patch drops the log spinlock when an I/O error occurs to avoid any possible problems in case of blocking or recursion in the I/O error routine. It also has a few cosmetic changes to tidy up various other files. Signed-off-by: Steven Whitehouse --- fs/gfs2/meta_io.c | 5 ++++- fs/gfs2/ops_inode.c | 5 ++--- fs/gfs2/page.c | 6 ++---- fs/gfs2/unlinked.c | 17 +++++++++-------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index da49973a90d1..fe46d563d3c8 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -226,8 +226,11 @@ void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) gfs2_assert(sdp, bd->bd_ail == ai); if (!buffer_busy(bh)) { - if (!buffer_uptodate(bh)) + if (!buffer_uptodate(bh)) { + gfs2_log_unlock(sdp); gfs2_io_error_bh(sdp, bh); + gfs2_log_lock(sdp); + } list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); continue; diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 62a12a59d91b..b25ec4c8e56a 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -213,8 +213,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, if (error) goto out_gunlock_q; - error = gfs2_trans_begin(sdp, - sdp->sd_max_dirres + + error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + al->al_rgd->rd_ri.ri_length + 2 * RES_DINODE + RES_STATFS + RES_QUOTA, 0); @@ -303,7 +302,7 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry) if (error) goto out_gunlock; - error = gfs2_unlinki(dip, &dentry->d_name, ip,ul); + error = gfs2_unlinki(dip, &dentry->d_name, ip, ul); gfs2_trans_end(sdp); diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c index a2c9e93c7c39..495db5594164 100644 --- a/fs/gfs2/page.c +++ b/fs/gfs2/page.c @@ -155,11 +155,9 @@ int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, if (!PageUptodate(page)) { void *kaddr = kmap(page); - memcpy(kaddr, - dibh->b_data + sizeof(struct gfs2_dinode), + memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), ip->i_di.di_size); - memset(kaddr + ip->i_di.di_size, - 0, + memset(kaddr + ip->i_di.di_size, 0, PAGE_CACHE_SIZE - ip->i_di.di_size); kunmap(page); diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c index 0d2314a5252c..2824b1665f95 100644 --- a/fs/gfs2/unlinked.c +++ b/fs/gfs2/unlinked.c @@ -130,11 +130,12 @@ static void enforce_limit(struct gfs2_sbd *sdp) unsigned int tries = 0, min = 0; int error; - if (atomic_read(&sdp->sd_unlinked_count) >= - gfs2_tune_get(sdp, gt_ilimit)) { - tries = gfs2_tune_get(sdp, gt_ilimit_tries); - min = gfs2_tune_get(sdp, gt_ilimit_min); - } + if (atomic_read(&sdp->sd_unlinked_count) < + gfs2_tune_get(sdp, gt_ilimit)) + return; + + tries = gfs2_tune_get(sdp, gt_ilimit_tries); + min = gfs2_tune_get(sdp, gt_ilimit_min); while (tries--) { struct gfs2_unlinked *ul = ul_fish(sdp); @@ -187,7 +188,7 @@ int gfs2_unlinked_get(struct gfs2_sbd *sdp, struct gfs2_unlinked **ul) goto fail; - found: +found: for (b = 0; b < 8; b++) if (!(byte & (1 << b))) break; @@ -202,7 +203,7 @@ int gfs2_unlinked_get(struct gfs2_sbd *sdp, struct gfs2_unlinked **ul) return 0; - fail: +fail: spin_unlock(&sdp->sd_unlinked_spin); kfree(*ul); return -ENOSPC; @@ -410,7 +411,7 @@ int gfs2_unlinked_init(struct gfs2_sbd *sdp) return 0; - fail: +fail: gfs2_unlinked_cleanup(sdp); return error; } From bd8968010a9a08e67a0ddb3ddee9feb8882e8c2f Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 18 May 2006 14:54:58 -0400 Subject: [PATCH 115/292] [GFS2] Remove semaphore.h from C files We no longer use semaphores, everything has been converted to mutex or rwsem, so we don't need to include this header any more. Signed-off-by: Steven Whitehouse --- fs/gfs2/acl.c | 1 - fs/gfs2/bmap.c | 1 - fs/gfs2/daemon.c | 1 - fs/gfs2/eaops.c | 1 - fs/gfs2/eattr.c | 1 - fs/gfs2/glock.c | 1 - fs/gfs2/glops.c | 1 - fs/gfs2/inode.c | 1 - fs/gfs2/lm.c | 1 - fs/gfs2/log.c | 1 - fs/gfs2/lops.c | 1 - fs/gfs2/lvb.c | 1 - fs/gfs2/main.c | 1 - fs/gfs2/meta_io.c | 1 - fs/gfs2/mount.c | 1 - fs/gfs2/ondisk.c | 1 - fs/gfs2/ops_address.c | 1 - fs/gfs2/ops_dentry.c | 1 - fs/gfs2/ops_export.c | 1 - fs/gfs2/ops_file.c | 1 - fs/gfs2/ops_fstype.c | 1 - fs/gfs2/ops_inode.c | 1 - fs/gfs2/ops_super.c | 1 - fs/gfs2/ops_vm.c | 1 - fs/gfs2/page.c | 1 - fs/gfs2/quota.c | 1 - fs/gfs2/recovery.c | 1 - fs/gfs2/rgrp.c | 1 - fs/gfs2/super.c | 1 - fs/gfs2/sys.c | 1 - fs/gfs2/trans.c | 1 - fs/gfs2/unlinked.c | 1 - fs/gfs2/util.c | 1 - 33 files changed, 33 deletions(-) diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index e9d05fe94357..d822256c7a53 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include "gfs2.h" diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 31c3e92820e4..32b1d66e68e1 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c index c2b5d69044c6..aa4d13002bb4 100644 --- a/fs/gfs2/daemon.c +++ b/fs/gfs2/daemon.c @@ -15,7 +15,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index 1b376eceb6af..e5e2565ac292 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include "gfs2.h" diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index af4f1c3f5929..3930304bc511 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include "gfs2.h" diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 9d4ae094fa2d..2029df4b349f 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include "gfs2.h" diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index d180c89dd567..5e8ec6a61824 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -13,7 +13,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 5bc9542c7fcb..d218cbf98aa7 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -16,7 +16,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index 06a785e9b582..600b2bc48ba9 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 02d31e35f0ca..0e5e9cf9dd46 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 4d90eb311497..22a4f038e3b9 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -13,7 +13,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/lvb.c b/fs/gfs2/lvb.c index 47867db92ea1..a56b23e0a3f1 100644 --- a/fs/gfs2/lvb.c +++ b/fs/gfs2/lvb.c @@ -13,7 +13,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index c8d17b7ba60b..b0a4582e78db 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -15,7 +15,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index fe46d563d3c8..92c1a3f823d8 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -18,7 +18,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c index e90ea7d32f9e..7e001356824e 100644 --- a/fs/gfs2/mount.c +++ b/fs/gfs2/mount.c @@ -13,7 +13,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index f6aba3b156c2..90d398d2d047 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -12,7 +12,6 @@ #include #include #include -#include #include "gfs2.h" #include diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index d89179b316fe..6d2fc107bbd3 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -17,7 +17,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index 958371076093..6cbff891063e 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -15,7 +15,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index be16c68263d1..a90397f28196 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index cf724800e0e9..00522fc927cd 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include "gfs2.h" diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 44c64effc964..5899ac33451c 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -16,7 +16,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index b25ec4c8e56a..c8aeaafec50f 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include "gfs2.h" diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 5910c7b5c846..3661b2f25b8f 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -19,7 +19,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index d67248cae9b9..23161be5db1f 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -15,7 +15,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c index 495db5594164..bc80247060f4 100644 --- a/fs/gfs2/page.c +++ b/fs/gfs2/page.c @@ -15,7 +15,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index d49ff43b3a86..adfb8062f5de 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -45,7 +45,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 87adebea3bc3..527544b68a6f 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 6d918a7c6222..1b1a2aee8f6b 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 75a8def8d0bc..788dbea45c87 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index f05ba8f69132..bbfa9e16abc3 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include "gfs2.h" diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 18c606d07126..a4c414c59351 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c index 2824b1665f95..9ed0a6b8fc63 100644 --- a/fs/gfs2/unlinked.c +++ b/fs/gfs2/unlinked.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "gfs2.h" #include "lm_interface.h" diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 7cd9e25639c4..7c3806c67406 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include "gfs2.h" From 3a8a9a1034813aa99f5ae3150f652d490c5ff10d Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 18 May 2006 15:09:15 -0400 Subject: [PATCH 116/292] [GFS2] Update copyright date to 2006 Signed-off-by: Steven Whitehouse --- fs/gfs2/acl.c | 2 +- fs/gfs2/acl.h | 2 +- fs/gfs2/bmap.c | 2 +- fs/gfs2/bmap.h | 2 +- fs/gfs2/daemon.c | 2 +- fs/gfs2/daemon.h | 2 +- fs/gfs2/dir.c | 2 +- fs/gfs2/dir.h | 2 +- fs/gfs2/eaops.c | 2 +- fs/gfs2/eaops.h | 2 +- fs/gfs2/eattr.c | 2 +- fs/gfs2/eattr.h | 2 +- fs/gfs2/format.h | 2 +- fs/gfs2/gfs2.h | 2 +- fs/gfs2/glock.c | 2 +- fs/gfs2/glock.h | 2 +- fs/gfs2/glops.c | 2 +- fs/gfs2/glops.h | 2 +- fs/gfs2/incore.h | 2 +- fs/gfs2/inode.c | 2 +- fs/gfs2/inode.h | 2 +- fs/gfs2/lm.c | 2 +- fs/gfs2/lm.h | 2 +- fs/gfs2/lm_interface.h | 2 +- fs/gfs2/locking.c | 2 +- fs/gfs2/log.c | 2 +- fs/gfs2/log.h | 2 +- fs/gfs2/lops.c | 2 +- fs/gfs2/lops.h | 2 +- fs/gfs2/lvb.c | 2 +- fs/gfs2/lvb.h | 2 +- fs/gfs2/main.c | 2 +- fs/gfs2/meta_io.c | 2 +- fs/gfs2/meta_io.h | 2 +- fs/gfs2/mount.c | 2 +- fs/gfs2/mount.h | 2 +- fs/gfs2/ondisk.c | 2 +- fs/gfs2/ops_address.c | 2 +- fs/gfs2/ops_address.h | 2 +- fs/gfs2/ops_dentry.c | 2 +- fs/gfs2/ops_dentry.h | 2 +- fs/gfs2/ops_export.c | 2 +- fs/gfs2/ops_export.h | 2 +- fs/gfs2/ops_file.c | 2 +- fs/gfs2/ops_file.h | 2 +- fs/gfs2/ops_fstype.c | 2 +- fs/gfs2/ops_fstype.h | 2 +- fs/gfs2/ops_inode.c | 2 +- fs/gfs2/ops_inode.h | 2 +- fs/gfs2/ops_super.c | 2 +- fs/gfs2/ops_super.h | 2 +- fs/gfs2/ops_vm.c | 2 +- fs/gfs2/ops_vm.h | 2 +- fs/gfs2/page.c | 2 +- fs/gfs2/page.h | 2 +- fs/gfs2/quota.c | 2 +- fs/gfs2/quota.h | 2 +- fs/gfs2/recovery.c | 2 +- fs/gfs2/recovery.h | 2 +- fs/gfs2/rgrp.c | 2 +- fs/gfs2/rgrp.h | 2 +- fs/gfs2/super.c | 2 +- fs/gfs2/super.h | 2 +- fs/gfs2/sys.c | 2 +- fs/gfs2/sys.h | 2 +- fs/gfs2/trans.c | 2 +- fs/gfs2/trans.h | 2 +- fs/gfs2/unlinked.c | 2 +- fs/gfs2/unlinked.h | 2 +- fs/gfs2/util.c | 2 +- fs/gfs2/util.h | 2 +- 71 files changed, 71 insertions(+), 71 deletions(-) diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index d822256c7a53..343dbe3e87bb 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/acl.h b/fs/gfs2/acl.h index a174b4f6bcc2..067105786eaa 100644 --- a/fs/gfs2/acl.h +++ b/fs/gfs2/acl.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 32b1d66e68e1..41abd3f4fc73 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index bc46c1149120..06ccb2d808ad 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c index aa4d13002bb4..9e7b9f296786 100644 --- a/fs/gfs2/daemon.c +++ b/fs/gfs2/daemon.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/daemon.h b/fs/gfs2/daemon.h index a27fdeda5fbb..aa68e7a1b0b7 100644 --- a/fs/gfs2/daemon.h +++ b/fs/gfs2/daemon.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 7f8b27e40916..6918a58261e2 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h index d209f1fcb8ac..173403095eb2 100644 --- a/fs/gfs2/dir.h +++ b/fs/gfs2/dir.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index e5e2565ac292..85c1dbace88b 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/eaops.h b/fs/gfs2/eaops.h index 30ec6a09bfd0..3dece17e3116 100644 --- a/fs/gfs2/eaops.h +++ b/fs/gfs2/eaops.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 3930304bc511..f5169a42a919 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/eattr.h b/fs/gfs2/eattr.h index ffd56686225b..19fb1dc4ddc4 100644 --- a/fs/gfs2/eattr.h +++ b/fs/gfs2/eattr.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/format.h b/fs/gfs2/format.h index c7bf32ce3eca..239f0c3553fc 100644 --- a/fs/gfs2/format.h +++ b/fs/gfs2/format.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/gfs2.h b/fs/gfs2/gfs2.h index 57175f70e2bd..6edbd551a4c0 100644 --- a/fs/gfs2/gfs2.h +++ b/fs/gfs2/gfs2.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 2029df4b349f..c04159031538 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index a36b26585fb8..9df09c7eeb95 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 5e8ec6a61824..e262f22f744e 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/glops.h b/fs/gfs2/glops.h index 94f2d264aa64..5c1e9491024f 100644 --- a/fs/gfs2/glops.h +++ b/fs/gfs2/glops.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 84dd2f579e62..fc4a983e3c89 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index d218cbf98aa7..27fbcd9b12f0 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index 13bc4eacac6b..5ef21317b2f6 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index 600b2bc48ba9..f45c0ffd1c35 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/lm.h b/fs/gfs2/lm.h index 4ee5c34434bc..e821101d19c0 100644 --- a/fs/gfs2/lm.h +++ b/fs/gfs2/lm.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/lm_interface.h b/fs/gfs2/lm_interface.h index 378432f17f27..9d34bf3df103 100644 --- a/fs/gfs2/lm_interface.h +++ b/fs/gfs2/lm_interface.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c index 6a78aacb26af..183192836e98 100644 --- a/fs/gfs2/locking.c +++ b/fs/gfs2/locking.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 0e5e9cf9dd46..2a8b4b71dd1f 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h index 84a3e902e848..8cfd0f1d29f8 100644 --- a/fs/gfs2/log.h +++ b/fs/gfs2/log.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 22a4f038e3b9..e4c75a74df5b 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h index 0c78d222d6f2..8a1029d3d389 100644 --- a/fs/gfs2/lops.h +++ b/fs/gfs2/lops.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/lvb.c b/fs/gfs2/lvb.c index a56b23e0a3f1..e88e9cce14e7 100644 --- a/fs/gfs2/lvb.c +++ b/fs/gfs2/lvb.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/lvb.h b/fs/gfs2/lvb.h index 3c4c17405e9a..1b1a8b75219a 100644 --- a/fs/gfs2/lvb.h +++ b/fs/gfs2/lvb.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index b0a4582e78db..9ce56b5c7803 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 92c1a3f823d8..b9895bbd5feb 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index d72144d5d727..23c6a596fd9e 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c index 7e001356824e..0d4b230785af 100644 --- a/fs/gfs2/mount.c +++ b/fs/gfs2/mount.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/mount.h b/fs/gfs2/mount.h index bc8331cd7b2c..2eb14722144f 100644 --- a/fs/gfs2/mount.h +++ b/fs/gfs2/mount.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index 90d398d2d047..b3bc21a6ba07 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 6d2fc107bbd3..16d3ebd32092 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h index f201a059fd91..b88adddaffb2 100644 --- a/fs/gfs2/ops_address.h +++ b/fs/gfs2/ops_address.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index 6cbff891063e..fef415e2068e 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_dentry.h b/fs/gfs2/ops_dentry.h index 94e3ee170165..1b6e75c0a4a7 100644 --- a/fs/gfs2/ops_dentry.h +++ b/fs/gfs2/ops_dentry.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index a90397f28196..a376ead7d0cd 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_export.h b/fs/gfs2/ops_export.h index 2f342f3d8755..88d58e57f518 100644 --- a/fs/gfs2/ops_export.h +++ b/fs/gfs2/ops_export.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 00522fc927cd..1e8f602c1e50 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_file.h b/fs/gfs2/ops_file.h index 192577b411f0..a2edce38f5cb 100644 --- a/fs/gfs2/ops_file.h +++ b/fs/gfs2/ops_file.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 5899ac33451c..a45982045509 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_fstype.h b/fs/gfs2/ops_fstype.h index c6452874483d..622f5760d6b2 100644 --- a/fs/gfs2/ops_fstype.h +++ b/fs/gfs2/ops_fstype.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index c8aeaafec50f..0c06f92368f2 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_inode.h b/fs/gfs2/ops_inode.h index 5fafd87c8d7b..930aaae91377 100644 --- a/fs/gfs2/ops_inode.h +++ b/fs/gfs2/ops_inode.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 3661b2f25b8f..6fa7b8649f14 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_super.h b/fs/gfs2/ops_super.h index a41d208dc558..a15ccc276113 100644 --- a/fs/gfs2/ops_super.h +++ b/fs/gfs2/ops_super.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index 23161be5db1f..263c1fb7bbaf 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/ops_vm.h b/fs/gfs2/ops_vm.h index 54e3a8769cbb..077cffcd4085 100644 --- a/fs/gfs2/ops_vm.h +++ b/fs/gfs2/ops_vm.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c index bc80247060f4..cd93644c7d70 100644 --- a/fs/gfs2/page.c +++ b/fs/gfs2/page.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/page.h b/fs/gfs2/page.h index 346e296420c6..2c853a90ac04 100644 --- a/fs/gfs2/page.h +++ b/fs/gfs2/page.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index adfb8062f5de..f752b0184690 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h index 1baeeb23d232..af05492f9644 100644 --- a/fs/gfs2/quota.h +++ b/fs/gfs2/quota.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 527544b68a6f..c504ac1b831d 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/recovery.h b/fs/gfs2/recovery.h index 248481189300..ac0f1d6ce456 100644 --- a/fs/gfs2/recovery.h +++ b/fs/gfs2/recovery.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 1b1a2aee8f6b..c1c6fa9c0e4b 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h index 4c44a191b1c1..d2db3719cc0f 100644 --- a/fs/gfs2/rgrp.h +++ b/fs/gfs2/rgrp.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 788dbea45c87..a943a505bc5a 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/super.h b/fs/gfs2/super.h index 175afdde43bb..df2495230402 100644 --- a/fs/gfs2/super.h +++ b/fs/gfs2/super.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index bbfa9e16abc3..d32a2c54daee 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/sys.h b/fs/gfs2/sys.h index 62c8ed89ab9c..c46a700e801e 100644 --- a/fs/gfs2/sys.h +++ b/fs/gfs2/sys.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index a4c414c59351..05e0b72d56ff 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h index 6b5e9e8bf561..60ef163dd9bb 100644 --- a/fs/gfs2/trans.h +++ b/fs/gfs2/trans.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c index 9ed0a6b8fc63..b92d73002055 100644 --- a/fs/gfs2/unlinked.c +++ b/fs/gfs2/unlinked.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/unlinked.h b/fs/gfs2/unlinked.h index 51e77f88d74f..159cf5ffe47e 100644 --- a/fs/gfs2/unlinked.h +++ b/fs/gfs2/unlinked.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 7c3806c67406..0b37d6bcc36e 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index 4532dbab0a2c..8216d28bd816 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -1,6 +1,6 @@ /* * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions From 320dd101e2d595a03439adb92b319f3af53dd1d0 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 18 May 2006 16:25:27 -0400 Subject: [PATCH 117/292] [GFS2] glock debugging and inode cache changes This adds some extra debugging to glock.c and changes inode.c's deallocation code to call the debugging code at a suitable moment. I'm chasing down a particular bug to do with deallocation at the moment and the code can go again once the bug is fixed. Also this includes the first part of some changes to unify the Linux struct inode and GFS2's struct gfs2_inode. This transformation will happen in small parts over the next short period. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 26 ++++++++++++++++---- fs/gfs2/glock.h | 1 + fs/gfs2/incore.h | 8 +++++++ fs/gfs2/inode.c | 58 ++++++++++++++++----------------------------- fs/gfs2/main.c | 18 +++++++++++++- fs/gfs2/ops_super.c | 24 +++++++++++++++++++ 6 files changed, 92 insertions(+), 43 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index c04159031538..2ef8accf1cbc 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -47,6 +47,7 @@ struct greedy { typedef void (*glock_examiner) (struct gfs2_glock * gl); static int gfs2_dump_lockstate(struct gfs2_sbd *sdp); +static int dump_glock(struct gfs2_glock *gl); /** * relaxed_state_ok - is a requested lock compatible with the current lock mode? @@ -290,6 +291,8 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, spin_lock_init(&gl->gl_spin); gl->gl_state = LM_ST_UNLOCKED; + gl->gl_owner = NULL; + gl->gl_ip = 0; INIT_LIST_HEAD(&gl->gl_holders); INIT_LIST_HEAD(&gl->gl_waiters1); INIT_LIST_HEAD(&gl->gl_waiters2); @@ -661,8 +664,11 @@ void gfs2_glmutex_lock(struct gfs2_glock *gl) spin_lock(&gl->gl_spin); if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) list_add_tail(&gh.gh_list, &gl->gl_waiters1); - else + else { + gl->gl_owner = current; + gl->gl_ip = (unsigned long)__builtin_return_address(0); complete(&gh.gh_wait); + } spin_unlock(&gl->gl_spin); wait_for_completion(&gh.gh_wait); @@ -683,6 +689,10 @@ static int gfs2_glmutex_trylock(struct gfs2_glock *gl) spin_lock(&gl->gl_spin); if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) acquired = 0; + else { + gl->gl_owner = current; + gl->gl_ip = (unsigned long)__builtin_return_address(0); + } spin_unlock(&gl->gl_spin); return acquired; @@ -698,6 +708,8 @@ void gfs2_glmutex_unlock(struct gfs2_glock *gl) { spin_lock(&gl->gl_spin); clear_bit(GLF_LOCK, &gl->gl_flags); + gl->gl_owner = NULL; + gl->gl_ip = 0; run_queue(gl); BUG_ON(!spin_is_locked(&gl->gl_spin)); spin_unlock(&gl->gl_spin); @@ -1173,7 +1185,7 @@ int gfs2_glock_nq(struct gfs2_holder *gh) struct gfs2_sbd *sdp = gl->gl_sbd; int error = 0; - restart: +restart: if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) { set_bit(HIF_ABORTED, &gh->gh_iflags); return -EIO; @@ -1196,6 +1208,9 @@ int gfs2_glock_nq(struct gfs2_holder *gh) clear_bit(GLF_PREFETCH, &gl->gl_flags); + if (error == GLR_TRYFAILED && (gh->gh_flags & GL_DUMP)) + dump_glock(gl); + return error; } @@ -2212,9 +2227,8 @@ static int dump_glock(struct gfs2_glock *gl) spin_lock(&gl->gl_spin); - printk(KERN_INFO "Glock (%u, %llu)\n", - gl->gl_name.ln_type, - gl->gl_name.ln_number); + printk(KERN_INFO "Glock (%u, %llu)\n", gl->gl_name.ln_type, + gl->gl_name.ln_number); printk(KERN_INFO " gl_flags ="); for (x = 0; x < 32; x++) if (test_bit(x, &gl->gl_flags)) @@ -2222,6 +2236,8 @@ static int dump_glock(struct gfs2_glock *gl) printk(" \n"); printk(KERN_INFO " gl_ref = %d\n", atomic_read(&gl->gl_ref.refcount)); printk(KERN_INFO " gl_state = %u\n", gl->gl_state); + printk(KERN_INFO " gl_owner = %s\n", gl->gl_owner->comm); + print_symbol(KERN_INFO " gl_ip = %s\n", gl->gl_ip); printk(KERN_INFO " req_gh = %s\n", (gl->gl_req_gh) ? "yes" : "no"); printk(KERN_INFO " req_bh = %s\n", (gl->gl_req_bh) ? "yes" : "no"); printk(KERN_INFO " lvb_count = %d\n", atomic_read(&gl->gl_lvb_count)); diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 9df09c7eeb95..2e0a2ba92aa0 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -27,6 +27,7 @@ #define GL_SYNC 0x00000800 #define GL_NOCANCEL 0x00001000 #define GL_AOP 0x00004000 +#define GL_DUMP 0x00008000 #define GLR_TRYFAILED 13 #define GLR_CANCELED 14 diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index fc4a983e3c89..92091d006a02 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -183,6 +183,8 @@ struct gfs2_glock { spinlock_t gl_spin; unsigned int gl_state; + struct task_struct *gl_owner; + unsigned long gl_ip; struct list_head gl_holders; struct list_head gl_waiters1; /* HIF_MUTEX */ struct list_head gl_waiters2; /* HIF_DEMOTE, HIF_GREEDY */ @@ -244,6 +246,7 @@ enum { }; struct gfs2_inode { + struct inode i_inode; struct gfs2_inum i_num; atomic_t i_count; @@ -270,6 +273,11 @@ struct gfs2_inode { struct buffer_head *i_cache[GFS2_MAX_META_HEIGHT]; }; +static inline struct gfs2_inode *GFS2_I(struct inode *inode) +{ + return container_of(inode, struct gfs2_inode, i_inode); +} + enum { GFF_DID_DIRECT_ALLOC = 0, }; diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 27fbcd9b12f0..c2c7d2b63a57 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -504,7 +504,7 @@ static int inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul, error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, &gfs2_inode_glops, LM_ST_EXCLUSIVE, - LM_FLAG_TRY_1CB, &i_gh); + LM_FLAG_TRY_1CB|GL_DUMP, &i_gh); switch(error) { case 0: break; @@ -724,9 +724,8 @@ struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) || (name->len == 2 && memcmp(name->name, "..", 2) == 0 && dir == sb->s_root->d_inode)) { - gfs2_inode_hold(dip); - ipp = dip; - goto done; + igrab(dir); + return dir; } error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); @@ -734,7 +733,7 @@ struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, return ERR_PTR(error); if (!is_root) { - error = gfs2_repermission(dip->i_vnode, MAY_EXEC, NULL); + error = gfs2_repermission(dir, MAY_EXEC, NULL); if (error) goto out; } @@ -756,7 +755,6 @@ struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, out: gfs2_glock_dq_uninit(&d_gh); -done: if (error == -ENOENT) return NULL; if (error == 0) { @@ -1058,7 +1056,6 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, int error; munge_mode_uid_gid(dip, &mode, &uid, &gid); - gfs2_alloc_get(dip); error = gfs2_quota_lock(dip, uid, gid); @@ -1069,19 +1066,14 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, if (error) goto out_quota; - error = gfs2_trans_begin(sdp, RES_DINODE + RES_UNLINKED + - RES_QUOTA, 0); + error = gfs2_trans_begin(sdp, RES_DINODE + RES_UNLINKED + RES_QUOTA, 0); if (error) goto out_quota; ul->ul_ut.ut_flags = 0; error = gfs2_unlinked_ondisk_munge(sdp, ul); - - init_dinode(dip, gl, &ul->ul_ut.ut_inum, - mode, uid, gid); - + init_dinode(dip, gl, &ul->ul_ut.ut_inum, mode, uid, gid); gfs2_quota_change(dip, +1, uid, gid); - gfs2_trans_end(sdp); out_quota: @@ -1089,7 +1081,6 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, out: gfs2_alloc_put(dip); - return error; } @@ -1123,8 +1114,7 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name, if (error) goto fail_quota_locks; - error = gfs2_trans_begin(sdp, - sdp->sd_max_dirres + + error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + al->al_rgd->rd_ri.ri_length + 2 * RES_DINODE + RES_UNLINKED + RES_STATFS + RES_QUOTA, 0); @@ -1157,19 +1147,18 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name, return 0; - fail_end_trans: +fail_end_trans: gfs2_trans_end(sdp); - fail_ipreserv: +fail_ipreserv: if (dip->i_alloc.al_rgd) gfs2_inplace_release(dip); - fail_quota_locks: +fail_quota_locks: gfs2_quota_unlock(dip); - fail: +fail: gfs2_alloc_put(dip); - return error; } @@ -1226,11 +1215,9 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, if (ul->ul_ut.ut_inum.no_addr < dip->i_num.no_addr) { gfs2_glock_dq(ghs); - error = gfs2_glock_nq_num(sdp, - ul->ul_ut.ut_inum.no_addr, - &gfs2_inode_glops, - LM_ST_EXCLUSIVE, GL_SKIP, - ghs + 1); + error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, + &gfs2_inode_glops, LM_ST_EXCLUSIVE, + GL_SKIP, ghs + 1); if (error) { gfs2_unlinked_put(sdp, ul); return ERR_PTR(error); @@ -1248,11 +1235,9 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, if (error) goto fail_gunlock2; } else { - error = gfs2_glock_nq_num(sdp, - ul->ul_ut.ut_inum.no_addr, - &gfs2_inode_glops, - LM_ST_EXCLUSIVE, GL_SKIP, - ghs + 1); + error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, + &gfs2_inode_glops, LM_ST_EXCLUSIVE, + GL_SKIP, ghs + 1); if (error) goto fail_gunlock; } @@ -1285,18 +1270,17 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, return ERR_PTR(-ENOMEM); return inode; - fail_iput: +fail_iput: gfs2_inode_put(ip); - fail_gunlock2: +fail_gunlock2: gfs2_glock_dq_uninit(ghs + 1); - fail_gunlock: +fail_gunlock: gfs2_glock_dq(ghs); - fail: +fail: gfs2_unlinked_put(sdp, ul); - return ERR_PTR(error); } diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index 9ce56b5c7803..b24d0b40d965 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -23,6 +23,20 @@ #include "sys.h" #include "util.h" +static void gfs2_init_inode_once(void *foo, kmem_cache_t *cachep, unsigned long flags) +{ + struct gfs2_inode *ip = foo; + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == + SLAB_CTOR_CONSTRUCTOR) { + inode_init_once(&ip->i_inode); + atomic_set(&ip->i_count, 0); + ip->i_vnode = &ip->i_inode; + spin_lock_init(&ip->i_spin); + init_rwsem(&ip->i_rw_mutex); + memset(ip->i_cache, 0, sizeof(ip->i_cache)); + } +} + /** * init_gfs2_fs - Register GFS2 as a filesystem * @@ -49,7 +63,9 @@ static int __init init_gfs2_fs(void) gfs2_inode_cachep = kmem_cache_create("gfs2_inode", sizeof(struct gfs2_inode), - 0, 0, NULL, NULL); + 0, (SLAB_RECLAIM_ACCOUNT| + SLAB_PANIC|SLAB_MEM_SPREAD), + gfs2_init_inode_once, NULL); if (!gfs2_inode_cachep) goto fail; diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 6fa7b8649f14..1c17acc946f9 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -361,7 +361,31 @@ static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) return 0; } +static struct inode *gfs2_alloc_inode(struct super_block *sb) +{ + struct gfs2_sbd *sdp = sb->s_fs_info; + struct gfs2_inode *ip; + + ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL); + if (ip) { + ip->i_flags = 0; + ip->i_gl = NULL; + ip->i_sbd = sdp; + ip->i_vnode = &ip->i_inode; + ip->i_greedy = gfs2_tune_get(sdp, gt_greedy_default); + ip->i_last_pfault = jiffies; + } + return &ip->i_inode; +} + +static void gfs2_destroy_inode(struct inode *inode) +{ + kmem_cache_free(gfs2_inode_cachep, inode); +} + struct super_operations gfs2_super_ops = { + .alloc_inode = gfs2_alloc_inode, + .destroy_inode = gfs2_destroy_inode, .write_inode = gfs2_write_inode, .put_super = gfs2_put_super, .write_super = gfs2_write_super, From d2f222e6310b073ae3d91b8d3d676621fae1314e Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 19 May 2006 08:24:02 -0400 Subject: [PATCH 118/292] [GFS2] setup lock_dlm kobject earlier Setup the lock_dlm kobject before setting up the dlm lockspace instead of after. We want to use the sysfs files to detect the mount without having to wait for the dlm setup which can take a while. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/mount.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c index aa79fbecaf6a..3caeafc02a1b 100644 --- a/fs/gfs2/locking/dlm/mount.c +++ b/fs/gfs2/locking/dlm/mount.c @@ -143,19 +143,19 @@ static int gdlm_mount(char *table_name, char *host_data, if (error) goto out_free; + error = gdlm_kobject_setup(ls, fskobj); + if (error) + goto out_thread; + error = dlm_new_lockspace(ls->fsname, strlen(ls->fsname), &ls->dlm_lockspace, nodir ? DLM_LSFL_NODIR : 0, GDLM_LVB_SIZE); if (error) { log_error("dlm_new_lockspace error %d", error); - goto out_thread; + goto out_kobj; } - error = gdlm_kobject_setup(ls, fskobj); - if (error) - goto out_dlm; - lockstruct->ls_jid = ls->jid; lockstruct->ls_first = ls->first; lockstruct->ls_lockspace = ls; @@ -164,8 +164,8 @@ static int gdlm_mount(char *table_name, char *host_data, lockstruct->ls_lvb_size = GDLM_LVB_SIZE; return 0; - out_dlm: - dlm_release_lockspace(ls->dlm_lockspace, 2); + out_kobj: + gdlm_kobject_release(ls); out_thread: gdlm_release_threads(ls); out_free: From 639b6d79b8c20cce4079fb035640c65456324d1c Mon Sep 17 00:00:00 2001 From: Ryan O'Hara Date: Mon, 22 May 2006 10:08:35 -0400 Subject: [PATCH 119/292] [GFS2] selinux support This adds support to GFS2 for selinux extended attributes. There is a known bug in gfs2_ea_get() which is believed to be independant of this patch. Further patches will follow once that bug is fixed in order to make GFS2 use as much of the generic eattr infrastructure as possible. Signed-off-by: Ryan O'Hara Signed-off-by: Steven Whitehouse --- fs/gfs2/eaops.c | 41 +++++++++++++++++++++++++++++++++++++ fs/gfs2/eaops.h | 2 ++ fs/gfs2/eattr.c | 15 +++++++++++--- fs/gfs2/eattr.h | 17 ++++++++++++--- include/linux/gfs2_ondisk.h | 3 ++- 5 files changed, 71 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index 85c1dbace88b..2243b44ecb07 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -43,6 +43,10 @@ unsigned int gfs2_ea_name2type(const char *name, char **truncated_name) type = GFS2_EATYPE_USR; if (truncated_name) *truncated_name = strchr(name, '.') + 1; + } else if (strncmp(name, "security.", 9) == 0) { + type = GFS2_EATYPE_SECURITY; + if (truncated_name) + *truncated_name = strchr(name, '.') + 1; } else { type = GFS2_EATYPE_UNUSED; if (truncated_name) @@ -166,6 +170,36 @@ static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) return gfs2_ea_remove_i(ip, er); } +static int security_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct inode *inode = ip->i_vnode; + int error = permission(inode, MAY_READ, NULL); + if (error) + return error; + + return gfs2_ea_get_i(ip, er); +} + +static int security_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct inode *inode = ip->i_vnode; + int error = permission(inode, MAY_WRITE, NULL); + if (error) + return error; + + return gfs2_ea_set_i(ip, er); +} + +static int security_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) +{ + struct inode *inode = ip->i_vnode; + int error = permission(inode, MAY_WRITE, NULL); + if (error) + return error; + + return gfs2_ea_remove_i(ip, er); +} + static struct gfs2_eattr_operations gfs2_user_eaops = { .eo_get = user_eo_get, .eo_set = user_eo_set, @@ -180,6 +214,13 @@ struct gfs2_eattr_operations gfs2_system_eaops = { .eo_name = "system", }; +struct gfs2_eattr_operations gfs2_security_eaops = { + .eo_get = security_eo_get, + .eo_set = security_eo_set, + .eo_remove = security_eo_remove, + .eo_name = "security", +}; + struct gfs2_eattr_operations *gfs2_ea_ops[] = { NULL, &gfs2_user_eaops, diff --git a/fs/gfs2/eaops.h b/fs/gfs2/eaops.h index 3dece17e3116..965a235c96e8 100644 --- a/fs/gfs2/eaops.h +++ b/fs/gfs2/eaops.h @@ -23,6 +23,8 @@ unsigned int gfs2_ea_name2type(const char *name, char **truncated_name); extern struct gfs2_eattr_operations gfs2_system_eaops; +extern struct gfs2_eattr_operations gfs2_security_eaops; + extern struct gfs2_eattr_operations *gfs2_ea_ops[]; #endif /* __EAOPS_DOT_H__ */ diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index f5169a42a919..187fba1c4678 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -368,7 +368,7 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, { struct ea_list *ei = private; struct gfs2_ea_request *er = ei->ei_er; - unsigned int ea_size = GFS2_EA_STRLEN(ea); + unsigned int ea_size = gfs2_ea_strlen(ea); if (ea->ea_type == GFS2_EATYPE_UNUSED) return 0; @@ -381,12 +381,21 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, if (ei->ei_size + ea_size > er->er_data_len) return -ERANGE; - if (ea->ea_type == GFS2_EATYPE_USR) { + switch (ea->ea_type) { + case GFS2_EATYPE_USR: prefix = "user."; l = 5; - } else { + break; + case GFS2_EATYPE_SYS: prefix = "system."; l = 7; + break; + case GFS2_EATYPE_SECURITY: + prefix = "security."; + l = 9; + break; + default: + break; } memcpy(er->er_data + ei->ei_size, diff --git a/fs/gfs2/eattr.h b/fs/gfs2/eattr.h index 19fb1dc4ddc4..ae199692e51d 100644 --- a/fs/gfs2/eattr.h +++ b/fs/gfs2/eattr.h @@ -18,9 +18,6 @@ ALIGN(sizeof(struct gfs2_ea_header) + (ea)->ea_name_len + \ ((GFS2_EA_IS_STUFFED(ea)) ? GFS2_EA_DATA_LEN(ea) : \ (sizeof(uint64_t) * (ea)->ea_num_ptrs)), 8) -#define GFS2_EA_STRLEN(ea) \ -((((ea)->ea_type == GFS2_EATYPE_USR) ? 5 : 7) + (ea)->ea_name_len + 1) - #define GFS2_EA_IS_STUFFED(ea) (!(ea)->ea_num_ptrs) #define GFS2_EA_IS_LAST(ea) ((ea)->ea_flags & GFS2_EAFLAG_LAST) @@ -83,4 +80,18 @@ int gfs2_ea_get_copy(struct gfs2_inode *ip, int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el, struct iattr *attr, char *data); +static inline unsigned int gfs2_ea_strlen(struct gfs2_ea_header *ea) +{ + switch (ea->ea_type) { + case GFS2_EATYPE_USR: + return (5 + (ea->ea_name_len + 1)); + case GFS2_EATYPE_SYS: + return (7 + (ea->ea_name_len + 1)); + case GFS2_EATYPE_SECURITY: + return (9 + (ea->ea_name_len + 1)); + default: + return (0); + } +} + #endif /* __EATTR_DOT_H__ */ diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index 4356e3864643..3893aac4e3ae 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -311,8 +311,9 @@ struct gfs2_leaf { #define GFS2_EATYPE_UNUSED 0 #define GFS2_EATYPE_USR 1 #define GFS2_EATYPE_SYS 2 +#define GFS2_EATYPE_SECURITY 3 -#define GFS2_EATYPE_LAST 2 +#define GFS2_EATYPE_LAST 3 #define GFS2_EATYPE_VALID(x) ((x) <= GFS2_EATYPE_LAST) #define GFS2_EAFLAG_LAST 0x01 /* last ea in block */ From 90cdd2083aea9a536ecdef62840db01fff2e645d Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 22 May 2006 10:36:25 -0400 Subject: [PATCH 120/292] [GFS2] Flag up issue in selinux code Signed-off-by: Steven Whitehouse --- fs/gfs2/eattr.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 187fba1c4678..346601538ac7 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -395,17 +395,14 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, l = 9; break; default: + /* FIXME: Needs looking at again */ break; } - memcpy(er->er_data + ei->ei_size, - prefix, l); - memcpy(er->er_data + ei->ei_size + l, - GFS2_EA2NAME(ea), + memcpy(er->er_data + ei->ei_size, prefix, l); + memcpy(er->er_data + ei->ei_size + l, GFS2_EA2NAME(ea), ea->ea_name_len); - memcpy(er->er_data + ei->ei_size + - ea_size - 1, - &c, 1); + memcpy(er->er_data + ei->ei_size + ea_size - 1, &c, 1); } ei->ei_size += ea_size; From 9229f013495dcdae76e9942ebc2cfc69851fe10a Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 24 May 2006 09:21:30 -0400 Subject: [PATCH 121/292] [GFS2] Cast 64 bit printk args to unsigned long long. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/recover.c | 2 +- fs/gfs2/locking/dlm/lock.c | 39 ++++++++++++++++++++----------------- fs/gfs2/locking/dlm/plock.c | 7 ++++--- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/fs/dlm/recover.c b/fs/dlm/recover.c index b036ee7dcb32..34876f60f298 100644 --- a/fs/dlm/recover.c +++ b/fs/dlm/recover.c @@ -421,7 +421,7 @@ int dlm_recover_master_reply(struct dlm_ls *ls, struct dlm_rcom *rc) r = recover_list_find(ls, rc->rc_id); if (!r) { log_error(ls, "dlm_recover_master_reply no id %llx", - rc->rc_id); + (unsigned long long)rc->rc_id); goto out; } diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index 3b0dfd7ae26e..e74f1215672f 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -35,7 +35,8 @@ static inline void gdlm_bast(void *astarg, int mode) if (!mode) { printk(KERN_INFO "lock_dlm: bast mode zero %x,%llx\n", - lp->lockname.ln_type, lp->lockname.ln_number); + lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number); return; } @@ -154,7 +155,7 @@ static inline void make_strname(struct lm_lockname *lockname, struct gdlm_strname *str) { sprintf(str->name, "%8x%16llx", lockname->ln_type, - lockname->ln_number); + (unsigned long long)lockname->ln_number); str->namelen = GDLM_STRNAME_BYTES; } @@ -197,8 +198,8 @@ void gdlm_delete_lp(struct gdlm_lock *lp) list_del_init(&lp->blist); if (!list_empty(&lp->delay_list)) list_del_init(&lp->delay_list); - gdlm_assert(!list_empty(&lp->all_list), - "%x,%llx", lp->lockname.ln_type, lp->lockname.ln_number); + gdlm_assert(!list_empty(&lp->all_list), "%x,%llx", lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number); list_del_init(&lp->all_list); ls->all_locks_count--; spin_unlock(&ls->async_lock); @@ -253,7 +254,7 @@ unsigned int gdlm_do_lock(struct gdlm_lock *lp) set_bit(LFL_ACTIVE, &lp->flags); log_debug("lk %x,%llx id %x %d,%d %x", lp->lockname.ln_type, - lp->lockname.ln_number, lp->lksb.sb_lkid, + (unsigned long long)lp->lockname.ln_number, lp->lksb.sb_lkid, lp->cur, lp->req, lp->lkf); error = dlm_lock(ls->dlm_lockspace, lp->req, &lp->lksb, lp->lkf, @@ -269,8 +270,8 @@ unsigned int gdlm_do_lock(struct gdlm_lock *lp) if (error) { log_debug("%s: gdlm_lock %x,%llx err=%d cur=%d req=%d lkf=%x " "flags=%lx", ls->fsname, lp->lockname.ln_type, - lp->lockname.ln_number, error, lp->cur, lp->req, - lp->lkf, lp->flags); + (unsigned long long)lp->lockname.ln_number, error, + lp->cur, lp->req, lp->lkf, lp->flags); return LM_OUT_ERROR; } return LM_OUT_ASYNC; @@ -289,15 +290,16 @@ static unsigned int gdlm_do_unlock(struct gdlm_lock *lp) lkf = DLM_LKF_VALBLK; log_debug("un %x,%llx %x %d %x", lp->lockname.ln_type, - lp->lockname.ln_number, lp->lksb.sb_lkid, lp->cur, lkf); + (unsigned long long)lp->lockname.ln_number, + lp->lksb.sb_lkid, lp->cur, lkf); error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, lkf, NULL, lp); if (error) { log_debug("%s: gdlm_unlock %x,%llx err=%d cur=%d req=%d lkf=%x " "flags=%lx", ls->fsname, lp->lockname.ln_type, - lp->lockname.ln_number, error, lp->cur, lp->req, - lp->lkf, lp->flags); + (unsigned long long)lp->lockname.ln_number, error, + lp->cur, lp->req, lp->lkf, lp->flags); return LM_OUT_ERROR; } return LM_OUT_ASYNC; @@ -338,8 +340,8 @@ void gdlm_cancel(lm_lock_t *lock) if (test_bit(LFL_DLM_CANCEL, &lp->flags)) return; - log_info("gdlm_cancel %x,%llx flags %lx", - lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); + log_info("gdlm_cancel %x,%llx flags %lx", lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number, lp->flags); spin_lock(&ls->async_lock); if (!list_empty(&lp->delay_list)) { @@ -356,10 +358,10 @@ void gdlm_cancel(lm_lock_t *lock) } if (!test_bit(LFL_ACTIVE, &lp->flags) || - test_bit(LFL_DLM_UNLOCK, &lp->flags)) { + test_bit(LFL_DLM_UNLOCK, &lp->flags)) { log_info("gdlm_cancel skip %x,%llx flags %lx", - lp->lockname.ln_type, lp->lockname.ln_number, - lp->flags); + lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number, lp->flags); return; } @@ -372,7 +374,8 @@ void gdlm_cancel(lm_lock_t *lock) NULL, lp); log_info("gdlm_cancel rv %d %x,%llx flags %lx", error, - lp->lockname.ln_type, lp->lockname.ln_number, lp->flags); + lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number, lp->flags); if (error == -EBUSY) clear_bit(LFL_DLM_CANCEL, &lp->flags); @@ -448,8 +451,8 @@ static void unhold_null_lock(struct gdlm_lock *lp) { struct gdlm_lock *lpn = lp->hold_null; - gdlm_assert(lpn, "%x,%llx", - lp->lockname.ln_type, lp->lockname.ln_number); + gdlm_assert(lpn, "%x,%llx", lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number); lpn->lksb.sb_lvbptr = NULL; lpn->lvb = NULL; set_bit(LFL_UNLOCK_DELETE, &lpn->flags); diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c index 86312d96147b..6adfb2d4fd8c 100644 --- a/fs/gfs2/locking/dlm/plock.c +++ b/fs/gfs2/locking/dlm/plock.c @@ -93,7 +93,8 @@ int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, if (!rv) { if (posix_lock_file_wait(file, fl) < 0) log_error("gdlm_plock: vfs lock error %x,%llx", - name->ln_type, name->ln_number); + name->ln_type, + (unsigned long long)name->ln_number); } kfree(op); @@ -113,7 +114,7 @@ int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, if (posix_lock_file_wait(file, fl) < 0) log_error("gdlm_punlock: vfs unlock error %x,%llx", - name->ln_type, name->ln_number); + name->ln_type, (unsigned long long)name->ln_number); op->info.optype = GDLM_PLOCK_OP_UNLOCK; op->info.pid = fl->fl_pid; @@ -243,7 +244,7 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count, wake_up(&recv_wq); else printk(KERN_INFO "gdlm dev_write no op %x %llx\n", info.fsid, - info.number); + (unsigned long long)info.number); return count; } From 382066da251132f768380f4852ed5afb72d88f80 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 24 May 2006 10:22:09 -0400 Subject: [PATCH 122/292] [GFS2] Casts for printing 64bit numbers Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 5 +++-- fs/gfs2/meta_io.c | 7 ++++--- fs/gfs2/ondisk.c | 24 ++++++++++++------------ fs/gfs2/rgrp.c | 4 ++-- fs/gfs2/util.c | 11 ++++++----- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 2ef8accf1cbc..0603a6de52c9 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -2196,7 +2196,8 @@ static int dump_inode(struct gfs2_inode *ip) printk(KERN_INFO " Inode:\n"); printk(KERN_INFO " num = %llu %llu\n", - ip->i_num.no_formal_ino, ip->i_num.no_addr); + (unsigned long long)ip->i_num.no_formal_ino, + (unsigned long long)ip->i_num.no_addr); printk(KERN_INFO " type = %u\n", IF2DT(ip->i_di.di_mode)); printk(KERN_INFO " i_count = %d\n", atomic_read(&ip->i_count)); printk(KERN_INFO " i_flags ="); @@ -2228,7 +2229,7 @@ static int dump_glock(struct gfs2_glock *gl) spin_lock(&gl->gl_spin); printk(KERN_INFO "Glock (%u, %llu)\n", gl->gl_name.ln_type, - gl->gl_name.ln_number); + (unsigned long long)gl->gl_name.ln_number); printk(KERN_INFO " gl_flags ="); for (x = 0; x < 32; x++) if (test_bit(x, &gl->gl_flags)) diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index b9895bbd5feb..c78517225f61 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -65,7 +65,7 @@ static void stuck_releasepage(struct buffer_head *bh) fs_warn(sdp, "stuck in gfs2_releasepage() %p\n", inode); fs_warn(sdp, "blkno = %llu, bh->b_count = %d\n", - (uint64_t)bh->b_blocknr, atomic_read(&bh->b_count)); + (unsigned long long)bh->b_blocknr, atomic_read(&bh->b_count)); fs_warn(sdp, "pinned = %u\n", buffer_pinned(bh)); fs_warn(sdp, "bh->b_private = %s\n", (bd) ? "!NULL" : "NULL"); @@ -75,7 +75,7 @@ static void stuck_releasepage(struct buffer_head *bh) gl = bd->bd_gl; fs_warn(sdp, "gl = (%u, %llu)\n", - gl->gl_name.ln_type, gl->gl_name.ln_number); + gl->gl_name.ln_type, (unsigned long long)gl->gl_name.ln_number); fs_warn(sdp, "bd_list_tr = %s, bd_le.le_list = %s\n", (list_empty(&bd->bd_list_tr)) ? "no" : "yes", @@ -89,7 +89,8 @@ static void stuck_releasepage(struct buffer_head *bh) return; fs_warn(sdp, "ip = %llu %llu\n", - ip->i_num.no_formal_ino, ip->i_num.no_addr); + (unsigned long long)ip->i_num.no_formal_ino, + (unsigned long long)ip->i_num.no_addr); fs_warn(sdp, "ip->i_count = %d, ip->i_vnode = %s\n", atomic_read(&ip->i_count), (ip->i_vnode) ? "!NULL" : "NULL"); diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index b3bc21a6ba07..be5c86e5787e 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -50,8 +50,8 @@ void gfs2_inum_out(const struct gfs2_inum *no, char *buf) static void gfs2_inum_print(struct gfs2_inum *no) { - pv(no, no_formal_ino, "%llu"); - pv(no, no_addr, "%llu"); + printk(KERN_INFO " no_formal_ino = %llu\n", (unsigned long long)no->no_formal_ino); + printk(KERN_INFO " no_addr = %llu\n", (unsigned long long)no->no_addr); } static void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf) @@ -111,10 +111,10 @@ void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf) void gfs2_rindex_print(struct gfs2_rindex *ri) { - pv(ri, ri_addr, "%llu"); + printk(KERN_INFO " ri_addr = %llu\n", (unsigned long long)ri->ri_addr); pv(ri, ri_length, "%u"); - pv(ri, ri_data0, "%llu"); + printk(KERN_INFO " ri_data0 = %llu\n", (unsigned long long)ri->ri_data0); pv(ri, ri_data, "%u"); pv(ri, ri_bitbytes, "%u"); @@ -226,16 +226,16 @@ void gfs2_dinode_print(struct gfs2_dinode *di) pv(di, di_uid, "%u"); pv(di, di_gid, "%u"); pv(di, di_nlink, "%u"); - pv(di, di_size, "%llu"); - pv(di, di_blocks, "%llu"); - pv(di, di_atime, "%lld"); - pv(di, di_mtime, "%lld"); - pv(di, di_ctime, "%lld"); + printk(KERN_INFO " di_size = %llu\n", (unsigned long long)di->di_size); + printk(KERN_INFO " di_blocks = %llu\n", (unsigned long long)di->di_blocks); + printk(KERN_INFO " di_atime = %lld\n", (long long)di->di_atime); + printk(KERN_INFO " di_mtime = %lld\n", (long long)di->di_mtime); + printk(KERN_INFO " di_ctime = %lld\n", (long long)di->di_ctime); pv(di, di_major, "%u"); pv(di, di_minor, "%u"); - pv(di, di_goal_meta, "%llu"); - pv(di, di_goal_data, "%llu"); + printk(KERN_INFO " di_goal_meta = %llu\n", (unsigned long long)di->di_goal_meta); + printk(KERN_INFO " di_goal_data = %llu\n", (unsigned long long)di->di_goal_data); pv(di, di_flags, "0x%.8X"); pv(di, di_payload_format, "%u"); @@ -244,7 +244,7 @@ void gfs2_dinode_print(struct gfs2_dinode *di) pv(di, di_depth, "%u"); pv(di, di_entries, "%u"); - pv(di, di_eattr, "%llu"); + printk(KERN_INFO " di_eattr = %llu\n", (unsigned long long)di->di_eattr); } void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf) diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index c1c6fa9c0e4b..691e6f3ce43b 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -1165,7 +1165,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, uint64_t bstart, rgd = gfs2_blk2rgrpd(sdp, bstart); if (!rgd) { if (gfs2_consist(sdp)) - fs_err(sdp, "block = %llu\n", bstart); + fs_err(sdp, "block = %llu\n", (unsigned long long)bstart); return NULL; } @@ -1452,7 +1452,7 @@ void gfs2_rlist_add(struct gfs2_sbd *sdp, struct gfs2_rgrp_list *rlist, rgd = gfs2_blk2rgrpd(sdp, block); if (!rgd) { if (gfs2_consist(sdp)) - fs_err(sdp, "block = %llu\n", block); + fs_err(sdp, "block = %llu\n", (unsigned long long)block); return; } diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 0b37d6bcc36e..88974e9824f7 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -116,7 +116,8 @@ int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, "GFS2: fsid=%s: inode = %llu %llu\n" "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", sdp->sd_fsname, - sdp->sd_fsname, ip->i_num.no_formal_ino, ip->i_num.no_addr, + sdp->sd_fsname, (unsigned long long)ip->i_num.no_formal_ino, + (unsigned long long)ip->i_num.no_addr, sdp->sd_fsname, function, file, line); return rv; } @@ -137,7 +138,7 @@ int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide, "GFS2: fsid=%s: RG = %llu\n" "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", sdp->sd_fsname, - sdp->sd_fsname, rgd->rd_ri.ri_addr, + sdp->sd_fsname, (unsigned long long)rgd->rd_ri.ri_addr, sdp->sd_fsname, function, file, line); return rv; } @@ -158,7 +159,7 @@ int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, "GFS2: fsid=%s: bh = %llu (%s)\n" "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", sdp->sd_fsname, - sdp->sd_fsname, (uint64_t)bh->b_blocknr, type, + sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, sdp->sd_fsname, function, file, line); return (me) ? -1 : -2; } @@ -179,7 +180,7 @@ int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, "GFS2: fsid=%s: bh = %llu (type: exp=%u, found=%u)\n" "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", sdp->sd_fsname, - sdp->sd_fsname, (uint64_t)bh->b_blocknr, type, t, + sdp->sd_fsname, (unsigned long long)bh->b_blocknr, type, t, sdp->sd_fsname, function, file, line); return (me) ? -1 : -2; } @@ -217,7 +218,7 @@ int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, "GFS2: fsid=%s: block = %llu\n" "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", sdp->sd_fsname, - sdp->sd_fsname, (uint64_t)bh->b_blocknr, + sdp->sd_fsname, (unsigned long long)bh->b_blocknr, sdp->sd_fsname, function, file, line); return rv; } From e79664886ddd569afa1b198ca436a63aefc19073 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 25 May 2006 12:47:04 -0400 Subject: [PATCH 123/292] [GFS2] Remove unused entry in ioctl-number.txt GFS2 doesn't use any ioctl numbers of its own, so we don't need a reserved range of numbers for it. Signed-off-by: Steven Whitehouse --- Documentation/ioctl-number.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/ioctl-number.txt b/Documentation/ioctl-number.txt index 93a86ac23cdd..171a44ebd939 100644 --- a/Documentation/ioctl-number.txt +++ b/Documentation/ioctl-number.txt @@ -124,7 +124,6 @@ Code Seq# Include File Comments 'e' 00-1F linux/video_encoder.h conflict! 'e' 00-1F net/irda/irtty.h conflict! 'f' 00-1F linux/ext2_fs.h -'g' 00-1F linux/gfs2_ioctl.h 'h' 00-7F Charon filesystem 'i' 00-3F linux/i2o.h From e70409f5f37587e101b4fd6d268686ae8e03ba88 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara Date: Thu, 25 May 2006 17:36:15 -0400 Subject: [PATCH 124/292] [GFS2] Fix for selinux support This should fix the mount problems with gfs2 and selinux. Signed-off-by: Ryan O'Hara Signed-off-by: Steven Whitehouse --- fs/gfs2/eaops.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index 2243b44ecb07..1c5ac3160b3b 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -225,5 +225,6 @@ struct gfs2_eattr_operations *gfs2_ea_ops[] = { NULL, &gfs2_user_eaops, &gfs2_system_eaops, + &gfs2_security_eaops, }; From 47c96298cd0b04b4478206fde55fd6a6431de980 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 25 May 2006 17:43:14 -0400 Subject: [PATCH 125/292] [GFS2] Change name due to local_nodeid being a macro Change names of local_nodeid to dlm_local_nodeid to prevent a namespace collision. Changed other local variable to match. Cc: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lowcomms.c | 48 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index cdd168e4bf45..75010da95b39 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -55,9 +55,9 @@ #include "config.h" #include "midcomms.h" -static struct sockaddr_storage *local_addr[DLM_MAX_ADDR_COUNT]; -static int local_count; -static int local_nodeid; +static struct sockaddr_storage *dlm_local_addr[DLM_MAX_ADDR_COUNT]; +static int dlm_local_count; +static int dlm_local_nodeid; /* One of these per connected node */ @@ -153,14 +153,14 @@ static int nodeid_to_addr(int nodeid, struct sockaddr *retaddr) struct sockaddr_storage addr; int error; - if (!local_count) + if (!dlm_local_count) return -1; error = dlm_nodeid_to_addr(nodeid, &addr); if (error) return error; - if (local_addr[0]->ss_family == AF_INET) { + if (dlm_local_addr[0]->ss_family == AF_INET) { struct sockaddr_in *in4 = (struct sockaddr_in *) &addr; struct sockaddr_in *ret4 = (struct sockaddr_in *) retaddr; ret4->sin_addr.s_addr = in4->sin_addr.s_addr; @@ -260,21 +260,21 @@ static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port, struct sockaddr_in *local4_addr; struct sockaddr_in6 *local6_addr; - if (!local_count) + if (!dlm_local_count) return; if (!port) { - if (local_addr[0]->ss_family == AF_INET) { - local4_addr = (struct sockaddr_in *)local_addr[0]; + if (dlm_local_addr[0]->ss_family == AF_INET) { + local4_addr = (struct sockaddr_in *)dlm_local_addr[0]; port = be16_to_cpu(local4_addr->sin_port); } else { - local6_addr = (struct sockaddr_in6 *)local_addr[0]; + local6_addr = (struct sockaddr_in6 *)dlm_local_addr[0]; port = be16_to_cpu(local6_addr->sin6_port); } } - saddr->ss_family = local_addr[0]->ss_family; - if (local_addr[0]->ss_family == AF_INET) { + saddr->ss_family = dlm_local_addr[0]->ss_family; + if (dlm_local_addr[0]->ss_family == AF_INET) { struct sockaddr_in *in4_addr = (struct sockaddr_in *)saddr; in4_addr->sin_port = cpu_to_be16(port); memset(&in4_addr->sin_zero, 0, sizeof(in4_addr->sin_zero)); @@ -636,7 +636,7 @@ static void init_local(void) struct sockaddr_storage sas, *addr; int i; - local_nodeid = dlm_our_nodeid(); + dlm_local_nodeid = dlm_our_nodeid(); for (i = 0; i < DLM_MAX_ADDR_COUNT - 1; i++) { if (dlm_our_addr(&sas, i)) @@ -646,7 +646,7 @@ static void init_local(void) if (!addr) break; memcpy(addr, &sas, sizeof(*addr)); - local_addr[local_count++] = addr; + dlm_local_addr[dlm_local_count++] = addr; } } @@ -659,15 +659,15 @@ static int init_sock(void) struct sctp_event_subscribe subscribe; int result = -EINVAL, num = 1, i, addr_len; - if (!local_count) { + if (!dlm_local_count) { init_local(); - if (!local_count) { + if (!dlm_local_count) { log_print("no local IP address has been set"); goto out; } } - result = sock_create_kern(local_addr[0]->ss_family, SOCK_SEQPACKET, + result = sock_create_kern(dlm_local_addr[0]->ss_family, SOCK_SEQPACKET, IPPROTO_SCTP, &sock); if (result < 0) { log_print("Can't create comms socket, check SCTP is loaded"); @@ -700,8 +700,8 @@ static int init_sock(void) sctp_con.sock->sk->sk_data_ready = lowcomms_data_ready; /* Bind to all interfaces. */ - for (i = 0; i < local_count; i++) { - memcpy(&localaddr, local_addr[i], sizeof(localaddr)); + for (i = 0; i < dlm_local_count; i++) { + memcpy(&localaddr, dlm_local_addr[i], sizeof(localaddr)); make_sockaddr(&localaddr, dlm_config.tcp_port, &addr_len); result = add_bind_addr(&localaddr, addr_len, num); @@ -879,7 +879,7 @@ static void initiate_association(int nodeid) cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo)); - sinfo->sinfo_ppid = cpu_to_le32(local_nodeid); + sinfo->sinfo_ppid = cpu_to_le32(dlm_local_nodeid); outmessage.msg_controllen = cmsg->cmsg_len; ret = kernel_sendmsg(sctp_con.sock, &outmessage, iov, 1, 1); @@ -924,7 +924,7 @@ static int send_to_sock(struct nodeinfo *ni) cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo)); - sinfo->sinfo_ppid = cpu_to_le32(local_nodeid); + sinfo->sinfo_ppid = cpu_to_le32(dlm_local_nodeid); sinfo->sinfo_assoc_id = ni->assoc_id; outmsg.msg_controllen = cmsg->cmsg_len; @@ -1231,9 +1231,9 @@ void dlm_lowcomms_exit(void) { int i; - for (i = 0; i < local_count; i++) - kfree(local_addr[i]); - local_count = 0; - local_nodeid = 0; + for (i = 0; i < dlm_local_count; i++) + kfree(dlm_local_addr[i]); + dlm_local_count = 0; + dlm_local_nodeid = 0; } From 6b61b072a8b54212ab0808c443e5c16699390d25 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 6 Jun 2006 14:49:39 -0400 Subject: [PATCH 126/292] [GFS2] Move some fields around to reduce wasted space We can reclaim some space by moving fields in some structures in order to allow them to pack better on 64 bit architectures. Signed-off-by: Steven Whitehouse --- fs/gfs2/incore.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 92091d006a02..8caefec88854 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -158,7 +158,7 @@ struct gfs2_holder { unsigned gh_flags; int gh_error; - unsigned long gh_iflags; + unsigned gh_iflags; struct completion gh_wait; unsigned long gh_ip; }; @@ -217,25 +217,21 @@ struct gfs2_glock { struct gfs2_alloc { /* Quota stuff */ - unsigned int al_qd_num; struct gfs2_quota_data *al_qd[4]; struct gfs2_holder al_qd_ghs[4]; + unsigned int al_qd_num; - /* Filled in by the caller to gfs2_inplace_reserve() */ - - uint32_t al_requested; + u32 al_requested; /* Filled in by caller of gfs2_inplace_reserve() */ + u32 al_alloced; /* Filled in by gfs2_alloc_*() */ /* Filled in by gfs2_inplace_reserve() */ - char *al_file; unsigned int al_line; + char *al_file; struct gfs2_holder al_ri_gh; struct gfs2_holder al_rgd_gh; struct gfs2_rgrpd *al_rgd; - /* Filled in by gfs2_alloc_*() */ - - uint32_t al_alloced; }; enum { From 01eb7c07968fdab0cca0d2474346cff176537de8 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 6 Jun 2006 17:31:30 -0400 Subject: [PATCH 127/292] [GFS2] Fix warning on impossible event in eattr code The caller ensures that ea_list_i() is never called with an invalid type, so lets BUG() if we see one. This clears up a couple of compiler warnings too. Signed-off-by: Steven Whitehouse --- fs/gfs2/eattr.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 346601538ac7..2e114c075707 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -374,8 +374,8 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, return 0; if (er->er_data_len) { - char *prefix; - unsigned int l; + char *prefix = NULL; + unsigned int l = 0; char c = 0; if (ei->ei_size + ea_size > er->er_data_len) @@ -394,11 +394,10 @@ static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, prefix = "security."; l = 9; break; - default: - /* FIXME: Needs looking at again */ - break; } + BUG_ON(l == 0); + memcpy(er->er_data + ei->ei_size, prefix, l); memcpy(er->er_data + ei->ei_size + l, GFS2_EA2NAME(ea), ea->ea_name_len); From 22da645fd6675b7abc55cf937ddf6132f343e5b9 Mon Sep 17 00:00:00 2001 From: Patrick Caulfield Date: Fri, 9 Jun 2006 16:14:20 -0400 Subject: [PATCH 128/292] [DLM] compat patch Here's a patch which add 32/64 bit compat to the DLM IOs and tidies the structures for alignment. As it causes an ABI change I had few qualms about adding the extra flag for "is64bit" as it simply uses a byte that would have been padding. Cc: David Woodhouse Signed-off-by: Patrick Caulfield Signed-off-by: Steven Whitehouse --- fs/dlm/device.c | 166 ++++++++++++++++++++++++++++++++++--- include/linux/dlm_device.h | 11 ++- 2 files changed, 163 insertions(+), 14 deletions(-) diff --git a/fs/dlm/device.c b/fs/dlm/device.c index 49a20d549216..47798fe46d72 100644 --- a/fs/dlm/device.c +++ b/fs/dlm/device.c @@ -2,7 +2,7 @@ ******************************************************************************* ** ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. ** ** This copyrighted material is made available to anyone wishing to use, ** modify, copy, or redistribute it subject to the terms and conditions @@ -59,6 +59,9 @@ static rwlock_t lockinfo_lock; #define LS_FLAG_DELETED 1 #define LS_FLAG_AUTOFREE 2 +/* flags in ls_flags*/ +#define FI_FLAG_OPEN 1 +#define FI_FLAG_COMPAT 2 #define LOCKINFO_MAGIC 0x53595324 @@ -117,9 +120,110 @@ struct file_info { wait_queue_head_t fi_wait; struct user_ls *fi_ls; atomic_t fi_refcnt; /* Number of users */ - unsigned long fi_flags; /* Bit 1 means the device is open */ + unsigned long fi_flags; }; +#ifdef CONFIG_COMPAT + +struct dlm_lock_params32 { + __u8 mode; + __u8 namelen; + __u16 flags; + __u32 lkid; + __u32 parent; + + __u32 castparam; + __u32 castaddr; + __u32 bastparam; + __u32 bastaddr; + __u32 lksb; + + char lvb[DLM_USER_LVB_LEN]; + char name[0]; +}; + +struct dlm_write_request32 { + __u32 version[3]; + __u8 cmd; + __u8 is64bit; + __u8 unused[2]; + + union { + struct dlm_lock_params32 lock; + struct dlm_lspace_params lspace; + } i; +}; + +struct dlm_lksb32 { + __u32 sb_status; + __u32 sb_lkid; + __u8 sb_flags; + __u32 sb_lvbptr; +}; + +struct dlm_lock_result32 { + __u32 length; + __u32 user_astaddr; + __u32 user_astparam; + __u32 user_lksb; + struct dlm_lksb32 lksb; + __u8 bast_mode; + __u8 unused[3]; + /* Offsets may be zero if no data is present */ + __u32 lvb_offset; +}; + + +static void compat_input(struct dlm_write_request *kparams, struct dlm_write_request32 *k32params) +{ + + kparams->version[0] = k32params->version[0]; + kparams->version[1] = k32params->version[1]; + kparams->version[2] = k32params->version[2]; + + kparams->cmd = k32params->cmd; + kparams->is64bit = k32params->is64bit; + if (kparams->cmd == DLM_USER_CREATE_LOCKSPACE || + kparams->cmd == DLM_USER_REMOVE_LOCKSPACE) { + + kparams->i.lspace.flags = k32params->i.lspace.flags; + kparams->i.lspace.minor = k32params->i.lspace.minor; + strcpy(kparams->i.lspace.name, k32params->i.lspace.name); + } + else { + kparams->i.lock.mode = k32params->i.lock.mode; + kparams->i.lock.namelen = k32params->i.lock.namelen; + kparams->i.lock.flags = k32params->i.lock.flags; + kparams->i.lock.lkid = k32params->i.lock.lkid; + kparams->i.lock.parent = k32params->i.lock.parent; + kparams->i.lock.castparam = (void *)(long)k32params->i.lock.castparam; + kparams->i.lock.castaddr = (void *)(long)k32params->i.lock.castaddr; + kparams->i.lock.bastparam = (void *)(long)k32params->i.lock.bastparam; + kparams->i.lock.bastaddr = (void *)(long)k32params->i.lock.bastaddr; + kparams->i.lock.lksb = (void *)(long)k32params->i.lock.lksb; + memcpy(kparams->i.lock.lvb, k32params->i.lock.lvb, DLM_USER_LVB_LEN); + memcpy(kparams->i.lock.name, k32params->i.lock.name, kparams->i.lock.namelen); + } +} + +void compat_output(struct dlm_lock_result *res, struct dlm_lock_result32 *res32) +{ + res32->length = res->length - (sizeof(struct dlm_lock_result) - sizeof(struct dlm_lock_result32)); + res32->user_astaddr = (__u32)(long)res->user_astaddr; + res32->user_astparam = (__u32)(long)res->user_astparam; + res32->user_lksb = (__u32)(long)res->user_lksb; + res32->bast_mode = res->bast_mode; + + res32->lvb_offset = res->lvb_offset; + res32->length = res->length; + + res32->lksb.sb_status = res->lksb.sb_status; + res32->lksb.sb_flags = res->lksb.sb_flags; + res32->lksb.sb_lkid = res->lksb.sb_lkid; + res32->lksb.sb_lvbptr = (__u32)(long)res->lksb.sb_lvbptr; +} +#endif + /* get and put ops for file_info. Actually I don't really like "get" and "put", but everyone @@ -364,7 +468,7 @@ static void ast_routine(void *param) li->li_grmode = li->li_rqmode; /* Only queue AST if the device is still open */ - if (test_bit(1, &li->li_file->fi_flags)) + if (test_bit(FI_FLAG_OPEN, &li->li_file->fi_flags)) add_to_astqueue(li, li->li_castaddr, li->li_castparam, lvb_updated); @@ -449,7 +553,7 @@ static int dlm_open(struct inode *inode, struct file *file) f->fi_ls = lsinfo; f->fi_flags = 0; get_file_info(f); - set_bit(1, &f->fi_flags); + set_bit(FI_FLAG_OPEN, &f->fi_flags); file->private_data = f; @@ -494,7 +598,7 @@ static int dlm_close(struct inode *inode, struct file *file) return -ENOENT; /* Mark this closed so that ASTs will not be delivered any more */ - clear_bit(1, &f->fi_flags); + clear_bit(FI_FLAG_OPEN, &f->fi_flags); /* Block signals while we are doing this */ sigfillset(&allsigs); @@ -643,11 +747,18 @@ static ssize_t dlm_read(struct file *file, char __user *buffer, size_t count, { struct file_info *fi = file->private_data; struct ast_info *ast; + void *data; int data_size; + int struct_size; int offset; DECLARE_WAITQUEUE(wait, current); +#ifdef CONFIG_COMPAT + struct dlm_lock_result32 result32; + if (count < sizeof(struct dlm_lock_result32)) +#else if (count < sizeof(struct dlm_lock_result)) +#endif return -EINVAL; spin_lock(&fi->fi_ast_lock); @@ -691,11 +802,21 @@ static ssize_t dlm_read(struct file *file, char __user *buffer, size_t count, spin_unlock(&fi->fi_ast_lock); /* Work out the size of the returned data */ - data_size = sizeof(struct dlm_lock_result); +#ifdef CONFIG_COMPAT + if (test_bit(FI_FLAG_COMPAT, &fi->fi_flags)) { + data_size = struct_size = sizeof(struct dlm_lock_result32); + data = &result32; + } + else +#endif + { + data_size = struct_size = sizeof(struct dlm_lock_result); + data = &ast->result; + } if (ast->lvb_updated && ast->result.lksb.sb_lvbptr) data_size += DLM_USER_LVB_LEN; - offset = sizeof(struct dlm_lock_result); + offset = struct_size; /* Room for the extended data ? */ if (count >= data_size) { @@ -711,8 +832,13 @@ static ssize_t dlm_read(struct file *file, char __user *buffer, size_t count, } ast->result.length = data_size; + +#ifdef CONFIG_COMPAT + compat_output(&ast->result, &result32); +#endif + /* Copy the header now it has all the offsets in it */ - if (copy_to_user(buffer, &ast->result, sizeof(struct dlm_lock_result))) + if (copy_to_user(buffer, data, struct_size)) offset = -EFAULT; /* If we only returned a header and there's more to come then put it @@ -970,8 +1096,14 @@ static ssize_t dlm_write(struct file *file, const char __user *buffer, sigset_t allsigs; int status; - /* -1 because lock name is optional */ - if (count < sizeof(struct dlm_write_request)-1) +#ifdef CONFIG_COMPAT + if (count < sizeof(struct dlm_write_request32)) +#else + if (count < sizeof(struct dlm_write_request)) +#endif + return -EINVAL; + + if (count > sizeof(struct dlm_write_request) + DLM_RESNAME_MAXLEN) return -EINVAL; /* Has the lockspace been deleted */ @@ -991,6 +1123,20 @@ static ssize_t dlm_write(struct file *file, const char __user *buffer, if (check_version(kparams)) goto out_free; +#ifdef CONFIG_COMPAT + if (!kparams->is64bit) { + struct dlm_write_request32 *k32params = (struct dlm_write_request32 *)kparams; + kparams = kmalloc(count + (sizeof(struct dlm_write_request) - sizeof(struct dlm_write_request32)), GFP_KERNEL); + if (!kparams) + return -ENOMEM; + + if (fi) + set_bit(FI_FLAG_COMPAT, &fi->fi_flags); + compat_input(kparams, k32params); + kfree(k32params); + } +#endif + /* Block signals while we are doing this */ sigfillset(&allsigs); sigprocmask(SIG_BLOCK, &allsigs, &tmpsig); diff --git a/include/linux/dlm_device.h b/include/linux/dlm_device.h index f8ba1981aa96..2a2dd189b9fd 100644 --- a/include/linux/dlm_device.h +++ b/include/linux/dlm_device.h @@ -18,35 +18,37 @@ #define DLM_USER_LVB_LEN 32 /* Version of the device interface */ -#define DLM_DEVICE_VERSION_MAJOR 4 +#define DLM_DEVICE_VERSION_MAJOR 5 #define DLM_DEVICE_VERSION_MINOR 0 #define DLM_DEVICE_VERSION_PATCH 0 /* struct passed to the lock write */ struct dlm_lock_params { __u8 mode; + __u8 namelen; __u16 flags; __u32 lkid; __u32 parent; - __u8 namelen; void __user *castparam; void __user *castaddr; void __user *bastparam; void __user *bastaddr; struct dlm_lksb __user *lksb; char lvb[DLM_USER_LVB_LEN]; - char name[1]; + char name[0]; }; struct dlm_lspace_params { __u32 flags; __u32 minor; - char name[1]; + char name[0]; }; struct dlm_write_request { __u32 version[3]; __u8 cmd; + __u8 is64bit; + __u8 unused[2]; union { struct dlm_lock_params lock; @@ -63,6 +65,7 @@ struct dlm_lock_result { struct dlm_lksb __user * user_lksb; struct dlm_lksb lksb; __u8 bast_mode; + __u8 unused[3]; /* Offsets may be zero if no data is present */ __u32 lvb_offset; }; From feaa7bba026c181ce071d5a4884f7f9dd26207a1 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 14 Jun 2006 15:32:57 -0400 Subject: [PATCH 129/292] [GFS2] Fix unlinked file handling This patch fixes the way we have been dealing with unlinked, but still open files. It removes all limits (other than memory for inodes, as per every other filesystem) on numbers of these which we can support on GFS2. It also means that (like other fs) its the responsibility of the last process to close the file to deallocate the storage, rather than the person who did the unlinking. Note that with GFS2, those two events might take place on different nodes. Also there are a number of other changes: o We use the Linux inode subsystem as it was intended to be used, wrt allocating GFS2 inodes o The Linux inode cache is now the point which we use for local enforcement of only holding one copy of the inode in core at once (previous to this we used the glock layer). o We no longer use the unlinked "special" file. We just ignore it completely. This makes unlinking more efficient. o We now use the 4th block allocation state. The previously unused state is used to track unlinked but still open inodes. o gfs2_inoded is no longer needed o Several fields are now no longer needed (and removed) from the in core struct gfs2_inode o Several fields are no longer needed (and removed) from the in core superblock There are a number of future possible optimisations and clean ups which have been made possible by this patch. Signed-off-by: Steven Whitehouse --- fs/gfs2/Makefile | 2 +- fs/gfs2/acl.c | 10 +- fs/gfs2/bmap.c | 44 +- fs/gfs2/daemon.c | 27 -- fs/gfs2/daemon.h | 1 - fs/gfs2/dir.c | 66 +-- fs/gfs2/eaops.c | 14 +- fs/gfs2/eattr.c | 70 +-- fs/gfs2/glock.c | 102 +---- fs/gfs2/glock.h | 5 +- fs/gfs2/glops.c | 9 +- fs/gfs2/incore.h | 48 +-- fs/gfs2/inode.c | 817 ++++++++---------------------------- fs/gfs2/inode.h | 32 +- fs/gfs2/log.c | 3 + fs/gfs2/lops.c | 30 +- fs/gfs2/main.c | 2 - fs/gfs2/meta_io.c | 12 +- fs/gfs2/ondisk.c | 17 - fs/gfs2/ops_address.c | 31 +- fs/gfs2/ops_dentry.c | 6 +- fs/gfs2/ops_export.c | 64 ++- fs/gfs2/ops_file.c | 42 +- fs/gfs2/ops_fstype.c | 103 +---- fs/gfs2/ops_inode.c | 168 +++----- fs/gfs2/ops_super.c | 110 ++++- fs/gfs2/ops_vm.c | 12 +- fs/gfs2/page.c | 64 ++- fs/gfs2/quota.c | 28 +- fs/gfs2/recovery.c | 23 +- fs/gfs2/rgrp.c | 120 +++--- fs/gfs2/rgrp.h | 1 + fs/gfs2/super.c | 45 +- fs/gfs2/sys.c | 2 - fs/gfs2/trans.h | 1 - fs/gfs2/unlinked.c | 459 -------------------- fs/gfs2/unlinked.h | 25 -- fs/gfs2/util.c | 2 +- include/linux/gfs2_ondisk.h | 34 +- 39 files changed, 752 insertions(+), 1899 deletions(-) delete mode 100644 fs/gfs2/unlinked.c delete mode 100644 fs/gfs2/unlinked.h diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile index 9974201aa16c..0b7977623b80 100644 --- a/fs/gfs2/Makefile +++ b/fs/gfs2/Makefile @@ -3,7 +3,7 @@ gfs2-y := acl.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \ glops.o inode.o lm.o log.o lops.o locking.o lvb.o main.o meta_io.o \ mount.o ondisk.o ops_address.o ops_dentry.o ops_export.o ops_file.o \ ops_fstype.o ops_inode.o ops_super.o ops_vm.o page.o quota.o \ - recovery.o rgrp.o super.o sys.o trans.o unlinked.o util.o + recovery.o rgrp.o super.o sys.o trans.o util.o obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += locking/nolock/ obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += locking/dlm/ diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index 343dbe3e87bb..9ef4cf2c03db 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -73,7 +73,7 @@ int gfs2_acl_validate_set(struct gfs2_inode *ip, int access, int gfs2_acl_validate_remove(struct gfs2_inode *ip, int access) { - if (!ip->i_sbd->sd_args.ar_posix_acl) + if (!GFS2_SB(&ip->i_inode)->sd_args.ar_posix_acl) return -EOPNOTSUPP; if (current->fsuid != ip->i_di.di_uid && !capable(CAP_FOWNER)) return -EPERM; @@ -160,7 +160,7 @@ int gfs2_check_acl_locked(struct inode *inode, int mask) struct posix_acl *acl = NULL; int error; - error = acl_get(inode->u.generic_ip, ACL_ACCESS, &acl, NULL, NULL, NULL); + error = acl_get(GFS2_I(inode), ACL_ACCESS, &acl, NULL, NULL, NULL); if (error) return error; @@ -175,7 +175,7 @@ int gfs2_check_acl_locked(struct inode *inode, int mask) int gfs2_check_acl(struct inode *inode, int mask) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder i_gh; int error; @@ -192,7 +192,7 @@ int gfs2_check_acl(struct inode *inode, int mask) static int munge_mode(struct gfs2_inode *ip, mode_t mode) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *dibh; int error; @@ -217,7 +217,7 @@ static int munge_mode(struct gfs2_inode *ip, mode_t mode) int gfs2_acl_create(struct gfs2_inode *dip, struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct posix_acl *acl = NULL, *clone; struct gfs2_ea_request er; mode_t mode = ip->i_di.di_mode; diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 41abd3f4fc73..98fa07c2b710 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -136,7 +136,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); uint64_t *arr; unsigned int max, height; @@ -169,7 +169,7 @@ static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size) static int build_height(struct inode *inode, unsigned height) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); unsigned new_height = height - ip->i_di.di_height; struct buffer_head *dibh; struct buffer_head *blocks[GFS2_MAX_META_HEIGHT]; @@ -283,7 +283,7 @@ static int build_height(struct inode *inode, unsigned height) static void find_metapath(struct gfs2_inode *ip, uint64_t block, struct metapath *mp) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); uint64_t b = block; unsigned int i; @@ -382,8 +382,8 @@ static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock, int *boundary, struct metapath *mp) { - struct gfs2_inode *ip = inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); struct buffer_head *bh; int create = *new; unsigned int bsize; @@ -446,7 +446,7 @@ out: static inline void bmap_lock(struct inode *inode, int create) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); if (create) down_write(&ip->i_rw_mutex); else @@ -455,7 +455,7 @@ static inline void bmap_lock(struct inode *inode, int create) static inline void bmap_unlock(struct inode *inode, int create) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); if (create) up_write(&ip->i_rw_mutex); else @@ -481,8 +481,8 @@ int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int * int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen) { - struct gfs2_inode *ip = inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); struct metapath mp; struct buffer_head *bh; int boundary; @@ -541,7 +541,7 @@ static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh, uint64_t block, int first, block_call_t bc, void *data) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *bh = NULL; uint64_t *top, *bottom; uint64_t bn; @@ -609,8 +609,8 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, struct buffer_head *bh, uint64_t *top, uint64_t *bottom, unsigned int height, void *data) { - struct strip_mine *sm = (struct strip_mine *)data; - struct gfs2_sbd *sdp = ip->i_sbd; + struct strip_mine *sm = data; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_rgrp_list rlist; uint64_t bn, bstart; uint32_t blen; @@ -756,7 +756,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, static int do_grow(struct gfs2_inode *ip, uint64_t size) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al; struct buffer_head *dibh; unsigned int h; @@ -795,7 +795,7 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size) h = calc_tree_height(ip, size); if (ip->i_di.di_height < h) { down_write(&ip->i_rw_mutex); - error = build_height(ip->i_vnode, h); + error = build_height(&ip->i_inode, h); up_write(&ip->i_rw_mutex); if (error) goto out_end_trans; @@ -830,7 +830,7 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size) static int trunc_start(struct gfs2_inode *ip, uint64_t size) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *dibh; int journaled = gfs2_is_jdata(ip); int error; @@ -854,7 +854,7 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size) } else { if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1)) - error = gfs2_block_truncate_page(ip->i_vnode->i_mapping); + error = gfs2_block_truncate_page(ip->i_inode.i_mapping); if (!error) { ip->i_di.di_size = size; @@ -883,7 +883,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size) if (!size) lblock = 0; else - lblock = (size - 1) >> ip->i_sbd->sd_sb.sb_bsize_shift; + lblock = (size - 1) >> GFS2_SB(&ip->i_inode)->sd_sb.sb_bsize_shift; find_metapath(ip, lblock, &mp); gfs2_alloc_get(ip); @@ -911,7 +911,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size) static int trunc_end(struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *dibh; int error; @@ -990,7 +990,7 @@ int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size) { int error; - if (gfs2_assert_warn(ip->i_sbd, S_ISREG(ip->i_di.di_mode))) + if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), S_ISREG(ip->i_di.di_mode))) return -EINVAL; if (size > ip->i_di.di_size) @@ -1027,7 +1027,7 @@ int gfs2_file_dealloc(struct gfs2_inode *ip) void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, unsigned int *data_blocks, unsigned int *ind_blocks) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); unsigned int tmp; if (gfs2_is_dir(ip)) { @@ -1057,7 +1057,7 @@ void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, unsigned int len, int *alloc_required) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); uint64_t lblock, lblock_stop, dblock; uint32_t extlen; int new = 0; @@ -1088,7 +1088,7 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, } for (; lblock < lblock_stop; lblock += extlen) { - error = gfs2_extent_map(ip->i_vnode, lblock, &new, &dblock, &extlen); + error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen); if (error) return error; diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c index 9e7b9f296786..1453605c8f32 100644 --- a/fs/gfs2/daemon.c +++ b/fs/gfs2/daemon.c @@ -25,7 +25,6 @@ #include "quota.h" #include "recovery.h" #include "super.h" -#include "unlinked.h" #include "util.h" /* This uses schedule_timeout() instead of msleep() because it's good for @@ -195,29 +194,3 @@ int gfs2_quotad(void *data) return 0; } -/** - * gfs2_inoded - Deallocate unlinked inodes - * @sdp: Pointer to GFS2 superblock - * - */ - -int gfs2_inoded(void *data) -{ - struct gfs2_sbd *sdp = data; - unsigned long t; - int error; - - while (!kthread_should_stop()) { - error = gfs2_unlinked_dealloc(sdp); - if (error && - error != -EROFS && - !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) - fs_err(sdp, "inoded: error = %d\n", error); - - t = gfs2_tune_get(sdp, gt_inoded_secs) * HZ; - schedule_timeout_interruptible(t); - } - - return 0; -} - diff --git a/fs/gfs2/daemon.h b/fs/gfs2/daemon.h index aa68e7a1b0b7..aa93eb6f668e 100644 --- a/fs/gfs2/daemon.h +++ b/fs/gfs2/daemon.h @@ -15,6 +15,5 @@ int gfs2_glockd(void *data); int gfs2_recoverd(void *data); int gfs2_logd(void *data); int gfs2_quotad(void *data); -int gfs2_inoded(void *data); #endif /* __DAEMON_DOT_H__ */ diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 6918a58261e2..b0353884dd7d 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -113,7 +113,7 @@ static int gfs2_dir_get_existing_buffer(struct gfs2_inode *ip, uint64_t block, error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT, &bh); if (error) return error; - if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_JD)) { + if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_JD)) { brelse(bh); return -EIO; } @@ -158,7 +158,7 @@ static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf, static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, uint64_t offset, unsigned int size) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *dibh; uint64_t lblock, dblock; uint32_t extlen = 0; @@ -197,7 +197,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, if (!extlen) { new = 1; - error = gfs2_extent_map(ip->i_vnode, lblock, &new, + error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen); if (error) goto fail; @@ -277,7 +277,7 @@ static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf, static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, uint64_t offset, unsigned int size) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); uint64_t lblock, dblock; uint32_t extlen = 0; unsigned int o; @@ -314,7 +314,7 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, if (!extlen) { new = 0; - error = gfs2_extent_map(ip->i_vnode, lblock, &new, + error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen); if (error) goto fail; @@ -534,7 +534,7 @@ static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, } consist_inode: - gfs2_consist_inode(inode->u.generic_ip); + gfs2_consist_inode(GFS2_I(inode)); return ERR_PTR(-EIO); } @@ -556,13 +556,13 @@ static int dirent_first(struct gfs2_inode *dip, struct buffer_head *bh, struct gfs2_meta_header *h = (struct gfs2_meta_header *)bh->b_data; if (be32_to_cpu(h->mh_type) == GFS2_METATYPE_LF) { - if (gfs2_meta_check(dip->i_sbd, bh)) + if (gfs2_meta_check(GFS2_SB(&dip->i_inode), bh)) return -EIO; *dent = (struct gfs2_dirent *)(bh->b_data + sizeof(struct gfs2_leaf)); return IS_LEAF; } else { - if (gfs2_metatype_check(dip->i_sbd, bh, GFS2_METATYPE_DI)) + if (gfs2_metatype_check(GFS2_SB(&dip->i_inode), bh, GFS2_METATYPE_DI)) return -EIO; *dent = (struct gfs2_dirent *)(bh->b_data + sizeof(struct gfs2_dinode)); @@ -674,7 +674,7 @@ static struct gfs2_dirent *gfs2_init_dirent(struct inode *inode, const struct qstr *name, struct buffer_head *bh) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_dirent *ndent; unsigned offset = 0, totlen; @@ -707,8 +707,10 @@ static int get_leaf(struct gfs2_inode *dip, uint64_t leaf_no, int error; error = gfs2_meta_read(dip->i_gl, leaf_no, DIO_START | DIO_WAIT, bhp); - if (!error && gfs2_metatype_check(dip->i_sbd, *bhp, GFS2_METATYPE_LF)) + if (!error && gfs2_metatype_check(GFS2_SB(&dip->i_inode), *bhp, GFS2_METATYPE_LF)) { + /* printk(KERN_INFO "block num=%llu\n", leaf_no); */ error = -EIO; + } return error; } @@ -759,7 +761,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, { struct buffer_head *bh; struct gfs2_dirent *dent; - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); int error; if (ip->i_di.di_flags & GFS2_DIF_EXHASH) { @@ -771,7 +773,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, gfs2_consist_inode(ip); return ERR_PTR(-EIO); } - + index = name->hash >> (32 - ip->i_di.di_depth); error = get_first_leaf(ip, index, &bh); if (error) @@ -786,12 +788,14 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, brelse(bh); if (!ln) break; + error = get_leaf(ip, ln, &bh); } while(!error); return error ? ERR_PTR(error) : NULL; } + error = gfs2_meta_inode_buffer(ip, &bh); if (error) return ERR_PTR(error); @@ -807,7 +811,7 @@ got_dent: static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, u16 depth) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); u64 bn = gfs2_alloc_meta(ip); struct buffer_head *bh = gfs2_meta_new(ip->i_gl, bn); struct gfs2_leaf *leaf; @@ -815,6 +819,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, struct qstr name = { .name = "", .len = 0, .hash = 0 }; if (!bh) return NULL; + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); leaf = (struct gfs2_leaf *)bh->b_data; @@ -838,8 +843,8 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, static int dir_make_exhash(struct inode *inode) { - struct gfs2_inode *dip = inode->u.generic_ip; - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *dip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); struct gfs2_dirent *dent; struct qstr args; struct buffer_head *bh, *dibh; @@ -874,7 +879,7 @@ static int dir_make_exhash(struct inode *inode) args.len = bh->b_size - sizeof(struct gfs2_dinode) + sizeof(struct gfs2_leaf); args.name = bh->b_data; - dent = gfs2_dirent_scan(dip->i_vnode, bh->b_data, bh->b_size, + dent = gfs2_dirent_scan(&dip->i_inode, bh->b_data, bh->b_size, gfs2_dirent_last, &args, NULL); if (!dent) { brelse(bh); @@ -933,7 +938,7 @@ static int dir_make_exhash(struct inode *inode) static int dir_split_leaf(struct inode *inode, const struct qstr *name) { - struct gfs2_inode *dip = inode->u.generic_ip; + struct gfs2_inode *dip = GFS2_I(inode); struct buffer_head *nbh, *obh, *dibh; struct gfs2_leaf *nleaf, *oleaf; struct gfs2_dirent *dent, *prev = NULL, *next = NULL, *new; @@ -1044,7 +1049,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) oleaf->lf_depth = nleaf->lf_depth; error = gfs2_meta_inode_buffer(dip, &dibh); - if (!gfs2_assert_withdraw(dip->i_sbd, !error)) { + if (!gfs2_assert_withdraw(GFS2_SB(&dip->i_inode), !error)) { dip->i_di.di_blocks++; gfs2_dinode_out(&dip->i_di, dibh->b_data); brelse(dibh); @@ -1073,7 +1078,7 @@ fail_brelse: static int dir_double_exhash(struct gfs2_inode *dip) { - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct buffer_head *dibh; uint32_t hsize; uint64_t *buf; @@ -1268,7 +1273,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque, gfs2_filldir_t filldir, int *copied, unsigned *depth, u64 leaf_no) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct buffer_head *bh; struct gfs2_leaf *lf; unsigned entries = 0; @@ -1348,8 +1353,8 @@ out: static int dir_e_read(struct inode *inode, uint64_t *offset, void *opaque, gfs2_filldir_t filldir) { - struct gfs2_inode *dip = inode->u.generic_ip; - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *dip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); uint32_t hsize, len = 0; uint32_t ht_offset, lp_offset, ht_offset_cur = -1; uint32_t hash, index; @@ -1407,7 +1412,7 @@ out: int gfs2_dir_read(struct inode *inode, uint64_t *offset, void *opaque, gfs2_filldir_t filldir) { - struct gfs2_inode *dip = inode->u.generic_ip; + struct gfs2_inode *dip = GFS2_I(inode); struct dirent_gather g; const struct gfs2_dirent **darr, *dent; struct buffer_head *dibh; @@ -1490,7 +1495,7 @@ int gfs2_dir_search(struct inode *dir, const struct qstr *name, static int dir_new_leaf(struct inode *inode, const struct qstr *name) { struct buffer_head *bh, *obh; - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_leaf *leaf, *oleaf; int error; u32 index; @@ -1545,7 +1550,7 @@ static int dir_new_leaf(struct inode *inode, const struct qstr *name) int gfs2_dir_add(struct inode *inode, const struct qstr *name, const struct gfs2_inum *inum, unsigned type) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct buffer_head *bh; struct gfs2_dirent *dent; struct gfs2_leaf *leaf; @@ -1623,7 +1628,7 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name) /* Returns _either_ the entry (if its first in block) or the previous entry otherwise */ - dent = gfs2_dirent_search(dip->i_vnode, name, gfs2_dirent_prev, &bh); + dent = gfs2_dirent_search(&dip->i_inode, name, gfs2_dirent_prev, &bh); if (!dent) { gfs2_consist_inode(dip); return -EIO; @@ -1659,6 +1664,7 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name) dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); gfs2_dinode_out(&dip->i_di, bh->b_data); brelse(bh); + mark_inode_dirty(&dip->i_inode); return error; } @@ -1683,7 +1689,7 @@ int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, struct gfs2_dirent *dent; int error; - dent = gfs2_dirent_search(dip->i_vnode, filename, gfs2_dirent_find, &bh); + dent = gfs2_dirent_search(&dip->i_inode, filename, gfs2_dirent_find, &bh); if (!dent) { gfs2_consist_inode(dip); return -EIO; @@ -1720,7 +1726,7 @@ int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) { - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct buffer_head *bh; struct gfs2_leaf *leaf; uint32_t hsize, len; @@ -1800,7 +1806,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, uint64_t leaf_no, void *data) { - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct gfs2_leaf *tmp_leaf; struct gfs2_rgrp_list rlist; struct buffer_head *bh, *dibh; @@ -1920,7 +1926,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip) { - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct buffer_head *bh; int error; diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index 1c5ac3160b3b..b7e6a37cab6e 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -58,7 +58,7 @@ unsigned int gfs2_ea_name2type(const char *name, char **truncated_name) static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) { - struct inode *inode = ip->i_vnode; + struct inode *inode = &ip->i_inode; int error = permission(inode, MAY_READ, NULL); if (error) return error; @@ -68,7 +68,7 @@ static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) { - struct inode *inode = ip->i_vnode; + struct inode *inode = &ip->i_inode; if (S_ISREG(inode->i_mode) || (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) { @@ -83,7 +83,7 @@ static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) static int user_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) { - struct inode *inode = ip->i_vnode; + struct inode *inode = &ip->i_inode; if (S_ISREG(inode->i_mode) || (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) { @@ -103,7 +103,7 @@ static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) !capable(CAP_SYS_ADMIN)) return -EPERM; - if (ip->i_sbd->sd_args.ar_posix_acl == 0 && + if (GFS2_SB(&ip->i_inode)->sd_args.ar_posix_acl == 0 && (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) || GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len))) return -EOPNOTSUPP; @@ -172,7 +172,7 @@ static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) static int security_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) { - struct inode *inode = ip->i_vnode; + struct inode *inode = &ip->i_inode; int error = permission(inode, MAY_READ, NULL); if (error) return error; @@ -182,7 +182,7 @@ static int security_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) static int security_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) { - struct inode *inode = ip->i_vnode; + struct inode *inode = &ip->i_inode; int error = permission(inode, MAY_WRITE, NULL); if (error) return error; @@ -192,7 +192,7 @@ static int security_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) static int security_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) { - struct inode *inode = ip->i_vnode; + struct inode *inode = &ip->i_inode; int error = permission(inode, MAY_WRITE, NULL); if (error) return error; diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 2e114c075707..96736932260f 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -80,7 +80,7 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, struct gfs2_ea_header *ea, *prev = NULL; int error = 0; - if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_EA)) + if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_EA)) return -EIO; for (ea = GFS2_EA_BH2FIRST(bh);; prev = ea, ea = GFS2_EA2NEXT(ea)) { @@ -128,13 +128,13 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) goto out; } - if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_IN)) { + if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_IN)) { error = -EIO; goto out; } eablk = (uint64_t *)(bh->b_data + sizeof(struct gfs2_meta_header)); - end = eablk + ip->i_sbd->sd_inptrs; + end = eablk + GFS2_SB(&ip->i_inode)->sd_inptrs; for (; eablk < end; eablk++) { uint64_t bn; @@ -232,7 +232,7 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, struct gfs2_ea_header *prev, void *private) { int *leave = private; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_rgrpd *rgd; struct gfs2_holder rg_gh; struct buffer_head *dibh; @@ -338,7 +338,7 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, if (error) goto out_alloc; - error = gfs2_rindex_hold(ip->i_sbd, &al->al_ri_gh); + error = gfs2_rindex_hold(GFS2_SB(&ip->i_inode), &al->al_ri_gh); if (error) goto out_quota; @@ -459,7 +459,7 @@ int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er) static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, char *data) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head **bh; unsigned int amount = GFS2_EA_DATA_LEN(ea); unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); @@ -604,7 +604,7 @@ int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_ea_header *ea; uint64_t block; @@ -641,7 +641,7 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp) static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, struct gfs2_ea_request *er) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); ea->ea_data_len = cpu_to_be32(er->er_data_len); ea->ea_name_len = er->er_name_len; @@ -723,7 +723,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, if (error) goto out_gunlock_q; - error = gfs2_trans_begin(ip->i_sbd, + error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), blks + al->al_rgd->rd_ri.ri_length + RES_DINODE + RES_STATFS + RES_QUOTA, 0); if (error) @@ -736,7 +736,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, error = gfs2_meta_inode_buffer(ip, &dibh); if (!error) { if (er->er_flags & GFS2_ERF_MODE) { - gfs2_assert_withdraw(ip->i_sbd, + gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), (ip->i_di.di_mode & S_IFMT) == (er->er_mode & S_IFMT)); ip->i_di.di_mode = er->er_mode; @@ -748,7 +748,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, } out_end_trans: - gfs2_trans_end(ip->i_sbd); + gfs2_trans_end(GFS2_SB(&ip->i_inode)); out_ipres: gfs2_inplace_release(ip); @@ -790,7 +790,7 @@ static int ea_init_i(struct gfs2_inode *ip, struct gfs2_ea_request *er, static int ea_init(struct gfs2_inode *ip, struct gfs2_ea_request *er) { - unsigned int jbsize = ip->i_sbd->sd_jbsize; + unsigned int jbsize = GFS2_SB(&ip->i_inode)->sd_jbsize; unsigned int blks = 1; if (GFS2_EAREQ_SIZE_STUFFED(er) > jbsize) @@ -830,7 +830,7 @@ static void ea_set_remove_stuffed(struct gfs2_inode *ip, return; } else if (GFS2_EA2NEXT(prev) != ea) { prev = GFS2_EA2NEXT(prev); - gfs2_assert_withdraw(ip->i_sbd, GFS2_EA2NEXT(prev) == ea); + gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), GFS2_EA2NEXT(prev) == ea); } len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea); @@ -857,7 +857,7 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh, struct buffer_head *dibh; int error; - error = gfs2_trans_begin(ip->i_sbd, RES_DINODE + 2 * RES_EATTR, 0); + error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + 2 * RES_EATTR, 0); if (error) return error; @@ -876,7 +876,7 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh, goto out; if (er->er_flags & GFS2_ERF_MODE) { - gfs2_assert_withdraw(ip->i_sbd, + gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), (ip->i_di.di_mode & S_IFMT) == (er->er_mode & S_IFMT)); ip->i_di.di_mode = er->er_mode; } @@ -885,7 +885,7 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh, gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); out: - gfs2_trans_end(ip->i_sbd); + gfs2_trans_end(GFS2_SB(&ip->i_inode)); return error; } @@ -921,7 +921,7 @@ static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh, int stuffed; int error; - stuffed = ea_calc_size(ip->i_sbd, es->es_er, &size); + stuffed = ea_calc_size(GFS2_SB(&ip->i_inode), es->es_er, &size); if (ea->ea_type == GFS2_EATYPE_UNUSED) { if (GFS2_EA_REC_LEN(ea) < size) @@ -947,7 +947,7 @@ static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh, es->es_bh = bh; es->es_ea = ea; blks = 2 + DIV_ROUND_UP(es->es_er->er_data_len, - ip->i_sbd->sd_jbsize); + GFS2_SB(&ip->i_inode)->sd_jbsize); error = ea_alloc_skeleton(ip, es->es_er, blks, ea_set_simple_alloc, es); @@ -961,7 +961,7 @@ static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh, static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, void *private) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *indbh, *newbh; uint64_t *eablk; int error; @@ -1050,8 +1050,8 @@ static int ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er, if (!(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT)) blks++; - if (GFS2_EAREQ_SIZE_STUFFED(er) > ip->i_sbd->sd_jbsize) - blks += DIV_ROUND_UP(er->er_data_len, ip->i_sbd->sd_jbsize); + if (GFS2_EAREQ_SIZE_STUFFED(er) > GFS2_SB(&ip->i_inode)->sd_jbsize) + blks += DIV_ROUND_UP(er->er_data_len, GFS2_SB(&ip->i_inode)->sd_jbsize); return ea_alloc_skeleton(ip, er, blks, ea_set_block, el); } @@ -1061,7 +1061,7 @@ static int ea_set_remove_unstuffed(struct gfs2_inode *ip, { if (el->el_prev && GFS2_EA2NEXT(el->el_prev) != el->el_ea) { el->el_prev = GFS2_EA2NEXT(el->el_prev); - gfs2_assert_withdraw(ip->i_sbd, + gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), GFS2_EA2NEXT(el->el_prev) == el->el_ea); } @@ -1119,7 +1119,7 @@ int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) er->er_data = NULL; er->er_data_len = 0; } - error = ea_check_size(ip->i_sbd, er); + error = ea_check_size(GFS2_SB(&ip->i_inode), er); if (error) return error; @@ -1127,7 +1127,7 @@ int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) if (error) return error; - if (IS_IMMUTABLE(ip->i_vnode)) + if (IS_IMMUTABLE(&ip->i_inode)) error = -EPERM; else error = gfs2_ea_ops[er->er_type]->eo_set(ip, er); @@ -1144,7 +1144,7 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el) struct buffer_head *dibh; int error; - error = gfs2_trans_begin(ip->i_sbd, RES_DINODE + RES_EATTR, 0); + error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + RES_EATTR, 0); if (error) return error; @@ -1169,7 +1169,7 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el) brelse(dibh); } - gfs2_trans_end(ip->i_sbd); + gfs2_trans_end(GFS2_SB(&ip->i_inode)); return error; } @@ -1219,7 +1219,7 @@ int gfs2_ea_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) if (error) return error; - if (IS_IMMUTABLE(ip->i_vnode) || IS_APPEND(ip->i_vnode)) + if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode)) error = -EPERM; else error = gfs2_ea_ops[er->er_type]->eo_remove(ip, er); @@ -1232,7 +1232,7 @@ int gfs2_ea_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, char *data) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head **bh; unsigned int amount = GFS2_EA_DATA_LEN(ea); unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); @@ -1304,7 +1304,7 @@ int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el, int error; if (GFS2_EA_IS_STUFFED(el->el_ea)) { - error = gfs2_trans_begin(ip->i_sbd, RES_DINODE + RES_EATTR, 0); + error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + RES_EATTR, 0); if (error) return error; @@ -1320,22 +1320,22 @@ int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el, error = gfs2_meta_inode_buffer(ip, &dibh); if (!error) { - error = inode_setattr(ip->i_vnode, attr); - gfs2_assert_warn(ip->i_sbd, !error); + error = inode_setattr(&ip->i_inode, attr); + gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); gfs2_inode_attr_out(ip); gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); } - gfs2_trans_end(ip->i_sbd); + gfs2_trans_end(GFS2_SB(&ip->i_inode)); return error; } static int ea_dealloc_indirect(struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_rgrp_list rlist; struct buffer_head *indbh, *dibh; uint64_t *eablk, *end; @@ -1456,7 +1456,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) static int ea_dealloc_block(struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; struct gfs2_rgrpd *rgd; struct buffer_head *dibh; @@ -1518,7 +1518,7 @@ int gfs2_ea_dealloc(struct gfs2_inode *ip) if (error) goto out_alloc; - error = gfs2_rindex_hold(ip->i_sbd, &al->al_ri_gh); + error = gfs2_rindex_hold(GFS2_SB(&ip->i_inode), &al->al_ri_gh); if (error) goto out_quota; diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 0603a6de52c9..35bac90878a5 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -654,7 +654,7 @@ static void run_queue(struct gfs2_glock *gl) * Gives caller exclusive access to manipulate a glock structure. */ -void gfs2_glmutex_lock(struct gfs2_glock *gl) +static void gfs2_glmutex_lock(struct gfs2_glock *gl) { struct gfs2_holder gh; @@ -704,7 +704,7 @@ static int gfs2_glmutex_trylock(struct gfs2_glock *gl) * */ -void gfs2_glmutex_unlock(struct gfs2_glock *gl) +static void gfs2_glmutex_unlock(struct gfs2_glock *gl) { spin_lock(&gl->gl_spin); clear_bit(GLF_LOCK, &gl->gl_flags); @@ -726,7 +726,7 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state) { struct gfs2_holder *gh, *new_gh = NULL; - restart: +restart: spin_lock(&gl->gl_spin); list_for_each_entry(gh, &gl->gl_waiters2, gh_list) { @@ -752,13 +752,27 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state) goto restart; } - out: +out: spin_unlock(&gl->gl_spin); if (new_gh) gfs2_holder_put(new_gh); } +void gfs2_glock_inode_squish(struct inode *inode) +{ + struct gfs2_holder gh; + struct gfs2_glock *gl = GFS2_I(inode)->i_gl; + gfs2_holder_init(gl, LM_ST_UNLOCKED, 0, &gh); + set_bit(HIF_DEMOTE, &gh.gh_iflags); + spin_lock(&gl->gl_spin); + gfs2_assert(inode->i_sb->s_fs_info, list_empty(&gl->gl_holders)); + list_add_tail(&gh.gh_list, &gl->gl_waiters2); + run_queue(gl); + spin_unlock(&gl->gl_spin); + gfs2_holder_uninit(&gh); +} + /** * state_change - record that the glock is now in a different state * @gl: the glock @@ -1383,8 +1397,7 @@ int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time) struct greedy *gr; struct gfs2_holder *gh; - if (!time || - gl->gl_sbd->sd_args.ar_localcaching || + if (!time || gl->gl_sbd->sd_args.ar_localcaching || test_and_set_bit(GLF_GREEDY, &gl->gl_flags)) return 1; @@ -1784,43 +1797,6 @@ void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data) } } -/** - * gfs2_try_toss_inode - try to remove a particular inode struct from cache - * sdp: the filesystem - * inum: the inode number - * - */ - -void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum) -{ - struct gfs2_glock *gl; - struct gfs2_inode *ip; - int error; - - error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops, - NO_CREATE, &gl); - if (error || !gl) - return; - - if (!gfs2_glmutex_trylock(gl)) - goto out; - - ip = gl->gl_object; - if (!ip) - goto out_unlock; - - if (atomic_read(&ip->i_count)) - goto out_unlock; - - gfs2_inode_destroy(ip, 1); - - out_unlock: - gfs2_glmutex_unlock(gl); - - out: - gfs2_glock_put(gl); -} - /** * gfs2_iopen_go_callback - Try to kick the inode/vnode associated with an * iopen glock from memory @@ -1831,34 +1807,10 @@ void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum) void gfs2_iopen_go_callback(struct gfs2_glock *io_gl, unsigned int state) { - struct gfs2_glock *i_gl; if (state != LM_ST_UNLOCKED) return; - - spin_lock(&io_gl->gl_spin); - i_gl = io_gl->gl_object; - if (i_gl) { - gfs2_glock_hold(i_gl); - spin_unlock(&io_gl->gl_spin); - } else { - spin_unlock(&io_gl->gl_spin); - return; - } - - if (gfs2_glmutex_trylock(i_gl)) { - struct gfs2_inode *ip = i_gl->gl_object; - if (ip) { - gfs2_try_toss_vnode(ip); - gfs2_glmutex_unlock(i_gl); - gfs2_glock_schedule_for_reclaim(i_gl); - goto out; - } - gfs2_glmutex_unlock(i_gl); - } - - out: - gfs2_glock_put(i_gl); + /* FIXME: remove this? */ } /** @@ -1935,11 +1887,6 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp) atomic_inc(&sdp->sd_reclaimed); if (gfs2_glmutex_trylock(gl)) { - if (gl->gl_ops == &gfs2_inode_glops) { - struct gfs2_inode *ip = gl->gl_object; - if (ip && !atomic_read(&ip->i_count)) - gfs2_inode_destroy(ip, 1); - } if (queue_empty(gl, &gl->gl_holders) && gl->gl_state != LM_ST_UNLOCKED && demote_ok(gl)) @@ -2018,7 +1965,7 @@ static void scan_glock(struct gfs2_glock *gl) if (gfs2_glmutex_trylock(gl)) { if (gl->gl_ops == &gfs2_inode_glops) { struct gfs2_inode *ip = gl->gl_object; - if (ip && !atomic_read(&ip->i_count)) + if (ip) goto out_schedule; } if (queue_empty(gl, &gl->gl_holders) && @@ -2078,11 +2025,6 @@ static void clear_glock(struct gfs2_glock *gl) } if (gfs2_glmutex_trylock(gl)) { - if (gl->gl_ops == &gfs2_inode_glops) { - struct gfs2_inode *ip = gl->gl_object; - if (ip && !atomic_read(&ip->i_count)) - gfs2_inode_destroy(ip, 1); - } if (queue_empty(gl, &gl->gl_holders) && gl->gl_state != LM_ST_UNLOCKED) handle_callback(gl, LM_ST_UNLOCKED); @@ -2199,13 +2141,11 @@ static int dump_inode(struct gfs2_inode *ip) (unsigned long long)ip->i_num.no_formal_ino, (unsigned long long)ip->i_num.no_addr); printk(KERN_INFO " type = %u\n", IF2DT(ip->i_di.di_mode)); - printk(KERN_INFO " i_count = %d\n", atomic_read(&ip->i_count)); printk(KERN_INFO " i_flags ="); for (x = 0; x < 32; x++) if (test_bit(x, &ip->i_flags)) printk(" %u", x); printk(" \n"); - printk(KERN_INFO " vnode = %s\n", (ip->i_vnode) ? "yes" : "no"); error = 0; diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 2e0a2ba92aa0..fdf58db44ae3 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -88,9 +88,6 @@ void gfs2_holder_uninit(struct gfs2_holder *gh); void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags); void gfs2_glock_drop_th(struct gfs2_glock *gl); -void gfs2_glmutex_lock(struct gfs2_glock *gl); -void gfs2_glmutex_unlock(struct gfs2_glock *gl); - int gfs2_glock_nq(struct gfs2_holder *gh); int gfs2_glock_poll(struct gfs2_holder *gh); int gfs2_glock_wait(struct gfs2_holder *gh); @@ -110,6 +107,7 @@ void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs); void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number, struct gfs2_glock_operations *glops, unsigned int state, int flags); +void gfs2_glock_inode_squish(struct inode *inode); /** * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock @@ -143,7 +141,6 @@ void gfs2_lvb_unhold(struct gfs2_glock *gl); void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data); -void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum); void gfs2_iopen_go_callback(struct gfs2_glock *gl, unsigned int state); void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl); diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index e262f22f744e..013bf5f1552f 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -129,6 +129,7 @@ static void inode_go_xmote_bh(struct gfs2_glock *gl) static void inode_go_drop_th(struct gfs2_glock *gl) { + printk(KERN_INFO "drop th %p\n", gl->gl_object); gfs2_pte_inval(gl); gfs2_glock_drop_th(gl); } @@ -147,6 +148,7 @@ static void inode_go_sync(struct gfs2_glock *gl, int flags) if (test_bit(GLF_DIRTY, &gl->gl_flags)) { if (meta && data) { + printk(KERN_INFO "sync all\n"); gfs2_page_sync(gl, flags | DIO_START); gfs2_log_flush(gl->gl_sbd, gl); gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); @@ -224,6 +226,7 @@ static int inode_go_lock(struct gfs2_holder *gh) return 0; if (ip->i_vn != gl->gl_vn) { + printk(KERN_INFO "refresh inode %p\n", &ip->i_inode); error = gfs2_inode_refresh(ip); if (error) return error; @@ -288,7 +291,7 @@ static void inode_greedy(struct gfs2_glock *gl) spin_unlock(&ip->i_spin); - gfs2_inode_put(ip); + iput(&ip->i_inode); } /** @@ -361,14 +364,14 @@ static void trans_go_xmote_th(struct gfs2_glock *gl, unsigned int state, static void trans_go_xmote_bh(struct gfs2_glock *gl) { struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_inode *ip = sdp->sd_jdesc->jd_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode); struct gfs2_glock *j_gl = ip->i_gl; struct gfs2_log_header head; int error; if (gl->gl_state != LM_ST_UNLOCKED && test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { - gfs2_meta_cache_flush(sdp->sd_jdesc->jd_inode->u.generic_ip); + gfs2_meta_cache_flush(GFS2_I(sdp->sd_jdesc->jd_inode)); j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA); error = gfs2_find_jhead(sdp->sd_jdesc, &head); diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 8caefec88854..9a67a5954126 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -33,7 +33,6 @@ struct gfs2_inode; struct gfs2_file; struct gfs2_revoke; struct gfs2_revoke_replay; -struct gfs2_unlinked; struct gfs2_quota_data; struct gfs2_log_buf; struct gfs2_trans; @@ -245,16 +244,12 @@ struct gfs2_inode { struct inode i_inode; struct gfs2_inum i_num; - atomic_t i_count; unsigned long i_flags; /* GIF_... */ uint64_t i_vn; - struct gfs2_dinode i_di; - - struct gfs2_glock *i_gl; - struct gfs2_sbd *i_sbd; - struct inode *i_vnode; + struct gfs2_dinode i_di; /* To be replaced by ref to block */ + struct gfs2_glock *i_gl; /* Move into i_gh? */ struct gfs2_holder i_iopen_gh; struct gfs2_holder i_gh; /* for prepare/commit_write only */ struct gfs2_alloc i_alloc; @@ -262,18 +257,27 @@ struct gfs2_inode { spinlock_t i_spin; struct rw_semaphore i_rw_mutex; - unsigned int i_greedy; unsigned long i_last_pfault; struct buffer_head *i_cache[GFS2_MAX_META_HEIGHT]; }; +/* + * Since i_inode is the first element of struct gfs2_inode, + * this is effectively a cast. + */ static inline struct gfs2_inode *GFS2_I(struct inode *inode) { return container_of(inode, struct gfs2_inode, i_inode); } +/* To be removed? */ +static inline struct gfs2_sbd *GFS2_SB(struct inode *inode) +{ + return inode->i_sb->s_fs_info; +} + enum { GFF_DID_DIRECT_ALLOC = 0, }; @@ -295,18 +299,6 @@ struct gfs2_revoke_replay { unsigned int rr_where; }; -enum { - ULF_LOCKED = 0, -}; - -struct gfs2_unlinked { - struct list_head ul_list; - unsigned int ul_count; - struct gfs2_unlinked_tag ul_ut; - unsigned long ul_flags; /* ULF_... */ - unsigned int ul_slot; -}; - enum { QDF_USER = 0, QDF_CHANGE = 1, @@ -436,7 +428,6 @@ struct gfs2_tune { unsigned int gt_recoverd_secs; unsigned int gt_logd_secs; unsigned int gt_quotad_secs; - unsigned int gt_inoded_secs; unsigned int gt_quota_simul_sync; /* Max quotavals to sync at once */ unsigned int gt_quota_warn_period; /* Secs between quota warn msgs */ @@ -495,7 +486,6 @@ struct gfs2_sbd { uint32_t sd_hash_bsize; /* sizeof(exhash block) */ uint32_t sd_hash_bsize_shift; uint32_t sd_hash_ptrs; /* Number of pointers in a hash block */ - uint32_t sd_ut_per_block; uint32_t sd_qc_per_block; uint32_t sd_max_dirres; /* Max blocks needed to add a directory entry */ uint32_t sd_max_height; /* Max height of a file's metadata tree */ @@ -527,7 +517,6 @@ struct gfs2_sbd { struct inode *sd_statfs_inode; struct inode *sd_ir_inode; struct inode *sd_sc_inode; - struct inode *sd_ut_inode; struct inode *sd_qc_inode; struct inode *sd_rindex; struct inode *sd_quota_inode; @@ -569,7 +558,6 @@ struct gfs2_sbd { struct gfs2_holder sd_ir_gh; struct gfs2_holder sd_sc_gh; - struct gfs2_holder sd_ut_gh; struct gfs2_holder sd_qc_gh; /* Daemon stuff */ @@ -578,21 +566,9 @@ struct gfs2_sbd { struct task_struct *sd_recoverd_process; struct task_struct *sd_logd_process; struct task_struct *sd_quotad_process; - struct task_struct *sd_inoded_process; struct task_struct *sd_glockd_process[GFS2_GLOCKD_MAX]; unsigned int sd_glockd_num; - /* Unlinked inode stuff */ - - struct list_head sd_unlinked_list; - atomic_t sd_unlinked_count; - spinlock_t sd_unlinked_spin; - struct mutex sd_unlinked_mutex; - - unsigned int sd_unlinked_slots; - unsigned int sd_unlinked_chunks; - unsigned char **sd_unlinked_bitmap; - /* Quota stuff */ struct list_head sd_quota_list; diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index c2c7d2b63a57..4e9c42119aed 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -35,7 +35,6 @@ #include "quota.h" #include "rgrp.h" #include "trans.h" -#include "unlinked.h" #include "util.h" /** @@ -72,7 +71,7 @@ static void inode_attr_in(struct gfs2_inode *ip, struct inode *inode) inode->i_ctime.tv_nsec = 0; inode->i_blksize = PAGE_SIZE; inode->i_blocks = ip->i_di.di_blocks << - (ip->i_sbd->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT); + (GFS2_SB(inode)->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT); if (ip->i_di.di_flags & GFS2_DIF_IMMUTABLE) inode->i_flags |= S_IMMUTABLE; @@ -93,13 +92,8 @@ static void inode_attr_in(struct gfs2_inode *ip, struct inode *inode) void gfs2_inode_attr_in(struct gfs2_inode *ip) { - struct inode *inode; - - inode = gfs2_ip2v_lookup(ip); - if (inode) { - inode_attr_in(ip, inode); - iput(inode); - } + struct inode *inode = &ip->i_inode; + inode_attr_in(ip, inode); } /** @@ -112,9 +106,9 @@ void gfs2_inode_attr_in(struct gfs2_inode *ip) void gfs2_inode_attr_out(struct gfs2_inode *ip) { - struct inode *inode = ip->i_vnode; + struct inode *inode = &ip->i_inode; - gfs2_assert_withdraw(ip->i_sbd, + gfs2_assert_withdraw(GFS2_SB(inode), (ip->i_di.di_mode & S_IFMT) == (inode->i_mode & S_IFMT)); ip->i_di.di_mode = inode->i_mode; ip->i_di.di_uid = inode->i_uid; @@ -124,95 +118,10 @@ void gfs2_inode_attr_out(struct gfs2_inode *ip) ip->i_di.di_ctime = inode->i_ctime.tv_sec; } -/** - * gfs2_ip2v_lookup - Get the struct inode for a struct gfs2_inode - * @ip: the struct gfs2_inode to get the struct inode for - * - * Returns: A VFS inode, or NULL if none - */ - -struct inode *gfs2_ip2v_lookup(struct gfs2_inode *ip) -{ - struct inode *inode = NULL; - - gfs2_assert_warn(ip->i_sbd, test_bit(GIF_MIN_INIT, &ip->i_flags)); - - spin_lock(&ip->i_spin); - if (ip->i_vnode) - inode = igrab(ip->i_vnode); - spin_unlock(&ip->i_spin); - - return inode; -} - -/** - * gfs2_ip2v - Get/Create a struct inode for a struct gfs2_inode - * @ip: the struct gfs2_inode to get the struct inode for - * - * Returns: A VFS inode, or NULL if no mem - */ - -struct inode *gfs2_ip2v(struct gfs2_inode *ip) -{ - struct inode *inode, *tmp; - - inode = gfs2_ip2v_lookup(ip); - if (inode) - return inode; - - tmp = new_inode(ip->i_sbd->sd_vfs); - if (!tmp) - return NULL; - - inode_attr_in(ip, tmp); - - if (S_ISREG(ip->i_di.di_mode)) { - tmp->i_op = &gfs2_file_iops; - tmp->i_fop = &gfs2_file_fops; - tmp->i_mapping->a_ops = &gfs2_file_aops; - } else if (S_ISDIR(ip->i_di.di_mode)) { - tmp->i_op = &gfs2_dir_iops; - tmp->i_fop = &gfs2_dir_fops; - } else if (S_ISLNK(ip->i_di.di_mode)) { - tmp->i_op = &gfs2_symlink_iops; - } else { - tmp->i_op = &gfs2_dev_iops; - init_special_inode(tmp, tmp->i_mode, tmp->i_rdev); - } - - tmp->u.generic_ip = NULL; - - for (;;) { - spin_lock(&ip->i_spin); - if (!ip->i_vnode) - break; - inode = igrab(ip->i_vnode); - spin_unlock(&ip->i_spin); - - if (inode) { - iput(tmp); - return inode; - } - yield(); - } - - inode = tmp; - - gfs2_inode_hold(ip); - ip->i_vnode = inode; - inode->u.generic_ip = ip; - - spin_unlock(&ip->i_spin); - - insert_inode_hash(inode); - - return inode; -} - static int iget_test(struct inode *inode, void *opaque) { - struct gfs2_inode *ip = inode->u.generic_ip; - struct gfs2_inum *inum = (struct gfs2_inum *)opaque; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_inum *inum = opaque; if (ip && ip->i_num.no_addr == inum->no_addr) return 1; @@ -220,18 +129,89 @@ static int iget_test(struct inode *inode, void *opaque) return 0; } -struct inode *gfs2_iget(struct super_block *sb, struct gfs2_inum *inum) +static int iget_set(struct inode *inode, void *opaque) +{ + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_inum *inum = opaque; + + ip->i_num = *inum; + return 0; +} + +struct inode *gfs2_ilookup(struct super_block *sb, struct gfs2_inum *inum) { return ilookup5(sb, (unsigned long)inum->no_formal_ino, iget_test, inum); } -void gfs2_inode_min_init(struct gfs2_inode *ip, unsigned int type) +static struct inode *gfs2_iget(struct super_block *sb, struct gfs2_inum *inum) { - if (!test_and_set_bit(GIF_MIN_INIT, &ip->i_flags)) { - ip->i_di.di_nlink = 1; - ip->i_di.di_mode = DT2IF(type); + return iget5_locked(sb, (unsigned long)inum->no_formal_ino, + iget_test, iget_set, inum); +} + +/** + * gfs2_inode_lookup - Lookup an inode + * @sb: The super block + * @inum: The inode number + * @type: The type of the inode + * + * Returns: A VFS inode, or an error + */ + +struct inode *gfs2_inode_lookup(struct super_block *sb, struct gfs2_inum *inum, unsigned int type) +{ + struct inode *inode = gfs2_iget(sb, inum); + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_glock *io_gl; + int error; + + if (inode->i_state & I_NEW) { + struct gfs2_sbd *sdp = GFS2_SB(inode); + umode_t mode = DT2IF(type); + inode->u.generic_ip = ip; + inode->i_mode = mode; + + if (S_ISREG(mode)) { + inode->i_op = &gfs2_file_iops; + inode->i_fop = &gfs2_file_fops; + inode->i_mapping->a_ops = &gfs2_file_aops; + } else if (S_ISDIR(mode)) { + inode->i_op = &gfs2_dir_iops; + inode->i_fop = &gfs2_dir_fops; + } else if (S_ISLNK(mode)) { + inode->i_op = &gfs2_symlink_iops; + } else { + inode->i_op = &gfs2_dev_iops; + } + + error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); + if (unlikely(error)) + goto fail; + ip->i_gl->gl_object = ip; + + error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_iopen_glops, CREATE, &io_gl); + if (unlikely(error)) + goto fail_put; + + ip->i_vn = ip->i_gl->gl_vn - 1; + error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh); + if (unlikely(error)) + goto fail_iopen; + + gfs2_glock_put(io_gl); + unlock_new_inode(inode); } + + return inode; +fail_iopen: + gfs2_glock_put(io_gl); +fail_put: + ip->i_gl->gl_object = NULL; + gfs2_glock_put(ip->i_gl); +fail: + iput(inode); + return ERR_PTR(error); } /** @@ -250,7 +230,7 @@ int gfs2_inode_refresh(struct gfs2_inode *ip) if (error) return error; - if (gfs2_metatype_check(ip->i_sbd, dibh, GFS2_METATYPE_DI)) { + if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), dibh, GFS2_METATYPE_DI)) { brelse(dibh); return -EIO; } @@ -273,151 +253,9 @@ int gfs2_inode_refresh(struct gfs2_inode *ip) return 0; } -/** - * inode_create - create a struct gfs2_inode - * @i_gl: The glock covering the inode - * @inum: The inode number - * @io_gl: the iopen glock to acquire/hold (using holder in new gfs2_inode) - * @io_state: the state the iopen glock should be acquired in - * @ipp: pointer to put the returned inode in - * - * Returns: errno - */ - -static int inode_create(struct gfs2_glock *i_gl, const struct gfs2_inum *inum, - struct gfs2_glock *io_gl, unsigned int io_state, - struct gfs2_inode **ipp, int need_lock) +int gfs2_dinode_dealloc(struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = i_gl->gl_sbd; - struct gfs2_inode *ip; - int error = 0; - - ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL); - if (!ip) - return -ENOMEM; - memset(ip, 0, sizeof(struct gfs2_inode)); - ip->i_num = *inum; - atomic_set(&ip->i_count, 1); - ip->i_vn = i_gl->gl_vn - 1; - ip->i_gl = i_gl; - ip->i_sbd = sdp; - spin_lock_init(&ip->i_spin); - init_rwsem(&ip->i_rw_mutex); - ip->i_greedy = gfs2_tune_get(sdp, gt_greedy_default); - - if (need_lock) { - error = gfs2_glock_nq_init(io_gl, - io_state, GL_LOCAL_EXCL | GL_EXACT, - &ip->i_iopen_gh); - if (error) - goto fail; - - spin_lock(&io_gl->gl_spin); - gfs2_glock_hold(i_gl); - io_gl->gl_object = i_gl; - spin_unlock(&io_gl->gl_spin); - } - - gfs2_glock_hold(i_gl); - i_gl->gl_object = ip; - atomic_inc(&sdp->sd_inode_count); - *ipp = ip; - return 0; - -fail: - gfs2_meta_cache_flush(ip); - kmem_cache_free(gfs2_inode_cachep, ip); - *ipp = NULL; - return error; -} - -/** - * gfs2_inode_get - Create or get a reference on an inode - * @i_gl: The glock covering the inode - * @inum: The inode number - * @create: - * @ipp: pointer to put the returned inode in - * - * Returns: errno - */ - -int gfs2_inode_get(struct gfs2_glock *i_gl, const struct gfs2_inum *inum, - int create, struct gfs2_inode **ipp) -{ - struct gfs2_sbd *sdp = i_gl->gl_sbd; - struct gfs2_glock *io_gl; - int error = 0; - - gfs2_glmutex_lock(i_gl); - - *ipp = i_gl->gl_object; - if (*ipp) { - error = -ESTALE; - if ((*ipp)->i_num.no_formal_ino != inum->no_formal_ino) - goto out; - atomic_inc(&(*ipp)->i_count); - error = 0; - goto out; - } - - if (!create) - goto out; - - error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_iopen_glops, - CREATE, &io_gl); - if (!error) { - error = inode_create(i_gl, inum, io_gl, LM_ST_SHARED, ipp, 1); - gfs2_glock_put(io_gl); - } - - out: - gfs2_glmutex_unlock(i_gl); - - return error; -} - -void gfs2_inode_hold(struct gfs2_inode *ip) -{ - gfs2_assert(ip->i_sbd, atomic_read(&ip->i_count) > 0); - atomic_inc(&ip->i_count); -} - -void gfs2_inode_put(struct gfs2_inode *ip) -{ - gfs2_assert(ip->i_sbd, atomic_read(&ip->i_count) > 0); - atomic_dec(&ip->i_count); -} - -void gfs2_inode_destroy(struct gfs2_inode *ip, int unlock) -{ - struct gfs2_sbd *sdp = ip->i_sbd; - struct gfs2_glock *i_gl = ip->i_gl; - - gfs2_assert_warn(sdp, !atomic_read(&ip->i_count)); - if (unlock) { - struct gfs2_glock *io_gl = ip->i_iopen_gh.gh_gl; - gfs2_assert(sdp, io_gl->gl_object == i_gl); - - spin_lock(&io_gl->gl_spin); - io_gl->gl_object = NULL; - spin_unlock(&io_gl->gl_spin); - gfs2_glock_put(i_gl); - - gfs2_glock_dq_uninit(&ip->i_iopen_gh); - } - - gfs2_meta_cache_flush(ip); - kmem_cache_free(gfs2_inode_cachep, ip); - - i_gl->gl_object = NULL; - gfs2_glock_put(i_gl); - - atomic_dec(&sdp->sd_inode_count); -} - -static int dinode_dealloc(struct gfs2_inode *ip, struct gfs2_unlinked *ul) -{ - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al; struct gfs2_rgrpd *rgd; int error; @@ -450,7 +288,7 @@ static int dinode_dealloc(struct gfs2_inode *ip, struct gfs2_unlinked *ul) if (error) goto out_rindex_relse; - error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_UNLINKED + + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 1); if (error) goto out_rg_gunlock; @@ -459,191 +297,20 @@ static int dinode_dealloc(struct gfs2_inode *ip, struct gfs2_unlinked *ul) gfs2_free_di(rgd, ip); - error = gfs2_unlinked_ondisk_rm(sdp, ul); - gfs2_trans_end(sdp); clear_bit(GLF_STICKY, &ip->i_gl->gl_flags); - out_rg_gunlock: +out_rg_gunlock: gfs2_glock_dq_uninit(&al->al_rgd_gh); - - out_rindex_relse: +out_rindex_relse: gfs2_glock_dq_uninit(&al->al_ri_gh); - - out_qs: +out_qs: gfs2_quota_unhold(ip); - - out: - gfs2_alloc_put(ip); - - return error; -} - -/** - * inode_dealloc - Deallocate all on-disk blocks for an inode (dinode) - * @sdp: the filesystem - * @inum: the inode number to deallocate - * @io_gh: a holder for the iopen glock for this inode - * - * N.B. When we enter this we already hold the iopen glock and getting - * the glock for the inode means that we are grabbing the locks in the - * "wrong" order so we must only so a try lock operation and fail if we - * don't get the lock. Thats ok, since if we fail it means someone else - * is using the inode still and thus we shouldn't be deallocating it - * anyway. - * - * Returns: errno - */ - -static int inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul, - struct gfs2_holder *io_gh) -{ - struct gfs2_inode *ip; - struct gfs2_holder i_gh; - int error; - - error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, - &gfs2_inode_glops, LM_ST_EXCLUSIVE, - LM_FLAG_TRY_1CB|GL_DUMP, &i_gh); - switch(error) { - case 0: - break; - case GLR_TRYFAILED: - return 1; /* or back off and relock in different order? */ - default: - return error; - } - - gfs2_assert_warn(sdp, !i_gh.gh_gl->gl_object); - error = inode_create(i_gh.gh_gl, &ul->ul_ut.ut_inum, io_gh->gh_gl, - LM_ST_EXCLUSIVE, &ip, 0); - - if (error) - goto out; - - error = gfs2_inode_refresh(ip); - if (error) - goto out_iput; - - if (ip->i_di.di_nlink) { - if (gfs2_consist_inode(ip)) - gfs2_dinode_print(&ip->i_di); - error = -EIO; - goto out_iput; - } - - if (S_ISDIR(ip->i_di.di_mode) && - (ip->i_di.di_flags & GFS2_DIF_EXHASH)) { - error = gfs2_dir_exhash_dealloc(ip); - if (error) - goto out_iput; - } - - if (ip->i_di.di_eattr) { - error = gfs2_ea_dealloc(ip); - if (error) - goto out_iput; - } - - if (!gfs2_is_stuffed(ip)) { - error = gfs2_file_dealloc(ip); - if (error) - goto out_iput; - } - - error = dinode_dealloc(ip, ul); - if (error) - goto out_iput; - -out_iput: - gfs2_glmutex_lock(i_gh.gh_gl); - gfs2_inode_put(ip); - gfs2_inode_destroy(ip, 0); - gfs2_glmutex_unlock(i_gh.gh_gl); - out: - gfs2_glock_dq_uninit(&i_gh); - + gfs2_alloc_put(ip); return error; } -/** - * try_inode_dealloc - Try to deallocate an inode and all its blocks - * @sdp: the filesystem - * - * Returns: 0 on success, -errno on error, 1 on busy (inode open) - */ - -static int try_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) -{ - int error = 0; - struct gfs2_holder iogh; - - gfs2_try_toss_inode(sdp, &ul->ul_ut.ut_inum); - error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, - &gfs2_iopen_glops, LM_ST_EXCLUSIVE, - LM_FLAG_TRY_1CB, &iogh); - switch (error) { - case 0: - break; - case GLR_TRYFAILED: - return 1; - default: - return error; - } - - error = inode_dealloc(sdp, ul, &iogh); - gfs2_glock_dq_uninit(&iogh); - - return error; -} - -static int inode_dealloc_uninit(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) -{ - struct gfs2_rgrpd *rgd; - struct gfs2_holder ri_gh, rgd_gh; - int error; - - error = gfs2_rindex_hold(sdp, &ri_gh); - if (error) - return error; - - rgd = gfs2_blk2rgrpd(sdp, ul->ul_ut.ut_inum.no_addr); - if (!rgd) { - gfs2_consist(sdp); - error = -EIO; - goto out; - } - - error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &rgd_gh); - if (error) - goto out; - - error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_UNLINKED + RES_STATFS, 0); - if (error) - goto out_gunlock; - - gfs2_free_uninit_di(rgd, ul->ul_ut.ut_inum.no_addr); - gfs2_unlinked_ondisk_rm(sdp, ul); - - gfs2_trans_end(sdp); - - out_gunlock: - gfs2_glock_dq_uninit(&rgd_gh); - out: - gfs2_glock_dq_uninit(&ri_gh); - - return error; -} - -int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) -{ - if (ul->ul_ut.ut_flags & GFS2_UTF_UNINIT) - return inode_dealloc_uninit(sdp, ul); - else - return try_inode_dealloc(sdp, ul); -} - /** * gfs2_change_nlink - Change nlink count on inode * @ip: The GFS2 inode @@ -654,6 +321,7 @@ int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) int gfs2_change_nlink(struct gfs2_inode *ip, int diff) { + struct gfs2_sbd *sdp = ip->i_inode.i_sb->s_fs_info; struct buffer_head *dibh; uint32_t nlink; int error; @@ -678,8 +346,30 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); + mark_inode_dirty(&ip->i_inode); - return 0; + if (ip->i_di.di_nlink == 0) { + struct gfs2_rgrpd *rgd; + struct gfs2_holder ri_gh, rg_gh; + + error = gfs2_rindex_hold(sdp, &ri_gh); + if (error) + goto out; + error = -EIO; + rgd = gfs2_blk2rgrpd(sdp, ip->i_num.no_addr); + if (!rgd) + goto out_norgrp; + error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &rg_gh); + if (error) + goto out_norgrp; + + gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */ + gfs2_glock_dq_uninit(&rg_gh); +out_norgrp: + gfs2_glock_dq_uninit(&ri_gh); + } +out: + return error; } struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) @@ -703,18 +393,15 @@ struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) * Returns: errno */ -struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, - struct nameidata *nd) +struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, + int is_root, struct nameidata *nd) { struct super_block *sb = dir->i_sb; - struct gfs2_inode *ipp; - struct gfs2_inode *dip = dir->u.generic_ip; - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *dip = GFS2_I(dir); struct gfs2_holder d_gh; struct gfs2_inum inum; unsigned int type; - struct gfs2_glock *gl; int error = 0; struct inode *inode = NULL; @@ -742,34 +429,18 @@ struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, if (error) goto out; - error = gfs2_glock_get(sdp, inum.no_addr, &gfs2_inode_glops, - CREATE, &gl); - if (error) - goto out; - - error = gfs2_inode_get(gl, &inum, CREATE, &ipp); - if (!error) - gfs2_inode_min_init(ipp, type); - - gfs2_glock_put(gl); + inode = gfs2_inode_lookup(sb, &inum, type); out: gfs2_glock_dq_uninit(&d_gh); if (error == -ENOENT) return NULL; - if (error == 0) { - inode = gfs2_ip2v(ipp); - gfs2_inode_put(ipp); - if (!inode) - return ERR_PTR(-ENOMEM); - return inode; - } - return ERR_PTR(error); + return inode; } static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) { - struct gfs2_inode *ip = sdp->sd_ir_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode); struct buffer_head *bh; struct gfs2_inum_range ir; int error; @@ -810,8 +481,8 @@ static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) { - struct gfs2_inode *ip = sdp->sd_ir_inode->u.generic_ip; - struct gfs2_inode *m_ip = sdp->sd_inum_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode); + struct gfs2_inode *m_ip = GFS2_I(sdp->sd_inum_inode); struct gfs2_holder gh; struct buffer_head *bh; struct gfs2_inum_range ir; @@ -895,12 +566,12 @@ static int pick_formal_ino(struct gfs2_sbd *sdp, uint64_t *inum) * Returns: errno */ -static int create_ok(struct gfs2_inode *dip, struct qstr *name, +static int create_ok(struct gfs2_inode *dip, const struct qstr *name, unsigned int mode) { int error; - error = gfs2_repermission(dip->i_vnode, MAY_WRITE | MAY_EXEC, NULL); + error = gfs2_repermission(&dip->i_inode, MAY_WRITE | MAY_EXEC, NULL); if (error) return error; @@ -908,7 +579,7 @@ static int create_ok(struct gfs2_inode *dip, struct qstr *name, if (!dip->i_di.di_nlink) return -EPERM; - error = gfs2_dir_search(dip->i_vnode, name, NULL, NULL); + error = gfs2_dir_search(&dip->i_inode, name, NULL, NULL); switch (error) { case -ENOENT: error = 0; @@ -930,7 +601,7 @@ static int create_ok(struct gfs2_inode *dip, struct qstr *name, static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, unsigned int *uid, unsigned int *gid) { - if (dip->i_sbd->sd_args.ar_suiddir && + if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir && (dip->i_di.di_mode & S_ISUID) && dip->i_di.di_uid) { if (S_ISDIR(*mode)) @@ -949,9 +620,9 @@ static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, *gid = current->fsgid; } -static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_unlinked *ul) +static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_inum *inum) { - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); int error; gfs2_alloc_get(dip); @@ -961,15 +632,11 @@ static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_unlinked *ul) if (error) goto out; - error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_UNLINKED + - RES_STATFS, 0); + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS, 0); if (error) goto out_ipreserv; - ul->ul_ut.ut_inum.no_addr = gfs2_alloc_di(dip); - - ul->ul_ut.ut_flags = GFS2_UTF_UNINIT; - error = gfs2_unlinked_ondisk_add(sdp, ul); + inum->no_addr = gfs2_alloc_di(dip); gfs2_trans_end(sdp); @@ -997,7 +664,7 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, struct gfs2_inum *inum, unsigned int mode, unsigned int uid, unsigned int gid) { - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct gfs2_dinode *di; struct buffer_head *dibh; @@ -1049,9 +716,9 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, } static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, - unsigned int mode, struct gfs2_unlinked *ul) + unsigned int mode, struct gfs2_inum *inum) { - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); unsigned int uid, gid; int error; @@ -1066,28 +733,25 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, if (error) goto out_quota; - error = gfs2_trans_begin(sdp, RES_DINODE + RES_UNLINKED + RES_QUOTA, 0); + error = gfs2_trans_begin(sdp, RES_DINODE + RES_QUOTA, 0); if (error) goto out_quota; - ul->ul_ut.ut_flags = 0; - error = gfs2_unlinked_ondisk_munge(sdp, ul); - init_dinode(dip, gl, &ul->ul_ut.ut_inum, mode, uid, gid); + init_dinode(dip, gl, inum, mode, uid, gid); gfs2_quota_change(dip, +1, uid, gid); gfs2_trans_end(sdp); - out_quota: +out_quota: gfs2_quota_unlock(dip); - - out: +out: gfs2_alloc_put(dip); return error; } -static int link_dinode(struct gfs2_inode *dip, struct qstr *name, - struct gfs2_inode *ip, struct gfs2_unlinked *ul) +static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, + struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct gfs2_alloc *al; int alloc_required; struct buffer_head *dibh; @@ -1099,7 +763,7 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name, if (error) goto fail; - error = alloc_required = gfs2_diradd_alloc_required(dip->i_vnode, name); + error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name); if (alloc_required < 0) goto fail; if (alloc_required) { @@ -1116,20 +780,17 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name, error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + al->al_rgd->rd_ri.ri_length + - 2 * RES_DINODE + RES_UNLINKED + + 2 * RES_DINODE + RES_STATFS + RES_QUOTA, 0); if (error) goto fail_ipreserv; } else { - error = gfs2_trans_begin(sdp, - RES_LEAF + - 2 * RES_DINODE + - RES_UNLINKED, 0); + error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0); if (error) goto fail_quota_locks; } - error = gfs2_dir_add(dip->i_vnode, name, &ip->i_num, IF2DT(ip->i_di.di_mode)); + error = gfs2_dir_add(&dip->i_inode, name, &ip->i_num, IF2DT(ip->i_di.di_mode)); if (error) goto fail_end_trans; @@ -1140,11 +801,6 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name, gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); - - error = gfs2_unlinked_ondisk_rm(sdp, ul); - if (error) - goto fail_end_trans; - return 0; fail_end_trans: @@ -1178,23 +834,19 @@ fail: * Returns: An inode */ -struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, +struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, unsigned int mode) { struct inode *inode; struct gfs2_inode *dip = ghs->gh_gl->gl_object; - struct gfs2_sbd *sdp = dip->i_sbd; - struct gfs2_unlinked *ul; - struct gfs2_inode *ip; + struct inode *dir = &dip->i_inode; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); + struct gfs2_inum inum; int error; if (!name->len || name->len > GFS2_FNAMESIZE) return ERR_PTR(-ENAMETOOLONG); - error = gfs2_unlinked_get(sdp, &ul); - if (error) - return ERR_PTR(error); - gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs); error = gfs2_glock_nq(ghs); if (error) @@ -1204,22 +856,21 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, if (error) goto fail_gunlock; - error = pick_formal_ino(sdp, &ul->ul_ut.ut_inum.no_formal_ino); + error = pick_formal_ino(sdp, &inum.no_formal_ino); if (error) goto fail_gunlock; - error = alloc_dinode(dip, ul); + error = alloc_dinode(dip, &inum); if (error) goto fail_gunlock; - if (ul->ul_ut.ut_inum.no_addr < dip->i_num.no_addr) { + if (inum.no_addr < dip->i_num.no_addr) { gfs2_glock_dq(ghs); - error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, + error = gfs2_glock_nq_num(sdp, inum.no_addr, &gfs2_inode_glops, LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1); if (error) { - gfs2_unlinked_put(sdp, ul); return ERR_PTR(error); } @@ -1227,7 +878,6 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, error = gfs2_glock_nq(ghs); if (error) { gfs2_glock_dq_uninit(ghs + 1); - gfs2_unlinked_put(sdp, ul); return ERR_PTR(error); } @@ -1235,94 +885,47 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, if (error) goto fail_gunlock2; } else { - error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, + error = gfs2_glock_nq_num(sdp, inum.no_addr, &gfs2_inode_glops, LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1); if (error) goto fail_gunlock; } - error = make_dinode(dip, ghs[1].gh_gl, mode, ul); + error = make_dinode(dip, ghs[1].gh_gl, mode, &inum); if (error) goto fail_gunlock2; - error = gfs2_inode_get(ghs[1].gh_gl, &ul->ul_ut.ut_inum, CREATE, &ip); - if (error) + inode = gfs2_inode_lookup(dir->i_sb, &inum, IF2DT(mode)); + if (IS_ERR(inode)) goto fail_gunlock2; - error = gfs2_inode_refresh(ip); + error = gfs2_inode_refresh(GFS2_I(inode)); if (error) goto fail_iput; - error = gfs2_acl_create(dip, ip); + error = gfs2_acl_create(dip, GFS2_I(inode)); if (error) goto fail_iput; - error = link_dinode(dip, name, ip, ul); + error = link_dinode(dip, name, GFS2_I(inode)); if (error) goto fail_iput; - gfs2_unlinked_put(sdp, ul); - - inode = gfs2_ip2v(ip); - gfs2_inode_put(ip); if (!inode) return ERR_PTR(-ENOMEM); return inode; fail_iput: - gfs2_inode_put(ip); - + iput(inode); fail_gunlock2: gfs2_glock_dq_uninit(ghs + 1); - fail_gunlock: gfs2_glock_dq(ghs); - fail: - gfs2_unlinked_put(sdp, ul); return ERR_PTR(error); } -/** - * gfs2_unlinki - Unlink a file - * @dip: The inode of the directory - * @name: The name of the file to be unlinked - * @ip: The inode of the file to be removed - * - * Assumes Glocks on both dip and ip are held. - * - * Returns: errno - */ - -int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name, - struct gfs2_inode *ip, struct gfs2_unlinked *ul) -{ - struct gfs2_sbd *sdp = dip->i_sbd; - int error; - - error = gfs2_dir_del(dip, name); - if (error) - return error; - - error = gfs2_change_nlink(ip, -1); - if (error) - return error; - - /* If this inode is being unlinked from the directory structure, - we need to mark that in the log so that it isn't lost during - a crash. */ - - if (!ip->i_di.di_nlink) { - ul->ul_ut.ut_inum = ip->i_num; - error = gfs2_unlinked_ondisk_add(sdp, ul); - if (!error) - set_bit(GLF_STICKY, &ip->i_gl->gl_flags); - } - - return error; -} - /** * gfs2_rmdiri - Remove a directory * @dip: The parent directory of the directory to be removed @@ -1334,10 +937,9 @@ int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name, * Returns: errno */ -int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, - struct gfs2_inode *ip, struct gfs2_unlinked *ul) +int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name, + struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = dip->i_sbd; struct qstr dotname; int error; @@ -1360,9 +962,7 @@ int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, if (error) return error; - dotname.len = 2; - dotname.name = ".."; - dotname.hash = gfs2_disk_hash(dotname.name, dotname.len); + gfs2_str2qstr(&dotname, ".."); error = gfs2_dir_del(ip, &dotname); if (error) return error; @@ -1371,15 +971,6 @@ int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, if (error) return error; - /* This inode is being unlinked from the directory structure and - we need to mark that in the log so that it isn't lost during - a crash. */ - - ul->ul_ut.ut_inum = ip->i_num; - error = gfs2_unlinked_ondisk_add(sdp, ul); - if (!error) - set_bit(GLF_STICKY, &ip->i_gl->gl_flags); - return error; } @@ -1394,30 +985,29 @@ int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, * Returns: 0 if the parent/child relationship is correct, errno if it isn't */ -int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name, +int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name, struct gfs2_inode *ip) { struct gfs2_inum inum; unsigned int type; int error; - if (IS_IMMUTABLE(ip->i_vnode) || IS_APPEND(ip->i_vnode)) + if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode)) return -EPERM; if ((dip->i_di.di_mode & S_ISVTX) && dip->i_di.di_uid != current->fsuid && - ip->i_di.di_uid != current->fsuid && - !capable(CAP_FOWNER)) + ip->i_di.di_uid != current->fsuid && !capable(CAP_FOWNER)) return -EPERM; - if (IS_APPEND(dip->i_vnode)) + if (IS_APPEND(&dip->i_inode)) return -EPERM; - error = gfs2_repermission(dip->i_vnode, MAY_WRITE | MAY_EXEC, NULL); + error = gfs2_repermission(&dip->i_inode, MAY_WRITE | MAY_EXEC, NULL); if (error) return error; - error = gfs2_dir_search(dip->i_vnode, name, &inum, &type); + error = gfs2_dir_search(&dip->i_inode, name, &inum, &type); if (error) return error; @@ -1445,7 +1035,7 @@ int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name, int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) { - struct inode *dir = to->i_vnode; + struct inode *dir = &to->i_inode; struct super_block *sb = dir->i_sb; struct inode *tmp; struct qstr dotdot; @@ -1456,7 +1046,7 @@ int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) igrab(dir); for (;;) { - if (dir == this->i_vnode) { + if (dir == &this->i_inode) { error = -EINVAL; break; } @@ -1528,12 +1118,10 @@ int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len) memcpy(*buf, dibh->b_data + sizeof(struct gfs2_dinode), x); *len = x; - out_brelse: +out_brelse: brelse(dibh); - - out: +out: gfs2_glock_dq_uninit(&i_gh); - return error; } @@ -1622,12 +1210,10 @@ int gfs2_glock_nq_atime(struct gfs2_holder *gh) return 0; - fail_end_trans: +fail_end_trans: gfs2_trans_end(sdp); - - fail: +fail: gfs2_glock_dq(gh); - return error; } @@ -1722,49 +1308,6 @@ int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs) return error; } -/** - * gfs2_try_toss_vnode - See if we can toss a vnode from memory - * @ip: the inode - * - * Returns: 1 if the vnode was tossed - */ - -void gfs2_try_toss_vnode(struct gfs2_inode *ip) -{ - struct inode *inode; - - inode = gfs2_ip2v_lookup(ip); - if (!inode) - return; - - d_prune_aliases(inode); - - if (S_ISDIR(ip->i_di.di_mode)) { - struct list_head *head = &inode->i_dentry; - struct dentry *d = NULL; - - spin_lock(&dcache_lock); - if (list_empty(head)) - spin_unlock(&dcache_lock); - else { - d = list_entry(head->next, struct dentry, d_alias); - dget_locked(d); - spin_unlock(&dcache_lock); - - if (have_submounts(d)) - dput(d); - else { - shrink_dcache_parent(d); - dput(d); - d_prune_aliases(inode); - } - } - } - - inode->i_nlink = 0; - iput(inode); -} - static int __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) @@ -1774,8 +1317,8 @@ __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) error = gfs2_meta_inode_buffer(ip, &dibh); if (!error) { - error = inode_setattr(ip->i_vnode, attr); - gfs2_assert_warn(ip->i_sbd, !error); + error = inode_setattr(&ip->i_inode, attr); + gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); gfs2_inode_attr_out(ip); gfs2_trans_add_bh(ip->i_gl, dibh, 1); @@ -1802,13 +1345,13 @@ int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) if (current->journal_info) return __gfs2_setattr_simple(ip, attr); - error = gfs2_trans_begin(ip->i_sbd, RES_DINODE, 0); + error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE, 0); if (error) return error; error = __gfs2_setattr_simple(ip, attr); - gfs2_trans_end(ip->i_sbd); + gfs2_trans_end(GFS2_SB(&ip->i_inode)); return error; } diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index 5ef21317b2f6..30cfcc10beb2 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -27,32 +27,20 @@ static inline int gfs2_is_dir(struct gfs2_inode *ip) void gfs2_inode_attr_in(struct gfs2_inode *ip); void gfs2_inode_attr_out(struct gfs2_inode *ip); -struct inode *gfs2_ip2v_lookup(struct gfs2_inode *ip); -struct inode *gfs2_ip2v(struct gfs2_inode *ip); -struct inode *gfs2_iget(struct super_block *sb, struct gfs2_inum *inum); +struct inode *gfs2_inode_lookup(struct super_block *sb, struct gfs2_inum *inum, unsigned type); +struct inode *gfs2_ilookup(struct super_block *sb, struct gfs2_inum *inum); -void gfs2_inode_min_init(struct gfs2_inode *ip, unsigned int type); int gfs2_inode_refresh(struct gfs2_inode *ip); -int gfs2_inode_get(struct gfs2_glock *i_gl, - const struct gfs2_inum *inum, int create, - struct gfs2_inode **ipp); -void gfs2_inode_hold(struct gfs2_inode *ip); -void gfs2_inode_put(struct gfs2_inode *ip); -void gfs2_inode_destroy(struct gfs2_inode *ip, int unlock); - -int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); - +int gfs2_dinode_dealloc(struct gfs2_inode *inode); int gfs2_change_nlink(struct gfs2_inode *ip, int diff); -struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, - struct nameidata *nd); -struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, +struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, + int is_root, struct nameidata *nd); +struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, unsigned int mode); -int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name, - struct gfs2_inode *ip, struct gfs2_unlinked *ul); -int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, - struct gfs2_inode *ip, struct gfs2_unlinked *ul); -int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name, +int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name, + struct gfs2_inode *ip); +int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name, struct gfs2_inode *ip); int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to); int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len); @@ -60,8 +48,6 @@ int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len); int gfs2_glock_nq_atime(struct gfs2_holder *gh); int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs); -void gfs2_try_toss_vnode(struct gfs2_inode *ip); - int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr); int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd); diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 2a8b4b71dd1f..483d4fa987f6 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -213,6 +213,9 @@ static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) int bdy; error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, &new, &dbn, &bdy); + if (!(!error && dbn)) { + printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, dbn, lbn); + } gfs2_assert_withdraw(sdp, !error && dbn); return dbn; diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index e4c75a74df5b..a76f1a778920 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -184,8 +184,7 @@ static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) static void buf_lo_before_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head, int pass) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); if (pass != 0) return; @@ -198,8 +197,8 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_log_descriptor *ld, __be64 *ptr, int pass) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(jd->jd_inode); + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); struct gfs2_glock *gl = ip->i_gl; unsigned int blks = be32_to_cpu(ld->ld_data1); struct buffer_head *bh_log, *bh_ip; @@ -245,8 +244,8 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(jd->jd_inode); + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); if (error) { gfs2_meta_sync(ip->i_gl, @@ -332,8 +331,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp) static void revoke_lo_before_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head, int pass) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); if (pass != 0) return; @@ -346,8 +344,7 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_log_descriptor *ld, __be64 *ptr, int pass) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); unsigned int blks = be32_to_cpu(ld->ld_length); unsigned int revokes = be32_to_cpu(ld->ld_data1); struct buffer_head *bh; @@ -393,8 +390,7 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, static void revoke_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); if (error) { gfs2_revoke_clean(sdp); @@ -465,7 +461,7 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le); struct gfs2_trans *tr = current->journal_info; struct address_space *mapping = bd->bd_bh->b_page->mapping; - struct gfs2_inode *ip = mapping->host->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(mapping->host); tr->tr_touched = 1; if (!list_empty(&bd->bd_list_tr) && @@ -665,8 +661,8 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_log_descriptor *ld, __be64 *ptr, int pass) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(jd->jd_inode); + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); struct gfs2_glock *gl = ip->i_gl; unsigned int blks = be32_to_cpu(ld->ld_data1); struct buffer_head *bh_log, *bh_ip; @@ -716,8 +712,8 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(jd->jd_inode); + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); if (error) { gfs2_meta_sync(ip->i_gl, diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index b24d0b40d965..c112943ee8c1 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -29,8 +29,6 @@ static void gfs2_init_inode_once(void *foo, kmem_cache_t *cachep, unsigned long if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) { inode_init_once(&ip->i_inode); - atomic_set(&ip->i_count, 0); - ip->i_vnode = &ip->i_inode; spin_lock_init(&ip->i_spin); init_rwsem(&ip->i_rw_mutex); memset(ip->i_cache, 0, sizeof(ip->i_cache)); diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index c78517225f61..2523d42a02de 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -91,9 +91,6 @@ static void stuck_releasepage(struct buffer_head *bh) fs_warn(sdp, "ip = %llu %llu\n", (unsigned long long)ip->i_num.no_formal_ino, (unsigned long long)ip->i_num.no_addr); - fs_warn(sdp, "ip->i_count = %d, ip->i_vnode = %s\n", - atomic_read(&ip->i_count), - (ip->i_vnode) ? "!NULL" : "NULL"); for (x = 0; x < GFS2_MAX_META_HEIGHT; x++) fs_warn(sdp, "ip->i_cache[%u] = %s\n", @@ -567,7 +564,6 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, bd = kmem_cache_alloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL), memset(bd, 0, sizeof(struct gfs2_bufdata)); - bd->bd_bh = bh; bd->bd_gl = gl; @@ -664,7 +660,7 @@ void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, void gfs2_meta_wipe(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct inode *aspace = ip->i_gl->gl_aspace; struct buffer_head *bh; @@ -770,7 +766,7 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num, if (new) meta_prep_new(bh); else { - error = gfs2_meta_reread(ip->i_sbd, bh, + error = gfs2_meta_reread(GFS2_SB(&ip->i_inode), bh, DIO_START | DIO_WAIT); if (error) { brelse(bh); @@ -797,7 +793,7 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num, } if (new) { - if (gfs2_assert_warn(ip->i_sbd, height)) { + if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), height)) { brelse(bh); return -EIO; } @@ -805,7 +801,7 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num, gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); - } else if (gfs2_metatype_check(ip->i_sbd, bh, + } else if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, (height) ? GFS2_METATYPE_IN : GFS2_METATYPE_DI)) { brelse(bh); return -EIO; diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index be5c86e5787e..09154ad7b270 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -293,23 +293,6 @@ void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf) str->sc_dinodes = cpu_to_be64(sc->sc_dinodes); } -void gfs2_unlinked_tag_in(struct gfs2_unlinked_tag *ut, char *buf) -{ - struct gfs2_unlinked_tag *str = (struct gfs2_unlinked_tag *)buf; - - gfs2_inum_in(&ut->ut_inum, buf); - ut->ut_flags = be32_to_cpu(str->ut_flags); -} - -void gfs2_unlinked_tag_out(struct gfs2_unlinked_tag *ut, char *buf) -{ - struct gfs2_unlinked_tag *str = (struct gfs2_unlinked_tag *)buf; - - gfs2_inum_out(&ut->ut_inum, buf); - str->ut_flags = cpu_to_be32(ut->ut_flags); - str->__pad = 0; -} - void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf) { struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf; diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 16d3ebd32092..207363aed112 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -81,7 +81,6 @@ int gfs2_get_block(struct inode *inode, sector_t lblock, static int get_block_noalloc(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { - struct gfs2_inode *ip = inode->u.generic_ip; int new = 0; uint64_t dblock; int error; @@ -93,7 +92,7 @@ static int get_block_noalloc(struct inode *inode, sector_t lblock, if (dblock) map_bh(bh_result, inode->i_sb, dblock); - else if (gfs2_assert_withdraw(ip->i_sbd, !create)) + else if (gfs2_assert_withdraw(GFS2_SB(inode), !create)) error = -EIO; if (boundary) set_buffer_boundary(bh_result); @@ -114,8 +113,8 @@ static int get_block_noalloc(struct inode *inode, sector_t lblock, static int gfs2_writepage(struct page *page, struct writeback_control *wbc) { struct inode *inode = page->mapping->host; - struct gfs2_inode *ip = page->mapping->host->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(page->mapping->host); + struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host); loff_t i_size = i_size_read(inode); pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT; unsigned offset; @@ -216,8 +215,8 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page) static int gfs2_readpage(struct file *file, struct page *page) { - struct gfs2_inode *ip = page->mapping->host->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(page->mapping->host); + struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host); struct gfs2_holder gh; int error; @@ -271,8 +270,8 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping, struct list_head *pages, unsigned nr_pages) { struct inode *inode = mapping->host; - struct gfs2_inode *ip = inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); struct gfs2_holder gh; unsigned page_idx; int ret; @@ -345,8 +344,8 @@ out_unlock: static int gfs2_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to) { - struct gfs2_inode *ip = page->mapping->host->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(page->mapping->host); + struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host); unsigned int data_blocks, ind_blocks, rblocks; int alloc_required; int error = 0; @@ -440,8 +439,8 @@ static int gfs2_commit_write(struct file *file, struct page *page, unsigned from, unsigned to) { struct inode *inode = page->mapping->host; - struct gfs2_inode *ip = inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); int error = -EOPNOTSUPP; struct buffer_head *dibh; struct gfs2_alloc *al = &ip->i_alloc;; @@ -520,7 +519,7 @@ fail_nounlock: static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock) { - struct gfs2_inode *ip = mapping->host->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(mapping->host); struct gfs2_holder i_gh; sector_t dblock = 0; int error; @@ -594,7 +593,7 @@ static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov, { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder gh; int rv; @@ -641,8 +640,8 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; - struct gfs2_inode *ip = inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); if (rw == WRITE) return gfs2_direct_IO_write(iocb, iov, offset, nr_segs); diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index fef415e2068e..fd55979ec428 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -38,8 +38,8 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) { struct dentry *parent = dget_parent(dentry); - struct gfs2_sbd *sdp = parent->d_inode->i_sb->s_fs_info; - struct gfs2_inode *dip = parent->d_inode->u.generic_ip; + struct gfs2_sbd *sdp = GFS2_SB(parent->d_inode); + struct gfs2_inode *dip = GFS2_I(parent->d_inode); struct inode *inode = dentry->d_inode; struct gfs2_holder d_gh; struct gfs2_inode *ip; @@ -71,7 +71,7 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) goto fail_gunlock; } - ip = inode->u.generic_ip; + ip = GFS2_I(inode); if (!gfs2_inum_equal(&ip->i_num, &inum)) goto invalid_gunlock; diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index a376ead7d0cd..eacc1c092f91 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -66,7 +66,7 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, { struct inode *inode = dentry->d_inode; struct super_block *sb = inode->i_sb; - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); if (*len < 4 || (connectable && *len < 8)) return 255; @@ -86,8 +86,8 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, spin_lock(&dentry->d_lock); inode = dentry->d_parent->d_inode; - ip = inode->u.generic_ip; - gfs2_inode_hold(ip); + ip = GFS2_I(inode); + igrab(inode); spin_unlock(&dentry->d_lock); fh[4] = ip->i_num.no_formal_ino >> 32; @@ -100,7 +100,7 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, fh[7] = cpu_to_be32(fh[7]); *len = 8; - gfs2_inode_put(ip); + iput(inode); return *len; } @@ -142,8 +142,8 @@ static int gfs2_get_name(struct dentry *parent, char *name, if (!S_ISDIR(dir->i_mode) || !inode) return -EINVAL; - dip = dir->u.generic_ip; - ip = inode->u.generic_ip; + dip = GFS2_I(dir); + ip = GFS2_I(inode); *name = 0; gnfd.inum = ip->i_num; @@ -189,39 +189,30 @@ static struct dentry *gfs2_get_parent(struct dentry *child) static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) { struct gfs2_sbd *sdp = sb->s_fs_info; - struct gfs2_inum *inum = (struct gfs2_inum *)inum_p; + struct gfs2_inum *inum = inum_p; struct gfs2_holder i_gh, ri_gh, rgd_gh; struct gfs2_rgrpd *rgd; - struct gfs2_inode *ip; struct inode *inode; struct dentry *dentry; int error; /* System files? */ - inode = gfs2_iget(sb, inum); + inode = gfs2_ilookup(sb, inum); if (inode) { - ip = inode->u.generic_ip; - if (ip->i_num.no_formal_ino != inum->no_formal_ino) { + if (GFS2_I(inode)->i_num.no_formal_ino != inum->no_formal_ino) { iput(inode); return ERR_PTR(-ESTALE); } goto out_inode; } - error = gfs2_glock_nq_num(sdp, - inum->no_addr, &gfs2_inode_glops, + error = gfs2_glock_nq_num(sdp, inum->no_addr, &gfs2_inode_glops, LM_ST_SHARED, LM_FLAG_ANY | GL_LOCAL_EXCL, &i_gh); if (error) return ERR_PTR(error); - error = gfs2_inode_get(i_gh.gh_gl, inum, NO_CREATE, &ip); - if (error) - goto fail; - if (ip) - goto out_ip; - error = gfs2_rindex_hold(sdp, &ri_gh); if (error) goto fail; @@ -242,32 +233,29 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) gfs2_glock_dq_uninit(&rgd_gh); gfs2_glock_dq_uninit(&ri_gh); - error = gfs2_inode_get(i_gh.gh_gl, inum, CREATE, &ip); - if (error) + inode = gfs2_inode_lookup(sb, inum, DT_UNKNOWN); + if (!inode) goto fail; - - error = gfs2_inode_refresh(ip); - if (error) { - gfs2_inode_put(ip); + if (IS_ERR(inode)) { + error = PTR_ERR(inode); + goto fail; + } + + error = gfs2_inode_refresh(GFS2_I(inode)); + if (error) { + iput(inode); goto fail; } - out_ip: error = -EIO; - if (ip->i_di.di_flags & GFS2_DIF_SYSTEM) { - gfs2_inode_put(ip); + if (GFS2_I(inode)->i_di.di_flags & GFS2_DIF_SYSTEM) { + iput(inode); goto fail; } gfs2_glock_dq_uninit(&i_gh); - inode = gfs2_ip2v(ip); - gfs2_inode_put(ip); - - if (!inode) - return ERR_PTR(-ENOMEM); - - out_inode: +out_inode: dentry = d_alloc_anon(inode); if (!dentry) { iput(inode); @@ -276,13 +264,13 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) return dentry; - fail_rgd: +fail_rgd: gfs2_glock_dq_uninit(&rgd_gh); - fail_rindex: +fail_rindex: gfs2_glock_dq_uninit(&ri_gh); - fail: +fail: gfs2_glock_dq_uninit(&i_gh); return ERR_PTR(error); } diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 1e8f602c1e50..222f3be3e06e 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -105,7 +105,7 @@ static int gfs2_read_actor(read_descriptor_t *desc, struct page *page, int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, char *buf, loff_t *pos, unsigned size) { - struct inode *inode = ip->i_vnode; + struct inode *inode = &ip->i_inode; read_descriptor_t desc; desc.written = 0; desc.arg.buf = buf; @@ -131,7 +131,7 @@ int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) { - struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); struct gfs2_holder i_gh; loff_t error; @@ -178,7 +178,7 @@ static ssize_t __gfs2_file_aio_read(struct kiocb *iocb, unsigned long nr_segs, loff_t *ppos) { struct file *filp = iocb->ki_filp; - struct gfs2_inode *ip = filp->f_mapping->host->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(filp->f_mapping->host); struct gfs2_holder gh; ssize_t retval; unsigned long seg; @@ -361,13 +361,13 @@ static int filldir_reg_func(void *opaque, const char *name, unsigned int length, static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) { struct inode *dir = file->f_mapping->host; - struct gfs2_inode *dip = dir->u.generic_ip; + struct gfs2_inode *dip = GFS2_I(dir); struct filldir_reg fdr; struct gfs2_holder d_gh; uint64_t offset = file->f_pos; int error; - fdr.fdr_sbd = dip->i_sbd; + fdr.fdr_sbd = GFS2_SB(dir); fdr.fdr_prefetch = 1; fdr.fdr_filldir = filldir; fdr.fdr_opaque = dirent; @@ -451,8 +451,8 @@ static int filldir_bad_func(void *opaque, const char *name, unsigned int length, static int readdir_bad(struct file *file, void *dirent, filldir_t filldir) { struct inode *dir = file->f_mapping->host; - struct gfs2_inode *dip = dir->u.generic_ip; - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *dip = GFS2_I(dir); + struct gfs2_sbd *sdp = GFS2_SB(dir); struct filldir_reg fdr; unsigned int entries, size; struct filldir_bad *fdb; @@ -561,7 +561,7 @@ static const u32 gfs2_to_iflags[32] = { static int gfs2_get_flags(struct file *filp, u32 __user *ptr) { struct inode *inode = filp->f_dentry->d_inode; - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder gh; int error; u32 iflags; @@ -601,8 +601,8 @@ static int gfs2_get_flags(struct file *filp, u32 __user *ptr) static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) { struct inode *inode = filp->f_dentry->d_inode; - struct gfs2_inode *ip = inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); struct buffer_head *bh; struct gfs2_holder gh; int error; @@ -693,7 +693,7 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) { - struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); struct gfs2_holder i_gh; int error; @@ -728,7 +728,7 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) static int gfs2_open(struct inode *inode, struct file *file) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder i_gh; struct gfs2_file *fp; int error; @@ -739,7 +739,7 @@ static int gfs2_open(struct inode *inode, struct file *file) mutex_init(&fp->f_fl_mutex); - gfs2_assert_warn(ip->i_sbd, !file->private_data); + gfs2_assert_warn(GFS2_SB(inode), !file->private_data); file->private_data = fp; if (S_ISREG(ip->i_di.di_mode)) { @@ -808,7 +808,7 @@ static int gfs2_close(struct inode *inode, struct file *file) static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) { - struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(dentry->d_inode); gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); @@ -826,8 +826,8 @@ static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) { - struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); + struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); struct lm_lockname name = { .ln_number = ip->i_num.no_addr, .ln_type = LM_TYPE_PLOCK }; @@ -881,7 +881,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) { struct gfs2_file *fp = file->private_data; struct gfs2_holder *fl_gh = &fp->f_fl_gh; - struct gfs2_inode *ip = file->f_dentry->d_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(file->f_dentry->d_inode); struct gfs2_glock *gl; unsigned int state; int flags; @@ -901,7 +901,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) &(struct file_lock){.fl_type = F_UNLCK}); gfs2_glock_dq_uninit(fl_gh); } else { - error = gfs2_glock_get(ip->i_sbd, + error = gfs2_glock_get(GFS2_SB(&ip->i_inode), ip->i_num.no_addr, &gfs2_flock_glops, CREATE, &gl); if (error) @@ -918,7 +918,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) error = -EAGAIN; } else { error = flock_lock_file_wait(file, fl); - gfs2_assert_warn(ip->i_sbd, !error); + gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); } out: @@ -950,8 +950,8 @@ static void do_unflock(struct file *file, struct file_lock *fl) static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) { - struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); + struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); if (!(fl->fl_flags & FL_FLOCK)) return -ENOLCK; diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index a45982045509..b68eb6b4a4c1 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -32,7 +32,6 @@ #include "recovery.h" #include "rgrp.h" #include "super.h" -#include "unlinked.h" #include "sys.h" #include "util.h" @@ -80,10 +79,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) spin_lock_init(&sdp->sd_jindex_spin); mutex_init(&sdp->sd_jindex_mutex); - INIT_LIST_HEAD(&sdp->sd_unlinked_list); - spin_lock_init(&sdp->sd_unlinked_spin); - mutex_init(&sdp->sd_unlinked_mutex); - INIT_LIST_HEAD(&sdp->sd_quota_list); spin_lock_init(&sdp->sd_quota_spin); mutex_init(&sdp->sd_quota_mutex); @@ -248,19 +243,19 @@ static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, return 0; - fail_trans: +fail_trans: gfs2_glock_put(sdp->sd_trans_gl); - fail_rename: +fail_rename: gfs2_glock_put(sdp->sd_rename_gl); - fail_live: +fail_live: gfs2_glock_dq_uninit(&sdp->sd_live_gh); - fail_mount: +fail_mount: gfs2_glock_dq_uninit(mount_gh); - fail: +fail: while (sdp->sd_glockd_num--) kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); @@ -269,28 +264,10 @@ static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, return error; } -static struct inode *gfs2_lookup_root(struct gfs2_sbd *sdp, - const struct gfs2_inum *inum) +static struct inode *gfs2_lookup_root(struct super_block *sb, + struct gfs2_inum *inum) { - int error; - struct gfs2_glock *gl; - struct gfs2_inode *ip; - struct inode *inode; - - error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops, - CREATE, &gl); - if (!error) { - error = gfs2_inode_get(gl, inum, CREATE, &ip); - if (!error) { - gfs2_inode_min_init(ip, DT_DIR); - inode = gfs2_ip2v(ip); - gfs2_inode_put(ip); - gfs2_glock_put(gl); - return inode; - } - gfs2_glock_put(gl); - } - return ERR_PTR(error); + return gfs2_inode_lookup(sb, inum, DT_DIR); } static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) @@ -305,8 +282,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) return 0; } - error = gfs2_glock_nq_num(sdp, - GFS2_SB_LOCK, &gfs2_meta_glops, + error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops, LM_ST_SHARED, 0, &sb_gh); if (error) { fs_err(sdp, "can't acquire superblock glock: %d\n", error); @@ -345,7 +321,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) inum = &sdp->sd_sb.sb_root_dir; if (sb->s_type == &gfs2meta_fs_type) inum = &sdp->sd_sb.sb_master_dir; - inode = gfs2_lookup_root(sdp, inum); + inode = gfs2_lookup_root(sb, inum); if (IS_ERR(inode)) { error = PTR_ERR(inode); fs_err(sdp, "can't read in root inode: %d\n", error); @@ -382,7 +358,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) fs_err(sdp, "can't lookup journal index: %d\n", error); return PTR_ERR(sdp->sd_jindex); } - ip = sdp->sd_jindex->u.generic_ip; + ip = GFS2_I(sdp->sd_jindex); set_bit(GLF_STICKY, &ip->i_gl->gl_flags); /* Load in the journal index special file */ @@ -413,8 +389,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) } sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid); - error = gfs2_glock_nq_num(sdp, - sdp->sd_lockstruct.ls_jid, + error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid, &gfs2_journal_glops, LM_ST_EXCLUSIVE, LM_FLAG_NOEXP, &sdp->sd_journal_gh); @@ -423,9 +398,8 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) goto fail_jindex; } - ip = sdp->sd_jdesc->jd_inode->u.generic_ip; - error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_SHARED, + ip = GFS2_I(sdp->sd_jdesc->jd_inode); + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_NOEXP | GL_EXACT, &sdp->sd_jinode_gh); if (error) { @@ -509,7 +483,7 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) if (undo) goto fail_qinode; - inode = gfs2_lookup_root(sdp, &sdp->sd_sb.sb_master_dir); + inode = gfs2_lookup_root(sdp->sd_vfs, &sdp->sd_sb.sb_master_dir); if (IS_ERR(inode)) { error = PTR_ERR(inode); fs_err(sdp, "can't read in master directory: %d\n", error); @@ -545,7 +519,7 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) fs_err(sdp, "can't get resource index inode: %d\n", error); goto fail_statfs; } - ip = sdp->sd_rindex->u.generic_ip; + ip = GFS2_I(sdp->sd_rindex); set_bit(GLF_STICKY, &ip->i_gl->gl_flags); sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1; @@ -614,14 +588,6 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) goto fail_ir_i; } - sprintf(buf, "unlinked_tag%u", sdp->sd_jdesc->jd_jid); - sdp->sd_ut_inode = gfs2_lookup_simple(pn, buf); - if (IS_ERR(sdp->sd_ut_inode)) { - error = PTR_ERR(sdp->sd_ut_inode); - fs_err(sdp, "can't find local \"ut\" file: %d\n", error); - goto fail_sc_i; - } - sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid); sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf); if (IS_ERR(sdp->sd_qc_inode)) { @@ -633,7 +599,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) iput(pn); pn = NULL; - ip = sdp->sd_ir_inode->u.generic_ip; + ip = GFS2_I(sdp->sd_ir_inode); error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &sdp->sd_ir_gh); @@ -642,7 +608,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) goto fail_qc_i; } - ip = sdp->sd_sc_inode->u.generic_ip; + ip = GFS2_I(sdp->sd_sc_inode); error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &sdp->sd_sc_gh); @@ -651,16 +617,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) goto fail_ir_gh; } - ip = sdp->sd_ut_inode->u.generic_ip; - error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_EXCLUSIVE, 0, - &sdp->sd_ut_gh); - if (error) { - fs_err(sdp, "can't lock local \"ut\" file: %d\n", error); - goto fail_sc_gh; - } - - ip = sdp->sd_qc_inode->u.generic_ip; + ip = GFS2_I(sdp->sd_qc_inode); error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &sdp->sd_qc_gh); @@ -675,9 +632,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) gfs2_glock_dq_uninit(&sdp->sd_qc_gh); fail_ut_gh: - gfs2_glock_dq_uninit(&sdp->sd_ut_gh); - fail_sc_gh: gfs2_glock_dq_uninit(&sdp->sd_sc_gh); fail_ir_gh: @@ -687,9 +642,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) iput(sdp->sd_qc_inode); fail_ut_i: - iput(sdp->sd_ut_inode); - fail_sc_i: iput(sdp->sd_sc_inode); fail_ir_i: @@ -707,7 +660,7 @@ static int init_threads(struct gfs2_sbd *sdp, int undo) int error = 0; if (undo) - goto fail_inoded; + goto fail_quotad; sdp->sd_log_flush_time = jiffies; sdp->sd_jindex_refresh_time = jiffies; @@ -731,25 +684,13 @@ static int init_threads(struct gfs2_sbd *sdp, int undo) } sdp->sd_quotad_process = p; - p = kthread_run(gfs2_inoded, sdp, "gfs2_inoded"); - error = IS_ERR(p); - if (error) { - fs_err(sdp, "can't start inoded thread: %d\n", error); - goto fail_quotad; - } - sdp->sd_inoded_process = p; - return 0; - fail_inoded: - kthread_stop(sdp->sd_inoded_process); - fail_quotad: +fail_quotad: kthread_stop(sdp->sd_quotad_process); - - fail: +fail: kthread_stop(sdp->sd_logd_process); - return error; } diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 0c06f92368f2..f678f6b62afd 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -38,7 +38,6 @@ #include "quota.h" #include "rgrp.h" #include "trans.h" -#include "unlinked.h" #include "util.h" /** @@ -53,8 +52,8 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd) { - struct gfs2_inode *dip = dir->u.generic_ip; - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *dip = GFS2_I(dir); + struct gfs2_sbd *sdp = GFS2_SB(dir); struct gfs2_holder ghs[2]; struct inode *inode; int new = 1; @@ -141,10 +140,10 @@ static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, static int gfs2_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) { - struct gfs2_inode *dip = dir->u.generic_ip; - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *dip = GFS2_I(dir); + struct gfs2_sbd *sdp = GFS2_SB(dir); struct inode *inode = old_dentry->d_inode; - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder ghs[2]; int alloc_required; int error; @@ -231,30 +230,29 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, error = gfs2_change_nlink(ip, +1); - out_end_trans: +out_end_trans: gfs2_trans_end(sdp); - out_ipres: +out_ipres: if (alloc_required) gfs2_inplace_release(dip); - out_gunlock_q: +out_gunlock_q: if (alloc_required) gfs2_quota_unlock(dip); - out_alloc: +out_alloc: if (alloc_required) gfs2_alloc_put(dip); - out_gunlock: +out_gunlock: gfs2_glock_dq_m(2, ghs); - out: +out: gfs2_holder_uninit(ghs); gfs2_holder_uninit(ghs + 1); if (!error) { - atomic_inc(&inode->i_count); d_instantiate(dentry, inode); mark_inode_dirty(inode); } @@ -274,17 +272,12 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, static int gfs2_unlink(struct inode *dir, struct dentry *dentry) { - struct gfs2_inode *dip = dir->u.generic_ip; - struct gfs2_sbd *sdp = dip->i_sbd; - struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; - struct gfs2_unlinked *ul; + struct gfs2_inode *dip = GFS2_I(dir); + struct gfs2_sbd *sdp = GFS2_SB(dir); + struct gfs2_inode *ip = GFS2_I(dentry->d_inode); struct gfs2_holder ghs[2]; int error; - error = gfs2_unlinked_get(sdp, &ul); - if (error) - return error; - gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); @@ -296,24 +289,23 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry) if (error) goto out_gunlock; - error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF + - RES_UNLINKED, 0); + error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0); if (error) goto out_gunlock; - error = gfs2_unlinki(dip, &dentry->d_name, ip, ul); + error = gfs2_dir_del(dip, &dentry->d_name); + if (error) + goto out_end_trans; + error = gfs2_change_nlink(ip, -1); + +out_end_trans: gfs2_trans_end(sdp); - - out_gunlock: +out_gunlock: gfs2_glock_dq_m(2, ghs); - - out: +out: gfs2_holder_uninit(ghs); gfs2_holder_uninit(ghs + 1); - - gfs2_unlinked_put(sdp, ul); - return error; } @@ -329,8 +321,8 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry) static int gfs2_symlink(struct inode *dir, struct dentry *dentry, const char *symname) { - struct gfs2_inode *dip = dir->u.generic_ip, *ip; - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *dip = GFS2_I(dir), *ip; + struct gfs2_sbd *sdp = GFS2_SB(dir); struct gfs2_holder ghs[2]; struct inode *inode; struct buffer_head *dibh; @@ -388,8 +380,8 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry, static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) { - struct gfs2_inode *dip = dir->u.generic_ip, *ip; - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *dip = GFS2_I(dir), *ip; + struct gfs2_sbd *sdp = GFS2_SB(dir); struct gfs2_holder ghs[2]; struct inode *inode; struct buffer_head *dibh; @@ -466,17 +458,12 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) { - struct gfs2_inode *dip = dir->u.generic_ip; - struct gfs2_sbd *sdp = dip->i_sbd; - struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; - struct gfs2_unlinked *ul; + struct gfs2_inode *dip = GFS2_I(dir); + struct gfs2_sbd *sdp = GFS2_SB(dir); + struct gfs2_inode *ip = GFS2_I(dentry->d_inode); struct gfs2_holder ghs[2]; int error; - error = gfs2_unlinked_get(sdp, &ul); - if (error) - return error; - gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); @@ -499,12 +486,11 @@ static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) goto out_gunlock; } - error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + - RES_UNLINKED, 0); + error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0); if (error) goto out_gunlock; - error = gfs2_rmdiri(dip, &dentry->d_name, ip, ul); + error = gfs2_rmdiri(dip, &dentry->d_name, ip); gfs2_trans_end(sdp); @@ -515,8 +501,6 @@ static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) gfs2_holder_uninit(ghs); gfs2_holder_uninit(ghs + 1); - gfs2_unlinked_put(sdp, ul); - return error; } @@ -532,8 +516,8 @@ static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) { - struct gfs2_inode *dip = dir->u.generic_ip, *ip; - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_inode *dip = GFS2_I(dir), *ip; + struct gfs2_sbd *sdp = GFS2_SB(dir); struct gfs2_holder ghs[2]; struct inode *inode; struct buffer_head *dibh; @@ -600,12 +584,11 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, static int gfs2_rename(struct inode *odir, struct dentry *odentry, struct inode *ndir, struct dentry *ndentry) { - struct gfs2_inode *odip = odir->u.generic_ip; - struct gfs2_inode *ndip = ndir->u.generic_ip; - struct gfs2_inode *ip = odentry->d_inode->u.generic_ip; + struct gfs2_inode *odip = GFS2_I(odir); + struct gfs2_inode *ndip = GFS2_I(ndir); + struct gfs2_inode *ip = GFS2_I(odentry->d_inode); struct gfs2_inode *nip = NULL; - struct gfs2_sbd *sdp = odip->i_sbd; - struct gfs2_unlinked *ul; + struct gfs2_sbd *sdp = GFS2_SB(odir); struct gfs2_holder ghs[4], r_gh; unsigned int num_gh; int dir_rename = 0; @@ -614,15 +597,11 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, int error; if (ndentry->d_inode) { - nip = ndentry->d_inode->u.generic_ip; + nip = GFS2_I(ndentry->d_inode); if (ip == nip) return 0; } - error = gfs2_unlinked_get(sdp, &ul); - if (error) - return error; - /* Make sure we aren't trying to move a dirctory into it's subdir */ if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) { @@ -743,14 +722,12 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + al->al_rgd->rd_ri.ri_length + 4 * RES_DINODE + 4 * RES_LEAF + - RES_UNLINKED + RES_STATFS + - RES_QUOTA, 0); + RES_STATFS + RES_QUOTA, 0); if (error) goto out_ipreserv; } else { error = gfs2_trans_begin(sdp, 4 * RES_DINODE + - 5 * RES_LEAF + - RES_UNLINKED, 0); + 5 * RES_LEAF, 0); if (error) goto out_gunlock; } @@ -759,9 +736,13 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, if (nip) { if (S_ISDIR(nip->i_di.di_mode)) - error = gfs2_rmdiri(ndip, &ndentry->d_name, nip, ul); - else - error = gfs2_unlinki(ndip, &ndentry->d_name, nip, ul); + error = gfs2_rmdiri(ndip, &ndentry->d_name, nip); + else { + error = gfs2_dir_del(ndip, &ndentry->d_name); + if (error) + goto out_end_trans; + error = gfs2_change_nlink(nip, -1); + } if (error) goto out_end_trans; } @@ -800,35 +781,26 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, if (error) goto out_end_trans; - out_end_trans: +out_end_trans: gfs2_trans_end(sdp); - - out_ipreserv: +out_ipreserv: if (alloc_required) gfs2_inplace_release(ndip); - - out_gunlock_q: +out_gunlock_q: if (alloc_required) gfs2_quota_unlock(ndip); - - out_alloc: +out_alloc: if (alloc_required) gfs2_alloc_put(ndip); - - out_gunlock: +out_gunlock: gfs2_glock_dq_m(num_gh, ghs); - - out_uninit: +out_uninit: for (x = 0; x < num_gh; x++) gfs2_holder_uninit(ghs + x); - - out_gunlock_r: +out_gunlock_r: if (dir_rename) gfs2_glock_dq_uninit(&r_gh); - - out: - gfs2_unlinked_put(sdp, ul); - +out: return error; } @@ -844,7 +816,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, static int gfs2_readlink(struct dentry *dentry, char __user *user_buf, int user_size) { - struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(dentry->d_inode); char array[GFS2_FAST_NAME_SIZE], *buf = array; unsigned int len = GFS2_FAST_NAME_SIZE; int error; @@ -880,7 +852,7 @@ static int gfs2_readlink(struct dentry *dentry, char __user *user_buf, static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) { - struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(dentry->d_inode); char array[GFS2_FAST_NAME_SIZE], *buf = array; unsigned int len = GFS2_FAST_NAME_SIZE; int error; @@ -906,7 +878,7 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder i_gh; int error; @@ -926,7 +898,7 @@ static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd) static int setattr_size(struct inode *inode, struct iattr *attr) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); int error; if (attr->ia_size != ip->i_di.di_size) { @@ -944,8 +916,8 @@ static int setattr_size(struct inode *inode, struct iattr *attr) static int setattr_chown(struct inode *inode, struct iattr *attr) { - struct gfs2_inode *ip = inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); struct buffer_head *dibh; uint32_t ouid, ogid, nuid, ngid; int error; @@ -1021,7 +993,7 @@ static int setattr_chown(struct inode *inode, struct iattr *attr) static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) { struct inode *inode = dentry->d_inode; - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder i_gh; int error; @@ -1068,7 +1040,7 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) { struct inode *inode = dentry->d_inode; - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder gh; int error; @@ -1084,7 +1056,7 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, static int gfs2_setxattr(struct dentry *dentry, const char *name, const void *data, size_t size, int flags) { - struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; + struct inode *inode = dentry->d_inode; struct gfs2_ea_request er; memset(&er, 0, sizeof(struct gfs2_ea_request)); @@ -1096,9 +1068,9 @@ static int gfs2_setxattr(struct dentry *dentry, const char *name, er.er_data_len = size; er.er_flags = flags; - gfs2_assert_warn(ip->i_sbd, !(er.er_flags & GFS2_ERF_MODE)); + gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE)); - return gfs2_ea_set(ip, &er); + return gfs2_ea_set(GFS2_I(inode), &er); } static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, @@ -1114,7 +1086,7 @@ static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, er.er_name_len = strlen(er.er_name); er.er_data_len = size; - return gfs2_ea_get(dentry->d_inode->u.generic_ip, &er); + return gfs2_ea_get(GFS2_I(dentry->d_inode), &er); } static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) @@ -1125,7 +1097,7 @@ static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) er.er_data = (size) ? buffer : NULL; er.er_data_len = size; - return gfs2_ea_list(dentry->d_inode->u.generic_ip, &er); + return gfs2_ea_list(GFS2_I(dentry->d_inode), &er); } static int gfs2_removexattr(struct dentry *dentry, const char *name) @@ -1138,7 +1110,7 @@ static int gfs2_removexattr(struct dentry *dentry, const char *name) return -EOPNOTSUPP; er.er_name_len = strlen(er.er_name); - return gfs2_ea_remove(dentry->d_inode->u.generic_ip, &er); + return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er); } struct inode_operations gfs2_file_iops = { diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 1c17acc946f9..317d497f8f88 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "gfs2.h" #include "lm_interface.h" @@ -36,6 +37,10 @@ #include "super.h" #include "sys.h" #include "util.h" +#include "trans.h" +#include "dir.h" +#include "eattr.h" +#include "bmap.h" /** * gfs2_write_inode - Make sure the inode is stable on the disk @@ -47,12 +52,15 @@ static int gfs2_write_inode(struct inode *inode, int sync) { - struct gfs2_inode *ip = inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(inode); - if (current->flags & PF_MEMALLOC) - return 0; - if (ip && sync) - gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); + /* Check this is a "normal" inode */ + if (inode->u.generic_ip) { + if (current->flags & PF_MEMALLOC) + return 0; + if (sync) + gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); + } return 0; } @@ -78,7 +86,6 @@ static void gfs2_put_super(struct super_block *sb) gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); mutex_unlock(&sdp->sd_freeze_lock); - kthread_stop(sdp->sd_inoded_process); kthread_stop(sdp->sd_quotad_process); kthread_stop(sdp->sd_logd_process); kthread_stop(sdp->sd_recoverd_process); @@ -110,11 +117,9 @@ static void gfs2_put_super(struct super_block *sb) gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); gfs2_glock_dq_uninit(&sdp->sd_ir_gh); gfs2_glock_dq_uninit(&sdp->sd_sc_gh); - gfs2_glock_dq_uninit(&sdp->sd_ut_gh); gfs2_glock_dq_uninit(&sdp->sd_qc_gh); iput(sdp->sd_ir_inode); iput(sdp->sd_sc_inode); - iput(sdp->sd_ut_inode); iput(sdp->sd_qc_inode); } @@ -274,16 +279,20 @@ static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) static void gfs2_clear_inode(struct inode *inode) { - struct gfs2_inode *ip = inode->u.generic_ip; - - if (ip) { - spin_lock(&ip->i_spin); - ip->i_vnode = NULL; - inode->u.generic_ip = NULL; - spin_unlock(&ip->i_spin); - + /* This tells us its a "real" inode and not one which only + * serves to contain an address space (see rgrp.c, meta_io.c) + * which therefore doesn't have its own glocks. + */ + if (inode->u.generic_ip) { + struct gfs2_inode *ip = GFS2_I(inode); + gfs2_glock_inode_squish(inode); + gfs2_assert(inode->i_sb->s_fs_info, ip->i_gl->gl_state == LM_ST_UNLOCKED); + ip->i_gl->gl_object = NULL; gfs2_glock_schedule_for_reclaim(ip->i_gl); - gfs2_inode_put(ip); + gfs2_glock_put(ip->i_gl); + ip->i_gl = NULL; + if (ip->i_iopen_gh.gh_gl) + gfs2_glock_dq_uninit(&ip->i_iopen_gh); } } @@ -361,6 +370,70 @@ static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) return 0; } +/* + * We have to (at the moment) hold the inodes main lock to cover + * the gap between unlocking the shared lock on the iopen lock and + * taking the exclusive lock. I'd rather do a shared -> exclusive + * conversion on the iopen lock, but we can change that later. This + * is safe, just less efficient. + */ +static void gfs2_delete_inode(struct inode *inode) +{ + struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_holder gh; + int error; + + if (!inode->u.generic_ip) + goto out; + + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &gh); + if (unlikely(error)) { + gfs2_glock_dq_uninit(&ip->i_iopen_gh); + goto out; + } + + gfs2_glock_dq(&ip->i_iopen_gh); + gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh); + error = gfs2_glock_nq(&ip->i_iopen_gh); + if (error) + goto out_uninit; + + if (S_ISDIR(ip->i_di.di_mode) && + (ip->i_di.di_flags & GFS2_DIF_EXHASH)) { + error = gfs2_dir_exhash_dealloc(ip); + if (error) + goto out_unlock; + } + + if (ip->i_di.di_eattr) { + error = gfs2_ea_dealloc(ip); + if (error) + goto out_unlock; + } + + if (!gfs2_is_stuffed(ip)) { + error = gfs2_file_dealloc(ip); + if (error) + goto out_unlock; + } + + error = gfs2_dinode_dealloc(ip); + +out_unlock: + gfs2_glock_dq(&ip->i_iopen_gh); +out_uninit: + gfs2_holder_uninit(&ip->i_iopen_gh); + gfs2_glock_dq_uninit(&gh); + if (error) + fs_warn(sdp, "gfs2_delete_inode: %d\n", error); +out: + truncate_inode_pages(&inode->i_data, 0); + clear_inode(inode); +} + + + static struct inode *gfs2_alloc_inode(struct super_block *sb) { struct gfs2_sbd *sdp = sb->s_fs_info; @@ -370,8 +443,6 @@ static struct inode *gfs2_alloc_inode(struct super_block *sb) if (ip) { ip->i_flags = 0; ip->i_gl = NULL; - ip->i_sbd = sdp; - ip->i_vnode = &ip->i_inode; ip->i_greedy = gfs2_tune_get(sdp, gt_greedy_default); ip->i_last_pfault = jiffies; } @@ -387,6 +458,7 @@ struct super_operations gfs2_super_ops = { .alloc_inode = gfs2_alloc_inode, .destroy_inode = gfs2_destroy_inode, .write_inode = gfs2_write_inode, + .delete_inode = gfs2_delete_inode, .put_super = gfs2_put_super, .write_super = gfs2_write_super, .write_super_lockfs = gfs2_write_super_lockfs, diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index 263c1fb7bbaf..08709f19ea98 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -38,15 +38,15 @@ static void pfault_be_greedy(struct gfs2_inode *ip) ip->i_last_pfault = jiffies; spin_unlock(&ip->i_spin); - gfs2_inode_hold(ip); + igrab(&ip->i_inode); if (gfs2_glock_be_greedy(ip->i_gl, time)) - gfs2_inode_put(ip); + iput(&ip->i_inode); } static struct page *gfs2_private_nopage(struct vm_area_struct *area, unsigned long address, int *type) { - struct gfs2_inode *ip = area->vm_file->f_mapping->host->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(area->vm_file->f_mapping->host); struct gfs2_holder i_gh; struct page *result; int error; @@ -69,7 +69,7 @@ static struct page *gfs2_private_nopage(struct vm_area_struct *area, static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); unsigned long index = page->index; uint64_t lblock = index << (PAGE_CACHE_SHIFT - sdp->sd_sb.sb_bsize_shift); @@ -114,7 +114,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) unsigned int extlen; int new = 1; - error = gfs2_extent_map(ip->i_vnode, lblock, &new, &dblock, &extlen); + error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen); if (error) goto out_trans; @@ -142,7 +142,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, unsigned long address, int *type) { - struct gfs2_inode *ip = area->vm_file->f_mapping->host->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(area->vm_file->f_mapping->host); struct gfs2_holder i_gh; struct page *result = NULL; unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) + diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c index cd93644c7d70..a8165a693b56 100644 --- a/fs/gfs2/page.c +++ b/fs/gfs2/page.c @@ -38,20 +38,17 @@ void gfs2_pte_inval(struct gfs2_glock *gl) struct inode *inode; ip = gl->gl_object; + inode = &ip->i_inode; if (!ip || !S_ISREG(ip->i_di.di_mode)) return; if (!test_bit(GIF_PAGED, &ip->i_flags)) return; - inode = gfs2_ip2v_lookup(ip); - if (inode) { - unmap_shared_mapping_range(inode->i_mapping, 0, 0); - iput(inode); + unmap_shared_mapping_range(inode->i_mapping, 0, 0); - if (test_bit(GIF_SW_PAGED, &ip->i_flags)) - set_bit(GLF_DIRTY, &gl->gl_flags); - } + if (test_bit(GIF_SW_PAGED, &ip->i_flags)) + set_bit(GLF_DIRTY, &gl->gl_flags); clear_bit(GIF_SW_PAGED, &ip->i_flags); } @@ -68,19 +65,12 @@ void gfs2_page_inval(struct gfs2_glock *gl) struct inode *inode; ip = gl->gl_object; + inode = &ip->i_inode; if (!ip || !S_ISREG(ip->i_di.di_mode)) return; - inode = gfs2_ip2v_lookup(ip); - if (inode) { - struct address_space *mapping = inode->i_mapping; - - truncate_inode_pages(mapping, 0); - gfs2_assert_withdraw(ip->i_sbd, !mapping->nrpages); - - iput(inode); - } - + truncate_inode_pages(inode->i_mapping, 0); + gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), !inode->i_mapping->nrpages); clear_bit(GIF_PAGED, &ip->i_flags); } @@ -97,32 +87,30 @@ void gfs2_page_sync(struct gfs2_glock *gl, int flags) { struct gfs2_inode *ip; struct inode *inode; + struct address_space *mapping; + int error = 0; ip = gl->gl_object; + inode = &ip->i_inode; if (!ip || !S_ISREG(ip->i_di.di_mode)) return; - inode = gfs2_ip2v_lookup(ip); - if (inode) { - struct address_space *mapping = inode->i_mapping; - int error = 0; + mapping = inode->i_mapping; - if (flags & DIO_START) - filemap_fdatawrite(mapping); - if (!error && (flags & DIO_WAIT)) - error = filemap_fdatawait(mapping); + if (flags & DIO_START) + filemap_fdatawrite(mapping); + if (!error && (flags & DIO_WAIT)) + error = filemap_fdatawait(mapping); - /* Put back any errors cleared by filemap_fdatawait() - so they can be caught by someone who can pass them - up to user space. */ + /* Put back any errors cleared by filemap_fdatawait() + so they can be caught by someone who can pass them + up to user space. */ - if (error == -ENOSPC) - set_bit(AS_ENOSPC, &mapping->flags); - else if (error) - set_bit(AS_EIO, &mapping->flags); + if (error == -ENOSPC) + set_bit(AS_ENOSPC, &mapping->flags); + else if (error) + set_bit(AS_EIO, &mapping->flags); - iput(inode); - } } /** @@ -138,8 +126,8 @@ void gfs2_page_sync(struct gfs2_glock *gl, int flags) int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, uint64_t block, void *private) { - struct gfs2_sbd *sdp = ip->i_sbd; - struct inode *inode = ip->i_vnode; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); + struct inode *inode = &ip->i_inode; struct page *page = (struct page *)private; struct buffer_head *bh; int release = 0; @@ -193,8 +181,8 @@ int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, int gfs2_block_truncate_page(struct address_space *mapping) { struct inode *inode = mapping->host; - struct gfs2_inode *ip = inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); loff_t from = inode->i_size; unsigned long index = from >> PAGE_CACHE_SHIFT; unsigned offset = from & (PAGE_CACHE_SIZE-1); diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index f752b0184690..d3cd5171d7c7 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -248,7 +248,7 @@ static void slot_put(struct gfs2_quota_data *qd) static int bh_get(struct gfs2_quota_data *qd) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; - struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); unsigned int block, offset; uint64_t dblock; int new = 0; @@ -266,7 +266,7 @@ static int bh_get(struct gfs2_quota_data *qd) block = qd->qd_slot / sdp->sd_qc_per_block; offset = qd->qd_slot % sdp->sd_qc_per_block;; - error = gfs2_block_map(ip->i_vnode, block, &new, &dblock, &boundary); + error = gfs2_block_map(&ip->i_inode, block, &new, &dblock, &boundary); if (error) goto fail; error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh); @@ -444,7 +444,7 @@ static void qdsb_put(struct gfs2_quota_data *qd) int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; struct gfs2_quota_data **qd = al->al_qd; int error; @@ -493,7 +493,7 @@ int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) void gfs2_quota_unhold(struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; unsigned int x; @@ -531,7 +531,7 @@ static int sort_qd(const void *a, const void *b) static void do_qc(struct gfs2_quota_data *qd, int64_t change) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; - struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); struct gfs2_quota_change *qc = qd->qd_bh_qc; int64_t x; @@ -578,7 +578,7 @@ static void do_qc(struct gfs2_quota_data *qd, int64_t change) static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, int64_t change, struct gfs2_quota_data *qd) { - struct inode *inode = ip->i_vnode; + struct inode *inode = &ip->i_inode; struct address_space *mapping = inode->i_mapping; unsigned long index = loc >> PAGE_CACHE_SHIFT; unsigned offset = loc & (PAGE_CACHE_SHIFT - 1); @@ -647,7 +647,7 @@ unlock: static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) { struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd; - struct gfs2_inode *ip = sdp->sd_quota_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); unsigned int data_blocks, ind_blocks; struct file_ra_state ra_state; struct gfs2_holder *ghs, i_gh; @@ -716,7 +716,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) goto out_gunlock; } - file_ra_state_init(&ra_state, ip->i_vnode->i_mapping); + file_ra_state_init(&ra_state, ip->i_inode.i_mapping); for (x = 0; x < num_qd; x++) { qd = qda[x]; offset = qd2offset(qd); @@ -758,7 +758,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, struct gfs2_holder *q_gh) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; - struct gfs2_inode *ip = sdp->sd_quota_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); struct gfs2_holder i_gh; struct gfs2_quota q; char buf[sizeof(struct gfs2_quota)]; @@ -829,7 +829,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, int gfs2_quota_lock(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; unsigned int x; int error = 0; @@ -958,7 +958,7 @@ static int print_message(struct gfs2_quota_data *qd, char *type) int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; struct gfs2_quota_data *qd; int64_t value; @@ -1008,7 +1008,7 @@ void gfs2_quota_change(struct gfs2_inode *ip, int64_t change, unsigned int x; unsigned int found = 0; - if (gfs2_assert_warn(ip->i_sbd, change)) + if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change)) return; if (ip->i_di.di_flags & GFS2_DIF_SYSTEM) return; @@ -1126,7 +1126,7 @@ int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, int gfs2_quota_init(struct gfs2_sbd *sdp) { - struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; unsigned int x, slot = 0; unsigned int found = 0; @@ -1162,7 +1162,7 @@ int gfs2_quota_init(struct gfs2_sbd *sdp) if (!extlen) { int new = 0; - error = gfs2_extent_map(ip->i_vnode, x, &new, &dblock, &extlen); + error = gfs2_extent_map(&ip->i_inode, x, &new, &dblock, &extlen); if (error) goto fail; } diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index c504ac1b831d..7aabc03e4abd 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -32,14 +32,14 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, struct buffer_head **bh) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(jd->jd_inode); struct gfs2_glock *gl = ip->i_gl; int new = 0; uint64_t dblock; uint32_t extlen; int error; - error = gfs2_extent_map(ip->i_vnode, blk, &new, &dblock, &extlen); + error = gfs2_extent_map(&ip->i_inode, blk, &new, &dblock, &extlen); if (error) return error; if (!dblock) { @@ -190,7 +190,7 @@ static int find_good_lh(struct gfs2_jdesc *jd, unsigned int *blk, *blk = 0; if (*blk == orig_blk) { - gfs2_consist_inode(jd->jd_inode->u.generic_ip); + gfs2_consist_inode(GFS2_I(jd->jd_inode)); return -EIO; } } @@ -224,7 +224,7 @@ static int jhead_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head) continue; if (lh.lh_sequence == head->lh_sequence) { - gfs2_consist_inode(jd->jd_inode->u.generic_ip); + gfs2_consist_inode(GFS2_I(jd->jd_inode)); return -EIO; } if (lh.lh_sequence < head->lh_sequence) @@ -300,8 +300,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header *head) static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, unsigned int end, int pass) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); struct buffer_head *bh; struct gfs2_log_descriptor *ld; int error = 0; @@ -330,7 +329,7 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, continue; } if (error == 1) { - gfs2_consist_inode(jd->jd_inode->u.generic_ip); + gfs2_consist_inode(GFS2_I(jd->jd_inode)); error = -EIO; } brelse(bh); @@ -367,8 +366,8 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(jd->jd_inode); + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); unsigned int lblock; int new = 0; uint64_t dblock; @@ -380,7 +379,7 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) lblock = head->lh_blkno; gfs2_replay_incr_blk(sdp, &lblock); - error = gfs2_block_map(ip->i_vnode, lblock, &new, &dblock, &boundary); + error = gfs2_block_map(&ip->i_inode, lblock, &new, &dblock, &boundary); if (error) return error; if (!dblock) { @@ -426,8 +425,8 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) int gfs2_recover_journal(struct gfs2_jdesc *jd) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(jd->jd_inode); + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); struct gfs2_log_header head; struct gfs2_holder j_gh, ji_gh, t_gh; unsigned long t; diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 691e6f3ce43b..75df79eb50ba 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -34,17 +34,19 @@ /* * These routines are used by the resource group routines (rgrp.c) * to keep track of block allocation. Each block is represented by two - * bits. One bit indicates whether or not the block is used. (1=used, - * 0=free) The other bit indicates whether or not the block contains a - * dinode or not. (1=dinode, 0=not-dinode) So, each byte represents - * GFS2_NBBY (i.e. 4) blocks. + * bits. So, each byte represents GFS2_NBBY (i.e. 4) blocks. + * + * 0 = Free + * 1 = Used (not metadata) + * 2 = Unlinked (still in use) inode + * 3 = Used (metadata) */ static const char valid_change[16] = { /* current */ - /* n */ 0, 1, 0, 1, + /* n */ 0, 1, 1, 1, /* e */ 1, 0, 0, 0, - /* w */ 0, 0, 0, 0, + /* w */ 0, 0, 0, 1, 1, 0, 0, 0 }; @@ -228,26 +230,27 @@ void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd) tmp = rgd->rd_ri.ri_data - rgd->rd_rg.rg_free - rgd->rd_rg.rg_dinodes; - if (count[1] != tmp) { + if (count[1] + count[2] != tmp) { if (gfs2_consist_rgrpd(rgd)) fs_err(sdp, "used data mismatch: %u != %u\n", count[1], tmp); return; } - if (count[2]) { - if (gfs2_consist_rgrpd(rgd)) - fs_err(sdp, "free metadata mismatch: %u != 0\n", - count[2]); - return; - } - if (count[3] != rgd->rd_rg.rg_dinodes) { if (gfs2_consist_rgrpd(rgd)) fs_err(sdp, "used metadata mismatch: %u != %u\n", count[3], rgd->rd_rg.rg_dinodes); return; } + + if (count[2] > count[3]) { + if (gfs2_consist_rgrpd(rgd)) + fs_err(sdp, "unlinked inodes > inodes: %u\n", + count[2]); + return; + } + } static inline int rgrp_contains_block(struct gfs2_rindex *ri, uint64_t block) @@ -368,6 +371,9 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd) uint32_t bytes_left, bytes; int x; + if (!length) + return -EINVAL; + rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_KERNEL); if (!rgd->rd_bits) return -ENOMEM; @@ -433,14 +439,16 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd) static int gfs2_ri_update(struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = ip->i_sbd; - struct inode *inode = ip->i_vnode; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); + struct inode *inode = &ip->i_inode; struct gfs2_rgrpd *rgd; char buf[sizeof(struct gfs2_rindex)]; struct file_ra_state ra_state; uint64_t junk = ip->i_di.di_size; int error; + printk(KERN_INFO "gfs2_ri_update inode=%p\n", inode); + if (do_div(junk, sizeof(struct gfs2_rindex))) { gfs2_consist_inode(ip); return -EIO; @@ -448,9 +456,12 @@ static int gfs2_ri_update(struct gfs2_inode *ip) clear_rgrpdi(sdp); + printk(KERN_INFO "rgrps cleared\n"); + file_ra_state_init(&ra_state, inode->i_mapping); for (sdp->sd_rgrps = 0;; sdp->sd_rgrps++) { loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex); + printk(KERN_INFO "reading rgrp %d\n", sdp->sd_rgrps); error = gfs2_internal_read(ip, &ra_state, buf, &pos, sizeof(struct gfs2_rindex)); if (!error) @@ -474,13 +485,15 @@ static int gfs2_ri_update(struct gfs2_inode *ip) list_add_tail(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list); gfs2_rindex_in(&rgd->rd_ri, buf); - + printk(KERN_INFO "compute bitstructs\n"); error = compute_bitstructs(rgd); if (error) goto fail; + printk(KERN_INFO "gfs2_glock_get\n"); error = gfs2_glock_get(sdp, rgd->rd_ri.ri_addr, &gfs2_rgrp_glops, CREATE, &rgd->rd_gl); + printk(KERN_INFO "gfs2_glock_got one\n"); if (error) goto fail; @@ -488,13 +501,14 @@ static int gfs2_ri_update(struct gfs2_inode *ip) rgd->rd_rg_vn = rgd->rd_gl->gl_vn - 1; } + printk(KERN_INFO "ok, finished\n"); sdp->sd_rindex_vn = ip->i_gl->gl_vn; - return 0; - fail: +fail: + printk(KERN_INFO "fail\n"); clear_rgrpdi(sdp); - + printk(KERN_INFO "cleared rgrps\n"); return error; } @@ -518,7 +532,7 @@ static int gfs2_ri_update(struct gfs2_inode *ip) int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh) { - struct gfs2_inode *ip = sdp->sd_rindex->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(sdp->sd_rindex); struct gfs2_glock *gl = ip->i_gl; int error; @@ -583,8 +597,7 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd) error = gfs2_meta_reread(sdp, bi->bi_bh, DIO_WAIT); if (error) goto fail; - if (gfs2_metatype_check(sdp, bi->bi_bh, - (y) ? GFS2_METATYPE_RB : + if (gfs2_metatype_check(sdp, bi->bi_bh, y ? GFS2_METATYPE_RB : GFS2_METATYPE_RG)) { error = -EIO; goto fail; @@ -605,7 +618,7 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd) return 0; - fail: +fail: while (x--) { bi = rgd->rd_bits + x; brelse(bi->bi_bh); @@ -667,8 +680,7 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd) if (!bi->bi_clone) continue; memcpy(bi->bi_clone + bi->bi_offset, - bi->bi_bh->b_data + bi->bi_offset, - bi->bi_len); + bi->bi_bh->b_data + bi->bi_offset, bi->bi_len); } spin_lock(&sdp->sd_rindex_spin); @@ -757,13 +769,11 @@ static struct gfs2_rgrpd *recent_rgrp_first(struct gfs2_sbd *sdp, goto out; } - first: +first: rgd = list_entry(sdp->sd_rindex_recent_list.next, struct gfs2_rgrpd, rd_recent); - - out: +out: spin_unlock(&sdp->sd_rindex_spin); - return rgd; } @@ -805,9 +815,8 @@ static struct gfs2_rgrpd *recent_rgrp_next(struct gfs2_rgrpd *cur_rgd, if (!list_empty(head)) rgd = list_entry(head->next, struct gfs2_rgrpd, rd_recent); - out: +out: spin_unlock(&sdp->sd_rindex_spin); - return rgd; } @@ -835,7 +844,7 @@ static void recent_rgrp_add(struct gfs2_rgrpd *new_rgd) } list_add_tail(&new_rgd->rd_recent, &sdp->sd_rindex_recent_list); - out: +out: spin_unlock(&sdp->sd_rindex_spin); } @@ -898,7 +907,7 @@ static void forward_rgrp_set(struct gfs2_sbd *sdp, struct gfs2_rgrpd *rgd) static int get_local_rgrp(struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_rgrpd *rgd, *begin = NULL; struct gfs2_alloc *al = &ip->i_alloc; int flags = LM_FLAG_TRY; @@ -965,7 +974,7 @@ static int get_local_rgrp(struct gfs2_inode *ip) } } - out: +out: ip->i_last_rg_alloc = rgd->rd_ri.ri_addr; if (begin) { @@ -988,7 +997,7 @@ static int get_local_rgrp(struct gfs2_inode *ip) int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; int error; @@ -1020,7 +1029,7 @@ int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line) void gfs2_inplace_release(struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1) @@ -1061,8 +1070,7 @@ unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, uint64_t block) gfs2_assert(rgd->rd_sbd, buf < length); buf_block = rgrp_block - bi->bi_start * GFS2_NBBY; - type = gfs2_testbit(rgd, - bi->bi_bh->b_data + bi->bi_offset, + type = gfs2_testbit(rgd, bi->bi_bh->b_data + bi->bi_offset, bi->bi_len, buf_block); return type; @@ -1210,7 +1218,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, uint64_t bstart, uint64_t gfs2_alloc_data(struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; struct gfs2_rgrpd *rgd = al->al_rgd; uint32_t goal, blk; @@ -1254,7 +1262,7 @@ uint64_t gfs2_alloc_data(struct gfs2_inode *ip) uint64_t gfs2_alloc_meta(struct gfs2_inode *ip) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; struct gfs2_rgrpd *rgd = al->al_rgd; uint32_t goal, blk; @@ -1299,7 +1307,7 @@ uint64_t gfs2_alloc_meta(struct gfs2_inode *ip) uint64_t gfs2_alloc_di(struct gfs2_inode *dip) { - struct gfs2_sbd *sdp = dip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct gfs2_alloc *al = &dip->i_alloc; struct gfs2_rgrpd *rgd = al->al_rgd; uint32_t blk; @@ -1341,7 +1349,7 @@ uint64_t gfs2_alloc_di(struct gfs2_inode *dip) void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_rgrpd *rgd; rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE); @@ -1370,7 +1378,7 @@ void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_rgrpd *rgd; rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE); @@ -1385,11 +1393,25 @@ void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) gfs2_trans_add_rg(rgd); gfs2_statfs_change(sdp, 0, +blen, 0); - gfs2_quota_change(ip, -(int64_t)blen, - ip->i_di.di_uid, ip->i_di.di_gid); + gfs2_quota_change(ip, -(int64_t)blen, ip->i_di.di_uid, ip->i_di.di_gid); gfs2_meta_wipe(ip, bstart, blen); } +void gfs2_unlink_di(struct inode *inode) +{ + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); + struct gfs2_rgrpd *rgd; + u64 blkno = ip->i_num.no_addr; + + rgd = rgblk_free(sdp, blkno, 1, GFS2_BLKST_UNLINKED); + if (!rgd) + return; + gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); + gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); + gfs2_trans_add_rg(rgd); +} + void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno) { struct gfs2_sbd *sdp = rgd->rd_sbd; @@ -1412,12 +1434,6 @@ void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno) gfs2_trans_add_rg(rgd); } -/** - * gfs2_free_uninit_di - free a dinode block - * @rgd: the resource group that contains the dinode - * @ip: the inode - * - */ void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) { diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h index d2db3719cc0f..e86a532cc159 100644 --- a/fs/gfs2/rgrp.h +++ b/fs/gfs2/rgrp.h @@ -45,6 +45,7 @@ void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno); void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip); +void gfs2_unlink_di(struct inode *inode); struct gfs2_rgrp_list { unsigned int rl_rgrps; diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index a943a505bc5a..f2d287660cc9 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -31,7 +31,6 @@ #include "rgrp.h" #include "super.h" #include "trans.h" -#include "unlinked.h" #include "util.h" /** @@ -55,7 +54,6 @@ void gfs2_tune_init(struct gfs2_tune *gt) gt->gt_recoverd_secs = 60; gt->gt_logd_secs = 1; gt->gt_quotad_secs = 5; - gt->gt_inoded_secs = 15; gt->gt_quota_simul_sync = 64; gt->gt_quota_warn_period = 10; gt->gt_quota_scale_num = 1; @@ -202,9 +200,6 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2; sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1; sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(uint64_t); - sdp->sd_ut_per_block = (sdp->sd_sb.sb_bsize - - sizeof(struct gfs2_meta_header)) / - sizeof(struct gfs2_unlinked_tag); sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header)) / sizeof(struct gfs2_quota_change); @@ -277,7 +272,7 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) { - struct gfs2_inode *dip = sdp->sd_jindex->u.generic_ip; + struct gfs2_inode *dip = GFS2_I(sdp->sd_jindex); struct qstr name; char buf[20]; struct gfs2_jdesc *jd; @@ -296,8 +291,7 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) name.len = sprintf(buf, "journal%u", sdp->sd_journals); name.hash = gfs2_disk_hash(name.name, name.len); - error = gfs2_dir_search(sdp->sd_jindex, - &name, NULL, NULL); + error = gfs2_dir_search(sdp->sd_jindex, &name, NULL, NULL); if (error == -ENOENT) { error = 0; break; @@ -423,22 +417,19 @@ struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp) int gfs2_jdesc_check(struct gfs2_jdesc *jd) { - struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_inode *ip = GFS2_I(jd->jd_inode); + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); int ar; int error; - if (ip->i_di.di_size < (8 << 20) || - ip->i_di.di_size > (1 << 30) || + if (ip->i_di.di_size < (8 << 20) || ip->i_di.di_size > (1 << 30) || (ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1))) { gfs2_consist_inode(ip); return -EIO; } jd->jd_blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; - error = gfs2_write_alloc_required(ip, - 0, ip->i_di.di_size, - &ar); + error = gfs2_write_alloc_required(ip, 0, ip->i_di.di_size, &ar); if (!error && ar) { gfs2_consist_inode(ip); error = -EIO; @@ -456,7 +447,7 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd) int gfs2_make_fs_rw(struct gfs2_sbd *sdp) { - struct gfs2_inode *ip = sdp->sd_jdesc->jd_inode->u.generic_ip; + struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode); struct gfs2_glock *j_gl = ip->i_gl; struct gfs2_holder t_gh; struct gfs2_log_header head; @@ -484,9 +475,6 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp) sdp->sd_log_sequence = head.lh_sequence + 1; gfs2_log_pointers_init(sdp, head.lh_blkno); - error = gfs2_unlinked_init(sdp); - if (error) - goto fail; error = gfs2_quota_init(sdp); if (error) goto fail_unlinked; @@ -498,7 +486,6 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp) return 0; fail_unlinked: - gfs2_unlinked_cleanup(sdp); fail: t_gh.gh_flags |= GL_NOCACHE; @@ -519,7 +506,6 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp) struct gfs2_holder t_gh; int error; - gfs2_unlinked_dealloc(sdp); gfs2_quota_sync(sdp); gfs2_statfs_sync(sdp); @@ -537,7 +523,6 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp) if (t_gh.gh_gl) gfs2_glock_dq_uninit(&t_gh); - gfs2_unlinked_cleanup(sdp); gfs2_quota_cleanup(sdp); return error; @@ -545,9 +530,9 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp) int gfs2_statfs_init(struct gfs2_sbd *sdp) { - struct gfs2_inode *m_ip = sdp->sd_statfs_inode->u.generic_ip; + struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; - struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip; + struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; struct buffer_head *m_bh, *l_bh; struct gfs2_holder gh; @@ -594,7 +579,7 @@ int gfs2_statfs_init(struct gfs2_sbd *sdp) void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, int64_t dinodes) { - struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip; + struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; struct buffer_head *l_bh; int error; @@ -620,8 +605,8 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, int gfs2_statfs_sync(struct gfs2_sbd *sdp) { - struct gfs2_inode *m_ip = sdp->sd_statfs_inode->u.generic_ip; - struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip; + struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); + struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; struct gfs2_holder gh; @@ -852,10 +837,8 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, error = -ENOMEM; goto out; } - ip = jd->jd_inode->u.generic_ip; - error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_SHARED, 0, - &lfcc->gh); + ip = GFS2_I(jd->jd_inode); + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh); if (error) { kfree(lfcc); goto out; diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index d32a2c54daee..3c4cb4558905 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -453,7 +453,6 @@ TUNE_ATTR_DAEMON(scand_secs, scand_process); TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process); TUNE_ATTR_DAEMON(logd_secs, logd_process); TUNE_ATTR_DAEMON(quotad_secs, quotad_process); -TUNE_ATTR_DAEMON(inoded_secs, inoded_process); TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); static struct attribute *tune_attrs[] = { @@ -485,7 +484,6 @@ static struct attribute *tune_attrs[] = { &tune_attr_recoverd_secs.attr, &tune_attr_logd_secs.attr, &tune_attr_quotad_secs.attr, - &tune_attr_inoded_secs.attr, &tune_attr_quota_scale.attr, &tune_attr_new_files_jdata.attr, &tune_attr_new_files_directio.attr, diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h index 60ef163dd9bb..fbef3f5a99e3 100644 --- a/fs/gfs2/trans.h +++ b/fs/gfs2/trans.h @@ -17,7 +17,6 @@ #define RES_LEAF 1 #define RES_RG_BIT 2 #define RES_EATTR 1 -#define RES_UNLINKED 1 #define RES_STATFS 1 #define RES_QUOTA 2 diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c deleted file mode 100644 index b92d73002055..000000000000 --- a/fs/gfs2/unlinked.c +++ /dev/null @@ -1,459 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "gfs2.h" -#include "lm_interface.h" -#include "incore.h" -#include "bmap.h" -#include "inode.h" -#include "meta_io.h" -#include "trans.h" -#include "unlinked.h" -#include "util.h" - -static int munge_ondisk(struct gfs2_sbd *sdp, unsigned int slot, - struct gfs2_unlinked_tag *ut) -{ - struct gfs2_inode *ip = sdp->sd_ut_inode->u.generic_ip; - unsigned int block, offset; - uint64_t dblock; - int new = 0; - struct buffer_head *bh; - int error; - int boundary; - - block = slot / sdp->sd_ut_per_block; - offset = slot % sdp->sd_ut_per_block; - - error = gfs2_block_map(ip->i_vnode, block, &new, &dblock, &boundary); - if (error) - return error; - error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh); - if (error) - return error; - if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_UT)) { - error = -EIO; - goto out; - } - - mutex_lock(&sdp->sd_unlinked_mutex); - gfs2_trans_add_bh(ip->i_gl, bh, 1); - gfs2_unlinked_tag_out(ut, bh->b_data + - sizeof(struct gfs2_meta_header) + - offset * sizeof(struct gfs2_unlinked_tag)); - mutex_unlock(&sdp->sd_unlinked_mutex); - - out: - brelse(bh); - - return error; -} - -static void ul_hash(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) -{ - spin_lock(&sdp->sd_unlinked_spin); - list_add(&ul->ul_list, &sdp->sd_unlinked_list); - gfs2_assert(sdp, ul->ul_count); - ul->ul_count++; - atomic_inc(&sdp->sd_unlinked_count); - spin_unlock(&sdp->sd_unlinked_spin); -} - -static void ul_unhash(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) -{ - spin_lock(&sdp->sd_unlinked_spin); - list_del_init(&ul->ul_list); - gfs2_assert(sdp, ul->ul_count > 1); - ul->ul_count--; - gfs2_assert_warn(sdp, atomic_read(&sdp->sd_unlinked_count) > 0); - atomic_dec(&sdp->sd_unlinked_count); - spin_unlock(&sdp->sd_unlinked_spin); -} - -static struct gfs2_unlinked *ul_fish(struct gfs2_sbd *sdp) -{ - struct list_head *head; - struct gfs2_unlinked *ul; - int found = 0; - - if (sdp->sd_vfs->s_flags & MS_RDONLY) - return NULL; - - spin_lock(&sdp->sd_unlinked_spin); - - head = &sdp->sd_unlinked_list; - - list_for_each_entry(ul, head, ul_list) { - if (test_bit(ULF_LOCKED, &ul->ul_flags)) - continue; - - list_move_tail(&ul->ul_list, head); - ul->ul_count++; - set_bit(ULF_LOCKED, &ul->ul_flags); - found = 1; - - break; - } - - if (!found) - ul = NULL; - - spin_unlock(&sdp->sd_unlinked_spin); - - return ul; -} - -/** - * enforce_limit - limit the number of inodes waiting to be deallocated - * @sdp: the filesystem - * - * Returns: errno - */ - -static void enforce_limit(struct gfs2_sbd *sdp) -{ - unsigned int tries = 0, min = 0; - int error; - - if (atomic_read(&sdp->sd_unlinked_count) < - gfs2_tune_get(sdp, gt_ilimit)) - return; - - tries = gfs2_tune_get(sdp, gt_ilimit_tries); - min = gfs2_tune_get(sdp, gt_ilimit_min); - - while (tries--) { - struct gfs2_unlinked *ul = ul_fish(sdp); - if (!ul) - break; - error = gfs2_inode_dealloc(sdp, ul); - gfs2_unlinked_put(sdp, ul); - - if (!error) { - if (!--min) - break; - } else if (error != 1) - break; - } -} - -static struct gfs2_unlinked *ul_alloc(struct gfs2_sbd *sdp) -{ - struct gfs2_unlinked *ul; - - ul = kzalloc(sizeof(struct gfs2_unlinked), GFP_KERNEL); - if (ul) { - INIT_LIST_HEAD(&ul->ul_list); - ul->ul_count = 1; - set_bit(ULF_LOCKED, &ul->ul_flags); - } - - return ul; -} - -int gfs2_unlinked_get(struct gfs2_sbd *sdp, struct gfs2_unlinked **ul) -{ - unsigned int c, o = 0, b; - unsigned char byte = 0; - - enforce_limit(sdp); - - *ul = ul_alloc(sdp); - if (!*ul) - return -ENOMEM; - - spin_lock(&sdp->sd_unlinked_spin); - - for (c = 0; c < sdp->sd_unlinked_chunks; c++) - for (o = 0; o < PAGE_SIZE; o++) { - byte = sdp->sd_unlinked_bitmap[c][o]; - if (byte != 0xFF) - goto found; - } - - goto fail; - -found: - for (b = 0; b < 8; b++) - if (!(byte & (1 << b))) - break; - (*ul)->ul_slot = c * (8 * PAGE_SIZE) + o * 8 + b; - - if ((*ul)->ul_slot >= sdp->sd_unlinked_slots) - goto fail; - - sdp->sd_unlinked_bitmap[c][o] |= 1 << b; - - spin_unlock(&sdp->sd_unlinked_spin); - - return 0; - -fail: - spin_unlock(&sdp->sd_unlinked_spin); - kfree(*ul); - return -ENOSPC; -} - -void gfs2_unlinked_put(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) -{ - gfs2_assert_warn(sdp, test_and_clear_bit(ULF_LOCKED, &ul->ul_flags)); - - spin_lock(&sdp->sd_unlinked_spin); - gfs2_assert(sdp, ul->ul_count); - ul->ul_count--; - if (!ul->ul_count) { - gfs2_icbit_munge(sdp, sdp->sd_unlinked_bitmap, ul->ul_slot, 0); - spin_unlock(&sdp->sd_unlinked_spin); - kfree(ul); - } else - spin_unlock(&sdp->sd_unlinked_spin); -} - -int gfs2_unlinked_ondisk_add(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) -{ - int error; - - gfs2_assert_warn(sdp, test_bit(ULF_LOCKED, &ul->ul_flags)); - gfs2_assert_warn(sdp, list_empty(&ul->ul_list)); - - error = munge_ondisk(sdp, ul->ul_slot, &ul->ul_ut); - if (!error) - ul_hash(sdp, ul); - - return error; -} - -int gfs2_unlinked_ondisk_munge(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) -{ - int error; - - gfs2_assert_warn(sdp, test_bit(ULF_LOCKED, &ul->ul_flags)); - gfs2_assert_warn(sdp, !list_empty(&ul->ul_list)); - - error = munge_ondisk(sdp, ul->ul_slot, &ul->ul_ut); - - return error; -} - -int gfs2_unlinked_ondisk_rm(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul) -{ - struct gfs2_unlinked_tag ut; - int error; - - gfs2_assert_warn(sdp, test_bit(ULF_LOCKED, &ul->ul_flags)); - gfs2_assert_warn(sdp, !list_empty(&ul->ul_list)); - - memset(&ut, 0, sizeof(struct gfs2_unlinked_tag)); - - error = munge_ondisk(sdp, ul->ul_slot, &ut); - if (error) - return error; - - ul_unhash(sdp, ul); - - return 0; -} - -/** - * gfs2_unlinked_dealloc - Go through the list of inodes to be deallocated - * @sdp: the filesystem - * - * Returns: errno - */ - -int gfs2_unlinked_dealloc(struct gfs2_sbd *sdp) -{ - unsigned int hits, strikes; - int error; - - for (;;) { - hits = 0; - strikes = 0; - - for (;;) { - struct gfs2_unlinked *ul = ul_fish(sdp); - if (!ul) - return 0; - error = gfs2_inode_dealloc(sdp, ul); - gfs2_unlinked_put(sdp, ul); - - if (!error) { - hits++; - if (strikes) - strikes--; - } else if (error == 1) { - strikes++; - if (strikes >= - atomic_read(&sdp->sd_unlinked_count)) { - error = 0; - break; - } - } else - return error; - } - - if (!hits || kthread_should_stop()) - break; - - cond_resched(); - } - - return 0; -} - -int gfs2_unlinked_init(struct gfs2_sbd *sdp) -{ - struct gfs2_inode *ip = sdp->sd_ut_inode->u.generic_ip; - unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; - unsigned int x, slot = 0; - unsigned int found = 0; - uint64_t dblock; - uint32_t extlen = 0; - int error; - - if (!ip->i_di.di_size || - ip->i_di.di_size > (64 << 20) || - ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1)) { - gfs2_consist_inode(ip); - return -EIO; - } - sdp->sd_unlinked_slots = blocks * sdp->sd_ut_per_block; - sdp->sd_unlinked_chunks = DIV_ROUND_UP(sdp->sd_unlinked_slots, - 8 * PAGE_SIZE); - - error = -ENOMEM; - - sdp->sd_unlinked_bitmap = kcalloc(sdp->sd_unlinked_chunks, - sizeof(unsigned char *), - GFP_KERNEL); - if (!sdp->sd_unlinked_bitmap) - return error; - - for (x = 0; x < sdp->sd_unlinked_chunks; x++) { - sdp->sd_unlinked_bitmap[x] = kzalloc(PAGE_SIZE, GFP_KERNEL); - if (!sdp->sd_unlinked_bitmap[x]) - goto fail; - } - - for (x = 0; x < blocks; x++) { - struct buffer_head *bh; - unsigned int y; - - if (!extlen) { - int new = 0; - error = gfs2_extent_map(ip->i_vnode, x, &new, &dblock, &extlen); - if (error) - goto fail; - } - gfs2_meta_ra(ip->i_gl, dblock, extlen); - error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, - &bh); - if (error) - goto fail; - error = -EIO; - if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_UT)) { - brelse(bh); - goto fail; - } - - for (y = 0; - y < sdp->sd_ut_per_block && slot < sdp->sd_unlinked_slots; - y++, slot++) { - struct gfs2_unlinked_tag ut; - struct gfs2_unlinked *ul; - - gfs2_unlinked_tag_in(&ut, bh->b_data + - sizeof(struct gfs2_meta_header) + - y * sizeof(struct gfs2_unlinked_tag)); - if (!ut.ut_inum.no_addr) - continue; - - error = -ENOMEM; - ul = ul_alloc(sdp); - if (!ul) { - brelse(bh); - goto fail; - } - ul->ul_ut = ut; - ul->ul_slot = slot; - - spin_lock(&sdp->sd_unlinked_spin); - gfs2_icbit_munge(sdp, sdp->sd_unlinked_bitmap, slot, 1); - spin_unlock(&sdp->sd_unlinked_spin); - ul_hash(sdp, ul); - - gfs2_unlinked_put(sdp, ul); - found++; - } - - brelse(bh); - dblock++; - extlen--; - } - - if (found) - fs_info(sdp, "found %u unlinked inodes\n", found); - - return 0; - -fail: - gfs2_unlinked_cleanup(sdp); - return error; -} - -/** - * gfs2_unlinked_cleanup - get rid of any extra struct gfs2_unlinked structures - * @sdp: the filesystem - * - */ - -void gfs2_unlinked_cleanup(struct gfs2_sbd *sdp) -{ - struct list_head *head = &sdp->sd_unlinked_list; - struct gfs2_unlinked *ul; - unsigned int x; - - spin_lock(&sdp->sd_unlinked_spin); - while (!list_empty(head)) { - ul = list_entry(head->next, struct gfs2_unlinked, ul_list); - - if (ul->ul_count > 1) { - list_move_tail(&ul->ul_list, head); - spin_unlock(&sdp->sd_unlinked_spin); - schedule(); - spin_lock(&sdp->sd_unlinked_spin); - continue; - } - - list_del_init(&ul->ul_list); - atomic_dec(&sdp->sd_unlinked_count); - - gfs2_assert_warn(sdp, ul->ul_count == 1); - gfs2_assert_warn(sdp, !test_bit(ULF_LOCKED, &ul->ul_flags)); - kfree(ul); - } - spin_unlock(&sdp->sd_unlinked_spin); - - gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_unlinked_count)); - - if (sdp->sd_unlinked_bitmap) { - for (x = 0; x < sdp->sd_unlinked_chunks; x++) - kfree(sdp->sd_unlinked_bitmap[x]); - kfree(sdp->sd_unlinked_bitmap); - } -} - diff --git a/fs/gfs2/unlinked.h b/fs/gfs2/unlinked.h deleted file mode 100644 index 159cf5ffe47e..000000000000 --- a/fs/gfs2/unlinked.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#ifndef __UNLINKED_DOT_H__ -#define __UNLINKED_DOT_H__ - -int gfs2_unlinked_get(struct gfs2_sbd *sdp, struct gfs2_unlinked **ul); -void gfs2_unlinked_put(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); - -int gfs2_unlinked_ondisk_add(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); -int gfs2_unlinked_ondisk_munge(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); -int gfs2_unlinked_ondisk_rm(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul); - -int gfs2_unlinked_dealloc(struct gfs2_sbd *sdp); - -int gfs2_unlinked_init(struct gfs2_sbd *sdp); -void gfs2_unlinked_cleanup(struct gfs2_sbd *sdp); - -#endif /* __UNLINKED_DOT_H__ */ diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 88974e9824f7..39e67b1ec70a 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -109,7 +109,7 @@ int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function, int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, const char *function, char *file, unsigned int line) { - struct gfs2_sbd *sdp = ip->i_sbd; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); int rv; rv = gfs2_lm_withdraw(sdp, "GFS2: fsid=%s: fatal: filesystem consistency error\n" diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index 3893aac4e3ae..1181da831939 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -1,11 +1,11 @@ /* -* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -* Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. -* -* This copyrighted material is made available to anyone wishing to use, -* modify, copy, or redistribute it subject to the terms and conditions -* of the GNU General Public License v.2. -*/ + * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ #ifndef __GFS2_ONDISK_DOT_H__ #define __GFS2_ONDISK_DOT_H__ @@ -36,7 +36,6 @@ #define GFS2_FORMAT_LB 1000 #define GFS2_FORMAT_EA 1600 #define GFS2_FORMAT_ED 1700 -#define GFS2_FORMAT_UT 1300 #define GFS2_FORMAT_QC 1400 /* These are format numbers for entities contained in files */ #define GFS2_FORMAT_RI 1100 @@ -80,7 +79,6 @@ static inline int gfs2_inum_equal(const struct gfs2_inum *ino1, #define GFS2_METATYPE_LB 12 #define GFS2_METATYPE_EA 10 #define GFS2_METATYPE_ED 11 -#define GFS2_METATYPE_UT 13 #define GFS2_METATYPE_QC 14 struct gfs2_meta_header { @@ -158,7 +156,7 @@ struct gfs2_rindex { #define GFS2_BLKST_FREE 0 #define GFS2_BLKST_USED 1 -#define GFS2_BLKST_INVALID 2 +#define GFS2_BLKST_UNLINKED 2 #define GFS2_BLKST_DINODE 3 #define GFS2_RGF_JOURNAL 0x00000001 @@ -396,20 +394,6 @@ struct gfs2_statfs_change { __be64 sc_dinodes; }; -/* - * Unlinked Tag - * Describes an allocated inode that isn't linked into - * the directory tree and might need to be deallocated. - */ - -#define GFS2_UTF_UNINIT 0x00000001 - -struct gfs2_unlinked_tag { - struct gfs2_inum ut_inum; - __be32 ut_flags; /* GFS2_UTF_... */ - __u32 __pad; -}; - /* * Quota change * Describes an allocation change for a particular @@ -445,8 +429,6 @@ extern void gfs2_inum_range_in(struct gfs2_inum_range *ir, char *buf); extern void gfs2_inum_range_out(struct gfs2_inum_range *ir, char *buf); extern void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, char *buf); extern void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf); -extern void gfs2_unlinked_tag_in(struct gfs2_unlinked_tag *ut, char *buf); -extern void gfs2_unlinked_tag_out(struct gfs2_unlinked_tag *ut, char *buf); extern void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf); /* Printing functions */ From 3a8476dda13bc6690c5c2d5f1d3078048392c188 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 19 Jun 2006 09:10:39 -0400 Subject: [PATCH 130/292] [GFS2] Remove debugging printks A few of my printks slipped through last time. Also fix a couple of minor bugs. Signed-off-by: Steven Whitehouse --- fs/gfs2/glops.c | 3 --- fs/gfs2/lops.c | 2 +- fs/gfs2/ops_inode.c | 5 +---- fs/gfs2/ops_super.c | 2 +- fs/gfs2/rgrp.c | 11 ----------- 5 files changed, 3 insertions(+), 20 deletions(-) diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 013bf5f1552f..a01874c58834 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -129,7 +129,6 @@ static void inode_go_xmote_bh(struct gfs2_glock *gl) static void inode_go_drop_th(struct gfs2_glock *gl) { - printk(KERN_INFO "drop th %p\n", gl->gl_object); gfs2_pte_inval(gl); gfs2_glock_drop_th(gl); } @@ -148,7 +147,6 @@ static void inode_go_sync(struct gfs2_glock *gl, int flags) if (test_bit(GLF_DIRTY, &gl->gl_flags)) { if (meta && data) { - printk(KERN_INFO "sync all\n"); gfs2_page_sync(gl, flags | DIO_START); gfs2_log_flush(gl->gl_sbd, gl); gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); @@ -226,7 +224,6 @@ static int inode_go_lock(struct gfs2_holder *gh) return 0; if (ip->i_vn != gl->gl_vn) { - printk(KERN_INFO "refresh inode %p\n", &ip->i_inode); error = gfs2_inode_refresh(ip); if (error) return error; diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index a76f1a778920..93563e72ae49 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -650,7 +650,7 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) } else gfs2_log_unlock(sdp); - kfree(bd1); + kmem_cache_free(gfs2_bufdata_cachep, bd1); } /* We've removed all the ordered write bufs here, so only jdata left */ diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index f678f6b62afd..2fe37aeac7b0 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -56,7 +56,6 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, struct gfs2_sbd *sdp = GFS2_SB(dir); struct gfs2_holder ghs[2]; struct inode *inode; - int new = 1; gfs2_holder_init(dip->i_gl, 0, 0, ghs); @@ -69,6 +68,7 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, gfs2_quota_unlock(dip); gfs2_alloc_put(dip); gfs2_glock_dq_uninit_m(2, ghs); + mark_inode_dirty(inode); break; } else if (PTR_ERR(inode) != -EEXIST || (nd->intent.open.flags & O_EXCL)) { @@ -79,7 +79,6 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd); if (inode) { if (!IS_ERR(inode)) { - new = 0; gfs2_holder_uninit(ghs); break; } else { @@ -90,8 +89,6 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry, } d_instantiate(dentry, inode); - if (new) - mark_inode_dirty(inode); return 0; } diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 317d497f8f88..5f5fc3c42907 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -59,7 +59,7 @@ static int gfs2_write_inode(struct inode *inode, int sync) if (current->flags & PF_MEMALLOC) return 0; if (sync) - gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); + gfs2_log_flush(GFS2_SB(inode), ip->i_gl); } return 0; diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 75df79eb50ba..651341918833 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -447,8 +447,6 @@ static int gfs2_ri_update(struct gfs2_inode *ip) uint64_t junk = ip->i_di.di_size; int error; - printk(KERN_INFO "gfs2_ri_update inode=%p\n", inode); - if (do_div(junk, sizeof(struct gfs2_rindex))) { gfs2_consist_inode(ip); return -EIO; @@ -456,12 +454,9 @@ static int gfs2_ri_update(struct gfs2_inode *ip) clear_rgrpdi(sdp); - printk(KERN_INFO "rgrps cleared\n"); - file_ra_state_init(&ra_state, inode->i_mapping); for (sdp->sd_rgrps = 0;; sdp->sd_rgrps++) { loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex); - printk(KERN_INFO "reading rgrp %d\n", sdp->sd_rgrps); error = gfs2_internal_read(ip, &ra_state, buf, &pos, sizeof(struct gfs2_rindex)); if (!error) @@ -485,15 +480,12 @@ static int gfs2_ri_update(struct gfs2_inode *ip) list_add_tail(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list); gfs2_rindex_in(&rgd->rd_ri, buf); - printk(KERN_INFO "compute bitstructs\n"); error = compute_bitstructs(rgd); if (error) goto fail; - printk(KERN_INFO "gfs2_glock_get\n"); error = gfs2_glock_get(sdp, rgd->rd_ri.ri_addr, &gfs2_rgrp_glops, CREATE, &rgd->rd_gl); - printk(KERN_INFO "gfs2_glock_got one\n"); if (error) goto fail; @@ -501,14 +493,11 @@ static int gfs2_ri_update(struct gfs2_inode *ip) rgd->rd_rg_vn = rgd->rd_gl->gl_vn - 1; } - printk(KERN_INFO "ok, finished\n"); sdp->sd_rindex_vn = ip->i_gl->gl_vn; return 0; fail: - printk(KERN_INFO "fail\n"); clear_rgrpdi(sdp); - printk(KERN_INFO "cleared rgrps\n"); return error; } From 7d5513d58d072cf38cae9c886653aadac38ef4a9 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Mon, 19 Jun 2006 09:15:38 -0400 Subject: [PATCH 131/292] [DLM] init rwsem earlier The nodeinfo_lock rwsem needs to be initialized when the module is loaded instead of when the dlm is first used. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lowcomms.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index 75010da95b39..7ab40422ab57 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -1190,10 +1190,6 @@ int dlm_lowcomms_start(void) { int error; - spin_lock_init(&write_nodes_lock); - INIT_LIST_HEAD(&write_nodes); - init_rwsem(&nodeinfo_lock); - error = init_sock(); if (error) goto fail_sock; @@ -1224,6 +1220,9 @@ void dlm_lowcomms_stop(void) int dlm_lowcomms_init(void) { init_waitqueue_head(&lowcomms_recv_wait); + spin_lock_init(&write_nodes_lock); + INIT_LIST_HEAD(&write_nodes); + init_rwsem(&nodeinfo_lock); return 0; } From b61dde795f120f5dca2c865a1860dd9ff76705a1 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 19 Jun 2006 10:51:11 -0400 Subject: [PATCH 132/292] [GFS2] Always include glock in transaction Include the glock in the transaction, even when not journaling data in order that ordered write data will be correctly flushed when the lock is released. Signed-off-by: Steven Whitehouse --- fs/gfs2/lops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 93563e72ae49..af03bf380f46 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -467,11 +467,11 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) if (!list_empty(&bd->bd_list_tr) && (ip->i_di.di_flags & GFS2_DIF_JDATA)) { tr->tr_num_buf++; - gfs2_trans_add_gl(bd->bd_gl); list_add(&bd->bd_list_tr, &tr->tr_list_buf); gfs2_pin(sdp, bd->bd_bh); tr->tr_num_buf_new++; } + gfs2_trans_add_gl(bd->bd_gl); gfs2_log_lock(sdp); if (!list_empty(&le->le_list)) { if (ip->i_di.di_flags & GFS2_DIF_JDATA) From 9f5aa2a921797ce6eb4542c7517915bd1d5fbd0b Mon Sep 17 00:00:00 2001 From: Patrick Caulfield Date: Mon, 19 Jun 2006 16:27:52 -0400 Subject: [PATCH 133/292] [DLM] Fix potential conflict in DLM userland locks Just spotted this one. The lockinfo structs are hashed by lockid but into a global structure. So that if there are two lockspaces with the same lockid all hell breaks loose. I'm not exactly sure what will happen but it can't be good! The attached patch moves the lockinfo_idr into the user_ls structure so that lockids are localised. patrick Signed-Off-By: Patrick Caulfield Signed-off-by: Steven Whitehouse --- fs/dlm/device.c | 60 +++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/fs/dlm/device.c b/fs/dlm/device.c index 47798fe46d72..825bbc0a09c0 100644 --- a/fs/dlm/device.c +++ b/fs/dlm/device.c @@ -45,10 +45,6 @@ static const char *name_prefix="dlm"; static struct list_head user_ls_list; static struct mutex user_ls_lock; -/* Lock infos are stored in here indexed by lock ID */ -static DEFINE_IDR(lockinfo_idr); -static rwlock_t lockinfo_lock; - /* Flags in li_flags */ #define LI_FLAG_COMPLETE 1 #define LI_FLAG_FIRSTLOCK 2 @@ -99,6 +95,10 @@ struct user_ls { atomic_t ls_refcnt; long ls_flags; + /* Lock infos are stored in here indexed by lock ID */ + struct idr lockinfo_idr; + rwlock_t lockinfo_lock; + /* Passed into misc_register() */ struct miscdevice ls_miscinfo; struct list_head ls_list; @@ -240,13 +240,13 @@ static void put_file_info(struct file_info *f) kfree(f); } -static void release_lockinfo(struct lock_info *li) +static void release_lockinfo(struct user_ls *ls, struct lock_info *li) { put_file_info(li->li_file); - write_lock(&lockinfo_lock); - idr_remove(&lockinfo_idr, li->li_lksb.sb_lkid); - write_unlock(&lockinfo_lock); + write_lock(&ls->lockinfo_lock); + idr_remove(&ls->lockinfo_idr, li->li_lksb.sb_lkid); + write_unlock(&ls->lockinfo_lock); if (li->li_lksb.sb_lvbptr) kfree(li->li_lksb.sb_lvbptr); @@ -255,46 +255,46 @@ static void release_lockinfo(struct lock_info *li) module_put(THIS_MODULE); } -static struct lock_info *get_lockinfo(uint32_t lockid) +static struct lock_info *get_lockinfo(struct user_ls *ls, uint32_t lockid) { struct lock_info *li; - read_lock(&lockinfo_lock); - li = idr_find(&lockinfo_idr, lockid); - read_unlock(&lockinfo_lock); + read_lock(&ls->lockinfo_lock); + li = idr_find(&ls->lockinfo_idr, lockid); + read_unlock(&ls->lockinfo_lock); return li; } -static int add_lockinfo(struct lock_info *li) +static int add_lockinfo(struct user_ls *ls, struct lock_info *li) { int n; int r; int ret = -EINVAL; - write_lock(&lockinfo_lock); + write_lock(&ls->lockinfo_lock); - if (idr_find(&lockinfo_idr, li->li_lksb.sb_lkid)) + if (idr_find(&ls->lockinfo_idr, li->li_lksb.sb_lkid)) goto out_up; ret = -ENOMEM; - r = idr_pre_get(&lockinfo_idr, GFP_KERNEL); + r = idr_pre_get(&ls->lockinfo_idr, GFP_KERNEL); if (!r) goto out_up; - r = idr_get_new_above(&lockinfo_idr, li, li->li_lksb.sb_lkid, &n); + r = idr_get_new_above(&ls->lockinfo_idr, li, li->li_lksb.sb_lkid, &n); if (r) goto out_up; if (n != li->li_lksb.sb_lkid) { - idr_remove(&lockinfo_idr, n); + idr_remove(&ls->lockinfo_idr, n); goto out_up; } ret = 0; out_up: - write_unlock(&lockinfo_lock); + write_unlock(&ls->lockinfo_lock); return ret; } @@ -358,6 +358,9 @@ static int register_lockspace(char *name, struct user_ls **ls, int flags) return status; } + idr_init(&newls->lockinfo_idr); + rwlock_init(&newls->lockinfo_lock); + snprintf((char*)newls->ls_miscinfo.name, namelen, "%s_%s", name_prefix, name); @@ -486,13 +489,13 @@ static void ast_routine(void *param) list_del(&li->li_ownerqueue); clear_bit(LI_FLAG_ONLIST, &li->li_flags); spin_unlock(&li->li_file->fi_li_lock); - release_lockinfo(li); + release_lockinfo(li->li_file->fi_ls, li); return; } /* Free unlocks & queries */ if (li->li_lksb.sb_status == -DLM_EUNLOCK || li->li_cmd == DLM_USER_QUERY) { - release_lockinfo(li); + release_lockinfo(li->li_file->fi_ls, li); } } else { /* Synchronous request, just wake up the caller */ @@ -641,7 +644,7 @@ static int dlm_close(struct inode *inode, struct file *file) old_li->li_lksb.sb_lkid, status); /* But tidy our references in it */ - release_lockinfo(old_li); + release_lockinfo(old_li->li_file->fi_ls, old_li); continue; } @@ -662,7 +665,7 @@ static int dlm_close(struct inode *inode, struct file *file) /* Unlock suceeded, free the lock_info struct. */ if (status == 0) - release_lockinfo(old_li); + release_lockinfo(old_li->li_file->fi_ls, old_li); } remove_wait_queue(&li.li_waitq, &wq); @@ -920,7 +923,7 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, unless we are adopting an orphaned persistent lock */ if (kparams->flags & DLM_LKF_CONVERT) { - li = get_lockinfo(kparams->lkid); + li = get_lockinfo(fi->fi_ls, kparams->lkid); /* If this is a persistent lock we will have to create a lockinfo again */ @@ -938,7 +941,7 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, fail we want rid of it */ init_completion(&li->li_firstcomp); set_bit(LI_FLAG_FIRSTLOCK, &li->li_flags); - add_lockinfo(li); + add_lockinfo(fi->fi_ls, li); /* TODO: do a query to get the current state ?? */ } @@ -1014,7 +1017,7 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, list_add(&li->li_ownerqueue, &fi->fi_li_list); set_bit(LI_FLAG_ONLIST, &li->li_flags); spin_unlock(&fi->fi_li_lock); - if (add_lockinfo(li)) + if (add_lockinfo(fi->fi_ls, li)) printk(KERN_WARNING "Add lockinfo failed\n"); complete(&li->li_firstcomp); @@ -1025,7 +1028,7 @@ static int do_user_lock(struct file_info *fi, uint8_t cmd, out_err: if (test_bit(LI_FLAG_FIRSTLOCK, &li->li_flags)) - release_lockinfo(li); + release_lockinfo(fi->fi_ls, li); return status; } @@ -1037,7 +1040,7 @@ static int do_user_unlock(struct file_info *fi, uint8_t cmd, int status; int convert_cancel = 0; - li = get_lockinfo(kparams->lkid); + li = get_lockinfo(fi->fi_ls, kparams->lkid); if (!li) { li = allocate_lockinfo(fi, cmd, kparams); if (!li) @@ -1209,7 +1212,6 @@ static int __init dlm_device_init(void) INIT_LIST_HEAD(&user_ls_list); mutex_init(&user_ls_lock); - rwlock_init(&lockinfo_lock); ctl_device.name = "dlm-control"; ctl_device.fops = &_dlm_ctl_fops; From 695165dfba5204791bc4ae8911ed8b6326ce6d91 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Tue, 20 Jun 2006 13:44:27 +0100 Subject: [PATCH 134/292] [GFS2] Fix use of bitops on unsigned int (struct gfs2_holder->gh_iflags) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fs/gfs2/glock.c: In function ‘gfs2_holder_get’: fs/gfs2/glock.c:439: warning: passing argument 2 of ‘set_bit’ from incompatible pointer type fs/gfs2/glock.c: In function ‘rq_promote’: fs/gfs2/glock.c:512: warning: passing argument 2 of ‘set_bit’ from incompatible pointer type fs/gfs2/glock.c:526: warning: passing argument 2 of ‘set_bit’ from incompatible pointer type ... Signed-off-by: David Woodhouse --- fs/gfs2/incore.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 9a67a5954126..034a855a14bb 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -157,7 +157,7 @@ struct gfs2_holder { unsigned gh_flags; int gh_error; - unsigned gh_iflags; + unsigned long gh_iflags; struct completion gh_wait; unsigned long gh_ip; }; From 0239c4ae8aa5cdee6dc3792effc2800d65292c04 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Tue, 20 Jun 2006 13:48:31 +0100 Subject: [PATCH 135/292] [GFS2] Fix printk format warnings in DLM code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fs/gfs2/locking/dlm/thread.c: In function ‘process_complete’: fs/gfs2/locking/dlm/thread.c:56: warning: format ‘%llx’ expects type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ fs/gfs2/locking/dlm/thread.c:69: warning: format ‘%llx’ expects type ‘long long unsigned int’, but argument 4 has type ‘uint64_t’ fs/gfs2/locking/dlm/thread.c:102: warning: format ‘%llx’ expects type ‘long long unsigned int’, but argument 3 has type ‘uint64_t’ fs/gfs2/locking/dlm/thread.c:124: warning: format ‘%llx’ expects type ‘long long unsigned int’, but argument 4 has type ‘uint64_t’ fs/gfs2/locking/dlm/thread.c:146: warning: format ‘%llx’ expects type ‘long long unsigned int’, but argument 4 has type ‘uint64_t’ fs/gfs2/locking/dlm/thread.c:148: warning: format ‘%llx’ expects type ‘long long unsigned int’, but argument 4 has type ‘uint64_t’ Signed-off-by: David Woodhouse --- fs/gfs2/locking/dlm/thread.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c index 3e2edcc2dbf6..489235b2edba 100644 --- a/fs/gfs2/locking/dlm/thread.c +++ b/fs/gfs2/locking/dlm/thread.c @@ -54,7 +54,8 @@ static void process_complete(struct gdlm_lock *lp) if (lp->lksb.sb_status == -DLM_ECANCEL) { log_info("complete dlm cancel %x,%llx flags %lx", - lp->lockname.ln_type, lp->lockname.ln_number, + lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number, lp->flags); lp->req = lp->cur; @@ -68,7 +69,8 @@ static void process_complete(struct gdlm_lock *lp) if (lp->lksb.sb_status != -DLM_EUNLOCK) { log_info("unlock sb_status %d %x,%llx flags %lx", lp->lksb.sb_status, lp->lockname.ln_type, - lp->lockname.ln_number, lp->flags); + (unsigned long long)lp->lockname.ln_number, + lp->flags); return; } @@ -100,7 +102,8 @@ static void process_complete(struct gdlm_lock *lp) if (test_and_clear_bit(LFL_CANCEL, &lp->flags)) { log_info("complete internal cancel %x,%llx", - lp->lockname.ln_type, lp->lockname.ln_number); + lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number); lp->req = lp->cur; acb.lc_ret |= LM_OUT_CANCELED; goto out; @@ -123,7 +126,8 @@ static void process_complete(struct gdlm_lock *lp) /* this could only happen with cancels I think */ log_info("ast sb_status %d %x,%llx flags %lx", lp->lksb.sb_status, lp->lockname.ln_type, - lp->lockname.ln_number, lp->flags); + (unsigned long long)lp->lockname.ln_number, + lp->flags); return; } @@ -144,9 +148,11 @@ static void process_complete(struct gdlm_lock *lp) if (test_and_clear_bit(LFL_REREQUEST, &lp->flags)) { gdlm_assert(lp->req == DLM_LOCK_NL, "%x,%llx", - lp->lockname.ln_type, lp->lockname.ln_number); + lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number); gdlm_assert(lp->prev_req > DLM_LOCK_NL, "%x,%llx", - lp->lockname.ln_type, lp->lockname.ln_number); + lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number); lp->cur = DLM_LOCK_NL; lp->req = lp->prev_req; @@ -183,7 +189,8 @@ static void process_complete(struct gdlm_lock *lp) lp->lkf &= ~DLM_LKF_CONVDEADLK; log_debug("rereq %x,%llx id %x %d,%d", - lp->lockname.ln_type, lp->lockname.ln_number, + lp->lockname.ln_type, + (unsigned long long)lp->lockname.ln_number, lp->lksb.sb_lkid, lp->cur, lp->req); set_bit(LFL_REREQUEST, &lp->flags); From 0d42e54220ba34e031167138ef91cbd42d8b5876 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 20 Jun 2006 16:13:49 -0400 Subject: [PATCH 136/292] [GFS2] Remove unused ra_state variable As per Nick Piggin's comments on lkml, remove the unused ra_state variable. Signed-off-by: Steven Whitehouse Cc: Nick Piggin --- fs/gfs2/quota.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index d3cd5171d7c7..1892b29ec98d 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -649,7 +649,6 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd; struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); unsigned int data_blocks, ind_blocks; - struct file_ra_state ra_state; struct gfs2_holder *ghs, i_gh; unsigned int qx, x; struct gfs2_quota_data *qd; @@ -716,7 +715,6 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) goto out_gunlock; } - file_ra_state_init(&ra_state, ip->i_inode.i_mapping); for (x = 0; x < num_qd; x++) { qd = qda[x]; offset = qd2offset(qd); @@ -790,10 +788,8 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, memset(buf, 0, sizeof(struct gfs2_quota)); pos = qd2offset(qd); - error = gfs2_internal_read(ip, - &ra_state, buf, - &pos, - sizeof(struct gfs2_quota)); + error = gfs2_internal_read(ip, &ra_state, buf, + &pos, sizeof(struct gfs2_quota)); if (error < 0) goto fail_gunlock; From bf9f424d9acf461fabcb0e9f47b356e08186d91f Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 21 Jun 2006 11:54:43 -0400 Subject: [PATCH 137/292] [GFS2] Make file_read_actor export _GPL Make file_read_actor export a _GPL export. Signed-off-by: Steven Whitehouse --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 82c448898d05..a02a0b2c986b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1044,7 +1044,7 @@ success: desc->arg.buf += size; return size; } -EXPORT_SYMBOL(file_read_actor); +EXPORT_SYMBOL_GPL(file_read_actor); /* * This is the "read()" routine for all filesystems From d9d1ca30505c6fed867e1724b16fdad0c281d7d1 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 21 Jun 2006 15:38:17 -0400 Subject: [PATCH 138/292] [GFS2] Fix double locking problem in rename The rename inode operation was trying to lock the same inode twice in the case of renaming with the source and destination directories the same. We now test for this and just lock once. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_inode.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 2fe37aeac7b0..3a2769ebfe4a 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -615,13 +615,19 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, goto out_gunlock_r; } + num_gh = 1; gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); - gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); - gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 2); - num_gh = 3; + if (odip != ndip) { + gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); + num_gh++; + } + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); + num_gh++; - if (nip) - gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++); + if (nip) { + gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); + num_gh++; + } error = gfs2_glock_nq_m(num_gh, ghs); if (error) From faf450ef4a8567e4c75a905aadae01cf401d893a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 22 Jun 2006 10:59:10 -0400 Subject: [PATCH 139/292] [GFS2] Remove gfs2_repermission gfs2_repermission is just a wrapper for permission, so remove it and call permission directly where required. Signed-off-by: Steven Whitehouse --- fs/gfs2/acl.c | 4 +--- fs/gfs2/inode.c | 11 +++-------- fs/gfs2/inode.h | 2 -- fs/gfs2/ops_file.c | 2 +- fs/gfs2/ops_inode.c | 10 ++++------ 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index 9ef4cf2c03db..399317841501 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -179,9 +179,7 @@ int gfs2_check_acl(struct inode *inode, int mask) struct gfs2_holder i_gh; int error; - error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_SHARED, LM_FLAG_ANY, - &i_gh); + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); if (!error) { error = gfs2_check_acl_locked(inode, mask); gfs2_glock_dq_uninit(&i_gh); diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 4e9c42119aed..c19feb9697b0 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -420,7 +420,7 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, return ERR_PTR(error); if (!is_root) { - error = gfs2_repermission(dir, MAY_EXEC, NULL); + error = permission(dir, MAY_EXEC, NULL); if (error) goto out; } @@ -571,7 +571,7 @@ static int create_ok(struct gfs2_inode *dip, const struct qstr *name, { int error; - error = gfs2_repermission(&dip->i_inode, MAY_WRITE | MAY_EXEC, NULL); + error = permission(&dip->i_inode, MAY_WRITE | MAY_EXEC, NULL); if (error) return error; @@ -1003,7 +1003,7 @@ int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name, if (IS_APPEND(&dip->i_inode)) return -EPERM; - error = gfs2_repermission(&dip->i_inode, MAY_WRITE | MAY_EXEC, NULL); + error = permission(&dip->i_inode, MAY_WRITE | MAY_EXEC, NULL); if (error) return error; @@ -1356,8 +1356,3 @@ int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) return error; } -int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd) -{ - return permission(inode, mask, nd); -} - diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index 30cfcc10beb2..8bb8b559bcea 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -50,8 +50,6 @@ int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs); int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr); -int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd); - struct inode *gfs2_lookup_simple(struct inode *dip, const char *name); #endif /* __INODE_DOT_H__ */ diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 222f3be3e06e..5e754198f5bb 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -640,7 +640,7 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) !capable(CAP_LINUX_IMMUTABLE)) goto out; if (!IS_IMMUTABLE(inode)) { - error = gfs2_repermission(inode, MAY_WRITE, NULL); + error = permission(inode, MAY_WRITE, NULL); if (error) goto out; } diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 3a2769ebfe4a..5d5ebbcba534 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -155,7 +155,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, if (error) goto out; - error = gfs2_repermission(dir, MAY_WRITE | MAY_EXEC, NULL); + error = permission(dir, MAY_WRITE | MAY_EXEC, NULL); if (error) goto out_gunlock; @@ -659,7 +659,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, } } } else { - error = gfs2_repermission(ndir, MAY_WRITE | MAY_EXEC, NULL); + error = permission(ndir, MAY_WRITE | MAY_EXEC, NULL); if (error) goto out_gunlock; @@ -694,7 +694,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, /* Check out the dir to be renamed */ if (dir_rename) { - error = gfs2_repermission(odentry->d_inode, MAY_WRITE, NULL); + error = permission(odentry->d_inode, MAY_WRITE, NULL); if (error) goto out_gunlock; } @@ -888,9 +888,7 @@ static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd) if (ip->i_vn == ip->i_gl->gl_vn) return generic_permission(inode, mask, gfs2_check_acl); - error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_SHARED, LM_FLAG_ANY, - &i_gh); + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); if (!error) { error = generic_permission(inode, mask, gfs2_check_acl_locked); gfs2_glock_dq_uninit(&i_gh); From 43f5d210a02dcf9d8bafb147044f27add10a459a Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Thu, 22 Jun 2006 11:16:40 -0400 Subject: [PATCH 140/292] [GFS2] [-mm patch] fs/gfs2/: make code static This patch makes the following needlessly global code static: - eaops.c: struct gfs2_security_eaops - rgrp.c: gfs2_free_uninit_di() Signed-off-by: Adrian Bunk Signed-off-by: Steven Whitehouse --- fs/gfs2/eaops.c | 2 +- fs/gfs2/eaops.h | 2 -- fs/gfs2/rgrp.c | 2 +- fs/gfs2/rgrp.h | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index b7e6a37cab6e..3ace242f2b16 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -214,7 +214,7 @@ struct gfs2_eattr_operations gfs2_system_eaops = { .eo_name = "system", }; -struct gfs2_eattr_operations gfs2_security_eaops = { +static struct gfs2_eattr_operations gfs2_security_eaops = { .eo_get = security_eo_get, .eo_set = security_eo_set, .eo_remove = security_eo_remove, diff --git a/fs/gfs2/eaops.h b/fs/gfs2/eaops.h index 965a235c96e8..3dece17e3116 100644 --- a/fs/gfs2/eaops.h +++ b/fs/gfs2/eaops.h @@ -23,8 +23,6 @@ unsigned int gfs2_ea_name2type(const char *name, char **truncated_name); extern struct gfs2_eattr_operations gfs2_system_eaops; -extern struct gfs2_eattr_operations gfs2_security_eaops; - extern struct gfs2_eattr_operations *gfs2_ea_ops[]; #endif /* __EAOPS_DOT_H__ */ diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 651341918833..14c1f88bfb5d 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -1401,7 +1401,7 @@ void gfs2_unlink_di(struct inode *inode) gfs2_trans_add_rg(rgd); } -void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno) +static void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno) { struct gfs2_sbd *sdp = rgd->rd_sbd; struct gfs2_rgrpd *tmp_rgd; diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h index e86a532cc159..9c42d2252ddd 100644 --- a/fs/gfs2/rgrp.h +++ b/fs/gfs2/rgrp.h @@ -43,7 +43,6 @@ uint64_t gfs2_alloc_di(struct gfs2_inode *ip); void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); -void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno); void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip); void gfs2_unlink_di(struct inode *inode); From bdd512aeeab860f7a9a537142dd0983f884d723a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 22 Jun 2006 15:26:33 -0400 Subject: [PATCH 141/292] [GFS2] Remove unused flag The flag GIF_MIN_INIT is no longer used or required. Signed-off-by: Steven Whitehouse --- fs/gfs2/incore.h | 1 - fs/gfs2/inode.c | 1 - 2 files changed, 2 deletions(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 034a855a14bb..90e0624d8065 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -234,7 +234,6 @@ struct gfs2_alloc { }; enum { - GIF_MIN_INIT = 0, GIF_QD_LOCKED = 1, GIF_PAGED = 2, GIF_SW_PAGED = 3, diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index c19feb9697b0..6499c4f91078 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -236,7 +236,6 @@ int gfs2_inode_refresh(struct gfs2_inode *ip) } gfs2_dinode_in(&ip->i_di, dibh->b_data); - set_bit(GIF_MIN_INIT, &ip->i_flags); brelse(dibh); From a464418425192da270a9944d0e48c33e186af601 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 22 Jun 2006 15:29:57 -0400 Subject: [PATCH 142/292] [GFS2] gfs2/dlm: mailing list and web page List new development mailing list and correct web page url. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- MAINTAINERS | 4 ++-- fs/gfs2/Kconfig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 50817bf60694..b7206bbc96f3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -845,7 +845,7 @@ P: Patrick Caulfield M: pcaulfie@redhat.com P: David Teigland M: teigland@redhat.com -L: linux-cluster@redhat.com +L: cluster-devel@redhat.com W: http://sources.redhat.com/cluster/ T: git kernel.org:/pub/scm/linux/kernel/git/steve/gfs-2.6.git S: Supported @@ -1103,7 +1103,7 @@ S: Maintained GFS2 FILE SYSTEM P: Steven Whitehouse M: swhiteho@redhat.com -L: linux-cluster@redhat.com +L: cluster-devel@redhat.com W: http://sources.redhat.com/cluster/ T: git kernel.org:/pub/scm/linux/kernel/git/steve/gfs-2.6.git S: Supported diff --git a/fs/gfs2/Kconfig b/fs/gfs2/Kconfig index 115f30d8c22e..8c27de8b9568 100644 --- a/fs/gfs2/Kconfig +++ b/fs/gfs2/Kconfig @@ -15,7 +15,7 @@ config GFS2_FS To use the GFS2 filesystem, you will need to enable one or more of the below locking modules. Documentation and utilities for GFS2 can - be found here: http://sources.redhat.com/cluster/gfs/ + be found here: http://sources.redhat.com/cluster config GFS2_FS_LOCKING_NOLOCK tristate "GFS2 \"nolock\" locking module" From a53311d4d9e1cde15aebc2048847ea19fb33ac3a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 23 Jun 2006 16:16:29 -0400 Subject: [PATCH 143/292] [GFS2] Use generic_file_sendfile directly Don't use a wrapper for generic_file_sendfile but call it directly. Cc: Christoph Hellwig Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 5e754198f5bb..ecef76e8373a 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -859,24 +859,6 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) return gfs2_lm_plock(sdp, &name, file, cmd, fl); } -/** - * gfs2_sendfile - Send bytes to a file or socket - * @in_file: The file to read from - * @out_file: The file to write to - * @count: The amount of data - * @offset: The beginning file offset - * - * Outputs: offset - updated according to number of bytes read - * - * Returns: The number of bytes sent, errno on failure - */ - -static ssize_t gfs2_sendfile(struct file *in_file, loff_t *offset, size_t count, - read_actor_t actor, void *target) -{ - return generic_file_sendfile(in_file, offset, count, actor, target); -} - static int do_flock(struct file *file, int cmd, struct file_lock *fl) { struct gfs2_file *fp = file->private_data; @@ -982,7 +964,7 @@ struct file_operations gfs2_file_fops = { .release = gfs2_close, .fsync = gfs2_fsync, .lock = gfs2_lock, - .sendfile = gfs2_sendfile, + .sendfile = generic_file_sendfile, .flock = gfs2_flock, .splice_read = generic_file_splice_read, .splice_write = generic_file_splice_write, From af18ddb8864b096e3ed4732e2d4b21c956dcfe3a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Sat, 24 Jun 2006 15:42:21 -0400 Subject: [PATCH 144/292] [GFS2] Eliminate one instance of __GFP_NOFAIL This removes one instance of GFP_NOFAIL from the glock callback function. It also fixes a bug where a , was used at a line end rather than ; causing unintended results. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 8 +++++--- fs/gfs2/ops_inode.c | 6 ++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 35bac90878a5..dbeb4ad836bd 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -416,7 +416,7 @@ void gfs2_holder_uninit(struct gfs2_holder *gh) * @gl: the glock * @state: the state we're requesting * @flags: the modifier flags - * @gfp_flags: __GFP_NOFAIL + * @gfp_flags: * * Figure out how big an impact this function has. Either: * 1) Replace it with a cache of structures hanging off the struct gfs2_sbd @@ -720,6 +720,7 @@ static void gfs2_glmutex_unlock(struct gfs2_glock *gl) * @gl: the glock * @state: the state the caller wants us to change to * + * Note: This may fail sliently if we are out of memory. */ static void handle_callback(struct gfs2_glock *gl, unsigned int state) @@ -744,8 +745,9 @@ restart: } else { spin_unlock(&gl->gl_spin); - new_gh = gfs2_holder_get(gl, state, LM_FLAG_TRY, - GFP_KERNEL | __GFP_NOFAIL), + new_gh = gfs2_holder_get(gl, state, LM_FLAG_TRY, GFP_KERNEL); + if (!new_gh) + return; set_bit(HIF_DEMOTE, &new_gh->gh_iflags); set_bit(HIF_DEALLOC, &new_gh->gh_iflags); diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 5d5ebbcba534..8895baafc640 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -962,10 +962,8 @@ static int setattr_chown(struct inode *inode, struct iattr *attr) brelse(dibh); if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { - gfs2_quota_change(ip, -ip->i_di.di_blocks, - ouid, ogid); - gfs2_quota_change(ip, ip->i_di.di_blocks, - nuid, ngid); + gfs2_quota_change(ip, -ip->i_di.di_blocks, ouid, ogid); + gfs2_quota_change(ip, ip->i_di.di_blocks, nuid, ngid); } out_end_trans: From 02630a12c7f72fa294981c8d86e38038781c25b7 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 3 Jul 2006 11:20:06 -0400 Subject: [PATCH 145/292] [GFS2] Remove dependance on tty_write_message() This removes the call in GFS2 to tty_write_message and replaces it with a printk. As the export was added by GFS2, we remove this as well. Signed-off-by: Steven Whitehouse --- fs/gfs2/quota.c | 23 ++++------------------- kernel/printk.c | 1 - 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 1892b29ec98d..3ca65c37c354 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -929,25 +928,11 @@ void gfs2_quota_unlock(struct gfs2_inode *ip) static int print_message(struct gfs2_quota_data *qd, char *type) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; - char *line; - int len; - line = kmalloc(MAX_LINE, GFP_KERNEL); - if (!line) - return -ENOMEM; - - len = snprintf(line, MAX_LINE-1, - "GFS2: fsid=%s: quota %s for %s %u\r\n", - sdp->sd_fsname, type, - (test_bit(QDF_USER, &qd->qd_flags)) ? "user" : "group", - qd->qd_id); - line[MAX_LINE-1] = 0; - - if (current->signal) { /* Is this test still required? */ - tty_write_message(current->signal->tty, line); - } - - kfree(line); + printk(KERN_INFO "GFS2: fsid=%s: quota %s for %s %u\r\n", + sdp->sd_fsname, type, + (test_bit(QDF_USER, &qd->qd_flags)) ? "user" : "group", + qd->qd_id); return 0; } diff --git a/kernel/printk.c b/kernel/printk.c index 9772b9e8feee..39ae24d2a415 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -1040,7 +1040,6 @@ void tty_write_message(struct tty_struct *tty, char *msg) tty->driver->write(tty, msg, strlen(msg)); return; } -EXPORT_SYMBOL_GPL(tty_write_message); /* * printk rate limiting, lifted from the networking subsystem. From ccd6efd0cd1244d5d4404393576c37f269de4c5a Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Fri, 30 Jun 2006 02:16:34 -0700 Subject: [PATCH 146/292] [patch 1/1] gfs2: get_sb_dev() fix Update GFS2 for dhowells API changes. Cc: Steven Whitehouse Cc: David Howells Signed-off-by: Andrew Morton Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_fstype.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index b68eb6b4a4c1..b040fda1f54c 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -812,11 +812,10 @@ static int fill_super(struct super_block *sb, void *data, int silent) return error; } -static struct super_block *gfs2_get_sb(struct file_system_type *fs_type, - int flags, const char *dev_name, - void *data) +static int gfs2_get_sb(struct file_system_type *fs_type, int flags, + const char *dev_name, void *data, struct vfsmount *mnt) { - return get_sb_bdev(fs_type, flags, dev_name, data, fill_super); + return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt); } static void gfs2_kill_sb(struct super_block *sb) From 0c0834a30cceeaf2748705d2b31f0d058693b716 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 3 Jul 2006 11:38:01 -0400 Subject: [PATCH 147/292] [GFS2] API change for gfs2_statfs The kernel API for super_operations->statfs() has changed so this updates GFS2 to the new API. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 5f5fc3c42907..50ea7f21f9cf 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -202,8 +202,9 @@ static void gfs2_unlockfs(struct super_block *sb) * Returns: 0 on success or error code */ -static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf) +static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf) { + struct super_block *sb = dentry->d_inode->i_sb; struct gfs2_sbd *sdp = sb->s_fs_info; struct gfs2_statfs_change sc; int error; From 66de045d9fe6147b065c47236d3b9d8d8a6cbd57 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 3 Jul 2006 13:37:30 -0400 Subject: [PATCH 148/292] [GFS2] Make our address_space_operations const As per Christoph's patch: http://www.kernel.org/git/?p=linux/kernel/git/steve/gfs2-2.6.git;a=commitdiff;h=f5e54d6e53a20cef45af7499e86164f0e0d16bb2 We mark struct address_space_operations const in GFS2. Signed-off-by: Steven Whitehouse --- fs/gfs2/meta_io.c | 2 +- fs/gfs2/ops_address.c | 2 +- fs/gfs2/ops_address.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 2523d42a02de..ddcd4dc1081d 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -159,7 +159,7 @@ static int gfs2_aspace_releasepage(struct page *page, gfp_t gfp_mask) return try_to_free_buffers(page); } -static struct address_space_operations aspace_aops = { +static const struct address_space_operations aspace_aops = { .writepage = gfs2_aspace_writepage, .releasepage = gfs2_aspace_releasepage, }; diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 207363aed112..26db3335d4b3 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -655,7 +655,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, DIO_OWN_LOCKING); } -struct address_space_operations gfs2_file_aops = { +const struct address_space_operations gfs2_file_aops = { .writepage = gfs2_writepage, .readpage = gfs2_readpage, .readpages = gfs2_readpages, diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h index b88adddaffb2..a7ef3bf36f3e 100644 --- a/fs/gfs2/ops_address.h +++ b/fs/gfs2/ops_address.h @@ -10,7 +10,7 @@ #ifndef __OPS_ADDRESS_DOT_H__ #define __OPS_ADDRESS_DOT_H__ -extern struct address_space_operations gfs2_file_aops; +extern const struct address_space_operations gfs2_file_aops; extern int gfs2_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create); From b0dd9308b703310e9a988df70f6ed3e87cb55655 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 3 Jul 2006 13:47:02 -0400 Subject: [PATCH 149/292] [GFS2] Mark file_operations const As per Arjan's patches: http://www.kernel.org/git/?p=linux/kernel/git/steve/gfs2-2.6.git;a=commitdiff;h=99ac48f54a91d02140c497edc31dc57d4bc5c85d and http://www.kernel.org/git/?p=linux/kernel/git/steve/gfs2-2.6.git;a=commitdiff;h=4b6f5d20b04dcbc3d888555522b90ba6d36c4106 make the GFS2 file_operations structures const. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 4 ++-- fs/gfs2/ops_file.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index ecef76e8373a..c8e2c98700a7 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -950,7 +950,7 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) return do_flock(file, cmd, fl); } -struct file_operations gfs2_file_fops = { +const struct file_operations gfs2_file_fops = { .llseek = gfs2_llseek, .read = gfs2_read, .readv = gfs2_file_readv, @@ -970,7 +970,7 @@ struct file_operations gfs2_file_fops = { .splice_write = generic_file_splice_write, }; -struct file_operations gfs2_dir_fops = { +const struct file_operations gfs2_dir_fops = { .readdir = gfs2_readdir, .unlocked_ioctl = gfs2_ioctl, .open = gfs2_open, diff --git a/fs/gfs2/ops_file.h b/fs/gfs2/ops_file.h index a2edce38f5cb..46302b513937 100644 --- a/fs/gfs2/ops_file.h +++ b/fs/gfs2/ops_file.h @@ -14,7 +14,7 @@ extern int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, char *buf, loff_t *pos, unsigned size); -extern struct file_operations gfs2_file_fops; -extern struct file_operations gfs2_dir_fops; +extern const struct file_operations gfs2_file_fops; +extern const struct file_operations gfs2_dir_fops; #endif /* __OPS_FILE_DOT_H__ */ From faac9bd0e3ce7cb0572ec66e0a426cacf6afa970 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 5 Jul 2006 08:24:34 -0400 Subject: [PATCH 150/292] [GFS2] Fix locking for Direct I/O reads We need to hold i_mutex when doing direct i/o reads. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 26db3335d4b3..27ce30148e69 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -642,6 +642,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, struct inode *inode = file->f_mapping->host; struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_sbd *sdp = GFS2_SB(inode); + int ret; if (rw == WRITE) return gfs2_direct_IO_write(iocb, iov, offset, nr_segs); @@ -650,9 +651,12 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) return -EINVAL; - return __blockdev_direct_IO(READ, iocb, inode, inode->i_sb->s_bdev, iov, - offset, nr_segs, gfs2_get_block, NULL, - DIO_OWN_LOCKING); + mutex_lock(&inode->i_mutex); + ret = __blockdev_direct_IO(READ, iocb, inode, inode->i_sb->s_bdev, iov, + offset, nr_segs, gfs2_get_block, NULL, + DIO_OWN_LOCKING); + mutex_unlock(&inode->i_mutex); + return ret; } const struct address_space_operations gfs2_file_aops = { From ecb1460dc44ffb8d3e570597f394504898f088bb Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 5 Jul 2006 10:41:39 -0400 Subject: [PATCH 151/292] [GFS2] Make GFS2 work with lock validator Change our one existing old-style lock initialiser to a new-style one. This allows the lock validator to work as intended. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_fstype.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index b040fda1f54c..a86ce67949db 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -57,7 +57,7 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) gfs2_tune_init(&sdp->sd_tune); for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { - sdp->sd_gl_hash[x].hb_lock = RW_LOCK_UNLOCKED; + rwlock_init(&sdp->sd_gl_hash[x].hb_lock); INIT_LIST_HEAD(&sdp->sd_gl_hash[x].hb_list); } INIT_LIST_HEAD(&sdp->sd_reclaim_list); From 3864caea2ed2b43bfc92e5cfbe001abe3f002a06 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 5 Jul 2006 11:17:36 -0400 Subject: [PATCH 152/292] [GFS2] Kbuild update to install correct headers Now that the headers_instakll target is in Linus' kernel, this update ensures that the correct GFS2/DLM headers are installed. Signed-off-by: Steven Whitehouse --- include/linux/Kbuild | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/include/linux/Kbuild b/include/linux/Kbuild index 2b8a7d68fae3..2121cde187d8 100644 --- a/include/linux/Kbuild +++ b/include/linux/Kbuild @@ -8,7 +8,7 @@ header-y += affs_fs.h affs_hardblocks.h aio_abi.h a.out.h arcfb.h \ atmppp.h atmsap.h atmsvc.h atm_zatm.h auto_fs4.h auxvec.h \ awe_voice.h ax25.h b1lli.h baycom.h bfs_fs.h blkpg.h \ bpqether.h cdk.h chio.h coda_psdev.h coff.h comstats.h \ - consolemap.h cycx_cfm.h dm-ioctl.h dn.h dqblk_v1.h \ + consolemap.h cycx_cfm.h dlm_device.h dm-ioctl.h dn.h dqblk_v1.h \ dqblk_v2.h dqblk_xfs.h efs_fs_sb.h elf-fdpic.h elf.h elf-em.h \ fadvise.h fd.h fdreg.h ftape-header-segment.h ftape-vendors.h \ fuse.h futex.h genetlink.h gen_stats.h gigaset_dev.h hdsmart.h \ @@ -18,28 +18,29 @@ header-y += affs_fs.h affs_hardblocks.h aio_abi.h a.out.h arcfb.h \ if_plip.h if_ppp.h if_slip.h if_strip.h if_tunnel.h in6.h \ in_route.h ioctl.h ip.h ipmi_msgdefs.h ip_mp_alg.h ipsec.h \ ipx.h irda.h isdn_divertif.h iso_fs.h ite_gpio.h ixjuser.h \ - jffs2.h keyctl.h limits.h major.h matroxfb.h meye.h minix_fs.h \ - mmtimer.h mqueue.h mtio.h ncp_no.h netfilter_arp.h netrom.h \ - nfs2.h nfs4_mount.h nfs_mount.h openprom_fs.h param.h \ - pci_ids.h pci_regs.h personality.h pfkeyv2.h pg.h pkt_cls.h \ - pkt_sched.h posix_types.h ppdev.h prctl.h ps2esdi.h qic117.h \ - qnxtypes.h quotaio_v1.h quotaio_v2.h radeonfb.h raw.h \ - resource.h rose.h sctp.h smbno.h snmp.h sockios.h som.h \ - sound.h stddef.h synclink.h telephony.h termios.h ticable.h \ - times.h tiocl.h tipc.h toshiba.h ultrasound.h un.h utime.h \ - utsname.h video_decoder.h video_encoder.h videotext.h vt.h \ - wavefront.h wireless.h xattr.h x25.h zorro_ids.h + jffs2.h keyctl.h limits.h lock_dlm_plock.h major.h matroxfb.h \ + meye.h minix_fs.h mmtimer.h mqueue.h mtio.h ncp_no.h \ + netfilter_arp.h netrom.h nfs2.h nfs4_mount.h nfs_mount.h \ + openprom_fs.h param.h pci_ids.h pci_regs.h personality.h \ + pfkeyv2.h pg.h pkt_cls.h pkt_sched.h posix_types.h ppdev.h \ + prctl.h ps2esdi.h qic117.h qnxtypes.h quotaio_v1.h quotaio_v2.h \ + radeonfb.h raw.h resource.h rose.h sctp.h smbno.h snmp.h \ + sockios.h som.h sound.h stddef.h synclink.h telephony.h \ + termios.h ticable.h times.h tiocl.h tipc.h toshiba.h \ + ultrasound.h un.h utime.h utsname.h video_decoder.h \ + video_encoder.h videotext.h vt.h wavefront.h wireless.h xattr.h \ + x25.h zorro_ids.h unifdef-y += acct.h adb.h adfs_fs.h agpgart.h apm_bios.h atalk.h \ atmarp.h atmdev.h atm.h atm_tcp.h audit.h auto_fs.h binfmts.h \ capability.h capi.h cciss_ioctl.h cdrom.h cm4000_cs.h \ cn_proc.h coda.h connector.h cramfs_fs.h cuda.h cyclades.h \ - dccp.h dirent.h divert.h elfcore.h errno.h errqueue.h \ + dccp.h dirent.h divert.h dlm.h elfcore.h errno.h errqueue.h \ ethtool.h eventpoll.h ext2_fs.h ext3_fs.h fb.h fcntl.h \ filter.h flat.h fs.h ftape.h gameport.h generic_serial.h \ - genhd.h hayesesp.h hdlcdrv.h hdlc.h hdreg.h hiddev.h hpet.h \ - i2c.h i2o-dev.h icmpv6.h if_bridge.h if_ec.h \ - if_eql.h if_ether.h if_frad.h if_ltalk.h if_pppox.h \ + genhd.h gfs2_ondisk.h hayesesp.h hdlcdrv.h hdlc.h hdreg.h \ + hiddev.h hpet.h i2c.h i2o-dev.h icmpv6.h iflags.h if_bridge.h \ + if_ec.h if_eql.h if_ether.h if_frad.h if_ltalk.h if_pppox.h \ if_shaper.h if_tr.h if_tun.h if_vlan.h if_wanpipe.h igmp.h \ inet_diag.h in.h inotify.h input.h ipc.h ipmi.h ipv6.h \ ipv6_route.h isdn.h isdnif.h isdn_ppp.h isicom.h jbd.h \ From fd4de2d41a9de2d949b0850d637aa84616f87ab8 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 5 Jul 2006 13:14:59 -0400 Subject: [PATCH 153/292] [GFS2] Add cast for printk Cast a uint64_t to unsigned long long for a printk. Signed-off-by: Steven Whitehouse --- fs/gfs2/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 483d4fa987f6..1596e9436c42 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -214,7 +214,7 @@ static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, &new, &dbn, &bdy); if (!(!error && dbn)) { - printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, dbn, lbn); + printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, (unsigned long long)dbn, lbn); } gfs2_assert_withdraw(sdp, !error && dbn); From 627add2d1385394d020c84533c91ad26bc37b166 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 5 Jul 2006 13:16:19 -0400 Subject: [PATCH 154/292] [GFS2] Correct logic in glock scanner Under certain circumstances the glock scanning logic would demote locks which ought not to have been selected for demotion. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index dbeb4ad836bd..7f362d0c3f7a 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1967,8 +1967,11 @@ static void scan_glock(struct gfs2_glock *gl) if (gfs2_glmutex_trylock(gl)) { if (gl->gl_ops == &gfs2_inode_glops) { struct gfs2_inode *ip = gl->gl_object; - if (ip) + if (ip == NULL) { + struct gfs2_sbd *sdp = gl->gl_sbd; + gfs2_assert_withdraw(sdp, gl->gl_state == LM_ST_UNLOCKED); goto out_schedule; + } } if (queue_empty(gl, &gl->gl_holders) && gl->gl_state != LM_ST_UNLOCKED && @@ -1982,7 +1985,7 @@ static void scan_glock(struct gfs2_glock *gl) return; - out_schedule: +out_schedule: gfs2_glmutex_unlock(gl); gfs2_glock_schedule_for_reclaim(gl); gfs2_glock_put(gl); From 29937ac6caa68d60c7f1a3e07b6137cf53e09e24 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 6 Jul 2006 17:58:03 -0400 Subject: [PATCH 155/292] [GFS2] Fixes to scanning of glocks (again) This really is the correct fix this time. We just ignore all glocks associated with inodes until the inodes are pushed from the inode cache. At that point the glocks are queued for reclaim, so we don't need to do it here. Also fix one or two other minor bugs. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 12 +++--------- fs/gfs2/inode.c | 2 ++ fs/gfs2/ops_inode.c | 1 + fs/gfs2/page.c | 3 +-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 7f362d0c3f7a..0381d4cc4146 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1965,19 +1965,13 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, static void scan_glock(struct gfs2_glock *gl) { if (gfs2_glmutex_trylock(gl)) { - if (gl->gl_ops == &gfs2_inode_glops) { - struct gfs2_inode *ip = gl->gl_object; - if (ip == NULL) { - struct gfs2_sbd *sdp = gl->gl_sbd; - gfs2_assert_withdraw(sdp, gl->gl_state == LM_ST_UNLOCKED); - goto out_schedule; - } - } + if (gl->gl_ops == &gfs2_inode_glops) + goto out; if (queue_empty(gl, &gl->gl_holders) && gl->gl_state != LM_ST_UNLOCKED && demote_ok(gl)) goto out_schedule; - +out: gfs2_glmutex_unlock(gl); } diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 6499c4f91078..f4c48395208a 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -325,6 +325,7 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) uint32_t nlink; int error; + BUG_ON(ip->i_di.di_nlink != ip->i_inode.i_nlink); nlink = ip->i_di.di_nlink + diff; /* If we are reducing the nlink count, but the new value ends up being @@ -341,6 +342,7 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) ip->i_di.di_nlink = nlink; ip->i_di.di_ctime = get_seconds(); + ip->i_inode.i_nlink = nlink; gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 8895baafc640..caecafe0469b 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -250,6 +250,7 @@ out: gfs2_holder_uninit(ghs + 1); if (!error) { + atomic_inc(&inode->i_count); d_instantiate(dentry, inode); mark_inode_dirty(inode); } diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c index a8165a693b56..b93caf294b9f 100644 --- a/fs/gfs2/page.c +++ b/fs/gfs2/page.c @@ -256,8 +256,7 @@ void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, struct buffer_head *bh; unsigned int start, end; - for (bh = head, start = 0; - bh != head || !start; + for (bh = head, start = 0; bh != head || !start; bh = bh->b_this_page, start = end) { end = start + bsize; if (end <= from || start >= to) From dc3e130a08996e2b56381365a5ac7bb1ce2a9f47 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 10 Jul 2006 11:19:29 -0400 Subject: [PATCH 156/292] [GFS2] Remove unused code from dir.c Remove a couple of commented out, and unused lines of code. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index b0353884dd7d..13d3709e0c0b 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -78,13 +78,8 @@ #define IS_LEAF 1 /* Hashed (leaf) directory */ #define IS_DINODE 2 /* Linear (stuffed dinode block) directory */ -#if 1 #define gfs2_disk_hash2offset(h) (((uint64_t)(h)) >> 1) #define gfs2_dir_offset2hash(p) ((uint32_t)(((uint64_t)(p)) << 1)) -#else -#define gfs2_disk_hash2offset(h) (((uint64_t)(h))) -#define gfs2_dir_offset2hash(p) ((uint32_t)(((uint64_t)(p)))) -#endif typedef int (*leaf_call_t) (struct gfs2_inode *dip, uint32_t index, uint32_t len, uint64_t leaf_no, From ffeb874b2b893aea7d10b0b088e06a7b1ded2a3e Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 10 Jul 2006 15:47:01 -0400 Subject: [PATCH 157/292] [GFS2] Bug fix to gfs2_readpages() This fixes a bug where we were releasing a page incorrectly sometimes when reading a stuffed file. This fixes the bug that Kevin reported when using Xen. Cc: Kevin Anderson Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 27ce30148e69..2c4ec5cf21ff 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -249,8 +249,6 @@ out_unlock: goto out; } -#define list_to_page(head) (list_entry((head)->prev, struct page, lru)) - /** * gfs2_readpages - Read a bunch of pages at once * @@ -290,7 +288,8 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping, struct pagevec lru_pvec; pagevec_init(&lru_pvec, 0); for (page_idx = 0; page_idx < nr_pages; page_idx++) { - struct page *page = list_to_page(pages); + struct page *page = list_entry(pages->prev, struct page, lru); + prefetchw(&page->flags); list_del(&page->lru); if (!add_to_page_cache(page, mapping, page->index, GFP_KERNEL)) { @@ -298,8 +297,9 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping, unlock_page(page); if (!pagevec_add(&lru_pvec, page)) __pagevec_lru_add(&lru_pvec); + } else { + page_cache_release(page); } - page_cache_release(page); } pagevec_lru_add(&lru_pvec); ret = 0; @@ -321,7 +321,7 @@ out_noerror: out_unlock: /* unlock all pages, we can't do any I/O right now */ for (page_idx = 0; page_idx < nr_pages; page_idx++) { - struct page *page = list_to_page(pages); + struct page *page = list_entry(pages->prev, struct page, lru); list_del(&page->lru); unlock_page(page); page_cache_release(page); From 4340fe62531f7d1dafb6f5359ffe0378bdb0db80 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 11 Jul 2006 09:46:33 -0400 Subject: [PATCH 158/292] [GFS2] Add generation number This adds a generation number for the eventual use of NFS to the ondisk inode. Its backward compatible with the current code since it doesn't really matter what the generation number is to start with, and indeed since its set to zero, due to it being taken from padding in both the inode and rgrp header, it should be fine. The eventual plan is to use this rather than no_formal_ino in the NFS filehandles. At that point no_formal_ino will be unused. At the same time we also add a releasepages call back to the "normal" address space for gfs2 inodes. Also I've removed a one-linrer function thats not required any more. Signed-off-by: Steven Whitehouse --- fs/gfs2/inode.c | 46 +++++++-------- fs/gfs2/meta_io.c | 112 +----------------------------------- fs/gfs2/ondisk.c | 6 +- fs/gfs2/ops_address.c | 111 +++++++++++++++++++++++++++++++++++ fs/gfs2/ops_address.h | 1 + fs/gfs2/ops_file.c | 2 +- fs/gfs2/rgrp.c | 12 ++-- fs/gfs2/rgrp.h | 6 +- include/linux/gfs2_ondisk.h | 6 +- 9 files changed, 153 insertions(+), 149 deletions(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index f4c48395208a..22ca3b5ddaea 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -38,15 +38,17 @@ #include "util.h" /** - * inode_attr_in - Copy attributes from the dinode into the VFS inode + * gfs2_inode_attr_in - Copy attributes from the dinode into the VFS inode * @ip: The GFS2 inode (with embedded disk inode data) * @inode: The Linux VFS inode * */ -static void inode_attr_in(struct gfs2_inode *ip, struct inode *inode) +void gfs2_inode_attr_in(struct gfs2_inode *ip) { - inode->i_ino = ip->i_num.no_formal_ino; + struct inode *inode = &ip->i_inode; + + inode->i_ino = ip->i_num.no_addr; switch (ip->i_di.di_mode & S_IFMT) { case S_IFBLK: @@ -84,18 +86,6 @@ static void inode_attr_in(struct gfs2_inode *ip, struct inode *inode) inode->i_flags &= ~S_APPEND; } -/** - * gfs2_inode_attr_in - Copy attributes from the dinode into the VFS inode - * @ip: The GFS2 inode (with embedded disk inode data) - * - */ - -void gfs2_inode_attr_in(struct gfs2_inode *ip) -{ - struct inode *inode = &ip->i_inode; - inode_attr_in(ip, inode); -} - /** * gfs2_inode_attr_out - Copy attributes from VFS inode into the dinode * @ip: The GFS2 inode @@ -621,7 +611,8 @@ static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, *gid = current->fsgid; } -static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_inum *inum) +static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_inum *inum, + u64 *generation) { struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); int error; @@ -637,14 +628,14 @@ static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_inum *inum) if (error) goto out_ipreserv; - inum->no_addr = gfs2_alloc_di(dip); + inum->no_addr = gfs2_alloc_di(dip, generation); gfs2_trans_end(sdp); - out_ipreserv: +out_ipreserv: gfs2_inplace_release(dip); - out: +out: gfs2_alloc_put(dip); return error; @@ -662,8 +653,9 @@ static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_inum *inum) */ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, - struct gfs2_inum *inum, unsigned int mode, - unsigned int uid, unsigned int gid) + const struct gfs2_inum *inum, unsigned int mode, + unsigned int uid, unsigned int gid, + const u64 *generation) { struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct gfs2_dinode *di; @@ -686,7 +678,7 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, di->di_atime = di->di_mtime = di->di_ctime = cpu_to_be64(get_seconds()); di->di_major = di->di_minor = cpu_to_be32(0); di->di_goal_meta = di->di_goal_data = cpu_to_be64(inum->no_addr); - di->__pad[0] = di->__pad[1] = 0; + di->di_generation = cpu_to_be64(*generation); di->di_flags = cpu_to_be32(0); if (S_ISREG(mode)) { @@ -717,7 +709,8 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, } static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, - unsigned int mode, struct gfs2_inum *inum) + unsigned int mode, const struct gfs2_inum *inum, + const u64 *generation) { struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); unsigned int uid, gid; @@ -738,7 +731,7 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, if (error) goto out_quota; - init_dinode(dip, gl, inum, mode, uid, gid); + init_dinode(dip, gl, inum, mode, uid, gid, generation); gfs2_quota_change(dip, +1, uid, gid); gfs2_trans_end(sdp); @@ -844,6 +837,7 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct gfs2_inum inum; int error; + u64 generation; if (!name->len || name->len > GFS2_FNAMESIZE) return ERR_PTR(-ENAMETOOLONG); @@ -861,7 +855,7 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, if (error) goto fail_gunlock; - error = alloc_dinode(dip, &inum); + error = alloc_dinode(dip, &inum, &generation); if (error) goto fail_gunlock; @@ -893,7 +887,7 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, goto fail_gunlock; } - error = make_dinode(dip, ghs[1].gh_gl, mode, &inum); + error = make_dinode(dip, ghs[1].gh_gl, mode, &inum, &generation); if (error) goto fail_gunlock2; diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index ddcd4dc1081d..cad44fd70d67 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -31,6 +31,7 @@ #include "rgrp.h" #include "trans.h" #include "util.h" +#include "ops_address.h" #define buffer_busy(bh) \ ((bh)->b_state & ((1ul << BH_Dirty) | (1ul << BH_Lock) | (1ul << BH_Pinned))) @@ -50,118 +51,9 @@ static int gfs2_aspace_writepage(struct page *page, return block_write_full_page(page, aspace_get_block, wbc); } -/** - * stuck_releasepage - We're stuck in gfs2_releasepage(). Print stuff out. - * @bh: the buffer we're stuck on - * - */ - -static void stuck_releasepage(struct buffer_head *bh) -{ - struct inode *inode = bh->b_page->mapping->host; - struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; - struct gfs2_bufdata *bd = bh->b_private; - struct gfs2_glock *gl; - - fs_warn(sdp, "stuck in gfs2_releasepage() %p\n", inode); - fs_warn(sdp, "blkno = %llu, bh->b_count = %d\n", - (unsigned long long)bh->b_blocknr, atomic_read(&bh->b_count)); - fs_warn(sdp, "pinned = %u\n", buffer_pinned(bh)); - fs_warn(sdp, "bh->b_private = %s\n", (bd) ? "!NULL" : "NULL"); - - if (!bd) - return; - - gl = bd->bd_gl; - - fs_warn(sdp, "gl = (%u, %llu)\n", - gl->gl_name.ln_type, (unsigned long long)gl->gl_name.ln_number); - - fs_warn(sdp, "bd_list_tr = %s, bd_le.le_list = %s\n", - (list_empty(&bd->bd_list_tr)) ? "no" : "yes", - (list_empty(&bd->bd_le.le_list)) ? "no" : "yes"); - - if (gl->gl_ops == &gfs2_inode_glops) { - struct gfs2_inode *ip = gl->gl_object; - unsigned int x; - - if (!ip) - return; - - fs_warn(sdp, "ip = %llu %llu\n", - (unsigned long long)ip->i_num.no_formal_ino, - (unsigned long long)ip->i_num.no_addr); - - for (x = 0; x < GFS2_MAX_META_HEIGHT; x++) - fs_warn(sdp, "ip->i_cache[%u] = %s\n", - x, (ip->i_cache[x]) ? "!NULL" : "NULL"); - } -} - -/** - * gfs2_aspace_releasepage - free the metadata associated with a page - * @page: the page that's being released - * @gfp_mask: passed from Linux VFS, ignored by us - * - * Call try_to_free_buffers() if the buffers in this page can be - * released. - * - * Returns: 0 - */ - -static int gfs2_aspace_releasepage(struct page *page, gfp_t gfp_mask) -{ - struct inode *aspace = page->mapping->host; - struct gfs2_sbd *sdp = aspace->i_sb->s_fs_info; - struct buffer_head *bh, *head; - struct gfs2_bufdata *bd; - unsigned long t; - - if (!page_has_buffers(page)) - goto out; - - head = bh = page_buffers(page); - do { - t = jiffies; - - while (atomic_read(&bh->b_count)) { - if (atomic_read(&aspace->i_writecount)) { - if (time_after_eq(jiffies, t + - gfs2_tune_get(sdp, gt_stall_secs) * HZ)) { - stuck_releasepage(bh); - t = jiffies; - } - - yield(); - continue; - } - - return 0; - } - - gfs2_assert_warn(sdp, !buffer_pinned(bh)); - - bd = bh->b_private; - if (bd) { - gfs2_assert_warn(sdp, bd->bd_bh == bh); - gfs2_assert_warn(sdp, list_empty(&bd->bd_list_tr)); - gfs2_assert_warn(sdp, list_empty(&bd->bd_le.le_list)); - gfs2_assert_warn(sdp, !bd->bd_ail); - kmem_cache_free(gfs2_bufdata_cachep, bd); - bh->b_private = NULL; - } - - bh = bh->b_this_page; - } - while (bh != head); - - out: - return try_to_free_buffers(page); -} - static const struct address_space_operations aspace_aops = { .writepage = gfs2_aspace_writepage, - .releasepage = gfs2_aspace_releasepage, + .releasepage = gfs2_releasepage, }; /** diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index 09154ad7b270..39c7f0345fc6 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -128,6 +128,7 @@ void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf) rg->rg_flags = be32_to_cpu(str->rg_flags); rg->rg_free = be32_to_cpu(str->rg_free); rg->rg_dinodes = be32_to_cpu(str->rg_dinodes); + rg->rg_igeneration = be64_to_cpu(str->rg_igeneration); } void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf) @@ -138,7 +139,8 @@ void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf) str->rg_flags = cpu_to_be32(rg->rg_flags); str->rg_free = cpu_to_be32(rg->rg_free); str->rg_dinodes = cpu_to_be32(rg->rg_dinodes); - + str->__pad = cpu_to_be32(0); + str->rg_igeneration = cpu_to_be64(rg->rg_igeneration); memset(&str->rg_reserved, 0, sizeof(str->rg_reserved)); } @@ -172,6 +174,7 @@ void gfs2_dinode_in(struct gfs2_dinode *di, char *buf) di->di_goal_meta = be64_to_cpu(str->di_goal_meta); di->di_goal_data = be64_to_cpu(str->di_goal_data); + di->di_generation = be64_to_cpu(str->di_generation); di->di_flags = be32_to_cpu(str->di_flags); di->di_payload_format = be32_to_cpu(str->di_payload_format); @@ -205,6 +208,7 @@ void gfs2_dinode_out(struct gfs2_dinode *di, char *buf) str->di_goal_meta = cpu_to_be64(di->di_goal_meta); str->di_goal_data = cpu_to_be64(di->di_goal_data); + str->di_generation = cpu_to_be64(di->di_generation); str->di_flags = cpu_to_be32(di->di_flags); str->di_payload_format = cpu_to_be32(di->di_payload_format); diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 2c4ec5cf21ff..031270ad55e2 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -33,6 +33,7 @@ #include "rgrp.h" #include "ops_file.h" #include "util.h" +#include "glops.h" /** * gfs2_get_block - Fills in a buffer head with details about a block @@ -659,6 +660,115 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, return ret; } +/** + * stuck_releasepage - We're stuck in gfs2_releasepage(). Print stuff out. + * @bh: the buffer we're stuck on + * + */ + +static void stuck_releasepage(struct buffer_head *bh) +{ + struct inode *inode = bh->b_page->mapping->host; + struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; + struct gfs2_bufdata *bd = bh->b_private; + struct gfs2_glock *gl; + + fs_warn(sdp, "stuck in gfs2_releasepage() %p\n", inode); + fs_warn(sdp, "blkno = %llu, bh->b_count = %d\n", + (unsigned long long)bh->b_blocknr, atomic_read(&bh->b_count)); + fs_warn(sdp, "pinned = %u\n", buffer_pinned(bh)); + fs_warn(sdp, "bh->b_private = %s\n", (bd) ? "!NULL" : "NULL"); + + if (!bd) + return; + + gl = bd->bd_gl; + + fs_warn(sdp, "gl = (%u, %llu)\n", + gl->gl_name.ln_type, (unsigned long long)gl->gl_name.ln_number); + + fs_warn(sdp, "bd_list_tr = %s, bd_le.le_list = %s\n", + (list_empty(&bd->bd_list_tr)) ? "no" : "yes", + (list_empty(&bd->bd_le.le_list)) ? "no" : "yes"); + + if (gl->gl_ops == &gfs2_inode_glops) { + struct gfs2_inode *ip = gl->gl_object; + unsigned int x; + + if (!ip) + return; + + fs_warn(sdp, "ip = %llu %llu\n", + (unsigned long long)ip->i_num.no_formal_ino, + (unsigned long long)ip->i_num.no_addr); + + for (x = 0; x < GFS2_MAX_META_HEIGHT; x++) + fs_warn(sdp, "ip->i_cache[%u] = %s\n", + x, (ip->i_cache[x]) ? "!NULL" : "NULL"); + } +} + +/** + * gfs2_aspace_releasepage - free the metadata associated with a page + * @page: the page that's being released + * @gfp_mask: passed from Linux VFS, ignored by us + * + * Call try_to_free_buffers() if the buffers in this page can be + * released. + * + * Returns: 0 + */ + +int gfs2_releasepage(struct page *page, gfp_t gfp_mask) +{ + struct inode *aspace = page->mapping->host; + struct gfs2_sbd *sdp = aspace->i_sb->s_fs_info; + struct buffer_head *bh, *head; + struct gfs2_bufdata *bd; + unsigned long t; + + if (!page_has_buffers(page)) + goto out; + + head = bh = page_buffers(page); + do { + t = jiffies; + + while (atomic_read(&bh->b_count)) { + if (atomic_read(&aspace->i_writecount)) { + if (time_after_eq(jiffies, t + + gfs2_tune_get(sdp, gt_stall_secs) * HZ)) { + stuck_releasepage(bh); + t = jiffies; + } + + yield(); + continue; + } + + return 0; + } + + gfs2_assert_warn(sdp, !buffer_pinned(bh)); + + bd = bh->b_private; + if (bd) { + gfs2_assert_warn(sdp, bd->bd_bh == bh); + gfs2_assert_warn(sdp, list_empty(&bd->bd_list_tr)); + gfs2_assert_warn(sdp, list_empty(&bd->bd_le.le_list)); + gfs2_assert_warn(sdp, !bd->bd_ail); + kmem_cache_free(gfs2_bufdata_cachep, bd); + bh->b_private = NULL; + } + + bh = bh->b_this_page; + } + while (bh != head); + + out: + return try_to_free_buffers(page); +} + const struct address_space_operations gfs2_file_aops = { .writepage = gfs2_writepage, .readpage = gfs2_readpage, @@ -668,6 +778,7 @@ const struct address_space_operations gfs2_file_aops = { .commit_write = gfs2_commit_write, .bmap = gfs2_bmap, .invalidatepage = gfs2_invalidatepage, + .releasepage = gfs2_releasepage, .direct_IO = gfs2_direct_IO, }; diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h index a7ef3bf36f3e..dfc3dda6de11 100644 --- a/fs/gfs2/ops_address.h +++ b/fs/gfs2/ops_address.h @@ -13,5 +13,6 @@ extern const struct address_space_operations gfs2_file_aops; extern int gfs2_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create); +extern int gfs2_releasepage(struct page *page, gfp_t gfp_mask); #endif /* __OPS_ADDRESS_DOT_H__ */ diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index c8e2c98700a7..26f1d3249b0f 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -333,7 +333,7 @@ static int filldir_reg_func(void *opaque, const char *name, unsigned int length, int error; error = fdr->fdr_filldir(fdr->fdr_opaque, name, length, offset, - inum->no_formal_ino, type); + inum->no_addr, type); if (error) return 1; diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 14c1f88bfb5d..65eea0b88bf7 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -1205,7 +1205,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, uint64_t bstart, * Returns: the allocated block */ -uint64_t gfs2_alloc_data(struct gfs2_inode *ip) +u64 gfs2_alloc_data(struct gfs2_inode *ip) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; @@ -1249,7 +1249,7 @@ uint64_t gfs2_alloc_data(struct gfs2_inode *ip) * Returns: the allocated block */ -uint64_t gfs2_alloc_meta(struct gfs2_inode *ip) +u64 gfs2_alloc_meta(struct gfs2_inode *ip) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; @@ -1294,13 +1294,13 @@ uint64_t gfs2_alloc_meta(struct gfs2_inode *ip) * Returns: the block allocated */ -uint64_t gfs2_alloc_di(struct gfs2_inode *dip) +u64 gfs2_alloc_di(struct gfs2_inode *dip, u64 *generation) { struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct gfs2_alloc *al = &dip->i_alloc; struct gfs2_rgrpd *rgd = al->al_rgd; - uint32_t blk; - uint64_t block; + u32 blk; + u64 block; blk = rgblk_search(rgd, rgd->rd_last_alloc_meta, GFS2_BLKST_FREE, GFS2_BLKST_DINODE); @@ -1312,7 +1312,7 @@ uint64_t gfs2_alloc_di(struct gfs2_inode *dip) gfs2_assert_withdraw(sdp, rgd->rd_rg.rg_free); rgd->rd_rg.rg_free--; rgd->rd_rg.rg_dinodes++; - + *generation = rgd->rd_rg.rg_igeneration++; gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data); diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h index 9c42d2252ddd..14600944d184 100644 --- a/fs/gfs2/rgrp.h +++ b/fs/gfs2/rgrp.h @@ -37,9 +37,9 @@ void gfs2_inplace_release(struct gfs2_inode *ip); unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, uint64_t block); -uint64_t gfs2_alloc_data(struct gfs2_inode *ip); -uint64_t gfs2_alloc_meta(struct gfs2_inode *ip); -uint64_t gfs2_alloc_di(struct gfs2_inode *ip); +u64 gfs2_alloc_data(struct gfs2_inode *ip); +u64 gfs2_alloc_meta(struct gfs2_inode *ip); +u64 gfs2_alloc_di(struct gfs2_inode *ip, u64 *generation); void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index 1181da831939..3ebd8743ce8c 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -170,8 +170,10 @@ struct gfs2_rgrp { __be32 rg_flags; __be32 rg_free; __be32 rg_dinodes; + __be32 __pad; + __be64 rg_igeneration; - __u8 rg_reserved[92]; /* Several fields from gfs1 now reserved */ + __u8 rg_reserved[80]; /* Several fields from gfs1 now reserved */ }; /* @@ -248,7 +250,7 @@ struct gfs2_dinode { */ __be64 di_goal_meta; /* rgrp to alloc from next */ __be64 di_goal_data; /* data block goal */ - __u32 __pad[2]; + __be64 di_generation; /* generation number for NFS */ __be32 di_flags; /* GFS2_DIF_... */ __be32 di_payload_format; /* GFS2_FORMAT_... */ From f3bba03fd16e25a262323293e5a07dea173c89f7 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 11 Jul 2006 09:50:54 -0400 Subject: [PATCH 159/292] [GFS2] Fix deadlock in memory allocation We must not call GFP_KERNEL memory allocations while we are holding the log lock (read or write) since that may trigger a log flush resulting in a deadlock. Eventually we need to fix the locking in log.c, for now this solves the problem at the expense of freeing up memory as fast as we would like to. This needs to be revisited later on. Cc: Kevin Anderson Signed-off-by: Steven Whitehouse --- fs/gfs2/meta_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index cad44fd70d67..42dfd32059bc 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -75,7 +75,7 @@ struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp) aspace = new_inode(sdp->sd_vfs); if (aspace) { - mapping_set_gfp_mask(aspace->i_mapping, GFP_KERNEL); + mapping_set_gfp_mask(aspace->i_mapping, GFP_NOFS); aspace->i_mapping->a_ops = &aspace_aops; aspace->i_size = ~0ULL; aspace->u.generic_ip = NULL; From b2a580d87b33816aa9b50268f70666368e12f7df Mon Sep 17 00:00:00 2001 From: Abhijith Das Date: Mon, 10 Jul 2006 12:36:12 -0500 Subject: [PATCH 160/292] [PATCH] patch to init di_payload_format field in gfs2_dinode A missing initialisation when creating a new on disk inode. Signed-off-by: Abhijith Das Signed-off-by: Steven Whitehouse --- fs/gfs2/inode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 22ca3b5ddaea..e76f345517b7 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -696,6 +696,7 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, } di->__pad1 = 0; + di->di_payload_format = cpu_to_be32(0); di->di_height = cpu_to_be32(0); di->__pad2 = 0; di->__pad3 = 0; From 4da3c6463ef6759fb50d12c8652bc29c5c1730a4 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 11 Jul 2006 13:19:13 -0400 Subject: [PATCH 161/292] [GFS2] Fix a coupls of warnings in dir.c Fix a couple of compiler warnings in dir.c caused by potentially uninitialised variables. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 13d3709e0c0b..e96b5322c843 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -936,7 +936,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) struct gfs2_inode *dip = GFS2_I(inode); struct buffer_head *nbh, *obh, *dibh; struct gfs2_leaf *nleaf, *oleaf; - struct gfs2_dirent *dent, *prev = NULL, *next = NULL, *new; + struct gfs2_dirent *dent = NULL, *prev = NULL, *next = NULL, *new; uint32_t start, len, half_len, divider; uint64_t bn, *lp, leaf_no; uint32_t index; @@ -1356,7 +1356,7 @@ static int dir_e_read(struct inode *inode, uint64_t *offset, void *opaque, uint64_t *lp; int copied = 0; int error = 0; - unsigned depth; + unsigned depth = 0; hsize = 1 << dip->i_di.di_depth; if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { From 2eb168ca94aba3bcae350ad9b31870955174a218 Mon Sep 17 00:00:00 2001 From: Wendy Cheng Date: Tue, 11 Jul 2006 13:28:53 -0400 Subject: [PATCH 162/292] [GFS2] NFS update Update the NFS filehandles so that they contain the file type. Signed-off-by: Wendy Cheng Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_export.c | 32 ++++++++++++++++++++------------ fs/gfs2/ops_export.h | 4 ++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index eacc1c092f91..6354f4799e68 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -34,30 +34,34 @@ static struct dentry *gfs2_decode_fh(struct super_block *sb, struct dentry *dentry), void *context) { - struct gfs2_inum this, parent; + struct gfs2_fh_obj fh_obj; + struct gfs2_inum *this, parent; if (fh_type != fh_len) return NULL; + this = &fh_obj.this; + fh_obj.imode = DT_UNKNOWN; memset(&parent, 0, sizeof(struct gfs2_inum)); switch (fh_type) { - case 8: + case 10: parent.no_formal_ino = ((uint64_t)be32_to_cpu(fh[4])) << 32; parent.no_formal_ino |= be32_to_cpu(fh[5]); parent.no_addr = ((uint64_t)be32_to_cpu(fh[6])) << 32; parent.no_addr |= be32_to_cpu(fh[7]); + fh_obj.imode = be32_to_cpu(fh[8]); case 4: - this.no_formal_ino = ((uint64_t)be32_to_cpu(fh[0])) << 32; - this.no_formal_ino |= be32_to_cpu(fh[1]); - this.no_addr = ((uint64_t)be32_to_cpu(fh[2])) << 32; - this.no_addr |= be32_to_cpu(fh[3]); + this->no_formal_ino = ((uint64_t)be32_to_cpu(fh[0])) << 32; + this->no_formal_ino |= be32_to_cpu(fh[1]); + this->no_addr = ((uint64_t)be32_to_cpu(fh[2])) << 32; + this->no_addr |= be32_to_cpu(fh[3]); break; default: return NULL; } - return gfs2_export_ops.find_exported_dentry(sb, &this, &parent, + return gfs2_export_ops.find_exported_dentry(sb, &fh_obj, &parent, acceptable, context); } @@ -68,7 +72,7 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, struct super_block *sb = inode->i_sb; struct gfs2_inode *ip = GFS2_I(inode); - if (*len < 4 || (connectable && *len < 8)) + if (*len < 4 || (connectable && *len < 10)) return 255; fh[0] = ip->i_num.no_formal_ino >> 32; @@ -98,7 +102,10 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, fh[6] = cpu_to_be32(fh[6]); fh[7] = ip->i_num.no_addr & 0xFFFFFFFF; fh[7] = cpu_to_be32(fh[7]); - *len = 8; + + fh[8] = cpu_to_be32(inode->i_mode); + fh[9] = 0; /* pad to double word */ + *len = 10; iput(inode); @@ -186,10 +193,11 @@ static struct dentry *gfs2_get_parent(struct dentry *child) return dentry; } -static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) +static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_obj) { struct gfs2_sbd *sdp = sb->s_fs_info; - struct gfs2_inum *inum = inum_p; + struct gfs2_fh_obj *fh_obj = (struct gfs2_fh_obj *)inum_obj; + struct gfs2_inum *inum = &fh_obj->this; struct gfs2_holder i_gh, ri_gh, rgd_gh; struct gfs2_rgrpd *rgd; struct inode *inode; @@ -233,7 +241,7 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) gfs2_glock_dq_uninit(&rgd_gh); gfs2_glock_dq_uninit(&ri_gh); - inode = gfs2_inode_lookup(sb, inum, DT_UNKNOWN); + inode = gfs2_inode_lookup(sb, inum, fh_obj->imode); if (!inode) goto fail; if (IS_ERR(inode)) { diff --git a/fs/gfs2/ops_export.h b/fs/gfs2/ops_export.h index 88d58e57f518..09fc077657d1 100644 --- a/fs/gfs2/ops_export.h +++ b/fs/gfs2/ops_export.h @@ -11,5 +11,9 @@ #define __OPS_EXPORT_DOT_H__ extern struct export_operations gfs2_export_ops; +struct gfs2_fh_obj { + struct gfs2_inum this; + __u32 imode; +}; #endif /* __OPS_EXPORT_DOT_H__ */ From 597d0cae0f99f62501e229bed50e8149604015bb Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 12 Jul 2006 16:44:04 -0500 Subject: [PATCH 163/292] [DLM] dlm: user locks This changes the way the dlm handles user locks. The core dlm is now aware of user locks so they can be dealt with more efficiently. There is no more dlm_device module which previously managed its own duplicate copy of every user lock. Signed-off-by: Patrick Caulfield Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/Kconfig | 8 - fs/dlm/Makefile | 4 +- fs/dlm/ast.c | 7 +- fs/dlm/device.c | 1239 ----------------------------------------- fs/dlm/dlm_internal.h | 44 ++ fs/dlm/lock.c | 304 +++++++++- fs/dlm/lock.h | 11 + fs/dlm/lockspace.c | 32 +- fs/dlm/lockspace.h | 1 + fs/dlm/main.c | 8 + fs/dlm/memory.c | 9 + fs/dlm/user.c | 769 +++++++++++++++++++++++++ fs/dlm/user.h | 16 + 13 files changed, 1192 insertions(+), 1260 deletions(-) delete mode 100644 fs/dlm/device.c create mode 100644 fs/dlm/user.c create mode 100644 fs/dlm/user.h diff --git a/fs/dlm/Kconfig b/fs/dlm/Kconfig index 09e78bf6e7a4..490f85b3fa59 100644 --- a/fs/dlm/Kconfig +++ b/fs/dlm/Kconfig @@ -10,14 +10,6 @@ config DLM A general purpose distributed lock manager for kernel or userspace applications. -config DLM_DEVICE - tristate "DLM device for userspace access" - depends on DLM - help - This module creates a misc device through which the dlm lockspace - and locking functions become available to userspace applications - (usually through the libdlm library). - config DLM_DEBUG bool "DLM debugging" depends on DLM diff --git a/fs/dlm/Makefile b/fs/dlm/Makefile index 1e6232e7d8e5..1832e0297f7d 100644 --- a/fs/dlm/Makefile +++ b/fs/dlm/Makefile @@ -1,6 +1,4 @@ obj-$(CONFIG_DLM) += dlm.o -obj-$(CONFIG_DLM_DEVICE) += dlm_device.o - dlm-y := ast.o \ config.o \ dir.o \ @@ -15,7 +13,7 @@ dlm-y := ast.o \ recover.o \ recoverd.o \ requestqueue.o \ + user.o \ util.o dlm-$(CONFIG_DLM_DEBUG) += debug_fs.o -dlm_device-y := device.o diff --git a/fs/dlm/ast.c b/fs/dlm/ast.c index 57bdf09b520a..a211330cbc42 100644 --- a/fs/dlm/ast.c +++ b/fs/dlm/ast.c @@ -13,7 +13,7 @@ #include "dlm_internal.h" #include "lock.h" -#include "ast.h" +#include "user.h" #define WAKE_ASTS 0 @@ -34,6 +34,11 @@ void dlm_del_ast(struct dlm_lkb *lkb) void dlm_add_ast(struct dlm_lkb *lkb, int type) { + if (lkb->lkb_flags & DLM_IFL_USER) { + dlm_user_add_ast(lkb, type); + return; + } + spin_lock(&ast_queue_lock); if (!(lkb->lkb_ast_type & (AST_COMP | AST_BAST))) { kref_get(&lkb->lkb_ref); diff --git a/fs/dlm/device.c b/fs/dlm/device.c deleted file mode 100644 index 825bbc0a09c0..000000000000 --- a/fs/dlm/device.c +++ /dev/null @@ -1,1239 +0,0 @@ -/****************************************************************************** -******************************************************************************* -** -** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. -** -** This copyrighted material is made available to anyone wishing to use, -** modify, copy, or redistribute it subject to the terms and conditions -** of the GNU General Public License v.2. -** -******************************************************************************* -******************************************************************************/ - -/* - * device.c - * - * This is the userland interface to the DLM. - * - * The locking is done via a misc char device (find the - * registered minor number in /proc/misc). - * - * User code should not use this interface directly but - * call the library routines in libdlm.a instead. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "lvb_table.h" - -static struct file_operations _dlm_fops; -static const char *name_prefix="dlm"; -static struct list_head user_ls_list; -static struct mutex user_ls_lock; - -/* Flags in li_flags */ -#define LI_FLAG_COMPLETE 1 -#define LI_FLAG_FIRSTLOCK 2 -#define LI_FLAG_PERSISTENT 3 -#define LI_FLAG_ONLIST 4 - -/* flags in ls_flags*/ -#define LS_FLAG_DELETED 1 -#define LS_FLAG_AUTOFREE 2 - -/* flags in ls_flags*/ -#define FI_FLAG_OPEN 1 -#define FI_FLAG_COMPAT 2 - -#define LOCKINFO_MAGIC 0x53595324 - -struct lock_info { - uint32_t li_magic; - uint8_t li_cmd; - int8_t li_grmode; - int8_t li_rqmode; - struct dlm_lksb li_lksb; - wait_queue_head_t li_waitq; - unsigned long li_flags; - void __user *li_castparam; - void __user *li_castaddr; - void __user *li_bastparam; - void __user *li_bastaddr; - void __user *li_pend_bastparam; - void __user *li_pend_bastaddr; - struct list_head li_ownerqueue; - struct file_info *li_file; - struct dlm_lksb __user *li_user_lksb; - struct completion li_firstcomp; -}; - -/* A queued AST no less */ -struct ast_info { - struct dlm_lock_result result; - struct list_head list; - uint32_t lvb_updated; - uint32_t progress; /* How much has been read */ -}; - -/* One of these per userland lockspace */ -struct user_ls { - void *ls_lockspace; - atomic_t ls_refcnt; - long ls_flags; - - /* Lock infos are stored in here indexed by lock ID */ - struct idr lockinfo_idr; - rwlock_t lockinfo_lock; - - /* Passed into misc_register() */ - struct miscdevice ls_miscinfo; - struct list_head ls_list; -}; - -/* misc_device info for the control device */ -static struct miscdevice ctl_device; - -/* - * Stuff we hang off the file struct. - * The first two are to cope with unlocking all the - * locks help by a process when it dies. - */ -struct file_info { - struct list_head fi_li_list; /* List of active lock_infos */ - spinlock_t fi_li_lock; - struct list_head fi_ast_list; /* Queue of ASTs to be delivered */ - spinlock_t fi_ast_lock; - wait_queue_head_t fi_wait; - struct user_ls *fi_ls; - atomic_t fi_refcnt; /* Number of users */ - unsigned long fi_flags; -}; - -#ifdef CONFIG_COMPAT - -struct dlm_lock_params32 { - __u8 mode; - __u8 namelen; - __u16 flags; - __u32 lkid; - __u32 parent; - - __u32 castparam; - __u32 castaddr; - __u32 bastparam; - __u32 bastaddr; - __u32 lksb; - - char lvb[DLM_USER_LVB_LEN]; - char name[0]; -}; - -struct dlm_write_request32 { - __u32 version[3]; - __u8 cmd; - __u8 is64bit; - __u8 unused[2]; - - union { - struct dlm_lock_params32 lock; - struct dlm_lspace_params lspace; - } i; -}; - -struct dlm_lksb32 { - __u32 sb_status; - __u32 sb_lkid; - __u8 sb_flags; - __u32 sb_lvbptr; -}; - -struct dlm_lock_result32 { - __u32 length; - __u32 user_astaddr; - __u32 user_astparam; - __u32 user_lksb; - struct dlm_lksb32 lksb; - __u8 bast_mode; - __u8 unused[3]; - /* Offsets may be zero if no data is present */ - __u32 lvb_offset; -}; - - -static void compat_input(struct dlm_write_request *kparams, struct dlm_write_request32 *k32params) -{ - - kparams->version[0] = k32params->version[0]; - kparams->version[1] = k32params->version[1]; - kparams->version[2] = k32params->version[2]; - - kparams->cmd = k32params->cmd; - kparams->is64bit = k32params->is64bit; - if (kparams->cmd == DLM_USER_CREATE_LOCKSPACE || - kparams->cmd == DLM_USER_REMOVE_LOCKSPACE) { - - kparams->i.lspace.flags = k32params->i.lspace.flags; - kparams->i.lspace.minor = k32params->i.lspace.minor; - strcpy(kparams->i.lspace.name, k32params->i.lspace.name); - } - else { - kparams->i.lock.mode = k32params->i.lock.mode; - kparams->i.lock.namelen = k32params->i.lock.namelen; - kparams->i.lock.flags = k32params->i.lock.flags; - kparams->i.lock.lkid = k32params->i.lock.lkid; - kparams->i.lock.parent = k32params->i.lock.parent; - kparams->i.lock.castparam = (void *)(long)k32params->i.lock.castparam; - kparams->i.lock.castaddr = (void *)(long)k32params->i.lock.castaddr; - kparams->i.lock.bastparam = (void *)(long)k32params->i.lock.bastparam; - kparams->i.lock.bastaddr = (void *)(long)k32params->i.lock.bastaddr; - kparams->i.lock.lksb = (void *)(long)k32params->i.lock.lksb; - memcpy(kparams->i.lock.lvb, k32params->i.lock.lvb, DLM_USER_LVB_LEN); - memcpy(kparams->i.lock.name, k32params->i.lock.name, kparams->i.lock.namelen); - } -} - -void compat_output(struct dlm_lock_result *res, struct dlm_lock_result32 *res32) -{ - res32->length = res->length - (sizeof(struct dlm_lock_result) - sizeof(struct dlm_lock_result32)); - res32->user_astaddr = (__u32)(long)res->user_astaddr; - res32->user_astparam = (__u32)(long)res->user_astparam; - res32->user_lksb = (__u32)(long)res->user_lksb; - res32->bast_mode = res->bast_mode; - - res32->lvb_offset = res->lvb_offset; - res32->length = res->length; - - res32->lksb.sb_status = res->lksb.sb_status; - res32->lksb.sb_flags = res->lksb.sb_flags; - res32->lksb.sb_lkid = res->lksb.sb_lkid; - res32->lksb.sb_lvbptr = (__u32)(long)res->lksb.sb_lvbptr; -} -#endif - - -/* get and put ops for file_info. - Actually I don't really like "get" and "put", but everyone - else seems to use them and I can't think of anything - nicer at the moment */ -static void get_file_info(struct file_info *f) -{ - atomic_inc(&f->fi_refcnt); -} - -static void put_file_info(struct file_info *f) -{ - if (atomic_dec_and_test(&f->fi_refcnt)) - kfree(f); -} - -static void release_lockinfo(struct user_ls *ls, struct lock_info *li) -{ - put_file_info(li->li_file); - - write_lock(&ls->lockinfo_lock); - idr_remove(&ls->lockinfo_idr, li->li_lksb.sb_lkid); - write_unlock(&ls->lockinfo_lock); - - if (li->li_lksb.sb_lvbptr) - kfree(li->li_lksb.sb_lvbptr); - kfree(li); - - module_put(THIS_MODULE); -} - -static struct lock_info *get_lockinfo(struct user_ls *ls, uint32_t lockid) -{ - struct lock_info *li; - - read_lock(&ls->lockinfo_lock); - li = idr_find(&ls->lockinfo_idr, lockid); - read_unlock(&ls->lockinfo_lock); - - return li; -} - -static int add_lockinfo(struct user_ls *ls, struct lock_info *li) -{ - int n; - int r; - int ret = -EINVAL; - - write_lock(&ls->lockinfo_lock); - - if (idr_find(&ls->lockinfo_idr, li->li_lksb.sb_lkid)) - goto out_up; - - ret = -ENOMEM; - r = idr_pre_get(&ls->lockinfo_idr, GFP_KERNEL); - if (!r) - goto out_up; - - r = idr_get_new_above(&ls->lockinfo_idr, li, li->li_lksb.sb_lkid, &n); - if (r) - goto out_up; - - if (n != li->li_lksb.sb_lkid) { - idr_remove(&ls->lockinfo_idr, n); - goto out_up; - } - - ret = 0; - - out_up: - write_unlock(&ls->lockinfo_lock); - - return ret; -} - - -static struct user_ls *__find_lockspace(int minor) -{ - struct user_ls *lsinfo; - - list_for_each_entry(lsinfo, &user_ls_list, ls_list) { - if (lsinfo->ls_miscinfo.minor == minor) - return lsinfo; - } - return NULL; -} - -/* Find a lockspace struct given the device minor number */ -static struct user_ls *find_lockspace(int minor) -{ - struct user_ls *lsinfo; - - mutex_lock(&user_ls_lock); - lsinfo = __find_lockspace(minor); - mutex_unlock(&user_ls_lock); - - return lsinfo; -} - -static void add_lockspace_to_list(struct user_ls *lsinfo) -{ - mutex_lock(&user_ls_lock); - list_add(&lsinfo->ls_list, &user_ls_list); - mutex_unlock(&user_ls_lock); -} - -/* Register a lockspace with the DLM and create a misc - device for userland to access it */ -static int register_lockspace(char *name, struct user_ls **ls, int flags) -{ - struct user_ls *newls; - int status; - int namelen; - - namelen = strlen(name)+strlen(name_prefix)+2; - - newls = kzalloc(sizeof(struct user_ls), GFP_KERNEL); - if (!newls) - return -ENOMEM; - - newls->ls_miscinfo.name = kzalloc(namelen, GFP_KERNEL); - if (!newls->ls_miscinfo.name) { - kfree(newls); - return -ENOMEM; - } - - status = dlm_new_lockspace(name, strlen(name), &newls->ls_lockspace, 0, - DLM_USER_LVB_LEN); - if (status != 0) { - kfree(newls->ls_miscinfo.name); - kfree(newls); - return status; - } - - idr_init(&newls->lockinfo_idr); - rwlock_init(&newls->lockinfo_lock); - - snprintf((char*)newls->ls_miscinfo.name, namelen, "%s_%s", - name_prefix, name); - - newls->ls_miscinfo.fops = &_dlm_fops; - newls->ls_miscinfo.minor = MISC_DYNAMIC_MINOR; - - status = misc_register(&newls->ls_miscinfo); - if (status) { - printk(KERN_ERR "dlm: misc register failed for %s\n", name); - dlm_release_lockspace(newls->ls_lockspace, 0); - kfree(newls->ls_miscinfo.name); - kfree(newls); - return status; - } - - if (flags & DLM_USER_LSFLG_AUTOFREE) - set_bit(LS_FLAG_AUTOFREE, &newls->ls_flags); - - add_lockspace_to_list(newls); - *ls = newls; - return 0; -} - -/* Called with the user_ls_lock mutex held */ -static int unregister_lockspace(struct user_ls *lsinfo, int force) -{ - int status; - - status = dlm_release_lockspace(lsinfo->ls_lockspace, force); - if (status) - return status; - - status = misc_deregister(&lsinfo->ls_miscinfo); - if (status) - return status; - - list_del(&lsinfo->ls_list); - set_bit(LS_FLAG_DELETED, &lsinfo->ls_flags); - lsinfo->ls_lockspace = NULL; - if (atomic_read(&lsinfo->ls_refcnt) == 0) { - kfree(lsinfo->ls_miscinfo.name); - kfree(lsinfo); - } - - return 0; -} - -/* Add it to userland's AST queue */ -static void add_to_astqueue(struct lock_info *li, void *astaddr, void *astparam, - int lvb_updated) -{ - struct ast_info *ast = kzalloc(sizeof(struct ast_info), GFP_KERNEL); - if (!ast) - return; - - ast->result.user_astparam = astparam; - ast->result.user_astaddr = astaddr; - ast->result.user_lksb = li->li_user_lksb; - memcpy(&ast->result.lksb, &li->li_lksb, sizeof(struct dlm_lksb)); - ast->lvb_updated = lvb_updated; - - spin_lock(&li->li_file->fi_ast_lock); - list_add_tail(&ast->list, &li->li_file->fi_ast_list); - spin_unlock(&li->li_file->fi_ast_lock); - wake_up_interruptible(&li->li_file->fi_wait); -} - -static void bast_routine(void *param, int mode) -{ - struct lock_info *li = param; - - if (li && li->li_bastaddr) - add_to_astqueue(li, li->li_bastaddr, li->li_bastparam, 0); -} - -/* - * This is the kernel's AST routine. - * All lock, unlock & query operations complete here. - * The only syncronous ops are those done during device close. - */ -static void ast_routine(void *param) -{ - struct lock_info *li = param; - - /* Param may be NULL if a persistent lock is unlocked by someone else */ - if (!li) - return; - - /* If this is a succesful conversion then activate the blocking ast - * args from the conversion request */ - if (!test_bit(LI_FLAG_FIRSTLOCK, &li->li_flags) && - li->li_lksb.sb_status == 0) { - - li->li_bastparam = li->li_pend_bastparam; - li->li_bastaddr = li->li_pend_bastaddr; - li->li_pend_bastaddr = NULL; - } - - /* If it's an async request then post data to the user's AST queue. */ - if (li->li_castaddr) { - int lvb_updated = 0; - - /* See if the lvb has been updated */ - if (dlm_lvb_operations[li->li_grmode+1][li->li_rqmode+1] == 1) - lvb_updated = 1; - - if (li->li_lksb.sb_status == 0) - li->li_grmode = li->li_rqmode; - - /* Only queue AST if the device is still open */ - if (test_bit(FI_FLAG_OPEN, &li->li_file->fi_flags)) - add_to_astqueue(li, li->li_castaddr, li->li_castparam, - lvb_updated); - - /* If it's a new lock operation that failed, then - * remove it from the owner queue and free the - * lock_info. - */ - if (test_and_clear_bit(LI_FLAG_FIRSTLOCK, &li->li_flags) && - li->li_lksb.sb_status != 0) { - - /* Wait till dlm_lock() has finished */ - wait_for_completion(&li->li_firstcomp); - - spin_lock(&li->li_file->fi_li_lock); - list_del(&li->li_ownerqueue); - clear_bit(LI_FLAG_ONLIST, &li->li_flags); - spin_unlock(&li->li_file->fi_li_lock); - release_lockinfo(li->li_file->fi_ls, li); - return; - } - /* Free unlocks & queries */ - if (li->li_lksb.sb_status == -DLM_EUNLOCK || - li->li_cmd == DLM_USER_QUERY) { - release_lockinfo(li->li_file->fi_ls, li); - } - } else { - /* Synchronous request, just wake up the caller */ - set_bit(LI_FLAG_COMPLETE, &li->li_flags); - wake_up_interruptible(&li->li_waitq); - } -} - -/* - * Wait for the lock op to complete and return the status. - */ -static int wait_for_ast(struct lock_info *li) -{ - /* Wait for the AST routine to complete */ - set_task_state(current, TASK_INTERRUPTIBLE); - while (!test_bit(LI_FLAG_COMPLETE, &li->li_flags)) - schedule(); - - set_task_state(current, TASK_RUNNING); - - return li->li_lksb.sb_status; -} - - -/* Open on control device */ -static int dlm_ctl_open(struct inode *inode, struct file *file) -{ - file->private_data = NULL; - return 0; -} - -/* Close on control device */ -static int dlm_ctl_close(struct inode *inode, struct file *file) -{ - return 0; -} - -/* Open on lockspace device */ -static int dlm_open(struct inode *inode, struct file *file) -{ - struct file_info *f; - struct user_ls *lsinfo; - - lsinfo = find_lockspace(iminor(inode)); - if (!lsinfo) - return -ENOENT; - - f = kzalloc(sizeof(struct file_info), GFP_KERNEL); - if (!f) - return -ENOMEM; - - atomic_inc(&lsinfo->ls_refcnt); - INIT_LIST_HEAD(&f->fi_li_list); - INIT_LIST_HEAD(&f->fi_ast_list); - spin_lock_init(&f->fi_li_lock); - spin_lock_init(&f->fi_ast_lock); - init_waitqueue_head(&f->fi_wait); - f->fi_ls = lsinfo; - f->fi_flags = 0; - get_file_info(f); - set_bit(FI_FLAG_OPEN, &f->fi_flags); - - file->private_data = f; - - return 0; -} - -/* Check the user's version matches ours */ -static int check_version(struct dlm_write_request *req) -{ - if (req->version[0] != DLM_DEVICE_VERSION_MAJOR || - (req->version[0] == DLM_DEVICE_VERSION_MAJOR && - req->version[1] > DLM_DEVICE_VERSION_MINOR)) { - - printk(KERN_DEBUG "dlm: process %s (%d) version mismatch " - "user (%d.%d.%d) kernel (%d.%d.%d)\n", - current->comm, - current->pid, - req->version[0], - req->version[1], - req->version[2], - DLM_DEVICE_VERSION_MAJOR, - DLM_DEVICE_VERSION_MINOR, - DLM_DEVICE_VERSION_PATCH); - return -EINVAL; - } - return 0; -} - -/* Close on lockspace device */ -static int dlm_close(struct inode *inode, struct file *file) -{ - struct file_info *f = file->private_data; - struct lock_info li; - struct lock_info *old_li, *safe; - sigset_t tmpsig; - sigset_t allsigs; - struct user_ls *lsinfo; - DECLARE_WAITQUEUE(wq, current); - - lsinfo = find_lockspace(iminor(inode)); - if (!lsinfo) - return -ENOENT; - - /* Mark this closed so that ASTs will not be delivered any more */ - clear_bit(FI_FLAG_OPEN, &f->fi_flags); - - /* Block signals while we are doing this */ - sigfillset(&allsigs); - sigprocmask(SIG_BLOCK, &allsigs, &tmpsig); - - /* We use our own lock_info struct here, so that any - * outstanding "real" ASTs will be delivered with the - * corresponding "real" params, thus freeing the lock_info - * that belongs the lock. This catches the corner case where - * a lock is BUSY when we try to unlock it here - */ - memset(&li, 0, sizeof(li)); - clear_bit(LI_FLAG_COMPLETE, &li.li_flags); - init_waitqueue_head(&li.li_waitq); - add_wait_queue(&li.li_waitq, &wq); - - /* - * Free any outstanding locks, they are on the - * list in LIFO order so there should be no problems - * about unlocking parents before children. - */ - list_for_each_entry_safe(old_li, safe, &f->fi_li_list, li_ownerqueue) { - int status; - int flags = 0; - - /* Don't unlock persistent locks, just mark them orphaned */ - if (test_bit(LI_FLAG_PERSISTENT, &old_li->li_flags)) { - list_del(&old_li->li_ownerqueue); - - /* Update master copy */ - /* TODO: Check locking core updates the local and - remote ORPHAN flags */ - li.li_lksb.sb_lkid = old_li->li_lksb.sb_lkid; - status = dlm_lock(f->fi_ls->ls_lockspace, - old_li->li_grmode, &li.li_lksb, - DLM_LKF_CONVERT|DLM_LKF_ORPHAN, - NULL, 0, 0, ast_routine, NULL, NULL); - if (status != 0) - printk("dlm: Error orphaning lock %x: %d\n", - old_li->li_lksb.sb_lkid, status); - - /* But tidy our references in it */ - release_lockinfo(old_li->li_file->fi_ls, old_li); - continue; - } - - clear_bit(LI_FLAG_COMPLETE, &li.li_flags); - - flags = DLM_LKF_FORCEUNLOCK; - if (old_li->li_grmode >= DLM_LOCK_PW) - flags |= DLM_LKF_IVVALBLK; - - status = dlm_unlock(f->fi_ls->ls_lockspace, - old_li->li_lksb.sb_lkid, flags, - &li.li_lksb, &li); - - /* Must wait for it to complete as the next lock could be its - * parent */ - if (status == 0) - wait_for_ast(&li); - - /* Unlock suceeded, free the lock_info struct. */ - if (status == 0) - release_lockinfo(old_li->li_file->fi_ls, old_li); - } - - remove_wait_queue(&li.li_waitq, &wq); - - /* - * If this is the last reference to the lockspace - * then free the struct. If it's an AUTOFREE lockspace - * then free the whole thing. - */ - mutex_lock(&user_ls_lock); - if (atomic_dec_and_test(&lsinfo->ls_refcnt)) { - - if (lsinfo->ls_lockspace) { - if (test_bit(LS_FLAG_AUTOFREE, &lsinfo->ls_flags)) { - unregister_lockspace(lsinfo, 1); - } - } else { - kfree(lsinfo->ls_miscinfo.name); - kfree(lsinfo); - } - } - mutex_unlock(&user_ls_lock); - put_file_info(f); - - /* Restore signals */ - sigprocmask(SIG_SETMASK, &tmpsig, NULL); - recalc_sigpending(); - - return 0; -} - -static int do_user_create_lockspace(struct file_info *fi, uint8_t cmd, - struct dlm_lspace_params *kparams) -{ - int status; - struct user_ls *lsinfo; - - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - status = register_lockspace(kparams->name, &lsinfo, kparams->flags); - - /* If it succeeded then return the minor number */ - if (status == 0) - status = lsinfo->ls_miscinfo.minor; - - return status; -} - -static int do_user_remove_lockspace(struct file_info *fi, uint8_t cmd, - struct dlm_lspace_params *kparams) -{ - int status; - int force = 1; - struct user_ls *lsinfo; - - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - mutex_lock(&user_ls_lock); - lsinfo = __find_lockspace(kparams->minor); - if (!lsinfo) { - mutex_unlock(&user_ls_lock); - return -EINVAL; - } - - if (kparams->flags & DLM_USER_LSFLG_FORCEFREE) - force = 3; - - status = unregister_lockspace(lsinfo, force); - mutex_unlock(&user_ls_lock); - - return status; -} - -/* Read call, might block if no ASTs are waiting. - * It will only ever return one message at a time, regardless - * of how many are pending. - */ -static ssize_t dlm_read(struct file *file, char __user *buffer, size_t count, - loff_t *ppos) -{ - struct file_info *fi = file->private_data; - struct ast_info *ast; - void *data; - int data_size; - int struct_size; - int offset; - DECLARE_WAITQUEUE(wait, current); -#ifdef CONFIG_COMPAT - struct dlm_lock_result32 result32; - - if (count < sizeof(struct dlm_lock_result32)) -#else - if (count < sizeof(struct dlm_lock_result)) -#endif - return -EINVAL; - - spin_lock(&fi->fi_ast_lock); - if (list_empty(&fi->fi_ast_list)) { - - /* No waiting ASTs. - * Return EOF if the lockspace been deleted. - */ - if (test_bit(LS_FLAG_DELETED, &fi->fi_ls->ls_flags)) - return 0; - - if (file->f_flags & O_NONBLOCK) { - spin_unlock(&fi->fi_ast_lock); - return -EAGAIN; - } - - add_wait_queue(&fi->fi_wait, &wait); - - repeat: - set_current_state(TASK_INTERRUPTIBLE); - if (list_empty(&fi->fi_ast_list) && - !signal_pending(current)) { - - spin_unlock(&fi->fi_ast_lock); - schedule(); - spin_lock(&fi->fi_ast_lock); - goto repeat; - } - - current->state = TASK_RUNNING; - remove_wait_queue(&fi->fi_wait, &wait); - - if (signal_pending(current)) { - spin_unlock(&fi->fi_ast_lock); - return -ERESTARTSYS; - } - } - - ast = list_entry(fi->fi_ast_list.next, struct ast_info, list); - list_del(&ast->list); - spin_unlock(&fi->fi_ast_lock); - - /* Work out the size of the returned data */ -#ifdef CONFIG_COMPAT - if (test_bit(FI_FLAG_COMPAT, &fi->fi_flags)) { - data_size = struct_size = sizeof(struct dlm_lock_result32); - data = &result32; - } - else -#endif - { - data_size = struct_size = sizeof(struct dlm_lock_result); - data = &ast->result; - } - if (ast->lvb_updated && ast->result.lksb.sb_lvbptr) - data_size += DLM_USER_LVB_LEN; - - offset = struct_size; - - /* Room for the extended data ? */ - if (count >= data_size) { - - if (ast->lvb_updated && ast->result.lksb.sb_lvbptr) { - if (copy_to_user(buffer+offset, - ast->result.lksb.sb_lvbptr, - DLM_USER_LVB_LEN)) - return -EFAULT; - ast->result.lvb_offset = offset; - offset += DLM_USER_LVB_LEN; - } - } - - ast->result.length = data_size; - -#ifdef CONFIG_COMPAT - compat_output(&ast->result, &result32); -#endif - - /* Copy the header now it has all the offsets in it */ - if (copy_to_user(buffer, data, struct_size)) - offset = -EFAULT; - - /* If we only returned a header and there's more to come then put it - back on the list */ - if (count < data_size) { - spin_lock(&fi->fi_ast_lock); - list_add(&ast->list, &fi->fi_ast_list); - spin_unlock(&fi->fi_ast_lock); - } else - kfree(ast); - return offset; -} - -static unsigned int dlm_poll(struct file *file, poll_table *wait) -{ - struct file_info *fi = file->private_data; - - poll_wait(file, &fi->fi_wait, wait); - - spin_lock(&fi->fi_ast_lock); - if (!list_empty(&fi->fi_ast_list)) { - spin_unlock(&fi->fi_ast_lock); - return POLLIN | POLLRDNORM; - } - - spin_unlock(&fi->fi_ast_lock); - return 0; -} - -static struct lock_info *allocate_lockinfo(struct file_info *fi, uint8_t cmd, - struct dlm_lock_params *kparams) -{ - struct lock_info *li; - - if (!try_module_get(THIS_MODULE)) - return NULL; - - li = kzalloc(sizeof(struct lock_info), GFP_KERNEL); - if (li) { - li->li_magic = LOCKINFO_MAGIC; - li->li_file = fi; - li->li_cmd = cmd; - li->li_flags = 0; - li->li_grmode = -1; - li->li_rqmode = -1; - li->li_pend_bastparam = NULL; - li->li_pend_bastaddr = NULL; - li->li_castaddr = NULL; - li->li_castparam = NULL; - li->li_lksb.sb_lvbptr = NULL; - li->li_bastaddr = kparams->bastaddr; - li->li_bastparam = kparams->bastparam; - - get_file_info(fi); - } - return li; -} - -static int do_user_lock(struct file_info *fi, uint8_t cmd, - struct dlm_lock_params *kparams) -{ - struct lock_info *li; - int status; - - /* - * Validate things that we need to have correct. - */ - if (!kparams->castaddr) - return -EINVAL; - - if (!kparams->lksb) - return -EINVAL; - - /* Persistent child locks are not available yet */ - if ((kparams->flags & DLM_LKF_PERSISTENT) && kparams->parent) - return -EINVAL; - - /* For conversions, there should already be a lockinfo struct, - unless we are adopting an orphaned persistent lock */ - if (kparams->flags & DLM_LKF_CONVERT) { - - li = get_lockinfo(fi->fi_ls, kparams->lkid); - - /* If this is a persistent lock we will have to create a - lockinfo again */ - if (!li && (kparams->flags & DLM_LKF_PERSISTENT)) { - li = allocate_lockinfo(fi, cmd, kparams); - if (!li) - return -ENOMEM; - - li->li_lksb.sb_lkid = kparams->lkid; - li->li_castaddr = kparams->castaddr; - li->li_castparam = kparams->castparam; - - /* OK, this isn't exactly a FIRSTLOCK but it is the - first time we've used this lockinfo, and if things - fail we want rid of it */ - init_completion(&li->li_firstcomp); - set_bit(LI_FLAG_FIRSTLOCK, &li->li_flags); - add_lockinfo(fi->fi_ls, li); - - /* TODO: do a query to get the current state ?? */ - } - if (!li) - return -EINVAL; - - if (li->li_magic != LOCKINFO_MAGIC) - return -EINVAL; - - /* For conversions don't overwrite the current blocking AST - info so that: - a) if a blocking AST fires before the conversion is queued - it runs the current handler - b) if the conversion is cancelled, the original blocking AST - declaration is active - The pend_ info is made active when the conversion - completes. - */ - li->li_pend_bastaddr = kparams->bastaddr; - li->li_pend_bastparam = kparams->bastparam; - } else { - li = allocate_lockinfo(fi, cmd, kparams); - if (!li) - return -ENOMEM; - - /* Allow us to complete our work before - the AST routine runs. In fact we only need (and use) this - when the initial lock fails */ - init_completion(&li->li_firstcomp); - set_bit(LI_FLAG_FIRSTLOCK, &li->li_flags); - } - - li->li_user_lksb = kparams->lksb; - li->li_castaddr = kparams->castaddr; - li->li_castparam = kparams->castparam; - li->li_lksb.sb_lkid = kparams->lkid; - li->li_rqmode = kparams->mode; - if (kparams->flags & DLM_LKF_PERSISTENT) - set_bit(LI_FLAG_PERSISTENT, &li->li_flags); - - /* Copy in the value block */ - if (kparams->flags & DLM_LKF_VALBLK) { - if (!li->li_lksb.sb_lvbptr) { - li->li_lksb.sb_lvbptr = kmalloc(DLM_USER_LVB_LEN, - GFP_KERNEL); - if (!li->li_lksb.sb_lvbptr) { - status = -ENOMEM; - goto out_err; - } - } - - memcpy(li->li_lksb.sb_lvbptr, kparams->lvb, DLM_USER_LVB_LEN); - } - - /* Lock it ... */ - status = dlm_lock(fi->fi_ls->ls_lockspace, - kparams->mode, &li->li_lksb, - kparams->flags, - kparams->name, kparams->namelen, - kparams->parent, - ast_routine, - li, - (li->li_pend_bastaddr || li->li_bastaddr) ? - bast_routine : NULL); - if (status) - goto out_err; - - /* If it succeeded (this far) with a new lock then keep track of - it on the file's lockinfo list */ - if (!status && test_bit(LI_FLAG_FIRSTLOCK, &li->li_flags)) { - - spin_lock(&fi->fi_li_lock); - list_add(&li->li_ownerqueue, &fi->fi_li_list); - set_bit(LI_FLAG_ONLIST, &li->li_flags); - spin_unlock(&fi->fi_li_lock); - if (add_lockinfo(fi->fi_ls, li)) - printk(KERN_WARNING "Add lockinfo failed\n"); - - complete(&li->li_firstcomp); - } - - /* Return the lockid as the user needs it /now/ */ - return li->li_lksb.sb_lkid; - - out_err: - if (test_bit(LI_FLAG_FIRSTLOCK, &li->li_flags)) - release_lockinfo(fi->fi_ls, li); - return status; - -} - -static int do_user_unlock(struct file_info *fi, uint8_t cmd, - struct dlm_lock_params *kparams) -{ - struct lock_info *li; - int status; - int convert_cancel = 0; - - li = get_lockinfo(fi->fi_ls, kparams->lkid); - if (!li) { - li = allocate_lockinfo(fi, cmd, kparams); - if (!li) - return -ENOMEM; - spin_lock(&fi->fi_li_lock); - list_add(&li->li_ownerqueue, &fi->fi_li_list); - set_bit(LI_FLAG_ONLIST, &li->li_flags); - spin_unlock(&fi->fi_li_lock); - } - - if (li->li_magic != LOCKINFO_MAGIC) - return -EINVAL; - - li->li_user_lksb = kparams->lksb; - li->li_castparam = kparams->castparam; - li->li_cmd = cmd; - - /* Cancelling a conversion doesn't remove the lock...*/ - if (kparams->flags & DLM_LKF_CANCEL && li->li_grmode != -1) - convert_cancel = 1; - - /* Wait until dlm_lock() has completed */ - if (!test_bit(LI_FLAG_ONLIST, &li->li_flags)) { - wait_for_completion(&li->li_firstcomp); - } - - /* dlm_unlock() passes a 0 for castaddr which means don't overwrite - the existing li_castaddr as that's the completion routine for - unlocks. dlm_unlock_wait() specifies a new AST routine to be - executed when the unlock completes. */ - if (kparams->castaddr) - li->li_castaddr = kparams->castaddr; - - /* Use existing lksb & astparams */ - status = dlm_unlock(fi->fi_ls->ls_lockspace, - kparams->lkid, - kparams->flags, &li->li_lksb, li); - - if (!status && !convert_cancel) { - spin_lock(&fi->fi_li_lock); - list_del(&li->li_ownerqueue); - clear_bit(LI_FLAG_ONLIST, &li->li_flags); - spin_unlock(&fi->fi_li_lock); - } - - return status; -} - -/* Write call, submit a locking request */ -static ssize_t dlm_write(struct file *file, const char __user *buffer, - size_t count, loff_t *ppos) -{ - struct file_info *fi = file->private_data; - struct dlm_write_request *kparams; - sigset_t tmpsig; - sigset_t allsigs; - int status; - -#ifdef CONFIG_COMPAT - if (count < sizeof(struct dlm_write_request32)) -#else - if (count < sizeof(struct dlm_write_request)) -#endif - return -EINVAL; - - if (count > sizeof(struct dlm_write_request) + DLM_RESNAME_MAXLEN) - return -EINVAL; - - /* Has the lockspace been deleted */ - if (fi && test_bit(LS_FLAG_DELETED, &fi->fi_ls->ls_flags)) - return -ENOENT; - - kparams = kmalloc(count, GFP_KERNEL); - if (!kparams) - return -ENOMEM; - - status = -EFAULT; - /* Get the command info */ - if (copy_from_user(kparams, buffer, count)) - goto out_free; - - status = -EBADE; - if (check_version(kparams)) - goto out_free; - -#ifdef CONFIG_COMPAT - if (!kparams->is64bit) { - struct dlm_write_request32 *k32params = (struct dlm_write_request32 *)kparams; - kparams = kmalloc(count + (sizeof(struct dlm_write_request) - sizeof(struct dlm_write_request32)), GFP_KERNEL); - if (!kparams) - return -ENOMEM; - - if (fi) - set_bit(FI_FLAG_COMPAT, &fi->fi_flags); - compat_input(kparams, k32params); - kfree(k32params); - } -#endif - - /* Block signals while we are doing this */ - sigfillset(&allsigs); - sigprocmask(SIG_BLOCK, &allsigs, &tmpsig); - - status = -EINVAL; - switch (kparams->cmd) - { - case DLM_USER_LOCK: - if (!fi) goto out_sig; - status = do_user_lock(fi, kparams->cmd, &kparams->i.lock); - break; - - case DLM_USER_UNLOCK: - if (!fi) goto out_sig; - status = do_user_unlock(fi, kparams->cmd, &kparams->i.lock); - break; - - case DLM_USER_CREATE_LOCKSPACE: - if (fi) goto out_sig; - status = do_user_create_lockspace(fi, kparams->cmd, - &kparams->i.lspace); - break; - - case DLM_USER_REMOVE_LOCKSPACE: - if (fi) goto out_sig; - status = do_user_remove_lockspace(fi, kparams->cmd, - &kparams->i.lspace); - break; - default: - printk("Unknown command passed to DLM device : %d\n", - kparams->cmd); - break; - } - - out_sig: - /* Restore signals */ - sigprocmask(SIG_SETMASK, &tmpsig, NULL); - recalc_sigpending(); - - out_free: - kfree(kparams); - if (status == 0) - return count; - else - return status; -} - -static struct file_operations _dlm_fops = { - .open = dlm_open, - .release = dlm_close, - .read = dlm_read, - .write = dlm_write, - .poll = dlm_poll, - .owner = THIS_MODULE, -}; - -static struct file_operations _dlm_ctl_fops = { - .open = dlm_ctl_open, - .release = dlm_ctl_close, - .write = dlm_write, - .owner = THIS_MODULE, -}; - -/* - * Create control device - */ -static int __init dlm_device_init(void) -{ - int r; - - INIT_LIST_HEAD(&user_ls_list); - mutex_init(&user_ls_lock); - - ctl_device.name = "dlm-control"; - ctl_device.fops = &_dlm_ctl_fops; - ctl_device.minor = MISC_DYNAMIC_MINOR; - - r = misc_register(&ctl_device); - if (r) { - printk(KERN_ERR "dlm: misc_register failed for control dev\n"); - return r; - } - - return 0; -} - -static void __exit dlm_device_exit(void) -{ - misc_deregister(&ctl_device); -} - -MODULE_DESCRIPTION("Distributed Lock Manager device interface"); -MODULE_AUTHOR("Red Hat, Inc."); -MODULE_LICENSE("GPL"); - -module_init(dlm_device_init); -module_exit(dlm_device_exit); diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index 149106f2b80f..db080de2a7e9 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,7 @@ struct dlm_mhandle; #define log_error(ls, fmt, args...) \ printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args) +#define DLM_LOG_DEBUG #ifdef DLM_LOG_DEBUG #define log_debug(ls, fmt, args...) log_error(ls, fmt, ##args) #else @@ -204,6 +206,9 @@ struct dlm_args { #define DLM_IFL_MSTCPY 0x00010000 #define DLM_IFL_RESEND 0x00020000 +#define DLM_IFL_DEAD 0x00040000 +#define DLM_IFL_USER 0x00000001 +#define DLM_IFL_ORPHAN 0x00000002 struct dlm_lkb { struct dlm_rsb *lkb_resource; /* the rsb */ @@ -231,6 +236,7 @@ struct dlm_lkb { struct list_head lkb_rsb_lookup; /* waiting for rsb lookup */ struct list_head lkb_wait_reply; /* waiting for remote reply */ struct list_head lkb_astqueue; /* need ast to be sent */ + struct list_head lkb_ownqueue; /* list of locks for a process */ char *lkb_lvbptr; struct dlm_lksb *lkb_lksb; /* caller's status block */ @@ -409,6 +415,7 @@ struct rcom_lock { struct dlm_ls { struct list_head ls_list; /* list of lockspaces */ + dlm_lockspace_t *ls_local_handle; uint32_t ls_global_id; /* global unique lockspace ID */ uint32_t ls_exflags; int ls_lvblen; @@ -444,6 +451,8 @@ struct dlm_ls { wait_queue_head_t ls_uevent_wait; /* user part of join/leave */ int ls_uevent_result; + struct miscdevice ls_device; + /* recovery related */ struct timer_list ls_timer; @@ -461,6 +470,7 @@ struct dlm_ls { spinlock_t ls_recover_list_lock; int ls_recover_list_count; wait_queue_head_t ls_wait_general; + struct mutex ls_clear_proc_locks; struct list_head ls_root_list; /* root resources */ struct rw_semaphore ls_root_sem; /* protect root_list */ @@ -475,6 +485,40 @@ struct dlm_ls { #define LSFL_RCOM_READY 3 #define LSFL_UEVENT_WAIT 4 +/* much of this is just saving user space pointers associated with the + lock that we pass back to the user lib with an ast */ + +struct dlm_user_args { + struct dlm_user_proc *proc; /* each process that opens the lockspace + device has private data + (dlm_user_proc) on the struct file, + the process's locks point back to it*/ + struct dlm_lksb lksb; + int old_mode; + int update_user_lvb; + struct dlm_lksb __user *user_lksb; + void __user *castparam; + void __user *castaddr; + void __user *bastparam; + void __user *bastaddr; +}; + +#define DLM_PROC_FLAGS_CLOSING 1 +#define DLM_PROC_FLAGS_COMPAT 2 + +/* locks list is kept so we can remove all a process's locks when it + exits (or orphan those that are persistent) */ + +struct dlm_user_proc { + dlm_lockspace_t *lockspace; + unsigned long flags; /* DLM_PROC_FLAGS */ + struct list_head asts; + spinlock_t asts_spin; + struct list_head locks; + spinlock_t locks_spin; + wait_queue_head_t wait; +}; + static inline int dlm_locking_stopped(struct dlm_ls *ls) { return !test_bit(LSFL_RUNNING, &ls->ls_flags); diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 5f6963904107..4e222f873b6c 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -55,8 +55,9 @@ R: do_xxxx() L: receive_xxxx_reply() <- R: send_xxxx_reply() */ - +#include #include "dlm_internal.h" +#include #include "memory.h" #include "lowcomms.h" #include "requestqueue.h" @@ -69,6 +70,7 @@ #include "rcom.h" #include "recover.h" #include "lvb_table.h" +#include "user.h" #include "config.h" static int send_request(struct dlm_rsb *r, struct dlm_lkb *lkb); @@ -84,6 +86,8 @@ static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, struct dlm_message *ms); static int receive_extralen(struct dlm_message *ms); +#define FAKE_USER_AST (void*)0xff00ff00 + /* * Lock compatibilty matrix - thanks Steve * UN = Unlocked state. Not really a state, used as a flag @@ -152,7 +156,7 @@ static const int __quecvt_compat_matrix[8][8] = { {0, 0, 0, 0, 0, 0, 0, 0} /* PD */ }; -static void dlm_print_lkb(struct dlm_lkb *lkb) +void dlm_print_lkb(struct dlm_lkb *lkb) { printk(KERN_ERR "lkb: nodeid %d id %x remid %x exflags %x flags %x\n" " status %d rqmode %d grmode %d wait_type %d ast_type %d\n", @@ -291,7 +295,7 @@ static int search_rsb_list(struct list_head *head, char *name, int len, if (len == r->res_length && !memcmp(name, r->res_name, len)) goto found; } - return -ENOENT; + return -EBADR; found: if (r->res_nodeid && (flags & R_MASTER)) @@ -376,7 +380,7 @@ static int find_rsb(struct dlm_ls *ls, char *name, int namelen, if (!error) goto out; - if (error == -ENOENT && !(flags & R_CREATE)) + if (error == -EBADR && !(flags & R_CREATE)) goto out; /* the rsb was found but wasn't a master copy */ @@ -920,7 +924,7 @@ static void set_lvb_lock_pc(struct dlm_rsb *r, struct dlm_lkb *lkb, if (!(lkb->lkb_exflags & DLM_LKF_VALBLK)) return; - b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1]; + b = dlm_lvb_operations[lkb->lkb_grmode + 1][lkb->lkb_rqmode + 1]; if (b == 1) { int len = receive_extralen(ms); memcpy(lkb->lkb_lvbptr, ms->m_extra, len); @@ -963,6 +967,8 @@ static void revert_lock(struct dlm_rsb *r, struct dlm_lkb *lkb) lkb->lkb_rqmode = DLM_LOCK_IV; switch (lkb->lkb_status) { + case DLM_LKSTS_GRANTED: + break; case DLM_LKSTS_CONVERT: move_lkb(r, lkb, DLM_LKSTS_GRANTED); break; @@ -1727,6 +1733,11 @@ static int do_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) return -DLM_EUNLOCK; } +/* FIXME: if revert_lock() finds that the lkb is granted, we should + skip the queue_cast(ECANCEL). It indicates that the request/convert + completed (and queued a normal ast) just before the cancel; we don't + want to clobber the sb_result for the normal ast with ECANCEL. */ + static int do_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb) { revert_lock(r, lkb); @@ -2739,7 +2750,7 @@ static void receive_request_reply(struct dlm_ls *ls, struct dlm_message *ms) confirm_master(r, error); break; - case -ENOENT: + case -EBADR: case -ENOTBLK: /* find_rsb failed to find rsb or rsb wasn't master */ r->res_nodeid = -1; @@ -3545,3 +3556,284 @@ int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc) return 0; } +int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua, + int mode, uint32_t flags, void *name, unsigned int namelen, + uint32_t parent_lkid) +{ + struct dlm_lkb *lkb; + struct dlm_args args; + int error; + + lock_recovery(ls); + + error = create_lkb(ls, &lkb); + if (error) { + kfree(ua); + goto out; + } + + if (flags & DLM_LKF_VALBLK) { + ua->lksb.sb_lvbptr = kmalloc(DLM_USER_LVB_LEN, GFP_KERNEL); + if (!ua->lksb.sb_lvbptr) { + kfree(ua); + __put_lkb(ls, lkb); + error = -ENOMEM; + goto out; + } + } + + /* After ua is attached to lkb it will be freed by free_lkb(). + When DLM_IFL_USER is set, the dlm knows that this is a userspace + lock and that lkb_astparam is the dlm_user_args structure. */ + + error = set_lock_args(mode, &ua->lksb, flags, namelen, parent_lkid, + FAKE_USER_AST, ua, FAKE_USER_AST, &args); + lkb->lkb_flags |= DLM_IFL_USER; + ua->old_mode = DLM_LOCK_IV; + + if (error) { + __put_lkb(ls, lkb); + goto out; + } + + error = request_lock(ls, lkb, name, namelen, &args); + + switch (error) { + case 0: + break; + case -EINPROGRESS: + error = 0; + break; + case -EAGAIN: + error = 0; + /* fall through */ + default: + __put_lkb(ls, lkb); + goto out; + } + + /* add this new lkb to the per-process list of locks */ + spin_lock(&ua->proc->locks_spin); + kref_get(&lkb->lkb_ref); + list_add_tail(&lkb->lkb_ownqueue, &ua->proc->locks); + spin_unlock(&ua->proc->locks_spin); + out: + unlock_recovery(ls); + return error; +} + +int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, + int mode, uint32_t flags, uint32_t lkid, char *lvb_in) +{ + struct dlm_lkb *lkb; + struct dlm_args args; + struct dlm_user_args *ua; + int error; + + lock_recovery(ls); + + error = find_lkb(ls, lkid, &lkb); + if (error) + goto out; + + /* user can change the params on its lock when it converts it, or + add an lvb that didn't exist before */ + + ua = (struct dlm_user_args *)lkb->lkb_astparam; + + if (flags & DLM_LKF_VALBLK && !ua->lksb.sb_lvbptr) { + ua->lksb.sb_lvbptr = kmalloc(DLM_USER_LVB_LEN, GFP_KERNEL); + if (!ua->lksb.sb_lvbptr) { + error = -ENOMEM; + goto out_put; + } + } + if (lvb_in && ua->lksb.sb_lvbptr) + memcpy(ua->lksb.sb_lvbptr, lvb_in, DLM_USER_LVB_LEN); + + ua->castparam = ua_tmp->castparam; + ua->castaddr = ua_tmp->castaddr; + ua->bastparam = ua_tmp->bastparam; + ua->bastaddr = ua_tmp->bastaddr; + ua->old_mode = lkb->lkb_grmode; + + error = set_lock_args(mode, &ua->lksb, flags, 0, 0, FAKE_USER_AST, ua, + FAKE_USER_AST, &args); + if (error) + goto out_put; + + error = convert_lock(ls, lkb, &args); + + if (error == -EINPROGRESS || error == -EAGAIN) + error = 0; + out_put: + dlm_put_lkb(lkb); + out: + unlock_recovery(ls); + kfree(ua_tmp); + return error; +} + +int dlm_user_unlock(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, + uint32_t flags, uint32_t lkid, char *lvb_in) +{ + struct dlm_lkb *lkb; + struct dlm_args args; + struct dlm_user_args *ua; + int error; + + lock_recovery(ls); + + error = find_lkb(ls, lkid, &lkb); + if (error) + goto out; + + ua = (struct dlm_user_args *)lkb->lkb_astparam; + + if (lvb_in && ua->lksb.sb_lvbptr) + memcpy(ua->lksb.sb_lvbptr, lvb_in, DLM_USER_LVB_LEN); + ua->castparam = ua_tmp->castparam; + + error = set_unlock_args(flags, ua, &args); + if (error) + goto out_put; + + error = unlock_lock(ls, lkb, &args); + + if (error == -DLM_EUNLOCK) + error = 0; + if (error) + goto out_put; + + spin_lock(&ua->proc->locks_spin); + list_del(&lkb->lkb_ownqueue); + spin_unlock(&ua->proc->locks_spin); + + /* this removes the reference for the proc->locks list added by + dlm_user_request */ + unhold_lkb(lkb); + out_put: + dlm_put_lkb(lkb); + out: + unlock_recovery(ls); + return error; +} + +int dlm_user_cancel(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, + uint32_t flags, uint32_t lkid) +{ + struct dlm_lkb *lkb; + struct dlm_args args; + struct dlm_user_args *ua; + int error; + + lock_recovery(ls); + + error = find_lkb(ls, lkid, &lkb); + if (error) + goto out; + + ua = (struct dlm_user_args *)lkb->lkb_astparam; + ua->castparam = ua_tmp->castparam; + + error = set_unlock_args(flags, ua, &args); + if (error) + goto out_put; + + error = cancel_lock(ls, lkb, &args); + + if (error == -DLM_ECANCEL) + error = 0; + if (error) + goto out_put; + + /* this lkb was removed from the WAITING queue */ + if (lkb->lkb_grmode == DLM_LOCK_IV) { + spin_lock(&ua->proc->locks_spin); + list_del(&lkb->lkb_ownqueue); + spin_unlock(&ua->proc->locks_spin); + unhold_lkb(lkb); + } + out_put: + dlm_put_lkb(lkb); + out: + unlock_recovery(ls); + return error; +} + +static int orphan_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb) +{ + struct dlm_user_args *ua = (struct dlm_user_args *)lkb->lkb_astparam; + + if (ua->lksb.sb_lvbptr) + kfree(ua->lksb.sb_lvbptr); + kfree(ua); + lkb->lkb_astparam = (long)NULL; + + /* TODO: propogate to master if needed */ + return 0; +} + +/* The force flag allows the unlock to go ahead even if the lkb isn't granted. + Regardless of what rsb queue the lock is on, it's removed and freed. */ + +static int unlock_proc_lock(struct dlm_ls *ls, struct dlm_lkb *lkb) +{ + struct dlm_user_args *ua = (struct dlm_user_args *)lkb->lkb_astparam; + struct dlm_args args; + int error; + + /* FIXME: we need to handle the case where the lkb is in limbo + while the rsb is being looked up, currently we assert in + _unlock_lock/is_remote because rsb nodeid is -1. */ + + set_unlock_args(DLM_LKF_FORCEUNLOCK, ua, &args); + + error = unlock_lock(ls, lkb, &args); + if (error == -DLM_EUNLOCK) + error = 0; + return error; +} + +/* The ls_clear_proc_locks mutex protects against dlm_user_add_asts() which + 1) references lkb->ua which we free here and 2) adds lkbs to proc->asts, + which we clear here. */ + +/* proc CLOSING flag is set so no more device_reads should look at proc->asts + list, and no more device_writes should add lkb's to proc->locks list; so we + shouldn't need to take asts_spin or locks_spin here. this assumes that + device reads/writes/closes are serialized -- FIXME: we may need to serialize + them ourself. */ + +void dlm_clear_proc_locks(struct dlm_ls *ls, struct dlm_user_proc *proc) +{ + struct dlm_lkb *lkb, *safe; + + lock_recovery(ls); + mutex_lock(&ls->ls_clear_proc_locks); + + list_for_each_entry_safe(lkb, safe, &proc->locks, lkb_ownqueue) { + if (lkb->lkb_ast_type) { + list_del(&lkb->lkb_astqueue); + unhold_lkb(lkb); + } + + list_del(&lkb->lkb_ownqueue); + + if (lkb->lkb_exflags & DLM_LKF_PERSISTENT) { + lkb->lkb_flags |= DLM_IFL_ORPHAN; + orphan_proc_lock(ls, lkb); + } else { + lkb->lkb_flags |= DLM_IFL_DEAD; + unlock_proc_lock(ls, lkb); + } + + /* this removes the reference for the proc->locks list + added by dlm_user_request, it may result in the lkb + being freed */ + + dlm_put_lkb(lkb); + } + mutex_unlock(&ls->ls_clear_proc_locks); + unlock_recovery(ls); +} diff --git a/fs/dlm/lock.h b/fs/dlm/lock.h index 56cdc073b1f6..8d2660f0ab10 100644 --- a/fs/dlm/lock.h +++ b/fs/dlm/lock.h @@ -14,6 +14,7 @@ #define __LOCK_DOT_H__ void dlm_print_rsb(struct dlm_rsb *r); +void dlm_print_lkb(struct dlm_lkb *lkb); int dlm_receive_message(struct dlm_header *hd, int nodeid, int recovery); int dlm_modes_compat(int mode1, int mode2); int dlm_find_rsb(struct dlm_ls *ls, char *name, int namelen, @@ -31,6 +32,16 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls); int dlm_recover_master_copy(struct dlm_ls *ls, struct dlm_rcom *rc); int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc); +int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua, int mode, + uint32_t flags, void *name, unsigned int namelen, uint32_t parent_lkid); +int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, + int mode, uint32_t flags, uint32_t lkid, char *lvb_in); +int dlm_user_unlock(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, + uint32_t flags, uint32_t lkid, char *lvb_in); +int dlm_user_cancel(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, + uint32_t flags, uint32_t lkid); +void dlm_clear_proc_locks(struct dlm_ls *ls, struct dlm_user_proc *proc); + static inline int is_master(struct dlm_rsb *r) { return !r->res_nodeid; diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index 9ed4b70348fb..3f6cb422ac4b 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -270,12 +270,36 @@ struct dlm_ls *dlm_find_lockspace_global(uint32_t id) return ls; } -struct dlm_ls *dlm_find_lockspace_local(void *id) +struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace_t *lockspace) { - struct dlm_ls *ls = id; + struct dlm_ls *ls; spin_lock(&lslist_lock); - ls->ls_count++; + list_for_each_entry(ls, &lslist, ls_list) { + if (ls->ls_local_handle == lockspace) { + ls->ls_count++; + goto out; + } + } + ls = NULL; + out: + spin_unlock(&lslist_lock); + return ls; +} + +struct dlm_ls *dlm_find_lockspace_device(int minor) +{ + struct dlm_ls *ls; + + spin_lock(&lslist_lock); + list_for_each_entry(ls, &lslist, ls_list) { + if (ls->ls_device.minor == minor) { + ls->ls_count++; + goto out; + } + } + ls = NULL; + out: spin_unlock(&lslist_lock); return ls; } @@ -436,6 +460,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace, init_rwsem(&ls->ls_in_recovery); INIT_LIST_HEAD(&ls->ls_requestqueue); mutex_init(&ls->ls_requestqueue_mutex); + mutex_init(&ls->ls_clear_proc_locks); ls->ls_recover_buf = kmalloc(dlm_config.buffer_size, GFP_KERNEL); if (!ls->ls_recover_buf) @@ -444,6 +469,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace, INIT_LIST_HEAD(&ls->ls_recover_list); spin_lock_init(&ls->ls_recover_list_lock); ls->ls_recover_list_count = 0; + ls->ls_local_handle = ls; init_waitqueue_head(&ls->ls_wait_general); INIT_LIST_HEAD(&ls->ls_root_list); init_rwsem(&ls->ls_root_sem); diff --git a/fs/dlm/lockspace.h b/fs/dlm/lockspace.h index 17bd3ba863a9..891eabbdd021 100644 --- a/fs/dlm/lockspace.h +++ b/fs/dlm/lockspace.h @@ -18,6 +18,7 @@ int dlm_lockspace_init(void); void dlm_lockspace_exit(void); struct dlm_ls *dlm_find_lockspace_global(uint32_t id); struct dlm_ls *dlm_find_lockspace_local(void *id); +struct dlm_ls *dlm_find_lockspace_device(int minor); void dlm_put_lockspace(struct dlm_ls *ls); #endif /* __LOCKSPACE_DOT_H__ */ diff --git a/fs/dlm/main.c b/fs/dlm/main.c index 81bf4cb22033..a8da8dc36b2e 100644 --- a/fs/dlm/main.c +++ b/fs/dlm/main.c @@ -14,6 +14,7 @@ #include "dlm_internal.h" #include "lockspace.h" #include "lock.h" +#include "user.h" #include "memory.h" #include "lowcomms.h" #include "config.h" @@ -50,10 +51,16 @@ static int __init init_dlm(void) if (error) goto out_debug; + error = dlm_user_init(); + if (error) + goto out_lowcomms; + printk("DLM (built %s %s) installed\n", __DATE__, __TIME__); return 0; + out_lowcomms: + dlm_lowcomms_exit(); out_debug: dlm_unregister_debugfs(); out_config: @@ -68,6 +75,7 @@ static int __init init_dlm(void) static void __exit exit_dlm(void) { + dlm_user_exit(); dlm_lowcomms_exit(); dlm_config_exit(); dlm_memory_exit(); diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c index f7cf4589fae8..48dfc27861f4 100644 --- a/fs/dlm/memory.c +++ b/fs/dlm/memory.c @@ -84,6 +84,15 @@ struct dlm_lkb *allocate_lkb(struct dlm_ls *ls) void free_lkb(struct dlm_lkb *lkb) { + if (lkb->lkb_flags & DLM_IFL_USER) { + struct dlm_user_args *ua; + ua = (struct dlm_user_args *)lkb->lkb_astparam; + if (ua) { + if (ua->lksb.sb_lvbptr) + kfree(ua->lksb.sb_lvbptr); + kfree(ua); + } + } kmem_cache_free(lkb_cache, lkb); } diff --git a/fs/dlm/user.c b/fs/dlm/user.c new file mode 100644 index 000000000000..1f05960a916f --- /dev/null +++ b/fs/dlm/user.c @@ -0,0 +1,769 @@ +/* + * Copyright (C) 2006 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dlm_internal.h" +#include "lockspace.h" +#include "lock.h" +#include "lvb_table.h" + +static const char *name_prefix="dlm"; +static struct miscdevice ctl_device; +static struct file_operations device_fops; + +#ifdef CONFIG_COMPAT + +struct dlm_lock_params32 { + __u8 mode; + __u8 namelen; + __u16 flags; + __u32 lkid; + __u32 parent; + + __u32 castparam; + __u32 castaddr; + __u32 bastparam; + __u32 bastaddr; + __u32 lksb; + + char lvb[DLM_USER_LVB_LEN]; + char name[0]; +}; + +struct dlm_write_request32 { + __u32 version[3]; + __u8 cmd; + __u8 is64bit; + __u8 unused[2]; + + union { + struct dlm_lock_params32 lock; + struct dlm_lspace_params lspace; + } i; +}; + +struct dlm_lksb32 { + __u32 sb_status; + __u32 sb_lkid; + __u8 sb_flags; + __u32 sb_lvbptr; +}; + +struct dlm_lock_result32 { + __u32 length; + __u32 user_astaddr; + __u32 user_astparam; + __u32 user_lksb; + struct dlm_lksb32 lksb; + __u8 bast_mode; + __u8 unused[3]; + /* Offsets may be zero if no data is present */ + __u32 lvb_offset; +}; + +static void compat_input(struct dlm_write_request *kb, + struct dlm_write_request32 *kb32) +{ + kb->version[0] = kb32->version[0]; + kb->version[1] = kb32->version[1]; + kb->version[2] = kb32->version[2]; + + kb->cmd = kb32->cmd; + kb->is64bit = kb32->is64bit; + if (kb->cmd == DLM_USER_CREATE_LOCKSPACE || + kb->cmd == DLM_USER_REMOVE_LOCKSPACE) { + kb->i.lspace.flags = kb32->i.lspace.flags; + kb->i.lspace.minor = kb32->i.lspace.minor; + strcpy(kb->i.lspace.name, kb32->i.lspace.name); + } else { + kb->i.lock.mode = kb32->i.lock.mode; + kb->i.lock.namelen = kb32->i.lock.namelen; + kb->i.lock.flags = kb32->i.lock.flags; + kb->i.lock.lkid = kb32->i.lock.lkid; + kb->i.lock.parent = kb32->i.lock.parent; + kb->i.lock.castparam = (void *)(long)kb32->i.lock.castparam; + kb->i.lock.castaddr = (void *)(long)kb32->i.lock.castaddr; + kb->i.lock.bastparam = (void *)(long)kb32->i.lock.bastparam; + kb->i.lock.bastaddr = (void *)(long)kb32->i.lock.bastaddr; + kb->i.lock.lksb = (void *)(long)kb32->i.lock.lksb; + memcpy(kb->i.lock.lvb, kb32->i.lock.lvb, DLM_USER_LVB_LEN); + memcpy(kb->i.lock.name, kb32->i.lock.name, kb->i.lock.namelen); + } +} + +static void compat_output(struct dlm_lock_result *res, + struct dlm_lock_result32 *res32) +{ + res32->length = res->length - (sizeof(struct dlm_lock_result) - + sizeof(struct dlm_lock_result32)); + res32->user_astaddr = (__u32)(long)res->user_astaddr; + res32->user_astparam = (__u32)(long)res->user_astparam; + res32->user_lksb = (__u32)(long)res->user_lksb; + res32->bast_mode = res->bast_mode; + + res32->lvb_offset = res->lvb_offset; + res32->length = res->length; + + res32->lksb.sb_status = res->lksb.sb_status; + res32->lksb.sb_flags = res->lksb.sb_flags; + res32->lksb.sb_lkid = res->lksb.sb_lkid; + res32->lksb.sb_lvbptr = (__u32)(long)res->lksb.sb_lvbptr; +} +#endif + + +void dlm_user_add_ast(struct dlm_lkb *lkb, int type) +{ + struct dlm_ls *ls; + struct dlm_user_args *ua; + struct dlm_user_proc *proc; + + /* dlm_clear_proc_locks() sets ORPHAN/DEAD flag on each + lkb before dealing with it. We need to check this + flag before taking ls_clear_proc_locks mutex because if + it's set, dlm_clear_proc_locks() holds the mutex. */ + + if (lkb->lkb_flags & (DLM_IFL_ORPHAN | DLM_IFL_DEAD)) { + /* log_print("user_add_ast skip1 %x", lkb->lkb_flags); */ + return; + } + + ls = lkb->lkb_resource->res_ls; + mutex_lock(&ls->ls_clear_proc_locks); + + /* If ORPHAN/DEAD flag is set, it means the process is dead so an ast + can't be delivered. For ORPHAN's, dlm_clear_proc_locks() freed + lkb->ua so we can't try to use it. */ + + if (lkb->lkb_flags & (DLM_IFL_ORPHAN | DLM_IFL_DEAD)) { + /* log_print("user_add_ast skip2 %x", lkb->lkb_flags); */ + goto out; + } + + DLM_ASSERT(lkb->lkb_astparam, dlm_print_lkb(lkb);); + ua = (struct dlm_user_args *)lkb->lkb_astparam; + proc = ua->proc; + + if (type == AST_BAST && ua->bastaddr == NULL) + goto out; + + spin_lock(&proc->asts_spin); + if (!(lkb->lkb_ast_type & (AST_COMP | AST_BAST))) { + kref_get(&lkb->lkb_ref); + list_add_tail(&lkb->lkb_astqueue, &proc->asts); + lkb->lkb_ast_type |= type; + wake_up_interruptible(&proc->wait); + } + + /* We want to copy the lvb to userspace when the completion + ast is read if the status is 0, the lock has an lvb and + lvb_ops says we should. We could probably have set_lvb_lock() + set update_user_lvb instead and not need old_mode */ + + if ((lkb->lkb_ast_type & AST_COMP) && + (lkb->lkb_lksb->sb_status == 0) && + lkb->lkb_lksb->sb_lvbptr && + dlm_lvb_operations[ua->old_mode + 1][lkb->lkb_grmode + 1]) + ua->update_user_lvb = 1; + else + ua->update_user_lvb = 0; + + spin_unlock(&proc->asts_spin); + out: + mutex_unlock(&ls->ls_clear_proc_locks); +} + +static int device_user_lock(struct dlm_user_proc *proc, + struct dlm_lock_params *params) +{ + struct dlm_ls *ls; + struct dlm_user_args *ua; + int error = -ENOMEM; + + ls = dlm_find_lockspace_local(proc->lockspace); + if (!ls) + return -ENOENT; + + if (!params->castaddr || !params->lksb) { + error = -EINVAL; + goto out; + } + + ua = kzalloc(sizeof(struct dlm_user_args), GFP_KERNEL); + if (!ua) + goto out; + ua->proc = proc; + ua->user_lksb = params->lksb; + ua->castparam = params->castparam; + ua->castaddr = params->castaddr; + ua->bastparam = params->bastparam; + ua->bastaddr = params->bastaddr; + + if (params->flags & DLM_LKF_CONVERT) + error = dlm_user_convert(ls, ua, + params->mode, params->flags, + params->lkid, params->lvb); + else { + error = dlm_user_request(ls, ua, + params->mode, params->flags, + params->name, params->namelen, + params->parent); + if (!error) + error = ua->lksb.sb_lkid; + } + out: + dlm_put_lockspace(ls); + return error; +} + +static int device_user_unlock(struct dlm_user_proc *proc, + struct dlm_lock_params *params) +{ + struct dlm_ls *ls; + struct dlm_user_args *ua; + int error = -ENOMEM; + + ls = dlm_find_lockspace_local(proc->lockspace); + if (!ls) + return -ENOENT; + + ua = kzalloc(sizeof(struct dlm_user_args), GFP_KERNEL); + if (!ua) + goto out; + ua->proc = proc; + ua->user_lksb = params->lksb; + ua->castparam = params->castparam; + ua->castaddr = params->castaddr; + + if (params->flags & DLM_LKF_CANCEL) + error = dlm_user_cancel(ls, ua, params->flags, params->lkid); + else + error = dlm_user_unlock(ls, ua, params->flags, params->lkid, + params->lvb); + out: + dlm_put_lockspace(ls); + return error; +} + +static int device_create_lockspace(struct dlm_lspace_params *params) +{ + dlm_lockspace_t *lockspace; + struct dlm_ls *ls; + int error, len; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + error = dlm_new_lockspace(params->name, strlen(params->name), + &lockspace, 0, DLM_USER_LVB_LEN); + if (error) + return error; + + ls = dlm_find_lockspace_local(lockspace); + if (!ls) + return -ENOENT; + + error = -ENOMEM; + len = strlen(params->name) + strlen(name_prefix) + 2; + ls->ls_device.name = kzalloc(len, GFP_KERNEL); + if (!ls->ls_device.name) + goto fail; + snprintf((char *)ls->ls_device.name, len, "%s_%s", name_prefix, + params->name); + ls->ls_device.fops = &device_fops; + ls->ls_device.minor = MISC_DYNAMIC_MINOR; + + error = misc_register(&ls->ls_device); + if (error) { + kfree(ls->ls_device.name); + goto fail; + } + + error = ls->ls_device.minor; + dlm_put_lockspace(ls); + return error; + + fail: + dlm_put_lockspace(ls); + dlm_release_lockspace(lockspace, 0); + return error; +} + +static int device_remove_lockspace(struct dlm_lspace_params *params) +{ + dlm_lockspace_t *lockspace; + struct dlm_ls *ls; + int error; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + ls = dlm_find_lockspace_device(params->minor); + if (!ls) + return -ENOENT; + + error = misc_deregister(&ls->ls_device); + if (error) { + dlm_put_lockspace(ls); + goto out; + } + kfree(ls->ls_device.name); + + lockspace = ls->ls_local_handle; + + /* dlm_release_lockspace waits for references to go to zero, + so all processes will need to close their device for the ls + before the release will procede */ + + dlm_put_lockspace(ls); + error = dlm_release_lockspace(lockspace, 0); +out: + return error; +} + +/* Check the user's version matches ours */ +static int check_version(struct dlm_write_request *req) +{ + if (req->version[0] != DLM_DEVICE_VERSION_MAJOR || + (req->version[0] == DLM_DEVICE_VERSION_MAJOR && + req->version[1] > DLM_DEVICE_VERSION_MINOR)) { + + printk(KERN_DEBUG "dlm: process %s (%d) version mismatch " + "user (%d.%d.%d) kernel (%d.%d.%d)\n", + current->comm, + current->pid, + req->version[0], + req->version[1], + req->version[2], + DLM_DEVICE_VERSION_MAJOR, + DLM_DEVICE_VERSION_MINOR, + DLM_DEVICE_VERSION_PATCH); + return -EINVAL; + } + return 0; +} + +/* + * device_write + * + * device_user_lock + * dlm_user_request -> request_lock + * dlm_user_convert -> convert_lock + * + * device_user_unlock + * dlm_user_unlock -> unlock_lock + * dlm_user_cancel -> cancel_lock + * + * device_create_lockspace + * dlm_new_lockspace + * + * device_remove_lockspace + * dlm_release_lockspace + */ + +/* a write to a lockspace device is a lock or unlock request, a write + to the control device is to create/remove a lockspace */ + +static ssize_t device_write(struct file *file, const char __user *buf, + size_t count, loff_t *ppos) +{ + struct dlm_user_proc *proc = file->private_data; + struct dlm_write_request *kbuf; + sigset_t tmpsig, allsigs; + int error; + +#ifdef CONFIG_COMPAT + if (count < sizeof(struct dlm_write_request32)) +#else + if (count < sizeof(struct dlm_write_request)) +#endif + return -EINVAL; + + kbuf = kmalloc(count, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + if (copy_from_user(kbuf, buf, count)) { + error = -EFAULT; + goto out_free; + } + + if (check_version(kbuf)) { + error = -EBADE; + goto out_free; + } + +#ifdef CONFIG_COMPAT + if (!kbuf->is64bit) { + struct dlm_write_request32 *k32buf; + k32buf = (struct dlm_write_request32 *)kbuf; + kbuf = kmalloc(count + (sizeof(struct dlm_write_request) - + sizeof(struct dlm_write_request32)), GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + if (proc) + set_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags); + compat_input(kbuf, k32buf); + kfree(k32buf); + } +#endif + + /* do we really need this? can a write happen after a close? */ + if ((kbuf->cmd == DLM_USER_LOCK || kbuf->cmd == DLM_USER_UNLOCK) && + test_bit(DLM_PROC_FLAGS_CLOSING, &proc->flags)) + return -EINVAL; + + sigfillset(&allsigs); + sigprocmask(SIG_BLOCK, &allsigs, &tmpsig); + + error = -EINVAL; + + switch (kbuf->cmd) + { + case DLM_USER_LOCK: + if (!proc) { + log_print("no locking on control device"); + goto out_sig; + } + error = device_user_lock(proc, &kbuf->i.lock); + break; + + case DLM_USER_UNLOCK: + if (!proc) { + log_print("no locking on control device"); + goto out_sig; + } + error = device_user_unlock(proc, &kbuf->i.lock); + break; + + case DLM_USER_CREATE_LOCKSPACE: + if (proc) { + log_print("create/remove only on control device"); + goto out_sig; + } + error = device_create_lockspace(&kbuf->i.lspace); + break; + + case DLM_USER_REMOVE_LOCKSPACE: + if (proc) { + log_print("create/remove only on control device"); + goto out_sig; + } + error = device_remove_lockspace(&kbuf->i.lspace); + break; + + default: + log_print("Unknown command passed to DLM device : %d\n", + kbuf->cmd); + } + + out_sig: + sigprocmask(SIG_SETMASK, &tmpsig, NULL); + recalc_sigpending(); + out_free: + kfree(kbuf); + return error; +} + +/* Every process that opens the lockspace device has its own "proc" structure + hanging off the open file that's used to keep track of locks owned by the + process and asts that need to be delivered to the process. */ + +static int device_open(struct inode *inode, struct file *file) +{ + struct dlm_user_proc *proc; + struct dlm_ls *ls; + + ls = dlm_find_lockspace_device(iminor(inode)); + if (!ls) + return -ENOENT; + + proc = kzalloc(sizeof(struct dlm_user_proc), GFP_KERNEL); + if (!proc) { + dlm_put_lockspace(ls); + return -ENOMEM; + } + + proc->lockspace = ls->ls_local_handle; + INIT_LIST_HEAD(&proc->asts); + INIT_LIST_HEAD(&proc->locks); + spin_lock_init(&proc->asts_spin); + spin_lock_init(&proc->locks_spin); + init_waitqueue_head(&proc->wait); + file->private_data = proc; + + return 0; +} + +static int device_close(struct inode *inode, struct file *file) +{ + struct dlm_user_proc *proc = file->private_data; + struct dlm_ls *ls; + sigset_t tmpsig, allsigs; + + ls = dlm_find_lockspace_local(proc->lockspace); + if (!ls) + return -ENOENT; + + sigfillset(&allsigs); + sigprocmask(SIG_BLOCK, &allsigs, &tmpsig); + + set_bit(DLM_PROC_FLAGS_CLOSING, &proc->flags); + + dlm_clear_proc_locks(ls, proc); + + /* at this point no more lkb's should exist for this lockspace, + so there's no chance of dlm_user_add_ast() being called and + looking for lkb->ua->proc */ + + kfree(proc); + file->private_data = NULL; + + dlm_put_lockspace(ls); + dlm_put_lockspace(ls); /* for the find in device_open() */ + + /* FIXME: AUTOFREE: if this ls is no longer used do + device_remove_lockspace() */ + + sigprocmask(SIG_SETMASK, &tmpsig, NULL); + recalc_sigpending(); + + return 0; +} + +static int copy_result_to_user(struct dlm_user_args *ua, int compat, int type, + int bmode, char __user *buf, size_t count) +{ +#ifdef CONFIG_COMPAT + struct dlm_lock_result32 result32; +#endif + struct dlm_lock_result result; + void *resultptr; + int error=0; + int len; + int struct_len; + + memset(&result, 0, sizeof(struct dlm_lock_result)); + memcpy(&result.lksb, &ua->lksb, sizeof(struct dlm_lksb)); + result.user_lksb = ua->user_lksb; + + /* FIXME: dlm1 provides for the user's bastparam/addr to not be updated + in a conversion unless the conversion is successful. See code + in dlm_user_convert() for updating ua from ua_tmp. OpenVMS, though, + notes that a new blocking AST address and parameter are set even if + the conversion fails, so maybe we should just do that. */ + + if (type == AST_BAST) { + result.user_astaddr = ua->bastaddr; + result.user_astparam = ua->bastparam; + result.bast_mode = bmode; + } else { + result.user_astaddr = ua->castaddr; + result.user_astparam = ua->castparam; + } + +#ifdef CONFIG_COMPAT + if (compat) + len = sizeof(struct dlm_lock_result32); + else +#endif + len = sizeof(struct dlm_lock_result); + struct_len = len; + + /* copy lvb to userspace if there is one, it's been updated, and + the user buffer has space for it */ + + if (ua->update_user_lvb && ua->lksb.sb_lvbptr && + count >= len + DLM_USER_LVB_LEN) { + if (copy_to_user(buf+len, ua->lksb.sb_lvbptr, + DLM_USER_LVB_LEN)) { + error = -EFAULT; + goto out; + } + + result.lvb_offset = len; + len += DLM_USER_LVB_LEN; + } + + result.length = len; + resultptr = &result; +#ifdef CONFIG_COMPAT + if (compat) { + compat_output(&result, &result32); + resultptr = &result32; + } +#endif + + if (copy_to_user(buf, resultptr, struct_len)) + error = -EFAULT; + else + error = len; + out: + return error; +} + +/* a read returns a single ast described in a struct dlm_lock_result */ + +static ssize_t device_read(struct file *file, char __user *buf, size_t count, + loff_t *ppos) +{ + struct dlm_user_proc *proc = file->private_data; + struct dlm_lkb *lkb; + struct dlm_user_args *ua; + DECLARE_WAITQUEUE(wait, current); + int error, type=0, bmode=0, removed = 0; + +#ifdef CONFIG_COMPAT + if (count < sizeof(struct dlm_lock_result32)) +#else + if (count < sizeof(struct dlm_lock_result)) +#endif + return -EINVAL; + + /* do we really need this? can a read happen after a close? */ + if (test_bit(DLM_PROC_FLAGS_CLOSING, &proc->flags)) + return -EINVAL; + + spin_lock(&proc->asts_spin); + if (list_empty(&proc->asts)) { + if (file->f_flags & O_NONBLOCK) { + spin_unlock(&proc->asts_spin); + return -EAGAIN; + } + + add_wait_queue(&proc->wait, &wait); + + repeat: + set_current_state(TASK_INTERRUPTIBLE); + if (list_empty(&proc->asts) && !signal_pending(current)) { + spin_unlock(&proc->asts_spin); + schedule(); + spin_lock(&proc->asts_spin); + goto repeat; + } + set_current_state(TASK_RUNNING); + remove_wait_queue(&proc->wait, &wait); + + if (signal_pending(current)) { + spin_unlock(&proc->asts_spin); + return -ERESTARTSYS; + } + } + + if (list_empty(&proc->asts)) { + spin_unlock(&proc->asts_spin); + return -EAGAIN; + } + + /* there may be both completion and blocking asts to return for + the lkb, don't remove lkb from asts list unless no asts remain */ + + lkb = list_entry(proc->asts.next, struct dlm_lkb, lkb_astqueue); + + if (lkb->lkb_ast_type & AST_COMP) { + lkb->lkb_ast_type &= ~AST_COMP; + type = AST_COMP; + } else if (lkb->lkb_ast_type & AST_BAST) { + lkb->lkb_ast_type &= ~AST_BAST; + type = AST_BAST; + bmode = lkb->lkb_bastmode; + } + + if (!lkb->lkb_ast_type) { + list_del(&lkb->lkb_astqueue); + removed = 1; + } + spin_unlock(&proc->asts_spin); + + ua = (struct dlm_user_args *)lkb->lkb_astparam; + error = copy_result_to_user(ua, + test_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags), + type, bmode, buf, count); + + /* removes reference for the proc->asts lists added by + dlm_user_add_ast() and may result in the lkb being freed */ + if (removed) + dlm_put_lkb(lkb); + + return error; +} + +static unsigned int device_poll(struct file *file, poll_table *wait) +{ + struct dlm_user_proc *proc = file->private_data; + + poll_wait(file, &proc->wait, wait); + + spin_lock(&proc->asts_spin); + if (!list_empty(&proc->asts)) { + spin_unlock(&proc->asts_spin); + return POLLIN | POLLRDNORM; + } + spin_unlock(&proc->asts_spin); + return 0; +} + +static int ctl_device_open(struct inode *inode, struct file *file) +{ + file->private_data = NULL; + return 0; +} + +static int ctl_device_close(struct inode *inode, struct file *file) +{ + return 0; +} + +static struct file_operations device_fops = { + .open = device_open, + .release = device_close, + .read = device_read, + .write = device_write, + .poll = device_poll, + .owner = THIS_MODULE, +}; + +static struct file_operations ctl_device_fops = { + .open = ctl_device_open, + .release = ctl_device_close, + .write = device_write, + .owner = THIS_MODULE, +}; + +int dlm_user_init(void) +{ + int error; + + ctl_device.name = "dlm-control"; + ctl_device.fops = &ctl_device_fops; + ctl_device.minor = MISC_DYNAMIC_MINOR; + + error = misc_register(&ctl_device); + if (error) + log_print("misc_register failed for control device"); + + return error; +} + +void dlm_user_exit(void) +{ + misc_deregister(&ctl_device); +} + diff --git a/fs/dlm/user.h b/fs/dlm/user.h new file mode 100644 index 000000000000..d38e9f3e4151 --- /dev/null +++ b/fs/dlm/user.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2006 Red Hat, Inc. All rights reserved. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.2. + */ + +#ifndef __USER_DOT_H__ +#define __USER_DOT_H__ + +void dlm_user_add_ast(struct dlm_lkb *lkb, int type); +int dlm_user_init(void); +void dlm_user_exit(void); + +#endif From 634ee0b9f458f3530b9c0ea7e6951dd03db7d678 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 17 Jul 2006 09:32:37 -0400 Subject: [PATCH 164/292] [GFS2] Fix use after free bug in dir.c Fix a use after free bug in dir.c spotted by Kevin Anderson. Cc: Kevin Anderson Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index e96b5322c843..f62223b9e53d 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -1763,9 +1763,8 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) if (error) goto out; leaf = (struct gfs2_leaf *)bh->b_data; - brelse(bh); - len = 1 << (dip->i_di.di_depth - be16_to_cpu(leaf->lf_depth)); + brelse(bh); error = lc(dip, index, len, leaf_no, data); if (error) @@ -1781,7 +1780,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) error = -EIO; } - out: +out: kfree(lp); return error; From e0f2bf780a970f7aae9263db2e14149132671cf2 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 17 Jul 2006 09:36:28 -0400 Subject: [PATCH 165/292] [GFS2] Fix endian conversion bug Fix an endian coversion bug in log.c spotted by Kevin Anderson. Cc: Kevin Anderson Signed-off-by: Steven Whitehouse --- fs/gfs2/log.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 1596e9436c42..60fdc94ccc8a 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -386,10 +386,10 @@ static void log_write_header(struct gfs2_sbd *sdp, uint32_t flags, int pull) lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH); lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH); - lh->lh_sequence = be64_to_cpu(sdp->sd_log_sequence++); - lh->lh_flags = be32_to_cpu(flags); - lh->lh_tail = be32_to_cpu(tail); - lh->lh_blkno = be32_to_cpu(sdp->sd_log_flush_head); + lh->lh_sequence = cpu_to_be64(sdp->sd_log_sequence++); + lh->lh_flags = cpu_to_be32(flags); + lh->lh_tail = cpu_to_be32(tail); + lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head); hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header)); lh->lh_hash = cpu_to_be32(hash); From 3b4a0a74949cf4f87f7ca84cc0457eb5687b2923 Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Sat, 15 Jul 2006 02:36:31 +0200 Subject: [PATCH 166/292] [DLM] [RFC: -mm patch] fs/dlm/lock.c: unexport dlm_lvb_operations On Thu, Jul 13, 2006 at 10:48:00PM -0700, Andrew Morton wrote: >... > Changes since 2.6.18-rc1-mm1: >... > git-gfs2.patch >... > git trees. >... This patch removes the unused EXPORT_SYMBOL_GPL(dlm_lvb_operations). Signed-off-by: Adrian Bunk Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 4e222f873b6c..82e1ac251843 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -128,7 +128,6 @@ const int dlm_lvb_operations[8][8] = { { -1, 0, 0, 0, 0, 0, 0, 0 }, /* EX */ { -1, 0, 0, 0, 0, 0, 0, 0 } /* PD */ }; -EXPORT_SYMBOL_GPL(dlm_lvb_operations); #define modes_compat(gr, rq) \ __dlm_compat_matrix[(gr)->lkb_grmode + 1][(rq)->lkb_rqmode + 1] From 34e22bed19013c77f942083e25cfc7adf6c71a8f Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 18 Jul 2006 11:24:04 -0500 Subject: [PATCH 167/292] [DLM] fix leaking user locks User NOQUEUE lock requests to a remote node that failed with -EAGAIN were never being removed from a process's list of locks. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 7 ++++--- fs/dlm/user.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 82e1ac251843..227443218167 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -526,6 +526,7 @@ static int create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret) lkb->lkb_nodeid = -1; lkb->lkb_grmode = DLM_LOCK_IV; kref_init(&lkb->lkb_ref); + INIT_LIST_HEAD(&lkb->lkb_ownqueue); get_random_bytes(&bucket, sizeof(bucket)); bucket &= (ls->ls_lkbtbl_size - 1); @@ -3705,7 +3706,7 @@ int dlm_user_unlock(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, goto out_put; spin_lock(&ua->proc->locks_spin); - list_del(&lkb->lkb_ownqueue); + list_del_init(&lkb->lkb_ownqueue); spin_unlock(&ua->proc->locks_spin); /* this removes the reference for the proc->locks list added by @@ -3749,7 +3750,7 @@ int dlm_user_cancel(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, /* this lkb was removed from the WAITING queue */ if (lkb->lkb_grmode == DLM_LOCK_IV) { spin_lock(&ua->proc->locks_spin); - list_del(&lkb->lkb_ownqueue); + list_del_init(&lkb->lkb_ownqueue); spin_unlock(&ua->proc->locks_spin); unhold_lkb(lkb); } @@ -3817,7 +3818,7 @@ void dlm_clear_proc_locks(struct dlm_ls *ls, struct dlm_user_proc *proc) unhold_lkb(lkb); } - list_del(&lkb->lkb_ownqueue); + list_del_init(&lkb->lkb_ownqueue); if (lkb->lkb_exflags & DLM_LKF_PERSISTENT) { lkb->lkb_flags |= DLM_IFL_ORPHAN; diff --git a/fs/dlm/user.c b/fs/dlm/user.c index 1f05960a916f..fd19caf9af97 100644 --- a/fs/dlm/user.c +++ b/fs/dlm/user.c @@ -133,6 +133,7 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, int type) struct dlm_ls *ls; struct dlm_user_args *ua; struct dlm_user_proc *proc; + int remove_ownqueue = 0; /* dlm_clear_proc_locks() sets ORPHAN/DEAD flag on each lkb before dealing with it. We need to check this @@ -171,6 +172,14 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, int type) wake_up_interruptible(&proc->wait); } + /* noqueue requests that fail may need to be removed from the + proc's locks list, there should be a better way of detecting + this situation than checking all these things... */ + + if (type == AST_COMP && lkb->lkb_grmode == DLM_LOCK_IV && + ua->lksb.sb_status == -EAGAIN && !list_empty(&lkb->lkb_ownqueue)) + remove_ownqueue = 1; + /* We want to copy the lvb to userspace when the completion ast is read if the status is 0, the lock has an lvb and lvb_ops says we should. We could probably have set_lvb_lock() @@ -185,6 +194,13 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, int type) ua->update_user_lvb = 0; spin_unlock(&proc->asts_spin); + + if (remove_ownqueue) { + spin_lock(&ua->proc->locks_spin); + list_del_init(&lkb->lkb_ownqueue); + spin_unlock(&ua->proc->locks_spin); + dlm_put_lkb(lkb); + } out: mutex_unlock(&ls->ls_clear_proc_locks); } From 36098198184b0644537f4b2257d861e9bdf124bd Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 20 Jul 2006 08:35:39 -0500 Subject: [PATCH 168/292] [DLM] fix whitespace damage My previous dlm patch added trailing whitespace damage, fix that. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/dlm/user.c b/fs/dlm/user.c index fd19caf9af97..494d00ac014e 100644 --- a/fs/dlm/user.c +++ b/fs/dlm/user.c @@ -175,7 +175,7 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, int type) /* noqueue requests that fail may need to be removed from the proc's locks list, there should be a better way of detecting this situation than checking all these things... */ - + if (type == AST_COMP && lkb->lkb_grmode == DLM_LOCK_IV && ua->lksb.sb_status == -EAGAIN && !list_empty(&lkb->lkb_ownqueue)) remove_ownqueue = 1; From c5921fd02e6c720938141a45f1f9dbd71b17fff2 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 20 Jul 2006 09:06:34 -0500 Subject: [PATCH 169/292] [GFS2] fix typo in locking/dlm Typo causes the error value from the wrong lock to be checked. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index e74f1215672f..f769eac1a34a 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -430,7 +430,7 @@ static int hold_null_lock(struct gdlm_lock *lp) init_completion(&lpn->ast_wait); gdlm_do_lock(lpn); wait_for_completion(&lpn->ast_wait); - error = lp->lksb.sb_status; + error = lpn->lksb.sb_status; if (error) { printk(KERN_INFO "lock_dlm: hold_null_lock dlm error %d\n", error); From 52f341cf75d2da84811127582616984eb0602360 Mon Sep 17 00:00:00 2001 From: Abhijith Das Date: Fri, 21 Jul 2006 02:03:21 -0400 Subject: [PATCH 170/292] [GFS2] gfs2_set_flags double locking patch traced the "umount hang due to spurious glock" issue that I was having with gfs2meta. It's in the do_gfs2_set_flags function, which does a gfs2_holder_init as well as a gfs2_glock_nq_init (increases ref count by 2 instead of 1). Signed-off-by: Abhijith Das Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 26f1d3249b0f..6764ca69bc52 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -608,12 +608,9 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) int error; u32 new_flags, flags; - gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); - if (error) { - gfs2_holder_uninit(&gh); + if (error) return error; - } flags = ip->i_di.di_flags; new_flags = (flags & ~mask) | (reqflags & mask); From a9e5f4d0780ec9cda7a70b08294d7718431b62a1 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 25 Jul 2006 17:24:12 -0400 Subject: [PATCH 171/292] [GFS2] Alter direct I/O path As per comments received, alter the GFS2 direct I/O path so that it uses the standard read functions "out of the box". Needs a small change to one of the VFS functions. This reduces the size of the code quite a lot and also removes the need for one new export. Some more work remains to be done, but this is the bones of the thing. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 54 ++++---------- fs/gfs2/ops_file.c | 170 +----------------------------------------- mm/filemap.c | 4 +- 3 files changed, 21 insertions(+), 207 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 031270ad55e2..d33f6aa79731 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -589,8 +589,9 @@ static void gfs2_invalidatepage(struct page *page, unsigned long offset) return; } -static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov, - loff_t offset, unsigned long nr_segs) +static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, + const struct iovec *iov, loff_t offset, + unsigned long nr_segs) { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; @@ -598,8 +599,10 @@ static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov, struct gfs2_holder gh; int rv; + if (rw == READ) + mutex_lock(&inode->i_mutex); /* - * Shared lock, even though its write, since we do no allocation + * Shared lock, even if its a write, since we do no allocation * on this path. All we need change is atime. */ gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); @@ -607,6 +610,9 @@ static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov, if (rv) goto out; + if (offset > i_size_read(inode)) + goto out; + /* * Should we return an error here? I can't see that O_DIRECT for * a journaled file makes any sense. For now we'll silently fall @@ -619,47 +625,19 @@ static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov, if (gfs2_is_stuffed(ip)) goto out; - rv = __blockdev_direct_IO(WRITE, iocb, inode, inode->i_sb->s_bdev, - iov, offset, nr_segs, gfs2_get_block, - NULL, DIO_OWN_LOCKING); + rv = blockdev_direct_IO_own_locking(rw, iocb, inode, + inode->i_sb->s_bdev, + iov, offset, nr_segs, + gfs2_get_block, NULL); out: gfs2_glock_dq_m(1, &gh); gfs2_holder_uninit(&gh); + if (rw == READ) + mutex_unlock(&inode->i_mutex); return rv; } -/** - * gfs2_direct_IO - * - * This is called with a shared lock already held for the read path. - * Currently, no locks are held when the write path is called. - */ -static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, - const struct iovec *iov, loff_t offset, - unsigned long nr_segs) -{ - struct file *file = iocb->ki_filp; - struct inode *inode = file->f_mapping->host; - struct gfs2_inode *ip = GFS2_I(inode); - struct gfs2_sbd *sdp = GFS2_SB(inode); - int ret; - - if (rw == WRITE) - return gfs2_direct_IO_write(iocb, iov, offset, nr_segs); - - if (gfs2_assert_warn(sdp, gfs2_glock_is_locked_by_me(ip->i_gl)) || - gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) - return -EINVAL; - - mutex_lock(&inode->i_mutex); - ret = __blockdev_direct_IO(READ, iocb, inode, inode->i_sb->s_bdev, iov, - offset, nr_segs, gfs2_get_block, NULL, - DIO_OWN_LOCKING); - mutex_unlock(&inode->i_mutex); - return ret; -} - /** * stuck_releasepage - We're stuck in gfs2_releasepage(). Print stuff out. * @bh: the buffer we're stuck on @@ -765,7 +743,7 @@ int gfs2_releasepage(struct page *page, gfp_t gfp_mask) } while (bh != head); - out: +out: return try_to_free_buffers(page); } diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 6764ca69bc52..d13e04e8a96a 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -148,170 +148,6 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) return error; } - -static ssize_t gfs2_direct_IO_read(struct kiocb *iocb, const struct iovec *iov, - loff_t offset, unsigned long nr_segs) -{ - struct file *file = iocb->ki_filp; - struct address_space *mapping = file->f_mapping; - ssize_t retval; - - retval = filemap_write_and_wait(mapping); - if (retval == 0) { - retval = mapping->a_ops->direct_IO(READ, iocb, iov, offset, - nr_segs); - } - return retval; -} - -/** - * __gfs2_file_aio_read - The main GFS2 read function - * - * N.B. This is almost, but not quite the same as __generic_file_aio_read() - * the important subtle different being that inode->i_size isn't valid - * unless we are holding a lock, and we do this _only_ on the O_DIRECT - * path since otherwise locking is done entirely at the page cache - * layer. - */ -static ssize_t __gfs2_file_aio_read(struct kiocb *iocb, - const struct iovec *iov, - unsigned long nr_segs, loff_t *ppos) -{ - struct file *filp = iocb->ki_filp; - struct gfs2_inode *ip = GFS2_I(filp->f_mapping->host); - struct gfs2_holder gh; - ssize_t retval; - unsigned long seg; - size_t count; - - count = 0; - for (seg = 0; seg < nr_segs; seg++) { - const struct iovec *iv = &iov[seg]; - - /* - * If any segment has a negative length, or the cumulative - * length ever wraps negative then return -EINVAL. - */ - count += iv->iov_len; - if (unlikely((ssize_t)(count|iv->iov_len) < 0)) - return -EINVAL; - if (access_ok(VERIFY_WRITE, iv->iov_base, iv->iov_len)) - continue; - if (seg == 0) - return -EFAULT; - nr_segs = seg; - count -= iv->iov_len; /* This segment is no good */ - break; - } - - /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ - if (filp->f_flags & O_DIRECT) { - loff_t pos = *ppos, size; - struct address_space *mapping; - struct inode *inode; - - mapping = filp->f_mapping; - inode = mapping->host; - retval = 0; - if (!count) - goto out; /* skip atime */ - - gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); - retval = gfs2_glock_nq_m_atime(1, &gh); - if (retval) - goto out; - if (gfs2_is_stuffed(ip)) { - gfs2_glock_dq_m(1, &gh); - gfs2_holder_uninit(&gh); - goto fallback_to_normal; - } - size = i_size_read(inode); - if (pos < size) { - retval = gfs2_direct_IO_read(iocb, iov, pos, nr_segs); - if (retval > 0 && !is_sync_kiocb(iocb)) - retval = -EIOCBQUEUED; - if (retval > 0) - *ppos = pos + retval; - } - file_accessed(filp); - gfs2_glock_dq_m(1, &gh); - gfs2_holder_uninit(&gh); - goto out; - } - -fallback_to_normal: - retval = 0; - if (count) { - for (seg = 0; seg < nr_segs; seg++) { - read_descriptor_t desc; - - desc.written = 0; - desc.arg.buf = iov[seg].iov_base; - desc.count = iov[seg].iov_len; - if (desc.count == 0) - continue; - desc.error = 0; - do_generic_file_read(filp,ppos,&desc,file_read_actor); - retval += desc.written; - if (desc.error) { - retval = retval ?: desc.error; - break; - } - } - } -out: - return retval; -} - -/** - * gfs2_read - Read bytes from a file - * @file: The file to read from - * @buf: The buffer to copy into - * @size: The amount of data requested - * @offset: The current file offset - * - * Outputs: Offset - updated according to number of bytes read - * - * Returns: The number of bytes read, errno on failure - */ - -static ssize_t gfs2_read(struct file *filp, char __user *buf, size_t size, - loff_t *offset) -{ - struct iovec local_iov = { .iov_base = buf, .iov_len = size }; - struct kiocb kiocb; - ssize_t ret; - - init_sync_kiocb(&kiocb, filp); - ret = __gfs2_file_aio_read(&kiocb, &local_iov, 1, offset); - if (-EIOCBQUEUED == ret) - ret = wait_on_sync_kiocb(&kiocb); - return ret; -} - -static ssize_t gfs2_file_readv(struct file *filp, const struct iovec *iov, - unsigned long nr_segs, loff_t *ppos) -{ - struct kiocb kiocb; - ssize_t ret; - - init_sync_kiocb(&kiocb, filp); - ret = __gfs2_file_aio_read(&kiocb, iov, nr_segs, ppos); - if (-EIOCBQUEUED == ret) - ret = wait_on_sync_kiocb(&kiocb); - return ret; -} - -static ssize_t gfs2_file_aio_read(struct kiocb *iocb, char __user *buf, - size_t count, loff_t pos) -{ - struct iovec local_iov = { .iov_base = buf, .iov_len = count }; - - BUG_ON(iocb->ki_pos != pos); - return __gfs2_file_aio_read(iocb, &local_iov, 1, &iocb->ki_pos); -} - - /** * filldir_reg_func - Report a directory entry to the caller of gfs2_dir_read() * @opaque: opaque data used by the function @@ -949,9 +785,9 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) const struct file_operations gfs2_file_fops = { .llseek = gfs2_llseek, - .read = gfs2_read, - .readv = gfs2_file_readv, - .aio_read = gfs2_file_aio_read, + .read = generic_file_read, + .readv = generic_file_readv, + .aio_read = generic_file_aio_read, .write = generic_file_write, .writev = generic_file_writev, .aio_write = generic_file_aio_write, diff --git a/mm/filemap.c b/mm/filemap.c index b9c91ab7f0f8..a92d690b3ae5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1122,7 +1122,6 @@ success: desc->arg.buf += size; return size; } -EXPORT_SYMBOL_GPL(file_read_actor); /** * __generic_file_aio_read - generic filesystem read routine @@ -1184,7 +1183,8 @@ __generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov, *ppos = pos + retval; } file_accessed(filp); - goto out; + if (retval != 0) + goto out; } retval = 0; From 5de6319b1839300ba6b461ed19531cdab90db9fc Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 25 Jul 2006 13:44:31 -0500 Subject: [PATCH 172/292] [DLM] more info through debugfs Display more information from debugfs, particularly locks waiting for a master lookup or operations waiting for a remote reply. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/debug_fs.c | 132 +++++++++++++++++++++++++++++++++++------- fs/dlm/dlm_internal.h | 3 +- fs/dlm/lockspace.c | 3 +- 3 files changed, 114 insertions(+), 24 deletions(-) diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index 49deca845dba..5faa747c7ca1 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -18,6 +18,9 @@ #include "dlm_internal.h" +#define DLM_DEBUG_BUF_LEN 4096 +static char debug_buf[DLM_DEBUG_BUF_LEN]; +static struct mutex debug_buf_lock; static struct dentry *dlm_root; @@ -28,6 +31,10 @@ struct rsb_iter { struct dlm_rsb *rsb; }; +/* + * dump all rsb's in the lockspace hash table + */ + static char *print_lockmode(int mode) { switch (mode) { @@ -76,7 +83,7 @@ static void print_lock(struct seq_file *s, struct dlm_lkb *lkb, static int print_resource(struct dlm_rsb *res, struct seq_file *s) { struct dlm_lkb *lkb; - int i, lvblen = res->res_ls->ls_lvblen; + int i, lvblen = res->res_ls->ls_lvblen, recover_list, root_list; seq_printf(s, "\nResource %p Name (len=%d) \"", res, res->res_length); for (i = 0; i < res->res_length; i++) { @@ -110,6 +117,15 @@ static int print_resource(struct dlm_rsb *res, struct seq_file *s) seq_printf(s, "\n"); } + root_list = !list_empty(&res->res_root_list); + recover_list = !list_empty(&res->res_recover_list); + + if (root_list || recover_list) { + seq_printf(s, "Recovery: root %d recover %d flags %lx " + "count %d\n", root_list, recover_list, + res->flags, res->res_recover_locks_count); + } + /* Print the locks attached to this resource */ seq_printf(s, "Granted Queue\n"); list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue) @@ -123,6 +139,18 @@ static int print_resource(struct dlm_rsb *res, struct seq_file *s) list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue) print_lock(s, lkb, res); + if (list_empty(&res->res_lookup)) + goto out; + + seq_printf(s, "Lookup Queue\n"); + list_for_each_entry(lkb, &res->res_lookup, lkb_rsb_lookup) { + seq_printf(s, "%08x %s", lkb->lkb_id, + print_lockmode(lkb->lkb_rqmode)); + if (lkb->lkb_wait_type) + seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); + seq_printf(s, "\n"); + } + out: return 0; } @@ -190,7 +218,7 @@ static struct rsb_iter *rsb_iter_init(struct dlm_ls *ls) return ri; } -static void *seq_start(struct seq_file *file, loff_t *pos) +static void *rsb_seq_start(struct seq_file *file, loff_t *pos) { struct rsb_iter *ri; loff_t n = *pos; @@ -209,7 +237,7 @@ static void *seq_start(struct seq_file *file, loff_t *pos) return ri; } -static void *seq_next(struct seq_file *file, void *iter_ptr, loff_t *pos) +static void *rsb_seq_next(struct seq_file *file, void *iter_ptr, loff_t *pos) { struct rsb_iter *ri = iter_ptr; @@ -223,12 +251,12 @@ static void *seq_next(struct seq_file *file, void *iter_ptr, loff_t *pos) return ri; } -static void seq_stop(struct seq_file *file, void *iter_ptr) +static void rsb_seq_stop(struct seq_file *file, void *iter_ptr) { /* nothing for now */ } -static int seq_show(struct seq_file *file, void *iter_ptr) +static int rsb_seq_show(struct seq_file *file, void *iter_ptr) { struct rsb_iter *ri = iter_ptr; @@ -237,19 +265,19 @@ static int seq_show(struct seq_file *file, void *iter_ptr) return 0; } -static struct seq_operations dlm_seq_ops = { - .start = seq_start, - .next = seq_next, - .stop = seq_stop, - .show = seq_show, +static struct seq_operations rsb_seq_ops = { + .start = rsb_seq_start, + .next = rsb_seq_next, + .stop = rsb_seq_stop, + .show = rsb_seq_show, }; -static int do_open(struct inode *inode, struct file *file) +static int rsb_open(struct inode *inode, struct file *file) { struct seq_file *seq; int ret; - ret = seq_open(file, &dlm_seq_ops); + ret = rsb_seq_open(file, &rsb_seq_ops); if (ret) return ret; @@ -259,32 +287,92 @@ static int do_open(struct inode *inode, struct file *file) return 0; } -static struct file_operations dlm_fops = { +static struct file_operations rsb_fops = { .owner = THIS_MODULE, - .open = do_open, + .open = rsb_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release }; +/* + * dump lkb's on the ls_waiters list + */ + +static int waiters_open(struct inode *inode, struct file *file) +{ + file->private_data = inode->i_private; + return 0; +} + +static ssize_t waiters_read(struct file *file, char __user *userbuf, + size_t count, loff_t *ppos) +{ + struct dlm_ls *ls = file->private_data; + struct dlm_lkb *lkb; + size_t len = DLM_DEBUG_BUF_LEN, pos = 0, rv; + + mutex_lock(&debug_buf_lock); + mutex_lock(&ls->ls_waiters_mutex); + memset(debug_buf, 0, sizeof(debug_buf)); + + list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) { + pos += snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n", + lkb->lkb_id, lkb->lkb_wait_type, + lkb->lkb_nodeid, lkb->lkb_resource->res_name); + } + mutex_unlock(&ls->ls_waiters_mutex); + + rv = simple_read_from_buffer(userbuf, count, ppos, debug_buf, pos); + mutex_unlock(&debug_buf_lock); + return rv; +} + +static struct file_operations waiters_fops = { + .owner = THIS_MODULE, + .open = waiters_open, + .read = waiters_read +}; + int dlm_create_debug_file(struct dlm_ls *ls) { - ls->ls_debug_dentry = debugfs_create_file(ls->ls_name, - S_IFREG | S_IRUGO, - dlm_root, - ls, - &dlm_fops); - return ls->ls_debug_dentry ? 0 : -ENOMEM; + char name[DLM_LOCKSPACE_LEN+8]; + + ls->ls_debug_rsb_dentry = debugfs_create_file(ls->ls_name, + S_IFREG | S_IRUGO, + dlm_root, + ls, + &rsb_fops); + if (!ls->ls_rsb_debug_dentry) + return -ENOMEM; + + memset(name, 0, sizeof(name)); + snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_waiters", ls->ls_name); + + ls->ls_debug_waiters_dentry = debugfs_create_file(name, + S_IFREG | S_IRUGO, + dlm_root, + ls, + &waiters_fops); + if (!ls->ls_debug_waiters_dentry) { + debugfs_remove(ls->ls_debug_rsb_dentry); + return -ENOMEM; + } + + return 0; } void dlm_delete_debug_file(struct dlm_ls *ls) { - if (ls->ls_debug_dentry) - debugfs_remove(ls->ls_debug_dentry); + if (ls->ls_debug_rsb_dentry) + debugfs_remove(ls->ls_debug_rsb_dentry); + if (ls->ls_debug_waiters_dentry) + debugfs_remove(ls->ls_debug_waiters_dentry); } int dlm_register_debugfs(void) { + mutex_init(&debug_buf_lock); dlm_root = debugfs_create_dir("dlm", NULL); return dlm_root ? 0 : -ENOMEM; } diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index db080de2a7e9..7c3c2d27c012 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -446,7 +446,8 @@ struct dlm_ls { struct dlm_lkb ls_stub_lkb; /* for returning errors */ struct dlm_message ls_stub_ms; /* for faking a reply */ - struct dentry *ls_debug_dentry; /* debugfs */ + struct dentry *ls_debug_rsb_dentry; /* debugfs */ + struct dentry *ls_debug_waiters_dentry; /* debugfs */ wait_queue_head_t ls_uevent_wait; /* user part of join/leave */ int ls_uevent_result; diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index 3f6cb422ac4b..31ed0fe16a31 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -446,7 +446,8 @@ static int new_lockspace(char *name, int namelen, void **lockspace, memset(&ls->ls_stub_rsb, 0, sizeof(struct dlm_rsb)); ls->ls_stub_rsb.res_ls = ls; - ls->ls_debug_dentry = NULL; + ls->ls_debug_rsb_dentry = NULL; + ls->ls_debug_waiters_dentry = NULL; init_waitqueue_head(&ls->ls_uevent_wait); ls->ls_uevent_result = 0; From f7da790d743d2f0b4f39e4fa442079b3b54f3bef Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 25 Jul 2006 13:53:33 -0500 Subject: [PATCH 173/292] [DLM] set purged flag on rsbs If a node becomes the new master of an rsb during recovery, the LOCKS_PURGED flag needs to be set on it so that any waiting/converting locks will try to be granted. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/recover.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/dlm/recover.c b/fs/dlm/recover.c index 34876f60f298..1a86dfc8034e 100644 --- a/fs/dlm/recover.c +++ b/fs/dlm/recover.c @@ -305,7 +305,8 @@ static void set_master_lkbs(struct dlm_rsb *r) /* * Propogate the new master nodeid to locks * The NEW_MASTER flag tells dlm_recover_locks() which rsb's to consider. - * The NEW_MASTER2 flag tells recover_lvb() which rsb's to consider. + * The NEW_MASTER2 flag tells recover_lvb() and set_locks_purged() which + * rsb's to consider. */ static void set_new_master(struct dlm_rsb *r, int nodeid) @@ -681,6 +682,16 @@ static void recover_conversion(struct dlm_rsb *r) } } +/* We've become the new master for this rsb and waiting/converting locks may + need to be granted in dlm_grant_after_purge() due to locks that may have + existed from a removed node. */ + +static void set_locks_purged(struct dlm_rsb *r) +{ + if (!list_empty(&r->res_waitqueue) || !list_empty(&r->res_convertqueue)) + rsb_set_flag(r, RSB_LOCKS_PURGED); +} + void dlm_recover_rsbs(struct dlm_ls *ls) { struct dlm_rsb *r; @@ -694,10 +705,13 @@ void dlm_recover_rsbs(struct dlm_ls *ls) if (is_master(r)) { if (rsb_flag(r, RSB_RECOVER_CONVERT)) recover_conversion(r); + if (rsb_flag(r, RSB_NEW_MASTER2)) + set_locks_purged(r); recover_lvb(r); count++; } rsb_clear_flag(r, RSB_RECOVER_CONVERT); + rsb_clear_flag(r, RSB_NEW_MASTER2); unlock_rsb(r); } up_read(&ls->ls_root_sem); From 2b4e926aab7c854a536beee6ba8b9a78a9e00316 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 25 Jul 2006 13:59:48 -0500 Subject: [PATCH 174/292] [DLM] fix loop in grant_after_purge The loop in grant_after_purge is intended to find all rsb's in each hash bucket that have the LOCKS_PURGED flag set. The loop was quitting the current bucket after finding just one rsb instead of going until there are no more. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 227443218167..eaad28e51ec9 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -3366,12 +3366,16 @@ static struct dlm_rsb *find_purged_rsb(struct dlm_ls *ls, int bucket) void dlm_grant_after_purge(struct dlm_ls *ls) { struct dlm_rsb *r; - int i; + int bucket = 0; - for (i = 0; i < ls->ls_rsbtbl_size; i++) { - r = find_purged_rsb(ls, i); - if (!r) + while (1) { + r = find_purged_rsb(ls, bucket); + if (!r) { + if (bucket == ls->ls_rsbtbl_size - 1) + break; + bucket++; continue; + } lock_rsb(r); if (is_master(r)) { grant_pending_locks(r); @@ -3379,6 +3383,7 @@ void dlm_grant_after_purge(struct dlm_ls *ls) } unlock_rsb(r); put_rsb(r); + schedule(); } } From 81456807a33c2122e2f1f92acfbaaa77b3d06c3c Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 25 Jul 2006 14:05:09 -0500 Subject: [PATCH 175/292] [DLM] schedule during long loop through locks The loop through all waiting locks in recover_waiters can potentially be long, so we should schedule explicitly. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index eaad28e51ec9..7d38f914c5b9 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -3193,6 +3193,7 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls) log_error(ls, "invalid lkb wait_type %d", lkb->lkb_wait_type); } + schedule(); } mutex_unlock(&ls->ls_waiters_mutex); } From f25ef0c1b4e032b2641857ac4cff3315c6eb90e3 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 26 Jul 2006 10:51:20 -0400 Subject: [PATCH 176/292] [GFS2] Tidy gfs2_unstuffer_page Tidy up gfs2_unstuffer_page by: a) Moving it into bmap.c b) Making it static c) Calling it directly from gfs2_unstuff_dinode d) Updating all callers of gfs2_unstuff_dinode due to one less required argument. It doesn't change the behaviour at all. Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 67 +++++++++++++++++++++++++++++++++++++++---- fs/gfs2/bmap.h | 7 +---- fs/gfs2/dir.c | 2 +- fs/gfs2/ops_address.c | 3 +- fs/gfs2/ops_vm.c | 2 +- fs/gfs2/page.c | 60 -------------------------------------- fs/gfs2/page.h | 2 -- 7 files changed, 66 insertions(+), 77 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 98fa07c2b710..72b19c5d7807 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -47,6 +47,65 @@ struct strip_mine { unsigned int sm_height; }; +/** + * gfs2_unstuffer_page - unstuff a stuffed inode into a block cached by a page + * @ip: the inode + * @dibh: the dinode buffer + * @block: the block number that was allocated + * @private: any locked page held by the caller process + * + * Returns: errno + */ + +static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, + uint64_t block, struct page *page) +{ + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); + struct inode *inode = &ip->i_inode; + struct buffer_head *bh; + int release = 0; + + if (!page || page->index) { + page = grab_cache_page(inode->i_mapping, 0); + if (!page) + return -ENOMEM; + release = 1; + } + + if (!PageUptodate(page)) { + void *kaddr = kmap(page); + + memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), + ip->i_di.di_size); + memset(kaddr + ip->i_di.di_size, 0, + PAGE_CACHE_SIZE - ip->i_di.di_size); + kunmap(page); + + SetPageUptodate(page); + } + + if (!page_has_buffers(page)) + create_empty_buffers(page, 1 << inode->i_blkbits, + (1 << BH_Uptodate)); + + bh = page_buffers(page); + + if (!buffer_mapped(bh)) + map_bh(bh, inode->i_sb, block); + + set_buffer_uptodate(bh); + if ((sdp->sd_args.ar_data == GFS2_DATA_ORDERED) || gfs2_is_jdata(ip)) + gfs2_trans_add_bh(ip->i_gl, bh, 0); + mark_buffer_dirty(bh); + + if (release) { + unlock_page(page); + page_cache_release(page); + } + + return 0; +} + /** * gfs2_unstuff_dinode - Unstuff a dinode when the data has grown too big * @ip: The GFS2 inode to unstuff @@ -59,8 +118,7 @@ struct strip_mine { * Returns: errno */ -int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, - void *private) +int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) { struct buffer_head *bh, *dibh; uint64_t block = 0; @@ -90,7 +148,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, } else { block = gfs2_alloc_data(ip); - error = unstuffer(ip, dibh, block, private); + error = gfs2_unstuffer_page(ip, dibh, block, page); if (error) goto out_brelse; } @@ -786,8 +844,7 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size) if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) { if (gfs2_is_stuffed(ip)) { - error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, - NULL); + error = gfs2_unstuff_dinode(ip, NULL); if (error) goto out_end_trans; } diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index 06ccb2d808ad..1a265412f7ee 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -10,12 +10,7 @@ #ifndef __BMAP_DOT_H__ #define __BMAP_DOT_H__ -typedef int (*gfs2_unstuffer_t) (struct gfs2_inode * ip, - struct buffer_head * dibh, uint64_t block, - void *private); -int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer, - void *private); - +int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page); int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *boundary); int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen); diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index f62223b9e53d..563b99e419b6 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -173,7 +173,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, return -EINVAL; if (gfs2_is_stuffed(ip)) { - error = gfs2_unstuff_dinode(ip, NULL, NULL); + error = gfs2_unstuff_dinode(ip, NULL); if (error) return error; } diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index d33f6aa79731..93e00a8af8cf 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -395,8 +395,7 @@ static int gfs2_prepare_write(struct file *file, struct page *page, if (gfs2_is_stuffed(ip)) { if (end > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) { - error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, - page); + error = gfs2_unstuff_dinode(ip, page); if (error == 0) goto prepare_write; } else if (!PageUptodate(page)) diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index 08709f19ea98..910722d4c483 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -104,7 +104,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) goto out_ipres; if (gfs2_is_stuffed(ip)) { - error = gfs2_unstuff_dinode(ip, gfs2_unstuffer_page, NULL); + error = gfs2_unstuff_dinode(ip, NULL); if (error) goto out_trans; } diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c index b93caf294b9f..0d6befed1ae5 100644 --- a/fs/gfs2/page.c +++ b/fs/gfs2/page.c @@ -113,66 +113,6 @@ void gfs2_page_sync(struct gfs2_glock *gl, int flags) } -/** - * gfs2_unstuffer_page - unstuff a stuffed inode into a block cached by a page - * @ip: the inode - * @dibh: the dinode buffer - * @block: the block number that was allocated - * @private: any locked page held by the caller process - * - * Returns: errno - */ - -int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, - uint64_t block, void *private) -{ - struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); - struct inode *inode = &ip->i_inode; - struct page *page = (struct page *)private; - struct buffer_head *bh; - int release = 0; - - if (!page || page->index) { - page = grab_cache_page(inode->i_mapping, 0); - if (!page) - return -ENOMEM; - release = 1; - } - - if (!PageUptodate(page)) { - void *kaddr = kmap(page); - - memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), - ip->i_di.di_size); - memset(kaddr + ip->i_di.di_size, 0, - PAGE_CACHE_SIZE - ip->i_di.di_size); - kunmap(page); - - SetPageUptodate(page); - } - - if (!page_has_buffers(page)) - create_empty_buffers(page, 1 << inode->i_blkbits, - (1 << BH_Uptodate)); - - bh = page_buffers(page); - - if (!buffer_mapped(bh)) - map_bh(bh, inode->i_sb, block); - - set_buffer_uptodate(bh); - if ((sdp->sd_args.ar_data == GFS2_DATA_ORDERED) || gfs2_is_jdata(ip)) - gfs2_trans_add_bh(ip->i_gl, bh, 0); - mark_buffer_dirty(bh); - - if (release) { - unlock_page(page); - page_cache_release(page); - } - - return 0; -} - /** * gfs2_block_truncate_page - Deal with zeroing out data for truncate * diff --git a/fs/gfs2/page.h b/fs/gfs2/page.h index 2c853a90ac04..67a4f4b79aa6 100644 --- a/fs/gfs2/page.h +++ b/fs/gfs2/page.h @@ -14,8 +14,6 @@ void gfs2_pte_inval(struct gfs2_glock *gl); void gfs2_page_inval(struct gfs2_glock *gl); void gfs2_page_sync(struct gfs2_glock *gl, int flags); -int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, - uint64_t block, void *private); int gfs2_block_truncate_page(struct address_space *mapping); void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, unsigned int from, unsigned int to); From ba7f72901cfd437d6de087bf44d2b64357cb38a5 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 26 Jul 2006 11:27:10 -0400 Subject: [PATCH 177/292] [GFS2] Remove page.[ch] The remaining routines in page.c were all only used in one other file, so they are now moved into the files where they are referenced and made static. Thus page.[ch] are no longer required. Signed-off-by: Steven Whitehouse --- fs/gfs2/Makefile | 2 +- fs/gfs2/bmap.c | 78 +++++++++++++++- fs/gfs2/glops.c | 89 +++++++++++++++++- fs/gfs2/ops_address.c | 19 +++- fs/gfs2/ops_inode.c | 1 - fs/gfs2/ops_super.c | 1 - fs/gfs2/ops_vm.c | 1 - fs/gfs2/page.c | 207 ------------------------------------------ fs/gfs2/page.h | 21 ----- 9 files changed, 184 insertions(+), 235 deletions(-) delete mode 100644 fs/gfs2/page.c delete mode 100644 fs/gfs2/page.h diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile index 0b7977623b80..b92852b66629 100644 --- a/fs/gfs2/Makefile +++ b/fs/gfs2/Makefile @@ -2,7 +2,7 @@ obj-$(CONFIG_GFS2_FS) += gfs2.o gfs2-y := acl.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \ glops.o inode.o lm.o log.o lops.o locking.o lvb.o main.o meta_io.o \ mount.o ondisk.o ops_address.o ops_dentry.o ops_export.o ops_file.o \ - ops_fstype.o ops_inode.o ops_super.o ops_vm.o page.o quota.o \ + ops_fstype.o ops_inode.o ops_super.o ops_vm.o quota.o \ recovery.o rgrp.o super.o sys.o trans.o util.o obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += locking/nolock/ diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 72b19c5d7807..d20d41e1c028 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -22,12 +22,12 @@ #include "glock.h" #include "inode.h" #include "meta_io.h" -#include "page.h" #include "quota.h" #include "rgrp.h" #include "trans.h" #include "dir.h" #include "util.h" +#include "ops_address.h" /* This doesn't need to be that large as max 64 bit pointers in a 4k * block is 512, so __u16 is fine for that. It saves stack space to @@ -885,6 +885,82 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size) return error; } + +/** + * gfs2_block_truncate_page - Deal with zeroing out data for truncate + * + * This is partly borrowed from ext3. + */ +static int gfs2_block_truncate_page(struct address_space *mapping) +{ + struct inode *inode = mapping->host; + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); + loff_t from = inode->i_size; + unsigned long index = from >> PAGE_CACHE_SHIFT; + unsigned offset = from & (PAGE_CACHE_SIZE-1); + unsigned blocksize, iblock, length, pos; + struct buffer_head *bh; + struct page *page; + void *kaddr; + int err; + + page = grab_cache_page(mapping, index); + if (!page) + return 0; + + blocksize = inode->i_sb->s_blocksize; + length = blocksize - (offset & (blocksize - 1)); + iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits); + + if (!page_has_buffers(page)) + create_empty_buffers(page, blocksize, 0); + + /* Find the buffer that contains "offset" */ + bh = page_buffers(page); + pos = blocksize; + while (offset >= pos) { + bh = bh->b_this_page; + iblock++; + pos += blocksize; + } + + err = 0; + + if (!buffer_mapped(bh)) { + gfs2_get_block(inode, iblock, bh, 0); + /* unmapped? It's a hole - nothing to do */ + if (!buffer_mapped(bh)) + goto unlock; + } + + /* Ok, it's mapped. Make sure it's up-to-date */ + if (PageUptodate(page)) + set_buffer_uptodate(bh); + + if (!buffer_uptodate(bh)) { + err = -EIO; + ll_rw_block(READ, 1, &bh); + wait_on_buffer(bh); + /* Uhhuh. Read error. Complain and punt. */ + if (!buffer_uptodate(bh)) + goto unlock; + } + + if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) + gfs2_trans_add_bh(ip->i_gl, bh, 0); + + kaddr = kmap_atomic(page, KM_USER0); + memset(kaddr + offset, 0, length); + flush_dcache_page(page); + kunmap_atomic(kaddr, KM_USER0); + +unlock: + unlock_page(page); + page_cache_release(page); + return err; +} + static int trunc_start(struct gfs2_inode *ip, uint64_t size) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index a01874c58834..3f909a81a071 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -23,11 +23,98 @@ #include "inode.h" #include "log.h" #include "meta_io.h" -#include "page.h" #include "recovery.h" #include "rgrp.h" #include "util.h" + +/** + * gfs2_pte_inval - Sync and invalidate all PTEs associated with a glock + * @gl: the glock + * + */ + +static void gfs2_pte_inval(struct gfs2_glock *gl) +{ + struct gfs2_inode *ip; + struct inode *inode; + + ip = gl->gl_object; + inode = &ip->i_inode; + if (!ip || !S_ISREG(ip->i_di.di_mode)) + return; + + if (!test_bit(GIF_PAGED, &ip->i_flags)) + return; + + unmap_shared_mapping_range(inode->i_mapping, 0, 0); + + if (test_bit(GIF_SW_PAGED, &ip->i_flags)) + set_bit(GLF_DIRTY, &gl->gl_flags); + + clear_bit(GIF_SW_PAGED, &ip->i_flags); +} + +/** + * gfs2_page_inval - Invalidate all pages associated with a glock + * @gl: the glock + * + */ + +static void gfs2_page_inval(struct gfs2_glock *gl) +{ + struct gfs2_inode *ip; + struct inode *inode; + + ip = gl->gl_object; + inode = &ip->i_inode; + if (!ip || !S_ISREG(ip->i_di.di_mode)) + return; + + truncate_inode_pages(inode->i_mapping, 0); + gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), !inode->i_mapping->nrpages); + clear_bit(GIF_PAGED, &ip->i_flags); +} + +/** + * gfs2_page_sync - Sync the data pages (not metadata) associated with a glock + * @gl: the glock + * @flags: DIO_START | DIO_WAIT + * + * Syncs data (not metadata) for a regular file. + * No-op for all other types. + */ + +static void gfs2_page_sync(struct gfs2_glock *gl, int flags) +{ + struct gfs2_inode *ip; + struct inode *inode; + struct address_space *mapping; + int error = 0; + + ip = gl->gl_object; + inode = &ip->i_inode; + if (!ip || !S_ISREG(ip->i_di.di_mode)) + return; + + mapping = inode->i_mapping; + + if (flags & DIO_START) + filemap_fdatawrite(mapping); + if (!error && (flags & DIO_WAIT)) + error = filemap_fdatawait(mapping); + + /* Put back any errors cleared by filemap_fdatawait() + so they can be caught by someone who can pass them + up to user space. */ + + if (error == -ENOSPC) + set_bit(AS_ENOSPC, &mapping->flags); + else if (error) + set_bit(AS_EIO, &mapping->flags); + +} + /** * meta_go_sync - sync out the metadata for this glock * @gl: the glock diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 93e00a8af8cf..fca69f12e4de 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -27,7 +27,6 @@ #include "log.h" #include "meta_io.h" #include "ops_address.h" -#include "page.h" #include "quota.h" #include "trans.h" #include "rgrp.h" @@ -35,6 +34,24 @@ #include "util.h" #include "glops.h" + +static void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, + unsigned int from, unsigned int to) +{ + struct buffer_head *head = page_buffers(page); + unsigned int bsize = head->b_size; + struct buffer_head *bh; + unsigned int start, end; + + for (bh = head, start = 0; bh != head || !start; + bh = bh->b_this_page, start = end) { + end = start + bsize; + if (end <= from || start >= to) + continue; + gfs2_trans_add_bh(ip->i_gl, bh, 0); + } +} + /** * gfs2_get_block - Fills in a buffer head with details about a block * @inode: The inode diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index caecafe0469b..8fb7c5c9a7c3 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -34,7 +34,6 @@ #include "meta_io.h" #include "ops_dentry.h" #include "ops_inode.h" -#include "page.h" #include "quota.h" #include "rgrp.h" #include "trans.h" diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 50ea7f21f9cf..730c7228f6ad 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -30,7 +30,6 @@ #include "log.h" #include "mount.h" #include "ops_super.h" -#include "page.h" #include "quota.h" #include "recovery.h" #include "rgrp.h" diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index 910722d4c483..aff66373b7e1 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -23,7 +23,6 @@ #include "glock.h" #include "inode.h" #include "ops_vm.h" -#include "page.h" #include "quota.h" #include "rgrp.h" #include "trans.h" diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c deleted file mode 100644 index 0d6befed1ae5..000000000000 --- a/fs/gfs2/page.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gfs2.h" -#include "lm_interface.h" -#include "incore.h" -#include "bmap.h" -#include "inode.h" -#include "page.h" -#include "trans.h" -#include "ops_address.h" -#include "util.h" - -/** - * gfs2_pte_inval - Sync and invalidate all PTEs associated with a glock - * @gl: the glock - * - */ - -void gfs2_pte_inval(struct gfs2_glock *gl) -{ - struct gfs2_inode *ip; - struct inode *inode; - - ip = gl->gl_object; - inode = &ip->i_inode; - if (!ip || !S_ISREG(ip->i_di.di_mode)) - return; - - if (!test_bit(GIF_PAGED, &ip->i_flags)) - return; - - unmap_shared_mapping_range(inode->i_mapping, 0, 0); - - if (test_bit(GIF_SW_PAGED, &ip->i_flags)) - set_bit(GLF_DIRTY, &gl->gl_flags); - - clear_bit(GIF_SW_PAGED, &ip->i_flags); -} - -/** - * gfs2_page_inval - Invalidate all pages associated with a glock - * @gl: the glock - * - */ - -void gfs2_page_inval(struct gfs2_glock *gl) -{ - struct gfs2_inode *ip; - struct inode *inode; - - ip = gl->gl_object; - inode = &ip->i_inode; - if (!ip || !S_ISREG(ip->i_di.di_mode)) - return; - - truncate_inode_pages(inode->i_mapping, 0); - gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), !inode->i_mapping->nrpages); - clear_bit(GIF_PAGED, &ip->i_flags); -} - -/** - * gfs2_page_sync - Sync the data pages (not metadata) associated with a glock - * @gl: the glock - * @flags: DIO_START | DIO_WAIT - * - * Syncs data (not metadata) for a regular file. - * No-op for all other types. - */ - -void gfs2_page_sync(struct gfs2_glock *gl, int flags) -{ - struct gfs2_inode *ip; - struct inode *inode; - struct address_space *mapping; - int error = 0; - - ip = gl->gl_object; - inode = &ip->i_inode; - if (!ip || !S_ISREG(ip->i_di.di_mode)) - return; - - mapping = inode->i_mapping; - - if (flags & DIO_START) - filemap_fdatawrite(mapping); - if (!error && (flags & DIO_WAIT)) - error = filemap_fdatawait(mapping); - - /* Put back any errors cleared by filemap_fdatawait() - so they can be caught by someone who can pass them - up to user space. */ - - if (error == -ENOSPC) - set_bit(AS_ENOSPC, &mapping->flags); - else if (error) - set_bit(AS_EIO, &mapping->flags); - -} - -/** - * gfs2_block_truncate_page - Deal with zeroing out data for truncate - * - * This is partly borrowed from ext3. - */ -int gfs2_block_truncate_page(struct address_space *mapping) -{ - struct inode *inode = mapping->host; - struct gfs2_inode *ip = GFS2_I(inode); - struct gfs2_sbd *sdp = GFS2_SB(inode); - loff_t from = inode->i_size; - unsigned long index = from >> PAGE_CACHE_SHIFT; - unsigned offset = from & (PAGE_CACHE_SIZE-1); - unsigned blocksize, iblock, length, pos; - struct buffer_head *bh; - struct page *page; - void *kaddr; - int err; - - page = grab_cache_page(mapping, index); - if (!page) - return 0; - - blocksize = inode->i_sb->s_blocksize; - length = blocksize - (offset & (blocksize - 1)); - iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits); - - if (!page_has_buffers(page)) - create_empty_buffers(page, blocksize, 0); - - /* Find the buffer that contains "offset" */ - bh = page_buffers(page); - pos = blocksize; - while (offset >= pos) { - bh = bh->b_this_page; - iblock++; - pos += blocksize; - } - - err = 0; - - if (!buffer_mapped(bh)) { - gfs2_get_block(inode, iblock, bh, 0); - /* unmapped? It's a hole - nothing to do */ - if (!buffer_mapped(bh)) - goto unlock; - } - - /* Ok, it's mapped. Make sure it's up-to-date */ - if (PageUptodate(page)) - set_buffer_uptodate(bh); - - if (!buffer_uptodate(bh)) { - err = -EIO; - ll_rw_block(READ, 1, &bh); - wait_on_buffer(bh); - /* Uhhuh. Read error. Complain and punt. */ - if (!buffer_uptodate(bh)) - goto unlock; - } - - if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) - gfs2_trans_add_bh(ip->i_gl, bh, 0); - - kaddr = kmap_atomic(page, KM_USER0); - memset(kaddr + offset, 0, length); - flush_dcache_page(page); - kunmap_atomic(kaddr, KM_USER0); - -unlock: - unlock_page(page); - page_cache_release(page); - return err; -} - -void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, - unsigned int from, unsigned int to) -{ - struct buffer_head *head = page_buffers(page); - unsigned int bsize = head->b_size; - struct buffer_head *bh; - unsigned int start, end; - - for (bh = head, start = 0; bh != head || !start; - bh = bh->b_this_page, start = end) { - end = start + bsize; - if (end <= from || start >= to) - continue; - gfs2_trans_add_bh(ip->i_gl, bh, 0); - } -} - diff --git a/fs/gfs2/page.h b/fs/gfs2/page.h deleted file mode 100644 index 67a4f4b79aa6..000000000000 --- a/fs/gfs2/page.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#ifndef __PAGE_DOT_H__ -#define __PAGE_DOT_H__ - -void gfs2_pte_inval(struct gfs2_glock *gl); -void gfs2_page_inval(struct gfs2_glock *gl); -void gfs2_page_sync(struct gfs2_glock *gl, int flags); - -int gfs2_block_truncate_page(struct address_space *mapping); -void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, - unsigned int from, unsigned int to); - -#endif /* __PAGE_DOT_H__ */ From 20abf975f75d6fb45d8c055d30cdcb112ca8b608 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 26 Jul 2006 08:29:06 -0500 Subject: [PATCH 178/292] [DLM] fix broken patches On Wed, Jul 26, 2006 at 10:47:14AM +0100, Steven Whitehouse wrote: > Hi, > > I've applied all the patches you sent, but they don't build: Argh, sorry about that... when I fixed these a long time ago they somehow never got included in the quilt patches. I mistakenly assumed the quilt patches matched the source I had in front of me. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/debug_fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index 5faa747c7ca1..516f6c9ee4d5 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -123,7 +123,7 @@ static int print_resource(struct dlm_rsb *res, struct seq_file *s) if (root_list || recover_list) { seq_printf(s, "Recovery: root %d recover %d flags %lx " "count %d\n", root_list, recover_list, - res->flags, res->res_recover_locks_count); + res->res_flags, res->res_recover_locks_count); } /* Print the locks attached to this resource */ @@ -277,7 +277,7 @@ static int rsb_open(struct inode *inode, struct file *file) struct seq_file *seq; int ret; - ret = rsb_seq_open(file, &rsb_seq_ops); + ret = seq_open(file, &rsb_seq_ops); if (ret) return ret; @@ -343,7 +343,7 @@ int dlm_create_debug_file(struct dlm_ls *ls) dlm_root, ls, &rsb_fops); - if (!ls->ls_rsb_debug_dentry) + if (!ls->ls_debug_rsb_dentry) return -ENOMEM; memset(name, 0, sizeof(name)); From ae4a382004fc6cf229c51deaf69910410d313e0b Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 26 Jul 2006 15:31:15 -0400 Subject: [PATCH 179/292] [DLM] fix i_private > I think you must have an old version of the base kernel as well? > i_private no longer exists in struct inode, so you'll have to use > something else, I have that patch in my stack but didn't send it; for some reason I thought it was already changed in your git tree. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/debug_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index 516f6c9ee4d5..8f471d9a9e3a 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -301,7 +301,7 @@ static struct file_operations rsb_fops = { static int waiters_open(struct inode *inode, struct file *file) { - file->private_data = inode->i_private; + file->private_data = inode->u.generic_ip; return 0; } From f45b7ddd2bae1dc98e35c3611b55cba6d2a8da9e Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 27 Jul 2006 13:53:53 -0400 Subject: [PATCH 180/292] [GFS2] Use a bio to read the superblock This means that we don't need to create a special inode just to contain a struct address_space in order to read a single disk block. Instead we read the disk block directly. Its slightly faster, and uses slightly less memory, but the real reason for doing this is that it removes a special case from the glock code. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 3 +- fs/gfs2/glops.c | 22 +++----------- fs/gfs2/ops_fstype.c | 5 ---- fs/gfs2/super.c | 69 +++++++++++++++++++++++++++++++++++++------- 4 files changed, 64 insertions(+), 35 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 0381d4cc4146..91ac9c9d4a96 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -311,8 +311,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, /* If this glock protects actual on-disk data or metadata blocks, create a VFS inode to manage the pages/buffers holding them. */ if (glops == &gfs2_inode_glops || - glops == &gfs2_rgrp_glops || - glops == &gfs2_meta_glops) { + glops == &gfs2_rgrp_glops) { gl->gl_aspace = gfs2_aspace_get(sdp); if (!gl->gl_aspace) { error = -ENOMEM; diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 3f909a81a071..75d4c50cff45 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -156,18 +156,6 @@ static void meta_go_inval(struct gfs2_glock *gl, int flags) gl->gl_vn++; } -/** - * meta_go_demote_ok - Check to see if it's ok to unlock a glock - * @gl: the glock - * - * Returns: 1 if we have no cached data; ok to demote meta glock - */ - -static int meta_go_demote_ok(struct gfs2_glock *gl) -{ - return !gl->gl_aspace->i_mapping->nrpages; -} - /** * inode_go_xmote_th - promote/demote a glock * @gl: the glock @@ -338,11 +326,12 @@ static void inode_go_unlock(struct gfs2_holder *gh) struct gfs2_glock *gl = gh->gh_gl; struct gfs2_inode *ip = gl->gl_object; - if (ip && test_bit(GLF_DIRTY, &gl->gl_flags)) - gfs2_inode_attr_in(ip); + if (ip) { + if (test_bit(GLF_DIRTY, &gl->gl_flags)) + gfs2_inode_attr_in(ip); - if (ip) gfs2_meta_cache_flush(ip); + } } /** @@ -507,9 +496,6 @@ static int quota_go_demote_ok(struct gfs2_glock *gl) struct gfs2_glock_operations gfs2_meta_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, - .go_sync = meta_go_sync, - .go_inval = meta_go_inval, - .go_demote_ok = meta_go_demote_ok, .go_type = LM_TYPE_META }; diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index a86ce67949db..de18923eea70 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -310,11 +310,6 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE); goto out; } - - /* Get rid of buffers from the original block size */ - sb_gh.gh_gl->gl_ops->go_inval(sb_gh.gh_gl, DIO_METADATA | DIO_DATA); - sb_gh.gh_gl->gl_aspace->i_blkbits = sdp->sd_sb.sb_bsize_shift; - sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); /* Get the root inode */ diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index f2d287660cc9..48fd4cb49c1e 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "gfs2.h" #include "lm_interface.h" @@ -157,6 +158,54 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent) return 0; } + +static int end_bio_io_page(struct bio *bio, unsigned int bytes_done, int error) +{ + struct page *page = bio->bi_private; + if (bio->bi_size) + return 1; + + if (!error) + SetPageUptodate(page); + unlock_page(page); + return 0; +} + +static struct page *gfs2_read_super(struct super_block *sb, sector_t sector) +{ + struct page *page; + struct bio *bio; + + page = alloc_page(GFP_KERNEL); + if (unlikely(!page)) + return NULL; + + ClearPageUptodate(page); + ClearPageDirty(page); + lock_page(page); + + bio = bio_alloc(GFP_KERNEL, 1); + if (unlikely(!bio)) { + __free_page(page); + return NULL; + } + + bio->bi_sector = sector; + bio->bi_bdev = sb->s_bdev; + bio_add_page(bio, page, PAGE_SIZE, 0); + + bio->bi_end_io = end_bio_io_page; + bio->bi_private = page; + submit_bio(READ | BIO_RW_SYNC, bio); + wait_on_page_locked(page); + bio_put(bio); + if (!PageUptodate(page)) { + __free_page(page); + return NULL; + } + return page; +} + /** * gfs2_read_sb - Read super block * @sdp: The GFS2 superblock @@ -167,23 +216,23 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent) int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) { - struct buffer_head *bh; uint32_t hash_blocks, ind_blocks, leaf_blocks; uint32_t tmp_blocks; unsigned int x; int error; + struct page *page; + char *sb; - error = gfs2_meta_read(gl, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift, - DIO_FORCE | DIO_START | DIO_WAIT, &bh); - if (error) { + page = gfs2_read_super(sdp->sd_vfs, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); + if (!page) { if (!silent) fs_err(sdp, "can't read superblock\n"); - return error; + return -EIO; } - - gfs2_assert(sdp, sizeof(struct gfs2_sb) <= bh->b_size); - gfs2_sb_in(&sdp->sd_sb, bh->b_data); - brelse(bh); + sb = kmap(page); + gfs2_sb_in(&sdp->sd_sb, sb); + kunmap(page); + __free_page(page); error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); if (error) @@ -202,7 +251,7 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(uint64_t); sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header)) / - sizeof(struct gfs2_quota_change); + sizeof(struct gfs2_quota_change); /* Compute maximum reservation required to add a entry to a directory */ From dd894be8df11ea40a1163b75596ab85d558816c8 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 27 Jul 2006 14:29:00 -0400 Subject: [PATCH 181/292] [GFS2] Change some allocations to GFP_NOFS Some allocations in rgrp.c should have been GFP_NOFS rather than GFP_KERNEL. Signed-off-by: Steven Whitehouse --- fs/gfs2/rgrp.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 65eea0b88bf7..4e0357dc838b 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -374,7 +374,7 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd) if (!length) return -EINVAL; - rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_KERNEL); + rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_NOFS); if (!rgd->rd_bits) return -ENOMEM; @@ -467,7 +467,7 @@ static int gfs2_ri_update(struct gfs2_inode *ip) goto fail; } - rgd = kzalloc(sizeof(struct gfs2_rgrpd), GFP_KERNEL); + rgd = kzalloc(sizeof(struct gfs2_rgrpd), GFP_NOFS); error = -ENOMEM; if (!rgd) goto fail; @@ -1184,14 +1184,13 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, uint64_t bstart, if (!bi->bi_clone) { bi->bi_clone = kmalloc(bi->bi_bh->b_size, - GFP_KERNEL | __GFP_NOFAIL); + GFP_NOFS | __GFP_NOFAIL); memcpy(bi->bi_clone + bi->bi_offset, bi->bi_bh->b_data + bi->bi_offset, bi->bi_len); } gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); - gfs2_setbit(rgd, - bi->bi_bh->b_data + bi->bi_offset, + gfs2_setbit(rgd, bi->bi_bh->b_data + bi->bi_offset, bi->bi_len, buf_blk, new_state); } @@ -1469,7 +1468,7 @@ void gfs2_rlist_add(struct gfs2_sbd *sdp, struct gfs2_rgrp_list *rlist, new_space = rlist->rl_space + 10; tmp = kcalloc(new_space, sizeof(struct gfs2_rgrpd *), - GFP_KERNEL | __GFP_NOFAIL); + GFP_NOFS | __GFP_NOFAIL); if (rlist->rl_rgd) { memcpy(tmp, rlist->rl_rgd, @@ -1501,7 +1500,7 @@ void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state, unsigned int x; rlist->rl_ghs = kcalloc(rlist->rl_rgrps, sizeof(struct gfs2_holder), - GFP_KERNEL | __GFP_NOFAIL); + GFP_NOFS | __GFP_NOFAIL); for (x = 0; x < rlist->rl_rgrps; x++) gfs2_holder_init(rlist->rl_rgd[x]->rd_gl, state, flags, From 2b98a54f796f701604737abd9c2017948e9e010b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 27 Jul 2006 16:37:48 -0400 Subject: [PATCH 182/292] [GFS2] Fix bug in super block reading code This gets the argument to submit_bio() correct. Signed-off-by: Steven Whitehouse --- fs/gfs2/super.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 48fd4cb49c1e..3c318a9e8a8c 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -167,6 +167,8 @@ static int end_bio_io_page(struct bio *bio, unsigned int bytes_done, int error) if (!error) SetPageUptodate(page); + else + printk(KERN_WARNING "gfs2: error %d reading superblock\n", error); unlock_page(page); return 0; } @@ -196,7 +198,7 @@ static struct page *gfs2_read_super(struct super_block *sb, sector_t sector) bio->bi_end_io = end_bio_io_page; bio->bi_private = page; - submit_bio(READ | BIO_RW_SYNC, bio); + submit_bio(READ_SYNC, bio); wait_on_page_locked(page); bio_put(bio); if (!PageUptodate(page)) { From 5dd9feafb351a8bf304292623cbc63335c34d279 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 28 Jul 2006 14:52:33 -0400 Subject: [PATCH 183/292] [GFS2] Fix bug in clear_inode We should have been waiting for lock demotion to finish in clear_inode. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 91ac9c9d4a96..b6edf7c0923b 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -771,6 +771,7 @@ void gfs2_glock_inode_squish(struct inode *inode) list_add_tail(&gh.gh_list, &gl->gl_waiters2); run_queue(gl); spin_unlock(&gl->gl_spin); + wait_for_completion(&gh.gh_wait); gfs2_holder_uninit(&gh); } From 420b9e5e45d33355471c8d2d593bb0e5d6c77421 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 31 Jul 2006 15:42:17 -0400 Subject: [PATCH 184/292] [GFS2] Tidy up in various files Tidy up some files and remove an unused routine in meta_io.h. Also added a bit of extra debugging in meta_io.h. Signed-off-by: Steven Whitehouse --- fs/gfs2/inode.c | 20 +++++--------------- fs/gfs2/meta_io.h | 23 ++++------------------- fs/gfs2/ops_file.c | 9 +++------ 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index e76f345517b7..9fb340984b29 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -277,8 +277,7 @@ int gfs2_dinode_dealloc(struct gfs2_inode *ip) if (error) goto out_rindex_relse; - error = gfs2_trans_begin(sdp, RES_RG_BIT + - RES_STATFS + RES_QUOTA, 1); + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 1); if (error) goto out_rg_gunlock; @@ -522,16 +521,13 @@ static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_inum_range_out(&ir, bh->b_data + sizeof(struct gfs2_dinode)); - out_brelse: +out_brelse: brelse(bh); - - out_end_trans: +out_end_trans: mutex_unlock(&sdp->sd_inum_mutex); gfs2_trans_end(sdp); - - out: +out: gfs2_glock_dq_uninit(&gh); - return error; } @@ -593,8 +589,7 @@ static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, unsigned int *uid, unsigned int *gid) { if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir && - (dip->i_di.di_mode & S_ISUID) && - dip->i_di.di_uid) { + (dip->i_di.di_mode & S_ISUID) && dip->i_di.di_uid) { if (S_ISDIR(*mode)) *mode |= S_ISUID; else if (dip->i_di.di_uid != current->fsuid) @@ -634,10 +629,8 @@ static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_inum *inum, out_ipreserv: gfs2_inplace_release(dip); - out: gfs2_alloc_put(dip); - return error; } @@ -1300,7 +1293,6 @@ int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs) } kfree(p); - return error; } @@ -1346,9 +1338,7 @@ int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) return error; error = __gfs2_setattr_simple(ip, attr); - gfs2_trans_end(GFS2_SB(&ip->i_inode)); - return error; } diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index 23c6a596fd9e..951814e86272 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h @@ -17,35 +17,20 @@ static inline void gfs2_buffer_clear(struct buffer_head *bh) static inline void gfs2_buffer_clear_tail(struct buffer_head *bh, int head) { + BUG_ON(head > bh->b_size); memset(bh->b_data + head, 0, bh->b_size - head); } -static inline void gfs2_buffer_clear_ends(struct buffer_head *bh, int offset, - int amount, int journaled) -{ - int z_off1 = (journaled) ? sizeof(struct gfs2_meta_header) : 0; - int z_len1 = offset - z_off1; - int z_off2 = offset + amount; - int z_len2 = (bh)->b_size - z_off2; - - if (z_len1) - memset(bh->b_data + z_off1, 0, z_len1); - - if (z_len2) - memset(bh->b_data + z_off2, 0, z_len2); -} - static inline void gfs2_buffer_copy_tail(struct buffer_head *to_bh, int to_head, struct buffer_head *from_bh, int from_head) { - memcpy(to_bh->b_data + to_head, - from_bh->b_data + from_head, + BUG_ON(from_head < to_head); + memcpy(to_bh->b_data + to_head, from_bh->b_data + from_head, from_bh->b_size - from_head); memset(to_bh->b_data + to_bh->b_size + to_head - from_head, - 0, - from_head - to_head); + 0, from_head - to_head); } struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp); diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index d13e04e8a96a..145a29fa4ea4 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -597,13 +597,11 @@ static int gfs2_open(struct inode *inode, struct file *file) return 0; - fail_gunlock: +fail_gunlock: gfs2_glock_dq_uninit(&i_gh); - - fail: +fail: file->private_data = NULL; kfree(fp); - return error; } @@ -736,9 +734,8 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); } - out: +out: mutex_unlock(&fp->f_fl_mutex); - return error; } From de9b75d31e81e87685d8cc70052a003c654f1e8e Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 28 Jul 2006 14:00:20 -0500 Subject: [PATCH 185/292] [GFS2] add plock owner We need to use fl_owner instead of fl_pid to track the owner of a posix lock. Pass the owner value out to user space where cluster plocks are managed. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/plock.c | 2 ++ include/linux/lock_dlm_plock.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c index 6adfb2d4fd8c..e5b11f0688f6 100644 --- a/fs/gfs2/locking/dlm/plock.c +++ b/fs/gfs2/locking/dlm/plock.c @@ -77,6 +77,7 @@ int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, op->info.number = name->ln_number; op->info.start = fl->fl_start; op->info.end = fl->fl_end; + op->info.owner = (__u64)(long) fl->fl_owner; send_op(op); wait_event(recv_wq, (op->done != 0)); @@ -122,6 +123,7 @@ int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, op->info.number = name->ln_number; op->info.start = fl->fl_start; op->info.end = fl->fl_end; + op->info.owner = (__u64)(long) fl->fl_owner; send_op(op); wait_event(recv_wq, (op->done != 0)); diff --git a/include/linux/lock_dlm_plock.h b/include/linux/lock_dlm_plock.h index 007b07a178ab..fc3415113973 100644 --- a/include/linux/lock_dlm_plock.h +++ b/include/linux/lock_dlm_plock.h @@ -12,7 +12,7 @@ #define GDLM_PLOCK_MISC_NAME "lock_dlm_plock" #define GDLM_PLOCK_VERSION_MAJOR 1 -#define GDLM_PLOCK_VERSION_MINOR 0 +#define GDLM_PLOCK_VERSION_MINOR 1 #define GDLM_PLOCK_VERSION_PATCH 0 enum { @@ -34,6 +34,7 @@ struct gdlm_plock_info { __u64 number; __u64 start; __u64 end; + __u64 owner; }; #endif From 899bb264507cfed83922bf14cd66a073494601ba Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 1 Aug 2006 15:28:57 -0400 Subject: [PATCH 186/292] [GFS2] Fix bug in directory code This was a nasty bug which resulted in corruption of hash tables in the directory code with larger directories. We forgot to increment a pointer in the read/write routines internal to the directory code. Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 563b99e419b6..76a23c172eeb 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -215,6 +215,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, if (error) goto fail; + buf += amount; copied += amount; lblock++; dblock++; @@ -335,6 +336,7 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, if (error) goto fail; + buf += amount; copied += amount; lblock++; From 59a1cc6bdabf5ed148b48808ad1a418d87f5e6bf Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 4 Aug 2006 15:41:22 -0400 Subject: [PATCH 187/292] [GFS2] Fix lock ordering bug in page fault path Mmapped files were able to trigger a lock ordering bug. Private maps do not need to take the glock so early on. Shared maps do unfortunately, however we can get around that by adding a flag into the flags for the struct gfs2_file. This only works because we are taking an exclusive lock at this point, so we know that nobody else can be racing with us. Fixes Red Hat bugzilla: #201196 Signed-off-by: Steven Whitehouse --- fs/gfs2/incore.h | 1 + fs/gfs2/log.c | 4 ++-- fs/gfs2/ops_address.c | 23 +++++++++++++++++++---- fs/gfs2/ops_vm.c | 20 +++++++------------- fs/gfs2/recovery.c | 9 +++------ 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 90e0624d8065..e98c14f30daa 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -279,6 +279,7 @@ static inline struct gfs2_sbd *GFS2_SB(struct inode *inode) enum { GFF_DID_DIRECT_ALLOC = 0, + GFF_EXLOCK = 1, }; struct gfs2_file { diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 60fdc94ccc8a..a591fb8fae20 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -256,8 +256,8 @@ static unsigned int current_tail(struct gfs2_sbd *sdp) if (list_empty(&sdp->sd_ail1_list)) tail = sdp->sd_log_head; else { - ai = list_entry(sdp->sd_ail1_list.prev, - struct gfs2_ail, ai_list); + ai = list_entry(sdp->sd_ail1_list.prev, struct gfs2_ail, + ai_list); tail = ai->ai_first; } diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index fca69f12e4de..bdd4d6b48721 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -237,14 +237,22 @@ static int gfs2_readpage(struct file *file, struct page *page) struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host); struct gfs2_holder gh; int error; + int do_unlock = 0; if (likely(file != &gfs2_internal_file_sentinal)) { + if (file) { + struct gfs2_file *gf = file->private_data; + if (test_bit(GFF_EXLOCK, &gf->f_flags)) + goto skip_lock; + } gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|GL_AOP, &gh); + do_unlock = 1; error = gfs2_glock_nq_m_atime(1, &gh); if (unlikely(error)) goto out_unlock; } +skip_lock: if (gfs2_is_stuffed(ip)) { error = stuffed_readpage(ip, page); unlock_page(page); @@ -262,7 +270,7 @@ out: return error; out_unlock: unlock_page(page); - if (file != &gfs2_internal_file_sentinal) + if (do_unlock) gfs2_holder_uninit(&gh); goto out; } @@ -291,17 +299,24 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping, struct gfs2_holder gh; unsigned page_idx; int ret; + int do_unlock = 0; if (likely(file != &gfs2_internal_file_sentinal)) { + if (file) { + struct gfs2_file *gf = file->private_data; + if (test_bit(GFF_EXLOCK, &gf->f_flags)) + goto skip_lock; + } gfs2_holder_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_TRY_1CB|GL_ATIME|GL_AOP, &gh); + do_unlock = 1; ret = gfs2_glock_nq_m_atime(1, &gh); if (ret == GLR_TRYFAILED) goto out_noerror; if (unlikely(ret)) goto out_unlock; } - +skip_lock: if (gfs2_is_stuffed(ip)) { struct pagevec lru_pvec; pagevec_init(&lru_pvec, 0); @@ -326,7 +341,7 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping, ret = mpage_readpages(mapping, pages, nr_pages, gfs2_get_block); } - if (likely(file != &gfs2_internal_file_sentinal)) { + if (do_unlock) { gfs2_glock_dq_m(1, &gh); gfs2_holder_uninit(&gh); } @@ -344,7 +359,7 @@ out_unlock: unlock_page(page); page_cache_release(page); } - if (likely(file != &gfs2_internal_file_sentinal)) + if (do_unlock) gfs2_holder_uninit(&gh); goto out; } diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index aff66373b7e1..875a769444a1 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -46,13 +46,7 @@ static struct page *gfs2_private_nopage(struct vm_area_struct *area, unsigned long address, int *type) { struct gfs2_inode *ip = GFS2_I(area->vm_file->f_mapping->host); - struct gfs2_holder i_gh; struct page *result; - int error; - - error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); - if (error) - return NULL; set_bit(GIF_PAGED, &ip->i_flags); @@ -61,8 +55,6 @@ static struct page *gfs2_private_nopage(struct vm_area_struct *area, if (result && result != NOPAGE_OOM) pfault_be_greedy(ip); - gfs2_glock_dq_uninit(&i_gh); - return result; } @@ -141,7 +133,9 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, unsigned long address, int *type) { - struct gfs2_inode *ip = GFS2_I(area->vm_file->f_mapping->host); + struct file *file = area->vm_file; + struct gfs2_file *gf = file->private_data; + struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); struct gfs2_holder i_gh; struct page *result = NULL; unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) + @@ -156,13 +150,14 @@ static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, set_bit(GIF_PAGED, &ip->i_flags); set_bit(GIF_SW_PAGED, &ip->i_flags); - error = gfs2_write_alloc_required(ip, - (uint64_t)index << PAGE_CACHE_SHIFT, + error = gfs2_write_alloc_required(ip, (u64)index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE, &alloc_required); if (error) goto out; + set_bit(GFF_EXLOCK, &gf->f_flags); result = filemap_nopage(area, address, type); + clear_bit(GFF_EXLOCK, &gf->f_flags); if (!result || result == NOPAGE_OOM) goto out; @@ -177,8 +172,7 @@ static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, } pfault_be_greedy(ip); - - out: +out: gfs2_glock_dq_uninit(&i_gh); return result; diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 7aabc03e4abd..bbd44a4b1a1f 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -153,8 +153,7 @@ static int get_log_header(struct gfs2_jdesc *jd, unsigned int blk, if (lh.lh_header.mh_magic != GFS2_MAGIC || lh.lh_header.mh_type != GFS2_METATYPE_LH || - lh.lh_blkno != blk || - lh.lh_hash != hash) + lh.lh_blkno != blk || lh.lh_hash != hash) return 1; *head = lh; @@ -482,11 +481,9 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd) /* Acquire a shared hold on the transaction lock */ - error = gfs2_glock_nq_init(sdp->sd_trans_gl, - LM_ST_SHARED, + error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, LM_FLAG_NOEXP | LM_FLAG_PRIORITY | - GL_NOCANCEL | GL_NOCACHE, - &t_gh); + GL_NOCANCEL | GL_NOCACHE, &t_gh); if (error) goto fail_gunlock_ji; From 3120ec541eafc6ed19bacb395adf08c5872143bf Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 4 Aug 2006 13:14:50 -0500 Subject: [PATCH 188/292] [GFS2] lockproto api prefix Use the gfs2_ prefix on the register/unregister functions for the lock modules. The gfs_ prefix was left from an old idea on how to share these with gfs1. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/lm_interface.h | 9 ++------- fs/gfs2/locking/dlm/main.c | 8 ++++---- fs/gfs2/locking/nolock/main.c | 4 ++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/fs/gfs2/lm_interface.h b/fs/gfs2/lm_interface.h index 9d34bf3df103..1da95a55f768 100644 --- a/fs/gfs2/lm_interface.h +++ b/fs/gfs2/lm_interface.h @@ -265,16 +265,11 @@ void __init gfs2_init_lmh(void); /* * Lock module bottom interface. A lock module makes itself available to GFS * with these functions. - * - * For the time being, we copy the gfs1 lock module bottom interface so the - * same lock modules can be used with both gfs1 and gfs2 (it won't be possible - * to load both gfs1 and gfs2 at once.) Eventually the lock modules will fork - * for gfs1/gfs2 and this API can change to the gfs2_ prefix. */ -int gfs_register_lockproto(struct lm_lockops *proto); +int gfs2_register_lockproto(struct lm_lockops *proto); -void gfs_unregister_lockproto(struct lm_lockops *proto); +void gfs2_unregister_lockproto(struct lm_lockops *proto); /* * Lock module top interface. GFS calls these functions when mounting or diff --git a/fs/gfs2/locking/dlm/main.c b/fs/gfs2/locking/dlm/main.c index 89728c91665f..870a1cd99f57 100644 --- a/fs/gfs2/locking/dlm/main.c +++ b/fs/gfs2/locking/dlm/main.c @@ -20,7 +20,7 @@ static int __init init_lock_dlm(void) { int error; - error = gfs_register_lockproto(&gdlm_ops); + error = gfs2_register_lockproto(&gdlm_ops); if (error) { printk(KERN_WARNING "lock_dlm: can't register protocol: %d\n", error); @@ -29,14 +29,14 @@ static int __init init_lock_dlm(void) error = gdlm_sysfs_init(); if (error) { - gfs_unregister_lockproto(&gdlm_ops); + gfs2_unregister_lockproto(&gdlm_ops); return error; } error = gdlm_plock_init(); if (error) { gdlm_sysfs_exit(); - gfs_unregister_lockproto(&gdlm_ops); + gfs2_unregister_lockproto(&gdlm_ops); return error; } @@ -52,7 +52,7 @@ static void __exit exit_lock_dlm(void) { gdlm_plock_exit(); gdlm_sysfs_exit(); - gfs_unregister_lockproto(&gdlm_ops); + gfs2_unregister_lockproto(&gdlm_ops); } module_init(init_lock_dlm); diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index 97ffac5cdefb..748aa5d33641 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -233,7 +233,7 @@ static int __init init_nolock(void) { int error; - error = gfs_register_lockproto(&nolock_ops); + error = gfs2_register_lockproto(&nolock_ops); if (error) { printk(KERN_WARNING "lock_nolock: can't register protocol: %d\n", error); @@ -247,7 +247,7 @@ static int __init init_nolock(void) static void __exit exit_nolock(void) { - gfs_unregister_lockproto(&nolock_ops); + gfs2_unregister_lockproto(&nolock_ops); } module_init(init_nolock); From 08eac93a689ca05c7b7413f6d362c7d38b5fd5b1 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 4 Aug 2006 16:19:20 -0500 Subject: [PATCH 189/292] [GFS2] match plock result with correct request When the result of a posix lock request is read it needs to be matched up with the correct waiting request. The owner field needs to be used in the comparison since more than one process may be waiting for locks on the same file. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/plock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c index e5b11f0688f6..1acb2519f439 100644 --- a/fs/gfs2/locking/dlm/plock.c +++ b/fs/gfs2/locking/dlm/plock.c @@ -232,7 +232,8 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count, spin_lock(&ops_lock); list_for_each_entry(op, &recv_list, list) { if (op->info.fsid == info.fsid && - op->info.number == info.number) { + op->info.number == info.number && + op->info.owner == info.owner) { list_del_init(&op->list); found = 1; op->done = 1; From 2b557f6dc7899a0f6afc0169534346f8fa977a46 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 7 Aug 2006 11:12:30 -0400 Subject: [PATCH 190/292] [GFS2] Fix gfs_ prefix in locking.c The previous patch didn't change all the gfs_ to gfs2_ so this is the remainder. Signed-off-by: Steven Whitehouse --- fs/gfs2/locking.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c index 183192836e98..ded1ef6c81e7 100644 --- a/fs/gfs2/locking.c +++ b/fs/gfs2/locking.c @@ -31,13 +31,13 @@ static struct list_head lmh_list; static struct mutex lmh_lock; /** - * gfs_register_lockproto - Register a low-level locking protocol + * gfs2_register_lockproto - Register a low-level locking protocol * @proto: the protocol definition * * Returns: 0 on success, -EXXX on failure */ -int gfs_register_lockproto(struct lm_lockops *proto) +int gfs2_register_lockproto(struct lm_lockops *proto) { struct lmh_wrapper *lw; @@ -67,12 +67,12 @@ int gfs_register_lockproto(struct lm_lockops *proto) } /** - * gfs_unregister_lockproto - Unregister a low-level locking protocol + * gfs2_unregister_lockproto - Unregister a low-level locking protocol * @proto: the protocol definition * */ -void gfs_unregister_lockproto(struct lm_lockops *proto) +void gfs2_unregister_lockproto(struct lm_lockops *proto) { struct lmh_wrapper *lw; @@ -117,7 +117,7 @@ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, int try = 0; int error, found; - retry: +retry: mutex_lock(&lmh_lock); found = 0; @@ -151,7 +151,7 @@ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, min_lvb_size, flags, lockstruct, fskobj); if (error) module_put(lw->lw_ops->lm_owner); - out: +out: mutex_unlock(&lmh_lock); return error; } @@ -186,6 +186,6 @@ void __init gfs2_init_lmh(void) INIT_LIST_HEAD(&lmh_list); } -EXPORT_SYMBOL_GPL(gfs_register_lockproto); -EXPORT_SYMBOL_GPL(gfs_unregister_lockproto); +EXPORT_SYMBOL_GPL(gfs2_register_lockproto); +EXPORT_SYMBOL_GPL(gfs2_unregister_lockproto); From cc346d555f2c3eb4a63b2df6bf9c9947f0a92a01 Mon Sep 17 00:00:00 2001 From: Patrick Caulfield Date: Tue, 8 Aug 2006 10:34:40 -0400 Subject: [PATCH 191/292] [DLM] fix userland unlock This patch fixes the userland DLM unlock code so that it correctly returns the address of the userland lock status block in its completion AST. It fixes bug #201348 Patrick Signed-Off-By: Patrick Caulfield Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 7d38f914c5b9..bb2e35151210 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -3699,6 +3699,7 @@ int dlm_user_unlock(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, if (lvb_in && ua->lksb.sb_lvbptr) memcpy(ua->lksb.sb_lvbptr, lvb_in, DLM_USER_LVB_LEN); ua->castparam = ua_tmp->castparam; + ua->user_lksb = ua_tmp->user_lksb; error = set_unlock_args(flags, ua, &args); if (error) From f4387149ec71fed11535b49400bad17d22fdc935 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 8 Aug 2006 13:23:19 -0400 Subject: [PATCH 192/292] [GFS2] Fix lack of buffers in writepage bug In some cases we can enter write page without there being buffers attached to the page. In this case the function to add gfs2_bufdata to the buffers fails sliently causing further failures down the stack. This fix ensures that we always add buffers in writepage if they didn't already exist (mmap is one way to trigger this). Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index bdd4d6b48721..45afd0508689 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -131,8 +131,8 @@ static int get_block_noalloc(struct inode *inode, sector_t lblock, static int gfs2_writepage(struct page *page, struct writeback_control *wbc) { struct inode *inode = page->mapping->host; - struct gfs2_inode *ip = GFS2_I(page->mapping->host); - struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host); + struct gfs2_inode *ip = GFS2_I(inode); + struct gfs2_sbd *sdp = GFS2_SB(inode); loff_t i_size = i_size_read(inode); pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT; unsigned offset; @@ -158,6 +158,10 @@ static int gfs2_writepage(struct page *page, struct writeback_control *wbc) error = gfs2_trans_begin(sdp, RES_DINODE + 1, 0); if (error) goto out_ignore; + if (!page_has_buffers(page)) { + create_empty_buffers(page, inode->i_sb->s_blocksize, + (1 << BH_Dirty)|(1 << BH_Uptodate)); + } gfs2_page_add_databufs(ip, page, 0, sdp->sd_vfs->s_blocksize-1); done_trans = 1; } From 5ff519112af6a6dab0ad7f6b0b0a2dcfff273e5b Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 8 Aug 2006 17:03:30 -0500 Subject: [PATCH 193/292] [DLM] print bad length in assertion Print the violating name length in the assertion. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c index 48dfc27861f4..989b608fd836 100644 --- a/fs/dlm/memory.c +++ b/fs/dlm/memory.c @@ -100,7 +100,8 @@ struct dlm_direntry *allocate_direntry(struct dlm_ls *ls, int namelen) { struct dlm_direntry *de; - DLM_ASSERT(namelen <= DLM_RESNAME_MAXLEN,); + DLM_ASSERT(namelen <= DLM_RESNAME_MAXLEN, + printk("namelen = %d\n", namelen);); de = kmalloc(sizeof(*de) + namelen, GFP_KERNEL); if (de) From f6db1b8e724b071d144055b48da3827ce26dba1c Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 8 Aug 2006 17:06:07 -0500 Subject: [PATCH 194/292] [DLM] abort recovery more quickly When we abort one recovery to do another, break out of the ping_members() routine more quickly, and wake up the dlm_recoverd thread more quickly instead of waiting for it to time out. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/member.c | 24 +++++++++++++++++++----- fs/dlm/recoverd.c | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/fs/dlm/member.c b/fs/dlm/member.c index cd0c51e724e0..ebb33c30f0f3 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -162,11 +162,22 @@ static void make_member_array(struct dlm_ls *ls) /* send a status request to all members just to establish comms connections */ -static void ping_members(struct dlm_ls *ls) +static int ping_members(struct dlm_ls *ls) { struct dlm_member *memb; - list_for_each_entry(memb, &ls->ls_nodes, list) - dlm_rcom_status(ls, memb->nodeid); + int error = 0; + + list_for_each_entry(memb, &ls->ls_nodes, list) { + error = dlm_recovery_stopped(ls); + if (error) + break; + error = dlm_rcom_status(ls, memb->nodeid); + if (error) + break; + } + if (error) + log_debug(ls, "ping_members aborted %d", error); + return error; } int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out) @@ -212,10 +223,13 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out) dlm_set_recover_status(ls, DLM_RS_NODES); *neg_out = neg; - ping_members(ls); + error = ping_members(ls); + if (error) + goto out; error = dlm_recover_members_wait(ls); - log_debug(ls, "total members %d", ls->ls_num_nodes); + out: + log_debug(ls, "total members %d error %d", ls->ls_num_nodes, error); return error; } diff --git a/fs/dlm/recoverd.c b/fs/dlm/recoverd.c index 70103533677d..eac8e9fa67f1 100644 --- a/fs/dlm/recoverd.c +++ b/fs/dlm/recoverd.c @@ -275,6 +275,7 @@ void dlm_recoverd_stop(struct dlm_ls *ls) void dlm_recoverd_suspend(struct dlm_ls *ls) { + wake_up(&ls->ls_wait_general); mutex_lock(&ls->ls_recoverd_active); } From 06442440bc442ef79cb060c6e786eaeeabd9044b Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 8 Aug 2006 11:31:30 -0500 Subject: [PATCH 195/292] [DLM] break from snprintf loop When the debug buffer has filled up, break from the loop and return the correct number of bytes that have been written. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/debug_fs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index 8f471d9a9e3a..9c3aeddc8667 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -310,16 +310,19 @@ static ssize_t waiters_read(struct file *file, char __user *userbuf, { struct dlm_ls *ls = file->private_data; struct dlm_lkb *lkb; - size_t len = DLM_DEBUG_BUF_LEN, pos = 0, rv; + size_t len = DLM_DEBUG_BUF_LEN, pos = 0, ret, rv; mutex_lock(&debug_buf_lock); mutex_lock(&ls->ls_waiters_mutex); memset(debug_buf, 0, sizeof(debug_buf)); list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) { - pos += snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n", - lkb->lkb_id, lkb->lkb_wait_type, - lkb->lkb_nodeid, lkb->lkb_resource->res_name); + ret = snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n", + lkb->lkb_id, lkb->lkb_wait_type, + lkb->lkb_nodeid, lkb->lkb_resource->res_name); + if (ret >= len - pos) + break; + pos += ret; } mutex_unlock(&ls->ls_waiters_mutex); From faa0f2677287a2e7ae796db8b73618ec43715e94 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Tue, 8 Aug 2006 17:08:42 -0500 Subject: [PATCH 196/292] [DLM] show nodeid for recovery message To aid debugging, it's useful to be able to see what nodeid the dlm is waiting on for a message reply. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/dlm_internal.h | 1 + fs/dlm/lockspace.c | 11 +++++++++++ fs/dlm/member.c | 3 ++- fs/dlm/rcom.c | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index 7c3c2d27c012..ec7e401133fd 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -467,6 +467,7 @@ struct dlm_ls { struct list_head ls_requestqueue;/* queue remote requests */ struct mutex ls_requestqueue_mutex; char *ls_recover_buf; + int ls_recover_nodeid; /* for debugging */ struct list_head ls_recover_list; spinlock_t ls_recover_list_lock; int ls_recover_list_count; diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index 31ed0fe16a31..7adaad53fc38 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -81,6 +81,11 @@ static ssize_t dlm_recover_status_show(struct dlm_ls *ls, char *buf) return sprintf(buf, "%x\n", status); } +static ssize_t dlm_recover_nodeid_show(struct dlm_ls *ls, char *buf) +{ + return sprintf(buf, "%d\n", ls->ls_recover_nodeid); +} + struct dlm_attr { struct attribute attr; ssize_t (*show)(struct dlm_ls *, char *); @@ -108,11 +113,17 @@ static struct dlm_attr dlm_attr_recover_status = { .show = dlm_recover_status_show }; +static struct dlm_attr dlm_attr_recover_nodeid = { + .attr = {.name = "recover_nodeid", .mode = S_IRUGO}, + .show = dlm_recover_nodeid_show +}; + static struct attribute *dlm_attrs[] = { &dlm_attr_control.attr, &dlm_attr_event.attr, &dlm_attr_id.attr, &dlm_attr_recover_status.attr, + &dlm_attr_recover_nodeid.attr, NULL, }; diff --git a/fs/dlm/member.c b/fs/dlm/member.c index ebb33c30f0f3..a3f7de7f3a8f 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -176,7 +176,8 @@ static int ping_members(struct dlm_ls *ls) break; } if (error) - log_debug(ls, "ping_members aborted %d", error); + log_debug(ls, "ping_members aborted %d last nodeid %d", + error, ls->ls_recover_nodeid); return error; } diff --git a/fs/dlm/rcom.c b/fs/dlm/rcom.c index 55fbe313340e..5573d8590e58 100644 --- a/fs/dlm/rcom.c +++ b/fs/dlm/rcom.c @@ -97,6 +97,7 @@ int dlm_rcom_status(struct dlm_ls *ls, int nodeid) int error = 0; memset(ls->ls_recover_buf, 0, dlm_config.buffer_size); + ls->ls_recover_nodeid = nodeid; if (nodeid == dlm_our_nodeid()) { rc = (struct dlm_rcom *) ls->ls_recover_buf; @@ -159,6 +160,7 @@ int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len) int error = 0, len = sizeof(struct dlm_rcom); memset(ls->ls_recover_buf, 0, dlm_config.buffer_size); + ls->ls_recover_nodeid = nodeid; if (nodeid == dlm_our_nodeid()) { dlm_copy_master_names(ls, last_name, last_len, From 4a99c3d9d6663085e28bc7ac8dae1e985c5a6174 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 9 Aug 2006 11:20:15 -0500 Subject: [PATCH 197/292] [DLM] reject replies to old requests When recoveries are aborted by other recoveries we can get replies to status or names requests that we've given up on. This can cause problems if we're making another request and receive an old reply. Add a sequence number to status/names requests and reject replies that don't match. A field already exists for the seq number that's used in other message types. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/dlm_internal.h | 1 + fs/dlm/rcom.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index ec7e401133fd..da7509986699 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -468,6 +468,7 @@ struct dlm_ls { struct mutex ls_requestqueue_mutex; char *ls_recover_buf; int ls_recover_nodeid; /* for debugging */ + uint64_t ls_rcom_seq; struct list_head ls_recover_list; spinlock_t ls_recover_list_lock; int ls_recover_list_count; diff --git a/fs/dlm/rcom.c b/fs/dlm/rcom.c index 5573d8590e58..64ba4929f90b 100644 --- a/fs/dlm/rcom.c +++ b/fs/dlm/rcom.c @@ -108,6 +108,7 @@ int dlm_rcom_status(struct dlm_ls *ls, int nodeid) error = create_rcom(ls, nodeid, DLM_RCOM_STATUS, 0, &rc, &mh); if (error) goto out; + rc->rc_id = ++ls->ls_rcom_seq; send_rcom(ls, mh, rc); @@ -140,19 +141,30 @@ static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in) sizeof(struct rcom_config), &rc, &mh); if (error) return; + rc->rc_id = rc_in->rc_id; rc->rc_result = dlm_recover_status(ls); make_config(ls, (struct rcom_config *) rc->rc_buf); send_rcom(ls, mh, rc); } -static void receive_rcom_status_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) +static void receive_sync_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) { + if (rc_in->rc_id != ls->ls_rcom_seq) { + log_debug(ls, "reject old reply %d got %llx wanted %llx", + rc_in->rc_type, rc_in->rc_id, ls->ls_rcom_seq); + return; + } memcpy(ls->ls_recover_buf, rc_in, rc_in->rc_header.h_length); set_bit(LSFL_RCOM_READY, &ls->ls_flags); wake_up(&ls->ls_wait_general); } +static void receive_rcom_status_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) +{ + receive_sync_reply(ls, rc_in); +} + int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len) { struct dlm_rcom *rc; @@ -173,6 +185,7 @@ int dlm_rcom_names(struct dlm_ls *ls, int nodeid, char *last_name, int last_len) if (error) goto out; memcpy(rc->rc_buf, last_name, last_len); + rc->rc_id = ++ls->ls_rcom_seq; send_rcom(ls, mh, rc); @@ -209,6 +222,7 @@ static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in) error = create_rcom(ls, nodeid, DLM_RCOM_NAMES_REPLY, outlen, &rc, &mh); if (error) return; + rc->rc_id = rc_in->rc_id; dlm_copy_master_names(ls, rc_in->rc_buf, inlen, rc->rc_buf, outlen, nodeid); @@ -217,9 +231,7 @@ static void receive_rcom_names(struct dlm_ls *ls, struct dlm_rcom *rc_in) static void receive_rcom_names_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in) { - memcpy(ls->ls_recover_buf, rc_in, rc_in->rc_header.h_length); - set_bit(LSFL_RCOM_READY, &ls->ls_flags); - wake_up(&ls->ls_wait_general); + receive_sync_reply(ls, rc_in); } int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodeid) From 8872187780f6104216c67e7b60c11f708b513c38 Mon Sep 17 00:00:00 2001 From: Russell Cattelan Date: Thu, 10 Aug 2006 11:08:40 -0500 Subject: [PATCH 198/292] [GFS2] Fix a couple of refcount leaks. recovery.c add a brelse to deal with gfs2_replay_read_block being called twice on the same block. add a dput to drop the ref count on the root inode. This was causing lingering glocks and thus causing a mount failure to hang. Fix a endian conversion macro that was was swizzling 16bits when it should have been swizzling 32. Signed-off-by: Russell Cattelan Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 9 ++++++--- fs/gfs2/ops_fstype.c | 4 ++++ fs/gfs2/recovery.c | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index b6edf7c0923b..a5e16e539999 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -2167,7 +2167,9 @@ static int dump_glock(struct gfs2_glock *gl) spin_lock(&gl->gl_spin); - printk(KERN_INFO "Glock (%u, %llu)\n", gl->gl_name.ln_type, + printk(KERN_INFO "Glock 0x%p (%u, %llu)\n", + gl, + gl->gl_name.ln_type, (unsigned long long)gl->gl_name.ln_number); printk(KERN_INFO " gl_flags ="); for (x = 0; x < 32; x++) @@ -2187,8 +2189,9 @@ static int dump_glock(struct gfs2_glock *gl) printk(KERN_INFO " reclaim = %s\n", (list_empty(&gl->gl_reclaim)) ? "no" : "yes"); if (gl->gl_aspace) - printk(KERN_INFO " aspace = %lu\n", - gl->gl_aspace->i_mapping->nrpages); + printk(KERN_INFO " aspace = 0x%p nrpages = %lu\n", + gl->gl_aspace, + gl->gl_aspace->i_mapping->nrpages); else printk(KERN_INFO " aspace = no\n"); printk(KERN_INFO " ail = %d\n", atomic_read(&gl->gl_ail_count)); diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index de18923eea70..444000968cf4 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -279,6 +279,10 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) int error = 0; if (undo) { + if (sb->s_root) { + dput(sb->s_root); + sb->s_root = NULL; + } return 0; } diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index bbd44a4b1a1f..8fe518cfb3de 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -325,6 +325,7 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, error = get_log_header(jd, start, &lh); if (!error) { gfs2_replay_incr_blk(sdp, &start); + brelse(bh); continue; } if (error == 1) { @@ -396,7 +397,7 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) lh = (struct gfs2_log_header *)bh->b_data; memset(lh, 0, sizeof(struct gfs2_log_header)); lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); - lh->lh_header.mh_type = cpu_to_be16(GFS2_METATYPE_LH); + lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH); lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH); lh->lh_sequence = cpu_to_be64(head->lh_sequence + 1); lh->lh_flags = cpu_to_be32(GFS2_LOG_HEAD_UNMOUNT); From fcc8abc8d4fcdbddc383091449f3696b411aa8fb Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 10 Aug 2006 13:31:23 -0500 Subject: [PATCH 199/292] [DLM] move kmap to after spin_unlock Doing the kmap() while holding the spinlock was causing recursive spinlock problems. It seems the kmap was scheduling, although there was no warning as I'd expect. Patrick, do we need locking around the kmap? Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lowcomms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index 7ab40422ab57..23f5ce12080b 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -934,11 +934,11 @@ static int send_to_sock(struct nodeinfo *ni) break; e = list_entry(ni->writequeue.next, struct writequeue_entry, list); - kmap(e->page); len = e->len; offset = e->offset; BUG_ON(len == 0 && e->users == 0); spin_unlock(&ni->writequeue_lock); + kmap(e->page); ret = 0; if (len) { From 15d00c0b91ca776b51b5ab04f79ab35b06670d30 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 18 Aug 2006 15:51:09 -0400 Subject: [PATCH 200/292] [GFS2] Fix leak of gfs2_bufdata This fixes a memory leak of struct gfs2_bufdata and also some problems in the ordered write handling code. It needs a bit more testing, but I believe that the reference counting of ordered write buffers should now be correct. This is aimed at fixing Red Hat bugzilla: #201028 and #201082 Signed-off-by: Steven Whitehouse --- fs/gfs2/lops.c | 6 +++--- fs/gfs2/meta_io.c | 1 - fs/gfs2/ops_address.c | 8 +++----- fs/gfs2/ops_super.c | 2 -- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index af03bf380f46..04bceb75ff23 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -464,7 +464,7 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) struct gfs2_inode *ip = GFS2_I(mapping->host); tr->tr_touched = 1; - if (!list_empty(&bd->bd_list_tr) && + if (list_empty(&bd->bd_list_tr) && (ip->i_di.di_flags & GFS2_DIF_JDATA)) { tr->tr_num_buf++; list_add(&bd->bd_list_tr, &tr->tr_list_buf); @@ -473,7 +473,7 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) } gfs2_trans_add_gl(bd->bd_gl); gfs2_log_lock(sdp); - if (!list_empty(&le->le_list)) { + if (list_empty(&le->le_list)) { if (ip->i_di.di_flags & GFS2_DIF_JDATA) sdp->sd_log_num_jdata++; sdp->sd_log_num_databuf++; @@ -640,10 +640,10 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) bd_le.le_list); list_del(&bd1->bd_le.le_list); sdp->sd_log_num_databuf--; - bh = bd1->bd_bh; if (bh) { bh->b_private = NULL; + get_bh(bh); gfs2_log_unlock(sdp); wait_on_buffer(bh); brelse(bh); diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 42dfd32059bc..502864b24196 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -464,7 +464,6 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, lops_init_le(&bd->bd_le, &gfs2_buf_lops); } else { lops_init_le(&bd->bd_le, &gfs2_databuf_lops); - get_bh(bh); } bh->b_private = bd; diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 45afd0508689..4c59cb110995 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -581,10 +581,8 @@ static void discard_buffer(struct gfs2_sbd *sdp, struct buffer_head *bh) if (bd) { bd->bd_bh = NULL; bh->b_private = NULL; - gfs2_log_unlock(sdp); - brelse(bh); - } else - gfs2_log_unlock(sdp); + } + gfs2_log_unlock(sdp); lock_buffer(bh); clear_buffer_dirty(bh); @@ -598,7 +596,7 @@ static void discard_buffer(struct gfs2_sbd *sdp, struct buffer_head *bh) static void gfs2_invalidatepage(struct page *page, unsigned long offset) { - struct gfs2_sbd *sdp = page->mapping->host->i_sb->s_fs_info; + struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host); struct buffer_head *head, *bh, *next; unsigned int curr_off = 0; diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 730c7228f6ad..2e392c994ab1 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -216,8 +216,6 @@ static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf) if (error) return error; - memset(buf, 0, sizeof(struct kstatfs)); - buf->f_type = GFS2_MAGIC; buf->f_bsize = sdp->sd_sb.sb_bsize; buf->f_blocks = sc.sc_total; From a345da3e8f28ff69e1b14df78f7ddc6e7b78b726 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 18 Aug 2006 11:54:25 -0500 Subject: [PATCH 201/292] [DLM] dump rsb and locks on assert Introduce new function dlm_dump_rsb() to call within assertions instead of dlm_print_rsb(). The new function dumps info about all locks on the rsb in addition to rsb details. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 40 +++++++++++++++++++++++++++++++--------- fs/dlm/lock.h | 1 + fs/dlm/recover.c | 4 ++-- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index bb2e35151210..712438513cc4 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -171,6 +171,28 @@ void dlm_print_rsb(struct dlm_rsb *r) r->res_recover_locks_count, r->res_name); } +void dlm_dump_rsb(struct dlm_rsb *r) +{ + struct dlm_lkb *lkb; + + dlm_print_rsb(r); + + printk(KERN_ERR "rsb: root_list empty %d recover_list empty %d\n", + list_empty(&r->res_root_list), list_empty(&r->res_recover_list)); + printk(KERN_ERR "rsb lookup list\n"); + list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) + dlm_print_lkb(lkb); + printk(KERN_ERR "rsb grant queue:\n"); + list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) + dlm_print_lkb(lkb); + printk(KERN_ERR "rsb convert queue:\n"); + list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) + dlm_print_lkb(lkb); + printk(KERN_ERR "rsb wait queue:\n"); + list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) + dlm_print_lkb(lkb); +} + /* Threads cannot use the lockspace while it's being recovered */ static inline void lock_recovery(struct dlm_ls *ls) @@ -478,7 +500,7 @@ static void unhold_rsb(struct dlm_rsb *r) { int rv; rv = kref_put(&r->res_ref, toss_rsb); - DLM_ASSERT(!rv, dlm_print_rsb(r);); + DLM_ASSERT(!rv, dlm_dump_rsb(r);); } static void kill_rsb(struct kref *kref) @@ -488,12 +510,12 @@ static void kill_rsb(struct kref *kref) /* All work is done after the return from kref_put() so we can release the write_lock before the remove and free. */ - DLM_ASSERT(list_empty(&r->res_lookup),); - DLM_ASSERT(list_empty(&r->res_grantqueue),); - DLM_ASSERT(list_empty(&r->res_convertqueue),); - DLM_ASSERT(list_empty(&r->res_waitqueue),); - DLM_ASSERT(list_empty(&r->res_root_list),); - DLM_ASSERT(list_empty(&r->res_recover_list),); + DLM_ASSERT(list_empty(&r->res_lookup), dlm_dump_rsb(r);); + DLM_ASSERT(list_empty(&r->res_grantqueue), dlm_dump_rsb(r);); + DLM_ASSERT(list_empty(&r->res_convertqueue), dlm_dump_rsb(r);); + DLM_ASSERT(list_empty(&r->res_waitqueue), dlm_dump_rsb(r);); + DLM_ASSERT(list_empty(&r->res_root_list), dlm_dump_rsb(r);); + DLM_ASSERT(list_empty(&r->res_recover_list), dlm_dump_rsb(r);); } /* Attaching/detaching lkb's from rsb's is for rsb reference counting. @@ -1336,7 +1358,7 @@ static void grant_pending_locks(struct dlm_rsb *r) struct dlm_lkb *lkb, *s; int high = DLM_LOCK_IV; - DLM_ASSERT(is_master(r), dlm_print_rsb(r);); + DLM_ASSERT(is_master(r), dlm_dump_rsb(r);); high = grant_pending_convert(r, high); high = grant_pending_wait(r, high); @@ -1431,7 +1453,7 @@ static int set_master(struct dlm_rsb *r, struct dlm_lkb *lkb) return 0; } - DLM_ASSERT(r->res_nodeid == -1, dlm_print_rsb(r);); + DLM_ASSERT(r->res_nodeid == -1, dlm_dump_rsb(r);); dir_nodeid = dlm_dir_nodeid(r); diff --git a/fs/dlm/lock.h b/fs/dlm/lock.h index 8d2660f0ab10..0843a3073ec3 100644 --- a/fs/dlm/lock.h +++ b/fs/dlm/lock.h @@ -14,6 +14,7 @@ #define __LOCK_DOT_H__ void dlm_print_rsb(struct dlm_rsb *r); +void dlm_dump_rsb(struct dlm_rsb *r); void dlm_print_lkb(struct dlm_lkb *lkb); int dlm_receive_message(struct dlm_header *hd, int nodeid, int recovery); int dlm_modes_compat(int mode1, int mode2); diff --git a/fs/dlm/recover.c b/fs/dlm/recover.c index 1a86dfc8034e..528a2a0fa329 100644 --- a/fs/dlm/recover.c +++ b/fs/dlm/recover.c @@ -490,7 +490,7 @@ static int recover_locks(struct dlm_rsb *r) if (all_queues_empty(r)) goto out; - DLM_ASSERT(!r->res_recover_locks_count, dlm_print_rsb(r);); + DLM_ASSERT(!r->res_recover_locks_count, dlm_dump_rsb(r);); error = recover_locks_queue(r, &r->res_grantqueue); if (error) @@ -557,7 +557,7 @@ int dlm_recover_locks(struct dlm_ls *ls) void dlm_recovered_lock(struct dlm_rsb *r) { - DLM_ASSERT(rsb_flag(r, RSB_NEW_MASTER), dlm_print_rsb(r);); + DLM_ASSERT(rsb_flag(r, RSB_NEW_MASTER), dlm_dump_rsb(r);); r->res_recover_locks_count--; if (!r->res_recover_locks_count) { From 08867605e1d5f575685aa2b5bf575aba3d996758 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 22 Aug 2006 11:03:57 -0400 Subject: [PATCH 202/292] [GFS2] Fix to list_del in lops.c A list_del should have been a list_del_init in lops.c which was resulting in incorrect status returns from list_empty(). Signed-off-by: Steven Whitheouse --- fs/gfs2/lops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 04bceb75ff23..82dfc96c4f59 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -638,7 +638,7 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) gfs2_log_lock(sdp); bd1 = list_entry(started.next, struct gfs2_bufdata, bd_le.le_list); - list_del(&bd1->bd_le.le_list); + list_del_init(&bd1->bd_le.le_list); sdp->sd_log_num_databuf--; bh = bd1->bd_bh; if (bh) { From b8e1aabf218a2037d9d6a3256c33fc6ef96ac44c Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 22 Aug 2006 16:25:50 -0400 Subject: [PATCH 203/292] [GFS2] Another list_del bug Another case where list_del should be list_del_init. Signed-off-by: Steven Whitehouse --- fs/gfs2/lops.c | 2 +- fs/gfs2/rgrp.c | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 82dfc96c4f59..08de8b7fb316 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -737,7 +737,7 @@ static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) while (!list_empty(head)) { bd = list_entry(head->next, struct gfs2_bufdata, bd_le.le_list); - list_del(&bd->bd_le.le_list); + list_del_init(&bd->bd_le.le_list); sdp->sd_log_num_databuf--; sdp->sd_log_num_jdata--; gfs2_unpin(sdp, bd->bd_bh, ai); diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 4e0357dc838b..84fcc1bfaf1b 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -857,8 +857,7 @@ static struct gfs2_rgrpd *forward_rgrp_get(struct gfs2_sbd *sdp) if (sdp->sd_rgrps >= journals) rg = sdp->sd_rgrps * sdp->sd_jdesc->jd_jid / journals; - for (x = 0, rgd = gfs2_rgrpd_get_first(sdp); - x < rg; + for (x = 0, rgd = gfs2_rgrpd_get_first(sdp); x < rg; x++, rgd = gfs2_rgrpd_get_next(rgd)) /* Do Nothing */; @@ -909,9 +908,8 @@ static int get_local_rgrp(struct gfs2_inode *ip) rgd = recent_rgrp_first(sdp, ip->i_last_rg_alloc); while (rgd) { - error = gfs2_glock_nq_init(rgd->rd_gl, - LM_ST_EXCLUSIVE, LM_FLAG_TRY, - &al->al_rgd_gh); + error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, + LM_FLAG_TRY, &al->al_rgd_gh); switch (error) { case 0: if (try_rgrp_fit(rgd, al)) @@ -934,8 +932,7 @@ static int get_local_rgrp(struct gfs2_inode *ip) begin = rgd = forward_rgrp_get(sdp); for (;;) { - error = gfs2_glock_nq_init(rgd->rd_gl, - LM_ST_EXCLUSIVE, flags, + error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, flags, &al->al_rgd_gh); switch (error) { case 0: From 10948eb4eddea6750a3b27f77bec423d844e6726 Mon Sep 17 00:00:00 2001 From: Patrick Caulfield Date: Wed, 23 Aug 2006 09:49:31 +0100 Subject: [PATCH 204/292] [DLM] preserve lksb address in user conversions This patch fixes bz#203444 where the LKSB was lost during userland conversion operations Signed-off-by: Patrick Caulfield Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 712438513cc4..7ffbe8090de0 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -3683,6 +3683,7 @@ int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, ua->castaddr = ua_tmp->castaddr; ua->bastparam = ua_tmp->bastparam; ua->bastaddr = ua_tmp->bastaddr; + ua->user_lksb = ua_tmp->user_lksb; ua->old_mode = lkb->lkb_grmode; error = set_lock_args(mode, &ua->lksb, flags, 0, 0, FAKE_USER_AST, ua, From c059f70e357af1adcfc1a9294e44cdd945adb841 Mon Sep 17 00:00:00 2001 From: Patrick Caulfield Date: Wed, 23 Aug 2006 10:24:03 +0100 Subject: [PATCH 205/292] [DLM] down conversion clearing flags Oh, and here's (hopefully) the last of these ua_tmp patches. I think I've caught all the paths now. Sorry it didn't make the last one. Signed-off-by: Patrick Caulfield Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 7ffbe8090de0..6dcd475826c1 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -3765,6 +3765,7 @@ int dlm_user_cancel(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, ua = (struct dlm_user_args *)lkb->lkb_astparam; ua->castparam = ua_tmp->castparam; + ua->user_lksb = ua_tmp->user_lksb; error = set_unlock_args(flags, ua, &args); if (error) From 32f105a123804c7882d447f013aeb3530b4d63c0 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 23 Aug 2006 16:07:31 -0400 Subject: [PATCH 206/292] [DLM] down conversion clearing flags The down-conversion optimization was resulting in the lkb flags being cleared because the stub message reply had no flags value set. Copy the current flags into the stub message so they'll be copied back into the lkb as part of processing the fake reply. Also add an assertion to catch this error more directly if it exists elsewhere. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/ast.c | 1 + fs/dlm/dlm_internal.h | 2 ++ fs/dlm/lock.c | 9 ++++----- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/dlm/ast.c b/fs/dlm/ast.c index a211330cbc42..f91d39cb1e0b 100644 --- a/fs/dlm/ast.c +++ b/fs/dlm/ast.c @@ -38,6 +38,7 @@ void dlm_add_ast(struct dlm_lkb *lkb, int type) dlm_user_add_ast(lkb, type); return; } + DLM_ASSERT(lkb->lkb_astaddr != DLM_FAKE_USER_AST, dlm_print_lkb(lkb);); spin_lock(&ast_queue_lock); if (!(lkb->lkb_ast_type & (AST_COMP | AST_BAST))) { diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index da7509986699..1e5cd67e1b7a 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -91,6 +91,8 @@ struct dlm_mhandle; } \ } +#define DLM_FAKE_USER_AST ERR_PTR(-EINVAL) + struct dlm_direntry { struct list_head list; diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 6dcd475826c1..67247f0b508a 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -86,8 +86,6 @@ static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, struct dlm_message *ms); static int receive_extralen(struct dlm_message *ms); -#define FAKE_USER_AST (void*)0xff00ff00 - /* * Lock compatibilty matrix - thanks Steve * UN = Unlocked state. Not really a state, used as a flag @@ -2195,6 +2193,7 @@ static int send_convert(struct dlm_rsb *r, struct dlm_lkb *lkb) if (!error && down_conversion(lkb)) { remove_from_waiters(lkb); r->res_ls->ls_stub_ms.m_result = 0; + r->res_ls->ls_stub_ms.m_flags = lkb->lkb_flags; __receive_convert_reply(r, lkb, &r->res_ls->ls_stub_ms); } @@ -3615,7 +3614,7 @@ int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua, lock and that lkb_astparam is the dlm_user_args structure. */ error = set_lock_args(mode, &ua->lksb, flags, namelen, parent_lkid, - FAKE_USER_AST, ua, FAKE_USER_AST, &args); + DLM_FAKE_USER_AST, ua, DLM_FAKE_USER_AST, &args); lkb->lkb_flags |= DLM_IFL_USER; ua->old_mode = DLM_LOCK_IV; @@ -3686,8 +3685,8 @@ int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp, ua->user_lksb = ua_tmp->user_lksb; ua->old_mode = lkb->lkb_grmode; - error = set_lock_args(mode, &ua->lksb, flags, 0, 0, FAKE_USER_AST, ua, - FAKE_USER_AST, &args); + error = set_lock_args(mode, &ua->lksb, flags, 0, 0, DLM_FAKE_USER_AST, + ua, DLM_FAKE_USER_AST, &args); if (error) goto out_put; From f5888750aad219bec42f3f28354eb230d1a47b89 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 23 Aug 2006 12:50:54 -0500 Subject: [PATCH 207/292] [DLM] sequence number missing in not_ready reply When a status reply is sent for a lockspace that doesn't yet exist, the message sequence number from the sender was not being copied into the reply causing the sender to ignore the reply. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/rcom.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/dlm/rcom.c b/fs/dlm/rcom.c index 64ba4929f90b..518239a8b1e9 100644 --- a/fs/dlm/rcom.c +++ b/fs/dlm/rcom.c @@ -388,6 +388,7 @@ static int send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in) rc->rc_header.h_cmd = DLM_RCOM; rc->rc_type = DLM_RCOM_STATUS_REPLY; + rc->rc_id = rc_in->rc_id; rc->rc_result = -ESRCH; dlm_rcom_out(rc); From 233e515f4062f99569c24f00ad7429a860b23db4 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 23 Aug 2006 16:05:44 -0500 Subject: [PATCH 208/292] [DLM] recover_locks not clearing NEW_MASTER flag When there are no locks on a resource, the recover_locks() function fails to clear the NEW_MASTER flag by going directly to out, missing the line that clears the flag. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/recover.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/fs/dlm/recover.c b/fs/dlm/recover.c index 528a2a0fa329..a5e6d184872e 100644 --- a/fs/dlm/recover.c +++ b/fs/dlm/recover.c @@ -473,22 +473,11 @@ static int recover_locks_queue(struct dlm_rsb *r, struct list_head *head) return error; } -static int all_queues_empty(struct dlm_rsb *r) -{ - if (!list_empty(&r->res_grantqueue) || - !list_empty(&r->res_convertqueue) || - !list_empty(&r->res_waitqueue)) - return 0; - return 1; -} - static int recover_locks(struct dlm_rsb *r) { int error = 0; lock_rsb(r); - if (all_queues_empty(r)) - goto out; DLM_ASSERT(!r->res_recover_locks_count, dlm_dump_rsb(r);); From 166afccd71fbb7bd758ab9fc770eef4924081077 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 24 Aug 2006 15:59:40 -0400 Subject: [PATCH 209/292] [GFS2] Tidy up error handling in gfs2_releasepage() This should clarify the logic in gfs2_releasepage() relating to error handling as well as making the response to errors a bit more graceful. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 4c59cb110995..48720421c796 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -683,6 +683,10 @@ static void stuck_releasepage(struct buffer_head *bh) struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; struct gfs2_bufdata *bd = bh->b_private; struct gfs2_glock *gl; +static unsigned limit = 0; + + if (limit++ > 3) + return; fs_warn(sdp, "stuck in gfs2_releasepage() %p\n", inode); fs_warn(sdp, "blkno = %llu, bh->b_count = %d\n", @@ -736,28 +740,24 @@ int gfs2_releasepage(struct page *page, gfp_t gfp_mask) struct gfs2_sbd *sdp = aspace->i_sb->s_fs_info; struct buffer_head *bh, *head; struct gfs2_bufdata *bd; - unsigned long t; + unsigned long t = jiffies + gfs2_tune_get(sdp, gt_stall_secs) * HZ; if (!page_has_buffers(page)) goto out; head = bh = page_buffers(page); do { - t = jiffies; - while (atomic_read(&bh->b_count)) { - if (atomic_read(&aspace->i_writecount)) { - if (time_after_eq(jiffies, t + - gfs2_tune_get(sdp, gt_stall_secs) * HZ)) { - stuck_releasepage(bh); - t = jiffies; - } + if (!atomic_read(&aspace->i_writecount)) + return 0; - yield(); - continue; + if (time_after_eq(jiffies, t)) { + stuck_releasepage(bh); + /* should we withdraw here? */ + return 0; } - return 0; + yield(); } gfs2_assert_warn(sdp, !buffer_pinned(bh)); @@ -773,8 +773,7 @@ int gfs2_releasepage(struct page *page, gfp_t gfp_mask) } bh = bh->b_this_page; - } - while (bh != head); + } while (bh != head); out: return try_to_free_buffers(page); From a2242db0906445491d9ac50bfa756b0de0a25d45 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 24 Aug 2006 17:03:05 -0400 Subject: [PATCH 210/292] [GFS2] Speed up scanning of glocks I noticed the gfs2_scand seemed to be taking a lot of CPU, so in order to cut that down a bit, here is a patch. Firstly the type of a glock is a constant during its lifetime, so that its possible to check this without needing locking. I've moved the (common) case of testing for an inode glock outside of the glmutex lock. Also there was a mutex left over from when the glock cache was master of the inode cache. That isn't required any more so I've removed that too. There is probably scope for further speed ups in the future in this area. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 24 +++++------------------- fs/gfs2/incore.h | 1 - fs/gfs2/ops_fstype.c | 1 - 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index a5e16e539999..005788fb361f 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -150,12 +150,9 @@ static void kill_glock(struct kref *kref) int gfs2_glock_put(struct gfs2_glock *gl) { - struct gfs2_sbd *sdp = gl->gl_sbd; struct gfs2_gl_hash_bucket *bucket = gl->gl_bucket; int rv = 0; - mutex_lock(&sdp->sd_invalidate_inodes_mutex); - write_lock(&bucket->hb_lock); if (kref_put(&gl->gl_ref, kill_glock)) { list_del_init(&gl->gl_list); @@ -166,8 +163,7 @@ int gfs2_glock_put(struct gfs2_glock *gl) goto out; } write_unlock(&bucket->hb_lock); - out: - mutex_unlock(&sdp->sd_invalidate_inodes_mutex); +out: return rv; } @@ -1964,19 +1960,18 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, static void scan_glock(struct gfs2_glock *gl) { + if (gl->gl_ops == &gfs2_inode_glops) + goto out; + if (gfs2_glmutex_trylock(gl)) { - if (gl->gl_ops == &gfs2_inode_glops) - goto out; if (queue_empty(gl, &gl->gl_holders) && gl->gl_state != LM_ST_UNLOCKED && demote_ok(gl)) goto out_schedule; -out: gfs2_glmutex_unlock(gl); } - +out: gfs2_glock_put(gl); - return; out_schedule: @@ -2070,16 +2065,7 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait) t = jiffies; } - /* invalidate_inodes() requires that the sb inodes list - not change, but an async completion callback for an - unlock can occur which does glock_put() which - can call iput() which will change the sb inodes list. - invalidate_inodes_mutex prevents glock_put()'s during - an invalidate_inodes() */ - - mutex_lock(&sdp->sd_invalidate_inodes_mutex); invalidate_inodes(sdp->sd_vfs); - mutex_unlock(&sdp->sd_invalidate_inodes_mutex); msleep(10); } } diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index e98c14f30daa..78d3cb511eb8 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -507,7 +507,6 @@ struct gfs2_sbd { struct gfs2_holder sd_live_gh; struct gfs2_glock *sd_rename_gl; struct gfs2_glock *sd_trans_gl; - struct mutex sd_invalidate_inodes_mutex; /* Inode Stuff */ diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 444000968cf4..c66067c84bcf 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -63,7 +63,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) INIT_LIST_HEAD(&sdp->sd_reclaim_list); spin_lock_init(&sdp->sd_reclaim_lock); init_waitqueue_head(&sdp->sd_reclaim_wq); - mutex_init(&sdp->sd_invalidate_inodes_mutex); mutex_init(&sdp->sd_inum_mutex); spin_lock_init(&sdp->sd_statfs_spin); From 5dc39fe621ead2fa2a0439a686be4df185861eae Mon Sep 17 00:00:00 2001 From: Benjamin Marzinski Date: Thu, 24 Aug 2006 14:47:17 -0500 Subject: [PATCH 211/292] [GFS2] Fix journal off-by-one error log_refund() incorrectly assumed that if a transaction had been touched, it always committed buffers to the incore log. Thus, when you got around to flushing the log, you would need one more block than you committed, to account for the header. So it automatically set reserved to 1, which had the effect of making sdp->sd_log_blks_reserved one greater when you got to gfs2_log_flush(). However, if you don't actually commit anything to the incore log between flushes, you don't need the header, because you aren't writing anything out. With this patch, log_refund() only increments reservered to account for the header if something has been committed since the last flush. Signed-off-by: Benjamin E. Marzinski Signed-off-by: Steven Whitehouse --- fs/gfs2/log.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index a591fb8fae20..af728cb3b327 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -509,7 +509,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) { - unsigned int reserved = 1; + unsigned int reserved = 0; unsigned int old; gfs2_log_lock(sdp); @@ -524,6 +524,8 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) if (sdp->sd_log_commited_revoke) reserved += gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke, sizeof(uint64_t)); + if (reserved) + reserved++; old = sdp->sd_log_blks_free; sdp->sd_log_blks_free += tr->tr_reserved - From 5f88f1ea16a2fb5f125505053d1bfb7901a88c64 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 24 Aug 2006 14:47:20 -0500 Subject: [PATCH 212/292] [DLM] add new lockspace to list ealier When a new lockspace was being created, the recoverd thread was being started for it before the lockspace was added to the global list of lockspaces. The new thread was looking up the lockspace in the global list and sometimes not finding it due to the race with the original thread adding it to the list. We need to add the lockspace to the global list before starting the thread instead of after, and if the new thread can't find the lockspace for some reason, it should return an error. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lockspace.c | 13 +++++++------ fs/dlm/recoverd.c | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index 7adaad53fc38..ff83f80e43eb 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -488,16 +488,17 @@ static int new_lockspace(char *name, int namelen, void **lockspace, down_write(&ls->ls_in_recovery); + spin_lock(&lslist_lock); + list_add(&ls->ls_list, &lslist); + spin_unlock(&lslist_lock); + + /* needs to find ls in lslist */ error = dlm_recoverd_start(ls); if (error) { log_error(ls, "can't start dlm_recoverd %d", error); goto out_rcomfree; } - spin_lock(&lslist_lock); - list_add(&ls->ls_list, &lslist); - spin_unlock(&lslist_lock); - dlm_create_debug_file(ls); error = kobject_setup(ls); @@ -519,11 +520,11 @@ static int new_lockspace(char *name, int namelen, void **lockspace, kobject_unregister(&ls->ls_kobj); out_del: dlm_delete_debug_file(ls); + dlm_recoverd_stop(ls); + out_rcomfree: spin_lock(&lslist_lock); list_del(&ls->ls_list); spin_unlock(&lslist_lock); - dlm_recoverd_stop(ls); - out_rcomfree: kfree(ls->ls_recover_buf); out_dirfree: kfree(ls->ls_dirtbl); diff --git a/fs/dlm/recoverd.c b/fs/dlm/recoverd.c index eac8e9fa67f1..362e3eff4dc9 100644 --- a/fs/dlm/recoverd.c +++ b/fs/dlm/recoverd.c @@ -234,6 +234,10 @@ static int dlm_recoverd(void *arg) struct dlm_ls *ls; ls = dlm_find_lockspace_local(arg); + if (!ls) { + log_print("dlm_recoverd: no lockspace %p", arg); + return -1; + } while (!kthread_should_stop()) { set_current_state(TASK_INTERRUPTIBLE); From 8638460540749ddb1beca9e9a68d655a6fe6df65 Mon Sep 17 00:00:00 2001 From: Abhijith Das Date: Fri, 25 Aug 2006 11:13:37 -0500 Subject: [PATCH 213/292] [GFS2] Allow mounting of gfs2 and gfs2meta at the same time This patch allows the simultaneous mounting of gfs2meta and gfs2 filesystems. A restriction however is that a gfs2meta fs may only be mounted if its corresponding gfs2 filesystem is also mounted. Also, a gfs2 filesystem cannot be unmounted before its gfs2meta filesystem. Signed-off-by: Abhijith Das Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 6 ++ fs/gfs2/incore.h | 2 + fs/gfs2/ops_fstype.c | 147 ++++++++++++++++++++++++++++++++++++++++++- fs/gfs2/ops_super.c | 3 + 4 files changed, 155 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 005788fb361f..ef713dbff601 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1165,7 +1165,13 @@ static void add_to_queue(struct gfs2_holder *gh) existing = find_holder_by_owner(&gl->gl_holders, gh->gh_owner); if (existing) { print_symbol(KERN_WARNING "original: %s\n", existing->gh_ip); + printk(KERN_INFO "pid : %d\n", existing->gh_owner->pid); + printk(KERN_INFO "lock type : %d lock state : %d\n", + existing->gh_gl->gl_name.ln_type, existing->gh_gl->gl_state); print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip); + printk(KERN_INFO "pid : %d\n", gh->gh_owner->pid); + printk(KERN_INFO "lock type : %d lock state : %d\n", + gl->gl_name.ln_type, gl->gl_state); BUG(); } diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 78d3cb511eb8..77f0903d2f3e 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -472,6 +472,7 @@ enum { struct gfs2_sbd { struct super_block *sd_vfs; + struct super_block *sd_vfs_meta; struct kobject sd_kobj; unsigned long sd_flags; /* SDF_... */ struct gfs2_sb sd_sb; @@ -652,6 +653,7 @@ struct gfs2_sbd { /* Debugging crud */ unsigned long sd_last_warning; + struct vfsmount *sd_gfs2mnt; }; #endif /* __INCORE_DOT_H__ */ diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index c66067c84bcf..e5a91ead250c 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include "gfs2.h" @@ -813,7 +815,138 @@ static int fill_super(struct super_block *sb, void *data, int silent) static int gfs2_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data, struct vfsmount *mnt) { - return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt); + struct super_block *sb; + struct gfs2_sbd *sdp; + int error = get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt); + if (error) + goto out; + sb = mnt->mnt_sb; + sdp = (struct gfs2_sbd*)sb->s_fs_info; + sdp->sd_gfs2mnt = mnt; +out: + return error; +} + +static int fill_super_meta(struct super_block *sb, struct super_block *new, + void *data, int silent) +{ + struct gfs2_sbd *sdp = sb->s_fs_info; + struct inode *inode; + int error = 0; + + new->s_fs_info = sdp; + sdp->sd_vfs_meta = sb; + + init_vfs(new, SDF_NOATIME); + + /* Get the master inode */ + inode = igrab(sdp->sd_master_dir); + + new->s_root = d_alloc_root(inode); + if (!new->s_root) { + fs_err(sdp, "can't get root dentry\n"); + error = -ENOMEM; + iput(inode); + } + new->s_root->d_op = &gfs2_dops; + + return error; +} +static int set_bdev_super(struct super_block *s, void *data) +{ + s->s_bdev = data; + s->s_dev = s->s_bdev->bd_dev; + return 0; +} + +static int test_bdev_super(struct super_block *s, void *data) +{ + return (void *)s->s_bdev == data; +} + +static struct super_block* get_gfs2_sb(const char *dev_name) +{ + struct kstat stat; + struct nameidata nd; + struct file_system_type *fstype; + struct super_block *sb = NULL, *s; + struct list_head *l; + int error; + + error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd); + if (error) { + printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n", + dev_name); + goto out; + } + error = vfs_getattr(nd.mnt, nd.dentry, &stat); + + fstype = get_fs_type("gfs2"); + list_for_each(l, &fstype->fs_supers) { + s = list_entry(l, struct super_block, s_instances); + if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) || + (S_ISDIR(stat.mode) && s == nd.dentry->d_inode->i_sb)) { + sb = s; + goto free_nd; + } + } + + printk(KERN_WARNING "GFS2: Unrecognized block device or " + "mount point %s", dev_name); + +free_nd: + path_release(&nd); +out: + return sb; +} + +static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags, + const char *dev_name, void *data, struct vfsmount *mnt) +{ + int error = 0; + struct super_block *sb = NULL, *new; + struct gfs2_sbd *sdp; + char *gfs2mnt = NULL; + + sb = get_gfs2_sb(dev_name); + if (!sb) { + printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n"); + error = -ENOENT; + goto error; + } + sdp = (struct gfs2_sbd*) sb->s_fs_info; + if (sdp->sd_vfs_meta) { + printk(KERN_WARNING "GFS2: gfs2meta mount already exists\n"); + error = -EBUSY; + goto error; + } + mutex_lock(&sb->s_bdev->bd_mount_mutex); + new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev); + mutex_unlock(&sb->s_bdev->bd_mount_mutex); + if (IS_ERR(new)) { + error = PTR_ERR(new); + goto error; + } + module_put(fs_type->owner); + new->s_flags = flags; + strlcpy(new->s_id, sb->s_id, sizeof(new->s_id)); + sb_set_blocksize(new, sb->s_blocksize); + error = fill_super_meta(sb, new, data, flags & MS_SILENT ? 1 : 0); + if (error) { + up_write(&new->s_umount); + deactivate_super(new); + goto error; + } + + new->s_flags |= MS_ACTIVE; + + /* Grab a reference to the gfs2 mount point */ + atomic_inc(&sdp->sd_gfs2mnt->mnt_count); + return simple_set_mnt(mnt, new); +error: + if (gfs2mnt) + kfree(gfs2mnt); + return error; } static void gfs2_kill_sb(struct super_block *sb) @@ -821,6 +954,14 @@ static void gfs2_kill_sb(struct super_block *sb) kill_block_super(sb); } +static void gfs2_kill_sb_meta(struct super_block *sb) +{ + struct gfs2_sbd *sdp = sb->s_fs_info; + generic_shutdown_super(sb); + sdp->sd_vfs_meta = NULL; + atomic_dec(&sdp->sd_gfs2mnt->mnt_count); +} + struct file_system_type gfs2_fs_type = { .name = "gfs2", .fs_flags = FS_REQUIRES_DEV, @@ -832,8 +973,8 @@ struct file_system_type gfs2_fs_type = { struct file_system_type gfs2meta_fs_type = { .name = "gfs2meta", .fs_flags = FS_REQUIRES_DEV, - .get_sb = gfs2_get_sb, - .kill_sb = gfs2_kill_sb, + .get_sb = gfs2_get_sb_meta, + .kill_sb = gfs2_kill_sb_meta, .owner = THIS_MODULE, }; diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 2e392c994ab1..18ed18c729e8 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -78,6 +78,9 @@ static void gfs2_put_super(struct super_block *sb) if (!sdp) return; + if (!strncmp(sb->s_type->name, "gfs2meta", 8)) + return; /* meta fs. don't do nothin' */ + /* Unfreeze the filesystem, if we need to */ mutex_lock(&sdp->sd_freeze_lock); From 8fb4b536e7b9dbaf7a6b8204e887b92a14e4352c Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 30 Aug 2006 09:30:00 -0400 Subject: [PATCH 214/292] [GFS2] Make glock operations const For all the usual reasons of enforcing correctness and potentially reducing code size, this patch makes the glock operations const. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 30 +++++++++++++++--------------- fs/gfs2/glock.h | 6 +++--- fs/gfs2/glops.c | 18 +++++++++--------- fs/gfs2/glops.h | 18 +++++++++--------- fs/gfs2/incore.h | 4 ++-- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index ef713dbff601..709e6e0914fd 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -253,7 +253,7 @@ static struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, */ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, - struct gfs2_glock_operations *glops, int create, + const struct gfs2_glock_operations *glops, int create, struct gfs2_glock **glp) { struct lm_lockname name; @@ -480,7 +480,7 @@ static int rq_promote(struct gfs2_holder *gh) { struct gfs2_glock *gl = gh->gh_gl; struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; if (!relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) { if (list_empty(&gl->gl_holders)) { @@ -535,7 +535,7 @@ static int rq_promote(struct gfs2_holder *gh) static int rq_demote(struct gfs2_holder *gh) { struct gfs2_glock *gl = gh->gh_gl; - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; if (!list_empty(&gl->gl_holders)) return 1; @@ -805,7 +805,7 @@ static void state_change(struct gfs2_glock *gl, unsigned int new_state) static void xmote_bh(struct gfs2_glock *gl, unsigned int ret) { struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; struct gfs2_holder *gh = gl->gl_req_gh; int prev_state = gl->gl_state; int op_done = 1; @@ -915,7 +915,7 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret) void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags) { struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; int lck_flags = flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB | LM_FLAG_NOEXP | LM_FLAG_ANY | LM_FLAG_PRIORITY); @@ -960,7 +960,7 @@ void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags) static void drop_bh(struct gfs2_glock *gl, unsigned int ret) { struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; struct gfs2_holder *gh = gl->gl_req_gh; clear_bit(GLF_PREFETCH, &gl->gl_flags); @@ -1010,7 +1010,7 @@ static void drop_bh(struct gfs2_glock *gl, unsigned int ret) void gfs2_glock_drop_th(struct gfs2_glock *gl) { struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; unsigned int ret; gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags)); @@ -1081,7 +1081,7 @@ static int glock_wait_internal(struct gfs2_holder *gh) { struct gfs2_glock *gl = gh->gh_gl; struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; if (test_bit(HIF_ABORTED, &gh->gh_iflags)) return -EIO; @@ -1294,7 +1294,7 @@ int gfs2_glock_wait(struct gfs2_holder *gh) void gfs2_glock_dq(struct gfs2_holder *gh) { struct gfs2_glock *gl = gh->gh_gl; - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; if (gh->gh_flags & GL_SYNC) set_bit(GLF_SYNC, &gl->gl_flags); @@ -1339,7 +1339,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh) static void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, int flags) { - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; spin_lock(&gl->gl_spin); @@ -1365,7 +1365,7 @@ static void greedy_work(void *data) struct greedy *gr = data; struct gfs2_holder *gh = &gr->gr_gh; struct gfs2_glock *gl = gh->gh_gl; - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; clear_bit(GLF_SKIP_WAITERS2, &gl->gl_flags); @@ -1447,8 +1447,8 @@ void gfs2_glock_dq_uninit(struct gfs2_holder *gh) */ int gfs2_glock_nq_num(struct gfs2_sbd *sdp, uint64_t number, - struct gfs2_glock_operations *glops, unsigned int state, - int flags, struct gfs2_holder *gh) + const struct gfs2_glock_operations *glops, + unsigned int state, int flags, struct gfs2_holder *gh) { struct gfs2_glock *gl; int error; @@ -1645,7 +1645,7 @@ void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs) */ void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number, - struct gfs2_glock_operations *glops, + const struct gfs2_glock_operations *glops, unsigned int state, int flags) { struct gfs2_glock *gl; @@ -1827,7 +1827,7 @@ void gfs2_iopen_go_callback(struct gfs2_glock *io_gl, unsigned int state) static int demote_ok(struct gfs2_glock *gl) { struct gfs2_sbd *sdp = gl->gl_sbd; - struct gfs2_glock_operations *glops = gl->gl_ops; + const struct gfs2_glock_operations *glops = gl->gl_ops; int demote = 1; if (test_bit(GLF_STICKY, &gl->gl_flags)) diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index fdf58db44ae3..12bdbfee4ddc 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -75,7 +75,7 @@ static inline int gfs2_glock_is_blocking(struct gfs2_glock *gl) } int gfs2_glock_get(struct gfs2_sbd *sdp, - uint64_t number, struct gfs2_glock_operations *glops, + uint64_t number, const struct gfs2_glock_operations *glops, int create, struct gfs2_glock **glp); void gfs2_glock_hold(struct gfs2_glock *gl); int gfs2_glock_put(struct gfs2_glock *gl); @@ -97,7 +97,7 @@ int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time); void gfs2_glock_dq_uninit(struct gfs2_holder *gh); int gfs2_glock_nq_num(struct gfs2_sbd *sdp, - uint64_t number, struct gfs2_glock_operations *glops, + uint64_t number, const struct gfs2_glock_operations *glops, unsigned int state, int flags, struct gfs2_holder *gh); int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs); @@ -105,7 +105,7 @@ void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs); void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs); void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number, - struct gfs2_glock_operations *glops, + const struct gfs2_glock_operations *glops, unsigned int state, int flags); void gfs2_glock_inode_squish(struct inode *inode); diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 75d4c50cff45..0c92c52fc92a 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -493,13 +493,13 @@ static int quota_go_demote_ok(struct gfs2_glock *gl) return !atomic_read(&gl->gl_lvb_count); } -struct gfs2_glock_operations gfs2_meta_glops = { +const struct gfs2_glock_operations gfs2_meta_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, .go_type = LM_TYPE_META }; -struct gfs2_glock_operations gfs2_inode_glops = { +const struct gfs2_glock_operations gfs2_inode_glops = { .go_xmote_th = inode_go_xmote_th, .go_xmote_bh = inode_go_xmote_bh, .go_drop_th = inode_go_drop_th, @@ -512,7 +512,7 @@ struct gfs2_glock_operations gfs2_inode_glops = { .go_type = LM_TYPE_INODE }; -struct gfs2_glock_operations gfs2_rgrp_glops = { +const struct gfs2_glock_operations gfs2_rgrp_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, .go_sync = meta_go_sync, @@ -523,40 +523,40 @@ struct gfs2_glock_operations gfs2_rgrp_glops = { .go_type = LM_TYPE_RGRP }; -struct gfs2_glock_operations gfs2_trans_glops = { +const struct gfs2_glock_operations gfs2_trans_glops = { .go_xmote_th = trans_go_xmote_th, .go_xmote_bh = trans_go_xmote_bh, .go_drop_th = trans_go_drop_th, .go_type = LM_TYPE_NONDISK }; -struct gfs2_glock_operations gfs2_iopen_glops = { +const struct gfs2_glock_operations gfs2_iopen_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, .go_callback = gfs2_iopen_go_callback, .go_type = LM_TYPE_IOPEN }; -struct gfs2_glock_operations gfs2_flock_glops = { +const struct gfs2_glock_operations gfs2_flock_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, .go_type = LM_TYPE_FLOCK }; -struct gfs2_glock_operations gfs2_nondisk_glops = { +const struct gfs2_glock_operations gfs2_nondisk_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, .go_type = LM_TYPE_NONDISK }; -struct gfs2_glock_operations gfs2_quota_glops = { +const struct gfs2_glock_operations gfs2_quota_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, .go_demote_ok = quota_go_demote_ok, .go_type = LM_TYPE_QUOTA }; -struct gfs2_glock_operations gfs2_journal_glops = { +const struct gfs2_glock_operations gfs2_journal_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, .go_type = LM_TYPE_JOURNAL diff --git a/fs/gfs2/glops.h b/fs/gfs2/glops.h index 5c1e9491024f..9409f0a7b47f 100644 --- a/fs/gfs2/glops.h +++ b/fs/gfs2/glops.h @@ -10,14 +10,14 @@ #ifndef __GLOPS_DOT_H__ #define __GLOPS_DOT_H__ -extern struct gfs2_glock_operations gfs2_meta_glops; -extern struct gfs2_glock_operations gfs2_inode_glops; -extern struct gfs2_glock_operations gfs2_rgrp_glops; -extern struct gfs2_glock_operations gfs2_trans_glops; -extern struct gfs2_glock_operations gfs2_iopen_glops; -extern struct gfs2_glock_operations gfs2_flock_glops; -extern struct gfs2_glock_operations gfs2_nondisk_glops; -extern struct gfs2_glock_operations gfs2_quota_glops; -extern struct gfs2_glock_operations gfs2_journal_glops; +extern const struct gfs2_glock_operations gfs2_meta_glops; +extern const struct gfs2_glock_operations gfs2_inode_glops; +extern const struct gfs2_glock_operations gfs2_rgrp_glops; +extern const struct gfs2_glock_operations gfs2_trans_glops; +extern const struct gfs2_glock_operations gfs2_iopen_glops; +extern const struct gfs2_glock_operations gfs2_flock_glops; +extern const struct gfs2_glock_operations gfs2_nondisk_glops; +extern const struct gfs2_glock_operations gfs2_quota_glops; +extern const struct gfs2_glock_operations gfs2_journal_glops; #endif /* __GLOPS_DOT_H__ */ diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 77f0903d2f3e..38098ac292af 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -130,7 +130,7 @@ struct gfs2_glock_operations { void (*go_unlock) (struct gfs2_holder * gh); void (*go_callback) (struct gfs2_glock * gl, unsigned int state); void (*go_greedy) (struct gfs2_glock * gl); - int go_type; + const int go_type; }; enum { @@ -189,7 +189,7 @@ struct gfs2_glock { struct list_head gl_waiters2; /* HIF_DEMOTE, HIF_GREEDY */ struct list_head gl_waiters3; /* HIF_PROMOTE */ - struct gfs2_glock_operations *gl_ops; + const struct gfs2_glock_operations *gl_ops; struct gfs2_holder *gl_req_gh; gfs2_glop_bh_t gl_req_bh; From 5e2b0613ed9f9641937dd5948051631249447c57 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 30 Aug 2006 09:38:30 -0400 Subject: [PATCH 215/292] [GFS2] Remove unused code from glock layer Remove the unused sync feature from glocks. This is currently done by calling the required functions to sync pages/blocks directly so this code isn't needed. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 8 -------- fs/gfs2/glock.h | 1 - fs/gfs2/glops.c | 2 -- fs/gfs2/incore.h | 1 - 4 files changed, 12 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 709e6e0914fd..c3dde8560827 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1296,9 +1296,6 @@ void gfs2_glock_dq(struct gfs2_holder *gh) struct gfs2_glock *gl = gh->gh_gl; const struct gfs2_glock_operations *glops = gl->gl_ops; - if (gh->gh_flags & GL_SYNC) - set_bit(GLF_SYNC, &gl->gl_flags); - if (gh->gh_flags & GL_NOCACHE) handle_callback(gl, LM_ST_UNLOCKED); @@ -1313,11 +1310,6 @@ void gfs2_glock_dq(struct gfs2_holder *gh) if (glops->go_unlock) glops->go_unlock(gh); - if (test_bit(GLF_SYNC, &gl->gl_flags)) { - if (glops->go_sync) - glops->go_sync(gl, DIO_METADATA | DIO_DATA); - } - gl->gl_stamp = jiffies; spin_lock(&gl->gl_spin); diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 12bdbfee4ddc..75fad634ced2 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -24,7 +24,6 @@ #define GL_SKIP 0x00000100 #define GL_ATIME 0x00000200 #define GL_NOCACHE 0x00000400 -#define GL_SYNC 0x00000800 #define GL_NOCANCEL 0x00001000 #define GL_AOP 0x00004000 #define GL_DUMP 0x00008000 diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 0c92c52fc92a..1a30fa9bec7a 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -137,7 +137,6 @@ static void meta_go_sync(struct gfs2_glock *gl, int flags) gfs2_ail_empty_gl(gl); } - clear_bit(GLF_SYNC, &gl->gl_flags); } /** @@ -236,7 +235,6 @@ static void inode_go_sync(struct gfs2_glock *gl, int flags) gfs2_ail_empty_gl(gl); } - clear_bit(GLF_SYNC, &gl->gl_flags); } /** diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 38098ac292af..362c2422d506 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -167,7 +167,6 @@ enum { GLF_LOCK = 1, GLF_STICKY = 2, GLF_PREFETCH = 3, - GLF_SYNC = 4, GLF_DIRTY = 5, GLF_SKIP_WAITERS2 = 6, GLF_GREEDY = 7, From ec45d9f583b3663f90a7c5c559fd13e6e4c56ad5 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 30 Aug 2006 10:36:52 -0400 Subject: [PATCH 216/292] [GFS2] Use slab properly with glocks We can take advantage of the slab allocator to ensure that all the list heads and the spinlock (plus one or two other fields) are initialised by slab to speed up allocation of glocks. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 39 ++++++++++++--------------------------- fs/gfs2/main.c | 23 ++++++++++++++++++++++- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index c3dde8560827..4a2e90dc1d02 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -278,31 +278,22 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, if (!gl) return -ENOMEM; - memset(gl, 0, sizeof(struct gfs2_glock)); - - INIT_LIST_HEAD(&gl->gl_list); + gl->gl_flags = 0; gl->gl_name = name; kref_init(&gl->gl_ref); - - spin_lock_init(&gl->gl_spin); - gl->gl_state = LM_ST_UNLOCKED; gl->gl_owner = NULL; gl->gl_ip = 0; - INIT_LIST_HEAD(&gl->gl_holders); - INIT_LIST_HEAD(&gl->gl_waiters1); - INIT_LIST_HEAD(&gl->gl_waiters2); - INIT_LIST_HEAD(&gl->gl_waiters3); - gl->gl_ops = glops; - + gl->gl_req_gh = NULL; + gl->gl_req_bh = NULL; + gl->gl_vn = 0; + gl->gl_stamp = jiffies; + gl->gl_object = NULL; gl->gl_bucket = bucket; - INIT_LIST_HEAD(&gl->gl_reclaim); - gl->gl_sbd = sdp; - + gl->gl_aspace = NULL; lops_init_le(&gl->gl_le, &gfs2_glock_lops); - INIT_LIST_HEAD(&gl->gl_ail_list); /* If this glock protects actual on-disk data or metadata blocks, create a VFS inode to manage the pages/buffers holding them. */ @@ -334,13 +325,11 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, return 0; - fail_aspace: +fail_aspace: if (gl->gl_aspace) gfs2_aspace_put(gl->gl_aspace); - - fail: +fail: kmem_cache_free(gfs2_glock_cachep, gl); - return error; } @@ -495,9 +484,7 @@ static int rq_promote(struct gfs2_holder *gh) gfs2_reclaim_glock(sdp); } - glops->go_xmote_th(gl, gh->gh_state, - gh->gh_flags); - + glops->go_xmote_th(gl, gh->gh_state, gh->gh_flags); spin_lock(&gl->gl_spin); } return 1; @@ -935,8 +922,7 @@ void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags) gfs2_glock_hold(gl); gl->gl_req_bh = xmote_bh; - lck_ret = gfs2_lm_lock(sdp, gl->gl_lock, gl->gl_state, state, - lck_flags); + lck_ret = gfs2_lm_lock(sdp, gl->gl_lock, gl->gl_state, state, lck_flags); if (gfs2_assert_withdraw(sdp, !(lck_ret & LM_OUT_ERROR))) return; @@ -1019,8 +1005,7 @@ void gfs2_glock_drop_th(struct gfs2_glock *gl) if (gl->gl_state == LM_ST_EXCLUSIVE) { if (glops->go_sync) - glops->go_sync(gl, - DIO_METADATA | DIO_DATA | DIO_RELEASE); + glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE); } gfs2_glock_hold(gl); diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index c112943ee8c1..dccc4f6f503f 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "gfs2.h" #include "lm_interface.h" @@ -35,6 +36,25 @@ static void gfs2_init_inode_once(void *foo, kmem_cache_t *cachep, unsigned long } } +static void gfs2_init_glock_once(void *foo, kmem_cache_t *cachep, unsigned long flags) +{ + struct gfs2_glock *gl = foo; + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == + SLAB_CTOR_CONSTRUCTOR) { + INIT_LIST_HEAD(&gl->gl_list); + spin_lock_init(&gl->gl_spin); + INIT_LIST_HEAD(&gl->gl_holders); + INIT_LIST_HEAD(&gl->gl_waiters1); + INIT_LIST_HEAD(&gl->gl_waiters2); + INIT_LIST_HEAD(&gl->gl_waiters3); + gl->gl_lvb = NULL; + atomic_set(&gl->gl_lvb_count, 0); + INIT_LIST_HEAD(&gl->gl_reclaim); + INIT_LIST_HEAD(&gl->gl_ail_list); + atomic_set(&gl->gl_ail_count, 0); + } +} + /** * init_gfs2_fs - Register GFS2 as a filesystem * @@ -55,7 +75,8 @@ static int __init init_gfs2_fs(void) gfs2_glock_cachep = kmem_cache_create("gfs2_glock", sizeof(struct gfs2_glock), - 0, 0, NULL, NULL); + 0, 0, + gfs2_init_glock_once, NULL); if (!gfs2_glock_cachep) goto fail; From d6a53727683bbf993c01ab49b45e0eac17e23df1 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 30 Aug 2006 11:16:23 -0400 Subject: [PATCH 217/292] [GFS2] Use const on glock lookup key Use const for the glock name which is being used as a lookup key in the glock hash table. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 4a2e90dc1d02..679cb836ed0c 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -83,7 +83,7 @@ static inline int relaxed_state_ok(unsigned int actual, unsigned requested, * Returns: The number of the corresponding hash bucket */ -static unsigned int gl_hash(struct lm_lockname *name) +static unsigned int gl_hash(const struct lm_lockname *name) { unsigned int h; @@ -200,7 +200,7 @@ static inline int queue_empty(struct gfs2_glock *gl, struct list_head *head) */ static struct gfs2_glock *search_bucket(struct gfs2_gl_hash_bucket *bucket, - struct lm_lockname *name) + const struct lm_lockname *name) { struct gfs2_glock *gl; @@ -227,7 +227,7 @@ static struct gfs2_glock *search_bucket(struct gfs2_gl_hash_bucket *bucket, */ static struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, - struct lm_lockname *name) + const struct lm_lockname *name) { struct gfs2_gl_hash_bucket *bucket = &sdp->sd_gl_hash[gl_hash(name)]; struct gfs2_glock *gl; From 899be4d3b7e00bf364d84c1c8cfe8bbbd1e3507b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 30 Aug 2006 12:50:28 -0400 Subject: [PATCH 218/292] [GFS2] Add superblock into key for glock lookups This adds the superblock as a key for glock lookups. Since the glocks are already stored in a per-superblock table, this has no effect at the moment. Later on this will change though. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 679cb836ed0c..b8ccb27906e8 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -200,6 +200,7 @@ static inline int queue_empty(struct gfs2_glock *gl, struct list_head *head) */ static struct gfs2_glock *search_bucket(struct gfs2_gl_hash_bucket *bucket, + const struct gfs2_sbd *sdp, const struct lm_lockname *name) { struct gfs2_glock *gl; @@ -209,6 +210,8 @@ static struct gfs2_glock *search_bucket(struct gfs2_gl_hash_bucket *bucket, continue; if (!lm_name_equal(&gl->gl_name, name)) continue; + if (gl->gl_sbd != sdp) + continue; kref_get(&gl->gl_ref); @@ -233,7 +236,7 @@ static struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, struct gfs2_glock *gl; read_lock(&bucket->hb_lock); - gl = search_bucket(bucket, name); + gl = search_bucket(bucket, sdp, name); read_unlock(&bucket->hb_lock); return gl; @@ -266,7 +269,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, bucket = &sdp->sd_gl_hash[gl_hash(&name)]; read_lock(&bucket->hb_lock); - gl = search_bucket(bucket, &name); + gl = search_bucket(bucket, sdp, &name); read_unlock(&bucket->hb_lock); if (gl || !create) { @@ -311,7 +314,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, goto fail_aspace; write_lock(&bucket->hb_lock); - tmp = search_bucket(bucket, &name); + tmp = search_bucket(bucket, sdp, &name); if (tmp) { write_unlock(&bucket->hb_lock); glock_free(gl); From 623d93555c8884768db65ffc11509c93e50dd4db Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 31 Aug 2006 12:14:44 -0400 Subject: [PATCH 219/292] [GFS2] Fix releasepage bug (fixes direct i/o writes) This patch fixes three main bugs. Firstly the direct i/o get_block was returning the wrong return code in certain cases. Secondly, the GFS2's releasepage function was not dealing with cases when clean, ordered buffers were found still queued on a transaction (which can happen depending on the ordering of journal flushes). Thirdly, the journaling code itself needed altering to take account of the after effects of removing the clean ordered buffers from the transactions before a journal flush. The releasepage bug did also show up under "normal" buffered i/o as well, so its not just a fix for direct i/o. In fact its not normally used in the direct i/o path at all, except when flushing existing buffers after performing a direct i/o write, but that was the code path that led us to spot this. Signed-off-by: Steven Whitehouse --- fs/gfs2/lops.c | 11 +++++++++++ fs/gfs2/ops_address.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 08de8b7fb316..0ec38b399097 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -592,6 +592,17 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) gfs2_log_lock(sdp); if (n++ > num) break; + } else if (!bd1->bd_bh) { + total_dbuf--; + sdp->sd_log_num_databuf--; + list_del_init(&bd1->bd_le.le_list); + if (bd1 == bd2) { + bd2 = NULL; + bd2 = list_prepare_entry(bd2, + &sdp->sd_log_le_databuf, + bd_le.le_list); + } + kmem_cache_free(gfs2_bufdata_cachep, bd1); } } gfs2_log_unlock(sdp); diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 48720421c796..0de7a9523633 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -118,6 +118,25 @@ static int get_block_noalloc(struct inode *inode, sector_t lblock, return error; } +static int get_block_direct(struct inode *inode, sector_t lblock, + struct buffer_head *bh_result, int create) +{ + int new = 0; + u64 dblock; + int error, boundary; + + error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary); + if (error) + return error; + + if (dblock) { + map_bh(bh_result, inode->i_sb, dblock); + if (boundary) + set_buffer_boundary(bh_result); + } + + return 0; +} /** * gfs2_writepage - Write complete page * @page: Page to write @@ -661,7 +680,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, rv = blockdev_direct_IO_own_locking(rw, iocb, inode, inode->i_sb->s_bdev, iov, offset, nr_segs, - gfs2_get_block, NULL); + get_block_direct, NULL); out: gfs2_glock_dq_m(1, &gh); gfs2_holder_uninit(&gh); @@ -724,7 +743,7 @@ static unsigned limit = 0; } /** - * gfs2_aspace_releasepage - free the metadata associated with a page + * gfs2_releasepage - free the metadata associated with a page * @page: the page that's being released * @gfp_mask: passed from Linux VFS, ignored by us * @@ -761,16 +780,22 @@ int gfs2_releasepage(struct page *page, gfp_t gfp_mask) } gfs2_assert_warn(sdp, !buffer_pinned(bh)); + gfs2_assert_warn(sdp, !buffer_dirty(bh)); + gfs2_log_lock(sdp); bd = bh->b_private; if (bd) { gfs2_assert_warn(sdp, bd->bd_bh == bh); gfs2_assert_warn(sdp, list_empty(&bd->bd_list_tr)); - gfs2_assert_warn(sdp, list_empty(&bd->bd_le.le_list)); gfs2_assert_warn(sdp, !bd->bd_ail); - kmem_cache_free(gfs2_bufdata_cachep, bd); + bd->bd_bh = NULL; + if (!list_empty(&bd->bd_le.le_list)) + bd = NULL; bh->b_private = NULL; } + gfs2_log_unlock(sdp); + if (bd) + kmem_cache_free(gfs2_bufdata_cachep, bd); bh = bh->b_this_page; } while (bh != head); From c6e6f0ba8fc1dea99c7bd020916f24d533b62697 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 30 Aug 2006 10:50:18 -0500 Subject: [PATCH 220/292] [DLM] force removal of user lockspace Check if the FORCEFREE flag has been provided from user space. If so, set the force option to dlm_release_lockspace() so that any remaining locks will be freed. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/user.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/dlm/user.c b/fs/dlm/user.c index 494d00ac014e..c37e93e4f2df 100644 --- a/fs/dlm/user.c +++ b/fs/dlm/user.c @@ -325,7 +325,7 @@ static int device_remove_lockspace(struct dlm_lspace_params *params) { dlm_lockspace_t *lockspace; struct dlm_ls *ls; - int error; + int error, force = 0; if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -341,6 +341,9 @@ static int device_remove_lockspace(struct dlm_lspace_params *params) } kfree(ls->ls_device.name); + if (params->flags & DLM_USER_LSFLG_FORCEFREE) + force = 2; + lockspace = ls->ls_local_handle; /* dlm_release_lockspace waits for references to go to zero, @@ -348,8 +351,8 @@ static int device_remove_lockspace(struct dlm_lspace_params *params) before the release will procede */ dlm_put_lockspace(ls); - error = dlm_release_lockspace(lockspace, 0); -out: + error = dlm_release_lockspace(lockspace, force); + out: return error; } From e9fc2aa091ab8fa46e60d4c9d06a89305c441652 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 1 Sep 2006 11:05:15 -0400 Subject: [PATCH 221/292] [GFS2] Update copyright, tidy up incore.h As per comments from Jan Engelhardt this updates the copyright message to say "version" in full rather than "v.2". Also incore.h has been updated to remove forward structure declarations which are not required. The gfs2_quota_lvb structure has now had endianess annotations added to it. Also quota.c has been updated so that we now store the lvb data locally in endian independant format to avoid needing a structure in host endianess too. As a result the endianess conversions are done as required at various points and thus the conversion routines in lvb.[ch] are no longer required. I've moved the one remaining constant in lvb.h thats used into lm.h and removed the unused lvb.[ch]. I have not changed the HIF_ constants. That is left to a later patch which I hope will unify the gh_flags and gh_iflags fields of the struct gfs2_holder. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/Makefile | 2 +- fs/gfs2/acl.c | 2 +- fs/gfs2/acl.h | 2 +- fs/gfs2/bmap.c | 2 +- fs/gfs2/bmap.h | 2 +- fs/gfs2/daemon.c | 2 +- fs/gfs2/daemon.h | 2 +- fs/gfs2/dir.c | 2 +- fs/gfs2/dir.h | 2 +- fs/gfs2/eaops.c | 2 +- fs/gfs2/eaops.h | 2 +- fs/gfs2/eattr.c | 2 +- fs/gfs2/eattr.h | 2 +- fs/gfs2/format.h | 2 +- fs/gfs2/gfs2.h | 2 +- fs/gfs2/glock.c | 2 +- fs/gfs2/glock.h | 2 +- fs/gfs2/glops.c | 2 +- fs/gfs2/glops.h | 2 +- fs/gfs2/incore.h | 28 +++++------------- fs/gfs2/inode.c | 2 +- fs/gfs2/inode.h | 2 +- fs/gfs2/lm.c | 3 +- fs/gfs2/lm.h | 4 ++- fs/gfs2/lm_interface.h | 2 +- fs/gfs2/locking.c | 2 +- fs/gfs2/locking/dlm/lock.c | 2 +- fs/gfs2/locking/dlm/lock_dlm.h | 2 +- fs/gfs2/locking/dlm/main.c | 2 +- fs/gfs2/locking/dlm/mount.c | 2 +- fs/gfs2/locking/dlm/plock.c | 2 +- fs/gfs2/locking/dlm/sysfs.c | 2 +- fs/gfs2/locking/dlm/thread.c | 2 +- fs/gfs2/locking/nolock/main.c | 2 +- fs/gfs2/log.c | 2 +- fs/gfs2/log.h | 2 +- fs/gfs2/lops.c | 2 +- fs/gfs2/lops.h | 2 +- fs/gfs2/lvb.c | 45 ---------------------------- fs/gfs2/lvb.h | 19 ------------ fs/gfs2/main.c | 2 +- fs/gfs2/meta_io.c | 2 +- fs/gfs2/meta_io.h | 2 +- fs/gfs2/mount.c | 2 +- fs/gfs2/mount.h | 2 +- fs/gfs2/ondisk.c | 2 +- fs/gfs2/ops_address.c | 2 +- fs/gfs2/ops_address.h | 2 +- fs/gfs2/ops_dentry.c | 2 +- fs/gfs2/ops_dentry.h | 2 +- fs/gfs2/ops_export.c | 2 +- fs/gfs2/ops_export.h | 2 +- fs/gfs2/ops_file.c | 2 +- fs/gfs2/ops_file.h | 2 +- fs/gfs2/ops_fstype.c | 2 +- fs/gfs2/ops_fstype.h | 2 +- fs/gfs2/ops_inode.c | 2 +- fs/gfs2/ops_inode.h | 2 +- fs/gfs2/ops_super.c | 2 +- fs/gfs2/ops_super.h | 2 +- fs/gfs2/ops_vm.c | 2 +- fs/gfs2/ops_vm.h | 2 +- fs/gfs2/quota.c | 54 +++++++++++++++++----------------- fs/gfs2/quota.h | 2 +- fs/gfs2/recovery.c | 2 +- fs/gfs2/recovery.h | 2 +- fs/gfs2/rgrp.c | 2 +- fs/gfs2/rgrp.h | 2 +- fs/gfs2/super.c | 2 +- fs/gfs2/super.h | 2 +- fs/gfs2/sys.c | 2 +- fs/gfs2/sys.h | 2 +- fs/gfs2/trans.c | 2 +- fs/gfs2/trans.h | 2 +- fs/gfs2/util.c | 2 +- fs/gfs2/util.h | 2 +- 76 files changed, 109 insertions(+), 184 deletions(-) delete mode 100644 fs/gfs2/lvb.c delete mode 100644 fs/gfs2/lvb.h diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile index b92852b66629..e3f1ada643ac 100644 --- a/fs/gfs2/Makefile +++ b/fs/gfs2/Makefile @@ -1,6 +1,6 @@ obj-$(CONFIG_GFS2_FS) += gfs2.o gfs2-y := acl.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \ - glops.o inode.o lm.o log.o lops.o locking.o lvb.o main.o meta_io.o \ + glops.o inode.o lm.o log.o lops.o locking.o main.o meta_io.o \ mount.o ondisk.o ops_address.o ops_dentry.o ops_export.o ops_file.o \ ops_fstype.o ops_inode.o ops_super.o ops_vm.o quota.o \ recovery.o rgrp.o super.o sys.o trans.o util.o diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index 399317841501..60c98c0314a1 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/acl.h b/fs/gfs2/acl.h index 067105786eaa..5856ba764680 100644 --- a/fs/gfs2/acl.h +++ b/fs/gfs2/acl.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __ACL_DOT_H__ diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index d20d41e1c028..913c0e5490e9 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index 1a265412f7ee..ab0157c5ed0e 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __BMAP_DOT_H__ diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c index 1453605c8f32..a2a07c41845d 100644 --- a/fs/gfs2/daemon.c +++ b/fs/gfs2/daemon.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/daemon.h b/fs/gfs2/daemon.h index aa93eb6f668e..801007120fb2 100644 --- a/fs/gfs2/daemon.h +++ b/fs/gfs2/daemon.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __DAEMON_DOT_H__ diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 76a23c172eeb..7b8a38eaa41a 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ /* diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h index 173403095eb2..366a5571648f 100644 --- a/fs/gfs2/dir.h +++ b/fs/gfs2/dir.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __DIR_DOT_H__ diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index 3ace242f2b16..3b8749c22731 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/eaops.h b/fs/gfs2/eaops.h index 3dece17e3116..1c27700ee8b8 100644 --- a/fs/gfs2/eaops.h +++ b/fs/gfs2/eaops.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __EAOPS_DOT_H__ diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 96736932260f..9081822ce80c 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/eattr.h b/fs/gfs2/eattr.h index ae199692e51d..7b0291f99fd9 100644 --- a/fs/gfs2/eattr.h +++ b/fs/gfs2/eattr.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __EATTR_DOT_H__ diff --git a/fs/gfs2/format.h b/fs/gfs2/format.h index 239f0c3553fc..9acbf457ee58 100644 --- a/fs/gfs2/format.h +++ b/fs/gfs2/format.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __FORMAT_DOT_H__ diff --git a/fs/gfs2/gfs2.h b/fs/gfs2/gfs2.h index 6edbd551a4c0..3bb11c0f8b56 100644 --- a/fs/gfs2/gfs2.h +++ b/fs/gfs2/gfs2.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __GFS2_DOT_H__ diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index b8ccb27906e8..989f4f78f9be 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 75fad634ced2..07a8d02a234d 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __GLOCK_DOT_H__ diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 1a30fa9bec7a..8e1d8ee68e2e 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/glops.h b/fs/gfs2/glops.h index 9409f0a7b47f..ba943e473665 100644 --- a/fs/gfs2/glops.h +++ b/fs/gfs2/glops.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __GLOPS_DOT_H__ diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 362c2422d506..06f5ec6ebf7f 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __INCORE_DOT_H__ @@ -22,24 +22,12 @@ struct gfs2_log_operations; struct gfs2_log_element; -struct gfs2_bitmap; -struct gfs2_rgrpd; -struct gfs2_bufdata; -struct gfs2_glock_operations; struct gfs2_holder; struct gfs2_glock; -struct gfs2_alloc; -struct gfs2_inode; -struct gfs2_file; -struct gfs2_revoke; -struct gfs2_revoke_replay; struct gfs2_quota_data; -struct gfs2_log_buf; struct gfs2_trans; struct gfs2_ail; struct gfs2_jdesc; -struct gfs2_args; -struct gfs2_tune; struct gfs2_gl_hash_bucket; struct gfs2_sbd; @@ -215,8 +203,8 @@ struct gfs2_glock { struct gfs2_alloc { /* Quota stuff */ - struct gfs2_quota_data *al_qd[4]; - struct gfs2_holder al_qd_ghs[4]; + struct gfs2_quota_data *al_qd[2*MAXQUOTAS]; + struct gfs2_holder al_qd_ghs[2*MAXQUOTAS]; unsigned int al_qd_num; u32 al_requested; /* Filled in by caller of gfs2_inplace_reserve() */ @@ -305,11 +293,11 @@ enum { }; struct gfs2_quota_lvb { - uint32_t qb_magic; - uint32_t __pad; - uint64_t qb_limit; /* Hard limit of # blocks to alloc */ - uint64_t qb_warn; /* Warn user when alloc is above this # */ - int64_t qb_value; /* Current # blocks allocated */ + __be32 qb_magic; + u32 __pad; + __be64 qb_limit; /* Hard limit of # blocks to alloc */ + __be64 qb_warn; /* Warn user when alloc is above this # */ + __be64 qb_value; /* Current # blocks allocated */ }; struct gfs2_quota_data { diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 9fb340984b29..decb0cf85691 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index 8bb8b559bcea..32015d89f249 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __INODE_DOT_H__ diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index f45c0ffd1c35..1a9e75da19d1 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include @@ -22,7 +22,6 @@ #include "lm.h" #include "super.h" #include "util.h" -#include "lvb.h" /** * gfs2_lm_mount - mount a locking protocol diff --git a/fs/gfs2/lm.h b/fs/gfs2/lm.h index e821101d19c0..15839aaa4ca6 100644 --- a/fs/gfs2/lm.h +++ b/fs/gfs2/lm.h @@ -4,12 +4,14 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __LM_DOT_H__ #define __LM_DOT_H__ +#define GFS2_MIN_LVB_SIZE 32 + int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent); void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp); void gfs2_lm_unmount(struct gfs2_sbd *sdp); diff --git a/fs/gfs2/lm_interface.h b/fs/gfs2/lm_interface.h index 1da95a55f768..e1e89d92a8db 100644 --- a/fs/gfs2/lm_interface.h +++ b/fs/gfs2/lm_interface.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __LM_INTERFACE_DOT_H__ diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c index ded1ef6c81e7..11c4068105cc 100644 --- a/fs/gfs2/locking.c +++ b/fs/gfs2/locking.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index f769eac1a34a..2d81d90db097 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include "lock_dlm.h" diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h index 530c2f542584..941063498532 100644 --- a/fs/gfs2/locking/dlm/lock_dlm.h +++ b/fs/gfs2/locking/dlm/lock_dlm.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef LOCK_DLM_DOT_H diff --git a/fs/gfs2/locking/dlm/main.c b/fs/gfs2/locking/dlm/main.c index 870a1cd99f57..2194b1d5b5ec 100644 --- a/fs/gfs2/locking/dlm/main.c +++ b/fs/gfs2/locking/dlm/main.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c index 3caeafc02a1b..f279385774b7 100644 --- a/fs/gfs2/locking/dlm/mount.c +++ b/fs/gfs2/locking/dlm/mount.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include "lock_dlm.h" diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c index 1acb2519f439..263636b390fe 100644 --- a/fs/gfs2/locking/dlm/plock.c +++ b/fs/gfs2/locking/dlm/plock.c @@ -3,7 +3,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c index 0d8bd0806dba..82bef017f944 100644 --- a/fs/gfs2/locking/dlm/sysfs.c +++ b/fs/gfs2/locking/dlm/sysfs.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c index 489235b2edba..0b4be102e170 100644 --- a/fs/gfs2/locking/dlm/thread.c +++ b/fs/gfs2/locking/dlm/thread.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include "lock_dlm.h" diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index 748aa5d33641..95a29914730a 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index af728cb3b327..45ea3ec6f776 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h index 8cfd0f1d29f8..80764e388bb2 100644 --- a/fs/gfs2/log.h +++ b/fs/gfs2/log.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __LOG_DOT_H__ diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 0ec38b399097..e2c2582c8f6e 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h index 8a1029d3d389..2e3365c2b101 100644 --- a/fs/gfs2/lops.h +++ b/fs/gfs2/lops.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __LOPS_DOT_H__ diff --git a/fs/gfs2/lvb.c b/fs/gfs2/lvb.c deleted file mode 100644 index e88e9cce14e7..000000000000 --- a/fs/gfs2/lvb.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#include -#include -#include -#include -#include -#include - -#include "gfs2.h" -#include "lm_interface.h" -#include "incore.h" -#include "lvb.h" - -#define pv(struct, member, fmt) printk(KERN_INFO " "#member" = "fmt"\n", \ - struct->member); - -void gfs2_quota_lvb_in(struct gfs2_quota_lvb *qb, char *lvb) -{ - struct gfs2_quota_lvb *str = (struct gfs2_quota_lvb *)lvb; - - qb->qb_magic = be32_to_cpu(str->qb_magic); - qb->qb_limit = be64_to_cpu(str->qb_limit); - qb->qb_warn = be64_to_cpu(str->qb_warn); - qb->qb_value = be64_to_cpu(str->qb_value); -} - -void gfs2_quota_lvb_out(struct gfs2_quota_lvb *qb, char *lvb) -{ - struct gfs2_quota_lvb *str = (struct gfs2_quota_lvb *)lvb; - - str->qb_magic = cpu_to_be32(qb->qb_magic); - str->qb_limit = cpu_to_be64(qb->qb_limit); - str->qb_warn = cpu_to_be64(qb->qb_warn); - str->qb_value = cpu_to_be64(qb->qb_value); -} - - diff --git a/fs/gfs2/lvb.h b/fs/gfs2/lvb.h deleted file mode 100644 index 1b1a8b75219a..000000000000 --- a/fs/gfs2/lvb.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. - */ - -#ifndef __LVB_DOT_H__ -#define __LVB_DOT_H__ - -#define GFS2_MIN_LVB_SIZE 32 - -void gfs2_quota_lvb_in(struct gfs2_quota_lvb *qb, char *lvb); -void gfs2_quota_lvb_out(struct gfs2_quota_lvb *qb, char *lvb); - -#endif /* __LVB_DOT_H__ */ - diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index dccc4f6f503f..b46f400705a2 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 502864b24196..03850b64c072 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index 951814e86272..4ddc936aae16 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __DIO_DOT_H__ diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c index 0d4b230785af..b66027827aaa 100644 --- a/fs/gfs2/mount.c +++ b/fs/gfs2/mount.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/mount.h b/fs/gfs2/mount.h index 2eb14722144f..8a21897b63e5 100644 --- a/fs/gfs2/mount.h +++ b/fs/gfs2/mount.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __MOUNT_DOT_H__ diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index 39c7f0345fc6..03881f9870f7 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 0de7a9523633..21ae9e4f0f6c 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h index dfc3dda6de11..6c07aa2bd98a 100644 --- a/fs/gfs2/ops_address.h +++ b/fs/gfs2/ops_address.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __OPS_ADDRESS_DOT_H__ diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index fd55979ec428..a1ba1ec8eef4 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/ops_dentry.h b/fs/gfs2/ops_dentry.h index 1b6e75c0a4a7..e7b05e5c62ec 100644 --- a/fs/gfs2/ops_dentry.h +++ b/fs/gfs2/ops_dentry.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __OPS_DENTRY_DOT_H__ diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index 6354f4799e68..c94cbc8b6ef6 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/ops_export.h b/fs/gfs2/ops_export.h index 09fc077657d1..d52c2d93010c 100644 --- a/fs/gfs2/ops_export.h +++ b/fs/gfs2/ops_export.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __OPS_EXPORT_DOT_H__ diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 145a29fa4ea4..07a0c861ac41 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/ops_file.h b/fs/gfs2/ops_file.h index 46302b513937..064e52c30665 100644 --- a/fs/gfs2/ops_file.h +++ b/fs/gfs2/ops_file.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __OPS_FILE_DOT_H__ diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index e5a91ead250c..46f910e29bf0 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/ops_fstype.h b/fs/gfs2/ops_fstype.h index 622f5760d6b2..b85ecce3ca6b 100644 --- a/fs/gfs2/ops_fstype.h +++ b/fs/gfs2/ops_fstype.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __OPS_FSTYPE_DOT_H__ diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 8fb7c5c9a7c3..1786a485acc5 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/ops_inode.h b/fs/gfs2/ops_inode.h index 930aaae91377..6f4b54783d29 100644 --- a/fs/gfs2/ops_inode.h +++ b/fs/gfs2/ops_inode.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __OPS_INODE_DOT_H__ diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 18ed18c729e8..6ced71240379 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/ops_super.h b/fs/gfs2/ops_super.h index a15ccc276113..cbc4f73e9a92 100644 --- a/fs/gfs2/ops_super.h +++ b/fs/gfs2/ops_super.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __OPS_SUPER_DOT_H__ diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index 875a769444a1..451f48d62e58 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/ops_vm.h b/fs/gfs2/ops_vm.h index 077cffcd4085..d5ba4b9c50fd 100644 --- a/fs/gfs2/ops_vm.h +++ b/fs/gfs2/ops_vm.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __OPS_VM_DOT_H__ diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 3ca65c37c354..be87983a20a9 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ /* @@ -52,7 +52,6 @@ #include "glock.h" #include "glops.h" #include "log.h" -#include "lvb.h" #include "meta_io.h" #include "quota.h" #include "rgrp.h" @@ -586,7 +585,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, struct page *page; void *kaddr; __be64 *ptr; - u64 value; + s64 value; int err = -EIO; page = grab_cache_page(mapping, index); @@ -627,7 +626,8 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, kaddr = kmap_atomic(page, KM_USER0); ptr = (__be64 *)(kaddr + offset); - value = *ptr = cpu_to_be64(be64_to_cpu(*ptr) + change); + value = (s64)be64_to_cpu(*ptr) + change; + *ptr = cpu_to_be64(value); flush_dcache_page(page); kunmap_atomic(kaddr, KM_USER0); err = 0; @@ -761,6 +761,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, char buf[sizeof(struct gfs2_quota)]; struct file_ra_state ra_state; int error; + struct gfs2_quota_lvb *qlvb; file_ra_state_init(&ra_state, sdp->sd_quota_inode->i_mapping); restart: @@ -768,9 +769,9 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, if (error) return error; - gfs2_quota_lvb_in(&qd->qd_qb, qd->qd_gl->gl_lvb); + qd->qd_qb = *(struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb; - if (force_refresh || qd->qd_qb.qb_magic != GFS2_MAGIC) { + if (force_refresh || qd->qd_qb.qb_magic != cpu_to_be32(GFS2_MAGIC)) { loff_t pos; gfs2_glock_dq_uninit(q_gh); error = gfs2_glock_nq_init(qd->qd_gl, @@ -779,9 +780,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, if (error) return error; - error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_SHARED, 0, - &i_gh); + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); if (error) goto fail; @@ -794,15 +793,15 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, gfs2_glock_dq_uninit(&i_gh); + gfs2_quota_in(&q, buf); - - memset(&qd->qd_qb, 0, sizeof(struct gfs2_quota_lvb)); - qd->qd_qb.qb_magic = GFS2_MAGIC; - qd->qd_qb.qb_limit = q.qu_limit; - qd->qd_qb.qb_warn = q.qu_warn; - qd->qd_qb.qb_value = q.qu_value; - - gfs2_quota_lvb_out(&qd->qd_qb, qd->qd_gl->gl_lvb); + qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb; + qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC); + qlvb->__pad = 0; + qlvb->qb_limit = cpu_to_be64(q.qu_limit); + qlvb->qb_warn = cpu_to_be64(q.qu_warn); + qlvb->qb_value = cpu_to_be64(q.qu_value); + qd->qd_qb = *qlvb; if (gfs2_glock_is_blocking(qd->qd_gl)) { gfs2_glock_dq_uninit(q_gh); @@ -877,13 +876,14 @@ static int need_sync(struct gfs2_quota_data *qd) if (value < 0) do_sync = 0; - else if (qd->qd_qb.qb_value >= (int64_t)qd->qd_qb.qb_limit) + else if ((s64)be64_to_cpu(qd->qd_qb.qb_value) >= + (s64)be64_to_cpu(qd->qd_qb.qb_limit)) do_sync = 0; else { value *= gfs2_jindex_size(sdp) * num; do_div(value, den); - value += qd->qd_qb.qb_value; - if (value < (int64_t)qd->qd_qb.qb_limit) + value += (s64)be64_to_cpu(qd->qd_qb.qb_value); + if (value < (int64_t)be64_to_cpu(qd->qd_qb.qb_limit)) do_sync = 0; } @@ -959,17 +959,17 @@ int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags)))) continue; - value = qd->qd_qb.qb_value; + value = (s64)be64_to_cpu(qd->qd_qb.qb_value); spin_lock(&sdp->sd_quota_spin); value += qd->qd_change; spin_unlock(&sdp->sd_quota_spin); - if (qd->qd_qb.qb_limit && (int64_t)qd->qd_qb.qb_limit < value) { + if (be64_to_cpu(qd->qd_qb.qb_limit) && (int64_t)be64_to_cpu(qd->qd_qb.qb_limit) < value) { print_message(qd, "exceeded"); error = -EDQUOT; break; - } else if (qd->qd_qb.qb_warn && - (int64_t)qd->qd_qb.qb_warn < value && + } else if (be64_to_cpu(qd->qd_qb.qb_warn) && + (int64_t)be64_to_cpu(qd->qd_qb.qb_warn) < value && time_after_eq(jiffies, qd->qd_last_warn + gfs2_tune_get(sdp, gt_quota_warn_period) * HZ)) { @@ -1088,9 +1088,9 @@ int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, goto out; memset(q, 0, sizeof(struct gfs2_quota)); - q->qu_limit = qd->qd_qb.qb_limit; - q->qu_warn = qd->qd_qb.qb_warn; - q->qu_value = qd->qd_qb.qb_value; + q->qu_limit = be64_to_cpu(qd->qd_qb.qb_limit); + q->qu_warn = be64_to_cpu(qd->qd_qb.qb_warn); + q->qu_value = be64_to_cpu(qd->qd_qb.qb_value); spin_lock(&sdp->sd_quota_spin); q->qu_value += qd->qd_change; diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h index af05492f9644..6702a56d49b5 100644 --- a/fs/gfs2/quota.h +++ b/fs/gfs2/quota.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __QUOTA_DOT_H__ diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 8fe518cfb3de..acafe4b4d6f0 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/recovery.h b/fs/gfs2/recovery.h index ac0f1d6ce456..bed1a7857f6e 100644 --- a/fs/gfs2/recovery.h +++ b/fs/gfs2/recovery.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __RECOVERY_DOT_H__ diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 84fcc1bfaf1b..62d0a84df982 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h index 14600944d184..f94761bf3460 100644 --- a/fs/gfs2/rgrp.h +++ b/fs/gfs2/rgrp.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __RGRP_DOT_H__ diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 3c318a9e8a8c..2cf2802fc92e 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/super.h b/fs/gfs2/super.h index df2495230402..4a6ce9582743 100644 --- a/fs/gfs2/super.h +++ b/fs/gfs2/super.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __SUPER_DOT_H__ diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index 3c4cb4558905..3ffa88506c44 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/sys.h b/fs/gfs2/sys.h index c46a700e801e..f8c01b50bfba 100644 --- a/fs/gfs2/sys.h +++ b/fs/gfs2/sys.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __SYS_DOT_H__ diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 05e0b72d56ff..8e18e634cbed 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h index fbef3f5a99e3..9e3ce84f6102 100644 --- a/fs/gfs2/trans.h +++ b/fs/gfs2/trans.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __TRANS_DOT_H__ diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 39e67b1ec70a..2852431764c9 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #include diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index 8216d28bd816..60b370365eea 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -4,7 +4,7 @@ * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License v.2. + * of the GNU General Public License version 2. */ #ifndef __UTIL_DOT_H__ From 5029996547a9f3988459e11955c13259495308ef Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 09:49:55 -0400 Subject: [PATCH 222/292] [GFS2] Tidy up locking code As per Jan Engelhardt's second email, this removes some unused code, and fixes up indenting in various places. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 53 +++++++++--------------------------- fs/gfs2/glock.h | 6 ++-- fs/gfs2/lm.c | 62 ++++++++++++------------------------------ fs/gfs2/lm.h | 25 ++++++++--------- fs/gfs2/lm_interface.h | 2 -- fs/gfs2/locking.c | 10 ++----- fs/gfs2/main.c | 2 -- 7 files changed, 47 insertions(+), 113 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 989f4f78f9be..fac271f390bf 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -300,8 +300,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, /* If this glock protects actual on-disk data or metadata blocks, create a VFS inode to manage the pages/buffers holding them. */ - if (glops == &gfs2_inode_glops || - glops == &gfs2_rgrp_glops) { + if (glops == &gfs2_inode_glops || glops == &gfs2_rgrp_glops) { gl->gl_aspace = gfs2_aspace_get(sdp); if (!gl->gl_aspace) { error = -ENOMEM; @@ -820,13 +819,11 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret) if (!gh) gl->gl_stamp = jiffies; - else if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) { spin_lock(&gl->gl_spin); list_del_init(&gh->gh_list); gh->gh_error = -EIO; spin_unlock(&gl->gl_spin); - } else if (test_bit(HIF_DEMOTE, &gh->gh_iflags)) { spin_lock(&gl->gl_spin); list_del_init(&gh->gh_list); @@ -842,7 +839,7 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret) spin_unlock(&gl->gl_spin); if (ret & LM_OUT_CANCELED) - handle_callback(gl, LM_ST_UNLOCKED); /* Lame */ + handle_callback(gl, LM_ST_UNLOCKED); } else if (ret & LM_OUT_CANCELED) { spin_lock(&gl->gl_spin); @@ -916,11 +913,8 @@ void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags) gfs2_assert_warn(sdp, state != LM_ST_UNLOCKED); gfs2_assert_warn(sdp, state != gl->gl_state); - if (gl->gl_state == LM_ST_EXCLUSIVE) { - if (glops->go_sync) - glops->go_sync(gl, - DIO_METADATA | DIO_DATA | DIO_RELEASE); - } + if (gl->gl_state == LM_ST_EXCLUSIVE && glops->go_sync) + glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE); gfs2_glock_hold(gl); gl->gl_req_bh = xmote_bh; @@ -1006,10 +1000,8 @@ void gfs2_glock_drop_th(struct gfs2_glock *gl) gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders)); gfs2_assert_warn(sdp, gl->gl_state != LM_ST_UNLOCKED); - if (gl->gl_state == LM_ST_EXCLUSIVE) { - if (glops->go_sync) - glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE); - } + if (gl->gl_state == LM_ST_EXCLUSIVE && glops->go_sync) + glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE); gfs2_glock_hold(gl); gl->gl_req_bh = drop_bh; @@ -1041,9 +1033,8 @@ static void do_cancels(struct gfs2_holder *gh) while (gl->gl_req_gh != gh && !test_bit(HIF_HOLDER, &gh->gh_iflags) && !list_empty(&gh->gh_list)) { - if (gl->gl_req_bh && - !(gl->gl_req_gh && - (gl->gl_req_gh->gh_flags & GL_NOCANCEL))) { + if (gl->gl_req_bh && !(gl->gl_req_gh && + (gl->gl_req_gh->gh_flags & GL_NOCANCEL))) { spin_unlock(&gl->gl_spin); gfs2_lm_cancel(gl->gl_sbd, gl->gl_lock); msleep(100); @@ -1323,10 +1314,8 @@ static void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state, spin_lock(&gl->gl_spin); - if (test_bit(GLF_LOCK, &gl->gl_flags) || - !list_empty(&gl->gl_holders) || - !list_empty(&gl->gl_waiters1) || - !list_empty(&gl->gl_waiters2) || + if (test_bit(GLF_LOCK, &gl->gl_flags) || !list_empty(&gl->gl_holders) || + !list_empty(&gl->gl_waiters1) || !list_empty(&gl->gl_waiters2) || !list_empty(&gl->gl_waiters3) || relaxed_state_ok(gl->gl_state, state, flags)) { spin_unlock(&gl->gl_spin); @@ -1690,19 +1679,6 @@ void gfs2_lvb_unhold(struct gfs2_glock *gl) gfs2_glock_put(gl); } -#if 0 -void gfs2_lvb_sync(struct gfs2_glock *gl) -{ - gfs2_glmutex_lock(gl); - - gfs2_assert(gl->gl_sbd, atomic_read(&gl->gl_lvb_count)); - if (!gfs2_assert_warn(gl->gl_sbd, gfs2_glock_is_held_excl(gl))) - gfs2_lm_sync_lvb(gl->gl_sbd, gl->gl_lock, gl->gl_lvb); - - gfs2_glmutex_unlock(gl); -} -#endif /* 0 */ - static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name, unsigned int state) { @@ -1813,8 +1789,7 @@ static int demote_ok(struct gfs2_glock *gl) if (test_bit(GLF_STICKY, &gl->gl_flags)) demote = 0; else if (test_bit(GLF_PREFETCH, &gl->gl_flags)) - demote = time_after_eq(jiffies, - gl->gl_stamp + + demote = time_after_eq(jiffies, gl->gl_stamp + gfs2_tune_get(sdp, gt_prefetch_secs) * HZ); else if (glops->go_demote_ok) demote = glops->go_demote_ok(gl); @@ -1872,8 +1847,7 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp) if (gfs2_glmutex_trylock(gl)) { if (queue_empty(gl, &gl->gl_holders) && - gl->gl_state != LM_ST_UNLOCKED && - demote_ok(gl)) + gl->gl_state != LM_ST_UNLOCKED && demote_ok(gl)) handle_callback(gl, LM_ST_UNLOCKED); gfs2_glmutex_unlock(gl); } @@ -2036,8 +2010,7 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait) cont = 0; for (x = 0; x < GFS2_GL_HASH_SIZE; x++) - if (examine_bucket(clear_glock, sdp, - &sdp->sd_gl_hash[x])) + if (examine_bucket(clear_glock, sdp, &sdp->sd_gl_hash[x])) cont = 1; if (!wait || !cont) diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 07a8d02a234d..1a90a1983beb 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -51,17 +51,17 @@ static inline int gfs2_glock_is_locked_by_me(struct gfs2_glock *gl) static inline int gfs2_glock_is_held_excl(struct gfs2_glock *gl) { - return (gl->gl_state == LM_ST_EXCLUSIVE); + return gl->gl_state == LM_ST_EXCLUSIVE; } static inline int gfs2_glock_is_held_dfrd(struct gfs2_glock *gl) { - return (gl->gl_state == LM_ST_DEFERRED); + return gl->gl_state == LM_ST_DEFERRED; } static inline int gfs2_glock_is_held_shrd(struct gfs2_glock *gl) { - return (gl->gl_state == LM_ST_SHARED); + return gl->gl_state == LM_ST_SHARED; } static inline int gfs2_glock_is_blocking(struct gfs2_glock *gl) diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index 1a9e75da19d1..fb918c7de655 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -124,10 +124,8 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, lm_lock_t **lockp) { - int error; - if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - error = -EIO; - else + int error = -EIO; + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = sdp->sd_lockstruct.ls_ops->lm_get_lock( sdp->sd_lockstruct.ls_lockspace, name, lockp); return error; @@ -143,12 +141,9 @@ unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, unsigned int cur_state, unsigned int req_state, unsigned int flags) { - int ret; - if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - ret = 0; - else - ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, - cur_state, + int ret = 0; + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, cur_state, req_state, flags); return ret; } @@ -156,10 +151,8 @@ unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, unsigned int cur_state) { - int ret; - if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - ret = 0; - else + int ret = 0; + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) ret = sdp->sd_lockstruct.ls_ops->lm_unlock(lock, cur_state); return ret; } @@ -172,10 +165,8 @@ void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock) int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp) { - int error; - if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - error = -EIO; - else + int error = -EIO; + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp); return error; } @@ -186,50 +177,33 @@ void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb); } -#if 0 -void gfs2_lm_sync_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) -{ - if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - sdp->sd_lockstruct.ls_ops->lm_sync_lvb(lock, lvb); -} -#endif /* 0 */ - int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, struct file *file, struct file_lock *fl) { - int error; - if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - error = -EIO; - else + int error = -EIO; + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = sdp->sd_lockstruct.ls_ops->lm_plock_get( - sdp->sd_lockstruct.ls_lockspace, - name, file, fl); + sdp->sd_lockstruct.ls_lockspace, name, file, fl); return error; } int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name, struct file *file, int cmd, struct file_lock *fl) { - int error; - if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - error = -EIO; - else + int error = -EIO; + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = sdp->sd_lockstruct.ls_ops->lm_plock( - sdp->sd_lockstruct.ls_lockspace, - name, file, cmd, fl); + sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl); return error; } int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name, struct file *file, struct file_lock *fl) { - int error; - if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - error = -EIO; - else + int error = -EIO; + if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = sdp->sd_lockstruct.ls_ops->lm_punlock( - sdp->sd_lockstruct.ls_lockspace, - name, file, fl); + sdp->sd_lockstruct.ls_lockspace, name, file, fl); return error; } diff --git a/fs/gfs2/lm.h b/fs/gfs2/lm.h index 15839aaa4ca6..dbef88852ef3 100644 --- a/fs/gfs2/lm.h +++ b/fs/gfs2/lm.h @@ -16,9 +16,9 @@ int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent); void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp); void gfs2_lm_unmount(struct gfs2_sbd *sdp); int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) -__attribute__ ((format(printf, 2, 3))); -int gfs2_lm_get_lock(struct gfs2_sbd *sdp, - struct lm_lockname *name, lm_lock_t **lockp); + __attribute__ ((format(printf, 2, 3))); +int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, + lm_lock_t **lockp); void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock); unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, unsigned int cur_state, unsigned int req_state, @@ -28,16 +28,13 @@ unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock); int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp); void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb); -int gfs2_lm_plock_get(struct gfs2_sbd *sdp, - struct lm_lockname *name, - struct file *file, struct file_lock *fl); -int gfs2_lm_plock(struct gfs2_sbd *sdp, - struct lm_lockname *name, - struct file *file, int cmd, struct file_lock *fl); -int gfs2_lm_punlock(struct gfs2_sbd *sdp, - struct lm_lockname *name, - struct file *file, struct file_lock *fl); -void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, - unsigned int jid, unsigned int message); +int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, + struct file *file, struct file_lock *fl); +int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name, + struct file *file, int cmd, struct file_lock *fl); +int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name, + struct file *file, struct file_lock *fl); +void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid, + unsigned int message); #endif /* __LM_DOT_H__ */ diff --git a/fs/gfs2/lm_interface.h b/fs/gfs2/lm_interface.h index e1e89d92a8db..0bf4c276e0fe 100644 --- a/fs/gfs2/lm_interface.h +++ b/fs/gfs2/lm_interface.h @@ -260,8 +260,6 @@ struct lm_lockstruct { int ls_flags; }; -void __init gfs2_init_lmh(void); - /* * Lock module bottom interface. A lock module makes itself available to GFS * with these functions. diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c index 11c4068105cc..fce2001e5e25 100644 --- a/fs/gfs2/locking.c +++ b/fs/gfs2/locking.c @@ -27,8 +27,8 @@ struct lmh_wrapper { /* List of registered low-level locking protocols. A file system selects one of them by name at mount time, e.g. lock_nolock, lock_dlm. */ -static struct list_head lmh_list; -static struct mutex lmh_lock; +static LIST_HEAD(lmh_list); +static DEFINE_MUTEX(lmh_lock); /** * gfs2_register_lockproto - Register a low-level locking protocol @@ -180,12 +180,6 @@ void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct) mutex_unlock(&lmh_lock); } -void __init gfs2_init_lmh(void) -{ - mutex_init(&lmh_lock); - INIT_LIST_HEAD(&lmh_list); -} - EXPORT_SYMBOL_GPL(gfs2_register_lockproto); EXPORT_SYMBOL_GPL(gfs2_unregister_lockproto); diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index b46f400705a2..143fda727a9c 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -65,8 +65,6 @@ static int __init init_gfs2_fs(void) { int error; - gfs2_init_lmh(); - error = gfs2_sys_init(); if (error) return error; From 75d3b817a0b48425da921052955cc58f20bbab52 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 11:41:31 -0400 Subject: [PATCH 223/292] [GFS2] Tidy up bmap/inode code As per Jan Engelhardt's third set of comments, this make various code style changes and moves the structures from format.h into super.c, which was the only place that format.h was actually used. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 16 +++++++--------- fs/gfs2/format.h | 21 --------------------- fs/gfs2/glops.c | 12 +++++------- fs/gfs2/inode.c | 47 +++++++++++++++++++++-------------------------- fs/gfs2/super.c | 9 ++++++++- 5 files changed, 41 insertions(+), 64 deletions(-) delete mode 100644 fs/gfs2/format.h diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 913c0e5490e9..b75a2f93dada 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -94,7 +94,7 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, map_bh(bh, inode->i_sb, block); set_buffer_uptodate(bh); - if ((sdp->sd_args.ar_data == GFS2_DATA_ORDERED) || gfs2_is_jdata(ip)) + if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) gfs2_trans_add_bh(ip->i_gl, bh, 0); mark_buffer_dirty(bh); @@ -369,7 +369,7 @@ static inline u64 *metapointer(struct buffer_head *bh, int *boundary, u64 *ptr; *boundary = 0; ptr = ((u64 *)(bh->b_data + head_size)) + mp->mp_list[height]; - if (ptr + 1 == (u64*)(bh->b_data + bh->b_size)) + if (ptr + 1 == (u64 *)(bh->b_data + bh->b_size)) *boundary = 1; return ptr; } @@ -456,7 +456,7 @@ static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock, if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) goto out; - bsize = (gfs2_is_dir(ip)) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize; + bsize = gfs2_is_dir(ip) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize; height = calc_tree_height(ip, (lblock + 1) * bsize); if (ip->i_di.di_height < height) { @@ -554,7 +554,7 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsi bh = gfs2_block_pointers(inode, lblock, new, dblock, &boundary, &mp); *extlen = 1; - if (bh && !IS_ERR(bh) && *dblock && !*new) { + if (bh != NULL && !IS_ERR(bh) && *dblock != 0 && *new == 0) { u64 tmp_dblock; int tmp_new; unsigned int nptrs; @@ -565,7 +565,7 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsi lookup_block(ip, bh, end_of_metadata, &mp, 0, &tmp_new, &tmp_dblock); if (*dblock + *extlen != tmp_dblock) break; - (*extlen)++; + ++*extlen; } } bmap_unlock(inode, create); @@ -612,10 +612,8 @@ static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh, return error; dibh = bh; - top = (uint64_t *)(bh->b_data + sizeof(struct gfs2_dinode)) + - mp->mp_list[0]; - bottom = (uint64_t *)(bh->b_data + sizeof(struct gfs2_dinode)) + - sdp->sd_diptrs; + top = (u64 *)(bh->b_data + sizeof(struct gfs2_dinode)) + mp->mp_list[0]; + bottom = (u64 *)(bh->b_data + sizeof(struct gfs2_dinode)) + sdp->sd_diptrs; } else { error = gfs2_meta_indirect_buffer(ip, height, block, 0, &bh); if (error) diff --git a/fs/gfs2/format.h b/fs/gfs2/format.h deleted file mode 100644 index 9acbf457ee58..000000000000 --- a/fs/gfs2/format.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. - * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. - * - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU General Public License version 2. - */ - -#ifndef __FORMAT_DOT_H__ -#define __FORMAT_DOT_H__ - -static const uint32_t gfs2_old_fs_formats[] = { - 0 -}; - -static const uint32_t gfs2_old_multihost_formats[] = { - 0 -}; - -#endif /* __FORMAT_DOT_H__ */ diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 8e1d8ee68e2e..d3e7b082a918 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -234,7 +234,6 @@ static void inode_go_sync(struct gfs2_glock *gl, int flags) if (flags & DIO_RELEASE) gfs2_ail_empty_gl(gl); } - } /** @@ -324,12 +323,11 @@ static void inode_go_unlock(struct gfs2_holder *gh) struct gfs2_glock *gl = gh->gh_gl; struct gfs2_inode *ip = gl->gl_object; - if (ip) { - if (test_bit(GLF_DIRTY, &gl->gl_flags)) - gfs2_inode_attr_in(ip); - - gfs2_meta_cache_flush(ip); - } + if (ip == NULL) + return; + if (test_bit(GLF_DIRTY, &gl->gl_flags)) + gfs2_inode_attr_in(ip); + gfs2_meta_cache_flush(ip); } /** diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index decb0cf85691..1aaaaa1cc8c3 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -97,15 +97,15 @@ void gfs2_inode_attr_in(struct gfs2_inode *ip) void gfs2_inode_attr_out(struct gfs2_inode *ip) { struct inode *inode = &ip->i_inode; - + struct gfs2_dinode *di = &ip->i_di; gfs2_assert_withdraw(GFS2_SB(inode), - (ip->i_di.di_mode & S_IFMT) == (inode->i_mode & S_IFMT)); - ip->i_di.di_mode = inode->i_mode; - ip->i_di.di_uid = inode->i_uid; - ip->i_di.di_gid = inode->i_gid; - ip->i_di.di_atime = inode->i_atime.tv_sec; - ip->i_di.di_mtime = inode->i_mtime.tv_sec; - ip->i_di.di_ctime = inode->i_ctime.tv_sec; + (di->di_mode & S_IFMT) == (inode->i_mode & S_IFMT)); + di->di_mode = inode->i_mode; + di->di_uid = inode->i_uid; + di->di_gid = inode->i_gid; + di->di_atime = inode->i_atime.tv_sec; + di->di_mtime = inode->i_mtime.tv_sec; + di->di_ctime = inode->i_ctime.tv_sec; } static int iget_test(struct inode *inode, void *opaque) @@ -1213,31 +1213,26 @@ fail: * * Returns: 1 if A > B * -1 if A < B - * 0 if A = B + * 0 if A == B */ static int glock_compare_atime(const void *arg_a, const void *arg_b) { - struct gfs2_holder *gh_a = *(struct gfs2_holder **)arg_a; - struct gfs2_holder *gh_b = *(struct gfs2_holder **)arg_b; - struct lm_lockname *a = &gh_a->gh_gl->gl_name; - struct lm_lockname *b = &gh_b->gh_gl->gl_name; - int ret = 0; + const struct gfs2_holder *gh_a = *(const struct gfs2_holder **)arg_a; + const struct gfs2_holder *gh_b = *(const struct gfs2_holder **)arg_b; + const struct lm_lockname *a = &gh_a->gh_gl->gl_name; + const struct lm_lockname *b = &gh_b->gh_gl->gl_name; if (a->ln_number > b->ln_number) - ret = 1; - else if (a->ln_number < b->ln_number) - ret = -1; - else { - if (gh_a->gh_state == LM_ST_SHARED && - gh_b->gh_state == LM_ST_EXCLUSIVE) - ret = 1; - else if (gh_a->gh_state == LM_ST_SHARED && - (gh_b->gh_flags & GL_ATIME)) - ret = 1; - } + return 1; + if (a->ln_number < b->ln_number) + return -1; + if (gh_a->gh_state == LM_ST_SHARED && gh_b->gh_state == LM_ST_EXCLUSIVE) + return 1; + if (gh_a->gh_state == LM_ST_SHARED && (gh_b->gh_flags & GL_ATIME)) + return 1; - return ret; + return 0; } /** diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 2cf2802fc92e..e93066f930c1 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -21,7 +21,6 @@ #include "incore.h" #include "bmap.h" #include "dir.h" -#include "format.h" #include "glock.h" #include "glops.h" #include "inode.h" @@ -34,6 +33,14 @@ #include "trans.h" #include "util.h" +static const uint32_t gfs2_old_fs_formats[] = { + 0 +}; + +static const uint32_t gfs2_old_multihost_formats[] = { + 0 +}; + /** * gfs2_tune_init - Fill a gfs2_tune structure with default values * @gt: tune From a91ea69ffd3f8a0b7139bfd44042ab384461e631 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 12:04:26 -0400 Subject: [PATCH 224/292] [GFS2] Align all labels against LH side This makes everything consistent. Signed-off-by: Steven Whitehouse --- fs/gfs2/acl.c | 14 +++---- fs/gfs2/bmap.c | 39 +++++++------------ fs/gfs2/dir.c | 18 +++------ fs/gfs2/eattr.c | 62 +++++++++++------------------- fs/gfs2/glock.c | 3 +- fs/gfs2/lm.c | 2 +- fs/gfs2/locking/dlm/lock.c | 2 +- fs/gfs2/locking/dlm/mount.c | 10 ++--- fs/gfs2/locking/dlm/thread.c | 2 +- fs/gfs2/meta_io.c | 2 +- fs/gfs2/mount.c | 4 +- fs/gfs2/ops_dentry.c | 16 +++----- fs/gfs2/ops_file.c | 3 +- fs/gfs2/ops_fstype.c | 73 +++++++++++------------------------- fs/gfs2/ops_inode.c | 26 +++---------- fs/gfs2/ops_vm.c | 12 ++---- fs/gfs2/quota.c | 49 ++++++++++-------------- fs/gfs2/super.c | 27 +++++-------- fs/gfs2/sys.c | 10 ++--- 19 files changed, 129 insertions(+), 245 deletions(-) diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index 60c98c0314a1..d846b5ad1d87 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -65,9 +65,8 @@ int gfs2_acl_validate_set(struct gfs2_inode *ip, int access, error = 0; } - out: +out: posix_acl_release(acl); - return error; } @@ -132,18 +131,16 @@ static int acl_get(struct gfs2_inode *ip, int access, struct posix_acl **acl, error = PTR_ERR(*acl); } - out_kfree: +out_kfree: if (error || !data) kfree(er.er_data); else { *data = er.er_data; *len = er.er_data_len; } - - out: +out: if (error || el == &el_this) brelse(el->el_bh); - return error; } @@ -270,7 +267,7 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct gfs2_inode *ip) } else munge_mode(ip, mode); - out: +out: posix_acl_release(acl); kfree(er.er_data); return error; @@ -303,11 +300,10 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr) error = gfs2_ea_acl_chmod(ip, &el, attr, data); } - out: +out: posix_acl_release(acl); brelse(el.el_bh); kfree(data); - return error; } diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index b75a2f93dada..bb597839c0c9 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -170,12 +170,10 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) gfs2_dinode_out(&ip->i_di, dibh->b_data); - out_brelse: +out_brelse: brelse(dibh); - - out: +out: up_write(&ip->i_rw_mutex); - return error; } @@ -642,9 +640,8 @@ static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh, break; } - out: +out: brelse(bh); - return error; } @@ -788,15 +785,12 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, gfs2_trans_end(sdp); - out_rg_gunlock: +out_rg_gunlock: gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); - - out_rlist: +out_rlist: gfs2_rlist_free(&rlist); - - out: +out: gfs2_glock_dq_uninit(&ip->i_alloc.al_ri_gh); - return error; } @@ -868,18 +862,14 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size) gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); - out_end_trans: +out_end_trans: gfs2_trans_end(sdp); - - out_ipres: +out_ipres: gfs2_inplace_release(ip); - - out_gunlock_q: +out_gunlock_q: gfs2_quota_unlock(ip); - - out: +out: gfs2_alloc_put(ip); - return error; } @@ -998,9 +988,8 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size) brelse(dibh); - out: +out: gfs2_trans_end(sdp); - return error; } @@ -1035,7 +1024,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size) gfs2_quota_unhold(ip); - out: +out: gfs2_alloc_put(ip); return error; } @@ -1070,11 +1059,9 @@ static int trunc_end(struct gfs2_inode *ip) gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); - out: +out: up_write(&ip->i_rw_mutex); - gfs2_trans_end(sdp); - return error; } diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 7b8a38eaa41a..59d0cbcaecff 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -1134,9 +1134,8 @@ static int dir_double_exhash(struct gfs2_inode *dip) return error; - fail: +fail: kfree(buf); - return error; } @@ -1890,23 +1889,18 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, gfs2_dinode_out(&dip->i_di, dibh->b_data); brelse(dibh); - out_end_trans: +out_end_trans: gfs2_trans_end(sdp); - - out_rg_gunlock: +out_rg_gunlock: gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); - - out_rlist: +out_rlist: gfs2_rlist_free(&rlist); gfs2_glock_dq_uninit(&dip->i_alloc.al_ri_gh); - - out_qs: +out_qs: gfs2_quota_unhold(dip); - - out: +out: gfs2_alloc_put(dip); kfree(ht); - return error; } diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 9081822ce80c..5a56e6568622 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -107,7 +107,7 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, return error; - fail: +fail: gfs2_consist_inode(ip); return -EIO; } @@ -152,9 +152,8 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) if (error) break; } - out: +out: brelse(bh); - return error; } @@ -319,9 +318,8 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, gfs2_trans_end(sdp); - out_gunlock: +out_gunlock: gfs2_glock_dq_uninit(&rg_gh); - return error; } @@ -348,12 +346,10 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, gfs2_glock_dq_uninit(&al->al_ri_gh); - out_quota: +out_quota: gfs2_quota_unhold(ip); - - out_alloc: +out_alloc: gfs2_alloc_put(ip); - return error; } @@ -506,9 +502,8 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, brelse(bh[x]); } - out: +out: kfree(bh); - return error; } @@ -747,18 +742,14 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, brelse(dibh); } - out_end_trans: +out_end_trans: gfs2_trans_end(GFS2_SB(&ip->i_inode)); - - out_ipres: +out_ipres: gfs2_inplace_release(ip); - - out_gunlock_q: +out_gunlock_q: gfs2_quota_unlock(ip); - - out: +out: gfs2_alloc_put(ip); - return error; } @@ -884,9 +875,8 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh, gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); - out: +out: gfs2_trans_end(GFS2_SB(&ip->i_inode)); - return error; } @@ -1025,9 +1015,8 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, if (private) ea_set_remove_stuffed(ip, (struct gfs2_ea_location *)private); - out: +out: brelse(indbh); - return error; } @@ -1285,15 +1274,13 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, brelse(bh[x]); } - out: +out: kfree(bh); - return error; - fail: +fail: gfs2_trans_end(sdp); kfree(bh); - return error; } @@ -1442,15 +1429,12 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) gfs2_trans_end(sdp); - out_gunlock: +out_gunlock: gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); - - out_rlist_free: +out_rlist_free: gfs2_rlist_free(&rlist); - - out: +out: brelse(indbh); - return error; } @@ -1494,9 +1478,8 @@ static int ea_dealloc_block(struct gfs2_inode *ip) gfs2_trans_end(sdp); - out_gunlock: +out_gunlock: gfs2_glock_dq_uninit(&al->al_rgd_gh); - return error; } @@ -1534,15 +1517,12 @@ int gfs2_ea_dealloc(struct gfs2_inode *ip) error = ea_dealloc_block(ip); - out_rindex: +out_rindex: gfs2_glock_dq_uninit(&al->al_ri_gh); - - out_quota: +out_quota: gfs2_quota_unhold(ip); - - out_alloc: +out_alloc: gfs2_alloc_put(ip); - return error; } diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index fac271f390bf..1c916fedc04b 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -2179,9 +2179,8 @@ static int dump_glock(struct gfs2_glock *gl) error = 0; - out: +out: spin_unlock(&gl->gl_spin); - return error; } diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index fb918c7de655..e60f95cae6c5 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -76,7 +76,7 @@ int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent) sdp->sd_args.ar_localcaching = 1; } - out: +out: return error; } diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index 2d81d90db097..1f15b6e8b2cf 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -437,7 +437,7 @@ static int hold_null_lock(struct gdlm_lock *lp) gdlm_delete_lp(lpn); lpn = NULL; } - out: +out: lp->hold_null = lpn; return error; } diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c index f279385774b7..82ac00af84a3 100644 --- a/fs/gfs2/locking/dlm/mount.c +++ b/fs/gfs2/locking/dlm/mount.c @@ -164,13 +164,13 @@ static int gdlm_mount(char *table_name, char *host_data, lockstruct->ls_lvb_size = GDLM_LVB_SIZE; return 0; - out_kobj: +out_kobj: gdlm_kobject_release(ls); - out_thread: +out_thread: gdlm_release_threads(ls); - out_free: +out_free: kfree(ls); - out: +out: return error; } @@ -194,7 +194,7 @@ static void gdlm_unmount(lm_lockspace_t *lockspace) rv = gdlm_release_all_locks(ls); if (rv) log_info("gdlm_unmount: %d stray locks freed", rv); - out: +out: kfree(ls); } diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c index 0b4be102e170..a782246d666b 100644 --- a/fs/gfs2/locking/dlm/thread.c +++ b/fs/gfs2/locking/dlm/thread.c @@ -206,7 +206,7 @@ static void process_complete(struct gdlm_lock *lp) if (lp->lksb.sb_flags & DLM_SBF_DEMOTED) set_bit(LFL_NOCACHE, &lp->flags); - out: +out: /* * This is an internal lock_dlm lock */ diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 03850b64c072..3f6da00e2f59 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -756,7 +756,7 @@ void gfs2_meta_ra(struct gfs2_glock *gl, uint64_t dblock, uint32_t extlen) break; } - out: +out: brelse(first_bh); } diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c index b66027827aaa..257c4a179dc6 100644 --- a/fs/gfs2/mount.c +++ b/fs/gfs2/mount.c @@ -203,11 +203,11 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount) return error; - need_value: +need_value: fs_info(sdp, "need value for option %s\n", o); return -EINVAL; - cant_remount: +cant_remount: fs_info(sdp, "can't remount with option %s\n", o); return -EINVAL; } diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index a1ba1ec8eef4..fa6ceffc7d82 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -81,31 +81,27 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) goto fail_gunlock; } - valid_gunlock: +valid_gunlock: gfs2_glock_dq_uninit(&d_gh); - - valid: +valid: dput(parent); return 1; - invalid_gunlock: +invalid_gunlock: gfs2_glock_dq_uninit(&d_gh); - - invalid: +invalid: if (inode && S_ISDIR(inode->i_mode)) { if (have_submounts(dentry)) goto valid; shrink_dcache_parent(dentry); } d_drop(dentry); - dput(parent); return 0; - fail_gunlock: +fail_gunlock: gfs2_glock_dq_uninit(&d_gh); - - fail: +fail: dput(parent); return 0; } diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 07a0c861ac41..53ce7816dc18 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -345,9 +345,8 @@ static int readdir_bad(struct file *file, void *dirent, filldir_t filldir) file->f_pos = offset; - out: +out: kfree(fdb); - return error; } diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 46f910e29bf0..d39314d5dd0a 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -173,9 +173,8 @@ static int init_names(struct gfs2_sbd *sdp, int silent) snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto); snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table); - out: +out: kfree(sb); - return error; } @@ -246,22 +245,17 @@ static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, fail_trans: gfs2_glock_put(sdp->sd_trans_gl); - fail_rename: gfs2_glock_put(sdp->sd_rename_gl); - fail_live: gfs2_glock_dq_uninit(&sdp->sd_live_gh); - fail_mount: gfs2_glock_dq_uninit(mount_gh); - fail: while (sdp->sd_glockd_num--) kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); kthread_stop(sdp->sd_scand_process); - return error; } @@ -451,25 +445,20 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) return 0; - fail_recoverd: +fail_recoverd: kthread_stop(sdp->sd_recoverd_process); - - fail_jinode_gh: +fail_jinode_gh: if (!sdp->sd_args.ar_spectator) gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); - - fail_journal_gh: +fail_journal_gh: if (!sdp->sd_args.ar_spectator) gfs2_glock_dq_uninit(&sdp->sd_journal_gh); - - fail_jindex: +fail_jindex: gfs2_jindex_free(sdp); if (jindex) gfs2_glock_dq_uninit(&ji_gh); - - fail: +fail: iput(sdp->sd_jindex); - return error; } @@ -534,14 +523,11 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) fail_qinode: iput(sdp->sd_quota_inode); - fail_rindex: gfs2_clear_rgrpd(sdp); iput(sdp->sd_rindex); - fail_statfs: iput(sdp->sd_statfs_inode); - fail_inum: iput(sdp->sd_inum_inode); fail_journal: @@ -628,27 +614,19 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo) return 0; - fail_qc_gh: +fail_qc_gh: gfs2_glock_dq_uninit(&sdp->sd_qc_gh); - - fail_ut_gh: - +fail_ut_gh: gfs2_glock_dq_uninit(&sdp->sd_sc_gh); - - fail_ir_gh: +fail_ir_gh: gfs2_glock_dq_uninit(&sdp->sd_ir_gh); - - fail_qc_i: +fail_qc_i: iput(sdp->sd_qc_inode); - - fail_ut_i: - +fail_ut_i: iput(sdp->sd_sc_inode); - - fail_ir_i: +fail_ir_i: iput(sdp->sd_ir_inode); - - fail: +fail: if (pn) iput(pn); return error; @@ -781,34 +759,26 @@ static int fill_super(struct super_block *sb, void *data, int silent) return 0; - fail_threads: +fail_threads: init_threads(sdp, UNDO); - - fail_per_node: +fail_per_node: init_per_node(sdp, UNDO); - - fail_inodes: +fail_inodes: init_inodes(sdp, UNDO); - - fail_sb: +fail_sb: init_sb(sdp, 0, UNDO); - - fail_locking: +fail_locking: init_locking(sdp, &mount_gh, UNDO); - - fail_lm: +fail_lm: gfs2_gl_hash_clear(sdp, WAIT); gfs2_lm_unmount(sdp); while (invalidate_inodes(sb)) yield(); - - fail_sys: +fail_sys: gfs2_sys_fs_del(sdp); - - fail: +fail: vfree(sdp); sb->s_fs_info = NULL; - return error; } @@ -852,6 +822,7 @@ static int fill_super_meta(struct super_block *sb, struct super_block *new, return error; } + static int set_bdev_super(struct super_block *s, void *data) { s->s_bdev = data; diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 1786a485acc5..bd9b9957f707 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -228,32 +228,25 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, out_end_trans: gfs2_trans_end(sdp); - out_ipres: if (alloc_required) gfs2_inplace_release(dip); - out_gunlock_q: if (alloc_required) gfs2_quota_unlock(dip); - out_alloc: if (alloc_required) gfs2_alloc_put(dip); - out_gunlock: gfs2_glock_dq_m(2, ghs); - out: gfs2_holder_uninit(ghs); gfs2_holder_uninit(ghs + 1); - if (!error) { atomic_inc(&inode->i_count); d_instantiate(dentry, inode); mark_inode_dirty(inode); } - return error; } @@ -491,13 +484,11 @@ static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) gfs2_trans_end(sdp); - out_gunlock: +out_gunlock: gfs2_glock_dq_m(2, ghs); - - out: +out: gfs2_holder_uninit(ghs); gfs2_holder_uninit(ghs + 1); - return error; } @@ -966,15 +957,12 @@ static int setattr_chown(struct inode *inode, struct iattr *attr) gfs2_quota_change(ip, ip->i_di.di_blocks, nuid, ngid); } - out_end_trans: +out_end_trans: gfs2_trans_end(sdp); - - out_gunlock_q: +out_gunlock_q: gfs2_quota_unlock(ip); - - out_alloc: +out_alloc: gfs2_alloc_put(ip); - return error; } @@ -1017,12 +1005,10 @@ static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) else error = gfs2_setattr_simple(ip, attr); - out: +out: gfs2_glock_dq_uninit(&i_gh); - if (!error) mark_inode_dirty(inode); - return error; } diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index 451f48d62e58..32ec8574ac8e 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -115,18 +115,14 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) gfs2_assert_warn(sdp, al->al_alloced); - out_trans: +out_trans: gfs2_trans_end(sdp); - - out_ipres: +out_ipres: gfs2_inplace_release(ip); - - out_gunlock_q: +out_gunlock_q: gfs2_quota_unlock(ip); - - out: +out: gfs2_alloc_put(ip); - return error; } diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index be87983a20a9..572b92eac367 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -105,7 +105,7 @@ static int qd_alloc(struct gfs2_sbd *sdp, int user, uint32_t id, return 0; - fail: +fail: kfree(qd); return error; } @@ -199,7 +199,7 @@ static int slot_get(struct gfs2_quota_data *qd) goto fail; - found: +found: for (b = 0; b < 8; b++) if (!(byte & (1 << b))) break; @@ -214,7 +214,7 @@ static int slot_get(struct gfs2_quota_data *qd) return 0; - fail: +fail: qd->qd_slot_count--; spin_unlock(&sdp->sd_quota_spin); return -ENOSPC; @@ -283,10 +283,9 @@ static int bh_get(struct gfs2_quota_data *qd) return 0; - fail_brelse: +fail_brelse: brelse(bh); - - fail: +fail: qd->qd_bh_count--; mutex_unlock(&sdp->sd_quota_mutex); return error; @@ -425,10 +424,9 @@ static int qdsb_get(struct gfs2_sbd *sdp, int user, uint32_t id, int create, return 0; - fail_slot: +fail_slot: slot_put(*qdp); - - fail: +fail: qd_put(*qdp); return error; } @@ -482,10 +480,9 @@ int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) qd++; } - out: +out: if (error) gfs2_quota_unhold(ip); - return error; } @@ -728,26 +725,21 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) error = 0; - out_end_trans: +out_end_trans: gfs2_trans_end(sdp); - - out_ipres: +out_ipres: if (nalloc) gfs2_inplace_release(ip); - - out_alloc: +out_alloc: if (nalloc) gfs2_alloc_put(ip); - - out_gunlock: +out_gunlock: gfs2_glock_dq_uninit(&i_gh); - - out: +out: while (qx--) gfs2_glock_dq_uninit(&ghs[qx]); kfree(ghs); gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); - return error; } @@ -764,7 +756,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, struct gfs2_quota_lvb *qlvb; file_ra_state_init(&ra_state, sdp->sd_quota_inode->i_mapping); - restart: +restart: error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh); if (error) return error; @@ -812,12 +804,10 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh, return 0; - fail_gunlock: +fail_gunlock: gfs2_glock_dq_uninit(&i_gh); - - fail: +fail: gfs2_glock_dq_uninit(q_gh); - return error; } @@ -919,7 +909,7 @@ void gfs2_quota_unlock(struct gfs2_inode *ip) qd_unlock(qda[x]); } - out: +out: gfs2_quota_unhold(ip); } @@ -1098,9 +1088,8 @@ int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, gfs2_glock_dq_uninit(&q_gh); - out: +out: qd_put(qd); - return error; } #endif /* 0 */ @@ -1202,7 +1191,7 @@ int gfs2_quota_init(struct gfs2_sbd *sdp) return 0; - fail: +fail: gfs2_quota_cleanup(sdp); return error; } diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index e93066f930c1..520266c2044b 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -535,7 +535,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp) error = gfs2_quota_init(sdp); if (error) - goto fail_unlinked; + goto fail; set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); @@ -543,9 +543,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp) return 0; - fail_unlinked: - - fail: +fail: t_gh.gh_flags |= GL_NOCACHE; gfs2_glock_dq_uninit(&t_gh); @@ -625,12 +623,10 @@ int gfs2_statfs_init(struct gfs2_sbd *sdp) brelse(l_bh); } - out_m_bh: +out_m_bh: brelse(m_bh); - - out: +out: gfs2_glock_dq_uninit(&gh); - return 0; } @@ -715,15 +711,12 @@ int gfs2_statfs_sync(struct gfs2_sbd *sdp) gfs2_trans_end(sdp); - out_bh2: +out_bh2: brelse(l_bh); - - out_bh: +out_bh: brelse(m_bh); - - out: +out: gfs2_glock_dq_uninit(&gh); - return error; } @@ -853,9 +846,8 @@ int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc) gfs2_glock_dq_uninit(&ri_gh); - out: +out: kfree(gha); - return error; } @@ -924,7 +916,7 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, if (error) gfs2_glock_dq_uninit(t_gh); - out: +out: while (!list_empty(&list)) { lfcc = list_entry(list.next, struct lfcc, list); list_del(&lfcc->list); @@ -932,7 +924,6 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, kfree(lfcc); } gfs2_glock_dq_uninit(&ji_gh); - return error; } diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index 3ffa88506c44..79199738c389 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -543,15 +543,15 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp) return 0; - fail_args: +fail_args: sysfs_remove_group(&sdp->sd_kobj, &args_group); - fail_counters: +fail_counters: sysfs_remove_group(&sdp->sd_kobj, &counters_group); - fail_lockstruct: +fail_lockstruct: sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); - fail_reg: +fail_reg: kobject_unregister(&sdp->sd_kobj); - fail: +fail: return error; } From cd915493fce912f1bd838ee1250737ecf33b8fae Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 12:49:07 -0400 Subject: [PATCH 225/292] [GFS2] Change all types to uX style This makes all fixed size types have consistent names. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 60 ++++++++-------- fs/gfs2/bmap.h | 4 +- fs/gfs2/dir.c | 124 ++++++++++++++++----------------- fs/gfs2/dir.h | 8 +-- fs/gfs2/eattr.c | 56 +++++++-------- fs/gfs2/eattr.h | 6 +- fs/gfs2/glock.c | 8 +-- fs/gfs2/glock.h | 6 +- fs/gfs2/incore.h | 72 +++++++++---------- fs/gfs2/inode.c | 20 +++--- fs/gfs2/lm_interface.h | 2 +- fs/gfs2/locking/dlm/lock.c | 8 +-- fs/gfs2/locking/dlm/lock_dlm.h | 14 ++-- fs/gfs2/locking/dlm/thread.c | 2 +- fs/gfs2/log.c | 18 ++--- fs/gfs2/lops.c | 18 ++--- fs/gfs2/meta_io.c | 18 ++--- fs/gfs2/meta_io.h | 10 +-- fs/gfs2/ops_address.c | 8 +-- fs/gfs2/ops_export.c | 12 ++-- fs/gfs2/ops_file.c | 10 +-- fs/gfs2/ops_inode.c | 12 ++-- fs/gfs2/ops_vm.c | 4 +- fs/gfs2/quota.c | 50 ++++++------- fs/gfs2/quota.h | 14 ++-- fs/gfs2/recovery.c | 16 ++--- fs/gfs2/recovery.h | 4 +- fs/gfs2/rgrp.c | 72 +++++++++---------- fs/gfs2/rgrp.h | 10 +-- fs/gfs2/super.c | 28 ++++---- fs/gfs2/super.h | 2 +- fs/gfs2/sys.c | 4 +- fs/gfs2/trans.c | 6 +- fs/gfs2/trans.h | 4 +- fs/gfs2/util.c | 2 +- fs/gfs2/util.h | 14 ++-- 36 files changed, 363 insertions(+), 363 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index bb597839c0c9..a97ad74d880c 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -38,8 +38,8 @@ struct metapath { }; typedef int (*block_call_t) (struct gfs2_inode *ip, struct buffer_head *dibh, - struct buffer_head *bh, uint64_t *top, - uint64_t *bottom, unsigned int height, + struct buffer_head *bh, u64 *top, + u64 *bottom, unsigned int height, void *data); struct strip_mine { @@ -58,7 +58,7 @@ struct strip_mine { */ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, - uint64_t block, struct page *page) + u64 block, struct page *page) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct inode *inode = &ip->i_inode; @@ -121,7 +121,7 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) { struct buffer_head *bh, *dibh; - uint64_t block = 0; + u64 block = 0; int isdir = gfs2_is_dir(ip); int error; @@ -161,7 +161,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); if (ip->i_di.di_size) { - *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) = + *(u64 *)(dibh->b_data + sizeof(struct gfs2_dinode)) = cpu_to_be64(block); ip->i_di.di_blocks++; } @@ -190,10 +190,10 @@ out: * Returns: the height the tree should be */ -static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size) +static unsigned int calc_tree_height(struct gfs2_inode *ip, u64 size) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); - uint64_t *arr; + u64 *arr; unsigned int max, height; if (ip->i_di.di_size > size) @@ -336,11 +336,11 @@ static int build_height(struct inode *inode, unsigned height) * */ -static void find_metapath(struct gfs2_inode *ip, uint64_t block, +static void find_metapath(struct gfs2_inode *ip, u64 block, struct metapath *mp) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); - uint64_t b = block; + u64 b = block; unsigned int i; for (i = ip->i_di.di_height; i--;) @@ -390,10 +390,10 @@ static inline u64 *metapointer(struct buffer_head *bh, int *boundary, static int lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, unsigned int height, struct metapath *mp, int create, - int *new, uint64_t *block) + int *new, u64 *block) { int boundary; - uint64_t *ptr = metapointer(bh, &boundary, height, mp); + u64 *ptr = metapointer(bh, &boundary, height, mp); if (*ptr) { *block = be64_to_cpu(*ptr); @@ -594,13 +594,13 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsi static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh, struct metapath *mp, unsigned int height, - uint64_t block, int first, block_call_t bc, + u64 block, int first, block_call_t bc, void *data) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *bh = NULL; - uint64_t *top, *bottom; - uint64_t bn; + u64 *top, *bottom; + u64 bn; int error; int mh_size = sizeof(struct gfs2_meta_header); @@ -617,10 +617,10 @@ static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh, if (error) return error; - top = (uint64_t *)(bh->b_data + mh_size) + + top = (u64 *)(bh->b_data + mh_size) + ((first) ? mp->mp_list[height] : 0); - bottom = (uint64_t *)(bh->b_data + mh_size) + sdp->sd_inptrs; + bottom = (u64 *)(bh->b_data + mh_size) + sdp->sd_inptrs; } error = bc(ip, dibh, bh, top, bottom, height, data); @@ -659,15 +659,15 @@ out: */ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, - struct buffer_head *bh, uint64_t *top, uint64_t *bottom, + struct buffer_head *bh, u64 *top, u64 *bottom, unsigned int height, void *data) { struct strip_mine *sm = data; struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_rgrp_list rlist; - uint64_t bn, bstart; - uint32_t blen; - uint64_t *p; + u64 bn, bstart; + u32 blen; + u64 *p; unsigned int rg_blocks = 0; int metadata; unsigned int revokes = 0; @@ -804,7 +804,7 @@ out: * Returns: errno */ -static int do_grow(struct gfs2_inode *ip, uint64_t size) +static int do_grow(struct gfs2_inode *ip, u64 size) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al; @@ -949,7 +949,7 @@ unlock: return err; } -static int trunc_start(struct gfs2_inode *ip, uint64_t size) +static int trunc_start(struct gfs2_inode *ip, u64 size) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *dibh; @@ -974,7 +974,7 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size) error = 1; } else { - if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1)) + if (size & (u64)(sdp->sd_sb.sb_bsize - 1)) error = gfs2_block_truncate_page(ip->i_inode.i_mapping); if (!error) { @@ -993,10 +993,10 @@ out: return error; } -static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size) +static int trunc_dealloc(struct gfs2_inode *ip, u64 size) { unsigned int height = ip->i_di.di_height; - uint64_t lblock; + u64 lblock; struct metapath mp; int error; @@ -1076,7 +1076,7 @@ out: * Returns: errno */ -static int do_shrink(struct gfs2_inode *ip, uint64_t size) +static int do_shrink(struct gfs2_inode *ip, u64 size) { int error; @@ -1104,7 +1104,7 @@ static int do_shrink(struct gfs2_inode *ip, uint64_t size) * Returns: errno */ -int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size) +int gfs2_truncatei(struct gfs2_inode *ip, u64 size) { int error; @@ -1172,12 +1172,12 @@ void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, * Returns: errno */ -int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, +int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset, unsigned int len, int *alloc_required) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); - uint64_t lblock, lblock_stop, dblock; - uint32_t extlen; + u64 lblock, lblock_stop, dblock; + u32 extlen; int new = 0; int error = 0; diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index ab0157c5ed0e..cb3b624fea31 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -14,14 +14,14 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page); int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *boundary); int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen); -int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size); +int gfs2_truncatei(struct gfs2_inode *ip, u64 size); int gfs2_truncatei_resume(struct gfs2_inode *ip); int gfs2_file_dealloc(struct gfs2_inode *ip); void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, unsigned int *data_blocks, unsigned int *ind_blocks); -int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, +int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset, unsigned int len, int *alloc_required); #endif /* __BMAP_DOT_H__ */ diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 59d0cbcaecff..2023dc4ea306 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -78,15 +78,15 @@ #define IS_LEAF 1 /* Hashed (leaf) directory */ #define IS_DINODE 2 /* Linear (stuffed dinode block) directory */ -#define gfs2_disk_hash2offset(h) (((uint64_t)(h)) >> 1) -#define gfs2_dir_offset2hash(p) ((uint32_t)(((uint64_t)(p)) << 1)) +#define gfs2_disk_hash2offset(h) (((u64)(h)) >> 1) +#define gfs2_dir_offset2hash(p) ((u32)(((u64)(p)) << 1)) typedef int (*leaf_call_t) (struct gfs2_inode *dip, - uint32_t index, uint32_t len, uint64_t leaf_no, + u32 index, u32 len, u64 leaf_no, void *data); -int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, uint64_t block, +int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, u64 block, struct buffer_head **bhp) { struct buffer_head *bh; @@ -99,7 +99,7 @@ int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, uint64_t block, return 0; } -static int gfs2_dir_get_existing_buffer(struct gfs2_inode *ip, uint64_t block, +static int gfs2_dir_get_existing_buffer(struct gfs2_inode *ip, u64 block, struct buffer_head **bhp) { struct buffer_head *bh; @@ -151,12 +151,12 @@ static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf, * Returns: The number of bytes correctly written or error code */ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, - uint64_t offset, unsigned int size) + u64 offset, unsigned int size) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *dibh; - uint64_t lblock, dblock; - uint32_t extlen = 0; + u64 lblock, dblock; + u32 extlen = 0; unsigned int o; int copied = 0; int error = 0; @@ -271,11 +271,11 @@ static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf, * Returns: The amount of data actually copied or the error */ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, - uint64_t offset, unsigned int size) + u64 offset, unsigned int size) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); - uint64_t lblock, dblock; - uint32_t extlen = 0; + u64 lblock, dblock; + u32 extlen = 0; unsigned int o; int copied = 0; int error = 0; @@ -581,7 +581,7 @@ static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, { struct gfs2_dirent *tmp, *cur; char *bh_end; - uint16_t cur_rec_len; + u16 cur_rec_len; cur = *dent; bh_end = bh->b_data + bh->b_size; @@ -630,7 +630,7 @@ static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh, struct gfs2_dirent *prev, struct gfs2_dirent *cur) { - uint16_t cur_rec_len, prev_rec_len; + u16 cur_rec_len, prev_rec_len; if (!cur->de_inum.no_addr) { gfs2_consist_inode(dip); @@ -698,7 +698,7 @@ static struct gfs2_dirent *gfs2_dirent_alloc(struct inode *inode, return gfs2_init_dirent(inode, dent, name, bh); } -static int get_leaf(struct gfs2_inode *dip, uint64_t leaf_no, +static int get_leaf(struct gfs2_inode *dip, u64 leaf_no, struct buffer_head **bhp) { int error; @@ -721,16 +721,16 @@ static int get_leaf(struct gfs2_inode *dip, uint64_t leaf_no, * Returns: 0 on success, error code otherwise */ -static int get_leaf_nr(struct gfs2_inode *dip, uint32_t index, - uint64_t *leaf_out) +static int get_leaf_nr(struct gfs2_inode *dip, u32 index, + u64 *leaf_out) { - uint64_t leaf_no; + u64 leaf_no; int error; error = gfs2_dir_read_data(dip, (char *)&leaf_no, - index * sizeof(uint64_t), - sizeof(uint64_t)); - if (error != sizeof(uint64_t)) + index * sizeof(u64), + sizeof(u64)); + if (error != sizeof(u64)) return (error < 0) ? error : -EIO; *leaf_out = be64_to_cpu(leaf_no); @@ -738,10 +738,10 @@ static int get_leaf_nr(struct gfs2_inode *dip, uint32_t index, return 0; } -static int get_first_leaf(struct gfs2_inode *dip, uint32_t index, +static int get_first_leaf(struct gfs2_inode *dip, u32 index, struct buffer_head **bh_out) { - uint64_t leaf_no; + u64 leaf_no; int error; error = get_leaf_nr(dip, index, &leaf_no); @@ -847,8 +847,8 @@ static int dir_make_exhash(struct inode *inode) struct buffer_head *bh, *dibh; struct gfs2_leaf *leaf; int y; - uint32_t x; - uint64_t *lp, bn; + u32 x; + u64 *lp, bn; int error; error = gfs2_meta_inode_buffer(dip, &dibh); @@ -904,7 +904,7 @@ static int dir_make_exhash(struct inode *inode) gfs2_trans_add_bh(dip->i_gl, dibh, 1); gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); - lp = (uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)); + lp = (u64 *)(dibh->b_data + sizeof(struct gfs2_dinode)); for (x = sdp->sd_hash_ptrs; x--; lp++) *lp = cpu_to_be64(bn); @@ -939,9 +939,9 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) struct buffer_head *nbh, *obh, *dibh; struct gfs2_leaf *nleaf, *oleaf; struct gfs2_dirent *dent = NULL, *prev = NULL, *next = NULL, *new; - uint32_t start, len, half_len, divider; - uint64_t bn, *lp, leaf_no; - uint32_t index; + u32 start, len, half_len, divider; + u64 bn, *lp, leaf_no; + u32 index; int x, moved = 0; int error; @@ -985,14 +985,14 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name) /* Change the pointers. Don't bother distinguishing stuffed from non-stuffed. This code is complicated enough already. */ - lp = kmalloc(half_len * sizeof(uint64_t), GFP_NOFS | __GFP_NOFAIL); + lp = kmalloc(half_len * sizeof(u64), GFP_NOFS | __GFP_NOFAIL); /* Change the pointers */ for (x = 0; x < half_len; x++) lp[x] = cpu_to_be64(bn); - error = gfs2_dir_write_data(dip, (char *)lp, start * sizeof(uint64_t), - half_len * sizeof(uint64_t)); - if (error != half_len * sizeof(uint64_t)) { + error = gfs2_dir_write_data(dip, (char *)lp, start * sizeof(u64), + half_len * sizeof(u64)); + if (error != half_len * sizeof(u64)) { if (error >= 0) error = -EIO; goto fail_lpfree; @@ -1077,15 +1077,15 @@ static int dir_double_exhash(struct gfs2_inode *dip) { struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct buffer_head *dibh; - uint32_t hsize; - uint64_t *buf; - uint64_t *from, *to; - uint64_t block; + u32 hsize; + u64 *buf; + u64 *from, *to; + u64 block; int x; int error = 0; hsize = 1 << dip->i_di.di_depth; - if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { + if (hsize * sizeof(u64) != dip->i_di.di_size) { gfs2_consist_inode(dip); return -EIO; } @@ -1105,7 +1105,7 @@ static int dir_double_exhash(struct gfs2_inode *dip) } from = buf; - to = (uint64_t *)((char *)buf + sdp->sd_hash_bsize); + to = (u64 *)((char *)buf + sdp->sd_hash_bsize); for (x = sdp->sd_hash_ptrs; x--; from++) { *to++ = *from; /* No endianess worries */ @@ -1153,7 +1153,7 @@ fail: static int compare_dents(const void *a, const void *b) { struct gfs2_dirent *dent_a, *dent_b; - uint32_t hash_a, hash_b; + u32 hash_a, hash_b; int ret = 0; dent_a = *(struct gfs2_dirent **)a; @@ -1201,14 +1201,14 @@ static int compare_dents(const void *a, const void *b) * Returns: errno, >0 on exception from filldir */ -static int do_filldir_main(struct gfs2_inode *dip, uint64_t *offset, +static int do_filldir_main(struct gfs2_inode *dip, u64 *offset, void *opaque, gfs2_filldir_t filldir, - const struct gfs2_dirent **darr, uint32_t entries, + const struct gfs2_dirent **darr, u32 entries, int *copied) { const struct gfs2_dirent *dent, *dent_next; struct gfs2_inum inum; - uint64_t off, off_next; + u64 off, off_next; unsigned int x, y; int run = 0; int error = 0; @@ -1346,21 +1346,21 @@ out: * Returns: errno */ -static int dir_e_read(struct inode *inode, uint64_t *offset, void *opaque, +static int dir_e_read(struct inode *inode, u64 *offset, void *opaque, gfs2_filldir_t filldir) { struct gfs2_inode *dip = GFS2_I(inode); struct gfs2_sbd *sdp = GFS2_SB(inode); - uint32_t hsize, len = 0; - uint32_t ht_offset, lp_offset, ht_offset_cur = -1; - uint32_t hash, index; - uint64_t *lp; + u32 hsize, len = 0; + u32 ht_offset, lp_offset, ht_offset_cur = -1; + u32 hash, index; + u64 *lp; int copied = 0; int error = 0; unsigned depth = 0; hsize = 1 << dip->i_di.di_depth; - if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { + if (hsize * sizeof(u64) != dip->i_di.di_size) { gfs2_consist_inode(dip); return -EIO; } @@ -1378,7 +1378,7 @@ static int dir_e_read(struct inode *inode, uint64_t *offset, void *opaque, if (ht_offset_cur != ht_offset) { error = gfs2_dir_read_data(dip, (char *)lp, - ht_offset * sizeof(uint64_t), + ht_offset * sizeof(u64), sdp->sd_hash_bsize); if (error != sdp->sd_hash_bsize) { if (error >= 0) @@ -1405,7 +1405,7 @@ out: return error; } -int gfs2_dir_read(struct inode *inode, uint64_t *offset, void *opaque, +int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque, gfs2_filldir_t filldir) { struct gfs2_inode *dip = GFS2_I(inode); @@ -1725,15 +1725,15 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct buffer_head *bh; struct gfs2_leaf *leaf; - uint32_t hsize, len; - uint32_t ht_offset, lp_offset, ht_offset_cur = -1; - uint32_t index = 0; - uint64_t *lp; - uint64_t leaf_no; + u32 hsize, len; + u32 ht_offset, lp_offset, ht_offset_cur = -1; + u32 index = 0; + u64 *lp; + u64 leaf_no; int error = 0; hsize = 1 << dip->i_di.di_depth; - if (hsize * sizeof(uint64_t) != dip->i_di.di_size) { + if (hsize * sizeof(u64) != dip->i_di.di_size) { gfs2_consist_inode(dip); return -EIO; } @@ -1748,7 +1748,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) if (ht_offset_cur != ht_offset) { error = gfs2_dir_read_data(dip, (char *)lp, - ht_offset * sizeof(uint64_t), + ht_offset * sizeof(u64), sdp->sd_hash_bsize); if (error != sdp->sd_hash_bsize) { if (error >= 0) @@ -1798,17 +1798,17 @@ out: * Returns: errno */ -static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, - uint64_t leaf_no, void *data) +static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len, + u64 leaf_no, void *data) { struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct gfs2_leaf *tmp_leaf; struct gfs2_rgrp_list rlist; struct buffer_head *bh, *dibh; - uint64_t blk, nblk; + u64 blk, nblk; unsigned int rg_blocks = 0, l_blocks = 0; char *ht; - unsigned int x, size = len * sizeof(uint64_t); + unsigned int x, size = len * sizeof(u64); int error; memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); @@ -1874,7 +1874,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, dip->i_di.di_blocks--; } - error = gfs2_dir_write_data(dip, ht, index * sizeof(uint64_t), size); + error = gfs2_dir_write_data(dip, ht, index * sizeof(u64), size); if (error != size) { if (error >= 0) error = -EIO; diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h index 366a5571648f..f1f83faa36ec 100644 --- a/fs/gfs2/dir.h +++ b/fs/gfs2/dir.h @@ -24,7 +24,7 @@ typedef int (*gfs2_filldir_t) (void *opaque, const char *name, unsigned int length, - uint64_t offset, + u64 offset, struct gfs2_inum *inum, unsigned int type); int gfs2_dir_search(struct inode *dir, const struct qstr *filename, @@ -32,7 +32,7 @@ int gfs2_dir_search(struct inode *dir, const struct qstr *filename, int gfs2_dir_add(struct inode *inode, const struct qstr *filename, const struct gfs2_inum *inum, unsigned int type); int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *filename); -int gfs2_dir_read(struct inode *inode, uint64_t * offset, void *opaque, +int gfs2_dir_read(struct inode *inode, u64 * offset, void *opaque, gfs2_filldir_t filldir); int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, struct gfs2_inum *new_inum, unsigned int new_type); @@ -41,10 +41,10 @@ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip); int gfs2_diradd_alloc_required(struct inode *dir, const struct qstr *filename); -int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, uint64_t block, +int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, u64 block, struct buffer_head **bhp); -static inline uint32_t gfs2_disk_hash(const char *data, int len) +static inline u32 gfs2_disk_hash(const char *data, int len) { return crc32_le(0xFFFFFFFF, data, len) ^ 0xFFFFFFFF; } diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 5a56e6568622..f6b5e306a6c8 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -115,7 +115,7 @@ fail: static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) { struct buffer_head *bh, *eabh; - uint64_t *eablk, *end; + u64 *eablk, *end; int error; error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, @@ -133,11 +133,11 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) goto out; } - eablk = (uint64_t *)(bh->b_data + sizeof(struct gfs2_meta_header)); + eablk = (u64 *)(bh->b_data + sizeof(struct gfs2_meta_header)); end = eablk + GFS2_SB(&ip->i_inode)->sd_inptrs; for (; eablk < end; eablk++) { - uint64_t bn; + u64 bn; if (!*eablk) break; @@ -235,8 +235,8 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, struct gfs2_rgrpd *rgd; struct gfs2_holder rg_gh; struct buffer_head *dibh; - uint64_t *dataptrs, bn = 0; - uint64_t bstart = 0; + u64 *dataptrs, bn = 0; + u64 bstart = 0; unsigned int blen = 0; unsigned int blks = 0; unsigned int x; @@ -296,7 +296,7 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, gfs2_free_meta(ip, bstart, blen); if (prev && !leave) { - uint32_t len; + u32 len; len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea); prev->ea_rec_len = cpu_to_be32(len); @@ -459,7 +459,7 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, struct buffer_head **bh; unsigned int amount = GFS2_EA_DATA_LEN(ea); unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); - uint64_t *dataptrs = GFS2_EA2DATAPTRS(ea); + u64 *dataptrs = GFS2_EA2DATAPTRS(ea); unsigned int x; int error = 0; @@ -601,7 +601,7 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_ea_header *ea; - uint64_t block; + u64 block; block = gfs2_alloc_meta(ip); @@ -649,7 +649,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, ea->ea_num_ptrs = 0; memcpy(GFS2_EA2DATA(ea), er->er_data, er->er_data_len); } else { - uint64_t *dataptr = GFS2_EA2DATAPTRS(ea); + u64 *dataptr = GFS2_EA2DATAPTRS(ea); const char *data = er->er_data; unsigned int data_len = er->er_data_len; unsigned int copy; @@ -658,7 +658,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, ea->ea_num_ptrs = DIV_ROUND_UP(er->er_data_len, sdp->sd_jbsize); for (x = 0; x < ea->ea_num_ptrs; x++) { struct buffer_head *bh; - uint64_t block; + u64 block; int mh_size = sizeof(struct gfs2_meta_header); block = gfs2_alloc_meta(ip); @@ -676,7 +676,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, memset(bh->b_data + mh_size + copy, 0, sdp->sd_jbsize - copy); - *dataptr++ = cpu_to_be64((uint64_t)bh->b_blocknr); + *dataptr++ = cpu_to_be64((u64)bh->b_blocknr); data += copy; data_len -= copy; @@ -792,10 +792,10 @@ static int ea_init(struct gfs2_inode *ip, struct gfs2_ea_request *er) static struct gfs2_ea_header *ea_split_ea(struct gfs2_ea_header *ea) { - uint32_t ea_size = GFS2_EA_SIZE(ea); + u32 ea_size = GFS2_EA_SIZE(ea); struct gfs2_ea_header *new = (struct gfs2_ea_header *)((char *)ea + ea_size); - uint32_t new_size = GFS2_EA_REC_LEN(ea) - ea_size; + u32 new_size = GFS2_EA_REC_LEN(ea) - ea_size; int last = ea->ea_flags & GFS2_EAFLAG_LAST; ea->ea_rec_len = cpu_to_be32(ea_size); @@ -812,7 +812,7 @@ static void ea_set_remove_stuffed(struct gfs2_inode *ip, { struct gfs2_ea_header *ea = el->el_ea; struct gfs2_ea_header *prev = el->el_prev; - uint32_t len; + u32 len; gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1); @@ -953,12 +953,12 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct buffer_head *indbh, *newbh; - uint64_t *eablk; + u64 *eablk; int error; int mh_size = sizeof(struct gfs2_meta_header); if (ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT) { - uint64_t *end; + u64 *end; error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_START | DIO_WAIT, &indbh); @@ -970,7 +970,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, goto out; } - eablk = (uint64_t *)(indbh->b_data + mh_size); + eablk = (u64 *)(indbh->b_data + mh_size); end = eablk + sdp->sd_inptrs; for (; eablk < end; eablk++) @@ -984,7 +984,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, gfs2_trans_add_bh(ip->i_gl, indbh, 1); } else { - uint64_t blk; + u64 blk; blk = gfs2_alloc_meta(ip); @@ -993,7 +993,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); gfs2_buffer_clear_tail(indbh, mh_size); - eablk = (uint64_t *)(indbh->b_data + mh_size); + eablk = (u64 *)(indbh->b_data + mh_size); *eablk = cpu_to_be64(ip->i_di.di_eattr); ip->i_di.di_eattr = blk; ip->i_di.di_flags |= GFS2_DIF_EA_INDIRECT; @@ -1006,7 +1006,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, if (error) goto out; - *eablk = cpu_to_be64((uint64_t)newbh->b_blocknr); + *eablk = cpu_to_be64((u64)newbh->b_blocknr); error = ea_write(ip, GFS2_EA_BH2FIRST(newbh), er); brelse(newbh); if (error) @@ -1140,7 +1140,7 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el) gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1); if (prev) { - uint32_t len; + u32 len; len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea); prev->ea_rec_len = cpu_to_be32(len); @@ -1225,7 +1225,7 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, struct buffer_head **bh; unsigned int amount = GFS2_EA_DATA_LEN(ea); unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); - uint64_t *dataptrs = GFS2_EA2DATAPTRS(ea); + u64 *dataptrs = GFS2_EA2DATAPTRS(ea); unsigned int x; int error; @@ -1325,9 +1325,9 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_rgrp_list rlist; struct buffer_head *indbh, *dibh; - uint64_t *eablk, *end; + u64 *eablk, *end; unsigned int rg_blocks = 0; - uint64_t bstart = 0; + u64 bstart = 0; unsigned int blen = 0; unsigned int blks = 0; unsigned int x; @@ -1345,11 +1345,11 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) goto out; } - eablk = (uint64_t *)(indbh->b_data + sizeof(struct gfs2_meta_header)); + eablk = (u64 *)(indbh->b_data + sizeof(struct gfs2_meta_header)); end = eablk + sdp->sd_inptrs; for (; eablk < end; eablk++) { - uint64_t bn; + u64 bn; if (!*eablk) break; @@ -1390,12 +1390,12 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) gfs2_trans_add_bh(ip->i_gl, indbh, 1); - eablk = (uint64_t *)(indbh->b_data + sizeof(struct gfs2_meta_header)); + eablk = (u64 *)(indbh->b_data + sizeof(struct gfs2_meta_header)); bstart = 0; blen = 0; for (; eablk < end; eablk++) { - uint64_t bn; + u64 bn; if (!*eablk) break; diff --git a/fs/gfs2/eattr.h b/fs/gfs2/eattr.h index 7b0291f99fd9..85c70c335c59 100644 --- a/fs/gfs2/eattr.h +++ b/fs/gfs2/eattr.h @@ -16,7 +16,7 @@ #define GFS2_EA_SIZE(ea) \ ALIGN(sizeof(struct gfs2_ea_header) + (ea)->ea_name_len + \ ((GFS2_EA_IS_STUFFED(ea)) ? GFS2_EA_DATA_LEN(ea) : \ - (sizeof(uint64_t) * (ea)->ea_num_ptrs)), 8) + (sizeof(u64) * (ea)->ea_num_ptrs)), 8) #define GFS2_EA_IS_STUFFED(ea) (!(ea)->ea_num_ptrs) #define GFS2_EA_IS_LAST(ea) ((ea)->ea_flags & GFS2_EAFLAG_LAST) @@ -26,13 +26,13 @@ ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + (er)->er_data_len, 8) #define GFS2_EAREQ_SIZE_UNSTUFFED(sdp, er) \ ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + \ - sizeof(uint64_t) * DIV_ROUND_UP((er)->er_data_len, (sdp)->sd_jbsize), 8) + sizeof(u64) * DIV_ROUND_UP((er)->er_data_len, (sdp)->sd_jbsize), 8) #define GFS2_EA2NAME(ea) ((char *)((struct gfs2_ea_header *)(ea) + 1)) #define GFS2_EA2DATA(ea) (GFS2_EA2NAME(ea) + (ea)->ea_name_len) #define GFS2_EA2DATAPTRS(ea) \ -((uint64_t *)(GFS2_EA2NAME(ea) + ALIGN((ea)->ea_name_len, 8))) +((u64 *)(GFS2_EA2NAME(ea) + ALIGN((ea)->ea_name_len, 8))) #define GFS2_EA2NEXT(ea) \ ((struct gfs2_ea_header *)((char *)(ea) + GFS2_EA_REC_LEN(ea))) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 1c916fedc04b..f2edc8b76121 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -87,7 +87,7 @@ static unsigned int gl_hash(const struct lm_lockname *name) { unsigned int h; - h = jhash(&name->ln_number, sizeof(uint64_t), 0); + h = jhash(&name->ln_number, sizeof(u64), 0); h = jhash(&name->ln_type, sizeof(unsigned int), h); h &= GFS2_GL_HASH_MASK; @@ -255,7 +255,7 @@ static struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, * Returns: errno */ -int gfs2_glock_get(struct gfs2_sbd *sdp, uint64_t number, +int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, const struct gfs2_glock_operations *glops, int create, struct gfs2_glock **glp) { @@ -1415,7 +1415,7 @@ void gfs2_glock_dq_uninit(struct gfs2_holder *gh) * Returns: errno */ -int gfs2_glock_nq_num(struct gfs2_sbd *sdp, uint64_t number, +int gfs2_glock_nq_num(struct gfs2_sbd *sdp, u64 number, const struct gfs2_glock_operations *glops, unsigned int state, int flags, struct gfs2_holder *gh) { @@ -1613,7 +1613,7 @@ void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs) * Returns: errno */ -void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number, +void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, u64 number, const struct gfs2_glock_operations *glops, unsigned int state, int flags) { diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 1a90a1983beb..4762cdb04f64 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -74,7 +74,7 @@ static inline int gfs2_glock_is_blocking(struct gfs2_glock *gl) } int gfs2_glock_get(struct gfs2_sbd *sdp, - uint64_t number, const struct gfs2_glock_operations *glops, + u64 number, const struct gfs2_glock_operations *glops, int create, struct gfs2_glock **glp); void gfs2_glock_hold(struct gfs2_glock *gl); int gfs2_glock_put(struct gfs2_glock *gl); @@ -96,14 +96,14 @@ int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time); void gfs2_glock_dq_uninit(struct gfs2_holder *gh); int gfs2_glock_nq_num(struct gfs2_sbd *sdp, - uint64_t number, const struct gfs2_glock_operations *glops, + u64 number, const struct gfs2_glock_operations *glops, unsigned int state, int flags, struct gfs2_holder *gh); int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs); void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs); void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs); -void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number, +void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, u64 number, const struct gfs2_glock_operations *glops, unsigned int state, int flags); void gfs2_glock_inode_squish(struct inode *inode); diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 06f5ec6ebf7f..407afd18fa2e 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -60,9 +60,9 @@ struct gfs2_log_element { struct gfs2_bitmap { struct buffer_head *bi_bh; char *bi_clone; - uint32_t bi_offset; - uint32_t bi_start; - uint32_t bi_len; + u32 bi_offset; + u32 bi_start; + u32 bi_len; }; struct gfs2_rgrpd { @@ -72,14 +72,14 @@ struct gfs2_rgrpd { struct gfs2_glock *rd_gl; /* Glock for this rgrp */ struct gfs2_rindex rd_ri; struct gfs2_rgrp rd_rg; - uint64_t rd_rg_vn; + u64 rd_rg_vn; struct gfs2_bitmap *rd_bits; unsigned int rd_bh_count; struct mutex rd_mutex; - uint32_t rd_free_clone; + u32 rd_free_clone; struct gfs2_log_element rd_le; - uint32_t rd_last_alloc_data; - uint32_t rd_last_alloc_meta; + u32 rd_last_alloc_data; + u32 rd_last_alloc_meta; struct gfs2_sbd *rd_sbd; }; @@ -185,7 +185,7 @@ struct gfs2_glock { char *gl_lvb; atomic_t gl_lvb_count; - uint64_t gl_vn; + u64 gl_vn; unsigned long gl_stamp; void *gl_object; @@ -232,14 +232,14 @@ struct gfs2_inode { unsigned long i_flags; /* GIF_... */ - uint64_t i_vn; + u64 i_vn; struct gfs2_dinode i_di; /* To be replaced by ref to block */ struct gfs2_glock *i_gl; /* Move into i_gh? */ struct gfs2_holder i_iopen_gh; struct gfs2_holder i_gh; /* for prepare/commit_write only */ struct gfs2_alloc i_alloc; - uint64_t i_last_rg_alloc; + u64 i_last_rg_alloc; spinlock_t i_spin; struct rw_semaphore i_rw_mutex; @@ -277,12 +277,12 @@ struct gfs2_file { struct gfs2_revoke { struct gfs2_log_element rv_le; - uint64_t rv_blkno; + u64 rv_blkno; }; struct gfs2_revoke_replay { struct list_head rr_list; - uint64_t rr_blkno; + u64 rr_blkno; unsigned int rr_where; }; @@ -304,11 +304,11 @@ struct gfs2_quota_data { struct list_head qd_list; unsigned int qd_count; - uint32_t qd_id; + u32 qd_id; unsigned long qd_flags; /* QDF_... */ - int64_t qd_change; - int64_t qd_change_sync; + s64 qd_change; + s64 qd_change_sync; unsigned int qd_slot; unsigned int qd_slot_count; @@ -320,7 +320,7 @@ struct gfs2_quota_data { struct gfs2_glock *qd_gl; struct gfs2_quota_lvb qd_qb; - uint64_t qd_sync_gen; + u64 qd_sync_gen; unsigned long qd_last_warn; unsigned long qd_last_touched; }; @@ -358,7 +358,7 @@ struct gfs2_ail { struct list_head ai_ail1_list; struct list_head ai_ail2_list; - uint64_t ai_sync_gen; + u64 ai_sync_gen; }; struct gfs2_jdesc { @@ -466,20 +466,20 @@ struct gfs2_sbd { /* Constants computed on mount */ - uint32_t sd_fsb2bb; - uint32_t sd_fsb2bb_shift; - uint32_t sd_diptrs; /* Number of pointers in a dinode */ - uint32_t sd_inptrs; /* Number of pointers in a indirect block */ - uint32_t sd_jbsize; /* Size of a journaled data block */ - uint32_t sd_hash_bsize; /* sizeof(exhash block) */ - uint32_t sd_hash_bsize_shift; - uint32_t sd_hash_ptrs; /* Number of pointers in a hash block */ - uint32_t sd_qc_per_block; - uint32_t sd_max_dirres; /* Max blocks needed to add a directory entry */ - uint32_t sd_max_height; /* Max height of a file's metadata tree */ - uint64_t sd_heightsize[GFS2_MAX_META_HEIGHT]; - uint32_t sd_max_jheight; /* Max height of journaled file's meta tree */ - uint64_t sd_jheightsize[GFS2_MAX_META_HEIGHT]; + u32 sd_fsb2bb; + u32 sd_fsb2bb_shift; + u32 sd_diptrs; /* Number of pointers in a dinode */ + u32 sd_inptrs; /* Number of pointers in a indirect block */ + u32 sd_jbsize; /* Size of a journaled data block */ + u32 sd_hash_bsize; /* sizeof(exhash block) */ + u32 sd_hash_bsize_shift; + u32 sd_hash_ptrs; /* Number of pointers in a hash block */ + u32 sd_qc_per_block; + u32 sd_max_dirres; /* Max blocks needed to add a directory entry */ + u32 sd_max_height; /* Max height of a file's metadata tree */ + u64 sd_heightsize[GFS2_MAX_META_HEIGHT]; + u32 sd_max_jheight; /* Max height of journaled file's meta tree */ + u64 sd_jheightsize[GFS2_MAX_META_HEIGHT]; struct gfs2_args sd_args; /* Mount arguments */ struct gfs2_tune sd_tune; /* Filesystem tuning structure */ @@ -522,7 +522,7 @@ struct gfs2_sbd { /* Resource group stuff */ - uint64_t sd_rindex_vn; + u64 sd_rindex_vn; spinlock_t sd_rindex_spin; struct mutex sd_rindex_mutex; struct list_head sd_rindex_list; @@ -567,7 +567,7 @@ struct gfs2_sbd { unsigned int sd_quota_chunks; unsigned char **sd_quota_bitmap; - uint64_t sd_quota_sync_gen; + u64 sd_quota_sync_gen; unsigned long sd_quota_sync_time; /* Log stuff */ @@ -595,7 +595,7 @@ struct gfs2_sbd { unsigned int sd_log_blks_free; struct mutex sd_log_reserve_mutex; - uint64_t sd_log_sequence; + u64 sd_log_sequence; unsigned int sd_log_head; unsigned int sd_log_tail; int sd_log_idle; @@ -605,11 +605,11 @@ struct gfs2_sbd { struct list_head sd_log_flush_list; unsigned int sd_log_flush_head; - uint64_t sd_log_flush_wrapped; + u64 sd_log_flush_wrapped; struct list_head sd_ail1_list; struct list_head sd_ail2_list; - uint64_t sd_ail_sync_gen; + u64 sd_ail_sync_gen; /* Replay stuff */ diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 1aaaaa1cc8c3..f683a400b006 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -311,7 +311,7 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) { struct gfs2_sbd *sdp = ip->i_inode.i_sb->s_fs_info; struct buffer_head *dibh; - uint32_t nlink; + u32 nlink; int error; BUG_ON(ip->i_di.di_nlink != ip->i_inode.i_nlink); @@ -428,7 +428,7 @@ out: return inode; } -static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) +static int pick_formal_ino_1(struct gfs2_sbd *sdp, u64 *formal_ino) { struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode); struct buffer_head *bh; @@ -469,7 +469,7 @@ static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) return 1; } -static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) +static int pick_formal_ino_2(struct gfs2_sbd *sdp, u64 *formal_ino) { struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode); struct gfs2_inode *m_ip = GFS2_I(sdp->sd_inum_inode); @@ -495,13 +495,13 @@ static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) if (!ir.ir_length) { struct buffer_head *m_bh; - uint64_t x, y; + u64 x, y; error = gfs2_meta_inode_buffer(m_ip, &m_bh); if (error) goto out_brelse; - x = *(uint64_t *)(m_bh->b_data + sizeof(struct gfs2_dinode)); + x = *(u64 *)(m_bh->b_data + sizeof(struct gfs2_dinode)); x = y = be64_to_cpu(x); ir.ir_start = x; ir.ir_length = GFS2_INUM_QUANTUM; @@ -510,7 +510,7 @@ static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) gfs2_consist_inode(m_ip); x = cpu_to_be64(x); gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1); - *(uint64_t *)(m_bh->b_data + sizeof(struct gfs2_dinode)) = x; + *(u64 *)(m_bh->b_data + sizeof(struct gfs2_dinode)) = x; brelse(m_bh); } @@ -531,7 +531,7 @@ out: return error; } -static int pick_formal_ino(struct gfs2_sbd *sdp, uint64_t *inum) +static int pick_formal_ino(struct gfs2_sbd *sdp, u64 *inum) { int error; @@ -577,9 +577,9 @@ static int create_ok(struct gfs2_inode *dip, const struct qstr *name, return error; } - if (dip->i_di.di_entries == (uint32_t)-1) + if (dip->i_di.di_entries == (u32)-1) return -EFBIG; - if (S_ISDIR(mode) && dip->i_di.di_nlink == (uint32_t)-1) + if (S_ISDIR(mode) && dip->i_di.di_nlink == (u32)-1) return -EMLINK; return 0; @@ -1131,7 +1131,7 @@ int gfs2_glock_nq_atime(struct gfs2_holder *gh) struct gfs2_glock *gl = gh->gh_gl; struct gfs2_sbd *sdp = gl->gl_sbd; struct gfs2_inode *ip = gl->gl_object; - int64_t curtime, quantum = gfs2_tune_get(sdp, gt_atime_quantum); + s64 curtime, quantum = gfs2_tune_get(sdp, gt_atime_quantum); unsigned int state; int flags; int error; diff --git a/fs/gfs2/lm_interface.h b/fs/gfs2/lm_interface.h index 0bf4c276e0fe..e2dfc3da4da9 100644 --- a/fs/gfs2/lm_interface.h +++ b/fs/gfs2/lm_interface.h @@ -160,7 +160,7 @@ typedef void (*lm_callback_t) (lm_fsdata_t *fsdata, unsigned int type, struct lm_lockname { - uint64_t ln_number; + u64 ln_number; unsigned int ln_type; }; diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index 1f15b6e8b2cf..dceea419b94b 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -61,7 +61,7 @@ void gdlm_queue_delayed(struct gdlm_lock *lp) /* convert gfs lock-state to dlm lock-mode */ -static int16_t make_mode(int16_t lmstate) +static s16 make_mode(s16 lmstate) { switch (lmstate) { case LM_ST_UNLOCKED: @@ -79,7 +79,7 @@ static int16_t make_mode(int16_t lmstate) /* convert dlm lock-mode to gfs lock-state */ -int16_t gdlm_make_lmstate(int16_t dlmmode) +s16 gdlm_make_lmstate(s16 dlmmode) { switch (dlmmode) { case DLM_LOCK_IV: @@ -101,14 +101,14 @@ int16_t gdlm_make_lmstate(int16_t dlmmode) static void check_cur_state(struct gdlm_lock *lp, unsigned int cur_state) { - int16_t cur = make_mode(cur_state); + s16 cur = make_mode(cur_state); if (lp->cur != DLM_LOCK_IV) gdlm_assert(lp->cur == cur, "%d, %d", lp->cur, cur); } static inline unsigned int make_flags(struct gdlm_lock *lp, unsigned int gfs_flags, - int16_t cur, int16_t req) + s16 cur, s16 req) { unsigned int lkf = 0; diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h index 941063498532..c7b6e370258f 100644 --- a/fs/gfs2/locking/dlm/lock_dlm.h +++ b/fs/gfs2/locking/dlm/lock_dlm.h @@ -56,7 +56,7 @@ enum { }; struct gdlm_ls { - uint32_t id; + u32 id; int jid; int first; int first_done; @@ -77,7 +77,7 @@ struct gdlm_ls { struct list_head delayed; struct list_head submit; struct list_head all_locks; - uint32_t all_locks_count; + u32 all_locks_count; wait_queue_head_t wait_control; struct task_struct *thread1; struct task_struct *thread2; @@ -109,10 +109,10 @@ struct gdlm_lock { char *lvb; struct dlm_lksb lksb; - int16_t cur; - int16_t req; - int16_t prev_req; - uint32_t lkf; /* dlm flags DLM_LKF_ */ + s16 cur; + s16 req; + s16 prev_req; + u32 lkf; /* dlm flags DLM_LKF_ */ unsigned long flags; /* lock_dlm flags LFL_ */ int bast_mode; /* protected by async_lock */ @@ -158,7 +158,7 @@ void gdlm_release_threads(struct gdlm_ls *); /* lock.c */ -int16_t gdlm_make_lmstate(int16_t); +s16 gdlm_make_lmstate(s16); void gdlm_queue_delayed(struct gdlm_lock *); void gdlm_submit_delayed(struct gdlm_ls *); int gdlm_release_all_locks(struct gdlm_ls *); diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c index a782246d666b..d4895ec242f6 100644 --- a/fs/gfs2/locking/dlm/thread.c +++ b/fs/gfs2/locking/dlm/thread.c @@ -48,7 +48,7 @@ static void process_complete(struct gdlm_lock *lp) { struct gdlm_ls *ls = lp->ls; struct lm_async_cb acb; - int16_t prev_mode = lp->cur; + s16 prev_mode = lp->cur; memset(&acb, 0, sizeof(acb)); diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 45ea3ec6f776..571389012874 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -62,7 +62,7 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags) { struct list_head *head = &sdp->sd_ail1_list; - uint64_t sync_gen; + u64 sync_gen; struct list_head *first, *tmp; struct gfs2_ail *first_ai, *ai; @@ -205,10 +205,10 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) up_read(&sdp->sd_log_flush_lock); } -static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) +static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) { int new = 0; - uint64_t dbn; + u64 dbn; int error; int bdy; @@ -287,7 +287,7 @@ static inline void log_incr_head(struct gfs2_sbd *sdp) struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp) { - uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head); + u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head); struct gfs2_log_buf *lb; struct buffer_head *bh; @@ -317,7 +317,7 @@ struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp) struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, struct buffer_head *real) { - uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head); + u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head); struct gfs2_log_buf *lb; struct buffer_head *bh; @@ -361,13 +361,13 @@ static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail, int pull) * Returns: the initialized log buffer descriptor */ -static void log_write_header(struct gfs2_sbd *sdp, uint32_t flags, int pull) +static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull) { - uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head); + u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head); struct buffer_head *bh; struct gfs2_log_header *lh; unsigned int tail; - uint32_t hash; + u32 hash; /* printk(KERN_INFO "log write header start (flags=%08x, pull=%d)\n", flags, pull); */ @@ -523,7 +523,7 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) reserved += sdp->sd_log_commited_buf; if (sdp->sd_log_commited_revoke) reserved += gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke, - sizeof(uint64_t)); + sizeof(u64)); if (reserved) reserved++; diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index e2c2582c8f6e..456d6ad1049d 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -202,7 +202,7 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_glock *gl = ip->i_gl; unsigned int blks = be32_to_cpu(ld->ld_data1); struct buffer_head *bh_log, *bh_ip; - uint64_t blkno; + u64 blkno; int error = 0; if (pass != 1 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_METADATA) @@ -294,7 +294,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp) ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD); ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_REVOKE); ld->ld_length = cpu_to_be32(gfs2_struct2blk(sdp, sdp->sd_log_num_revoke, - sizeof(uint64_t))); + sizeof(u64))); ld->ld_data1 = cpu_to_be32(sdp->sd_log_num_revoke); ld->ld_data2 = cpu_to_be32(0); memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved)); @@ -305,7 +305,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp) list_del_init(&rv->rv_le.le_list); sdp->sd_log_num_revoke--; - if (offset + sizeof(uint64_t) > sdp->sd_sb.sb_bsize) { + if (offset + sizeof(u64) > sdp->sd_sb.sb_bsize) { set_buffer_dirty(bh); ll_rw_block(WRITE, 1, &bh); @@ -320,7 +320,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp) *(__be64 *)(bh->b_data + offset) = cpu_to_be64(rv->rv_blkno); kfree(rv); - offset += sizeof(uint64_t); + offset += sizeof(u64); } gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); @@ -349,7 +349,7 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, unsigned int revokes = be32_to_cpu(ld->ld_data1); struct buffer_head *bh; unsigned int offset; - uint64_t blkno; + u64 blkno; int first = 1; int error; @@ -366,7 +366,7 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, if (!first) gfs2_metatype_check(sdp, bh, GFS2_METATYPE_LB); - while (offset + sizeof(uint64_t) <= sdp->sd_sb.sb_bsize) { + while (offset + sizeof(u64) <= sdp->sd_sb.sb_bsize) { blkno = be64_to_cpu(*(__be64 *)(bh->b_data + offset)); error = gfs2_revoke_add(sdp, blkno, start); @@ -377,7 +377,7 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, if (!--revokes) break; - offset += sizeof(uint64_t); + offset += sizeof(u64); } brelse(bh); @@ -677,8 +677,8 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, struct gfs2_glock *gl = ip->i_gl; unsigned int blks = be32_to_cpu(ld->ld_data1); struct buffer_head *bh_log, *bh_ip; - uint64_t blkno; - uint64_t esc; + u64 blkno; + u64 esc; int error = 0; if (pass != 1 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_JDATA) diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 3f6da00e2f59..5b10379c20eb 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -213,7 +213,7 @@ void gfs2_ail_empty_gl(struct gfs2_glock *gl) struct list_head *head = &gl->gl_ail_list; struct gfs2_bufdata *bd; struct buffer_head *bh; - uint64_t blkno; + u64 blkno; int error; blocks = atomic_read(&gl->gl_ail_count); @@ -303,7 +303,7 @@ void gfs2_meta_sync(struct gfs2_glock *gl, int flags) */ static struct buffer_head *getbuf(struct gfs2_sbd *sdp, struct inode *aspace, - uint64_t blkno, int create) + u64 blkno, int create) { struct page *page; struct buffer_head *bh; @@ -366,7 +366,7 @@ static void meta_prep_new(struct buffer_head *bh) * Returns: The buffer */ -struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, uint64_t blkno) +struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno) { struct buffer_head *bh; bh = getbuf(gl->gl_sbd, gl->gl_aspace, blkno, CREATE); @@ -384,7 +384,7 @@ struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, uint64_t blkno) * Returns: errno */ -int gfs2_meta_read(struct gfs2_glock *gl, uint64_t blkno, int flags, +int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags, struct buffer_head **bhp) { int error; @@ -549,7 +549,7 @@ void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, * */ -void gfs2_meta_wipe(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) +void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct inode *aspace = ip->i_gl->gl_aspace; @@ -573,7 +573,7 @@ void gfs2_meta_wipe(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) if (bd) { gfs2_log_lock(sdp); if (bd->bd_ail) { - uint64_t blkno = bh->b_blocknr; + u64 blkno = bh->b_blocknr; bd->bd_ail = NULL; list_del(&bd->bd_ail_st_list); list_del(&bd->bd_ail_gl_list); @@ -637,7 +637,7 @@ void gfs2_meta_cache_flush(struct gfs2_inode *ip) * Returns: errno */ -int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num, +int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num, int new, struct buffer_head **bhp) { struct buffer_head *bh, **bh_slot = ip->i_cache + height; @@ -711,12 +711,12 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num, * */ -void gfs2_meta_ra(struct gfs2_glock *gl, uint64_t dblock, uint32_t extlen) +void gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen) { struct gfs2_sbd *sdp = gl->gl_sbd; struct inode *aspace = gl->gl_aspace; struct buffer_head *first_bh, *bh; - uint32_t max_ra = gfs2_tune_get(sdp, gt_max_readahead) >> + u32 max_ra = gfs2_tune_get(sdp, gt_max_readahead) >> sdp->sd_sb.sb_bsize_shift; int error; diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index 4ddc936aae16..9a9acc940292 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h @@ -44,8 +44,8 @@ void gfs2_ail_empty_gl(struct gfs2_glock *gl); void gfs2_meta_inval(struct gfs2_glock *gl); void gfs2_meta_sync(struct gfs2_glock *gl, int flags); -struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, uint64_t blkno); -int gfs2_meta_read(struct gfs2_glock *gl, uint64_t blkno, +struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno); +int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags, struct buffer_head **bhp); int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags); @@ -55,10 +55,10 @@ void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, struct gfs2_ail *ai); -void gfs2_meta_wipe(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); +void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen); void gfs2_meta_cache_flush(struct gfs2_inode *ip); -int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num, +int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num, int new, struct buffer_head **bhp); static inline int gfs2_meta_inode_buffer(struct gfs2_inode *ip, @@ -67,7 +67,7 @@ static inline int gfs2_meta_inode_buffer(struct gfs2_inode *ip, return gfs2_meta_indirect_buffer(ip, 0, ip->i_num.no_addr, 0, bhp); } -void gfs2_meta_ra(struct gfs2_glock *gl, uint64_t dblock, uint32_t extlen); +void gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen); void gfs2_meta_syncfs(struct gfs2_sbd *sdp); #endif /* __DIO_DOT_H__ */ diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 21ae9e4f0f6c..ae9c46e75392 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -66,7 +66,7 @@ int gfs2_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { int new = create; - uint64_t dblock; + u64 dblock; int error; int boundary; @@ -100,7 +100,7 @@ static int get_block_noalloc(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { int new = 0; - uint64_t dblock; + u64 dblock; int error; int boundary; @@ -510,10 +510,10 @@ static int gfs2_commit_write(struct file *file, struct page *page, gfs2_trans_add_bh(ip->i_gl, dibh, 1); if (gfs2_is_stuffed(ip)) { - uint64_t file_size; + u64 file_size; void *kaddr; - file_size = ((uint64_t)page->index << PAGE_CACHE_SHIFT) + to; + file_size = ((u64)page->index << PAGE_CACHE_SHIFT) + to; kaddr = kmap_atomic(page, KM_USER0); memcpy(dibh->b_data + sizeof(struct gfs2_dinode) + from, diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index c94cbc8b6ef6..cf826893dd5f 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -46,15 +46,15 @@ static struct dentry *gfs2_decode_fh(struct super_block *sb, switch (fh_type) { case 10: - parent.no_formal_ino = ((uint64_t)be32_to_cpu(fh[4])) << 32; + parent.no_formal_ino = ((u64)be32_to_cpu(fh[4])) << 32; parent.no_formal_ino |= be32_to_cpu(fh[5]); - parent.no_addr = ((uint64_t)be32_to_cpu(fh[6])) << 32; + parent.no_addr = ((u64)be32_to_cpu(fh[6])) << 32; parent.no_addr |= be32_to_cpu(fh[7]); fh_obj.imode = be32_to_cpu(fh[8]); case 4: - this->no_formal_ino = ((uint64_t)be32_to_cpu(fh[0])) << 32; + this->no_formal_ino = ((u64)be32_to_cpu(fh[0])) << 32; this->no_formal_ino |= be32_to_cpu(fh[1]); - this->no_addr = ((uint64_t)be32_to_cpu(fh[2])) << 32; + this->no_addr = ((u64)be32_to_cpu(fh[2])) << 32; this->no_addr |= be32_to_cpu(fh[3]); break; default: @@ -118,7 +118,7 @@ struct get_name_filldir { }; static int get_name_filldir(void *opaque, const char *name, unsigned int length, - uint64_t offset, struct gfs2_inum *inum, + u64 offset, struct gfs2_inum *inum, unsigned int type) { struct get_name_filldir *gnfd = (struct get_name_filldir *)opaque; @@ -140,7 +140,7 @@ static int gfs2_get_name(struct dentry *parent, char *name, struct gfs2_inode *dip, *ip; struct get_name_filldir gnfd; struct gfs2_holder gh; - uint64_t offset = 0; + u64 offset = 0; int error; if (!dir) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 53ce7816dc18..f5ddd496d3ec 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -47,7 +47,7 @@ struct filldir_bad_entry { char *fbe_name; unsigned int fbe_length; - uint64_t fbe_offset; + u64 fbe_offset; struct gfs2_inum fbe_inum; unsigned int fbe_type; }; @@ -161,7 +161,7 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) */ static int filldir_reg_func(void *opaque, const char *name, unsigned int length, - uint64_t offset, struct gfs2_inum *inum, + u64 offset, struct gfs2_inum *inum, unsigned int type) { struct filldir_reg *fdr = (struct filldir_reg *)opaque; @@ -200,7 +200,7 @@ static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) struct gfs2_inode *dip = GFS2_I(dir); struct filldir_reg fdr; struct gfs2_holder d_gh; - uint64_t offset = file->f_pos; + u64 offset = file->f_pos; int error; fdr.fdr_sbd = GFS2_SB(dir); @@ -239,7 +239,7 @@ static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) */ static int filldir_bad_func(void *opaque, const char *name, unsigned int length, - uint64_t offset, struct gfs2_inum *inum, + u64 offset, struct gfs2_inum *inum, unsigned int type) { struct filldir_bad *fdb = (struct filldir_bad *)opaque; @@ -293,7 +293,7 @@ static int readdir_bad(struct file *file, void *dirent, filldir_t filldir) unsigned int entries, size; struct filldir_bad *fdb; struct gfs2_holder d_gh; - uint64_t offset = file->f_pos; + u64 offset = file->f_pos; unsigned int x; struct filldir_bad_entry *fbe; int error; diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index bd9b9957f707..c680f050e17f 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -172,7 +172,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, if (!dip->i_di.di_nlink) goto out_gunlock; error = -EFBIG; - if (dip->i_di.di_entries == (uint32_t)-1) + if (dip->i_di.di_entries == (u32)-1) goto out_gunlock; error = -EPERM; if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) @@ -181,7 +181,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, if (!ip->i_di.di_nlink) goto out_gunlock; error = -EMLINK; - if (ip->i_di.di_nlink == (uint32_t)-1) + if (ip->i_di.di_nlink == (u32)-1) goto out_gunlock; alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name); @@ -509,7 +509,7 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, struct gfs2_holder ghs[2]; struct inode *inode; struct buffer_head *dibh; - uint32_t major = 0, minor = 0; + u32 major = 0, minor = 0; int error; switch (mode & S_IFMT) { @@ -670,12 +670,12 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, error = -EINVAL; goto out_gunlock; } - if (ndip->i_di.di_entries == (uint32_t)-1) { + if (ndip->i_di.di_entries == (u32)-1) { error = -EFBIG; goto out_gunlock; } if (S_ISDIR(ip->i_di.di_mode) && - ndip->i_di.di_nlink == (uint32_t)-1) { + ndip->i_di.di_nlink == (u32)-1) { error = -EMLINK; goto out_gunlock; } @@ -911,7 +911,7 @@ static int setattr_chown(struct inode *inode, struct iattr *attr) struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_sbd *sdp = GFS2_SB(inode); struct buffer_head *dibh; - uint32_t ouid, ogid, nuid, ngid; + u32 ouid, ogid, nuid, ngid; int error; ouid = ip->i_di.di_uid; diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index 32ec8574ac8e..3b3463144126 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -62,7 +62,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); unsigned long index = page->index; - uint64_t lblock = index << (PAGE_CACHE_SHIFT - + u64 lblock = index << (PAGE_CACHE_SHIFT - sdp->sd_sb.sb_bsize_shift); unsigned int blocks = PAGE_CACHE_SIZE >> sdp->sd_sb.sb_bsize_shift; struct gfs2_alloc *al; @@ -101,7 +101,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) } for (x = 0; x < blocks; ) { - uint64_t dblock; + u64 dblock; unsigned int extlen; int new = 1; diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 572b92eac367..f5830befc307 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -65,17 +65,17 @@ #define QUOTA_USER 1 #define QUOTA_GROUP 0 -static uint64_t qd2offset(struct gfs2_quota_data *qd) +static u64 qd2offset(struct gfs2_quota_data *qd) { - uint64_t offset; + u64 offset; - offset = 2 * (uint64_t)qd->qd_id + !test_bit(QDF_USER, &qd->qd_flags); + offset = 2 * (u64)qd->qd_id + !test_bit(QDF_USER, &qd->qd_flags); offset *= sizeof(struct gfs2_quota); return offset; } -static int qd_alloc(struct gfs2_sbd *sdp, int user, uint32_t id, +static int qd_alloc(struct gfs2_sbd *sdp, int user, u32 id, struct gfs2_quota_data **qdp) { struct gfs2_quota_data *qd; @@ -91,7 +91,7 @@ static int qd_alloc(struct gfs2_sbd *sdp, int user, uint32_t id, set_bit(QDF_USER, &qd->qd_flags); qd->qd_slot = -1; - error = gfs2_glock_get(sdp, 2 * (uint64_t)id + !user, + error = gfs2_glock_get(sdp, 2 * (u64)id + !user, &gfs2_quota_glops, CREATE, &qd->qd_gl); if (error) goto fail; @@ -110,7 +110,7 @@ fail: return error; } -static int qd_get(struct gfs2_sbd *sdp, int user, uint32_t id, int create, +static int qd_get(struct gfs2_sbd *sdp, int user, u32 id, int create, struct gfs2_quota_data **qdp) { struct gfs2_quota_data *qd = NULL, *new_qd = NULL; @@ -248,7 +248,7 @@ static int bh_get(struct gfs2_quota_data *qd) struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); unsigned int block, offset; - uint64_t dblock; + u64 dblock; int new = 0; struct buffer_head *bh; int error; @@ -405,7 +405,7 @@ static void qd_unlock(struct gfs2_quota_data *qd) qd_put(qd); } -static int qdsb_get(struct gfs2_sbd *sdp, int user, uint32_t id, int create, +static int qdsb_get(struct gfs2_sbd *sdp, int user, u32 id, int create, struct gfs2_quota_data **qdp) { int error; @@ -438,7 +438,7 @@ static void qdsb_put(struct gfs2_quota_data *qd) qd_put(qd); } -int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) +int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; @@ -523,12 +523,12 @@ static int sort_qd(const void *a, const void *b) return ret; } -static void do_qc(struct gfs2_quota_data *qd, int64_t change) +static void do_qc(struct gfs2_quota_data *qd, s64 change) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); struct gfs2_quota_change *qc = qd->qd_bh_qc; - int64_t x; + s64 x; mutex_lock(&sdp->sd_quota_mutex); gfs2_trans_add_bh(ip->i_gl, qd->qd_bh, 1); @@ -571,7 +571,7 @@ static void do_qc(struct gfs2_quota_data *qd, int64_t change) * in turn mostly borrowed from ext3 */ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, - int64_t change, struct gfs2_quota_data *qd) + s64 change, struct gfs2_quota_data *qd) { struct inode *inode = &ip->i_inode; struct address_space *mapping = inode->i_mapping; @@ -811,7 +811,7 @@ fail: return error; } -int gfs2_quota_lock(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) +int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; @@ -848,7 +848,7 @@ static int need_sync(struct gfs2_quota_data *qd) { struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; struct gfs2_tune *gt = &sdp->sd_tune; - int64_t value; + s64 value; unsigned int num, den; int do_sync = 1; @@ -873,7 +873,7 @@ static int need_sync(struct gfs2_quota_data *qd) value *= gfs2_jindex_size(sdp) * num; do_div(value, den); value += (s64)be64_to_cpu(qd->qd_qb.qb_value); - if (value < (int64_t)be64_to_cpu(qd->qd_qb.qb_limit)) + if (value < (s64)be64_to_cpu(qd->qd_qb.qb_limit)) do_sync = 0; } @@ -927,12 +927,12 @@ static int print_message(struct gfs2_quota_data *qd, char *type) return 0; } -int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) +int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; struct gfs2_quota_data *qd; - int64_t value; + s64 value; unsigned int x; int error = 0; @@ -954,12 +954,12 @@ int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) value += qd->qd_change; spin_unlock(&sdp->sd_quota_spin); - if (be64_to_cpu(qd->qd_qb.qb_limit) && (int64_t)be64_to_cpu(qd->qd_qb.qb_limit) < value) { + if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) { print_message(qd, "exceeded"); error = -EDQUOT; break; } else if (be64_to_cpu(qd->qd_qb.qb_warn) && - (int64_t)be64_to_cpu(qd->qd_qb.qb_warn) < value && + (s64)be64_to_cpu(qd->qd_qb.qb_warn) < value && time_after_eq(jiffies, qd->qd_last_warn + gfs2_tune_get(sdp, gt_quota_warn_period) * HZ)) { @@ -971,8 +971,8 @@ int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) return error; } -void gfs2_quota_change(struct gfs2_inode *ip, int64_t change, - uint32_t uid, uint32_t gid) +void gfs2_quota_change(struct gfs2_inode *ip, s64 change, + u32 uid, u32 gid) { struct gfs2_alloc *al = &ip->i_alloc; struct gfs2_quota_data *qd; @@ -1038,7 +1038,7 @@ int gfs2_quota_sync(struct gfs2_sbd *sdp) return error; } -int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, uint32_t id) +int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, u32 id) { struct gfs2_quota_data *qd; struct gfs2_holder q_gh; @@ -1058,7 +1058,7 @@ int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, uint32_t id) } #if 0 -int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id, +int gfs2_quota_read(struct gfs2_sbd *sdp, int user, u32 id, struct gfs2_quota *q) { struct gfs2_quota_data *qd; @@ -1100,8 +1100,8 @@ int gfs2_quota_init(struct gfs2_sbd *sdp) unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; unsigned int x, slot = 0; unsigned int found = 0; - uint64_t dblock; - uint32_t extlen = 0; + u64 dblock; + u32 extlen = 0; int error; if (!ip->i_di.di_size || diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h index 6702a56d49b5..d93c61c99365 100644 --- a/fs/gfs2/quota.h +++ b/fs/gfs2/quota.h @@ -10,20 +10,20 @@ #ifndef __QUOTA_DOT_H__ #define __QUOTA_DOT_H__ -#define NO_QUOTA_CHANGE ((uint32_t)-1) +#define NO_QUOTA_CHANGE ((u32)-1) -int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid); +int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid); void gfs2_quota_unhold(struct gfs2_inode *ip); -int gfs2_quota_lock(struct gfs2_inode *ip, uint32_t uid, uint32_t gid); +int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid); void gfs2_quota_unlock(struct gfs2_inode *ip); -int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid); -void gfs2_quota_change(struct gfs2_inode *ip, int64_t change, - uint32_t uid, uint32_t gid); +int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid); +void gfs2_quota_change(struct gfs2_inode *ip, s64 change, + u32 uid, u32 gid); int gfs2_quota_sync(struct gfs2_sbd *sdp); -int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, uint32_t id); +int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, u32 id); int gfs2_quota_init(struct gfs2_sbd *sdp); void gfs2_quota_scan(struct gfs2_sbd *sdp); diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index acafe4b4d6f0..ab55191926c3 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -35,8 +35,8 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, struct gfs2_inode *ip = GFS2_I(jd->jd_inode); struct gfs2_glock *gl = ip->i_gl; int new = 0; - uint64_t dblock; - uint32_t extlen; + u64 dblock; + u32 extlen; int error; error = gfs2_extent_map(&ip->i_inode, blk, &new, &dblock, &extlen); @@ -53,7 +53,7 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, return error; } -int gfs2_revoke_add(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where) +int gfs2_revoke_add(struct gfs2_sbd *sdp, u64 blkno, unsigned int where) { struct list_head *head = &sdp->sd_revoke_list; struct gfs2_revoke_replay *rr; @@ -82,7 +82,7 @@ int gfs2_revoke_add(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where) return 1; } -int gfs2_revoke_check(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where) +int gfs2_revoke_check(struct gfs2_sbd *sdp, u64 blkno, unsigned int where) { struct gfs2_revoke_replay *rr; int wrap, a, b, revoke; @@ -137,7 +137,7 @@ static int get_log_header(struct gfs2_jdesc *jd, unsigned int blk, { struct buffer_head *bh; struct gfs2_log_header lh; - uint32_t hash; + u32 hash; int error; error = gfs2_replay_read_block(jd, blk, &bh); @@ -249,7 +249,7 @@ static int jhead_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head) int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header *head) { struct gfs2_log_header lh_1, lh_m; - uint32_t blk_1, blk_2, blk_m; + u32 blk_1, blk_2, blk_m; int error; blk_1 = 0; @@ -370,9 +370,9 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); unsigned int lblock; int new = 0; - uint64_t dblock; + u64 dblock; struct gfs2_log_header *lh; - uint32_t hash; + u32 hash; struct buffer_head *bh; int error; int boundary; diff --git a/fs/gfs2/recovery.h b/fs/gfs2/recovery.h index bed1a7857f6e..1b35516b7591 100644 --- a/fs/gfs2/recovery.h +++ b/fs/gfs2/recovery.h @@ -19,8 +19,8 @@ static inline void gfs2_replay_incr_blk(struct gfs2_sbd *sdp, unsigned int *blk) int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, struct buffer_head **bh); -int gfs2_revoke_add(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where); -int gfs2_revoke_check(struct gfs2_sbd *sdp, uint64_t blkno, unsigned int where); +int gfs2_revoke_add(struct gfs2_sbd *sdp, u64 blkno, unsigned int where); +int gfs2_revoke_check(struct gfs2_sbd *sdp, u64 blkno, unsigned int where); void gfs2_revoke_clean(struct gfs2_sbd *sdp); int gfs2_find_jhead(struct gfs2_jdesc *jd, diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 62d0a84df982..af49c8b82ffb 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -60,7 +60,7 @@ static const char valid_change[16] = { */ static void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, uint32_t block, + unsigned int buflen, u32 block, unsigned char new_state) { unsigned char *byte, *end, cur_state; @@ -90,7 +90,7 @@ static void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, */ static unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, uint32_t block) + unsigned int buflen, u32 block) { unsigned char *byte, *end, cur_state; unsigned int bit; @@ -122,12 +122,12 @@ static unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer, * Return: the block number (bitmap buffer scope) that was found */ -static uint32_t gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, - unsigned int buflen, uint32_t goal, +static u32 gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, + unsigned int buflen, u32 goal, unsigned char old_state) { unsigned char *byte, *end, alloc; - uint32_t blk = goal; + u32 blk = goal; unsigned int bit; byte = buffer + (goal / GFS2_NBBY); @@ -169,7 +169,7 @@ static uint32_t gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, * Returns: The number of bits */ -static uint32_t gfs2_bitcount(struct gfs2_rgrpd *rgd, unsigned char *buffer, +static u32 gfs2_bitcount(struct gfs2_rgrpd *rgd, unsigned char *buffer, unsigned int buflen, unsigned char state) { unsigned char *byte = buffer; @@ -177,7 +177,7 @@ static uint32_t gfs2_bitcount(struct gfs2_rgrpd *rgd, unsigned char *buffer, unsigned char state1 = state << 2; unsigned char state2 = state << 4; unsigned char state3 = state << 6; - uint32_t count = 0; + u32 count = 0; for (; byte < end; byte++) { if (((*byte) & 0x03) == state) @@ -204,11 +204,11 @@ void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd) { struct gfs2_sbd *sdp = rgd->rd_sbd; struct gfs2_bitmap *bi = NULL; - uint32_t length = rgd->rd_ri.ri_length; - uint32_t count[4], tmp; + u32 length = rgd->rd_ri.ri_length; + u32 count[4], tmp; int buf, x; - memset(count, 0, 4 * sizeof(uint32_t)); + memset(count, 0, 4 * sizeof(u32)); /* Count # blocks in each of 4 possible allocation states */ for (buf = 0; buf < length; buf++) { @@ -253,10 +253,10 @@ void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd) } -static inline int rgrp_contains_block(struct gfs2_rindex *ri, uint64_t block) +static inline int rgrp_contains_block(struct gfs2_rindex *ri, u64 block) { - uint64_t first = ri->ri_data0; - uint64_t last = first + ri->ri_data; + u64 first = ri->ri_data0; + u64 last = first + ri->ri_data; return !!(first <= block && block < last); } @@ -268,7 +268,7 @@ static inline int rgrp_contains_block(struct gfs2_rindex *ri, uint64_t block) * Returns: The resource group, or NULL if not found */ -struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, uint64_t blk) +struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk) { struct gfs2_rgrpd *rgd; @@ -367,8 +367,8 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd) { struct gfs2_sbd *sdp = rgd->rd_sbd; struct gfs2_bitmap *bi; - uint32_t length = rgd->rd_ri.ri_length; /* # blocks in hdr & bitmap */ - uint32_t bytes_left, bytes; + u32 length = rgd->rd_ri.ri_length; /* # blocks in hdr & bitmap */ + u32 bytes_left, bytes; int x; if (!length) @@ -444,7 +444,7 @@ static int gfs2_ri_update(struct gfs2_inode *ip) struct gfs2_rgrpd *rgd; char buf[sizeof(struct gfs2_rindex)]; struct file_ra_state ra_state; - uint64_t junk = ip->i_di.di_size; + u64 junk = ip->i_di.di_size; int error; if (do_div(junk, sizeof(struct gfs2_rindex))) { @@ -741,7 +741,7 @@ static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_alloc *al) */ static struct gfs2_rgrpd *recent_rgrp_first(struct gfs2_sbd *sdp, - uint64_t rglast) + u64 rglast) { struct gfs2_rgrpd *rgd = NULL; @@ -1037,10 +1037,10 @@ void gfs2_inplace_release(struct gfs2_inode *ip) * Returns: The block type (GFS2_BLKST_*) */ -unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, uint64_t block) +unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block) { struct gfs2_bitmap *bi = NULL; - uint32_t length, rgrp_block, buf_block; + u32 length, rgrp_block, buf_block; unsigned int buf; unsigned char type; @@ -1083,12 +1083,12 @@ unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, uint64_t block) * Returns: the block number allocated */ -static uint32_t rgblk_search(struct gfs2_rgrpd *rgd, uint32_t goal, +static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, unsigned char old_state, unsigned char new_state) { struct gfs2_bitmap *bi = NULL; - uint32_t length = rgd->rd_ri.ri_length; - uint32_t blk = 0; + u32 length = rgd->rd_ri.ri_length; + u32 blk = 0; unsigned int buf, x; /* Find bitmap block that contains bits for goal block */ @@ -1148,12 +1148,12 @@ static uint32_t rgblk_search(struct gfs2_rgrpd *rgd, uint32_t goal, * Returns: Resource group containing the block(s) */ -static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, uint64_t bstart, - uint32_t blen, unsigned char new_state) +static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart, + u32 blen, unsigned char new_state) { struct gfs2_rgrpd *rgd; struct gfs2_bitmap *bi = NULL; - uint32_t length, rgrp_blk, buf_blk; + u32 length, rgrp_blk, buf_blk; unsigned int buf; rgd = gfs2_blk2rgrpd(sdp, bstart); @@ -1206,8 +1206,8 @@ u64 gfs2_alloc_data(struct gfs2_inode *ip) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; struct gfs2_rgrpd *rgd = al->al_rgd; - uint32_t goal, blk; - uint64_t block; + u32 goal, blk; + u64 block; if (rgrp_contains_block(&rgd->rd_ri, ip->i_di.di_goal_data)) goal = ip->i_di.di_goal_data - rgd->rd_ri.ri_data0; @@ -1250,8 +1250,8 @@ u64 gfs2_alloc_meta(struct gfs2_inode *ip) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_alloc *al = &ip->i_alloc; struct gfs2_rgrpd *rgd = al->al_rgd; - uint32_t goal, blk; - uint64_t block; + u32 goal, blk; + u64 block; if (rgrp_contains_block(&rgd->rd_ri, ip->i_di.di_goal_meta)) goal = ip->i_di.di_goal_meta - rgd->rd_ri.ri_data0; @@ -1332,7 +1332,7 @@ u64 gfs2_alloc_di(struct gfs2_inode *dip, u64 *generation) * */ -void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) +void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_rgrpd *rgd; @@ -1349,7 +1349,7 @@ void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) gfs2_trans_add_rg(rgd); gfs2_statfs_change(sdp, 0, +blen, 0); - gfs2_quota_change(ip, -(int64_t)blen, + gfs2_quota_change(ip, -(s64)blen, ip->i_di.di_uid, ip->i_di.di_gid); } @@ -1361,7 +1361,7 @@ void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) * */ -void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) +void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_rgrpd *rgd; @@ -1378,7 +1378,7 @@ void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) gfs2_trans_add_rg(rgd); gfs2_statfs_change(sdp, 0, +blen, 0); - gfs2_quota_change(ip, -(int64_t)blen, ip->i_di.di_uid, ip->i_di.di_gid); + gfs2_quota_change(ip, -(s64)blen, ip->i_di.di_uid, ip->i_di.di_gid); gfs2_meta_wipe(ip, bstart, blen); } @@ -1397,7 +1397,7 @@ void gfs2_unlink_di(struct inode *inode) gfs2_trans_add_rg(rgd); } -static void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno) +static void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, u64 blkno) { struct gfs2_sbd *sdp = rgd->rd_sbd; struct gfs2_rgrpd *tmp_rgd; @@ -1440,7 +1440,7 @@ void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) */ void gfs2_rlist_add(struct gfs2_sbd *sdp, struct gfs2_rgrp_list *rlist, - uint64_t block) + u64 block) { struct gfs2_rgrpd *rgd; struct gfs2_rgrpd **tmp; diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h index f94761bf3460..3d6ae37e85df 100644 --- a/fs/gfs2/rgrp.h +++ b/fs/gfs2/rgrp.h @@ -12,7 +12,7 @@ void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd); -struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, uint64_t blk); +struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk); struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp); struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd); @@ -35,14 +35,14 @@ gfs2_inplace_reserve_i((ip), __FILE__, __LINE__) void gfs2_inplace_release(struct gfs2_inode *ip); -unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, uint64_t block); +unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block); u64 gfs2_alloc_data(struct gfs2_inode *ip); u64 gfs2_alloc_meta(struct gfs2_inode *ip); u64 gfs2_alloc_di(struct gfs2_inode *ip, u64 *generation); -void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); -void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); +void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen); +void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen); void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip); void gfs2_unlink_di(struct inode *inode); @@ -54,7 +54,7 @@ struct gfs2_rgrp_list { }; void gfs2_rlist_add(struct gfs2_sbd *sdp, struct gfs2_rgrp_list *rlist, - uint64_t block); + u64 block); void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state, int flags); void gfs2_rlist_free(struct gfs2_rgrp_list *rlist); diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 520266c2044b..f1d07d987c7b 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -33,11 +33,11 @@ #include "trans.h" #include "util.h" -static const uint32_t gfs2_old_fs_formats[] = { +static const u32 gfs2_old_fs_formats[] = { 0 }; -static const uint32_t gfs2_old_multihost_formats[] = { +static const u32 gfs2_old_multihost_formats[] = { 0 }; @@ -225,8 +225,8 @@ static struct page *gfs2_read_super(struct super_block *sb, sector_t sector) int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) { - uint32_t hash_blocks, ind_blocks, leaf_blocks; - uint32_t tmp_blocks; + u32 hash_blocks, ind_blocks, leaf_blocks; + u32 tmp_blocks; unsigned int x; int error; struct page *page; @@ -251,20 +251,20 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) GFS2_BASIC_BLOCK_SHIFT; sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; sdp->sd_diptrs = (sdp->sd_sb.sb_bsize - - sizeof(struct gfs2_dinode)) / sizeof(uint64_t); + sizeof(struct gfs2_dinode)) / sizeof(u64); sdp->sd_inptrs = (sdp->sd_sb.sb_bsize - - sizeof(struct gfs2_meta_header)) / sizeof(uint64_t); + sizeof(struct gfs2_meta_header)) / sizeof(u64); sdp->sd_jbsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header); sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2; sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1; - sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(uint64_t); + sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(u64); sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header)) / sizeof(struct gfs2_quota_change); /* Compute maximum reservation required to add a entry to a directory */ - hash_blocks = DIV_ROUND_UP(sizeof(uint64_t) * (1 << GFS2_DIR_MAX_DEPTH), + hash_blocks = DIV_ROUND_UP(sizeof(u64) * (1 << GFS2_DIR_MAX_DEPTH), sdp->sd_jbsize); ind_blocks = 0; @@ -281,8 +281,8 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) sizeof(struct gfs2_dinode); sdp->sd_heightsize[1] = sdp->sd_sb.sb_bsize * sdp->sd_diptrs; for (x = 2;; x++) { - uint64_t space, d; - uint32_t m; + u64 space, d; + u32 m; space = sdp->sd_heightsize[x - 1] * sdp->sd_inptrs; d = space; @@ -299,8 +299,8 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) sizeof(struct gfs2_dinode); sdp->sd_jheightsize[1] = sdp->sd_jbsize * sdp->sd_diptrs; for (x = 2;; x++) { - uint64_t space, d; - uint32_t m; + u64 space, d; + u32 m; space = sdp->sd_jheightsize[x - 1] * sdp->sd_inptrs; d = space; @@ -630,8 +630,8 @@ out: return 0; } -void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, - int64_t dinodes) +void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free, + s64 dinodes) { struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; diff --git a/fs/gfs2/super.h b/fs/gfs2/super.h index 4a6ce9582743..b073300a93e8 100644 --- a/fs/gfs2/super.h +++ b/fs/gfs2/super.h @@ -40,7 +40,7 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp); int gfs2_statfs_init(struct gfs2_sbd *sdp); void gfs2_statfs_change(struct gfs2_sbd *sdp, - int64_t total, int64_t free, int64_t dinodes); + s64 total, s64 free, s64 dinodes); int gfs2_statfs_sync(struct gfs2_sbd *sdp); int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc); int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc); diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index 79199738c389..8aefda22f98e 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -138,7 +138,7 @@ static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf, static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { - uint32_t id; + u32 id; if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -152,7 +152,7 @@ static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf, size_t len) { - uint32_t id; + u32 id; if (!capable(CAP_SYS_ADMIN)) return -EACCES; diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 8e18e634cbed..acf840160d5f 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -46,7 +46,7 @@ int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks, tr->tr_reserved += 6 + blocks; if (revokes) tr->tr_reserved += gfs2_struct2blk(sdp, revokes, - sizeof(uint64_t)); + sizeof(u64)); INIT_LIST_HEAD(&tr->tr_list_buf); gfs2_holder_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &tr->tr_t_gh); @@ -142,7 +142,7 @@ void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta) lops_add(sdp, &bd->bd_le); } -void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, uint64_t blkno) +void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, u64 blkno) { struct gfs2_revoke *rv = kmalloc(sizeof(struct gfs2_revoke), GFP_NOFS | __GFP_NOFAIL); @@ -151,7 +151,7 @@ void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, uint64_t blkno) lops_add(sdp, &rv->rv_le); } -void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, uint64_t blkno) +void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno) { struct gfs2_revoke *rv; int found = 0; diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h index 9e3ce84f6102..6550d3d18263 100644 --- a/fs/gfs2/trans.h +++ b/fs/gfs2/trans.h @@ -27,8 +27,8 @@ void gfs2_trans_end(struct gfs2_sbd *sdp); void gfs2_trans_add_gl(struct gfs2_glock *gl); void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta); -void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, uint64_t blkno); -void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, uint64_t blkno); +void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, u64 blkno); +void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno); void gfs2_trans_add_rg(struct gfs2_rgrpd *rgd); #endif /* __TRANS_DOT_H__ */ diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 2852431764c9..d72eb8addc7a 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -171,7 +171,7 @@ int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, */ int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, - uint16_t type, uint16_t t, const char *function, + u16 type, u16 t, const char *function, char *file, unsigned int line) { int me; diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index 60b370365eea..204fdb81e34d 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -82,7 +82,7 @@ static inline int gfs2_meta_check_i(struct gfs2_sbd *sdp, char *file, unsigned int line) { struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; - uint32_t magic = mh->mh_magic; + u32 magic = mh->mh_magic; magic = be32_to_cpu(magic); if (unlikely(magic != GFS2_MAGIC)) return gfs2_meta_check_ii(sdp, bh, "magic number", function, @@ -95,19 +95,19 @@ gfs2_meta_check_i((sdp), (bh), __FUNCTION__, __FILE__, __LINE__) int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, - uint16_t type, uint16_t t, + u16 type, u16 t, const char *function, char *file, unsigned int line); static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp, struct buffer_head *bh, - uint16_t type, + u16 type, const char *function, char *file, unsigned int line) { struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; - uint32_t magic = mh->mh_magic; - uint16_t t = be32_to_cpu(mh->mh_type); + u32 magic = mh->mh_magic; + u16 t = be32_to_cpu(mh->mh_type); magic = be32_to_cpu(magic); if (unlikely(magic != GFS2_MAGIC)) return gfs2_meta_check_ii(sdp, bh, "magic number", function, @@ -121,8 +121,8 @@ static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp, #define gfs2_metatype_check(sdp, bh, type) \ gfs2_metatype_check_i((sdp), (bh), (type), __FUNCTION__, __FILE__, __LINE__) -static inline void gfs2_metatype_set(struct buffer_head *bh, uint16_t type, - uint16_t format) +static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type, + u16 format) { struct gfs2_meta_header *mh; mh = (struct gfs2_meta_header *)bh->b_data; From c26687113aea9a11c6f23ddf668f1fe43eca4ce7 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 13:55:48 -0400 Subject: [PATCH 226/292] [GFS2] Remove a cast, tidy gfs2_inode_attr_in The remains of the changes for Jan Engelhardt's third email. Remove a cast and tidy up gfs2_inode_attr_in. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 2 +- fs/gfs2/inode.c | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index a97ad74d880c..0f9567fe5c8b 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -344,7 +344,7 @@ static void find_metapath(struct gfs2_inode *ip, u64 block, unsigned int i; for (i = ip->i_di.di_height; i--;) - mp->mp_list[i] = (__u16)do_div(b, sdp->sd_inptrs); + mp->mp_list[i] = do_div(b, sdp->sd_inptrs); } diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index f683a400b006..0d010f0654d9 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -47,40 +47,41 @@ void gfs2_inode_attr_in(struct gfs2_inode *ip) { struct inode *inode = &ip->i_inode; + struct gfs2_dinode *di = &ip->i_di; inode->i_ino = ip->i_num.no_addr; - switch (ip->i_di.di_mode & S_IFMT) { + switch (di->di_mode & S_IFMT) { case S_IFBLK: case S_IFCHR: - inode->i_rdev = MKDEV(ip->i_di.di_major, ip->i_di.di_minor); + inode->i_rdev = MKDEV(di->di_major, di->di_minor); break; default: inode->i_rdev = 0; break; }; - inode->i_mode = ip->i_di.di_mode; - inode->i_nlink = ip->i_di.di_nlink; - inode->i_uid = ip->i_di.di_uid; - inode->i_gid = ip->i_di.di_gid; - i_size_write(inode, ip->i_di.di_size); - inode->i_atime.tv_sec = ip->i_di.di_atime; - inode->i_mtime.tv_sec = ip->i_di.di_mtime; - inode->i_ctime.tv_sec = ip->i_di.di_ctime; + inode->i_mode = di->di_mode; + inode->i_nlink = di->di_nlink; + inode->i_uid = di->di_uid; + inode->i_gid = di->di_gid; + i_size_write(inode, di->di_size); + inode->i_atime.tv_sec = di->di_atime; + inode->i_mtime.tv_sec = di->di_mtime; + inode->i_ctime.tv_sec = di->di_ctime; inode->i_atime.tv_nsec = 0; inode->i_mtime.tv_nsec = 0; inode->i_ctime.tv_nsec = 0; inode->i_blksize = PAGE_SIZE; - inode->i_blocks = ip->i_di.di_blocks << + inode->i_blocks = di->di_blocks << (GFS2_SB(inode)->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT); - if (ip->i_di.di_flags & GFS2_DIF_IMMUTABLE) + if (di->di_flags & GFS2_DIF_IMMUTABLE) inode->i_flags |= S_IMMUTABLE; else inode->i_flags &= ~S_IMMUTABLE; - if (ip->i_di.di_flags & GFS2_DIF_APPENDONLY) + if (di->di_flags & GFS2_DIF_APPENDONLY) inode->i_flags |= S_APPEND; else inode->i_flags &= ~S_APPEND; From 82ffa51637f9239aaddd3151fb0d41c657f760db Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 14:47:06 -0400 Subject: [PATCH 227/292] [GFS2] More style changes As per Jan Engelhardt's fourth email, this is the first part of the change set with a few minor style points. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/lops.c | 9 ++++----- fs/gfs2/meta_io.c | 5 ++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 456d6ad1049d..5898d6d3c1fe 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -118,7 +118,7 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp) unsigned n; __be64 *ptr; - offset += (sizeof(__be64) - 1); + offset += sizeof(__be64) - 1; offset &= ~(sizeof(__be64) - 1); limit = (sdp->sd_sb.sb_bsize - offset)/sizeof(__be64); /* for 4k blocks, limit = 503 */ @@ -219,8 +219,8 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, continue; error = gfs2_replay_read_block(jd, start, &bh_log); - if (error) - return error; + if (error) + return error; bh_ip = gfs2_meta_new(gl, blkno); memcpy(bh_ip->b_data, bh_log->b_data, bh_log->b_size); @@ -248,8 +248,7 @@ static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); if (error) { - gfs2_meta_sync(ip->i_gl, - DIO_START | DIO_WAIT); + gfs2_meta_sync(ip->i_gl, DIO_START | DIO_WAIT); return; } if (pass != 1) diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 5b10379c20eb..6af3521339fc 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -460,11 +460,10 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, bd->bd_gl = gl; INIT_LIST_HEAD(&bd->bd_list_tr); - if (meta) { + if (meta) lops_init_le(&bd->bd_le, &gfs2_buf_lops); - } else { + else lops_init_le(&bd->bd_le, &gfs2_databuf_lops); - } bh->b_private = bd; if (meta) From 38c60ef228596c8e331437ea9287ce035706b107 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 14:48:37 -0400 Subject: [PATCH 228/292] [GFS2] Use const in endian conversion routines Use const in endian conversion and printing of on-disk structures. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/ondisk.c | 78 ++++++++++++++++++------------------- include/linux/gfs2_ondisk.h | 42 ++++++++++---------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c index 03881f9870f7..1025960b0e6e 100644 --- a/fs/gfs2/ondisk.c +++ b/fs/gfs2/ondisk.c @@ -32,56 +32,56 @@ * first arg: the cpu-order structure */ -void gfs2_inum_in(struct gfs2_inum *no, char *buf) +void gfs2_inum_in(struct gfs2_inum *no, const void *buf) { - struct gfs2_inum *str = (struct gfs2_inum *)buf; + const struct gfs2_inum *str = buf; no->no_formal_ino = be64_to_cpu(str->no_formal_ino); no->no_addr = be64_to_cpu(str->no_addr); } -void gfs2_inum_out(const struct gfs2_inum *no, char *buf) +void gfs2_inum_out(const struct gfs2_inum *no, void *buf) { - struct gfs2_inum *str = (struct gfs2_inum *)buf; + struct gfs2_inum *str = buf; str->no_formal_ino = cpu_to_be64(no->no_formal_ino); str->no_addr = cpu_to_be64(no->no_addr); } -static void gfs2_inum_print(struct gfs2_inum *no) +static void gfs2_inum_print(const struct gfs2_inum *no) { printk(KERN_INFO " no_formal_ino = %llu\n", (unsigned long long)no->no_formal_ino); printk(KERN_INFO " no_addr = %llu\n", (unsigned long long)no->no_addr); } -static void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf) +static void gfs2_meta_header_in(struct gfs2_meta_header *mh, const void *buf) { - struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf; + const struct gfs2_meta_header *str = buf; mh->mh_magic = be32_to_cpu(str->mh_magic); mh->mh_type = be32_to_cpu(str->mh_type); mh->mh_format = be32_to_cpu(str->mh_format); } -static void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf) +static void gfs2_meta_header_out(const struct gfs2_meta_header *mh, void *buf) { - struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf; + struct gfs2_meta_header *str = buf; str->mh_magic = cpu_to_be32(mh->mh_magic); str->mh_type = cpu_to_be32(mh->mh_type); str->mh_format = cpu_to_be32(mh->mh_format); } -static void gfs2_meta_header_print(struct gfs2_meta_header *mh) +static void gfs2_meta_header_print(const struct gfs2_meta_header *mh) { pv(mh, mh_magic, "0x%.8X"); pv(mh, mh_type, "%u"); pv(mh, mh_format, "%u"); } -void gfs2_sb_in(struct gfs2_sb *sb, char *buf) +void gfs2_sb_in(struct gfs2_sb *sb, const void *buf) { - struct gfs2_sb *str = (struct gfs2_sb *)buf; + const struct gfs2_sb *str = buf; gfs2_meta_header_in(&sb->sb_header, buf); @@ -97,9 +97,9 @@ void gfs2_sb_in(struct gfs2_sb *sb, char *buf) memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN); } -void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf) +void gfs2_rindex_in(struct gfs2_rindex *ri, const void *buf) { - struct gfs2_rindex *str = (struct gfs2_rindex *)buf; + const struct gfs2_rindex *str = buf; ri->ri_addr = be64_to_cpu(str->ri_addr); ri->ri_length = be32_to_cpu(str->ri_length); @@ -109,7 +109,7 @@ void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf) } -void gfs2_rindex_print(struct gfs2_rindex *ri) +void gfs2_rindex_print(const struct gfs2_rindex *ri) { printk(KERN_INFO " ri_addr = %llu\n", (unsigned long long)ri->ri_addr); pv(ri, ri_length, "%u"); @@ -120,9 +120,9 @@ void gfs2_rindex_print(struct gfs2_rindex *ri) pv(ri, ri_bitbytes, "%u"); } -void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf) +void gfs2_rgrp_in(struct gfs2_rgrp *rg, const void *buf) { - struct gfs2_rgrp *str = (struct gfs2_rgrp *)buf; + const struct gfs2_rgrp *str = buf; gfs2_meta_header_in(&rg->rg_header, buf); rg->rg_flags = be32_to_cpu(str->rg_flags); @@ -131,9 +131,9 @@ void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf) rg->rg_igeneration = be64_to_cpu(str->rg_igeneration); } -void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf) +void gfs2_rgrp_out(const struct gfs2_rgrp *rg, void *buf) { - struct gfs2_rgrp *str = (struct gfs2_rgrp *)buf; + struct gfs2_rgrp *str = buf; gfs2_meta_header_out(&rg->rg_header, buf); str->rg_flags = cpu_to_be32(rg->rg_flags); @@ -144,21 +144,21 @@ void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf) memset(&str->rg_reserved, 0, sizeof(str->rg_reserved)); } -void gfs2_quota_in(struct gfs2_quota *qu, char *buf) +void gfs2_quota_in(struct gfs2_quota *qu, const void *buf) { - struct gfs2_quota *str = (struct gfs2_quota *)buf; + const struct gfs2_quota *str = buf; qu->qu_limit = be64_to_cpu(str->qu_limit); qu->qu_warn = be64_to_cpu(str->qu_warn); qu->qu_value = be64_to_cpu(str->qu_value); } -void gfs2_dinode_in(struct gfs2_dinode *di, char *buf) +void gfs2_dinode_in(struct gfs2_dinode *di, const void *buf) { - struct gfs2_dinode *str = (struct gfs2_dinode *)buf; + const struct gfs2_dinode *str = buf; gfs2_meta_header_in(&di->di_header, buf); - gfs2_inum_in(&di->di_num, (char *)&str->di_num); + gfs2_inum_in(&di->di_num, &str->di_num); di->di_mode = be32_to_cpu(str->di_mode); di->di_uid = be32_to_cpu(str->di_uid); @@ -187,9 +187,9 @@ void gfs2_dinode_in(struct gfs2_dinode *di, char *buf) } -void gfs2_dinode_out(struct gfs2_dinode *di, char *buf) +void gfs2_dinode_out(const struct gfs2_dinode *di, void *buf) { - struct gfs2_dinode *str = (struct gfs2_dinode *)buf; + struct gfs2_dinode *str = buf; gfs2_meta_header_out(&di->di_header, buf); gfs2_inum_out(&di->di_num, (char *)&str->di_num); @@ -221,7 +221,7 @@ void gfs2_dinode_out(struct gfs2_dinode *di, char *buf) } -void gfs2_dinode_print(struct gfs2_dinode *di) +void gfs2_dinode_print(const struct gfs2_dinode *di) { gfs2_meta_header_print(&di->di_header); gfs2_inum_print(&di->di_num); @@ -251,9 +251,9 @@ void gfs2_dinode_print(struct gfs2_dinode *di) printk(KERN_INFO " di_eattr = %llu\n", (unsigned long long)di->di_eattr); } -void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf) +void gfs2_log_header_in(struct gfs2_log_header *lh, const void *buf) { - struct gfs2_log_header *str = (struct gfs2_log_header *)buf; + const struct gfs2_log_header *str = buf; gfs2_meta_header_in(&lh->lh_header, buf); lh->lh_sequence = be64_to_cpu(str->lh_sequence); @@ -263,43 +263,43 @@ void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf) lh->lh_hash = be32_to_cpu(str->lh_hash); } -void gfs2_inum_range_in(struct gfs2_inum_range *ir, char *buf) +void gfs2_inum_range_in(struct gfs2_inum_range *ir, const void *buf) { - struct gfs2_inum_range *str = (struct gfs2_inum_range *)buf; + const struct gfs2_inum_range *str = buf; ir->ir_start = be64_to_cpu(str->ir_start); ir->ir_length = be64_to_cpu(str->ir_length); } -void gfs2_inum_range_out(struct gfs2_inum_range *ir, char *buf) +void gfs2_inum_range_out(const struct gfs2_inum_range *ir, void *buf) { - struct gfs2_inum_range *str = (struct gfs2_inum_range *)buf; + struct gfs2_inum_range *str = buf; str->ir_start = cpu_to_be64(ir->ir_start); str->ir_length = cpu_to_be64(ir->ir_length); } -void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, char *buf) +void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, const void *buf) { - struct gfs2_statfs_change *str = (struct gfs2_statfs_change *)buf; + const struct gfs2_statfs_change *str = buf; sc->sc_total = be64_to_cpu(str->sc_total); sc->sc_free = be64_to_cpu(str->sc_free); sc->sc_dinodes = be64_to_cpu(str->sc_dinodes); } -void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf) +void gfs2_statfs_change_out(const struct gfs2_statfs_change *sc, void *buf) { - struct gfs2_statfs_change *str = (struct gfs2_statfs_change *)buf; + struct gfs2_statfs_change *str = buf; str->sc_total = cpu_to_be64(sc->sc_total); str->sc_free = cpu_to_be64(sc->sc_free); str->sc_dinodes = cpu_to_be64(sc->sc_dinodes); } -void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf) +void gfs2_quota_change_in(struct gfs2_quota_change *qc, const void *buf) { - struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf; + const struct gfs2_quota_change *str = buf; qc->qc_change = be64_to_cpu(str->qc_change); qc->qc_flags = be32_to_cpu(str->qc_flags); diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h index 3ebd8743ce8c..a7ae7c177cac 100644 --- a/include/linux/gfs2_ondisk.h +++ b/include/linux/gfs2_ondisk.h @@ -413,30 +413,30 @@ struct gfs2_quota_change { #ifdef __KERNEL__ /* Translation functions */ -extern void gfs2_inum_in(struct gfs2_inum *no, char *buf); -extern void gfs2_inum_out(const struct gfs2_inum *no, char *buf); -extern void gfs2_sb_in(struct gfs2_sb *sb, char *buf); -extern void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf); -extern void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf); -extern void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf); -extern void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf); -extern void gfs2_quota_in(struct gfs2_quota *qu, char *buf); -extern void gfs2_quota_out(struct gfs2_quota *qu, char *buf); -extern void gfs2_dinode_in(struct gfs2_dinode *di, char *buf); -extern void gfs2_dinode_out(struct gfs2_dinode *di, char *buf); -extern void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf); -extern void gfs2_ea_header_out(struct gfs2_ea_header *ea, char *buf); -extern void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf); -extern void gfs2_inum_range_in(struct gfs2_inum_range *ir, char *buf); -extern void gfs2_inum_range_out(struct gfs2_inum_range *ir, char *buf); -extern void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, char *buf); -extern void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf); -extern void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf); +extern void gfs2_inum_in(struct gfs2_inum *no, const void *buf); +extern void gfs2_inum_out(const struct gfs2_inum *no, void *buf); +extern void gfs2_sb_in(struct gfs2_sb *sb, const void *buf); +extern void gfs2_rindex_in(struct gfs2_rindex *ri, const void *buf); +extern void gfs2_rindex_out(const struct gfs2_rindex *ri, void *buf); +extern void gfs2_rgrp_in(struct gfs2_rgrp *rg, const void *buf); +extern void gfs2_rgrp_out(const struct gfs2_rgrp *rg, void *buf); +extern void gfs2_quota_in(struct gfs2_quota *qu, const void *buf); +extern void gfs2_quota_out(const struct gfs2_quota *qu, void *buf); +extern void gfs2_dinode_in(struct gfs2_dinode *di, const void *buf); +extern void gfs2_dinode_out(const struct gfs2_dinode *di, void *buf); +extern void gfs2_ea_header_in(struct gfs2_ea_header *ea, const void *buf); +extern void gfs2_ea_header_out(const struct gfs2_ea_header *ea, void *buf); +extern void gfs2_log_header_in(struct gfs2_log_header *lh, const void *buf); +extern void gfs2_inum_range_in(struct gfs2_inum_range *ir, const void *buf); +extern void gfs2_inum_range_out(const struct gfs2_inum_range *ir, void *buf); +extern void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, const void *buf); +extern void gfs2_statfs_change_out(const struct gfs2_statfs_change *sc, void *buf); +extern void gfs2_quota_change_in(struct gfs2_quota_change *qc, const void *buf); /* Printing functions */ -extern void gfs2_rindex_print(struct gfs2_rindex *ri); -extern void gfs2_dinode_print(struct gfs2_dinode *di); +extern void gfs2_rindex_print(const struct gfs2_rindex *ri); +extern void gfs2_dinode_print(const struct gfs2_dinode *di); #endif /* __KERNEL__ */ From dd538c832aaf8e35c46c98a825fa9dacee3cf226 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 14:53:30 -0400 Subject: [PATCH 229/292] [GFS2] Spelling sentinal -> sentinel A spelling mistake (one of mine). Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 6 +++--- fs/gfs2/ops_file.c | 4 ++-- fs/gfs2/ops_file.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index ae9c46e75392..96988ccf2087 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -262,7 +262,7 @@ static int gfs2_readpage(struct file *file, struct page *page) int error; int do_unlock = 0; - if (likely(file != &gfs2_internal_file_sentinal)) { + if (likely(file != &gfs2_internal_file_sentinel)) { if (file) { struct gfs2_file *gf = file->private_data; if (test_bit(GFF_EXLOCK, &gf->f_flags)) @@ -285,7 +285,7 @@ skip_lock: if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = -EIO; - if (file != &gfs2_internal_file_sentinal) { + if (file != &gfs2_internal_file_sentinel) { gfs2_glock_dq_m(1, &gh); gfs2_holder_uninit(&gh); } @@ -324,7 +324,7 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping, int ret; int do_unlock = 0; - if (likely(file != &gfs2_internal_file_sentinal)) { + if (likely(file != &gfs2_internal_file_sentinel)) { if (file) { struct gfs2_file *gf = file->private_data; if (test_bit(GFF_EXLOCK, &gf->f_flags)) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index f5ddd496d3ec..9dcf72aa9f66 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -79,7 +79,7 @@ struct filldir_reg { * any other part of this. Its use is purely as a flag so that we * know (in readpage()) whether or not do to locking. */ -struct file gfs2_internal_file_sentinal = { +struct file gfs2_internal_file_sentinel = { .f_flags = O_NOATIME|O_RDONLY, }; @@ -112,7 +112,7 @@ int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, desc.count = size; desc.error = 0; do_generic_mapping_read(inode->i_mapping, ra_state, - &gfs2_internal_file_sentinal, pos, &desc, + &gfs2_internal_file_sentinel, pos, &desc, gfs2_read_actor); return desc.written ? desc.written : desc.error; } diff --git a/fs/gfs2/ops_file.h b/fs/gfs2/ops_file.h index 064e52c30665..b1c1bf838ec9 100644 --- a/fs/gfs2/ops_file.h +++ b/fs/gfs2/ops_file.h @@ -9,7 +9,7 @@ #ifndef __OPS_FILE_DOT_H__ #define __OPS_FILE_DOT_H__ -extern struct file gfs2_internal_file_sentinal; +extern struct file gfs2_internal_file_sentinel; extern int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, char *buf, loff_t *pos, unsigned size); From 0bd5996a00346fee772cbdebc5666fd4e514089b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 14:59:35 -0400 Subject: [PATCH 230/292] [GFS2] Style changes in ops_address.c As per the remainder of Jan Engelhardt's fourth email comments, remove an cast thats not required. Also tidy up the "limit" code in stuck_releasepage(). Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 96988ccf2087..d44d42fb4163 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -517,7 +517,7 @@ static int gfs2_commit_write(struct file *file, struct page *page, kaddr = kmap_atomic(page, KM_USER0); memcpy(dibh->b_data + sizeof(struct gfs2_dinode) + from, - (char *)kaddr + from, to - from); + kaddr + from, to - from); kunmap_atomic(page, KM_USER0); SetPageUptodate(page); @@ -704,8 +704,9 @@ static void stuck_releasepage(struct buffer_head *bh) struct gfs2_glock *gl; static unsigned limit = 0; - if (limit++ > 3) + if (limit > 3) return; + limit++; fs_warn(sdp, "stuck in gfs2_releasepage() %p\n", inode); fs_warn(sdp, "blkno = %llu, bh->b_count = %d\n", From 26c1a57412b59a2284a521c711d9e9105bb6ad23 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 15:32:10 -0400 Subject: [PATCH 231/292] [GFS2] More code style updates As per Jan Engelhardt's fifth email. This has most of the changes recommended, which is the removal of casts which are not required, some indenting fixes and similar. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 60 ++++++++++++++++++++++---------------------- fs/gfs2/ops_fstype.c | 4 +-- fs/gfs2/ops_inode.c | 2 +- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 9dcf72aa9f66..b551074a3c98 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -94,12 +94,12 @@ static int gfs2_read_actor(read_descriptor_t *desc, struct page *page, kaddr = kmap(page); memcpy(desc->arg.buf, kaddr + offset, size); - kunmap(page); + kunmap(page); - desc->count = count - size; - desc->written += size; - desc->arg.buf += size; - return size; + desc->count = count - size; + desc->written += size; + desc->arg.buf += size; + return size; } int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, @@ -700,7 +700,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) int error = 0; state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; - flags = ((IS_SETLKW(cmd)) ? 0 : LM_FLAG_TRY) | GL_EXACT | GL_NOCACHE; + flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY) | GL_EXACT | GL_NOCACHE; mutex_lock(&fp->f_fl_mutex); @@ -780,32 +780,32 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) } const struct file_operations gfs2_file_fops = { - .llseek = gfs2_llseek, - .read = generic_file_read, - .readv = generic_file_readv, - .aio_read = generic_file_aio_read, - .write = generic_file_write, - .writev = generic_file_writev, - .aio_write = generic_file_aio_write, - .unlocked_ioctl = gfs2_ioctl, - .mmap = gfs2_mmap, - .open = gfs2_open, - .release = gfs2_close, - .fsync = gfs2_fsync, - .lock = gfs2_lock, - .sendfile = generic_file_sendfile, - .flock = gfs2_flock, - .splice_read = generic_file_splice_read, - .splice_write = generic_file_splice_write, + .llseek = gfs2_llseek, + .read = generic_file_read, + .readv = generic_file_readv, + .aio_read = generic_file_aio_read, + .write = generic_file_write, + .writev = generic_file_writev, + .aio_write = generic_file_aio_write, + .unlocked_ioctl = gfs2_ioctl, + .mmap = gfs2_mmap, + .open = gfs2_open, + .release = gfs2_close, + .fsync = gfs2_fsync, + .lock = gfs2_lock, + .sendfile = generic_file_sendfile, + .flock = gfs2_flock, + .splice_read = generic_file_splice_read, + .splice_write = generic_file_splice_write, }; const struct file_operations gfs2_dir_fops = { - .readdir = gfs2_readdir, - .unlocked_ioctl = gfs2_ioctl, - .open = gfs2_open, - .release = gfs2_close, - .fsync = gfs2_fsync, - .lock = gfs2_lock, - .flock = gfs2_flock, + .readdir = gfs2_readdir, + .unlocked_ioctl = gfs2_ioctl, + .open = gfs2_open, + .release = gfs2_close, + .fsync = gfs2_fsync, + .lock = gfs2_lock, + .flock = gfs2_flock, }; diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index d39314d5dd0a..c94422b30ceb 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -791,7 +791,7 @@ static int gfs2_get_sb(struct file_system_type *fs_type, int flags, if (error) goto out; sb = mnt->mnt_sb; - sdp = (struct gfs2_sbd*)sb->s_fs_info; + sdp = sb->s_fs_info; sdp->sd_gfs2mnt = mnt; out: return error; @@ -832,7 +832,7 @@ static int set_bdev_super(struct super_block *s, void *data) static int test_bdev_super(struct super_block *s, void *data) { - return (void *)s->s_bdev == data; + return s->s_bdev == data; } static struct super_block* get_gfs2_sb(const char *dev_name) diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index c680f050e17f..2f38313b4bd5 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -1014,7 +1014,7 @@ out: /** * gfs2_getattr - Read out an inode's attributes - * @mnt: ? + * @mnt: The vfsmount the inode is being accessed from * @dentry: The dentry to stat * @stat: The inode's stats * From 5acd3967347dab361d296d39ba19f8241507ef65 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 4 Sep 2006 16:16:45 -0400 Subject: [PATCH 232/292] [GFS2] Some further style changes Introduce a couple of new constants which make the NFS filehandle sizes that GFS2 uses a bit clearer. Also fix one or two minor issues as per Jan Engelhardt's sixth email. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_export.c | 11 ++++++----- fs/gfs2/ops_export.h | 3 +++ fs/gfs2/ops_super.c | 6 ++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index cf826893dd5f..4b8c6a9893e4 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -45,13 +45,13 @@ static struct dentry *gfs2_decode_fh(struct super_block *sb, memset(&parent, 0, sizeof(struct gfs2_inum)); switch (fh_type) { - case 10: + case GFS2_LARGE_FH_SIZE: parent.no_formal_ino = ((u64)be32_to_cpu(fh[4])) << 32; parent.no_formal_ino |= be32_to_cpu(fh[5]); parent.no_addr = ((u64)be32_to_cpu(fh[6])) << 32; parent.no_addr |= be32_to_cpu(fh[7]); fh_obj.imode = be32_to_cpu(fh[8]); - case 4: + case GFS2_SMALL_FH_SIZE: this->no_formal_ino = ((u64)be32_to_cpu(fh[0])) << 32; this->no_formal_ino |= be32_to_cpu(fh[1]); this->no_addr = ((u64)be32_to_cpu(fh[2])) << 32; @@ -72,7 +72,8 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, struct super_block *sb = inode->i_sb; struct gfs2_inode *ip = GFS2_I(inode); - if (*len < 4 || (connectable && *len < 10)) + if (*len < GFS2_SMALL_FH_SIZE || + (connectable && *len < GFS2_LARGE_FH_SIZE)) return 255; fh[0] = ip->i_num.no_formal_ino >> 32; @@ -83,7 +84,7 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, fh[2] = cpu_to_be32(fh[2]); fh[3] = ip->i_num.no_addr & 0xFFFFFFFF; fh[3] = cpu_to_be32(fh[3]); - *len = 4; + *len = GFS2_SMALL_FH_SIZE; if (!connectable || inode == sb->s_root->d_inode) return *len; @@ -105,7 +106,7 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len, fh[8] = cpu_to_be32(inode->i_mode); fh[9] = 0; /* pad to double word */ - *len = 10; + *len = GFS2_LARGE_FH_SIZE; iput(inode); diff --git a/fs/gfs2/ops_export.h b/fs/gfs2/ops_export.h index d52c2d93010c..09aca5046fb1 100644 --- a/fs/gfs2/ops_export.h +++ b/fs/gfs2/ops_export.h @@ -10,6 +10,9 @@ #ifndef __OPS_EXPORT_DOT_H__ #define __OPS_EXPORT_DOT_H__ +#define GFS2_SMALL_FH_SIZE 4 +#define GFS2_LARGE_FH_SIZE 10 + extern struct export_operations gfs2_export_ops; struct gfs2_fh_obj { struct gfs2_inum this; diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 6ced71240379..820db9333bd5 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -79,7 +79,7 @@ static void gfs2_put_super(struct super_block *sb) return; if (!strncmp(sb->s_type->name, "gfs2meta", 8)) - return; /* meta fs. don't do nothin' */ + return; /* Nothing to do */ /* Unfreeze the filesystem, if we need to */ @@ -136,7 +136,6 @@ static void gfs2_put_super(struct super_block *sb) /* At this point, we're through participating in the lockspace */ gfs2_sys_fs_del(sdp); vfree(sdp); - sb->s_fs_info = NULL; } /** @@ -149,8 +148,7 @@ static void gfs2_put_super(struct super_block *sb) static void gfs2_write_super(struct super_block *sb) { - struct gfs2_sbd *sdp = sb->s_fs_info; - gfs2_log_flush(sdp, NULL); + gfs2_log_flush(sb->s_fs_info, NULL); } /** From 2bdbc5d73961c040fdc9b30d985fab3047d697a0 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 5 Sep 2006 09:34:20 -0400 Subject: [PATCH 233/292] [GFS2] Directory code style changes As per comments from Jan Engelhardt, remove redundant casts, redundant endian conversions, add a smattering of const and rewrite the dirent_next function in order to avoid as many casts as possible. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/dir.c | 92 ++++++++++++++++++++++----------------------- fs/gfs2/dir.h | 4 +- fs/gfs2/ops_super.c | 3 +- 3 files changed, 47 insertions(+), 52 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 2023dc4ea306..d74a52bda540 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -81,9 +81,10 @@ #define gfs2_disk_hash2offset(h) (((u64)(h)) >> 1) #define gfs2_dir_offset2hash(p) ((u32)(((u64)(p)) << 1)) -typedef int (*leaf_call_t) (struct gfs2_inode *dip, - u32 index, u32 len, u64 leaf_no, - void *data); +typedef int (*leaf_call_t) (struct gfs2_inode *dip, u32 index, u32 len, + u64 leaf_no, void *data); +typedef int (*gfs2_dscan_t)(const struct gfs2_dirent *dent, + const struct qstr *name, void *opaque); int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, u64 block, @@ -348,17 +349,13 @@ fail: return (copied) ? copied : error; } -typedef int (*gfs2_dscan_t)(const struct gfs2_dirent *dent, - const struct qstr *name, - void *opaque); - static inline int __gfs2_dirent_find(const struct gfs2_dirent *dent, const struct qstr *name, int ret) { if (dent->de_inum.no_addr != 0 && be32_to_cpu(dent->de_hash) == name->hash && be16_to_cpu(dent->de_name_len) == name->len && - memcmp((char *)(dent+1), name->name, name->len) == 0) + memcmp(dent+1, name->name, name->len) == 0) return ret; return 0; } @@ -483,8 +480,7 @@ wrong_type: return -1; } -static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, - void *buf, +static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, void *buf, unsigned int len, gfs2_dscan_t scan, const struct qstr *name, void *opaque) @@ -500,7 +496,7 @@ static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, offset = ret; prev = NULL; - dent = (struct gfs2_dirent *)(buf + offset); + dent = buf + offset; size = be16_to_cpu(dent->de_rec_len); if (gfs2_check_dirent(dent, offset, size, len, 1)) goto consist_inode; @@ -512,7 +508,7 @@ static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode, if (offset == len) break; prev = dent; - dent = (struct gfs2_dirent *)(buf + offset); + dent = buf + offset; size = be16_to_cpu(dent->de_rec_len); if (gfs2_check_dirent(dent, offset, size, len, 0)) goto consist_inode; @@ -567,6 +563,24 @@ static int dirent_first(struct gfs2_inode *dip, struct buffer_head *bh, } } +static int dirent_check_reclen(struct gfs2_inode *dip, + const struct gfs2_dirent *d, const void *end_p) +{ + const void *ptr = d; + u16 rec_len = be16_to_cpu(d->de_rec_len); + + if (unlikely(rec_len < sizeof(struct gfs2_dirent))) + goto broken; + ptr += rec_len; + if (ptr < end_p) + return rec_len; + if (ptr == end_p) + return -ENOENT; +broken: + gfs2_consist_inode(dip); + return -EIO; +} + /** * dirent_next - Next dirent * @dip: the directory @@ -579,33 +593,18 @@ static int dirent_first(struct gfs2_inode *dip, struct buffer_head *bh, static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, struct gfs2_dirent **dent) { - struct gfs2_dirent *tmp, *cur; - char *bh_end; - u16 cur_rec_len; + struct gfs2_dirent *cur = *dent, *tmp; + char *bh_end = bh->b_data + bh->b_size; + int ret; - cur = *dent; - bh_end = bh->b_data + bh->b_size; - cur_rec_len = be16_to_cpu(cur->de_rec_len); + ret = dirent_check_reclen(dip, cur, bh_end); + if (ret < 0) + return ret; - if ((char *)cur + cur_rec_len >= bh_end) { - if ((char *)cur + cur_rec_len > bh_end) { - gfs2_consist_inode(dip); - return -EIO; - } - return -ENOENT; - } - - tmp = (struct gfs2_dirent *)((char *)cur + cur_rec_len); - - if ((char *)tmp + be16_to_cpu(tmp->de_rec_len) > bh_end) { - gfs2_consist_inode(dip); - return -EIO; - } - - if (cur_rec_len == 0) { - gfs2_consist_inode(dip); - return -EIO; - } + tmp = (void *)cur + ret; + ret = dirent_check_reclen(dip, tmp, bh_end); + if (ret == -EIO) + return ret; /* Only the first dent could ever have de_inum.no_addr == 0 */ if (!tmp->de_inum.no_addr) { @@ -614,7 +613,6 @@ static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh, } *dent = tmp; - return 0; } @@ -821,9 +819,9 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); leaf = (struct gfs2_leaf *)bh->b_data; leaf->lf_depth = cpu_to_be16(depth); - leaf->lf_entries = cpu_to_be16(0); + leaf->lf_entries = 0; leaf->lf_dirent_format = cpu_to_be16(GFS2_FORMAT_DE); - leaf->lf_next = cpu_to_be64(0); + leaf->lf_next = 0; memset(leaf->lf_reserved, 0, sizeof(leaf->lf_reserved)); dent = (struct gfs2_dirent *)(leaf+1); gfs2_qstr2dirent(&name, bh->b_size - sizeof(struct gfs2_leaf), dent); @@ -1152,14 +1150,14 @@ fail: static int compare_dents(const void *a, const void *b) { - struct gfs2_dirent *dent_a, *dent_b; + const struct gfs2_dirent *dent_a, *dent_b; u32 hash_a, hash_b; int ret = 0; - dent_a = *(struct gfs2_dirent **)a; + dent_a = *(const struct gfs2_dirent **)a; hash_a = be32_to_cpu(dent_a->de_hash); - dent_b = *(struct gfs2_dirent **)b; + dent_b = *(const struct gfs2_dirent **)b; hash_b = be32_to_cpu(dent_b->de_hash); if (hash_a > hash_b) @@ -1175,9 +1173,7 @@ static int compare_dents(const void *a, const void *b) else if (len_a < len_b) ret = -1; else - ret = memcmp((char *)(dent_a + 1), - (char *)(dent_b + 1), - len_a); + ret = memcmp(dent_a + 1, dent_b + 1, len_a); } return ret; @@ -1246,7 +1242,7 @@ static int do_filldir_main(struct gfs2_inode *dip, u64 *offset, gfs2_inum_in(&inum, (char *)&dent->de_inum); - error = filldir(opaque, (char *)(dent + 1), + error = filldir(opaque, (const char *)(dent + 1), be16_to_cpu(dent->de_name_len), off, &inum, be16_to_cpu(dent->de_type)); @@ -1298,7 +1294,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque, return 0; error = -ENOMEM; - larr = vmalloc((leaves + entries) * sizeof(void*)); + larr = vmalloc((leaves + entries) * sizeof(void *)); if (!larr) goto out; darr = (const struct gfs2_dirent **)(larr + leaves); diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h index f1f83faa36ec..d32449f0839c 100644 --- a/fs/gfs2/dir.h +++ b/fs/gfs2/dir.h @@ -46,7 +46,7 @@ int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, u64 block, static inline u32 gfs2_disk_hash(const char *data, int len) { - return crc32_le(0xFFFFFFFF, data, len) ^ 0xFFFFFFFF; + return crc32_le((u32)~0, data, len) ^ (u32)~0; } @@ -67,7 +67,7 @@ static inline void gfs2_qstr2dirent(const struct qstr *name, u16 reclen, struct dent->de_name_len = cpu_to_be16(name->len); dent->de_type = cpu_to_be16(0); memset(dent->__pad, 0, sizeof(dent->__pad)); - memcpy((char*)(dent+1), name->name, name->len); + memcpy(dent + 1, name->name, name->len); } #endif /* __DIR_DOT_H__ */ diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 820db9333bd5..addcf1334b3c 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -190,8 +190,7 @@ static void gfs2_write_super_lockfs(struct super_block *sb) static void gfs2_unlockfs(struct super_block *sb) { - struct gfs2_sbd *sdp = sb->s_fs_info; - gfs2_unfreeze_fs(sdp); + gfs2_unfreeze_fs(sb->s_fs_info); } /** From f2f7ba5237e2fe10ba3e328a4f728b9e1ff141da Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 5 Sep 2006 10:39:21 -0400 Subject: [PATCH 234/292] [GFS2] Make headers compile on their own As per Jan Engelhardt's comments, this should make all the headers compile on their own by including and/or declaring structures early. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/acl.h | 2 ++ fs/gfs2/bmap.h | 4 ++++ fs/gfs2/dir.h | 6 ++++++ fs/gfs2/eaops.h | 1 + fs/gfs2/eattr.h | 3 +++ fs/gfs2/glock.h | 2 ++ fs/gfs2/glops.h | 2 ++ fs/gfs2/incore.h | 2 ++ fs/gfs2/lm.h | 2 ++ fs/gfs2/log.h | 4 ++++ fs/gfs2/lops.h | 3 +++ fs/gfs2/meta_io.h | 4 ++++ fs/gfs2/mount.h | 2 ++ fs/gfs2/ops_address.h | 4 ++++ fs/gfs2/ops_dentry.h | 2 ++ fs/gfs2/ops_file.h | 4 ++++ fs/gfs2/ops_fstype.h | 2 ++ fs/gfs2/ops_inode.h | 2 ++ fs/gfs2/ops_super.h | 2 ++ fs/gfs2/ops_vm.h | 2 ++ fs/gfs2/quota.h | 3 +++ fs/gfs2/recovery.h | 2 ++ fs/gfs2/rgrp.h | 4 ++++ fs/gfs2/super.h | 2 ++ fs/gfs2/sys.h | 3 +++ fs/gfs2/trans.h | 9 +++++++-- fs/gfs2/util.h | 1 + 27 files changed, 77 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/acl.h b/fs/gfs2/acl.h index 5856ba764680..05c294fe0d78 100644 --- a/fs/gfs2/acl.h +++ b/fs/gfs2/acl.h @@ -10,6 +10,8 @@ #ifndef __ACL_DOT_H__ #define __ACL_DOT_H__ +#include "incore.h" + #define GFS2_POSIX_ACL_ACCESS "posix_acl_access" #define GFS2_POSIX_ACL_ACCESS_LEN 16 #define GFS2_POSIX_ACL_DEFAULT "posix_acl_default" diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index cb3b624fea31..503f1cdda290 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -10,6 +10,10 @@ #ifndef __BMAP_DOT_H__ #define __BMAP_DOT_H__ +struct inode; +struct gfs2_inode; +struct page; + int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page); int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *boundary); int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen); diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h index d32449f0839c..371233419b07 100644 --- a/fs/gfs2/dir.h +++ b/fs/gfs2/dir.h @@ -10,6 +10,12 @@ #ifndef __DIR_DOT_H__ #define __DIR_DOT_H__ +#include + +struct inode; +struct gfs2_inode; +struct gfs2_inum; + /** * gfs2_filldir_t - Report a directory entry to the caller of gfs2_dir_read() * @opaque: opaque data used by the function diff --git a/fs/gfs2/eaops.h b/fs/gfs2/eaops.h index 1c27700ee8b8..b045897e1e83 100644 --- a/fs/gfs2/eaops.h +++ b/fs/gfs2/eaops.h @@ -11,6 +11,7 @@ #define __EAOPS_DOT_H__ struct gfs2_ea_request; +struct gfs2_inode; struct gfs2_eattr_operations { int (*eo_get) (struct gfs2_inode *ip, struct gfs2_ea_request *er); diff --git a/fs/gfs2/eattr.h b/fs/gfs2/eattr.h index 85c70c335c59..cb7c2d846765 100644 --- a/fs/gfs2/eattr.h +++ b/fs/gfs2/eattr.h @@ -10,6 +10,9 @@ #ifndef __EATTR_DOT_H__ #define __EATTR_DOT_H__ +struct gfs2_inode; +struct iattr; + #define GFS2_EA_REC_LEN(ea) be32_to_cpu((ea)->ea_rec_len) #define GFS2_EA_DATA_LEN(ea) be32_to_cpu((ea)->ea_data_len) diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 4762cdb04f64..2e1d32866321 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -10,6 +10,8 @@ #ifndef __GLOCK_DOT_H__ #define __GLOCK_DOT_H__ +#include "incore.h" + /* Flags for lock requests; used in gfs2_holder gh_flag field. From lm_interface.h: #define LM_FLAG_TRY 0x00000001 diff --git a/fs/gfs2/glops.h b/fs/gfs2/glops.h index ba943e473665..a1d9b5b024e6 100644 --- a/fs/gfs2/glops.h +++ b/fs/gfs2/glops.h @@ -10,6 +10,8 @@ #ifndef __GLOPS_DOT_H__ #define __GLOPS_DOT_H__ +#include "incore.h" + extern const struct gfs2_glock_operations gfs2_meta_glops; extern const struct gfs2_glock_operations gfs2_inode_glops; extern const struct gfs2_glock_operations gfs2_rgrp_glops; diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 407afd18fa2e..225924ca6b3e 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -10,6 +10,8 @@ #ifndef __INCORE_DOT_H__ #define __INCORE_DOT_H__ +#include + #define DIO_FORCE 0x00000001 #define DIO_CLEAN 0x00000002 #define DIO_DIRTY 0x00000004 diff --git a/fs/gfs2/lm.h b/fs/gfs2/lm.h index dbef88852ef3..6b890e73e6c1 100644 --- a/fs/gfs2/lm.h +++ b/fs/gfs2/lm.h @@ -10,6 +10,8 @@ #ifndef __LM_DOT_H__ #define __LM_DOT_H__ +struct gfs2_sbd; + #define GFS2_MIN_LVB_SIZE 32 int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent); diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h index 80764e388bb2..7f5737d55612 100644 --- a/fs/gfs2/log.h +++ b/fs/gfs2/log.h @@ -10,6 +10,10 @@ #ifndef __LOG_DOT_H__ #define __LOG_DOT_H__ +#include +#include +#include "incore.h" + /** * gfs2_log_lock - acquire the right to mess with the log manager * @sdp: the filesystem diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h index 2e3365c2b101..5839c05ae6be 100644 --- a/fs/gfs2/lops.h +++ b/fs/gfs2/lops.h @@ -10,6 +10,9 @@ #ifndef __LOPS_DOT_H__ #define __LOPS_DOT_H__ +#include +#include "incore.h" + extern const struct gfs2_log_operations gfs2_glock_lops; extern const struct gfs2_log_operations gfs2_buf_lops; extern const struct gfs2_log_operations gfs2_revoke_lops; diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index 9a9acc940292..086a472df3f1 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h @@ -10,6 +10,10 @@ #ifndef __DIO_DOT_H__ #define __DIO_DOT_H__ +#include +#include +#include "incore.h" + static inline void gfs2_buffer_clear(struct buffer_head *bh) { memset(bh->b_data, 0, bh->b_size); diff --git a/fs/gfs2/mount.h b/fs/gfs2/mount.h index 8a21897b63e5..401288acfdf3 100644 --- a/fs/gfs2/mount.h +++ b/fs/gfs2/mount.h @@ -10,6 +10,8 @@ #ifndef __MOUNT_DOT_H__ #define __MOUNT_DOT_H__ +struct gfs2_sbd; + int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount); #endif /* __MOUNT_DOT_H__ */ diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h index 6c07aa2bd98a..35aaee4aa7e1 100644 --- a/fs/gfs2/ops_address.h +++ b/fs/gfs2/ops_address.h @@ -10,6 +10,10 @@ #ifndef __OPS_ADDRESS_DOT_H__ #define __OPS_ADDRESS_DOT_H__ +#include +#include +#include + extern const struct address_space_operations gfs2_file_aops; extern int gfs2_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create); diff --git a/fs/gfs2/ops_dentry.h b/fs/gfs2/ops_dentry.h index e7b05e5c62ec..5caa3db4d3f5 100644 --- a/fs/gfs2/ops_dentry.h +++ b/fs/gfs2/ops_dentry.h @@ -10,6 +10,8 @@ #ifndef __OPS_DENTRY_DOT_H__ #define __OPS_DENTRY_DOT_H__ +#include + extern struct dentry_operations gfs2_dops; #endif /* __OPS_DENTRY_DOT_H__ */ diff --git a/fs/gfs2/ops_file.h b/fs/gfs2/ops_file.h index b1c1bf838ec9..ce319f89ec8e 100644 --- a/fs/gfs2/ops_file.h +++ b/fs/gfs2/ops_file.h @@ -9,6 +9,10 @@ #ifndef __OPS_FILE_DOT_H__ #define __OPS_FILE_DOT_H__ + +#include +struct gfs2_inode; + extern struct file gfs2_internal_file_sentinel; extern int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, diff --git a/fs/gfs2/ops_fstype.h b/fs/gfs2/ops_fstype.h index b85ecce3ca6b..7cc2c296271b 100644 --- a/fs/gfs2/ops_fstype.h +++ b/fs/gfs2/ops_fstype.h @@ -10,6 +10,8 @@ #ifndef __OPS_FSTYPE_DOT_H__ #define __OPS_FSTYPE_DOT_H__ +#include + extern struct file_system_type gfs2_fs_type; extern struct file_system_type gfs2meta_fs_type; diff --git a/fs/gfs2/ops_inode.h b/fs/gfs2/ops_inode.h index 6f4b54783d29..b15acb4fd34c 100644 --- a/fs/gfs2/ops_inode.h +++ b/fs/gfs2/ops_inode.h @@ -10,6 +10,8 @@ #ifndef __OPS_INODE_DOT_H__ #define __OPS_INODE_DOT_H__ +#include + extern struct inode_operations gfs2_file_iops; extern struct inode_operations gfs2_dir_iops; extern struct inode_operations gfs2_symlink_iops; diff --git a/fs/gfs2/ops_super.h b/fs/gfs2/ops_super.h index cbc4f73e9a92..9de73f042f78 100644 --- a/fs/gfs2/ops_super.h +++ b/fs/gfs2/ops_super.h @@ -10,6 +10,8 @@ #ifndef __OPS_SUPER_DOT_H__ #define __OPS_SUPER_DOT_H__ +#include + extern struct super_operations gfs2_super_ops; #endif /* __OPS_SUPER_DOT_H__ */ diff --git a/fs/gfs2/ops_vm.h b/fs/gfs2/ops_vm.h index d5ba4b9c50fd..4ae8f43ed5e3 100644 --- a/fs/gfs2/ops_vm.h +++ b/fs/gfs2/ops_vm.h @@ -10,6 +10,8 @@ #ifndef __OPS_VM_DOT_H__ #define __OPS_VM_DOT_H__ +#include + extern struct vm_operations_struct gfs2_vm_ops_private; extern struct vm_operations_struct gfs2_vm_ops_sharewrite; diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h index d93c61c99365..a8be1417051f 100644 --- a/fs/gfs2/quota.h +++ b/fs/gfs2/quota.h @@ -10,6 +10,9 @@ #ifndef __QUOTA_DOT_H__ #define __QUOTA_DOT_H__ +struct gfs2_inode; +struct gfs2_sbd; + #define NO_QUOTA_CHANGE ((u32)-1) int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid); diff --git a/fs/gfs2/recovery.h b/fs/gfs2/recovery.h index 1b35516b7591..961feedf4d8b 100644 --- a/fs/gfs2/recovery.h +++ b/fs/gfs2/recovery.h @@ -10,6 +10,8 @@ #ifndef __RECOVERY_DOT_H__ #define __RECOVERY_DOT_H__ +#include "incore.h" + static inline void gfs2_replay_incr_blk(struct gfs2_sbd *sdp, unsigned int *blk) { if (++*blk == sdp->sd_jdesc->jd_blocks) diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h index 3d6ae37e85df..355895767387 100644 --- a/fs/gfs2/rgrp.h +++ b/fs/gfs2/rgrp.h @@ -10,6 +10,10 @@ #ifndef __RGRP_DOT_H__ #define __RGRP_DOT_H__ +struct gfs2_rgrpd; +struct gfs2_sbd; +struct gfs2_holder; + void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd); struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk); diff --git a/fs/gfs2/super.h b/fs/gfs2/super.h index b073300a93e8..5fa5119cfba6 100644 --- a/fs/gfs2/super.h +++ b/fs/gfs2/super.h @@ -10,6 +10,8 @@ #ifndef __SUPER_DOT_H__ #define __SUPER_DOT_H__ +#include "incore.h" + void gfs2_tune_init(struct gfs2_tune *gt); int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent); diff --git a/fs/gfs2/sys.h b/fs/gfs2/sys.h index f8c01b50bfba..1ca8cdac5304 100644 --- a/fs/gfs2/sys.h +++ b/fs/gfs2/sys.h @@ -10,6 +10,9 @@ #ifndef __SYS_DOT_H__ #define __SYS_DOT_H__ +#include +struct gfs2_sbd; + /* Allow args to be passed to GFS2 when using an initial ram disk */ extern char *gfs2_sys_margs; extern spinlock_t gfs2_sys_margs_lock; diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h index 6550d3d18263..23d4cbe1de5b 100644 --- a/fs/gfs2/trans.h +++ b/fs/gfs2/trans.h @@ -10,6 +10,11 @@ #ifndef __TRANS_DOT_H__ #define __TRANS_DOT_H__ +#include +struct gfs2_sbd; +struct gfs2_rgrpd; +struct gfs2_glock; + #define RES_DINODE 1 #define RES_INDIRECT 1 #define RES_JDATA 1 @@ -20,8 +25,8 @@ #define RES_STATFS 1 #define RES_QUOTA 2 -int gfs2_trans_begin(struct gfs2_sbd *sdp, - unsigned int blocks, unsigned int revokes); +int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks, + unsigned int revokes); void gfs2_trans_end(struct gfs2_sbd *sdp); diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index 204fdb81e34d..76a50899fe9e 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -10,6 +10,7 @@ #ifndef __UTIL_DOT_H__ #define __UTIL_DOT_H__ +#include "incore.h" #define fs_printk(level, fs, fmt, arg...) \ printk(level "GFS2: fsid=%s: " fmt , (fs)->sd_fsname , ## arg) From ea67eedb211d3418fa62fe3477e0d19b2888225e Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 5 Sep 2006 10:53:09 -0400 Subject: [PATCH 235/292] [GFS2] Fix end of multi-line structures As per Jan Engelhardt's request, I've added a ',' to the end of each of the multi-line structures which didn't already have one (most already did). Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/glops.c | 18 +++++++++--------- fs/gfs2/lops.c | 12 ++++++------ fs/gfs2/sys.c | 16 ++++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index d3e7b082a918..0c50a720d01d 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -492,7 +492,7 @@ static int quota_go_demote_ok(struct gfs2_glock *gl) const struct gfs2_glock_operations gfs2_meta_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, - .go_type = LM_TYPE_META + .go_type = LM_TYPE_META, }; const struct gfs2_glock_operations gfs2_inode_glops = { @@ -505,7 +505,7 @@ const struct gfs2_glock_operations gfs2_inode_glops = { .go_lock = inode_go_lock, .go_unlock = inode_go_unlock, .go_greedy = inode_greedy, - .go_type = LM_TYPE_INODE + .go_type = LM_TYPE_INODE, }; const struct gfs2_glock_operations gfs2_rgrp_glops = { @@ -516,45 +516,45 @@ const struct gfs2_glock_operations gfs2_rgrp_glops = { .go_demote_ok = rgrp_go_demote_ok, .go_lock = rgrp_go_lock, .go_unlock = rgrp_go_unlock, - .go_type = LM_TYPE_RGRP + .go_type = LM_TYPE_RGRP, }; const struct gfs2_glock_operations gfs2_trans_glops = { .go_xmote_th = trans_go_xmote_th, .go_xmote_bh = trans_go_xmote_bh, .go_drop_th = trans_go_drop_th, - .go_type = LM_TYPE_NONDISK + .go_type = LM_TYPE_NONDISK, }; const struct gfs2_glock_operations gfs2_iopen_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, .go_callback = gfs2_iopen_go_callback, - .go_type = LM_TYPE_IOPEN + .go_type = LM_TYPE_IOPEN, }; const struct gfs2_glock_operations gfs2_flock_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, - .go_type = LM_TYPE_FLOCK + .go_type = LM_TYPE_FLOCK, }; const struct gfs2_glock_operations gfs2_nondisk_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, - .go_type = LM_TYPE_NONDISK + .go_type = LM_TYPE_NONDISK, }; const struct gfs2_glock_operations gfs2_quota_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, .go_demote_ok = quota_go_demote_ok, - .go_type = LM_TYPE_QUOTA + .go_type = LM_TYPE_QUOTA, }; const struct gfs2_glock_operations gfs2_journal_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, - .go_type = LM_TYPE_JOURNAL + .go_type = LM_TYPE_JOURNAL, }; diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 5898d6d3c1fe..07655a755619 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -760,7 +760,7 @@ static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) const struct gfs2_log_operations gfs2_glock_lops = { .lo_add = glock_lo_add, .lo_after_commit = glock_lo_after_commit, - .lo_name = "glock" + .lo_name = "glock", }; const struct gfs2_log_operations gfs2_buf_lops = { @@ -771,7 +771,7 @@ const struct gfs2_log_operations gfs2_buf_lops = { .lo_before_scan = buf_lo_before_scan, .lo_scan_elements = buf_lo_scan_elements, .lo_after_scan = buf_lo_after_scan, - .lo_name = "buf" + .lo_name = "buf", }; const struct gfs2_log_operations gfs2_revoke_lops = { @@ -780,13 +780,13 @@ const struct gfs2_log_operations gfs2_revoke_lops = { .lo_before_scan = revoke_lo_before_scan, .lo_scan_elements = revoke_lo_scan_elements, .lo_after_scan = revoke_lo_after_scan, - .lo_name = "revoke" + .lo_name = "revoke", }; const struct gfs2_log_operations gfs2_rg_lops = { .lo_add = rg_lo_add, .lo_after_commit = rg_lo_after_commit, - .lo_name = "rg" + .lo_name = "rg", }; const struct gfs2_log_operations gfs2_databuf_lops = { @@ -796,7 +796,7 @@ const struct gfs2_log_operations gfs2_databuf_lops = { .lo_after_commit = databuf_lo_after_commit, .lo_scan_elements = databuf_lo_scan_elements, .lo_after_scan = databuf_lo_after_scan, - .lo_name = "databuf" + .lo_name = "databuf", }; const struct gfs2_log_operations *gfs2_log_ops[] = { @@ -805,6 +805,6 @@ const struct gfs2_log_operations *gfs2_log_ops[] = { &gfs2_revoke_lops, &gfs2_rg_lops, &gfs2_databuf_lops, - NULL + NULL, }; diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index 8aefda22f98e..7a282a4bde2a 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -253,7 +253,7 @@ static struct attribute *lockstruct_attrs[] = { &lockstruct_attr_first.attr, &lockstruct_attr_lvb_size.attr, &lockstruct_attr_flags.attr, - NULL + NULL, }; /* @@ -310,7 +310,7 @@ static struct attribute *args_attrs[] = { &args_attr_suiddir.attr, &args_attr_data.attr, &args_attr_noatime.attr, - NULL + NULL, }; /* @@ -339,7 +339,7 @@ static struct attribute *counters_attrs[] = { &counters_attr_glock_held_count.attr, &counters_attr_inode_count.attr, &counters_attr_reclaimed.attr, - NULL + NULL, }; /* @@ -487,27 +487,27 @@ static struct attribute *tune_attrs[] = { &tune_attr_quota_scale.attr, &tune_attr_new_files_jdata.attr, &tune_attr_new_files_directio.attr, - NULL + NULL, }; static struct attribute_group lockstruct_group = { .name = "lockstruct", - .attrs = lockstruct_attrs + .attrs = lockstruct_attrs, }; static struct attribute_group counters_group = { .name = "counters", - .attrs = counters_attrs + .attrs = counters_attrs, }; static struct attribute_group args_group = { .name = "args", - .attrs = args_attrs + .attrs = args_attrs, }; static struct attribute_group tune_group = { .name = "tune", - .attrs = tune_attrs + .attrs = tune_attrs, }; int gfs2_sys_fs_add(struct gfs2_sbd *sdp) From 16910427e1eb2a8069708ee24406d2d465381ebd Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 5 Sep 2006 11:15:45 -0400 Subject: [PATCH 236/292] [GFS2] Style changes in rgrp.c Change one constant plus remove a redundant !!. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/rgrp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index af49c8b82ffb..baa93c5d9592 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -29,7 +29,7 @@ #include "ops_file.h" #include "util.h" -#define BFITNOENT 0xFFFFFFFF +#define BFITNOENT (u32)~0 /* * These routines are used by the resource group routines (rgrp.c) @@ -257,7 +257,7 @@ static inline int rgrp_contains_block(struct gfs2_rindex *ri, u64 block) { u64 first = ri->ri_data0; u64 last = first + ri->ri_data; - return !!(first <= block && block < last); + return first <= block && block < last; } /** From cca195c5c09b81065018dee39f4013b95bf47502 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 5 Sep 2006 13:15:18 -0400 Subject: [PATCH 237/292] [GFS2] Extended attribute code style changes As per Jan Engelhardt's request and also a few of my own. It has been possible to add a few most const to the code as a result of the change in gfs2_ea_name2type. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/eaops.c | 8 ++-- fs/gfs2/eaops.h | 2 +- fs/gfs2/eattr.c | 102 ++++++++++++++++++------------------------------ fs/gfs2/eattr.h | 10 ++--- 4 files changed, 48 insertions(+), 74 deletions(-) diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index 3b8749c22731..adb898ceaa18 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -31,22 +31,22 @@ * Returns: GFS2_EATYPE_XXX */ -unsigned int gfs2_ea_name2type(const char *name, char **truncated_name) +unsigned int gfs2_ea_name2type(const char *name, const char **truncated_name) { unsigned int type; if (strncmp(name, "system.", 7) == 0) { type = GFS2_EATYPE_SYS; if (truncated_name) - *truncated_name = strchr(name, '.') + 1; + *truncated_name = name + sizeof("system.") - 1; } else if (strncmp(name, "user.", 5) == 0) { type = GFS2_EATYPE_USR; if (truncated_name) - *truncated_name = strchr(name, '.') + 1; + *truncated_name = name + sizeof("user.") - 1; } else if (strncmp(name, "security.", 9) == 0) { type = GFS2_EATYPE_SECURITY; if (truncated_name) - *truncated_name = strchr(name, '.') + 1; + *truncated_name = name + sizeof("security.") - 1; } else { type = GFS2_EATYPE_UNUSED; if (truncated_name) diff --git a/fs/gfs2/eaops.h b/fs/gfs2/eaops.h index b045897e1e83..508b4f7a2449 100644 --- a/fs/gfs2/eaops.h +++ b/fs/gfs2/eaops.h @@ -20,7 +20,7 @@ struct gfs2_eattr_operations { char *eo_name; }; -unsigned int gfs2_ea_name2type(const char *name, char **truncated_name); +unsigned int gfs2_ea_name2type(const char *name, const char **truncated_name); extern struct gfs2_eattr_operations gfs2_system_eaops; diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index f6b5e306a6c8..d7b92fba6998 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -68,11 +68,9 @@ static int ea_check_size(struct gfs2_sbd *sdp, struct gfs2_ea_request *er) return 0; } -typedef int (*ea_call_t) (struct gfs2_inode *ip, - struct buffer_head *bh, +typedef int (*ea_call_t) (struct gfs2_inode *ip, struct buffer_head *bh, struct gfs2_ea_header *ea, - struct gfs2_ea_header *prev, - void *private); + struct gfs2_ea_header *prev, void *private); static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, ea_call_t ea_call, void *data) @@ -86,9 +84,8 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, for (ea = GFS2_EA_BH2FIRST(bh);; prev = ea, ea = GFS2_EA2NEXT(ea)) { if (!GFS2_EA_REC_LEN(ea)) goto fail; - if (!(bh->b_data <= (char *)ea && - (char *)GFS2_EA2NEXT(ea) <= - bh->b_data + bh->b_size)) + if (!(bh->b_data <= (char *)ea && (char *)GFS2_EA2NEXT(ea) <= + bh->b_data + bh->b_size)) goto fail; if (!GFS2_EATYPE_VALID(ea->ea_type)) goto fail; @@ -118,8 +115,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) u64 *eablk, *end; int error; - error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, - DIO_START | DIO_WAIT, &bh); + error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_START | DIO_WAIT, &bh); if (error) return error; @@ -143,8 +139,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) break; bn = be64_to_cpu(*eablk); - error = gfs2_meta_read(ip->i_gl, bn, DIO_START | DIO_WAIT, - &eabh); + error = gfs2_meta_read(ip->i_gl, bn, DIO_START | DIO_WAIT, &eabh); if (error) break; error = ea_foreach_i(ip, eabh, ea_call, data); @@ -184,12 +179,6 @@ static int ea_find_i(struct gfs2_inode *ip, struct buffer_head *bh, } } -#if 0 - else if ((ip->i_di.di_flags & GFS2_DIF_EA_PACKED) && - er->er_type == GFS2_EATYPE_SYS) - return 1; -#endif - return 0; } @@ -246,11 +235,12 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, return 0; dataptrs = GFS2_EA2DATAPTRS(ea); - for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) + for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) { if (*dataptrs) { blks++; bn = be64_to_cpu(*dataptrs); } + } if (!blks) return 0; @@ -264,9 +254,8 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, if (error) return error; - error = gfs2_trans_begin(sdp, rgd->rd_ri.ri_length + - RES_DINODE + RES_EATTR + RES_STATFS + - RES_QUOTA, blks); + error = gfs2_trans_begin(sdp, rgd->rd_ri.ri_length + RES_DINODE + + RES_EATTR + RES_STATFS + RES_QUOTA, blks); if (error) goto out_gunlock; @@ -340,9 +329,7 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, if (error) goto out_quota; - error = ea_dealloc_unstuffed(ip, - bh, ea, prev, - (leave) ? &error : NULL); + error = ea_dealloc_unstuffed(ip, bh, ea, prev, (leave) ? &error : NULL); gfs2_glock_dq_uninit(&al->al_ri_gh); @@ -423,9 +410,7 @@ int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er) er->er_data_len = 0; } - error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_SHARED, LM_FLAG_ANY, - &i_gh); + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); if (error) return error; @@ -445,9 +430,9 @@ int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er) /** * ea_get_unstuffed - actually copies the unstuffed data into the * request buffer - * @ip: - * @ea: - * @data: + * @ip: The GFS2 inode + * @ea: The extended attribute header structure + * @data: The data to be copied * * Returns: errno */ @@ -492,8 +477,7 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, goto out; } - memcpy(data, - bh[x]->b_data + sizeof(struct gfs2_meta_header), + memcpy(data, bh[x]->b_data + sizeof(struct gfs2_meta_header), (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); amount -= sdp->sd_jbsize; @@ -511,9 +495,7 @@ int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el, char *data) { if (GFS2_EA_IS_STUFFED(el->el_ea)) { - memcpy(data, - GFS2_EA2DATA(el->el_ea), - GFS2_EA_DATA_LEN(el->el_ea)); + memcpy(data, GFS2_EA2DATA(el->el_ea), GFS2_EA_DATA_LEN(el->el_ea)); return 0; } else return ea_get_unstuffed(ip, el->el_ea, data); @@ -521,8 +503,8 @@ int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el, /** * gfs2_ea_get_i - - * @ip: - * @er: + * @ip: The GFS2 inode + * @er: The request structure * * Returns: actual size of data on success, -errno on error */ @@ -557,8 +539,8 @@ int gfs2_ea_get_i(struct gfs2_inode *ip, struct gfs2_ea_request *er) /** * gfs2_ea_get - - * @ip: - * @er: + * @ip: The GFS2 inode + * @er: The request structure * * Returns: actual size of data on success, -errno on error */ @@ -576,9 +558,7 @@ int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) er->er_data_len = 0; } - error = gfs2_glock_nq_init(ip->i_gl, - LM_ST_SHARED, LM_FLAG_ANY, - &i_gh); + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); if (error) return error; @@ -592,7 +572,7 @@ int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) /** * ea_alloc_blk - allocates a new block for extended attributes. * @ip: A pointer to the inode that's getting extended attributes - * @bhp: + * @bhp: Pointer to pointer to a struct buffer_head * * Returns: errno */ @@ -624,8 +604,8 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp) /** * ea_write - writes the request info to an ea, creating new blocks if * necessary - * @ip: inode that is being modified - * @ea: the location of the new ea in a block + * @ip: inode that is being modified + * @ea: the location of the new ea in a block * @er: the write request * * Note: does not update ea_rec_len or the GFS2_EAFLAG_LAST bin of ea_flags @@ -669,14 +649,14 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, ip->i_di.di_blocks++; - copy = (data_len > sdp->sd_jbsize) ? sdp->sd_jbsize : - data_len; + copy = data_len > sdp->sd_jbsize ? sdp->sd_jbsize : + data_len; memcpy(bh->b_data + mh_size, data, copy); if (copy < sdp->sd_jbsize) memset(bh->b_data + mh_size + copy, 0, sdp->sd_jbsize - copy); - *dataptr++ = cpu_to_be64((u64)bh->b_blocknr); + *dataptr++ = cpu_to_be64(bh->b_blocknr); data += copy; data_len -= copy; @@ -690,13 +670,11 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, } typedef int (*ea_skeleton_call_t) (struct gfs2_inode *ip, - struct gfs2_ea_request *er, - void *private); + struct gfs2_ea_request *er, void *private); static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, unsigned int blks, - ea_skeleton_call_t skeleton_call, - void *private) + ea_skeleton_call_t skeleton_call, void *private) { struct gfs2_alloc *al; struct buffer_head *dibh; @@ -1013,7 +991,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, goto out; if (private) - ea_set_remove_stuffed(ip, (struct gfs2_ea_location *)private); + ea_set_remove_stuffed(ip, private); out: brelse(indbh); @@ -1101,8 +1079,7 @@ int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) struct gfs2_holder i_gh; int error; - if (!er->er_name_len || - er->er_name_len > GFS2_EA_MAX_NAME_LEN) + if (!er->er_name_len || er->er_name_len > GFS2_EA_MAX_NAME_LEN) return -EINVAL; if (!er->er_data || !er->er_data_len) { er->er_data = NULL; @@ -1264,8 +1241,7 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, gfs2_trans_add_bh(ip->i_gl, bh[x], 1); - memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), - data, + memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), data, (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); amount -= sdp->sd_jbsize; @@ -1296,8 +1272,7 @@ int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el, return error; gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1); - memcpy(GFS2_EA2DATA(el->el_ea), - data, + memcpy(GFS2_EA2DATA(el->el_ea), data, GFS2_EA_DATA_LEN(el->el_ea)); } else error = ea_acl_chmod_unstuffed(ip, el->el_ea, data); @@ -1382,9 +1357,8 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) if (error) goto out_rlist_free; - error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + - RES_INDIRECT + RES_STATFS + - RES_QUOTA, blks); + error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + RES_INDIRECT + + RES_STATFS + RES_QUOTA, blks); if (error) goto out_gunlock; @@ -1457,8 +1431,8 @@ static int ea_dealloc_block(struct gfs2_inode *ip) if (error) return error; - error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_DINODE + - RES_STATFS + RES_QUOTA, 1); + error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_DINODE + RES_STATFS + + RES_QUOTA, 1); if (error) goto out_gunlock; diff --git a/fs/gfs2/eattr.h b/fs/gfs2/eattr.h index cb7c2d846765..ffa65947d686 100644 --- a/fs/gfs2/eattr.h +++ b/fs/gfs2/eattr.h @@ -46,7 +46,7 @@ ALIGN(sizeof(struct gfs2_ea_header) + (er)->er_name_len + \ #define GFS2_ERF_MODE 0x80000000 struct gfs2_ea_request { - char *er_name; + const char *er_name; char *er_data; unsigned int er_name_len; unsigned int er_data_len; @@ -87,13 +87,13 @@ static inline unsigned int gfs2_ea_strlen(struct gfs2_ea_header *ea) { switch (ea->ea_type) { case GFS2_EATYPE_USR: - return (5 + (ea->ea_name_len + 1)); + return 5 + ea->ea_name_len + 1; case GFS2_EATYPE_SYS: - return (7 + (ea->ea_name_len + 1)); + return 7 + ea->ea_name_len + 1; case GFS2_EATYPE_SECURITY: - return (9 + (ea->ea_name_len + 1)); + return 9 + ea->ea_name_len + 1; default: - return (0); + return 0; } } From a67cdbd4579c387c021a17c7447da8b88f2a94f4 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 5 Sep 2006 14:41:30 -0400 Subject: [PATCH 238/292] [GFS2] Style changes in logging code As per Jan Engelhardt's comments, removed some unused code and removed some brackets which were not required. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/log.c | 12 +----------- fs/gfs2/lops.c | 2 +- fs/gfs2/recovery.c | 4 ++-- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 571389012874..382a19eea1c7 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -177,7 +177,6 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks) gfs2_log_lock(sdp); } sdp->sd_log_blks_free -= blks; - /* printk(KERN_INFO "reserved %u blocks (%u left)\n", blks, sdp->sd_log_blks_free); */ gfs2_log_unlock(sdp); mutex_unlock(&sdp->sd_log_reserve_mutex); @@ -198,7 +197,6 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) gfs2_log_lock(sdp); sdp->sd_log_blks_free += blks; - /* printk(KERN_INFO "released %u blocks (%u left)\n", blks, sdp->sd_log_blks_free); */ gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); gfs2_log_unlock(sdp); @@ -213,9 +211,8 @@ static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) int bdy; error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, &new, &dbn, &bdy); - if (!(!error && dbn)) { + if (error || !dbn) printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, (unsigned long long)dbn, lbn); - } gfs2_assert_withdraw(sdp, !error && dbn); return dbn; @@ -414,13 +411,6 @@ static void log_flush_commit(struct gfs2_sbd *sdp) struct list_head *head = &sdp->sd_log_flush_list; struct gfs2_log_buf *lb; struct buffer_head *bh; -#if 0 - unsigned int d; - - d = log_distance(sdp, sdp->sd_log_flush_head, sdp->sd_log_head); - - gfs2_assert_withdraw(sdp, d + 1 == sdp->sd_log_blks_reserved); -#endif while (!list_empty(head)) { lb = list_entry(head->next, struct gfs2_log_buf, lb_list); diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 07655a755619..f8f6d4b56a01 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -518,7 +518,7 @@ static void databuf_lo_before_commit(struct gfs2_sbd *sdp) unsigned int num, n; __be64 *ptr = NULL; - offset += (2*sizeof(__be64) - 1); + offset += 2*sizeof(__be64) - 1; offset &= ~(2*sizeof(__be64) - 1); limit = (sdp->sd_sb.sb_bsize - offset)/sizeof(__be64); diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index ab55191926c3..a27569c5d85e 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -306,8 +306,8 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, u32 length; __be64 *ptr; unsigned int offset = sizeof(struct gfs2_log_descriptor); - offset += (sizeof(__be64)-1); - offset &= ~(sizeof(__be64)-1); + offset += sizeof(__be64) - 1; + offset &= ~(sizeof(__be64) - 1); while (start != end) { error = gfs2_replay_read_block(jd, start, &bh); From 48fac1790935ef2f9548d92e7c8ba604d1b80c12 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 5 Sep 2006 15:17:12 -0400 Subject: [PATCH 239/292] [GFS2] Remove unused code from quota As per Jan Engelhardt's request, some unused code is removed and some consts added in the quota code. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/quota.c | 63 ++++++++----------------------------------------- 1 file changed, 10 insertions(+), 53 deletions(-) diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index f5830befc307..fe1828ffebfa 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -503,24 +503,22 @@ void gfs2_quota_unhold(struct gfs2_inode *ip) static int sort_qd(const void *a, const void *b) { - struct gfs2_quota_data *qd_a = *(struct gfs2_quota_data **)a; - struct gfs2_quota_data *qd_b = *(struct gfs2_quota_data **)b; - int ret = 0; + const struct gfs2_quota_data *qd_a = *(const struct gfs2_quota_data **)a; + const struct gfs2_quota_data *qd_b = *(const struct gfs2_quota_data **)b; if (!test_bit(QDF_USER, &qd_a->qd_flags) != !test_bit(QDF_USER, &qd_b->qd_flags)) { if (test_bit(QDF_USER, &qd_a->qd_flags)) - ret = -1; + return -1; else - ret = 1; - } else { - if (qd_a->qd_id < qd_b->qd_id) - ret = -1; - else if (qd_a->qd_id > qd_b->qd_id) - ret = 1; + return 1; } + if (qd_a->qd_id < qd_b->qd_id) + return -1; + if (qd_a->qd_id > qd_b->qd_id) + return 1; - return ret; + return 0; } static void do_qc(struct gfs2_quota_data *qd, s64 change) @@ -622,17 +620,13 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, gfs2_trans_add_bh(ip->i_gl, bh, 0); kaddr = kmap_atomic(page, KM_USER0); - ptr = (__be64 *)(kaddr + offset); + ptr = kaddr + offset; value = (s64)be64_to_cpu(*ptr) + change; *ptr = cpu_to_be64(value); flush_dcache_page(page); kunmap_atomic(kaddr, KM_USER0); err = 0; qd->qd_qb.qb_magic = cpu_to_be32(GFS2_MAGIC); -#if 0 - qd->qd_qb.qb_limit = cpu_to_be64(q.qu_limit); - qd->qd_qb.qb_warn = cpu_to_be64(q.qu_warn); -#endif qd->qd_qb.qb_value = cpu_to_be64(value); unlock: unlock_page(page); @@ -1057,43 +1051,6 @@ int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, u32 id) return error; } -#if 0 -int gfs2_quota_read(struct gfs2_sbd *sdp, int user, u32 id, - struct gfs2_quota *q) -{ - struct gfs2_quota_data *qd; - struct gfs2_holder q_gh; - int error; - - if (((user) ? (id != current->fsuid) : (!in_group_p(id))) && - !capable(CAP_SYS_ADMIN)) - return -EACCES; - - error = qd_get(sdp, user, id, CREATE, &qd); - if (error) - return error; - - error = do_glock(qd, NO_FORCE, &q_gh); - if (error) - goto out; - - memset(q, 0, sizeof(struct gfs2_quota)); - q->qu_limit = be64_to_cpu(qd->qd_qb.qb_limit); - q->qu_warn = be64_to_cpu(qd->qd_qb.qb_warn); - q->qu_value = be64_to_cpu(qd->qd_qb.qb_value); - - spin_lock(&sdp->sd_quota_spin); - q->qu_value += qd->qd_change; - spin_unlock(&sdp->sd_quota_spin); - - gfs2_glock_dq_uninit(&q_gh); - -out: - qd_put(qd); - return error; -} -#endif /* 0 */ - int gfs2_quota_init(struct gfs2_sbd *sdp) { struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); From 2c1e52aa905f2223dc600cfeda6c0dc94fac8b81 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 5 Sep 2006 15:41:57 -0400 Subject: [PATCH 240/292] [GFS2] More style fixes As per Jan Engelhardt's follow up emails, here are a few small fixes which were missed earlier. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/rgrp.c | 13 +------------ fs/gfs2/rgrp.h | 5 ++++- fs/gfs2/sys.c | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index baa93c5d9592..7a5ab817ad9c 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -29,7 +29,7 @@ #include "ops_file.h" #include "util.h" -#define BFITNOENT (u32)~0 +#define BFITNOENT ((u32)~0) /* * These routines are used by the resource group routines (rgrp.c) @@ -693,17 +693,6 @@ struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip) return al; } -/** - * gfs2_alloc_put - throw away the struct gfs2_alloc for an inode - * @ip: the inode - * - */ - -void gfs2_alloc_put(struct gfs2_inode *ip) -{ - return; -} - /** * try_rgrp_fit - See if a given reservation will fit in a given RG * @rgd: the RG data diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h index 355895767387..9eedfd12bfff 100644 --- a/fs/gfs2/rgrp.h +++ b/fs/gfs2/rgrp.h @@ -30,7 +30,10 @@ void gfs2_rgrp_bh_put(struct gfs2_rgrpd *rgd); void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd); struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip); -void gfs2_alloc_put(struct gfs2_inode *ip); +static inline void gfs2_alloc_put(struct gfs2_inode *ip) +{ + return; /* Se we can see where ip->i_alloc is used */ +} int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line); diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index 7a282a4bde2a..0d7f0a4e3717 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -223,7 +223,7 @@ static struct kobj_type gfs2_ktype = { static struct kset gfs2_kset = { .subsys = &fs_subsys, - .kobj = {.name = "gfs2",}, + .kobj = {.name = "gfs2"}, .ktype = &gfs2_ktype, }; From 7b62536141927212158ab84ce2afda9319ae6f2d Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 5 Sep 2006 15:56:17 -0400 Subject: [PATCH 241/292] [GFS2] Add a comment in ops_export.c Ass a comment explaining the slightly odd construct used to pass error values back. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_export.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index 4b8c6a9893e4..470e8829e7f4 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -182,6 +182,10 @@ static struct dentry *gfs2_get_parent(struct dentry *child) if (!inode) return ERR_PTR(-ENOENT); + /* + * In case of an error, @inode carries the error value, and we + * have to return that as a(n invalid) pointer to dentry. + */ if (IS_ERR(inode)) return ERR_PTR(PTR_ERR(inode)); From c53921248c79197befa7caa4c17b1af5c077a2c2 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 5 Sep 2006 14:30:40 +0200 Subject: [PATCH 242/292] [GFS2] More style changes Remove redundant brackets Signed-off-by: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 4 ++-- fs/gfs2/dir.c | 4 ++-- fs/gfs2/log.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 0f9567fe5c8b..57caad7bc0d5 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -618,7 +618,7 @@ static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh, return error; top = (u64 *)(bh->b_data + mh_size) + - ((first) ? mp->mp_list[height] : 0); + (first ? mp->mp_list[height] : 0); bottom = (u64 *)(bh->b_data + mh_size) + sdp->sd_inptrs; } @@ -957,7 +957,7 @@ static int trunc_start(struct gfs2_inode *ip, u64 size) int error; error = gfs2_trans_begin(sdp, - RES_DINODE + ((journaled) ? RES_JDATA : 0), 0); + RES_DINODE + (journaled ? RES_JDATA : 0), 0); if (error) return error; diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index d74a52bda540..f3dbda216caf 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -284,7 +284,7 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, if (offset >= ip->i_di.di_size) return 0; - if ((offset + size) > ip->i_di.di_size) + if (offset + size > ip->i_di.di_size) size = ip->i_di.di_size - offset; if (!size) @@ -399,7 +399,7 @@ static int gfs2_dirent_find_space(const struct gfs2_dirent *dent, if (!dent->de_inum.no_addr) actual = GFS2_DIRENT_SIZE(0); - if ((totlen - actual) >= required) + if (totlen - actual >= required) return 1; return 0; } diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 382a19eea1c7..8fce592f4011 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -342,8 +342,8 @@ static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail, int pull) ail2_empty(sdp, new_tail); gfs2_log_lock(sdp); - sdp->sd_log_blks_free += dist - ((pull) ? 1 : 0); - /* printk(KERN_INFO "pull tail refunding %u blocks (%u left) pull=%d\n", dist - ((pull) ? 1 : 0), sdp->sd_log_blks_free, pull); */ + sdp->sd_log_blks_free += dist - (pull ? 1 : 0); + /* printk(KERN_INFO "pull tail refunding %u blocks (%u left) pull=%d\n", dist - (pull ? 1 : 0), sdp->sd_log_blks_free, pull); */ gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); gfs2_log_unlock(sdp); From 3204a6c05588788f7686bc45585185a9a4788430 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 6 Sep 2006 16:57:06 -0500 Subject: [PATCH 243/292] [GFS2] use snprintf for sysfs show Use snprintf(buf, PAGE_SIZE, ...) instead of sprintf for sysfs show methods. Per instructions in Documentation/filesystems/sysfs.txt Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/sys.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index 0d7f0a4e3717..88386d8dc05a 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -32,12 +32,12 @@ spinlock_t gfs2_sys_margs_lock; static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) { - return sprintf(buf, "%s\n", sdp->sd_vfs->s_id); + return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_vfs->s_id); } static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) { - return sprintf(buf, "%s\n", sdp->sd_fsname); + return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname); } static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) @@ -48,7 +48,7 @@ static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) count = sdp->sd_freeze_count; mutex_unlock(&sdp->sd_freeze_lock); - return sprintf(buf, "%u\n", count); + return snprintf(buf, PAGE_SIZE, "%u\n", count); } static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len) @@ -80,7 +80,7 @@ static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len) static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf) { unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags); - return sprintf(buf, "%u\n", b); + return snprintf(buf, PAGE_SIZE, "%u\n", b); } static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len) @@ -239,7 +239,7 @@ struct lockstruct_attr { #define LOCKSTRUCT_ATTR(name, fmt) \ static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ { \ - return sprintf(buf, fmt, sdp->sd_lockstruct.ls_##name); \ + return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \ } \ static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name) @@ -268,7 +268,7 @@ struct args_attr { #define ARGS_ATTR(name, fmt) \ static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ { \ - return sprintf(buf, fmt, sdp->sd_args.ar_##name); \ + return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \ } \ static struct args_attr args_attr_##name = __ATTR_RO(name) @@ -290,7 +290,8 @@ ARGS_ATTR(data, "%d\n"); /* one oddball doesn't fit the macro mold */ static ssize_t noatime_show(struct gfs2_sbd *sdp, char *buf) { - return sprintf(buf, "%d\n", !!test_bit(SDF_NOATIME, &sdp->sd_flags)); + return snprintf(buf, PAGE_SIZE, "%d\n", + !!test_bit(SDF_NOATIME, &sdp->sd_flags)); } static struct args_attr args_attr_noatime = __ATTR_RO(noatime); @@ -325,7 +326,8 @@ struct counters_attr { #define COUNTERS_ATTR(name, fmt) \ static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ { \ - return sprintf(buf, fmt, (unsigned int)atomic_read(&sdp->sd_##name)); \ + return snprintf(buf, PAGE_SIZE, fmt, \ + (unsigned int)atomic_read(&sdp->sd_##name)); \ } \ static struct counters_attr counters_attr_##name = __ATTR_RO(name) @@ -348,8 +350,9 @@ static struct attribute *counters_attrs[] = { static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf) { - return sprintf(buf, "%u %u\n", sdp->sd_tune.gt_quota_scale_num, - sdp->sd_tune.gt_quota_scale_den); + return snprintf(buf, PAGE_SIZE, "%u %u\n", + sdp->sd_tune.gt_quota_scale_num, + sdp->sd_tune.gt_quota_scale_den); } static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf, @@ -403,7 +406,7 @@ static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store) #define TUNE_ATTR_2(name, store) \ static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ { \ - return sprintf(buf, "%u\n", sdp->sd_tune.gt_##name); \ + return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \ } \ TUNE_ATTR_3(name, name##_show, store) From a1d144c71ddc11d3e9d9f29e92cf037da382a541 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 6 Sep 2006 17:01:40 -0500 Subject: [PATCH 244/292] [DLM] use snprintf in sysfs show Use snprintf(buf, PAGE_SIZE, ...) instead of sprintf in sysfs show methods. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lockspace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index ff83f80e43eb..109333c8ecb9 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -66,7 +66,7 @@ static ssize_t dlm_event_store(struct dlm_ls *ls, const char *buf, size_t len) static ssize_t dlm_id_show(struct dlm_ls *ls, char *buf) { - return sprintf(buf, "%u\n", ls->ls_global_id); + return snprintf(buf, PAGE_SIZE, "%u\n", ls->ls_global_id); } static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len) @@ -78,12 +78,12 @@ static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len) static ssize_t dlm_recover_status_show(struct dlm_ls *ls, char *buf) { uint32_t status = dlm_recover_status(ls); - return sprintf(buf, "%x\n", status); + return snprintf(buf, PAGE_SIZE, "%x\n", status); } static ssize_t dlm_recover_nodeid_show(struct dlm_ls *ls, char *buf) { - return sprintf(buf, "%d\n", ls->ls_recover_nodeid); + return snprintf(buf, PAGE_SIZE, "%d\n", ls->ls_recover_nodeid); } struct dlm_attr { From 62f140c173f2c85e15527eefc6e2fb3c37a97eb1 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 7 Sep 2006 09:54:55 -0400 Subject: [PATCH 245/292] [GFS2] Add brackets in locking/dlm/sysfs.c As per Jan Engelhardt's request. Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/sysfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c index 82bef017f944..c1237a91fc68 100644 --- a/fs/gfs2/locking/dlm/sysfs.c +++ b/fs/gfs2/locking/dlm/sysfs.c @@ -42,8 +42,9 @@ static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len) else if (val == 0) { clear_bit(DFL_BLOCK_LOCKS, &ls->flags); gdlm_submit_delayed(ls); - } else + } else { ret = -EINVAL; + } return ret; } From b8547856f9c158ff70effbcfd15969c908fbe1b3 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 7 Sep 2006 13:12:27 -0400 Subject: [PATCH 246/292] [GFS2] Add gfs2 superblock to glock hash function This is another patch preparing for sharing of the glock hash table between different gfs2 mounts. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index f2edc8b76121..00769674f2ea 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -83,12 +83,14 @@ static inline int relaxed_state_ok(unsigned int actual, unsigned requested, * Returns: The number of the corresponding hash bucket */ -static unsigned int gl_hash(const struct lm_lockname *name) +static unsigned int gl_hash(const struct gfs2_sbd *sdp, + const struct lm_lockname *name) { unsigned int h; h = jhash(&name->ln_number, sizeof(u64), 0); h = jhash(&name->ln_type, sizeof(unsigned int), h); + h = jhash(&sdp, sizeof(struct gfs2_sbd *), h); h &= GFS2_GL_HASH_MASK; return h; @@ -232,7 +234,7 @@ static struct gfs2_glock *search_bucket(struct gfs2_gl_hash_bucket *bucket, static struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, const struct lm_lockname *name) { - struct gfs2_gl_hash_bucket *bucket = &sdp->sd_gl_hash[gl_hash(name)]; + struct gfs2_gl_hash_bucket *bucket = &sdp->sd_gl_hash[gl_hash(sdp, name)]; struct gfs2_glock *gl; read_lock(&bucket->hb_lock); @@ -266,7 +268,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, name.ln_number = number; name.ln_type = glops->go_type; - bucket = &sdp->sd_gl_hash[gl_hash(&name)]; + bucket = &sdp->sd_gl_hash[gl_hash(sdp, &name)]; read_lock(&bucket->hb_lock); gl = search_bucket(bucket, sdp, &name); From 85d1da67f7e1239afa3494d05be87da6fc3ecada Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 7 Sep 2006 14:40:21 -0400 Subject: [PATCH 247/292] [GFS2] Move glock hash table out of superblock There are several reasons why we want to do this: - Firstly its large and thus we'll scale better with multiple GFS2 fs mounted at the same time - Secondly its easier to scale its size as required (thats a plan for later patches) - Thirdly, we can use kzalloc rather than vmalloc when allocating the superblock (its now only 4888 bytes) - Fourth its all part of my plan to eventually be able to use RCU with the glock hash. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 54 ++++++++++++++++++++++++++++---------------- fs/gfs2/glock.h | 2 ++ fs/gfs2/incore.h | 12 ++++------ fs/gfs2/main.c | 6 ++++- fs/gfs2/ops_fstype.c | 9 +------- 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 00769674f2ea..5759f52a1cf9 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -49,6 +49,8 @@ typedef void (*glock_examiner) (struct gfs2_glock * gl); static int gfs2_dump_lockstate(struct gfs2_sbd *sdp); static int dump_glock(struct gfs2_glock *gl); +static struct gfs2_gl_hash_bucket gl_hash_table[GFS2_GL_HASH_SIZE]; + /** * relaxed_state_ok - is a requested lock compatible with the current lock mode? * @actual: the current state of the lock @@ -231,10 +233,10 @@ static struct gfs2_glock *search_bucket(struct gfs2_gl_hash_bucket *bucket, * Returns: NULL, or the struct gfs2_glock with the requested number */ -static struct gfs2_glock *gfs2_glock_find(struct gfs2_sbd *sdp, +static struct gfs2_glock *gfs2_glock_find(const struct gfs2_sbd *sdp, const struct lm_lockname *name) { - struct gfs2_gl_hash_bucket *bucket = &sdp->sd_gl_hash[gl_hash(sdp, name)]; + struct gfs2_gl_hash_bucket *bucket = &gl_hash_table[gl_hash(sdp, name)]; struct gfs2_glock *gl; read_lock(&bucket->hb_lock); @@ -268,7 +270,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, name.ln_number = number; name.ln_type = glops->go_type; - bucket = &sdp->sd_gl_hash[gl_hash(sdp, &name)]; + bucket = &gl_hash_table[gl_hash(sdp, &name)]; read_lock(&bucket->hb_lock); gl = search_bucket(bucket, sdp, &name); @@ -648,9 +650,9 @@ static void gfs2_glmutex_lock(struct gfs2_glock *gl) set_bit(HIF_MUTEX, &gh.gh_iflags); spin_lock(&gl->gl_spin); - if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) + if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) { list_add_tail(&gh.gh_list, &gl->gl_waiters1); - else { + } else { gl->gl_owner = current; gl->gl_ip = (unsigned long)__builtin_return_address(0); complete(&gh.gh_wait); @@ -673,9 +675,9 @@ static int gfs2_glmutex_trylock(struct gfs2_glock *gl) int acquired = 1; spin_lock(&gl->gl_spin); - if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) + if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) { acquired = 0; - else { + } else { gl->gl_owner = current; gl->gl_ip = (unsigned long)__builtin_return_address(0); } @@ -830,9 +832,9 @@ static void xmote_bh(struct gfs2_glock *gl, unsigned int ret) spin_lock(&gl->gl_spin); list_del_init(&gh->gh_list); if (gl->gl_state == gh->gh_state || - gl->gl_state == LM_ST_UNLOCKED) + gl->gl_state == LM_ST_UNLOCKED) { gh->gh_error = 0; - else { + } else { if (gfs2_assert_warn(sdp, gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) == -1) fs_warn(sdp, "ret = 0x%.8X\n", ret); @@ -1090,8 +1092,7 @@ static int glock_wait_internal(struct gfs2_holder *gh) return gh->gh_error; gfs2_assert_withdraw(sdp, test_bit(HIF_HOLDER, &gh->gh_iflags)); - gfs2_assert_withdraw(sdp, relaxed_state_ok(gl->gl_state, - gh->gh_state, + gfs2_assert_withdraw(sdp, relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)); if (test_bit(HIF_FIRST, &gh->gh_iflags)) { @@ -1901,6 +1902,8 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, if (test_bit(GLF_PLUG, &gl->gl_flags)) continue; + if (gl->gl_sbd != sdp) + continue; /* examiner() must glock_put() */ gfs2_glock_hold(gl); @@ -1953,7 +1956,7 @@ void gfs2_scand_internal(struct gfs2_sbd *sdp) unsigned int x; for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { - examine_bucket(scan_glock, sdp, &sdp->sd_gl_hash[x]); + examine_bucket(scan_glock, sdp, &gl_hash_table[x]); cond_resched(); } } @@ -2012,7 +2015,7 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait) cont = 0; for (x = 0; x < GFS2_GL_HASH_SIZE; x++) - if (examine_bucket(clear_glock, sdp, &sdp->sd_gl_hash[x])) + if (examine_bucket(clear_glock, sdp, &gl_hash_table[x])) cont = 1; if (!wait || !cont) @@ -2114,14 +2117,13 @@ static int dump_glock(struct gfs2_glock *gl) spin_lock(&gl->gl_spin); - printk(KERN_INFO "Glock 0x%p (%u, %llu)\n", - gl, - gl->gl_name.ln_type, + printk(KERN_INFO "Glock 0x%p (%u, %llu)\n", gl, gl->gl_name.ln_type, (unsigned long long)gl->gl_name.ln_number); printk(KERN_INFO " gl_flags ="); - for (x = 0; x < 32; x++) + for (x = 0; x < 32; x++) { if (test_bit(x, &gl->gl_flags)) printk(" %u", x); + } printk(" \n"); printk(KERN_INFO " gl_ref = %d\n", atomic_read(&gl->gl_ref.refcount)); printk(KERN_INFO " gl_state = %u\n", gl->gl_state); @@ -2136,8 +2138,7 @@ static int dump_glock(struct gfs2_glock *gl) printk(KERN_INFO " reclaim = %s\n", (list_empty(&gl->gl_reclaim)) ? "no" : "yes"); if (gl->gl_aspace) - printk(KERN_INFO " aspace = 0x%p nrpages = %lu\n", - gl->gl_aspace, + printk(KERN_INFO " aspace = 0x%p nrpages = %lu\n", gl->gl_aspace, gl->gl_aspace->i_mapping->nrpages); else printk(KERN_INFO " aspace = no\n"); @@ -2203,13 +2204,15 @@ static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) int error = 0; for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { - bucket = &sdp->sd_gl_hash[x]; + bucket = &gl_hash_table[x]; read_lock(&bucket->hb_lock); list_for_each_entry(gl, &bucket->hb_list, gl_list) { if (test_bit(GLF_PLUG, &gl->gl_flags)) continue; + if (gl->gl_sbd != sdp) + continue; error = dump_glock(gl); if (error) @@ -2226,3 +2229,14 @@ static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) return error; } +int __init gfs2_glock_init(void) +{ + unsigned i; + for(i = 0; i < GFS2_GL_HASH_SIZE; i++) { + struct gfs2_gl_hash_bucket *hb = &gl_hash_table[i]; + rwlock_init(&hb->hb_lock); + INIT_LIST_HEAD(&hb->hb_list); + } + return 0; +} + diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 2e1d32866321..0febca3d6d47 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -150,4 +150,6 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp); void gfs2_scand_internal(struct gfs2_sbd *sdp); void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait); +int __init gfs2_glock_init(void); + #endif /* __GLOCK_DOT_H__ */ diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 225924ca6b3e..61849607211f 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -30,7 +30,6 @@ struct gfs2_quota_data; struct gfs2_trans; struct gfs2_ail; struct gfs2_jdesc; -struct gfs2_gl_hash_bucket; struct gfs2_sbd; typedef void (*gfs2_glop_bh_t) (struct gfs2_glock *gl, unsigned int ret); @@ -107,6 +106,11 @@ struct gfs2_bufdata { struct list_head bd_ail_gl_list; }; +struct gfs2_gl_hash_bucket { + rwlock_t hb_lock; + struct list_head hb_list; +}; + struct gfs2_glock_operations { void (*go_xmote_th) (struct gfs2_glock * gl, unsigned int state, int flags); @@ -442,11 +446,6 @@ struct gfs2_tune { unsigned int gt_statfs_slow; }; -struct gfs2_gl_hash_bucket { - rwlock_t hb_lock; - struct list_head hb_list; -}; - enum { SDF_JOURNAL_CHECKED = 0, SDF_JOURNAL_LIVE = 1, @@ -489,7 +488,6 @@ struct gfs2_sbd { /* Lock Stuff */ struct lm_lockstruct sd_lockstruct; - struct gfs2_gl_hash_bucket sd_gl_hash[GFS2_GL_HASH_SIZE]; struct list_head sd_reclaim_list; spinlock_t sd_reclaim_lock; wait_queue_head_t sd_reclaim_wq; diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index 143fda727a9c..2bdf246436c7 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -23,6 +23,7 @@ #include "ops_fstype.h" #include "sys.h" #include "util.h" +#include "glock.h" static void gfs2_init_inode_once(void *foo, kmem_cache_t *cachep, unsigned long flags) { @@ -69,8 +70,11 @@ static int __init init_gfs2_fs(void) if (error) return error; - error = -ENOMEM; + error = gfs2_glock_init(); + if (error) + goto fail; + error = -ENOMEM; gfs2_glock_cachep = kmem_cache_create("gfs2_glock", sizeof(struct gfs2_glock), 0, 0, diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index c94422b30ceb..f5140bdc1027 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -45,23 +45,16 @@ extern struct dentry_operations gfs2_dops; static struct gfs2_sbd *init_sbd(struct super_block *sb) { struct gfs2_sbd *sdp; - unsigned int x; - sdp = vmalloc(sizeof(struct gfs2_sbd)); + sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL); if (!sdp) return NULL; - memset(sdp, 0, sizeof(struct gfs2_sbd)); - sb->s_fs_info = sdp; sdp->sd_vfs = sb; gfs2_tune_init(&sdp->sd_tune); - for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { - rwlock_init(&sdp->sd_gl_hash[x].hb_lock); - INIT_LIST_HEAD(&sdp->sd_gl_hash[x].hb_list); - } INIT_LIST_HEAD(&sdp->sd_reclaim_list); spin_lock_init(&sdp->sd_reclaim_lock); init_waitqueue_head(&sdp->sd_reclaim_wq); From b9201ce9a826f5ae4a8e153b52cf5d29f525ca11 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 7 Sep 2006 14:46:39 -0400 Subject: [PATCH 248/292] [GFS2] Forgot to remove unused include vmalloc.h Excatly as the subject line says. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_fstype.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index f5140bdc1027..f4397ce51482 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include From 1c089c325d5cda0f64a3cf8edf3aaafa148f200a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 7 Sep 2006 15:50:20 -0400 Subject: [PATCH 249/292] [GFS2] Remove one typedef This removes one of the typedefs from the locking interface. It is replaced by a forward declaration of the gfs2 superblock. The other two are not so easy to solve since in their case, they can refer to one of two possible structures. Cc: David Teigland Cc: Jan Engelhardt Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 5 ++--- fs/gfs2/glock.h | 2 +- fs/gfs2/lm_interface.h | 9 ++++----- fs/gfs2/locking.c | 6 +++--- fs/gfs2/locking/dlm/lock_dlm.h | 2 +- fs/gfs2/locking/dlm/mount.c | 8 ++++---- fs/gfs2/locking/dlm/sysfs.c | 2 +- fs/gfs2/locking/dlm/thread.c | 6 +++--- fs/gfs2/locking/nolock/main.c | 2 +- 9 files changed, 20 insertions(+), 22 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 5759f52a1cf9..87b37fe269b6 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1704,7 +1704,7 @@ static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name, /** * gfs2_glock_cb - Callback used by locking module - * @fsdata: Pointer to the superblock + * @sdp: Pointer to the superblock * @type: Type of callback * @data: Type dependent data pointer * @@ -1713,9 +1713,8 @@ static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name, * a journal from another client needs to be recovered. */ -void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data) +void gfs2_glock_cb(struct gfs2_sbd *sdp, unsigned int type, void *data) { - struct gfs2_sbd *sdp = (struct gfs2_sbd *)fsdata; switch (type) { case LM_CB_NEED_E: diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 0febca3d6d47..e3bf4bcd4b29 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -140,7 +140,7 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl, int gfs2_lvb_hold(struct gfs2_glock *gl); void gfs2_lvb_unhold(struct gfs2_glock *gl); -void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data); +void gfs2_glock_cb(struct gfs2_sbd *sdp, unsigned int type, void *data); void gfs2_iopen_go_callback(struct gfs2_glock *gl, unsigned int state); diff --git a/fs/gfs2/lm_interface.h b/fs/gfs2/lm_interface.h index e2dfc3da4da9..75835e0f4254 100644 --- a/fs/gfs2/lm_interface.h +++ b/fs/gfs2/lm_interface.h @@ -17,10 +17,9 @@ typedef void lm_lockspace_t; typedef void lm_lock_t; -typedef void lm_fsdata_t; +struct gfs2_sbd; -typedef void (*lm_callback_t) (lm_fsdata_t *fsdata, unsigned int type, - void *data); +typedef void (*lm_callback_t) (struct gfs2_sbd *sdp, unsigned int type, void *data); /* * lm_mount() flags @@ -183,7 +182,7 @@ struct lm_lockops { */ int (*lm_mount) (char *table_name, char *host_data, - lm_callback_t cb, lm_fsdata_t *fsdata, + lm_callback_t cb, struct gfs2_sbd *sdp, unsigned int min_lvb_size, int flags, struct lm_lockstruct *lockstruct, struct kobject *fskobj); @@ -275,7 +274,7 @@ void gfs2_unregister_lockproto(struct lm_lockops *proto); */ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, - lm_callback_t cb, lm_fsdata_t *fsdata, + lm_callback_t cb, struct gfs2_sbd *sdp, unsigned int min_lvb_size, int flags, struct lm_lockstruct *lockstruct, struct kobject *fskobj); diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c index fce2001e5e25..31421ee6d863 100644 --- a/fs/gfs2/locking.c +++ b/fs/gfs2/locking.c @@ -99,7 +99,7 @@ void gfs2_unregister_lockproto(struct lm_lockops *proto) * @table_name - the name of the lock space * @host_data - data specific to this host * @cb - the callback to the code using the lock module - * @fsdata - data to pass back with the callback + * @sdp - The GFS2 superblock * @min_lvb_size - the mininum LVB size that the caller can deal with * @flags - LM_MFLAG_* * @lockstruct - a structure returned describing the mount @@ -108,7 +108,7 @@ void gfs2_unregister_lockproto(struct lm_lockops *proto) */ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, - lm_callback_t cb, lm_fsdata_t *fsdata, + lm_callback_t cb, struct gfs2_sbd *sdp, unsigned int min_lvb_size, int flags, struct lm_lockstruct *lockstruct, struct kobject *fskobj) @@ -147,7 +147,7 @@ retry: goto retry; } - error = lw->lw_ops->lm_mount(table_name, host_data, cb, fsdata, + error = lw->lw_ops->lm_mount(table_name, host_data, cb, sdp, min_lvb_size, flags, lockstruct, fskobj); if (error) module_put(lw->lw_ops->lm_owner); diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h index c7b6e370258f..e6898d236521 100644 --- a/fs/gfs2/locking/dlm/lock_dlm.h +++ b/fs/gfs2/locking/dlm/lock_dlm.h @@ -67,7 +67,7 @@ struct gdlm_ls { int fsflags; dlm_lockspace_t *dlm_lockspace; lm_callback_t fscb; - lm_fsdata_t *fsdata; + struct gfs2_sbd *sdp; int recover_jid; int recover_jid_done; int recover_jid_status; diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c index 82ac00af84a3..8a1764f4d71c 100644 --- a/fs/gfs2/locking/dlm/mount.c +++ b/fs/gfs2/locking/dlm/mount.c @@ -14,7 +14,7 @@ int gdlm_drop_period; struct lm_lockops gdlm_ops; -static struct gdlm_ls *init_gdlm(lm_callback_t cb, lm_fsdata_t *fsdata, +static struct gdlm_ls *init_gdlm(lm_callback_t cb, struct gfs2_sbd *sdp, int flags, char *table_name) { struct gdlm_ls *ls; @@ -27,7 +27,7 @@ static struct gdlm_ls *init_gdlm(lm_callback_t cb, lm_fsdata_t *fsdata, ls->drop_locks_count = gdlm_drop_count; ls->drop_locks_period = gdlm_drop_period; ls->fscb = cb; - ls->fsdata = fsdata; + ls->sdp = sdp; ls->fsflags = flags; spin_lock_init(&ls->async_lock); INIT_LIST_HEAD(&ls->complete); @@ -120,7 +120,7 @@ static int make_args(struct gdlm_ls *ls, char *data_arg, int *nodir) } static int gdlm_mount(char *table_name, char *host_data, - lm_callback_t cb, lm_fsdata_t *fsdata, + lm_callback_t cb, struct gfs2_sbd *sdp, unsigned int min_lvb_size, int flags, struct lm_lockstruct *lockstruct, struct kobject *fskobj) @@ -131,7 +131,7 @@ static int gdlm_mount(char *table_name, char *host_data, if (min_lvb_size > GDLM_LVB_SIZE) goto out; - ls = init_gdlm(cb, fsdata, flags, table_name); + ls = init_gdlm(cb, sdp, flags, table_name); if (!ls) goto out; diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c index c1237a91fc68..29ae06f94944 100644 --- a/fs/gfs2/locking/dlm/sysfs.c +++ b/fs/gfs2/locking/dlm/sysfs.c @@ -102,7 +102,7 @@ static ssize_t recover_show(struct gdlm_ls *ls, char *buf) static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len) { ls->recover_jid = simple_strtol(buf, NULL, 0); - ls->fscb(ls->fsdata, LM_CB_NEED_RECOVERY, &ls->recover_jid); + ls->fscb(ls->sdp, LM_CB_NEED_RECOVERY, &ls->recover_jid); return len; } diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c index d4895ec242f6..554bf882a4c2 100644 --- a/fs/gfs2/locking/dlm/thread.c +++ b/fs/gfs2/locking/dlm/thread.c @@ -41,7 +41,7 @@ static void process_blocking(struct gdlm_lock *lp, int bast_mode) gdlm_assert(0, "unknown bast mode %u", lp->bast_mode); } - ls->fscb(ls->fsdata, cb, &lp->lockname); + ls->fscb(ls->sdp, cb, &lp->lockname); } static void process_complete(struct gdlm_lock *lp) @@ -232,7 +232,7 @@ out: (lp->cur > DLM_LOCK_NL) && (prev_mode > DLM_LOCK_NL)) acb.lc_ret |= LM_OUT_CACHEABLE; - ls->fscb(ls->fsdata, LM_CB_ASYNC, &acb); + ls->fscb(ls->sdp, LM_CB_ASYNC, &acb); } static inline int no_work(struct gdlm_ls *ls, int blocking) @@ -318,7 +318,7 @@ static int gdlm_thread(void *data) gdlm_do_lock(lp); if (drop) - ls->fscb(ls->fsdata, LM_CB_DROPLOCKS, NULL); + ls->fscb(ls->sdp, LM_CB_DROPLOCKS, NULL); schedule(); } diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index 95a29914730a..e326079430a2 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -24,7 +24,7 @@ struct nolock_lockspace { static struct lm_lockops nolock_ops; static int nolock_mount(char *table_name, char *host_data, - lm_callback_t cb, lm_fsdata_t *fsdata, + lm_callback_t cb, struct gfs2_sbd *sdp, unsigned int min_lvb_size, int flags, struct lm_lockstruct *lockstruct, struct kobject *fskobj) From 5ce311ebdb90429519f7c6d2092e4ae6ca8cba74 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 7 Sep 2006 17:35:48 -0400 Subject: [PATCH 250/292] [GFS2] Remove unused sync_lvb code from lock modules This code is no longer used for anything and can be removed from the locking modules. The sync_lvb function is not required as this happens automatically with the current locking system. Signed-off-by: Steven Whitehouse --- fs/gfs2/lm_interface.h | 1 - fs/gfs2/locking/dlm/lock.c | 17 ----------------- fs/gfs2/locking/dlm/lock_dlm.h | 1 - fs/gfs2/locking/dlm/mount.c | 1 - fs/gfs2/locking/nolock/main.c | 12 ------------ 5 files changed, 32 deletions(-) diff --git a/fs/gfs2/lm_interface.h b/fs/gfs2/lm_interface.h index 75835e0f4254..148136a34625 100644 --- a/fs/gfs2/lm_interface.h +++ b/fs/gfs2/lm_interface.h @@ -211,7 +211,6 @@ struct lm_lockops { int (*lm_hold_lvb) (lm_lock_t *lock, char **lvbp); void (*lm_unhold_lvb) (lm_lock_t *lock, char *lvb); - void (*lm_sync_lvb) (lm_lock_t *lock, char *lvb); /* * Posix Lock oriented operations diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index dceea419b94b..e4359b1b7174 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -490,23 +490,6 @@ void gdlm_unhold_lvb(lm_lock_t *lock, char *lvb) gdlm_del_lvb(lp); } -void gdlm_sync_lvb(lm_lock_t *lock, char *lvb) -{ - struct gdlm_lock *lp = (struct gdlm_lock *) lock; - - if (lp->cur != DLM_LOCK_EX) - return; - - init_completion(&lp->ast_wait); - set_bit(LFL_SYNC_LVB, &lp->flags); - - lp->req = DLM_LOCK_EX; - lp->lkf = make_flags(lp, 0, lp->cur, lp->req); - - gdlm_do_lock(lp); - wait_for_completion(&lp->ast_wait); -} - void gdlm_submit_delayed(struct gdlm_ls *ls) { struct gdlm_lock *lp, *safe; diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h index e6898d236521..a4f534a0ecff 100644 --- a/fs/gfs2/locking/dlm/lock_dlm.h +++ b/fs/gfs2/locking/dlm/lock_dlm.h @@ -172,7 +172,6 @@ unsigned int gdlm_unlock(lm_lock_t *, unsigned int); void gdlm_cancel(lm_lock_t *); int gdlm_hold_lvb(lm_lock_t *, char **); void gdlm_unhold_lvb(lm_lock_t *, char *); -void gdlm_sync_lvb(lm_lock_t *, char *); /* plock.c */ diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c index 8a1764f4d71c..832fb819a2b5 100644 --- a/fs/gfs2/locking/dlm/mount.c +++ b/fs/gfs2/locking/dlm/mount.c @@ -249,7 +249,6 @@ struct lm_lockops gdlm_ops = { .lm_cancel = gdlm_cancel, .lm_hold_lvb = gdlm_hold_lvb, .lm_unhold_lvb = gdlm_unhold_lvb, - .lm_sync_lvb = gdlm_sync_lvb, .lm_recovery_done = gdlm_recovery_done, .lm_owner = THIS_MODULE, }; diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index e326079430a2..ba7399787f62 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -162,17 +162,6 @@ static void nolock_unhold_lvb(lm_lock_t *lock, char *lvb) kfree(lvb); } -/** - * nolock_sync_lvb - sync out the value of a lvb - * @lock: the lock the LVB is associated with - * @lvb: the lock value block - * - */ - -static void nolock_sync_lvb(lm_lock_t *lock, char *lvb) -{ -} - static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl) { @@ -221,7 +210,6 @@ static struct lm_lockops nolock_ops = { .lm_cancel = nolock_cancel, .lm_hold_lvb = nolock_hold_lvb, .lm_unhold_lvb = nolock_unhold_lvb, - .lm_sync_lvb = nolock_sync_lvb, .lm_plock_get = nolock_plock_get, .lm_plock = nolock_plock, .lm_punlock = nolock_punlock, From a2c4580797f62b0dd9a48f1e0ce3fe8b8fd76262 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 8 Sep 2006 10:13:03 -0400 Subject: [PATCH 251/292] [GFS2] vfree should be kfree This was missed in an earlier patch when changing over from vmalloc to kmalloc for the superblock. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_fstype.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index f4397ce51482..e8b7a1ae163b 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -769,7 +769,7 @@ fail_lm: fail_sys: gfs2_sys_fs_del(sdp); fail: - vfree(sdp); + kfree(sdp); sb->s_fs_info = NULL; return error; } From 9b47c11d1cbedcba685c9bd90c73fd41acdfab0e Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 8 Sep 2006 10:17:58 -0400 Subject: [PATCH 252/292] [GFS2] Use void * instead of typedef for locking module interface As requested by Jan Engelhardt, this removes the typedefs in the locking module interface and replaces them with void *. Also since we are changing the interface, I've added a few consts as well. Cc: Jan Engelhardt Cc: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 3 +- fs/gfs2/glock.h | 2 +- fs/gfs2/incore.h | 2 +- fs/gfs2/lm.c | 14 ++++----- fs/gfs2/lm.h | 14 ++++----- fs/gfs2/lm_interface.h | 57 +++++++++++++--------------------- fs/gfs2/locking.c | 10 +++--- fs/gfs2/locking/dlm/lock.c | 32 +++++++++---------- fs/gfs2/locking/dlm/lock_dlm.h | 22 ++++++------- fs/gfs2/locking/dlm/mount.c | 24 +++++++------- fs/gfs2/locking/dlm/plock.c | 15 +++++---- fs/gfs2/locking/nolock/main.c | 44 +++++++++++++------------- 12 files changed, 113 insertions(+), 126 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 87b37fe269b6..92aa0e8c9099 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1713,8 +1713,9 @@ static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name, * a journal from another client needs to be recovered. */ -void gfs2_glock_cb(struct gfs2_sbd *sdp, unsigned int type, void *data) +void gfs2_glock_cb(void *cb_data, unsigned int type, void *data) { + struct gfs2_sbd *sdp = cb_data; switch (type) { case LM_CB_NEED_E: diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index e3bf4bcd4b29..52b8a308635a 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -140,7 +140,7 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl, int gfs2_lvb_hold(struct gfs2_glock *gl); void gfs2_lvb_unhold(struct gfs2_glock *gl); -void gfs2_glock_cb(struct gfs2_sbd *sdp, unsigned int type, void *data); +void gfs2_glock_cb(void *cb_data, unsigned int type, void *data); void gfs2_iopen_go_callback(struct gfs2_glock *gl, unsigned int state); diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 61849607211f..9f5d98ff823a 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -187,7 +187,7 @@ struct gfs2_glock { struct gfs2_holder *gl_req_gh; gfs2_glop_bh_t gl_req_bh; - lm_lock_t *gl_lock; + void *gl_lock; char *gl_lvb; atomic_t gl_lvb_count; diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index e60f95cae6c5..4e23aa5ef75d 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -122,7 +122,7 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) } int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, - lm_lock_t **lockp) + void **lockp) { int error = -EIO; if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) @@ -131,13 +131,13 @@ int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, return error; } -void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock) +void gfs2_lm_put_lock(struct gfs2_sbd *sdp, void *lock) { if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) sdp->sd_lockstruct.ls_ops->lm_put_lock(lock); } -unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, +unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock, unsigned int cur_state, unsigned int req_state, unsigned int flags) { @@ -148,7 +148,7 @@ unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, return ret; } -unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, +unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, void *lock, unsigned int cur_state) { int ret = 0; @@ -157,13 +157,13 @@ unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, return ret; } -void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock) +void gfs2_lm_cancel(struct gfs2_sbd *sdp, void *lock) { if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) sdp->sd_lockstruct.ls_ops->lm_cancel(lock); } -int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp) +int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp) { int error = -EIO; if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) @@ -171,7 +171,7 @@ int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp) return error; } -void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb) +void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, void *lock, char *lvb) { if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(lock, lvb); diff --git a/fs/gfs2/lm.h b/fs/gfs2/lm.h index 6b890e73e6c1..21cdc30ee08c 100644 --- a/fs/gfs2/lm.h +++ b/fs/gfs2/lm.h @@ -20,16 +20,16 @@ void gfs2_lm_unmount(struct gfs2_sbd *sdp); int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) __attribute__ ((format(printf, 2, 3))); int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name, - lm_lock_t **lockp); -void gfs2_lm_put_lock(struct gfs2_sbd *sdp, lm_lock_t *lock); -unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, lm_lock_t *lock, + void **lockp); +void gfs2_lm_put_lock(struct gfs2_sbd *sdp, void *lock); +unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock, unsigned int cur_state, unsigned int req_state, unsigned int flags); -unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, lm_lock_t *lock, +unsigned int gfs2_lm_unlock(struct gfs2_sbd *sdp, void *lock, unsigned int cur_state); -void gfs2_lm_cancel(struct gfs2_sbd *sdp, lm_lock_t *lock); -int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char **lvbp); -void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, lm_lock_t *lock, char *lvb); +void gfs2_lm_cancel(struct gfs2_sbd *sdp, void *lock); +int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp); +void gfs2_lm_unhold_lvb(struct gfs2_sbd *sdp, void *lock, char *lvb); int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, struct file *file, struct file_lock *fl); int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name, diff --git a/fs/gfs2/lm_interface.h b/fs/gfs2/lm_interface.h index 148136a34625..1418fdc9ac02 100644 --- a/fs/gfs2/lm_interface.h +++ b/fs/gfs2/lm_interface.h @@ -10,16 +10,8 @@ #ifndef __LM_INTERFACE_DOT_H__ #define __LM_INTERFACE_DOT_H__ -/* - * Opaque handles represent the lock module's lockspace structure, the lock - * module's lock structures, and GFS's file system (superblock) structure. - */ -typedef void lm_lockspace_t; -typedef void lm_lock_t; -struct gfs2_sbd; - -typedef void (*lm_callback_t) (struct gfs2_sbd *sdp, unsigned int type, void *data); +typedef void (*lm_callback_t) (void *ptr, unsigned int type, void *data); /* * lm_mount() flags @@ -175,64 +167,60 @@ struct lm_async_cb { struct lm_lockstruct; struct lm_lockops { - char lm_proto_name[256]; + const char *lm_proto_name; /* * Mount/Unmount */ int (*lm_mount) (char *table_name, char *host_data, - lm_callback_t cb, struct gfs2_sbd *sdp, + lm_callback_t cb, void *cb_data, unsigned int min_lvb_size, int flags, struct lm_lockstruct *lockstruct, struct kobject *fskobj); - void (*lm_others_may_mount) (lm_lockspace_t *lockspace); + void (*lm_others_may_mount) (void *lockspace); - void (*lm_unmount) (lm_lockspace_t *lockspace); + void (*lm_unmount) (void *lockspace); - void (*lm_withdraw) (lm_lockspace_t *lockspace); + void (*lm_withdraw) (void *lockspace); /* * Lock oriented operations */ - int (*lm_get_lock) (lm_lockspace_t *lockspace, - struct lm_lockname *name, lm_lock_t **lockp); + int (*lm_get_lock) (void *lockspace, struct lm_lockname *name, void **lockp); - void (*lm_put_lock) (lm_lock_t *lock); + void (*lm_put_lock) (void *lock); - unsigned int (*lm_lock) (lm_lock_t *lock, unsigned int cur_state, + unsigned int (*lm_lock) (void *lock, unsigned int cur_state, unsigned int req_state, unsigned int flags); - unsigned int (*lm_unlock) (lm_lock_t *lock, unsigned int cur_state); + unsigned int (*lm_unlock) (void *lock, unsigned int cur_state); - void (*lm_cancel) (lm_lock_t *lock); + void (*lm_cancel) (void *lock); - int (*lm_hold_lvb) (lm_lock_t *lock, char **lvbp); - void (*lm_unhold_lvb) (lm_lock_t *lock, char *lvb); + int (*lm_hold_lvb) (void *lock, char **lvbp); + void (*lm_unhold_lvb) (void *lock, char *lvb); /* * Posix Lock oriented operations */ - int (*lm_plock_get) (lm_lockspace_t *lockspace, - struct lm_lockname *name, + int (*lm_plock_get) (void *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl); - int (*lm_plock) (lm_lockspace_t *lockspace, - struct lm_lockname *name, + int (*lm_plock) (void *lockspace, struct lm_lockname *name, struct file *file, int cmd, struct file_lock *fl); - int (*lm_punlock) (lm_lockspace_t *lockspace, - struct lm_lockname *name, + int (*lm_punlock) (void *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl); /* * Client oriented operations */ - void (*lm_recovery_done) (lm_lockspace_t *lockspace, unsigned int jid, + void (*lm_recovery_done) (void *lockspace, unsigned int jid, unsigned int message); struct module *lm_owner; @@ -253,8 +241,8 @@ struct lm_lockstruct { unsigned int ls_jid; unsigned int ls_first; unsigned int ls_lvb_size; - lm_lockspace_t *ls_lockspace; - struct lm_lockops *ls_ops; + void *ls_lockspace; + const struct lm_lockops *ls_ops; int ls_flags; }; @@ -263,9 +251,8 @@ struct lm_lockstruct { * with these functions. */ -int gfs2_register_lockproto(struct lm_lockops *proto); - -void gfs2_unregister_lockproto(struct lm_lockops *proto); +int gfs2_register_lockproto(const struct lm_lockops *proto); +void gfs2_unregister_lockproto(const struct lm_lockops *proto); /* * Lock module top interface. GFS calls these functions when mounting or @@ -273,7 +260,7 @@ void gfs2_unregister_lockproto(struct lm_lockops *proto); */ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, - lm_callback_t cb, struct gfs2_sbd *sdp, + lm_callback_t cb, void *cb_data, unsigned int min_lvb_size, int flags, struct lm_lockstruct *lockstruct, struct kobject *fskobj); diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c index 31421ee6d863..65eca48b2eae 100644 --- a/fs/gfs2/locking.c +++ b/fs/gfs2/locking.c @@ -21,7 +21,7 @@ struct lmh_wrapper { struct list_head lw_list; - struct lm_lockops *lw_ops; + const struct lm_lockops *lw_ops; }; /* List of registered low-level locking protocols. A file system selects one @@ -37,7 +37,7 @@ static DEFINE_MUTEX(lmh_lock); * Returns: 0 on success, -EXXX on failure */ -int gfs2_register_lockproto(struct lm_lockops *proto) +int gfs2_register_lockproto(const struct lm_lockops *proto) { struct lmh_wrapper *lw; @@ -72,7 +72,7 @@ int gfs2_register_lockproto(struct lm_lockops *proto) * */ -void gfs2_unregister_lockproto(struct lm_lockops *proto) +void gfs2_unregister_lockproto(const struct lm_lockops *proto) { struct lmh_wrapper *lw; @@ -108,7 +108,7 @@ void gfs2_unregister_lockproto(struct lm_lockops *proto) */ int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data, - lm_callback_t cb, struct gfs2_sbd *sdp, + lm_callback_t cb, void *cb_data, unsigned int min_lvb_size, int flags, struct lm_lockstruct *lockstruct, struct kobject *fskobj) @@ -147,7 +147,7 @@ retry: goto retry; } - error = lw->lw_ops->lm_mount(table_name, host_data, cb, sdp, + error = lw->lw_ops->lm_mount(table_name, host_data, cb, cb_data, min_lvb_size, flags, lockstruct, fskobj); if (error) module_put(lw->lw_ops->lm_owner); diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c index e4359b1b7174..b167addf9fd1 100644 --- a/fs/gfs2/locking/dlm/lock.c +++ b/fs/gfs2/locking/dlm/lock.c @@ -207,21 +207,21 @@ void gdlm_delete_lp(struct gdlm_lock *lp) kfree(lp); } -int gdlm_get_lock(lm_lockspace_t *lockspace, struct lm_lockname *name, - lm_lock_t **lockp) +int gdlm_get_lock(void *lockspace, struct lm_lockname *name, + void **lockp) { struct gdlm_lock *lp; int error; - error = gdlm_create_lp((struct gdlm_ls *) lockspace, name, &lp); + error = gdlm_create_lp(lockspace, name, &lp); - *lockp = (lm_lock_t *) lp; + *lockp = lp; return error; } -void gdlm_put_lock(lm_lock_t *lock) +void gdlm_put_lock(void *lock) { - gdlm_delete_lp((struct gdlm_lock *) lock); + gdlm_delete_lp(lock); } unsigned int gdlm_do_lock(struct gdlm_lock *lp) @@ -305,10 +305,10 @@ static unsigned int gdlm_do_unlock(struct gdlm_lock *lp) return LM_OUT_ASYNC; } -unsigned int gdlm_lock(lm_lock_t *lock, unsigned int cur_state, +unsigned int gdlm_lock(void *lock, unsigned int cur_state, unsigned int req_state, unsigned int flags) { - struct gdlm_lock *lp = (struct gdlm_lock *) lock; + struct gdlm_lock *lp = lock; clear_bit(LFL_DLM_CANCEL, &lp->flags); if (flags & LM_FLAG_NOEXP) @@ -321,9 +321,9 @@ unsigned int gdlm_lock(lm_lock_t *lock, unsigned int cur_state, return gdlm_do_lock(lp); } -unsigned int gdlm_unlock(lm_lock_t *lock, unsigned int cur_state) +unsigned int gdlm_unlock(void *lock, unsigned int cur_state) { - struct gdlm_lock *lp = (struct gdlm_lock *) lock; + struct gdlm_lock *lp = lock; clear_bit(LFL_DLM_CANCEL, &lp->flags); if (lp->cur == DLM_LOCK_IV) @@ -331,9 +331,9 @@ unsigned int gdlm_unlock(lm_lock_t *lock, unsigned int cur_state) return gdlm_do_unlock(lp); } -void gdlm_cancel(lm_lock_t *lock) +void gdlm_cancel(void *lock) { - struct gdlm_lock *lp = (struct gdlm_lock *) lock; + struct gdlm_lock *lp = lock; struct gdlm_ls *ls = lp->ls; int error, delay_list = 0; @@ -464,9 +464,9 @@ static void unhold_null_lock(struct gdlm_lock *lp) intact on the resource while the lvb is "held" even if it's holding no locks on the resource. */ -int gdlm_hold_lvb(lm_lock_t *lock, char **lvbp) +int gdlm_hold_lvb(void *lock, char **lvbp) { - struct gdlm_lock *lp = (struct gdlm_lock *) lock; + struct gdlm_lock *lp = lock; int error; error = gdlm_add_lvb(lp); @@ -482,9 +482,9 @@ int gdlm_hold_lvb(lm_lock_t *lock, char **lvbp) return error; } -void gdlm_unhold_lvb(lm_lock_t *lock, char *lvb) +void gdlm_unhold_lvb(void *lock, char *lvb) { - struct gdlm_lock *lp = (struct gdlm_lock *) lock; + struct gdlm_lock *lp = lock; unhold_null_lock(lp); gdlm_del_lvb(lp); diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h index a4f534a0ecff..3a45c020d01e 100644 --- a/fs/gfs2/locking/dlm/lock_dlm.h +++ b/fs/gfs2/locking/dlm/lock_dlm.h @@ -112,7 +112,7 @@ struct gdlm_lock { s16 cur; s16 req; s16 prev_req; - u32 lkf; /* dlm flags DLM_LKF_ */ + u32 lkf; /* dlm flags DLM_LKF_ */ unsigned long flags; /* lock_dlm flags LFL_ */ int bast_mode; /* protected by async_lock */ @@ -165,23 +165,23 @@ int gdlm_release_all_locks(struct gdlm_ls *); void gdlm_delete_lp(struct gdlm_lock *); unsigned int gdlm_do_lock(struct gdlm_lock *); -int gdlm_get_lock(lm_lockspace_t *, struct lm_lockname *, lm_lock_t **); -void gdlm_put_lock(lm_lock_t *); -unsigned int gdlm_lock(lm_lock_t *, unsigned int, unsigned int, unsigned int); -unsigned int gdlm_unlock(lm_lock_t *, unsigned int); -void gdlm_cancel(lm_lock_t *); -int gdlm_hold_lvb(lm_lock_t *, char **); -void gdlm_unhold_lvb(lm_lock_t *, char *); +int gdlm_get_lock(void *, struct lm_lockname *, void **); +void gdlm_put_lock(void *); +unsigned int gdlm_lock(void *, unsigned int, unsigned int, unsigned int); +unsigned int gdlm_unlock(void *, unsigned int); +void gdlm_cancel(void *); +int gdlm_hold_lvb(void *, char **); +void gdlm_unhold_lvb(void *, char *); /* plock.c */ int gdlm_plock_init(void); void gdlm_plock_exit(void); -int gdlm_plock(lm_lockspace_t *, struct lm_lockname *, struct file *, int, +int gdlm_plock(void *, struct lm_lockname *, struct file *, int, struct file_lock *); -int gdlm_plock_get(lm_lockspace_t *, struct lm_lockname *, struct file *, +int gdlm_plock_get(void *, struct lm_lockname *, struct file *, struct file_lock *); -int gdlm_punlock(lm_lockspace_t *, struct lm_lockname *, struct file *, +int gdlm_punlock(void *, struct lm_lockname *, struct file *, struct file_lock *); #endif diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c index 832fb819a2b5..1f94dd35a943 100644 --- a/fs/gfs2/locking/dlm/mount.c +++ b/fs/gfs2/locking/dlm/mount.c @@ -11,7 +11,7 @@ int gdlm_drop_count; int gdlm_drop_period; -struct lm_lockops gdlm_ops; +const struct lm_lockops gdlm_ops; static struct gdlm_ls *init_gdlm(lm_callback_t cb, struct gfs2_sbd *sdp, @@ -120,7 +120,7 @@ static int make_args(struct gdlm_ls *ls, char *data_arg, int *nodir) } static int gdlm_mount(char *table_name, char *host_data, - lm_callback_t cb, struct gfs2_sbd *sdp, + lm_callback_t cb, void *cb_data, unsigned int min_lvb_size, int flags, struct lm_lockstruct *lockstruct, struct kobject *fskobj) @@ -131,7 +131,7 @@ static int gdlm_mount(char *table_name, char *host_data, if (min_lvb_size > GDLM_LVB_SIZE) goto out; - ls = init_gdlm(cb, sdp, flags, table_name); + ls = init_gdlm(cb, cb_data, flags, table_name); if (!ls) goto out; @@ -174,9 +174,9 @@ out: return error; } -static void gdlm_unmount(lm_lockspace_t *lockspace) +static void gdlm_unmount(void *lockspace) { - struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + struct gdlm_ls *ls = lockspace; int rv; log_debug("unmount flags %lx", ls->flags); @@ -198,18 +198,18 @@ out: kfree(ls); } -static void gdlm_recovery_done(lm_lockspace_t *lockspace, unsigned int jid, +static void gdlm_recovery_done(void *lockspace, unsigned int jid, unsigned int message) { - struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + struct gdlm_ls *ls = lockspace; ls->recover_jid_done = jid; ls->recover_jid_status = message; kobject_uevent(&ls->kobj, KOBJ_CHANGE); } -static void gdlm_others_may_mount(lm_lockspace_t *lockspace) +static void gdlm_others_may_mount(void *lockspace) { - struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + struct gdlm_ls *ls = lockspace; ls->first_done = 1; kobject_uevent(&ls->kobj, KOBJ_CHANGE); } @@ -218,9 +218,9 @@ static void gdlm_others_may_mount(lm_lockspace_t *lockspace) other mounters, and lets us know (sets WITHDRAW flag). Then, userspace leaves the mount group while we leave the lockspace. */ -static void gdlm_withdraw(lm_lockspace_t *lockspace) +static void gdlm_withdraw(void *lockspace) { - struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + struct gdlm_ls *ls = lockspace; kobject_uevent(&ls->kobj, KOBJ_OFFLINE); @@ -233,7 +233,7 @@ static void gdlm_withdraw(lm_lockspace_t *lockspace) gdlm_kobject_release(ls); } -struct lm_lockops gdlm_ops = { +const struct lm_lockops gdlm_ops = { .lm_proto_name = "lock_dlm", .lm_mount = gdlm_mount, .lm_others_may_mount = gdlm_others_may_mount, diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c index 263636b390fe..7365aec9511b 100644 --- a/fs/gfs2/locking/dlm/plock.c +++ b/fs/gfs2/locking/dlm/plock.c @@ -58,10 +58,10 @@ static void send_op(struct plock_op *op) wake_up(&send_wq); } -int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, +int gdlm_plock(void *lockspace, struct lm_lockname *name, struct file *file, int cmd, struct file_lock *fl) { - struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + struct gdlm_ls *ls = lockspace; struct plock_op *op; int rv; @@ -102,10 +102,10 @@ int gdlm_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, return rv; } -int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, +int gdlm_punlock(void *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl) { - struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + struct gdlm_ls *ls = lockspace; struct plock_op *op; int rv; @@ -141,10 +141,10 @@ int gdlm_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, return rv; } -int gdlm_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, +int gdlm_plock_get(void *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl) { - struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; + struct gdlm_ls *ls = lockspace; struct plock_op *op; int rv; @@ -231,8 +231,7 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count, spin_lock(&ops_lock); list_for_each_entry(op, &recv_list, list) { - if (op->info.fsid == info.fsid && - op->info.number == info.number && + if (op->info.fsid == info.fsid && op->info.number == info.number && op->info.owner == info.owner) { list_del_init(&op->list); found = 1; diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index ba7399787f62..7b263fc6c273 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -21,10 +21,10 @@ struct nolock_lockspace { unsigned int nl_lvb_size; }; -static struct lm_lockops nolock_ops; +static const struct lm_lockops nolock_ops; static int nolock_mount(char *table_name, char *host_data, - lm_callback_t cb, struct gfs2_sbd *sdp, + lm_callback_t cb, void *cb_data, unsigned int min_lvb_size, int flags, struct lm_lockstruct *lockstruct, struct kobject *fskobj) @@ -50,24 +50,24 @@ static int nolock_mount(char *table_name, char *host_data, lockstruct->ls_jid = jid; lockstruct->ls_first = 1; lockstruct->ls_lvb_size = min_lvb_size; - lockstruct->ls_lockspace = (lm_lockspace_t *)nl; + lockstruct->ls_lockspace = nl; lockstruct->ls_ops = &nolock_ops; lockstruct->ls_flags = LM_LSFLAG_LOCAL; return 0; } -static void nolock_others_may_mount(lm_lockspace_t *lockspace) +static void nolock_others_may_mount(void *lockspace) { } -static void nolock_unmount(lm_lockspace_t *lockspace) +static void nolock_unmount(void *lockspace) { - struct nolock_lockspace *nl = (struct nolock_lockspace *)lockspace; + struct nolock_lockspace *nl = lockspace; kfree(nl); } -static void nolock_withdraw(lm_lockspace_t *lockspace) +static void nolock_withdraw(void *lockspace) { } @@ -80,10 +80,10 @@ static void nolock_withdraw(lm_lockspace_t *lockspace) * Returns: 0 on success, -EXXX on failure */ -static int nolock_get_lock(lm_lockspace_t *lockspace, struct lm_lockname *name, - lm_lock_t **lockp) +static int nolock_get_lock(void *lockspace, struct lm_lockname *name, + void **lockp) { - *lockp = (lm_lock_t *)lockspace; + *lockp = lockspace; return 0; } @@ -93,7 +93,7 @@ static int nolock_get_lock(lm_lockspace_t *lockspace, struct lm_lockname *name, * */ -static void nolock_put_lock(lm_lock_t *lock) +static void nolock_put_lock(void *lock) { } @@ -107,7 +107,7 @@ static void nolock_put_lock(lm_lock_t *lock) * Returns: A bitmap of LM_OUT_* */ -static unsigned int nolock_lock(lm_lock_t *lock, unsigned int cur_state, +static unsigned int nolock_lock(void *lock, unsigned int cur_state, unsigned int req_state, unsigned int flags) { return req_state | LM_OUT_CACHEABLE; @@ -121,12 +121,12 @@ static unsigned int nolock_lock(lm_lock_t *lock, unsigned int cur_state, * Returns: 0 */ -static unsigned int nolock_unlock(lm_lock_t *lock, unsigned int cur_state) +static unsigned int nolock_unlock(void *lock, unsigned int cur_state) { return 0; } -static void nolock_cancel(lm_lock_t *lock) +static void nolock_cancel(void *lock) { } @@ -138,9 +138,9 @@ static void nolock_cancel(lm_lock_t *lock) * Returns: 0 on success, -EXXX on failure */ -static int nolock_hold_lvb(lm_lock_t *lock, char **lvbp) +static int nolock_hold_lvb(void *lock, char **lvbp) { - struct nolock_lockspace *nl = (struct nolock_lockspace *)lock; + struct nolock_lockspace *nl = lock; int error = 0; *lvbp = kzalloc(nl->nl_lvb_size, GFP_KERNEL); @@ -157,12 +157,12 @@ static int nolock_hold_lvb(lm_lock_t *lock, char **lvbp) * */ -static void nolock_unhold_lvb(lm_lock_t *lock, char *lvb) +static void nolock_unhold_lvb(void *lock, char *lvb) { kfree(lvb); } -static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, +static int nolock_plock_get(void *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl) { struct file_lock tmp; @@ -176,7 +176,7 @@ static int nolock_plock_get(lm_lockspace_t *lockspace, struct lm_lockname *name, return 0; } -static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, +static int nolock_plock(void *lockspace, struct lm_lockname *name, struct file *file, int cmd, struct file_lock *fl) { int error; @@ -184,7 +184,7 @@ static int nolock_plock(lm_lockspace_t *lockspace, struct lm_lockname *name, return error; } -static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, +static int nolock_punlock(void *lockspace, struct lm_lockname *name, struct file *file, struct file_lock *fl) { int error; @@ -192,12 +192,12 @@ static int nolock_punlock(lm_lockspace_t *lockspace, struct lm_lockname *name, return error; } -static void nolock_recovery_done(lm_lockspace_t *lockspace, unsigned int jid, +static void nolock_recovery_done(void *lockspace, unsigned int jid, unsigned int message) { } -static struct lm_lockops nolock_ops = { +static const struct lm_lockops nolock_ops = { .lm_proto_name = "lock_nolock", .lm_mount = nolock_mount, .lm_others_may_mount = nolock_others_may_mount, From 37b2fa6a24f996d751dc80fbc8a77602cead269b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Fri, 8 Sep 2006 13:35:56 -0400 Subject: [PATCH 253/292] [GFS2] Move rwlocks in glock.c into their own array This splits the rwlocks guarding the hash chains of the glock hash table into their own array. This will reduce memory usage in some cases due to better alignment, although the real reason for doing it is to allow the two tables to be different sizes in future (i.e. the locks will be sized proportionally with the max number of CPUs and the hash chains sized proportinally with the size of physical memory) In order to allow this, the gl_bucket member of struct gfs2_glock has now become gl_hash, so we record the hash rather than a pointer to the bucket itself. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 87 +++++++++++++++++++++++------------------------- fs/gfs2/incore.h | 7 +--- 2 files changed, 43 insertions(+), 51 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 92aa0e8c9099..49512696160e 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -44,12 +44,17 @@ struct greedy { struct work_struct gr_work; }; +struct gfs2_gl_hash_bucket { + struct list_head hb_list; +}; + typedef void (*glock_examiner) (struct gfs2_glock * gl); static int gfs2_dump_lockstate(struct gfs2_sbd *sdp); static int dump_glock(struct gfs2_glock *gl); static struct gfs2_gl_hash_bucket gl_hash_table[GFS2_GL_HASH_SIZE]; +static rwlock_t gl_hash_locks[GFS2_GL_HASH_SIZE]; /** * relaxed_state_ok - is a requested lock compatible with the current lock mode? @@ -154,19 +159,18 @@ static void kill_glock(struct kref *kref) int gfs2_glock_put(struct gfs2_glock *gl) { - struct gfs2_gl_hash_bucket *bucket = gl->gl_bucket; int rv = 0; - write_lock(&bucket->hb_lock); + write_lock(&gl_hash_locks[gl->gl_hash]); if (kref_put(&gl->gl_ref, kill_glock)) { - list_del_init(&gl->gl_list); - write_unlock(&bucket->hb_lock); + list_del_init(&gl_hash_table[gl->gl_hash].hb_list); + write_unlock(&gl_hash_locks[gl->gl_hash]); BUG_ON(spin_is_locked(&gl->gl_spin)); glock_free(gl); rv = 1; goto out; } - write_unlock(&bucket->hb_lock); + write_unlock(&gl_hash_locks[gl->gl_hash]); out: return rv; } @@ -203,13 +207,13 @@ static inline int queue_empty(struct gfs2_glock *gl, struct list_head *head) * Returns: NULL, or the struct gfs2_glock with the requested number */ -static struct gfs2_glock *search_bucket(struct gfs2_gl_hash_bucket *bucket, +static struct gfs2_glock *search_bucket(unsigned int hash, const struct gfs2_sbd *sdp, const struct lm_lockname *name) { struct gfs2_glock *gl; - list_for_each_entry(gl, &bucket->hb_list, gl_list) { + list_for_each_entry(gl, &gl_hash_table[hash].hb_list, gl_list) { if (test_bit(GLF_PLUG, &gl->gl_flags)) continue; if (!lm_name_equal(&gl->gl_name, name)) @@ -236,12 +240,12 @@ static struct gfs2_glock *search_bucket(struct gfs2_gl_hash_bucket *bucket, static struct gfs2_glock *gfs2_glock_find(const struct gfs2_sbd *sdp, const struct lm_lockname *name) { - struct gfs2_gl_hash_bucket *bucket = &gl_hash_table[gl_hash(sdp, name)]; + unsigned int hash = gl_hash(sdp, name); struct gfs2_glock *gl; - read_lock(&bucket->hb_lock); - gl = search_bucket(bucket, sdp, name); - read_unlock(&bucket->hb_lock); + read_lock(&gl_hash_locks[hash]); + gl = search_bucket(hash, sdp, name); + read_unlock(&gl_hash_locks[hash]); return gl; } @@ -263,18 +267,14 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, const struct gfs2_glock_operations *glops, int create, struct gfs2_glock **glp) { - struct lm_lockname name; + struct lm_lockname name = { .ln_number = number, .ln_type = glops->go_type }; struct gfs2_glock *gl, *tmp; - struct gfs2_gl_hash_bucket *bucket; + unsigned int hash = gl_hash(sdp, &name); int error; - name.ln_number = number; - name.ln_type = glops->go_type; - bucket = &gl_hash_table[gl_hash(sdp, &name)]; - - read_lock(&bucket->hb_lock); - gl = search_bucket(bucket, sdp, &name); - read_unlock(&bucket->hb_lock); + read_lock(&gl_hash_locks[hash]); + gl = search_bucket(hash, sdp, &name); + read_unlock(&gl_hash_locks[hash]); if (gl || !create) { *glp = gl; @@ -289,6 +289,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, gl->gl_name = name; kref_init(&gl->gl_ref); gl->gl_state = LM_ST_UNLOCKED; + gl->gl_hash = hash; gl->gl_owner = NULL; gl->gl_ip = 0; gl->gl_ops = glops; @@ -297,7 +298,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, gl->gl_vn = 0; gl->gl_stamp = jiffies; gl->gl_object = NULL; - gl->gl_bucket = bucket; gl->gl_sbd = sdp; gl->gl_aspace = NULL; lops_init_le(&gl->gl_le, &gfs2_glock_lops); @@ -316,15 +316,15 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, if (error) goto fail_aspace; - write_lock(&bucket->hb_lock); - tmp = search_bucket(bucket, sdp, &name); + write_lock(&gl_hash_locks[hash]); + tmp = search_bucket(hash, sdp, &name); if (tmp) { - write_unlock(&bucket->hb_lock); + write_unlock(&gl_hash_locks[hash]); glock_free(gl); gl = tmp; } else { - list_add_tail(&gl->gl_list, &bucket->hb_list); - write_unlock(&bucket->hb_lock); + list_add_tail(&gl->gl_list, &gl_hash_table[hash].hb_list); + write_unlock(&gl_hash_locks[hash]); } *glp = gl; @@ -1868,7 +1868,7 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp) */ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, - struct gfs2_gl_hash_bucket *bucket) + unsigned int hash) { struct glock_plug plug; struct list_head *tmp; @@ -1879,20 +1879,20 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, memset(&plug.gl_flags, 0, sizeof(unsigned long)); set_bit(GLF_PLUG, &plug.gl_flags); - write_lock(&bucket->hb_lock); - list_add(&plug.gl_list, &bucket->hb_list); - write_unlock(&bucket->hb_lock); + write_lock(&gl_hash_locks[hash]); + list_add(&plug.gl_list, &gl_hash_table[hash].hb_list); + write_unlock(&gl_hash_locks[hash]); for (;;) { - write_lock(&bucket->hb_lock); + write_lock(&gl_hash_locks[hash]); for (;;) { tmp = plug.gl_list.next; - if (tmp == &bucket->hb_list) { + if (tmp == &gl_hash_table[hash].hb_list) { list_del(&plug.gl_list); - entries = !list_empty(&bucket->hb_list); - write_unlock(&bucket->hb_lock); + entries = !list_empty(&gl_hash_table[hash].hb_list); + write_unlock(&gl_hash_locks[hash]); return entries; } gl = list_entry(tmp, struct gfs2_glock, gl_list); @@ -1911,7 +1911,7 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, break; } - write_unlock(&bucket->hb_lock); + write_unlock(&gl_hash_locks[hash]); examiner(gl); } @@ -1956,7 +1956,7 @@ void gfs2_scand_internal(struct gfs2_sbd *sdp) unsigned int x; for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { - examine_bucket(scan_glock, sdp, &gl_hash_table[x]); + examine_bucket(scan_glock, sdp, x); cond_resched(); } } @@ -2015,7 +2015,7 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait) cont = 0; for (x = 0; x < GFS2_GL_HASH_SIZE; x++) - if (examine_bucket(clear_glock, sdp, &gl_hash_table[x])) + if (examine_bucket(clear_glock, sdp, x)) cont = 1; if (!wait || !cont) @@ -2198,17 +2198,15 @@ out: static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) { - struct gfs2_gl_hash_bucket *bucket; struct gfs2_glock *gl; unsigned int x; int error = 0; for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { - bucket = &gl_hash_table[x]; - read_lock(&bucket->hb_lock); + read_lock(&gl_hash_locks[x]); - list_for_each_entry(gl, &bucket->hb_list, gl_list) { + list_for_each_entry(gl, &gl_hash_table[x].hb_list, gl_list) { if (test_bit(GLF_PLUG, &gl->gl_flags)) continue; if (gl->gl_sbd != sdp) @@ -2219,7 +2217,7 @@ static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) break; } - read_unlock(&bucket->hb_lock); + read_unlock(&gl_hash_locks[x]); if (error) break; @@ -2233,9 +2231,8 @@ int __init gfs2_glock_init(void) { unsigned i; for(i = 0; i < GFS2_GL_HASH_SIZE; i++) { - struct gfs2_gl_hash_bucket *hb = &gl_hash_table[i]; - rwlock_init(&hb->hb_lock); - INIT_LIST_HEAD(&hb->hb_list); + rwlock_init(&gl_hash_locks[i]); + INIT_LIST_HEAD(&gl_hash_table[i].hb_list); } return 0; } diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 9f5d98ff823a..f50ea6282e77 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -106,11 +106,6 @@ struct gfs2_bufdata { struct list_head bd_ail_gl_list; }; -struct gfs2_gl_hash_bucket { - rwlock_t hb_lock; - struct list_head hb_list; -}; - struct gfs2_glock_operations { void (*go_xmote_th) (struct gfs2_glock * gl, unsigned int state, int flags); @@ -175,6 +170,7 @@ struct gfs2_glock { spinlock_t gl_spin; unsigned int gl_state; + unsigned int gl_hash; struct task_struct *gl_owner; unsigned long gl_ip; struct list_head gl_holders; @@ -195,7 +191,6 @@ struct gfs2_glock { unsigned long gl_stamp; void *gl_object; - struct gfs2_gl_hash_bucket *gl_bucket; struct list_head gl_reclaim; struct gfs2_sbd *gl_sbd; From fa9f0e4925c7796afd14bf7bbf7a064078818bbc Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 8 Sep 2006 08:36:35 -0500 Subject: [PATCH 254/292] [DLM] confirm master for recovered waiting requests Fixing the following scenario: - A request is on the waiters list waiting for a reply from a remote node. - The request is the first one on the resource, so first_lkid is set. - The remote node fails causing recovery. - During recovery the requesting node becomes master. - The request is now processed locally instead of being a remote operation. - At this point we need to call confirm_master() on the resource since we're certain we're now the master node. This will clear first_lkid. - We weren't calling confirm_master(), so first_lkid was not being cleared causing subsequent requests on that resource to get stuck. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 67247f0b508a..af2f2f01bd5f 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -3283,6 +3283,8 @@ int dlm_recover_waiters_post(struct dlm_ls *ls) hold_rsb(r); lock_rsb(r); _request_lock(r, lkb); + if (is_master(r)) + confirm_master(r, 0); unlock_rsb(r); put_rsb(r); break; From ff6af411ae65da95a1801668b9580c5c33f0f7d1 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Sat, 9 Sep 2006 16:56:34 -0400 Subject: [PATCH 255/292] [GFS2] vfree should be kfree (II) The superblock is now created with kmalloc, not vmalloc. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_super.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index addcf1334b3c..975e93b7992e 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -135,7 +134,7 @@ static void gfs2_put_super(struct super_block *sb) /* At this point, we're through participating in the lockspace */ gfs2_sys_fs_del(sdp); - vfree(sdp); + kfree(sdp); } /** From 087efdd391f47305dc251a7b00dcc5d69e8c636a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Sat, 9 Sep 2006 16:59:11 -0400 Subject: [PATCH 256/292] [GFS2] Make glock hash locks proportional to NR_CPUS Make the number of locks used for hash chains in glock.c proportional to NR_CPUS. Also move constants for the number of hash chains into glock.c from incore.h since they are not used outside of glock.c. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 93 ++++++++++++++++++++++++++++++++++++++---------- fs/gfs2/incore.h | 3 -- 2 files changed, 74 insertions(+), 22 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 49512696160e..8abfefe4efd4 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -53,8 +53,59 @@ typedef void (*glock_examiner) (struct gfs2_glock * gl); static int gfs2_dump_lockstate(struct gfs2_sbd *sdp); static int dump_glock(struct gfs2_glock *gl); +#define GFS2_GL_HASH_SHIFT 13 +#define GFS2_GL_HASH_SIZE (1 << GFS2_GL_HASH_SHIFT) +#define GFS2_GL_HASH_MASK (GFS2_GL_HASH_SIZE - 1) + static struct gfs2_gl_hash_bucket gl_hash_table[GFS2_GL_HASH_SIZE]; -static rwlock_t gl_hash_locks[GFS2_GL_HASH_SIZE]; + +/* + * Despite what you might think, the numbers below are not arbitrary :-) + * They are taken from the ipv4 routing hash code, which is well tested + * and thus should be nearly optimal. Later on we might tweek the numbers + * but for now this should be fine. + * + * The reason for putting the locks in a separate array from the list heads + * is that we can have fewer locks than list heads and save memory. We use + * the same hash function for both, but with a different hash mask. + */ +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) || \ + defined(CONFIG_PROVE_LOCKING) + +#ifdef CONFIG_LOCKDEP +# define GL_HASH_LOCK_SZ 256 +#else +# if NR_CPUS >= 32 +# define GL_HASH_LOCK_SZ 4096 +# elif NR_CPUS >= 16 +# define GL_HASH_LOCK_SZ 2048 +# elif NR_CPUS >= 8 +# define GL_HASH_LOCK_SZ 1024 +# elif NR_CPUS >= 4 +# define GL_HASH_LOCK_SZ 512 +# else +# define GL_HASH_LOCK_SZ 256 +# endif +#endif + +/* We never want more locks than chains */ +#if GFS2_GL_HASH_SIZE < GL_HASH_LOCK_SZ +# undef GL_HASH_LOCK_SZ +# define GL_HASH_LOCK_SZ GFS2_GL_HASH_SIZE +#endif + +static rwlock_t gl_hash_locks[GL_HASH_LOCK_SZ]; + +static inline rwlock_t *gl_lock_addr(unsigned int x) +{ + return &gl_hash_locks[(x) & (GL_HASH_LOCK_SZ-1)]; +} +#else /* not SMP, so no spinlocks required */ +static inline rwlock_t *gl_lock_addr(x) +{ + return NULL; +} +#endif /** * relaxed_state_ok - is a requested lock compatible with the current lock mode? @@ -161,16 +212,16 @@ int gfs2_glock_put(struct gfs2_glock *gl) { int rv = 0; - write_lock(&gl_hash_locks[gl->gl_hash]); + write_lock(gl_lock_addr(gl->gl_hash)); if (kref_put(&gl->gl_ref, kill_glock)) { list_del_init(&gl_hash_table[gl->gl_hash].hb_list); - write_unlock(&gl_hash_locks[gl->gl_hash]); + write_unlock(gl_lock_addr(gl->gl_hash)); BUG_ON(spin_is_locked(&gl->gl_spin)); glock_free(gl); rv = 1; goto out; } - write_unlock(&gl_hash_locks[gl->gl_hash]); + write_unlock(gl_lock_addr(gl->gl_hash)); out: return rv; } @@ -243,9 +294,9 @@ static struct gfs2_glock *gfs2_glock_find(const struct gfs2_sbd *sdp, unsigned int hash = gl_hash(sdp, name); struct gfs2_glock *gl; - read_lock(&gl_hash_locks[hash]); + read_lock(gl_lock_addr(hash)); gl = search_bucket(hash, sdp, name); - read_unlock(&gl_hash_locks[hash]); + read_unlock(gl_lock_addr(hash)); return gl; } @@ -272,9 +323,9 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, unsigned int hash = gl_hash(sdp, &name); int error; - read_lock(&gl_hash_locks[hash]); + read_lock(gl_lock_addr(hash)); gl = search_bucket(hash, sdp, &name); - read_unlock(&gl_hash_locks[hash]); + read_unlock(gl_lock_addr(hash)); if (gl || !create) { *glp = gl; @@ -316,15 +367,15 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, if (error) goto fail_aspace; - write_lock(&gl_hash_locks[hash]); + write_lock(gl_lock_addr(hash)); tmp = search_bucket(hash, sdp, &name); if (tmp) { - write_unlock(&gl_hash_locks[hash]); + write_unlock(gl_lock_addr(hash)); glock_free(gl); gl = tmp; } else { list_add_tail(&gl->gl_list, &gl_hash_table[hash].hb_list); - write_unlock(&gl_hash_locks[hash]); + write_unlock(gl_lock_addr(hash)); } *glp = gl; @@ -1879,12 +1930,12 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, memset(&plug.gl_flags, 0, sizeof(unsigned long)); set_bit(GLF_PLUG, &plug.gl_flags); - write_lock(&gl_hash_locks[hash]); + write_lock(gl_lock_addr(hash)); list_add(&plug.gl_list, &gl_hash_table[hash].hb_list); - write_unlock(&gl_hash_locks[hash]); + write_unlock(gl_lock_addr(hash)); for (;;) { - write_lock(&gl_hash_locks[hash]); + write_lock(gl_lock_addr(hash)); for (;;) { tmp = plug.gl_list.next; @@ -1892,7 +1943,7 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, if (tmp == &gl_hash_table[hash].hb_list) { list_del(&plug.gl_list); entries = !list_empty(&gl_hash_table[hash].hb_list); - write_unlock(&gl_hash_locks[hash]); + write_unlock(gl_lock_addr(hash)); return entries; } gl = list_entry(tmp, struct gfs2_glock, gl_list); @@ -1911,7 +1962,7 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, break; } - write_unlock(&gl_hash_locks[hash]); + write_unlock(gl_lock_addr(hash)); examiner(gl); } @@ -2204,7 +2255,7 @@ static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { - read_lock(&gl_hash_locks[x]); + read_lock(gl_lock_addr(x)); list_for_each_entry(gl, &gl_hash_table[x].hb_list, gl_list) { if (test_bit(GLF_PLUG, &gl->gl_flags)) @@ -2217,7 +2268,7 @@ static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) break; } - read_unlock(&gl_hash_locks[x]); + read_unlock(gl_lock_addr(x)); if (error) break; @@ -2231,9 +2282,13 @@ int __init gfs2_glock_init(void) { unsigned i; for(i = 0; i < GFS2_GL_HASH_SIZE; i++) { - rwlock_init(&gl_hash_locks[i]); INIT_LIST_HEAD(&gl_hash_table[i].hb_list); } +#ifdef GL_HASH_LOCK_SZ + for(i = 0; i < GL_HASH_LOCK_SZ; i++) { + rwlock_init(&gl_hash_locks[i]); + } +#endif return 0; } diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index f50ea6282e77..64e13435ca3b 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -448,9 +448,6 @@ enum { SDF_NOATIME = 3, }; -#define GFS2_GL_HASH_SHIFT 13 -#define GFS2_GL_HASH_SIZE (1 << GFS2_GL_HASH_SHIFT) -#define GFS2_GL_HASH_MASK (GFS2_GL_HASH_SIZE - 1) #define GFS2_FSNAME_LEN 256 struct gfs2_sbd { From a5e08a9ef50e8b6feb099f8e4b253df04f5ec9db Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Sat, 9 Sep 2006 17:07:05 -0400 Subject: [PATCH 257/292] [GFS2] Add consts to glock sorting function Add back the consts which were casted away in the glock sorting function. Also add early exit code. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 8abfefe4efd4..e941183bbcdb 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1494,26 +1494,20 @@ int gfs2_glock_nq_num(struct gfs2_sbd *sdp, u64 number, static int glock_compare(const void *arg_a, const void *arg_b) { - struct gfs2_holder *gh_a = *(struct gfs2_holder **)arg_a; - struct gfs2_holder *gh_b = *(struct gfs2_holder **)arg_b; - struct lm_lockname *a = &gh_a->gh_gl->gl_name; - struct lm_lockname *b = &gh_b->gh_gl->gl_name; - int ret = 0; + const struct gfs2_holder *gh_a = *(const struct gfs2_holder **)arg_a; + const struct gfs2_holder *gh_b = *(const struct gfs2_holder **)arg_b; + const struct lm_lockname *a = &gh_a->gh_gl->gl_name; + const struct lm_lockname *b = &gh_b->gh_gl->gl_name; if (a->ln_number > b->ln_number) - ret = 1; - else if (a->ln_number < b->ln_number) - ret = -1; - else { - if (gh_a->gh_state == LM_ST_SHARED && - gh_b->gh_state == LM_ST_EXCLUSIVE) - ret = 1; - else if (!(gh_a->gh_flags & GL_LOCAL_EXCL) && - (gh_b->gh_flags & GL_LOCAL_EXCL)) - ret = 1; - } - - return ret; + return 1; + if (a->ln_number < b->ln_number) + return -1; + if (gh_a->gh_state == LM_ST_SHARED && gh_b->gh_state == LM_ST_EXCLUSIVE) + return 1; + if (!(gh_a->gh_flags & GL_LOCAL_EXCL) && (gh_b->gh_flags & GL_LOCAL_EXCL)) + return 1; + return 0; } /** From 94610610f10749c0e17b4d2840ff8a7cb636c413 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Sat, 9 Sep 2006 18:59:27 -0400 Subject: [PATCH 258/292] [GFS2] Remove unused function from glock.c The callback for iopen locks is unused, so this removes it. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 22 ++-------------------- fs/gfs2/glock.h | 2 -- fs/gfs2/glops.c | 1 - 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index e941183bbcdb..b348053c4363 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -98,7 +98,7 @@ static rwlock_t gl_hash_locks[GL_HASH_LOCK_SZ]; static inline rwlock_t *gl_lock_addr(unsigned int x) { - return &gl_hash_locks[(x) & (GL_HASH_LOCK_SZ-1)]; + return &gl_hash_locks[x & (GL_HASH_LOCK_SZ-1)]; } #else /* not SMP, so no spinlocks required */ static inline rwlock_t *gl_lock_addr(x) @@ -1805,22 +1805,6 @@ void gfs2_glock_cb(void *cb_data, unsigned int type, void *data) } } -/** - * gfs2_iopen_go_callback - Try to kick the inode/vnode associated with an - * iopen glock from memory - * @io_gl: the iopen glock - * @state: the state into which the glock should be put - * - */ - -void gfs2_iopen_go_callback(struct gfs2_glock *io_gl, unsigned int state) -{ - - if (state != LM_ST_UNLOCKED) - return; - /* FIXME: remove this? */ -} - /** * demote_ok - Check to see if it's ok to unlock a glock * @gl: the glock @@ -2000,10 +1984,8 @@ void gfs2_scand_internal(struct gfs2_sbd *sdp) { unsigned int x; - for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { + for (x = 0; x < GFS2_GL_HASH_SIZE; x++) examine_bucket(scan_glock, sdp, x); - cond_resched(); - } } /** diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index 52b8a308635a..2b2a889ee2cc 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h @@ -142,8 +142,6 @@ void gfs2_lvb_unhold(struct gfs2_glock *gl); void gfs2_glock_cb(void *cb_data, unsigned int type, void *data); -void gfs2_iopen_go_callback(struct gfs2_glock *gl, unsigned int state); - void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl); void gfs2_reclaim_glock(struct gfs2_sbd *sdp); diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 0c50a720d01d..d3aef74ea5d4 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -529,7 +529,6 @@ const struct gfs2_glock_operations gfs2_trans_glops = { const struct gfs2_glock_operations gfs2_iopen_glops = { .go_xmote_th = gfs2_glock_xmote_th, .go_drop_th = gfs2_glock_drop_th, - .go_callback = gfs2_iopen_go_callback, .go_type = LM_TYPE_IOPEN, }; From 24264434603cc102d71fb2a1b3b7e282a781f449 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 11 Sep 2006 21:40:30 -0400 Subject: [PATCH 259/292] [GFS2] Rewrite of examine_bucket() The existing implementation of this function in glock.c was not very efficient as it relied upon keeping a cursor element upon the hash chain in question and moving it along. This new version improves upon this by using the current element as a cursor. This is possible since we only look at the "next" element in the list after we've taken the read_lock() subsequent to calling the examiner function. Obviously we have to eventually drop the ref count that we are then left with and we cannot do that while holding the read_lock, so we do that next time we drop the lock. That means either just before we examine another glock, or when the loop has terminated. The new implementation has several advantages: it uses only a read_lock() rather than a write_lock(), so it can run simnultaneously with other code, it doesn't need a "plug" element, so that it removes a test not only from this list iterator, but from all the other glock list iterators too. So it makes things faster and smaller. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 95 ++++++++++++++++-------------------------------- fs/gfs2/incore.h | 1 - 2 files changed, 31 insertions(+), 65 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index b348053c4363..b5effb9e4a38 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -33,12 +34,6 @@ #include "super.h" #include "util.h" -/* Must be kept in sync with the beginning of struct gfs2_glock */ -struct glock_plug { - struct list_head gl_list; - unsigned long gl_flags; -}; - struct greedy { struct gfs2_holder gr_gh; struct work_struct gr_work; @@ -52,6 +47,7 @@ typedef void (*glock_examiner) (struct gfs2_glock * gl); static int gfs2_dump_lockstate(struct gfs2_sbd *sdp); static int dump_glock(struct gfs2_glock *gl); +static int dump_inode(struct gfs2_inode *ip); #define GFS2_GL_HASH_SHIFT 13 #define GFS2_GL_HASH_SIZE (1 << GFS2_GL_HASH_SHIFT) @@ -214,7 +210,7 @@ int gfs2_glock_put(struct gfs2_glock *gl) write_lock(gl_lock_addr(gl->gl_hash)); if (kref_put(&gl->gl_ref, kill_glock)) { - list_del_init(&gl_hash_table[gl->gl_hash].hb_list); + list_del_init(&gl->gl_list); write_unlock(gl_lock_addr(gl->gl_hash)); BUG_ON(spin_is_locked(&gl->gl_spin)); glock_free(gl); @@ -265,8 +261,6 @@ static struct gfs2_glock *search_bucket(unsigned int hash, struct gfs2_glock *gl; list_for_each_entry(gl, &gl_hash_table[hash].hb_list, gl_list) { - if (test_bit(GLF_PLUG, &gl->gl_flags)) - continue; if (!lm_name_equal(&gl->gl_name, name)) continue; if (gl->gl_sbd != sdp) @@ -1899,51 +1893,33 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp) static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, unsigned int hash) { - struct glock_plug plug; - struct list_head *tmp; - struct gfs2_glock *gl; - int entries; + struct gfs2_glock *gl, *prev = NULL; + int has_entries = 0; + struct list_head *head = &gl_hash_table[hash].hb_list; - /* Add "plug" to end of bucket list, work back up list from there */ - memset(&plug.gl_flags, 0, sizeof(unsigned long)); - set_bit(GLF_PLUG, &plug.gl_flags); - - write_lock(gl_lock_addr(hash)); - list_add(&plug.gl_list, &gl_hash_table[hash].hb_list); - write_unlock(gl_lock_addr(hash)); - - for (;;) { - write_lock(gl_lock_addr(hash)); - - for (;;) { - tmp = plug.gl_list.next; - - if (tmp == &gl_hash_table[hash].hb_list) { - list_del(&plug.gl_list); - entries = !list_empty(&gl_hash_table[hash].hb_list); - write_unlock(gl_lock_addr(hash)); - return entries; - } - gl = list_entry(tmp, struct gfs2_glock, gl_list); - - /* Move plug up list */ - list_move(&plug.gl_list, &gl->gl_list); - - if (test_bit(GLF_PLUG, &gl->gl_flags)) - continue; - if (gl->gl_sbd != sdp) - continue; - - /* examiner() must glock_put() */ + read_lock(gl_lock_addr(hash)); + /* Can't use list_for_each_entry - don't want prefetch here */ + if (list_empty(head)) + goto out; + has_entries = 1; + gl = list_entry(head->next, struct gfs2_glock, gl_list); + while(&gl->gl_list != head) { + if (gl->gl_sbd == sdp) { gfs2_glock_hold(gl); - - break; + read_unlock(gl_lock_addr(hash)); + if (prev) + gfs2_glock_put(prev); + prev = gl; + examiner(gl); + read_lock(gl_lock_addr(hash)); } - - write_unlock(gl_lock_addr(hash)); - - examiner(gl); + gl = list_entry(gl->gl_list.next, struct gfs2_glock, gl_list); } +out: + read_unlock(gl_lock_addr(hash)); + if (prev) + gfs2_glock_put(prev); + return has_entries; } /** @@ -1955,23 +1931,19 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, static void scan_glock(struct gfs2_glock *gl) { if (gl->gl_ops == &gfs2_inode_glops) - goto out; + return; if (gfs2_glmutex_trylock(gl)) { if (queue_empty(gl, &gl->gl_holders) && - gl->gl_state != LM_ST_UNLOCKED && - demote_ok(gl)) + gl->gl_state != LM_ST_UNLOCKED && demote_ok(gl)) goto out_schedule; gfs2_glmutex_unlock(gl); } -out: - gfs2_glock_put(gl); return; out_schedule: gfs2_glmutex_unlock(gl); gfs2_glock_schedule_for_reclaim(gl); - gfs2_glock_put(gl); } /** @@ -2014,11 +1986,8 @@ static void clear_glock(struct gfs2_glock *gl) if (queue_empty(gl, &gl->gl_holders) && gl->gl_state != LM_ST_UNLOCKED) handle_callback(gl, LM_ST_UNLOCKED); - gfs2_glmutex_unlock(gl); } - - gfs2_glock_put(gl); } /** @@ -2040,10 +2009,10 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait) for (;;) { cont = 0; - - for (x = 0; x < GFS2_GL_HASH_SIZE; x++) - if (examine_bucket(clear_glock, sdp, x)) + for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { + if (examine_bucket(clear_glock, sdp, x)) cont = 1; + } if (!wait || !cont) break; @@ -2234,8 +2203,6 @@ static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) read_lock(gl_lock_addr(x)); list_for_each_entry(gl, &gl_hash_table[x].hb_list, gl_list) { - if (test_bit(GLF_PLUG, &gl->gl_flags)) - continue; if (gl->gl_sbd != sdp) continue; diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 64e13435ca3b..1fed8d1abae5 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -152,7 +152,6 @@ struct gfs2_holder { }; enum { - GLF_PLUG = 0, GLF_LOCK = 1, GLF_STICKY = 2, GLF_PREFETCH = 3, From b6397893a5ed81970e803d61ee2f1a0e79f87438 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 12 Sep 2006 10:10:01 -0400 Subject: [PATCH 260/292] [GFS2] Use hlist for glock hash chains This results in smaller list heads, so that we can have more chains in the same amount of memory (twice as many). I've multiplied the size of the table by four though - this is because we are saving memory by not having one lock per chain any more. So we land up using about the same amount of memory for the hash table as we did before I started these changes, the difference being that we now have four times as many hash chains. The reason that I say "about the same amount of memory" is that the actual amount now depends upon the NR_CPUS and some of the config variables, so that its not exact and in some cases we do use more memory. Eventually we might want to scale the hash table size according to the size of physical ram as measured on module load. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 28 ++++++++++++++++------------ fs/gfs2/incore.h | 2 +- fs/gfs2/main.c | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index b5effb9e4a38..cf54b0b001fd 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -40,7 +40,7 @@ struct greedy { }; struct gfs2_gl_hash_bucket { - struct list_head hb_list; + struct hlist_head hb_list; }; typedef void (*glock_examiner) (struct gfs2_glock * gl); @@ -49,7 +49,7 @@ static int gfs2_dump_lockstate(struct gfs2_sbd *sdp); static int dump_glock(struct gfs2_glock *gl); static int dump_inode(struct gfs2_inode *ip); -#define GFS2_GL_HASH_SHIFT 13 +#define GFS2_GL_HASH_SHIFT 15 #define GFS2_GL_HASH_SIZE (1 << GFS2_GL_HASH_SHIFT) #define GFS2_GL_HASH_MASK (GFS2_GL_HASH_SIZE - 1) @@ -210,7 +210,7 @@ int gfs2_glock_put(struct gfs2_glock *gl) write_lock(gl_lock_addr(gl->gl_hash)); if (kref_put(&gl->gl_ref, kill_glock)) { - list_del_init(&gl->gl_list); + hlist_del(&gl->gl_list); write_unlock(gl_lock_addr(gl->gl_hash)); BUG_ON(spin_is_locked(&gl->gl_spin)); glock_free(gl); @@ -259,8 +259,9 @@ static struct gfs2_glock *search_bucket(unsigned int hash, const struct lm_lockname *name) { struct gfs2_glock *gl; + struct hlist_node *h; - list_for_each_entry(gl, &gl_hash_table[hash].hb_list, gl_list) { + hlist_for_each_entry(gl, h, &gl_hash_table[hash].hb_list, gl_list) { if (!lm_name_equal(&gl->gl_name, name)) continue; if (gl->gl_sbd != sdp) @@ -368,7 +369,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, glock_free(gl); gl = tmp; } else { - list_add_tail(&gl->gl_list, &gl_hash_table[hash].hb_list); + hlist_add_head(&gl->gl_list, &gl_hash_table[hash].hb_list); write_unlock(gl_lock_addr(hash)); } @@ -1895,15 +1896,15 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, { struct gfs2_glock *gl, *prev = NULL; int has_entries = 0; - struct list_head *head = &gl_hash_table[hash].hb_list; + struct hlist_head *head = &gl_hash_table[hash].hb_list; read_lock(gl_lock_addr(hash)); - /* Can't use list_for_each_entry - don't want prefetch here */ - if (list_empty(head)) + /* Can't use hlist_for_each_entry - don't want prefetch here */ + if (hlist_empty(head)) goto out; has_entries = 1; - gl = list_entry(head->next, struct gfs2_glock, gl_list); - while(&gl->gl_list != head) { + gl = list_entry(head->first, struct gfs2_glock, gl_list); + while(1) { if (gl->gl_sbd == sdp) { gfs2_glock_hold(gl); read_unlock(gl_lock_addr(hash)); @@ -1913,6 +1914,8 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, examiner(gl); read_lock(gl_lock_addr(hash)); } + if (gl->gl_list.next == NULL) + break; gl = list_entry(gl->gl_list.next, struct gfs2_glock, gl_list); } out: @@ -2195,6 +2198,7 @@ out: static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) { struct gfs2_glock *gl; + struct hlist_node *h; unsigned int x; int error = 0; @@ -2202,7 +2206,7 @@ static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) read_lock(gl_lock_addr(x)); - list_for_each_entry(gl, &gl_hash_table[x].hb_list, gl_list) { + hlist_for_each_entry(gl, h, &gl_hash_table[x].hb_list, gl_list) { if (gl->gl_sbd != sdp) continue; @@ -2225,7 +2229,7 @@ int __init gfs2_glock_init(void) { unsigned i; for(i = 0; i < GFS2_GL_HASH_SIZE; i++) { - INIT_LIST_HEAD(&gl_hash_table[i].hb_list); + INIT_HLIST_HEAD(&gl_hash_table[i].hb_list); } #ifdef GL_HASH_LOCK_SZ for(i = 0; i < GL_HASH_LOCK_SZ; i++) { diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 1fed8d1abae5..c68d39271ede 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -161,7 +161,7 @@ enum { }; struct gfs2_glock { - struct list_head gl_list; + struct hlist_node gl_list; unsigned long gl_flags; /* GLF_... */ struct lm_lockname gl_name; struct kref gl_ref; diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index 2bdf246436c7..d2867988cc34 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -42,7 +42,7 @@ static void gfs2_init_glock_once(void *foo, kmem_cache_t *cachep, unsigned long struct gfs2_glock *gl = foo; if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) { - INIT_LIST_HEAD(&gl->gl_list); + INIT_HLIST_NODE(&gl->gl_list); spin_lock_init(&gl->gl_spin); INIT_LIST_HEAD(&gl->gl_holders); INIT_LIST_HEAD(&gl->gl_waiters1); From 16feb9fec0e1f74339bd6992130ceedb3aa9567e Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 13 Sep 2006 10:43:37 -0400 Subject: [PATCH 261/292] [GFS2] Use atomic_t rather than kref in glock.c Use atomic_t as the ref count in glocks rather than a kref. This is another step towards using RCU for the glock hash. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 34 ++++++++++++---------------------- fs/gfs2/incore.h | 2 +- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index cf54b0b001fd..2316490723c0 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -179,23 +178,7 @@ static void glock_free(struct gfs2_glock *gl) void gfs2_glock_hold(struct gfs2_glock *gl) { - kref_get(&gl->gl_ref); -} - -/* All work is done after the return from kref_put() so we - can release the write_lock before the free. */ - -static void kill_glock(struct kref *kref) -{ - struct gfs2_glock *gl = container_of(kref, struct gfs2_glock, gl_ref); - struct gfs2_sbd *sdp = gl->gl_sbd; - - gfs2_assert(sdp, gl->gl_state == LM_ST_UNLOCKED); - gfs2_assert(sdp, list_empty(&gl->gl_reclaim)); - gfs2_assert(sdp, list_empty(&gl->gl_holders)); - gfs2_assert(sdp, list_empty(&gl->gl_waiters1)); - gfs2_assert(sdp, list_empty(&gl->gl_waiters2)); - gfs2_assert(sdp, list_empty(&gl->gl_waiters3)); + atomic_inc(&gl->gl_ref); } /** @@ -207,12 +190,19 @@ static void kill_glock(struct kref *kref) int gfs2_glock_put(struct gfs2_glock *gl) { int rv = 0; + struct gfs2_sbd *sdp = gl->gl_sbd; write_lock(gl_lock_addr(gl->gl_hash)); - if (kref_put(&gl->gl_ref, kill_glock)) { + if (atomic_dec_and_test(&gl->gl_ref)) { hlist_del(&gl->gl_list); write_unlock(gl_lock_addr(gl->gl_hash)); BUG_ON(spin_is_locked(&gl->gl_spin)); + gfs2_assert(sdp, gl->gl_state == LM_ST_UNLOCKED); + gfs2_assert(sdp, list_empty(&gl->gl_reclaim)); + gfs2_assert(sdp, list_empty(&gl->gl_holders)); + gfs2_assert(sdp, list_empty(&gl->gl_waiters1)); + gfs2_assert(sdp, list_empty(&gl->gl_waiters2)); + gfs2_assert(sdp, list_empty(&gl->gl_waiters3)); glock_free(gl); rv = 1; goto out; @@ -267,7 +257,7 @@ static struct gfs2_glock *search_bucket(unsigned int hash, if (gl->gl_sbd != sdp) continue; - kref_get(&gl->gl_ref); + atomic_inc(&gl->gl_ref); return gl; } @@ -333,7 +323,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, gl->gl_flags = 0; gl->gl_name = name; - kref_init(&gl->gl_ref); + atomic_set(&gl->gl_ref, 1); gl->gl_state = LM_ST_UNLOCKED; gl->gl_hash = hash; gl->gl_owner = NULL; @@ -2124,7 +2114,7 @@ static int dump_glock(struct gfs2_glock *gl) printk(" %u", x); } printk(" \n"); - printk(KERN_INFO " gl_ref = %d\n", atomic_read(&gl->gl_ref.refcount)); + printk(KERN_INFO " gl_ref = %d\n", atomic_read(&gl->gl_ref)); printk(KERN_INFO " gl_state = %u\n", gl->gl_state); printk(KERN_INFO " gl_owner = %s\n", gl->gl_owner->comm); print_symbol(KERN_INFO " gl_ip = %s\n", gl->gl_ip); diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index c68d39271ede..89df68b32fc6 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -164,7 +164,7 @@ struct gfs2_glock { struct hlist_node gl_list; unsigned long gl_flags; /* GLF_... */ struct lm_lockname gl_name; - struct kref gl_ref; + atomic_t gl_ref; spinlock_t gl_spin; From faa31ce85f626dff30ba865684bd1f0ad97a9ca0 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 13 Sep 2006 11:13:27 -0400 Subject: [PATCH 262/292] [GFS2] Tidy up log.c Based upon previous feedback from lkml and also removing some commented out debugging which is no longer needed. Signed-off-by: Steven Whitehouse --- fs/gfs2/log.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 8fce592f4011..50f88059c3d5 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -47,8 +47,7 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, unsigned int first, second; blks = 1; - first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / - ssize; + first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / ssize; if (nstruct > first) { second = (sdp->sd_sb.sb_bsize - @@ -230,8 +229,7 @@ static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) * Returns: the distance in blocks */ -static inline unsigned int log_distance(struct gfs2_sbd *sdp, - unsigned int newer, +static inline unsigned int log_distance(struct gfs2_sbd *sdp, unsigned int newer, unsigned int older) { int dist; @@ -250,11 +248,10 @@ static unsigned int current_tail(struct gfs2_sbd *sdp) gfs2_log_lock(sdp); - if (list_empty(&sdp->sd_ail1_list)) + if (list_empty(&sdp->sd_ail1_list)) { tail = sdp->sd_log_head; - else { - ai = list_entry(sdp->sd_ail1_list.prev, struct gfs2_ail, - ai_list); + } else { + ai = list_entry(sdp->sd_ail1_list.prev, struct gfs2_ail, ai_list); tail = ai->ai_first; } @@ -266,8 +263,7 @@ static unsigned int current_tail(struct gfs2_sbd *sdp) static inline void log_incr_head(struct gfs2_sbd *sdp) { if (sdp->sd_log_flush_head == sdp->sd_log_tail) - gfs2_assert_withdraw(sdp, - sdp->sd_log_flush_head == sdp->sd_log_head); + gfs2_assert_withdraw(sdp, sdp->sd_log_flush_head == sdp->sd_log_head); if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) { sdp->sd_log_flush_head = 0; @@ -343,9 +339,7 @@ static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail, int pull) gfs2_log_lock(sdp); sdp->sd_log_blks_free += dist - (pull ? 1 : 0); - /* printk(KERN_INFO "pull tail refunding %u blocks (%u left) pull=%d\n", dist - (pull ? 1 : 0), sdp->sd_log_blks_free, pull); */ - gfs2_assert_withdraw(sdp, - sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); + gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); gfs2_log_unlock(sdp); sdp->sd_log_tail = new_tail; @@ -366,8 +360,6 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull) unsigned int tail; u32 hash; - /* printk(KERN_INFO "log write header start (flags=%08x, pull=%d)\n", flags, pull); */ - bh = sb_getblk(sdp->sd_vfs, blkno); lock_buffer(bh); memset(bh->b_data, 0, bh->b_size); @@ -402,8 +394,6 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull) sdp->sd_log_idle = (tail == sdp->sd_log_flush_head); log_incr_head(sdp); - - /* printk(KERN_INFO "log write header out\n"); */ } static void log_flush_commit(struct gfs2_sbd *sdp) @@ -459,8 +449,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) INIT_LIST_HEAD(&ai->ai_ail1_list); INIT_LIST_HEAD(&ai->ai_ail2_list); - gfs2_assert_withdraw(sdp, - sdp->sd_log_num_buf == sdp->sd_log_commited_buf); + gfs2_assert_withdraw(sdp, sdp->sd_log_num_buf == sdp->sd_log_commited_buf); gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke); @@ -476,13 +465,12 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) lops_after_commit(sdp, ai); sdp->sd_log_head = sdp->sd_log_flush_head; - /* printk(KERN_INFO "sd_log_num_hdrs %u\n", sdp->sd_log_num_hdrs); */ sdp->sd_log_blks_free -= sdp->sd_log_num_hdrs; - sdp->sd_log_blks_reserved = - sdp->sd_log_commited_buf = - sdp->sd_log_num_hdrs = - sdp->sd_log_commited_revoke = 0; + sdp->sd_log_blks_reserved = 0; + sdp->sd_log_commited_buf = 0; + sdp->sd_log_num_hdrs = 0; + sdp->sd_log_commited_revoke = 0; gfs2_log_lock(sdp); if (!list_empty(&ai->ai_ail1_list)) { @@ -551,8 +539,9 @@ void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks)) { gfs2_log_unlock(sdp); gfs2_log_flush(sdp, NULL); - } else + } else { gfs2_log_unlock(sdp); + } } /** @@ -580,7 +569,6 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp) log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT, 0); - /* printk(KERN_INFO "sd_log_blks_free %u, sd_jdesc->jd_blocks %u\n", sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); */ gfs2_assert_warn(sdp, sdp->sd_log_blks_free == sdp->sd_jdesc->jd_blocks); gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail); gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list)); From a8336344a5fd1366eb3616d351c39cadcd077f43 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 14 Sep 2006 13:57:38 -0400 Subject: [PATCH 263/292] [GFS2] Fix glock hash clearing A one liner bug fix to prevent the return value being wrong when more than one superblock is mounted. Signed-off-by: Steven Whitehouse --- fs/gfs2/glock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 2316490723c0..64a1676e5f48 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1892,7 +1892,6 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, /* Can't use hlist_for_each_entry - don't want prefetch here */ if (hlist_empty(head)) goto out; - has_entries = 1; gl = list_entry(head->first, struct gfs2_glock, gl_list); while(1) { if (gl->gl_sbd == sdp) { @@ -1902,6 +1901,7 @@ static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, gfs2_glock_put(prev); prev = gl; examiner(gl); + has_entries = 1; read_lock(gl_lock_addr(hash)); } if (gl->gl_list.next == NULL) From 65952fb4e91c159d253bd28ceaf028a86dbb0b02 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Fri, 15 Sep 2006 13:09:11 -0500 Subject: [PATCH 264/292] [GFS2] print mount errors related to sysfs Print an error message if mount fails in setting up the sysfs files. Signed-off-by: David Teigland Signed-off-by: Steven Whitehouse --- fs/gfs2/sys.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index 88386d8dc05a..c9b23084918f 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -555,6 +555,7 @@ fail_lockstruct: fail_reg: kobject_unregister(&sdp->sd_kobj); fail: + fs_err(sdp, "error %d adding sysfs files", error); return error; } From 7a6bbacbb8dec6fbd1242c959250388f907d429e Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 18 Sep 2006 17:18:23 -0400 Subject: [PATCH 265/292] [GFS2] Map multiple blocks at once where possible This is a tidy up of the GFS2 bmap code. The main change is that the bh is passed to gfs2_block_map allowing the flags to be set directly rather than having to repeat that code several times in ops_address.c. At the same time, the extent mapping code from gfs2_extent_map has been moved into gfs2_block_map. This allows all calls to gfs2_block_map to map extents in the case that no allocation is taking place. As a result reads and non-allocating writes should be faster. A quick test with postmark appears to support this. There is a limit on the number of blocks mapped in a single bmap call in that it will only ever map blocks which are pointed to from a single pointer block. So in other words, it will never try to do additional i/o in order to satisfy read-ahead. The maximum number of blocks is thus somewhat less than 512 (the GFS2 4k block size minus the header divided by sizeof(u64)). I've further limited the mapping of "normal" blocks to 32 blocks (to avoid extra work) since readpages() will currently read a maximum of 32 blocks ahead (128k). Some further work will probably be needed to set a suitable value for DIO as well, but for now thats left at the maximum 512 (see ops_address.c:gfs2_get_block_direct). There is probably a lot more that can be done to improve bmap for GFS2, but this is a good first step. Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 131 +++++++++++++++++++++--------------------- fs/gfs2/bmap.h | 2 +- fs/gfs2/log.c | 14 ++--- fs/gfs2/ops_address.c | 72 ++++++----------------- fs/gfs2/quota.c | 8 +-- fs/gfs2/recovery.c | 10 ++-- 6 files changed, 94 insertions(+), 143 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 57caad7bc0d5..cc91e482eda0 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -423,8 +423,7 @@ static int lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, * gfs2_block_pointers - Map a block from an inode to a disk block * @inode: The inode * @lblock: The logical block number - * @new: Value/Result argument (1 = may create/did create new blocks) - * @boundary: gets set if we've hit a block boundary + * @map_bh: The bh to be mapped * @mp: metapath to use * * Find the block number on the current device which corresponds to an @@ -433,37 +432,35 @@ static int lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, * Returns: errno */ -static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock, - int *new, u64 *dblock, - int *boundary, - struct metapath *mp) +static int gfs2_block_pointers(struct inode *inode, u64 lblock, int create, + struct buffer_head *bh_map, struct metapath *mp, + unsigned int maxlen) { struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_sbd *sdp = GFS2_SB(inode); struct buffer_head *bh; - int create = *new; unsigned int bsize; unsigned int height; unsigned int end_of_metadata; unsigned int x; int error = 0; - - *new = 0; - *dblock = 0; + int new = 0; + u64 dblock = 0; + int boundary; if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) - goto out; + return 0; bsize = gfs2_is_dir(ip) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize; height = calc_tree_height(ip, (lblock + 1) * bsize); if (ip->i_di.di_height < height) { if (!create) - goto out; + return 0; error = build_height(inode, height); if (error) - goto out; + return error; } find_metapath(ip, lblock, mp); @@ -471,32 +468,54 @@ static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock, error = gfs2_meta_inode_buffer(ip, &bh); if (error) - goto out; + return error; for (x = 0; x < end_of_metadata; x++) { - lookup_block(ip, bh, x, mp, create, new, dblock); + lookup_block(ip, bh, x, mp, create, &new, &dblock); brelse(bh); - if (!*dblock) - goto out; + if (!dblock) + return 0; - error = gfs2_meta_indirect_buffer(ip, x+1, *dblock, *new, &bh); + error = gfs2_meta_indirect_buffer(ip, x+1, dblock, new, &bh); if (error) - goto out; + return error; } - *boundary = lookup_block(ip, bh, end_of_metadata, mp, create, new, dblock); - if (*new) { - struct buffer_head *dibh; - error = gfs2_meta_inode_buffer(ip, &dibh); - if (!error) { - gfs2_trans_add_bh(ip->i_gl, dibh, 1); - gfs2_dinode_out(&ip->i_di, dibh->b_data); - brelse(dibh); + boundary = lookup_block(ip, bh, end_of_metadata, mp, create, &new, &dblock); + clear_buffer_mapped(bh_map); + clear_buffer_new(bh_map); + clear_buffer_boundary(bh_map); + + if (dblock) { + map_bh(bh_map, inode->i_sb, dblock); + if (boundary) + set_buffer_boundary(bh); + if (new) { + struct buffer_head *dibh; + error = gfs2_meta_inode_buffer(ip, &dibh); + if (!error) { + gfs2_trans_add_bh(ip->i_gl, dibh, 1); + gfs2_dinode_out(&ip->i_di, dibh->b_data); + brelse(dibh); + } + set_buffer_new(bh_map); + goto out_brelse; + } + while(--maxlen && !buffer_boundary(bh_map)) { + u64 eblock; + + mp->mp_list[end_of_metadata]++; + boundary = lookup_block(ip, bh, end_of_metadata, mp, 0, &new, &eblock); + if (eblock != ++dblock) + break; + bh_map->b_size += inode->i_blksize; + if (boundary) + set_buffer_boundary(bh_map); } } - return bh; -out: - return ERR_PTR(error); +out_brelse: + brelse(bh); + return 0; } @@ -518,30 +537,23 @@ static inline void bmap_unlock(struct inode *inode, int create) up_read(&ip->i_rw_mutex); } -int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *boundary) +int gfs2_block_map(struct inode *inode, u64 lblock, int create, + struct buffer_head *bh, unsigned int maxlen) { struct metapath mp; - struct buffer_head *bh; - int create = *new; + int ret; bmap_lock(inode, create); - bh = gfs2_block_pointers(inode, lblock, new, dblock, boundary, &mp); + ret = gfs2_block_pointers(inode, lblock, create, bh, &mp, maxlen); bmap_unlock(inode, create); - if (!bh) - return 0; - if (IS_ERR(bh)) - return PTR_ERR(bh); - brelse(bh); - return 0; + return ret; } int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen) { - struct gfs2_inode *ip = GFS2_I(inode); - struct gfs2_sbd *sdp = GFS2_SB(inode); struct metapath mp; - struct buffer_head *bh; - int boundary; + struct buffer_head bh = { .b_state = 0, .b_blocknr = 0, .b_size = 0 }; + int ret; int create = *new; BUG_ON(!extlen); @@ -549,30 +561,15 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsi BUG_ON(!new); bmap_lock(inode, create); - bh = gfs2_block_pointers(inode, lblock, new, dblock, &boundary, &mp); - *extlen = 1; - - if (bh != NULL && !IS_ERR(bh) && *dblock != 0 && *new == 0) { - u64 tmp_dblock; - int tmp_new; - unsigned int nptrs; - unsigned end_of_metadata = ip->i_di.di_height - 1; - - nptrs = (end_of_metadata) ? sdp->sd_inptrs : sdp->sd_diptrs; - while (++mp.mp_list[end_of_metadata] < nptrs) { - lookup_block(ip, bh, end_of_metadata, &mp, 0, &tmp_new, &tmp_dblock); - if (*dblock + *extlen != tmp_dblock) - break; - ++*extlen; - } - } + ret = gfs2_block_pointers(inode, lblock, create, &bh, &mp, *extlen); bmap_unlock(inode, create); - if (!bh) - return 0; - if (IS_ERR(bh)) - return PTR_ERR(bh); - brelse(bh); - return 0; + *extlen = bh.b_size >> inode->i_blkbits; + *dblock = bh.b_blocknr; + if (buffer_new(&bh)) + *new = 1; + else + *new = 0; + return ret; } /** diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h index 503f1cdda290..0fd379b4cd9e 100644 --- a/fs/gfs2/bmap.h +++ b/fs/gfs2/bmap.h @@ -15,7 +15,7 @@ struct gfs2_inode; struct page; int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page); -int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *boundary); +int gfs2_block_map(struct inode *inode, u64 lblock, int create, struct buffer_head *bh, unsigned int maxlen); int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen); int gfs2_truncatei(struct gfs2_inode *ip, u64 size); diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 50f88059c3d5..ab341cd0a76a 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -204,17 +204,15 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) { - int new = 0; - u64 dbn; int error; - int bdy; + struct buffer_head bh_map; - error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, &new, &dbn, &bdy); - if (error || !dbn) - printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, (unsigned long long)dbn, lbn); - gfs2_assert_withdraw(sdp, !error && dbn); + error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, 0, &bh_map, 1); + if (error || !bh_map.b_blocknr) + printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, bh_map.b_blocknr, lbn); + gfs2_assert_withdraw(sdp, !error && bh_map.b_blocknr); - return dbn; + return bh_map.b_blocknr; } /** diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index d44d42fb4163..6f9ac5e6e3f6 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -65,29 +65,11 @@ static void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, int gfs2_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { - int new = create; - u64 dblock; - int error; - int boundary; - - error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary); - if (error) - return error; - - if (!dblock) - return 0; - - map_bh(bh_result, inode->i_sb, dblock); - if (new) - set_buffer_new(bh_result); - if (boundary) - set_buffer_boundary(bh_result); - - return 0; + return gfs2_block_map(inode, lblock, create, bh_result, 32); } /** - * get_block_noalloc - Fills in a buffer head with details about a block + * gfs2_get_block_noalloc - Fills in a buffer head with details about a block * @inode: The inode * @lblock: The block number to look up * @bh_result: The buffer head to return the result in @@ -96,47 +78,25 @@ int gfs2_get_block(struct inode *inode, sector_t lblock, * Returns: errno */ -static int get_block_noalloc(struct inode *inode, sector_t lblock, - struct buffer_head *bh_result, int create) +static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock, + struct buffer_head *bh_result, int create) { - int new = 0; - u64 dblock; int error; - int boundary; - error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary); + error = gfs2_block_map(inode, lblock, 0, bh_result, 1); if (error) return error; - - if (dblock) - map_bh(bh_result, inode->i_sb, dblock); - else if (gfs2_assert_withdraw(GFS2_SB(inode), !create)) - error = -EIO; - if (boundary) - set_buffer_boundary(bh_result); - - return error; -} - -static int get_block_direct(struct inode *inode, sector_t lblock, - struct buffer_head *bh_result, int create) -{ - int new = 0; - u64 dblock; - int error, boundary; - - error = gfs2_block_map(inode, lblock, &new, &dblock, &boundary); - if (error) - return error; - - if (dblock) { - map_bh(bh_result, inode->i_sb, dblock); - if (boundary) - set_buffer_boundary(bh_result); - } - + if (bh_result->b_blocknr == 0) + return -EIO; return 0; } + +static int gfs2_get_block_direct(struct inode *inode, sector_t lblock, + struct buffer_head *bh_result, int create) +{ + return gfs2_block_map(inode, lblock, 0, bh_result, 512); +} + /** * gfs2_writepage - Write complete page * @page: Page to write @@ -184,7 +144,7 @@ static int gfs2_writepage(struct page *page, struct writeback_control *wbc) gfs2_page_add_databufs(ip, page, 0, sdp->sd_vfs->s_blocksize-1); done_trans = 1; } - error = block_write_full_page(page, get_block_noalloc, wbc); + error = block_write_full_page(page, gfs2_get_block_noalloc, wbc); if (done_trans) gfs2_trans_end(sdp); gfs2_meta_cache_flush(ip); @@ -680,7 +640,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, rv = blockdev_direct_IO_own_locking(rw, iocb, inode, inode->i_sb->s_bdev, iov, offset, nr_segs, - get_block_direct, NULL); + gfs2_get_block_direct, NULL); out: gfs2_glock_dq_m(1, &gh); gfs2_holder_uninit(&gh); diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index fe1828ffebfa..bc9ad058d20e 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -248,11 +248,9 @@ static int bh_get(struct gfs2_quota_data *qd) struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); unsigned int block, offset; - u64 dblock; - int new = 0; struct buffer_head *bh; int error; - int boundary; + struct buffer_head bh_map; mutex_lock(&sdp->sd_quota_mutex); @@ -264,10 +262,10 @@ static int bh_get(struct gfs2_quota_data *qd) block = qd->qd_slot / sdp->sd_qc_per_block; offset = qd->qd_slot % sdp->sd_qc_per_block;; - error = gfs2_block_map(&ip->i_inode, block, &new, &dblock, &boundary); + error = gfs2_block_map(&ip->i_inode, block, 0, &bh_map, 1); if (error) goto fail; - error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh); + error = gfs2_meta_read(ip->i_gl, bh_map.b_blocknr, DIO_START | DIO_WAIT, &bh); if (error) goto fail; error = -EIO; diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index a27569c5d85e..130e9fbf9692 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -369,25 +369,23 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) struct gfs2_inode *ip = GFS2_I(jd->jd_inode); struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); unsigned int lblock; - int new = 0; - u64 dblock; struct gfs2_log_header *lh; u32 hash; struct buffer_head *bh; int error; - int boundary; + struct buffer_head bh_map; lblock = head->lh_blkno; gfs2_replay_incr_blk(sdp, &lblock); - error = gfs2_block_map(&ip->i_inode, lblock, &new, &dblock, &boundary); + error = gfs2_block_map(&ip->i_inode, lblock, 0, &bh_map, 1); if (error) return error; - if (!dblock) { + if (!bh_map.b_blocknr) { gfs2_consist_inode(ip); return -EIO; } - bh = sb_getblk(sdp->sd_vfs, dblock); + bh = sb_getblk(sdp->sd_vfs, bh_map.b_blocknr); lock_buffer(bh); memset(bh->b_data, 0, bh->b_size); set_buffer_uptodate(bh); From dc41aeedef6b776583064be8abe6813159b4901d Mon Sep 17 00:00:00 2001 From: Russell Cattelan Date: Mon, 18 Sep 2006 17:26:48 -0400 Subject: [PATCH 266/292] [GFS2] Fix for mmap() bug in readpage Fix for Red Hat bz 205307. Don't need to lock in readpage if the higher level code has already grabbed the lock. Signed-off-by: Russell Cattelan Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 6f9ac5e6e3f6..25d7025e43c2 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -218,14 +218,16 @@ static int gfs2_readpage(struct file *file, struct page *page) { struct gfs2_inode *ip = GFS2_I(page->mapping->host); struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host); + struct gfs2_file *gf = NULL; struct gfs2_holder gh; int error; int do_unlock = 0; if (likely(file != &gfs2_internal_file_sentinel)) { if (file) { - struct gfs2_file *gf = file->private_data; + gf = file->private_data; if (test_bit(GFF_EXLOCK, &gf->f_flags)) + /* gfs2_sharewrite_nopage has grabbed the ip->i_gl already */ goto skip_lock; } gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|GL_AOP, &gh); @@ -245,7 +247,8 @@ skip_lock: if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = -EIO; - if (file != &gfs2_internal_file_sentinel) { + if (gf && !test_bit(GFF_EXLOCK, &gf->f_flags) && + file != &gfs2_internal_file_sentinel) { gfs2_glock_dq_m(1, &gh); gfs2_holder_uninit(&gh); } From 07903c02d056452da369595f00eac078bf4c7ef0 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 18 Sep 2006 17:30:05 -0400 Subject: [PATCH 267/292] [GFS2] Tweek unlock test in readpage() This make the unlock test a bit simpler. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_address.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 25d7025e43c2..7cd53d118c89 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -247,8 +247,7 @@ skip_lock: if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) error = -EIO; - if (gf && !test_bit(GFF_EXLOCK, &gf->f_flags) && - file != &gfs2_internal_file_sentinel) { + if (do_unlock) { gfs2_glock_dq_m(1, &gh); gfs2_holder_uninit(&gh); } From f3b30912e0eab0e4160c7649a5f2b10be68027b9 Mon Sep 17 00:00:00 2001 From: "akpm@osdl.org" Date: Mon, 18 Sep 2006 22:16:03 -0700 Subject: [PATCH 268/292] [GFS2] inode-diet-eliminate-i_blksize-and-use-a-per-superblock-default-vs-gfs2 i_blksize got removed in -mm. Cc: Steven Whitehouse Signed-off-by: Andrew Morton Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index cc91e482eda0..bd5bc887ef9b 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -508,7 +508,7 @@ static int gfs2_block_pointers(struct inode *inode, u64 lblock, int create, boundary = lookup_block(ip, bh, end_of_metadata, mp, 0, &new, &eblock); if (eblock != ++dblock) break; - bh_map->b_size += inode->i_blksize; + bh_map->b_size += (1 << inode->i_blkbits); if (boundary) set_buffer_boundary(bh_map); } From 7d308590ae60d1f038a54a94e78a385c5c163452 Mon Sep 17 00:00:00 2001 From: Fabio Massimo Di Nitto Date: Tue, 19 Sep 2006 07:56:29 +0200 Subject: [PATCH 269/292] [GFS2] Export lm_interface to kernel headers lm_interface.h has a few out of the tree clients such as GFS1 and userland tools. Right now, these clients keeps a copy of the file in their build tree that can go out of sync. Move lm_interface.h to include/linux, export it to userland and clean up fs/gfs2 to use the new location. Signed-off-by: Fabio M. Di Nitto Signed-off-by: Steven Whitehouse --- fs/gfs2/acl.c | 2 +- fs/gfs2/bmap.c | 2 +- fs/gfs2/daemon.c | 2 +- fs/gfs2/dir.c | 2 +- fs/gfs2/eaops.c | 2 +- fs/gfs2/eattr.c | 2 +- fs/gfs2/glock.c | 2 +- fs/gfs2/glops.c | 2 +- fs/gfs2/inode.c | 2 +- fs/gfs2/lm.c | 2 +- fs/gfs2/locking.c | 3 +-- fs/gfs2/locking/dlm/lock_dlm.h | 2 +- fs/gfs2/locking/nolock/main.c | 3 +-- fs/gfs2/log.c | 2 +- fs/gfs2/lops.c | 2 +- fs/gfs2/main.c | 2 +- fs/gfs2/meta_io.c | 2 +- fs/gfs2/mount.c | 2 +- fs/gfs2/ops_address.c | 2 +- fs/gfs2/ops_dentry.c | 2 +- fs/gfs2/ops_export.c | 2 +- fs/gfs2/ops_file.c | 2 +- fs/gfs2/ops_fstype.c | 2 +- fs/gfs2/ops_inode.c | 2 +- fs/gfs2/ops_super.c | 2 +- fs/gfs2/ops_vm.c | 2 +- fs/gfs2/quota.c | 2 +- fs/gfs2/recovery.c | 2 +- fs/gfs2/rgrp.c | 2 +- fs/gfs2/super.c | 2 +- fs/gfs2/sys.c | 2 +- fs/gfs2/trans.c | 2 +- fs/gfs2/util.c | 2 +- include/linux/Kbuild | 6 +++--- {fs/gfs2 => include/linux}/lm_interface.h | 0 35 files changed, 36 insertions(+), 38 deletions(-) rename {fs/gfs2 => include/linux}/lm_interface.h (100%) diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index d846b5ad1d87..3123fc071233 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -15,9 +15,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "acl.h" #include "eaops.h" diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index bd5bc887ef9b..19b9bfc10349 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -14,9 +14,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "bmap.h" #include "glock.h" diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c index a2a07c41845d..a9908cd78cd9 100644 --- a/fs/gfs2/daemon.c +++ b/fs/gfs2/daemon.c @@ -15,9 +15,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "daemon.h" #include "glock.h" diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index f3dbda216caf..739028688270 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -61,9 +61,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "dir.h" #include "glock.h" diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index adb898ceaa18..1a7877fe7393 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -14,10 +14,10 @@ #include #include #include +#include #include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "acl.h" #include "eaops.h" diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index d7b92fba6998..698942ec7c99 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -14,10 +14,10 @@ #include #include #include +#include #include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "acl.h" #include "eaops.h" diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 64a1676e5f48..f98694e7d668 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -18,10 +18,10 @@ #include #include #include +#include #include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "glock.h" #include "glops.h" diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index d3aef74ea5d4..9c046dbf4729 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -13,9 +13,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "bmap.h" #include "glock.h" diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 0d010f0654d9..b9e4bcb3bf1e 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -16,9 +16,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "acl.h" #include "bmap.h" diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index 4e23aa5ef75d..2109fc4791d4 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -14,9 +14,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "glock.h" #include "lm.h" diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c index 65eca48b2eae..663fee728783 100644 --- a/fs/gfs2/locking.c +++ b/fs/gfs2/locking.c @@ -16,8 +16,7 @@ #include #include #include - -#include "lm_interface.h" +#include struct lmh_wrapper { struct list_head lw_list; diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h index 3a45c020d01e..33af707a4d3f 100644 --- a/fs/gfs2/locking/dlm/lock_dlm.h +++ b/fs/gfs2/locking/dlm/lock_dlm.h @@ -26,7 +26,7 @@ #include #include -#include "../../lm_interface.h" +#include /* * Internally, we prefix things with gdlm_ and GDLM_ (for gfs-dlm) since a diff --git a/fs/gfs2/locking/nolock/main.c b/fs/gfs2/locking/nolock/main.c index 7b263fc6c273..acfbc941f319 100644 --- a/fs/gfs2/locking/nolock/main.c +++ b/fs/gfs2/locking/nolock/main.c @@ -14,8 +14,7 @@ #include #include #include - -#include "../../lm_interface.h" +#include struct nolock_lockspace { unsigned int nl_lvb_size; diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index ab341cd0a76a..08b80b263ade 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -14,9 +14,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "bmap.h" #include "glock.h" diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index f8f6d4b56a01..e44d245d51d4 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -13,9 +13,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "glock.h" #include "log.h" diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index d2867988cc34..7903be735fe9 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -15,10 +15,10 @@ #include #include #include +#include #include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "ops_fstype.h" #include "sys.h" diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 6af3521339fc..a5630ec6c045 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -18,9 +18,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "glock.h" #include "glops.h" diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c index 257c4a179dc6..ef3092e29607 100644 --- a/fs/gfs2/mount.c +++ b/fs/gfs2/mount.c @@ -13,9 +13,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "mount.h" #include "sys.h" diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 7cd53d118c89..91ec8080eeb2 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -17,9 +17,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "bmap.h" #include "glock.h" diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c index fa6ceffc7d82..00041b1b8025 100644 --- a/fs/gfs2/ops_dentry.c +++ b/fs/gfs2/ops_dentry.c @@ -15,9 +15,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "dir.h" #include "glock.h" diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c index 470e8829e7f4..86127d93bd35 100644 --- a/fs/gfs2/ops_export.c +++ b/fs/gfs2/ops_export.c @@ -14,9 +14,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "dir.h" #include "glock.h" diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index b551074a3c98..80f3ff0bba7b 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -22,10 +22,10 @@ #include #include #include +#include #include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "bmap.h" #include "dir.h" diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index e8b7a1ae163b..e32a6b242e0c 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -17,9 +17,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "daemon.h" #include "glock.h" diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 2f38313b4bd5..bb2ef6a86533 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -19,10 +19,10 @@ #include #include #include +#include #include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "acl.h" #include "bmap.h" diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 975e93b7992e..f9538849c418 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -19,9 +19,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "glock.h" #include "inode.h" diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c index 3b3463144126..5453d2947ab3 100644 --- a/fs/gfs2/ops_vm.c +++ b/fs/gfs2/ops_vm.c @@ -15,9 +15,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "bmap.h" #include "glock.h" diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index bc9ad058d20e..c5eb6c646177 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -44,9 +44,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "bmap.h" #include "glock.h" diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 130e9fbf9692..518f9128137e 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -14,9 +14,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "bmap.h" #include "glock.h" diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 7a5ab817ad9c..113b4ace6893 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -14,9 +14,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "glock.h" #include "glops.h" diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index f1d07d987c7b..fe207a3e206e 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -15,9 +15,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "bmap.h" #include "dir.h" diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index c9b23084918f..0e0ec988f731 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -15,10 +15,10 @@ #include #include #include +#include #include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "lm.h" #include "sys.h" diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index acf840160d5f..f8dabf8446bb 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -14,9 +14,9 @@ #include #include #include +#include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "glock.h" #include "log.h" diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index d72eb8addc7a..196c604faadc 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -14,10 +14,10 @@ #include #include #include +#include #include #include "gfs2.h" -#include "lm_interface.h" #include "incore.h" #include "glock.h" #include "lm.h" diff --git a/include/linux/Kbuild b/include/linux/Kbuild index 2121cde187d8..d8e720f9c21a 100644 --- a/include/linux/Kbuild +++ b/include/linux/Kbuild @@ -45,9 +45,9 @@ unifdef-y += acct.h adb.h adfs_fs.h agpgart.h apm_bios.h atalk.h \ inet_diag.h in.h inotify.h input.h ipc.h ipmi.h ipv6.h \ ipv6_route.h isdn.h isdnif.h isdn_ppp.h isicom.h jbd.h \ joystick.h kdev_t.h kd.h kernelcapi.h kernel.h keyboard.h \ - llc.h loop.h lp.h mempolicy.h mii.h mman.h mroute.h msdos_fs.h \ - msg.h nbd.h ncp_fs.h ncp.h ncp_mount.h netdevice.h \ - netfilter_bridge.h netfilter_decnet.h netfilter.h \ + llc.h lm_interface.h loop.h lp.h mempolicy.h mii.h mman.h \ + mroute.h msdos_fs.h msg.h nbd.h ncp_fs.h ncp.h ncp_mount.h \ + netdevice.h netfilter_bridge.h netfilter_decnet.h netfilter.h \ netfilter_ipv4.h netfilter_ipv6.h netfilter_logging.h net.h \ netlink.h nfs3.h nfs4.h nfsacl.h nfs_fs.h nfs.h nfs_idmap.h \ n_r3964.h nubus.h nvram.h parport.h patchkey.h pci.h pktcdvd.h \ diff --git a/fs/gfs2/lm_interface.h b/include/linux/lm_interface.h similarity index 100% rename from fs/gfs2/lm_interface.h rename to include/linux/lm_interface.h From 74669416f747363c14dba2ee6137540ae5a6834f Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 19 Sep 2006 11:17:38 -0400 Subject: [PATCH 270/292] [GFS2] Use list_for_each_entry_safe_reverse in gfs2_ail1_start() This is an attempt to fix Red Hat bz 204364. I don't hit it all the time, but with these changes, running postmark which used to trigger it on a regular basis no longer appears to. So I'm not saying that its 100% certain that its fixed, but it does look promising at the moment. Signed-off-by: Steven Whitehouse --- fs/gfs2/log.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 08b80b263ade..6112d648b7ee 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -62,8 +62,9 @@ void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags) { struct list_head *head = &sdp->sd_ail1_list; u64 sync_gen; - struct list_head *first, *tmp; - struct gfs2_ail *first_ai, *ai; + struct list_head *first; + struct gfs2_ail *first_ai, *ai, *tmp; + int done = 0; gfs2_log_lock(sdp); if (list_empty(head)) { @@ -75,27 +76,25 @@ void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags) first = head->prev; first_ai = list_entry(first, struct gfs2_ail, ai_list); first_ai->ai_sync_gen = sync_gen; - gfs2_ail1_start_one(sdp, first_ai); + gfs2_ail1_start_one(sdp, first_ai); /* This may drop log lock */ if (flags & DIO_ALL) first = NULL; - for (;;) { + while(!done) { if (first && (head->prev != first || gfs2_ail1_empty_one(sdp, first_ai, 0))) break; - for (tmp = head->prev; tmp != head; tmp = tmp->prev) { - ai = list_entry(tmp, struct gfs2_ail, ai_list); + done = 1; + list_for_each_entry_safe_reverse(ai, tmp, head, ai_list) { if (ai->ai_sync_gen >= sync_gen) continue; ai->ai_sync_gen = sync_gen; - gfs2_ail1_start_one(sdp, ai); + gfs2_ail1_start_one(sdp, ai); /* This may drop log lock */ + done = 0; break; } - - if (tmp == head) - break; } gfs2_log_unlock(sdp); From f0e522a901f209d55992a20f4e30123b43af37dd Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 19 Sep 2006 16:41:11 -0400 Subject: [PATCH 271/292] [GFS2] Remove "NFS only" readdir path This code path shouldn't be needed, so remove it for now. This tidys things up. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 187 +++------------------------------------------ 1 file changed, 9 insertions(+), 178 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 80f3ff0bba7b..372dbcb3f7f3 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -43,27 +43,6 @@ #include "util.h" #include "eaops.h" -/* "bad" is for NFS support */ -struct filldir_bad_entry { - char *fbe_name; - unsigned int fbe_length; - u64 fbe_offset; - struct gfs2_inum fbe_inum; - unsigned int fbe_type; -}; - -struct filldir_bad { - struct gfs2_sbd *fdb_sbd; - - struct filldir_bad_entry *fdb_entry; - unsigned int fdb_entry_num; - unsigned int fdb_entry_off; - - char *fdb_name; - unsigned int fdb_name_size; - unsigned int fdb_name_off; -}; - /* For regular, non-NFS */ struct filldir_reg { struct gfs2_sbd *fdr_sbd; @@ -149,7 +128,7 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) } /** - * filldir_reg_func - Report a directory entry to the caller of gfs2_dir_read() + * filldir_func - Report a directory entry to the caller of gfs2_dir_read() * @opaque: opaque data used by the function * @name: the name of the directory entry * @length: the length of the name @@ -160,9 +139,9 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) * Returns: 0 on success, 1 if buffer full */ -static int filldir_reg_func(void *opaque, const char *name, unsigned int length, - u64 offset, struct gfs2_inum *inum, - unsigned int type) +static int filldir_func(void *opaque, const char *name, unsigned int length, + u64 offset, struct gfs2_inum *inum, + unsigned int type) { struct filldir_reg *fdr = (struct filldir_reg *)opaque; struct gfs2_sbd *sdp = fdr->fdr_sbd; @@ -174,11 +153,9 @@ static int filldir_reg_func(void *opaque, const char *name, unsigned int length, return 1; if (fdr->fdr_prefetch && !(length == 1 && *name == '.')) { - gfs2_glock_prefetch_num(sdp, - inum->no_addr, &gfs2_inode_glops, + gfs2_glock_prefetch_num(sdp, inum->no_addr, &gfs2_inode_glops, LM_ST_SHARED, LM_FLAG_TRY | LM_FLAG_ANY); - gfs2_glock_prefetch_num(sdp, - inum->no_addr, &gfs2_iopen_glops, + gfs2_glock_prefetch_num(sdp, inum->no_addr, &gfs2_iopen_glops, LM_ST_SHARED, LM_FLAG_TRY); } @@ -186,7 +163,7 @@ static int filldir_reg_func(void *opaque, const char *name, unsigned int length, } /** - * readdir_reg - Read directory entries from a directory + * gfs2_readdir - Read directory entries from a directory * @file: The directory to read from * @dirent: Buffer for dirents * @filldir: Function used to do the copying @@ -194,7 +171,7 @@ static int filldir_reg_func(void *opaque, const char *name, unsigned int length, * Returns: errno */ -static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) +static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) { struct inode *dir = file->f_mapping->host; struct gfs2_inode *dip = GFS2_I(dir); @@ -215,7 +192,7 @@ static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) return error; } - error = gfs2_dir_read(dir, &offset, &fdr, filldir_reg_func); + error = gfs2_dir_read(dir, &offset, &fdr, filldir_func); gfs2_glock_dq_uninit(&d_gh); @@ -224,152 +201,6 @@ static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) return error; } -/** - * filldir_bad_func - Report a directory entry to the caller of gfs2_dir_read() - * @opaque: opaque data used by the function - * @name: the name of the directory entry - * @length: the length of the name - * @offset: the entry's offset in the directory - * @inum: the inode number the entry points to - * @type: the type of inode the entry points to - * - * For supporting NFS. - * - * Returns: 0 on success, 1 if buffer full - */ - -static int filldir_bad_func(void *opaque, const char *name, unsigned int length, - u64 offset, struct gfs2_inum *inum, - unsigned int type) -{ - struct filldir_bad *fdb = (struct filldir_bad *)opaque; - struct gfs2_sbd *sdp = fdb->fdb_sbd; - struct filldir_bad_entry *fbe; - - if (fdb->fdb_entry_off == fdb->fdb_entry_num || - fdb->fdb_name_off + length > fdb->fdb_name_size) - return 1; - - fbe = &fdb->fdb_entry[fdb->fdb_entry_off]; - fbe->fbe_name = fdb->fdb_name + fdb->fdb_name_off; - memcpy(fbe->fbe_name, name, length); - fbe->fbe_length = length; - fbe->fbe_offset = offset; - fbe->fbe_inum = *inum; - fbe->fbe_type = type; - - fdb->fdb_entry_off++; - fdb->fdb_name_off += length; - - if (!(length == 1 && *name == '.')) { - gfs2_glock_prefetch_num(sdp, - inum->no_addr, &gfs2_inode_glops, - LM_ST_SHARED, LM_FLAG_TRY | LM_FLAG_ANY); - gfs2_glock_prefetch_num(sdp, - inum->no_addr, &gfs2_iopen_glops, - LM_ST_SHARED, LM_FLAG_TRY); - } - - return 0; -} - -/** - * readdir_bad - Read directory entries from a directory - * @file: The directory to read from - * @dirent: Buffer for dirents - * @filldir: Function used to do the copying - * - * For supporting NFS. - * - * Returns: errno - */ - -static int readdir_bad(struct file *file, void *dirent, filldir_t filldir) -{ - struct inode *dir = file->f_mapping->host; - struct gfs2_inode *dip = GFS2_I(dir); - struct gfs2_sbd *sdp = GFS2_SB(dir); - struct filldir_reg fdr; - unsigned int entries, size; - struct filldir_bad *fdb; - struct gfs2_holder d_gh; - u64 offset = file->f_pos; - unsigned int x; - struct filldir_bad_entry *fbe; - int error; - - entries = gfs2_tune_get(sdp, gt_entries_per_readdir); - size = sizeof(struct filldir_bad) + - entries * (sizeof(struct filldir_bad_entry) + GFS2_FAST_NAME_SIZE); - - fdb = kzalloc(size, GFP_KERNEL); - if (!fdb) - return -ENOMEM; - - fdb->fdb_sbd = sdp; - fdb->fdb_entry = (struct filldir_bad_entry *)(fdb + 1); - fdb->fdb_entry_num = entries; - fdb->fdb_name = ((char *)fdb) + sizeof(struct filldir_bad) + - entries * sizeof(struct filldir_bad_entry); - fdb->fdb_name_size = entries * GFS2_FAST_NAME_SIZE; - - gfs2_holder_init(dip->i_gl, LM_ST_SHARED, GL_ATIME, &d_gh); - error = gfs2_glock_nq_atime(&d_gh); - if (error) { - gfs2_holder_uninit(&d_gh); - goto out; - } - - error = gfs2_dir_read(dir, &offset, fdb, filldir_bad_func); - - gfs2_glock_dq_uninit(&d_gh); - - fdr.fdr_sbd = sdp; - fdr.fdr_prefetch = 0; - fdr.fdr_filldir = filldir; - fdr.fdr_opaque = dirent; - - for (x = 0; x < fdb->fdb_entry_off; x++) { - fbe = &fdb->fdb_entry[x]; - - error = filldir_reg_func(&fdr, - fbe->fbe_name, fbe->fbe_length, - fbe->fbe_offset, - &fbe->fbe_inum, fbe->fbe_type); - if (error) { - file->f_pos = fbe->fbe_offset; - error = 0; - goto out; - } - } - - file->f_pos = offset; - -out: - kfree(fdb); - return error; -} - -/** - * gfs2_readdir - Read directory entries from a directory - * @file: The directory to read from - * @dirent: Buffer for dirents - * @filldir: Function used to do the copying - * - * Returns: errno - */ - -static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) -{ - int error; - - if (strcmp(current->comm, "nfsd") != 0) - error = readdir_reg(file, dirent, filldir); - else - error = readdir_bad(file, dirent, filldir); - - return error; -} static const u32 iflags_to_gfs2[32] = { [iflag_Sync] = GFS2_DIF_SYNC, From 56965536b8056f57830219efbba4b85218d96d6c Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 20 Sep 2006 15:48:09 -0400 Subject: [PATCH 272/292] [GFS2] Remove unused constants Three of the DIO constants were not being used, so remove them. Signed-off-by: Steven Whitehouse --- fs/gfs2/incore.h | 3 --- fs/gfs2/meta_io.c | 6 +----- fs/gfs2/ops_address.c | 4 ++-- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 89df68b32fc6..7183dcf03563 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -12,9 +12,6 @@ #include -#define DIO_FORCE 0x00000001 -#define DIO_CLEAN 0x00000002 -#define DIO_DIRTY 0x00000004 #define DIO_START 0x00000008 #define DIO_WAIT 0x00000010 #define DIO_METADATA 0x00000020 diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index a5630ec6c045..6b52aacb0736 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -120,8 +120,7 @@ void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) gfs2_io_error_bh(sdp, bh); gfs2_log_lock(sdp); } - list_move(&bd->bd_ail_st_list, - &ai->ai_ail2_list); + list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); continue; } @@ -411,9 +410,6 @@ int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags) if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) return -EIO; - if (flags & DIO_FORCE) - clear_buffer_uptodate(bh); - if ((flags & DIO_START) && !buffer_uptodate(bh)) ll_rw_block(READ, 1, &bh); diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 91ec8080eeb2..3f9da7ce5dd9 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -65,7 +65,7 @@ static void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, int gfs2_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { - return gfs2_block_map(inode, lblock, create, bh_result, 32); + return gfs2_block_map(inode, lblock, create, bh_result, 4); } /** @@ -94,7 +94,7 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock, static int gfs2_get_block_direct(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { - return gfs2_block_map(inode, lblock, 0, bh_result, 512); + return gfs2_block_map(inode, lblock, 0, bh_result, 32); } /** From 7276b3b0c77101f8b3f4e45e89a29cf9045e831a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Thu, 21 Sep 2006 17:05:23 -0400 Subject: [PATCH 273/292] [GFS2] Tidy up meta_io code Fix a bug in the directory reading code, where we might have dereferenced a NULL pointer in case of OOM. Updated the directory code to use the new & improved version of gfs2_meta_ra() which now returns the first block that was being read. Previously it was releasing it requiring following code to grab the block again at each point it was called. Also turned off readahead on directory lookups since we are reading a hash table, and therefore reading the entries in order is very unlikely. Readahead is still used for all other calls to the directory reading function (e.g. when growing the hash table). Removed the DIO_START constant. Everywhere this was used, it was used to unconditionally start i/o aside from a couple of places, so I've removed it and made the couple of exceptions to this rule into separate functions. Also hunted through the other DIO flags and removed them as arguments from functions which were always called with the same combination of arguments. Updated gfs2_meta_indirect_buffer to be a bit more efficient and hopefully also be a bit easier to read. Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 4 +- fs/gfs2/dir.c | 58 +++++++------- fs/gfs2/eattr.c | 23 +++--- fs/gfs2/glops.c | 55 ++++++++------ fs/gfs2/incore.h | 1 - fs/gfs2/lops.c | 9 +-- fs/gfs2/meta_io.c | 173 +++++++++++++++++++----------------------- fs/gfs2/meta_io.h | 6 +- fs/gfs2/ops_address.c | 2 +- fs/gfs2/quota.c | 16 ++-- fs/gfs2/recovery.c | 3 +- fs/gfs2/rgrp.c | 5 +- 12 files changed, 164 insertions(+), 191 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 19b9bfc10349..3fb9a26b6f58 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -448,6 +448,8 @@ static int gfs2_block_pointers(struct inode *inode, u64 lblock, int create, u64 dblock = 0; int boundary; + BUG_ON(maxlen == 0); + if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) return 0; @@ -561,7 +563,7 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsi BUG_ON(!new); bmap_lock(inode, create); - ret = gfs2_block_pointers(inode, lblock, create, &bh, &mp, *extlen); + ret = gfs2_block_pointers(inode, lblock, create, &bh, &mp, 32); bmap_unlock(inode, create); *extlen = bh.b_size >> inode->i_blkbits; *dblock = bh.b_blocknr; diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 739028688270..40e94ac0b93d 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -106,7 +106,7 @@ static int gfs2_dir_get_existing_buffer(struct gfs2_inode *ip, u64 block, struct buffer_head *bh; int error; - error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT, &bh); + error = gfs2_meta_read(ip->i_gl, block, DIO_WAIT, &bh); if (error) return error; if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_JD)) { @@ -246,7 +246,7 @@ fail: } static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf, - unsigned int offset, unsigned int size) + u64 offset, unsigned int size) { struct buffer_head *dibh; int error; @@ -271,8 +271,8 @@ static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf, * * Returns: The amount of data actually copied or the error */ -static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, - u64 offset, unsigned int size) +static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, u64 offset, + unsigned int size, unsigned ra) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); u64 lblock, dblock; @@ -291,8 +291,7 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, return 0; if (gfs2_is_stuffed(ip)) - return gfs2_dir_read_stuffed(ip, buf, (unsigned int)offset, - size); + return gfs2_dir_read_stuffed(ip, buf, offset, size); if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) return -EINVAL; @@ -313,34 +312,31 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, new = 0; error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen); + if (error || !dblock) + goto fail; + BUG_ON(extlen < 1); + if (!ra) + extlen = 1; + bh = gfs2_meta_ra(ip->i_gl, dblock, extlen); + } + if (!bh) { + error = gfs2_meta_read(ip->i_gl, dblock, DIO_WAIT, &bh); if (error) goto fail; } - - if (extlen > 1) - gfs2_meta_ra(ip->i_gl, dblock, extlen); - - if (dblock) { - if (new) - error = gfs2_dir_get_new_buffer(ip, dblock, &bh); - else - error = gfs2_dir_get_existing_buffer(ip, dblock, &bh); - if (error) - goto fail; - dblock++; - extlen--; - } else - bh = NULL; - + error = gfs2_metatype_check(sdp, bh, GFS2_METATYPE_JD); + if (error) { + brelse(bh); + goto fail; + } + dblock++; + extlen--; memcpy(buf, bh->b_data + o, amount); brelse(bh); - if (error) - goto fail; - + bh = NULL; buf += amount; copied += amount; lblock++; - o = sizeof(struct gfs2_meta_header); } @@ -701,7 +697,7 @@ static int get_leaf(struct gfs2_inode *dip, u64 leaf_no, { int error; - error = gfs2_meta_read(dip->i_gl, leaf_no, DIO_START | DIO_WAIT, bhp); + error = gfs2_meta_read(dip->i_gl, leaf_no, DIO_WAIT, bhp); if (!error && gfs2_metatype_check(GFS2_SB(&dip->i_inode), *bhp, GFS2_METATYPE_LF)) { /* printk(KERN_INFO "block num=%llu\n", leaf_no); */ error = -EIO; @@ -727,7 +723,7 @@ static int get_leaf_nr(struct gfs2_inode *dip, u32 index, error = gfs2_dir_read_data(dip, (char *)&leaf_no, index * sizeof(u64), - sizeof(u64)); + sizeof(u64), 0); if (error != sizeof(u64)) return (error < 0) ? error : -EIO; @@ -1095,7 +1091,7 @@ static int dir_double_exhash(struct gfs2_inode *dip) for (block = dip->i_di.di_size >> sdp->sd_hash_bsize_shift; block--;) { error = gfs2_dir_read_data(dip, (char *)buf, block * sdp->sd_hash_bsize, - sdp->sd_hash_bsize); + sdp->sd_hash_bsize, 1); if (error != sdp->sd_hash_bsize) { if (error >= 0) error = -EIO; @@ -1375,7 +1371,7 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque, if (ht_offset_cur != ht_offset) { error = gfs2_dir_read_data(dip, (char *)lp, ht_offset * sizeof(u64), - sdp->sd_hash_bsize); + sdp->sd_hash_bsize, 1); if (error != sdp->sd_hash_bsize) { if (error >= 0) error = -EIO; @@ -1745,7 +1741,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) if (ht_offset_cur != ht_offset) { error = gfs2_dir_read_data(dip, (char *)lp, ht_offset * sizeof(u64), - sdp->sd_hash_bsize); + sdp->sd_hash_bsize, 1); if (error != sdp->sd_hash_bsize) { if (error >= 0) error = -EIO; diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index 698942ec7c99..bd5ca602f9f0 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -115,7 +115,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) u64 *eablk, *end; int error; - error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_START | DIO_WAIT, &bh); + error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_WAIT, &bh); if (error) return error; @@ -139,7 +139,7 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) break; bn = be64_to_cpu(*eablk); - error = gfs2_meta_read(ip->i_gl, bn, DIO_START | DIO_WAIT, &eabh); + error = gfs2_meta_read(ip->i_gl, bn, DIO_WAIT, &eabh); if (error) break; error = ea_foreach_i(ip, eabh, ea_call, data); @@ -453,8 +453,8 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, return -ENOMEM; for (x = 0; x < nptrs; x++) { - error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), - DIO_START, bh + x); + error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), 0, + bh + x); if (error) { while (x--) brelse(bh[x]); @@ -464,7 +464,7 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, } for (x = 0; x < nptrs; x++) { - error = gfs2_meta_reread(sdp, bh[x], DIO_WAIT); + error = gfs2_meta_wait(sdp, bh[x]); if (error) { for (; x < nptrs; x++) brelse(bh[x]); @@ -938,8 +938,8 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, if (ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT) { u64 *end; - error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, - DIO_START | DIO_WAIT, &indbh); + error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_WAIT, + &indbh); if (error) return error; @@ -1215,8 +1215,8 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, goto out; for (x = 0; x < nptrs; x++) { - error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), - DIO_START, bh + x); + error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), 0, + bh + x); if (error) { while (x--) brelse(bh[x]); @@ -1226,7 +1226,7 @@ static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, } for (x = 0; x < nptrs; x++) { - error = gfs2_meta_reread(sdp, bh[x], DIO_WAIT); + error = gfs2_meta_wait(sdp, bh[x]); if (error) { for (; x < nptrs; x++) brelse(bh[x]); @@ -1310,8 +1310,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip) memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); - error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, - DIO_START | DIO_WAIT, &indbh); + error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_WAIT, &indbh); if (error) return error; diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 9c046dbf4729..ef1492e2d445 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -77,32 +77,24 @@ static void gfs2_page_inval(struct gfs2_glock *gl) } /** - * gfs2_page_sync - Sync the data pages (not metadata) associated with a glock + * gfs2_page_wait - Wait for writeback of data * @gl: the glock - * @flags: DIO_START | DIO_WAIT * * Syncs data (not metadata) for a regular file. * No-op for all other types. */ -static void gfs2_page_sync(struct gfs2_glock *gl, int flags) +static void gfs2_page_wait(struct gfs2_glock *gl) { - struct gfs2_inode *ip; - struct inode *inode; - struct address_space *mapping; - int error = 0; + struct gfs2_inode *ip = gl->gl_object; + struct inode *inode = &ip->i_inode; + struct address_space *mapping = inode->i_mapping; + int error; - ip = gl->gl_object; - inode = &ip->i_inode; - if (!ip || !S_ISREG(ip->i_di.di_mode)) + if (!S_ISREG(ip->i_di.di_mode)) return; - mapping = inode->i_mapping; - - if (flags & DIO_START) - filemap_fdatawrite(mapping); - if (!error && (flags & DIO_WAIT)) - error = filemap_fdatawait(mapping); + error = filemap_fdatawait(mapping); /* Put back any errors cleared by filemap_fdatawait() so they can be caught by someone who can pass them @@ -115,6 +107,18 @@ static void gfs2_page_sync(struct gfs2_glock *gl, int flags) } +static void gfs2_page_writeback(struct gfs2_glock *gl) +{ + struct gfs2_inode *ip = gl->gl_object; + struct inode *inode = &ip->i_inode; + struct address_space *mapping = inode->i_mapping; + + if (!S_ISREG(ip->i_di.di_mode)) + return; + + filemap_fdatawrite(mapping); +} + /** * meta_go_sync - sync out the metadata for this glock * @gl: the glock @@ -132,7 +136,7 @@ static void meta_go_sync(struct gfs2_glock *gl, int flags) if (test_and_clear_bit(GLF_DIRTY, &gl->gl_flags)) { gfs2_log_flush(gl->gl_sbd, gl); - gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); + gfs2_meta_sync(gl); if (flags & DIO_RELEASE) gfs2_ail_empty_gl(gl); } @@ -185,8 +189,7 @@ static void inode_go_xmote_bh(struct gfs2_glock *gl) if (gl->gl_state != LM_ST_UNLOCKED && (!gh || !(gh->gh_flags & GL_SKIP))) { - error = gfs2_meta_read(gl, gl->gl_name.ln_number, DIO_START, - &bh); + error = gfs2_meta_read(gl, gl->gl_name.ln_number, 0, &bh); if (!error) brelse(bh); } @@ -221,16 +224,18 @@ static void inode_go_sync(struct gfs2_glock *gl, int flags) if (test_bit(GLF_DIRTY, &gl->gl_flags)) { if (meta && data) { - gfs2_page_sync(gl, flags | DIO_START); + gfs2_page_writeback(gl); gfs2_log_flush(gl->gl_sbd, gl); - gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); - gfs2_page_sync(gl, flags | DIO_WAIT); + gfs2_meta_sync(gl); + gfs2_page_wait(gl); clear_bit(GLF_DIRTY, &gl->gl_flags); } else if (meta) { gfs2_log_flush(gl->gl_sbd, gl); - gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); - } else if (data) - gfs2_page_sync(gl, flags | DIO_START | DIO_WAIT); + gfs2_meta_sync(gl); + } else if (data) { + gfs2_page_writeback(gl); + gfs2_page_wait(gl); + } if (flags & DIO_RELEASE) gfs2_ail_empty_gl(gl); } diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 7183dcf03563..118dc693d111 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -12,7 +12,6 @@ #include -#define DIO_START 0x00000008 #define DIO_WAIT 0x00000010 #define DIO_METADATA 0x00000020 #define DIO_DATA 0x00000040 diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index e44d245d51d4..2a98cbe3290f 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -248,13 +248,13 @@ static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); if (error) { - gfs2_meta_sync(ip->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(ip->i_gl); return; } if (pass != 1) return; - gfs2_meta_sync(ip->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(ip->i_gl); fs_info(sdp, "jid=%u: Replayed %u of %u blocks\n", jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); @@ -726,15 +726,14 @@ static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); if (error) { - gfs2_meta_sync(ip->i_gl, - DIO_START | DIO_WAIT); + gfs2_meta_sync(ip->i_gl); return; } if (pass != 1) return; /* data sync? */ - gfs2_meta_sync(ip->i_gl, DIO_START | DIO_WAIT); + gfs2_meta_sync(ip->i_gl); fs_info(sdp, "jid=%u: Replayed %u of %u data blocks\n", jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 6b52aacb0736..d3708af0a4d1 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -273,19 +273,16 @@ void gfs2_meta_inval(struct gfs2_glock *gl) /** * gfs2_meta_sync - Sync all buffers associated with a glock * @gl: The glock - * @flags: DIO_START | DIO_WAIT * */ -void gfs2_meta_sync(struct gfs2_glock *gl, int flags) +void gfs2_meta_sync(struct gfs2_glock *gl) { struct address_space *mapping = gl->gl_aspace->i_mapping; - int error = 0; + int error; - if (flags & DIO_START) - filemap_fdatawrite(mapping); - if (!error && (flags & DIO_WAIT)) - error = filemap_fdatawait(mapping); + filemap_fdatawrite(mapping); + error = filemap_fdatawait(mapping); if (error) gfs2_io_error(gl->gl_sbd); @@ -377,7 +374,7 @@ struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno) * gfs2_meta_read - Read a block from disk * @gl: The glock covering the block * @blkno: The block number - * @flags: flags to gfs2_dreread() + * @flags: flags * @bhp: the place where the buffer is returned (NULL on failure) * * Returns: errno @@ -386,45 +383,43 @@ struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno) int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags, struct buffer_head **bhp) { - int error; - *bhp = getbuf(gl->gl_sbd, gl->gl_aspace, blkno, CREATE); - error = gfs2_meta_reread(gl->gl_sbd, *bhp, flags); - if (error) - brelse(*bhp); + if (!buffer_uptodate(*bhp)) + ll_rw_block(READ, 1, bhp); + if (flags & DIO_WAIT) { + int error = gfs2_meta_wait(gl->gl_sbd, *bhp); + if (error) { + brelse(*bhp); + return error; + } + } - return error; + return 0; } /** - * gfs2_meta_reread - Reread a block from disk + * gfs2_meta_wait - Reread a block from disk * @sdp: the filesystem - * @bh: The block to read - * @flags: Flags that control the read + * @bh: The block to wait for * * Returns: errno */ -int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags) +int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh) { if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) return -EIO; - if ((flags & DIO_START) && !buffer_uptodate(bh)) - ll_rw_block(READ, 1, &bh); + wait_on_buffer(bh); - if (flags & DIO_WAIT) { - wait_on_buffer(bh); - - if (!buffer_uptodate(bh)) { - struct gfs2_trans *tr = current->journal_info; - if (tr && tr->tr_touched) - gfs2_io_error_bh(sdp, bh); - return -EIO; - } - if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) - return -EIO; + if (!buffer_uptodate(bh)) { + struct gfs2_trans *tr = current->journal_info; + if (tr && tr->tr_touched) + gfs2_io_error_bh(sdp, bh); + return -EIO; } + if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) + return -EIO; return 0; } @@ -635,67 +630,57 @@ void gfs2_meta_cache_flush(struct gfs2_inode *ip) int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num, int new, struct buffer_head **bhp) { - struct buffer_head *bh, **bh_slot = ip->i_cache + height; - int error; + struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); + struct gfs2_glock *gl = ip->i_gl; + struct buffer_head *bh = NULL, **bh_slot = ip->i_cache + height; + int in_cache = 0; spin_lock(&ip->i_spin); - bh = *bh_slot; - if (bh) { - if (bh->b_blocknr == num) - get_bh(bh); - else - bh = NULL; + if (*bh_slot && (*bh_slot)->b_blocknr == num) { + bh = *bh_slot; + get_bh(bh); + in_cache = 1; } spin_unlock(&ip->i_spin); - if (bh) { - if (new) - meta_prep_new(bh); - else { - error = gfs2_meta_reread(GFS2_SB(&ip->i_inode), bh, - DIO_START | DIO_WAIT); - if (error) { - brelse(bh); - return error; - } - } - } else { - if (new) - bh = gfs2_meta_new(ip->i_gl, num); - else { - error = gfs2_meta_read(ip->i_gl, num, - DIO_START | DIO_WAIT, &bh); - if (error) - return error; - } + if (!bh) + bh = getbuf(gl->gl_sbd, gl->gl_aspace, num, CREATE); - spin_lock(&ip->i_spin); - if (*bh_slot != bh) { - brelse(*bh_slot); - *bh_slot = bh; - get_bh(bh); - } - spin_unlock(&ip->i_spin); - } + if (!bh) + return -ENOBUFS; if (new) { - if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), height)) { - brelse(bh); - return -EIO; - } + if (gfs2_assert_warn(sdp, height)) + goto err; + meta_prep_new(bh); gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); + } else { + u32 mtype = height ? GFS2_METATYPE_IN : GFS2_METATYPE_DI; + if (!buffer_uptodate(bh)) { + ll_rw_block(READ, 1, &bh); + if (gfs2_meta_wait(sdp, bh)) + goto err; + } + if (gfs2_metatype_check(sdp, bh, mtype)) + goto err; + } - } else if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, - (height) ? GFS2_METATYPE_IN : GFS2_METATYPE_DI)) { - brelse(bh); - return -EIO; + if (!in_cache) { + spin_lock(&ip->i_spin); + if (*bh_slot) + brelse(*bh_slot); + *bh_slot = bh; + get_bh(bh); + spin_unlock(&ip->i_spin); } *bhp = bh; - return 0; +err: + brelse(bh); + return -EIO; } /** @@ -704,19 +689,21 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num, * @dblock: the starting disk block * @extlen: the number of blocks in the extent * + * returns: the first buffer in the extent */ -void gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen) +struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen) { struct gfs2_sbd *sdp = gl->gl_sbd; struct inode *aspace = gl->gl_aspace; struct buffer_head *first_bh, *bh; u32 max_ra = gfs2_tune_get(sdp, gt_max_readahead) >> sdp->sd_sb.sb_bsize_shift; - int error; - if (!extlen || !max_ra) - return; + BUG_ON(!extlen); + + if (max_ra < 1) + max_ra = 1; if (extlen > max_ra) extlen = max_ra; @@ -724,11 +711,8 @@ void gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen) if (buffer_uptodate(first_bh)) goto out; - if (!buffer_locked(first_bh)) { - error = gfs2_meta_reread(sdp, first_bh, DIO_START); - if (error) - goto out; - } + if (!buffer_locked(first_bh)) + ll_rw_block(READ, 1, &first_bh); dblock++; extlen--; @@ -736,23 +720,18 @@ void gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen) while (extlen) { bh = getbuf(sdp, aspace, dblock, CREATE); - if (!buffer_uptodate(bh) && !buffer_locked(bh)) { - error = gfs2_meta_reread(sdp, bh, DIO_START); - brelse(bh); - if (error) - goto out; - } else - brelse(bh); - + if (!buffer_uptodate(bh) && !buffer_locked(bh)) + ll_rw_block(READA, 1, &bh); + brelse(bh); dblock++; extlen--; - - if (buffer_uptodate(first_bh)) - break; + if (!buffer_locked(first_bh) && buffer_uptodate(first_bh)) + goto out; } + wait_on_buffer(first_bh); out: - brelse(first_bh); + return first_bh; } /** diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index 086a472df3f1..3323e6d0ed8f 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h @@ -46,12 +46,12 @@ void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai); void gfs2_ail_empty_gl(struct gfs2_glock *gl); void gfs2_meta_inval(struct gfs2_glock *gl); -void gfs2_meta_sync(struct gfs2_glock *gl, int flags); +void gfs2_meta_sync(struct gfs2_glock *gl); struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno); int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags, struct buffer_head **bhp); -int gfs2_meta_reread(struct gfs2_sbd *sdp, struct buffer_head *bh, int flags); +int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh); void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, int meta); @@ -71,7 +71,7 @@ static inline int gfs2_meta_inode_buffer(struct gfs2_inode *ip, return gfs2_meta_indirect_buffer(ip, 0, ip->i_num.no_addr, 0, bhp); } -void gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen); +struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen); void gfs2_meta_syncfs(struct gfs2_sbd *sdp); #endif /* __DIO_DOT_H__ */ diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 3f9da7ce5dd9..8b18e974fa4d 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -65,7 +65,7 @@ static void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page, int gfs2_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { - return gfs2_block_map(inode, lblock, create, bh_result, 4); + return gfs2_block_map(inode, lblock, create, bh_result, 32); } /** diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index c5eb6c646177..da46e14388f4 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -265,7 +265,7 @@ static int bh_get(struct gfs2_quota_data *qd) error = gfs2_block_map(&ip->i_inode, block, 0, &bh_map, 1); if (error) goto fail; - error = gfs2_meta_read(ip->i_gl, bh_map.b_blocknr, DIO_START | DIO_WAIT, &bh); + error = gfs2_meta_read(ip->i_gl, bh_map.b_blocknr, DIO_WAIT, &bh); if (error) goto fail; error = -EIO; @@ -1059,8 +1059,7 @@ int gfs2_quota_init(struct gfs2_sbd *sdp) u32 extlen = 0; int error; - if (!ip->i_di.di_size || - ip->i_di.di_size > (64 << 20) || + if (!ip->i_di.di_size || ip->i_di.di_size > (64 << 20) || ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1)) { gfs2_consist_inode(ip); return -EIO; @@ -1091,19 +1090,16 @@ int gfs2_quota_init(struct gfs2_sbd *sdp) if (error) goto fail; } - gfs2_meta_ra(ip->i_gl, dblock, extlen); - error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, - &bh); - if (error) - goto fail; error = -EIO; + bh = gfs2_meta_ra(ip->i_gl, dblock, extlen); + if (!bh) + goto fail; if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) { brelse(bh); goto fail; } - for (y = 0; - y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots; + for (y = 0; y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots; y++, slot++) { struct gfs2_quota_change qc; struct gfs2_quota_data *qd; diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 518f9128137e..4d4ea7e66edc 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -47,8 +47,7 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, return -EIO; } - gfs2_meta_ra(gl, dblock, extlen); - error = gfs2_meta_read(gl, dblock, DIO_START | DIO_WAIT, bh); + *bh = gfs2_meta_ra(gl, dblock, extlen); return error; } diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 113b4ace6893..5f8e225c5497 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -575,15 +575,14 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd) for (x = 0; x < length; x++) { bi = rgd->rd_bits + x; - error = gfs2_meta_read(gl, rgd->rd_ri.ri_addr + x, DIO_START, - &bi->bi_bh); + error = gfs2_meta_read(gl, rgd->rd_ri.ri_addr + x, 0, &bi->bi_bh); if (error) goto fail; } for (y = length; y--;) { bi = rgd->rd_bits + y; - error = gfs2_meta_reread(sdp, bi->bi_bh, DIO_WAIT); + error = gfs2_meta_wait(sdp, bi->bi_bh); if (error) goto fail; if (gfs2_metatype_check(sdp, bi->bi_bh, y ? GFS2_METATYPE_RB : From 907b9bceb41fa46beae93f79cc4a2247df502c0f Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 25 Sep 2006 09:26:04 -0400 Subject: [PATCH 274/292] [GFS2/DLM] Fix trailing whitespace As per Andrew Morton's request, removed trailing whitespace. Cc: Andrew Morton Signed-off-by: Steven Whitehouse --- fs/dlm/lock.c | 2 +- fs/gfs2/acl.c | 2 +- fs/gfs2/bmap.c | 4 ++-- fs/gfs2/daemon.c | 2 +- fs/gfs2/dir.c | 13 ++++++------- fs/gfs2/eaops.c | 2 +- fs/gfs2/eattr.c | 2 +- fs/gfs2/glock.c | 12 ++++++------ fs/gfs2/inode.c | 5 ++--- fs/gfs2/inode.h | 2 +- fs/gfs2/lm.c | 2 +- fs/gfs2/locking/dlm/thread.c | 4 ++-- fs/gfs2/lops.c | 2 +- fs/gfs2/main.c | 2 +- fs/gfs2/ops_address.c | 4 ++-- fs/gfs2/ops_file.c | 6 +++--- fs/gfs2/ops_fstype.c | 18 +++++++++--------- fs/gfs2/ops_inode.c | 2 +- fs/gfs2/ops_super.c | 2 +- fs/gfs2/quota.c | 6 +++--- fs/gfs2/recovery.c | 4 ++-- fs/gfs2/rgrp.c | 2 +- fs/gfs2/super.c | 5 ++--- 23 files changed, 51 insertions(+), 54 deletions(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index af2f2f01bd5f..3f2befa4797b 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -1757,7 +1757,7 @@ static int do_unlock(struct dlm_rsb *r, struct dlm_lkb *lkb) skip the queue_cast(ECANCEL). It indicates that the request/convert completed (and queued a normal ast) just before the cancel; we don't want to clobber the sb_result for the normal ast with ECANCEL. */ - + static int do_cancel(struct dlm_rsb *r, struct dlm_lkb *lkb) { revert_lock(r, lkb); diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index 3123fc071233..5f959b8ce406 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c @@ -181,7 +181,7 @@ int gfs2_check_acl(struct inode *inode, int mask) error = gfs2_check_acl_locked(inode, mask); gfs2_glock_dq_uninit(&i_gh); } - + return error; } diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 3fb9a26b6f58..92eef825167d 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -130,7 +130,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) error = gfs2_meta_inode_buffer(ip, &dibh); if (error) goto out; - + if (ip->i_di.di_size) { /* Get a free block, fill it with the stuffed data, and write it out to disk */ @@ -246,7 +246,7 @@ static int build_height(struct inode *inode, unsigned height) blocks[n] = gfs2_meta_new(ip->i_gl, bn); gfs2_trans_add_bh(ip->i_gl, blocks[n], 1); } - + n = 0; bn = blocks[0]->b_blocknr; if (new_height > 1) { diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c index a9908cd78cd9..cab1f68d4685 100644 --- a/fs/gfs2/daemon.c +++ b/fs/gfs2/daemon.c @@ -30,7 +30,7 @@ /* This uses schedule_timeout() instead of msleep() because it's good for the daemons to wake up more often than the timeout when unmounting so the user's unmount doesn't sit there forever. - + The kthread functions used to start these daemons block and flush signals. */ /** diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 40e94ac0b93d..459498cac93b 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -81,7 +81,7 @@ #define gfs2_disk_hash2offset(h) (((u64)(h)) >> 1) #define gfs2_dir_offset2hash(p) ((u32)(((u64)(p)) << 1)) -typedef int (*leaf_call_t) (struct gfs2_inode *dip, u32 index, u32 len, +typedef int (*leaf_call_t) (struct gfs2_inode *dip, u32 index, u32 len, u64 leaf_no, void *data); typedef int (*gfs2_dscan_t)(const struct gfs2_dirent *dent, const struct qstr *name, void *opaque); @@ -119,7 +119,6 @@ static int gfs2_dir_get_existing_buffer(struct gfs2_inode *ip, u64 block, static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf, unsigned int offset, unsigned int size) - { struct buffer_head *dibh; int error; @@ -685,7 +684,7 @@ static struct gfs2_dirent *gfs2_dirent_alloc(struct inode *inode, const struct qstr *name) { struct gfs2_dirent *dent; - dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, + dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, gfs2_dirent_find_space, name, NULL); if (!dent || IS_ERR(dent)) return dent; @@ -764,7 +763,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, gfs2_consist_inode(ip); return ERR_PTR(-EIO); } - + index = name->hash >> (32 - ip->i_di.di_depth); error = get_first_leaf(ip, index, &bh); if (error) @@ -779,14 +778,14 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode, brelse(bh); if (!ln) break; - + error = get_leaf(ip, ln, &bh); } while(!error); return error ? ERR_PTR(error) : NULL; } - + error = gfs2_meta_inode_buffer(ip, &bh); if (error) return ERR_PTR(error); @@ -810,7 +809,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, struct qstr name = { .name = "", .len = 0, .hash = 0 }; if (!bh) return NULL; - + gfs2_trans_add_bh(ip->i_gl, bh, 1); gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); leaf = (struct gfs2_leaf *)bh->b_data; diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c index 1a7877fe7393..92c54e9b0dc3 100644 --- a/fs/gfs2/eaops.c +++ b/fs/gfs2/eaops.c @@ -146,7 +146,7 @@ static int system_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) if (error == -ENODATA) error = 0; } - return error; + return error; } return -EPERM; diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c index bd5ca602f9f0..a65a4ccfd4dd 100644 --- a/fs/gfs2/eattr.c +++ b/fs/gfs2/eattr.c @@ -1133,7 +1133,7 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el) gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); - } + } gfs2_trans_end(GFS2_SB(&ip->i_inode)); diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index f98694e7d668..78fe0fae23ff 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -371,7 +371,7 @@ fail_aspace: if (gl->gl_aspace) gfs2_aspace_put(gl->gl_aspace); fail: - kmem_cache_free(gfs2_glock_cachep, gl); + kmem_cache_free(gfs2_glock_cachep, gl); return error; } @@ -614,7 +614,7 @@ static int rq_greedy(struct gfs2_holder *gh) gfs2_holder_uninit(gh); kfree(container_of(gh, struct greedy, gr_gh)); - spin_lock(&gl->gl_spin); + spin_lock(&gl->gl_spin); return 0; } @@ -1184,11 +1184,11 @@ static void add_to_queue(struct gfs2_holder *gh) if (existing) { print_symbol(KERN_WARNING "original: %s\n", existing->gh_ip); printk(KERN_INFO "pid : %d\n", existing->gh_owner->pid); - printk(KERN_INFO "lock type : %d lock state : %d\n", + printk(KERN_INFO "lock type : %d lock state : %d\n", existing->gh_gl->gl_name.ln_type, existing->gh_gl->gl_state); print_symbol(KERN_WARNING "new: %s\n", gh->gh_ip); printk(KERN_INFO "pid : %d\n", gh->gh_owner->pid); - printk(KERN_INFO "lock type : %d lock state : %d\n", + printk(KERN_INFO "lock type : %d lock state : %d\n", gl->gl_name.ln_type, gl->gl_state); BUG(); } @@ -1203,7 +1203,7 @@ static void add_to_queue(struct gfs2_holder *gh) if (gh->gh_flags & LM_FLAG_PRIORITY) list_add(&gh->gh_list, &gl->gl_waiters3); else - list_add_tail(&gh->gh_list, &gl->gl_waiters3); + list_add_tail(&gh->gh_list, &gl->gl_waiters3); } /** @@ -2003,7 +2003,7 @@ void gfs2_gl_hash_clear(struct gfs2_sbd *sdp, int wait) for (;;) { cont = 0; for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { - if (examine_bucket(clear_glock, sdp, x)) + if (examine_bucket(clear_glock, sdp, x)) cont = 1; } diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index b9e4bcb3bf1e..ac9535be304f 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -386,7 +386,6 @@ struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, int is_root, struct nameidata *nd) - { struct super_block *sb = dir->i_sb; struct gfs2_inode *dip = GFS2_I(dir); @@ -491,7 +490,7 @@ static int pick_formal_ino_2(struct gfs2_sbd *sdp, u64 *formal_ino) error = gfs2_meta_inode_buffer(ip, &bh); if (error) goto out_end_trans; - + gfs2_inum_range_in(&ir, bh->b_data + sizeof(struct gfs2_dinode)); if (!ir.ir_length) { @@ -769,7 +768,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + al->al_rgd->rd_ri.ri_length + - 2 * RES_DINODE + + 2 * RES_DINODE + RES_STATFS + RES_QUOTA, 0); if (error) goto fail_ipreserv; diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h index 32015d89f249..f5d861760579 100644 --- a/fs/gfs2/inode.h +++ b/fs/gfs2/inode.h @@ -34,7 +34,7 @@ int gfs2_inode_refresh(struct gfs2_inode *ip); int gfs2_dinode_dealloc(struct gfs2_inode *inode); int gfs2_change_nlink(struct gfs2_inode *ip, int diff); -struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, +struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, int is_root, struct nameidata *nd); struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, unsigned int mode); diff --git a/fs/gfs2/lm.c b/fs/gfs2/lm.c index 2109fc4791d4..effe4a337c1d 100644 --- a/fs/gfs2/lm.c +++ b/fs/gfs2/lm.c @@ -106,7 +106,7 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) fs_err(sdp, "about to withdraw from the cluster\n"); BUG_ON(sdp->sd_args.ar_debug); - + fs_err(sdp, "waiting for outstanding I/O\n"); diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c index 554bf882a4c2..9cf1f168eaf8 100644 --- a/fs/gfs2/locking/dlm/thread.c +++ b/fs/gfs2/locking/dlm/thread.c @@ -54,7 +54,7 @@ static void process_complete(struct gdlm_lock *lp) if (lp->lksb.sb_status == -DLM_ECANCEL) { log_info("complete dlm cancel %x,%llx flags %lx", - lp->lockname.ln_type, + lp->lockname.ln_type, (unsigned long long)lp->lockname.ln_number, lp->flags); @@ -102,7 +102,7 @@ static void process_complete(struct gdlm_lock *lp) if (test_and_clear_bit(LFL_CANCEL, &lp->flags)) { log_info("complete internal cancel %x,%llx", - lp->lockname.ln_type, + lp->lockname.ln_type, (unsigned long long)lp->lockname.ln_number); lp->req = lp->cur; acb.lc_ret |= LM_OUT_CANCELED; diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 2a98cbe3290f..881e337b6a70 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c @@ -420,7 +420,7 @@ static void rg_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) gfs2_log_lock(sdp); sdp->sd_log_num_rg++; list_add(&le->le_list, &sdp->sd_log_le_rg); - gfs2_log_unlock(sdp); + gfs2_log_unlock(sdp); } static void rg_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index 7903be735fe9..21508a13bb78 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -77,7 +77,7 @@ static int __init init_gfs2_fs(void) error = -ENOMEM; gfs2_glock_cachep = kmem_cache_create("gfs2_glock", sizeof(struct gfs2_glock), - 0, 0, + 0, 0, gfs2_init_glock_once, NULL); if (!gfs2_glock_cachep) goto fail; diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 8b18e974fa4d..811f4ada2a01 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -296,7 +296,7 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping, LM_FLAG_TRY_1CB|GL_ATIME|GL_AOP, &gh); do_unlock = 1; ret = gfs2_glock_nq_m_atime(1, &gh); - if (ret == GLR_TRYFAILED) + if (ret == GLR_TRYFAILED) goto out_noerror; if (unlikely(ret)) goto out_unlock; @@ -681,7 +681,7 @@ static unsigned limit = 0; gl = bd->bd_gl; - fs_warn(sdp, "gl = (%u, %llu)\n", + fs_warn(sdp, "gl = (%u, %llu)\n", gl->gl_name.ln_type, (unsigned long long)gl->gl_name.ln_number); fs_warn(sdp, "bd_list_tr = %s, bd_le.le_list = %s\n", diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index 372dbcb3f7f3..a9ac1358ce21 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -236,7 +236,7 @@ static int gfs2_get_flags(struct file *filp, u32 __user *ptr) error = gfs2_glock_nq_m_atime(1, &gh); if (error) return error; - + iflags = iflags_cvt(gfs2_to_iflags, ip->i_di.di_flags); if (put_user(iflags, ptr)) error = -EFAULT; @@ -299,7 +299,7 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) goto out; if (IS_APPEND(inode) && (new_flags & GFS2_DIF_APPENDONLY)) goto out; - if (((new_flags ^ flags) & GFS2_DIF_IMMUTABLE) && + if (((new_flags ^ flags) & GFS2_DIF_IMMUTABLE) && !capable(CAP_LINUX_IMMUTABLE)) goto out; if (!IS_IMMUTABLE(inode)) { @@ -541,7 +541,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) goto out; gfs2_glock_hold(gl); flock_lock_file_wait(file, - &(struct file_lock){.fl_type = F_UNLCK}); + &(struct file_lock){.fl_type = F_UNLCK}); gfs2_glock_dq_uninit(fl_gh); } else { error = gfs2_glock_get(GFS2_SB(&ip->i_inode), diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index e32a6b242e0c..a9aa2edd756f 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -146,7 +146,7 @@ static int init_names(struct gfs2_sbd *sdp, int silent) brelse(bh); return -ENOMEM; } - gfs2_sb_in(sb, bh->b_data); + gfs2_sb_in(sb, bh->b_data); brelse(bh); error = gfs2_check_sb(sdp, sb, silent); @@ -272,7 +272,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) } return 0; } - + error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops, LM_ST_SHARED, 0, &sb_gh); if (error) { @@ -358,7 +358,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo) error = -EINVAL; if (!gfs2_jindex_size(sdp)) { fs_err(sdp, "no journals!\n"); - goto fail_jindex; + goto fail_jindex; } if (sdp->sd_args.ar_spectator) { @@ -789,7 +789,7 @@ out: return error; } -static int fill_super_meta(struct super_block *sb, struct super_block *new, +static int fill_super_meta(struct super_block *sb, struct super_block *new, void *data, int silent) { struct gfs2_sbd *sdp = sb->s_fs_info; @@ -821,7 +821,7 @@ static int set_bdev_super(struct super_block *s, void *data) s->s_dev = s->s_bdev->bd_dev; return 0; } - + static int test_bdev_super(struct super_block *s, void *data) { return s->s_bdev == data; @@ -835,10 +835,10 @@ static struct super_block* get_gfs2_sb(const char *dev_name) struct super_block *sb = NULL, *s; struct list_head *l; int error; - + error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd); if (error) { - printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n", + printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n", dev_name); goto out; } @@ -900,9 +900,9 @@ static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags, deactivate_super(new); goto error; } - + new->s_flags |= MS_ACTIVE; - + /* Grab a reference to the gfs2 mount point */ atomic_inc(&sdp->sd_gfs2mnt->mnt_count); return simple_set_mnt(mnt, new); diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index bb2ef6a86533..57af0192b241 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -522,7 +522,7 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, case S_IFSOCK: break; default: - return -EOPNOTSUPP; + return -EOPNOTSUPP; }; gfs2_holder_init(dip->i_gl, 0, 0, ghs); diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index f9538849c418..8cfda6452139 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -367,7 +367,7 @@ static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) return 0; } -/* +/* * We have to (at the moment) hold the inodes main lock to cover * the gap between unlocking the shared lock on the iopen lock and * taking the exclusive lock. I'd rather do a shared -> exclusive diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index da46e14388f4..c0a3c9a2a593 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -556,7 +556,7 @@ static void do_qc(struct gfs2_quota_data *qd, s64 change) qd_hold(qd); slot_hold(qd); } - + mutex_unlock(&sdp->sd_quota_mutex); } @@ -777,7 +777,7 @@ restart: gfs2_glock_dq_uninit(&i_gh); - + gfs2_quota_in(&q, buf); qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb; qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC); @@ -1062,7 +1062,7 @@ int gfs2_quota_init(struct gfs2_sbd *sdp) if (!ip->i_di.di_size || ip->i_di.di_size > (64 << 20) || ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1)) { gfs2_consist_inode(ip); - return -EIO; + return -EIO; } sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block; sdp->sd_quota_chunks = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * PAGE_SIZE); diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 4d4ea7e66edc..0a8a4b87dcc6 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -444,11 +444,11 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd) switch (error) { case 0: break; - + case GLR_TRYFAILED: fs_info(sdp, "jid=%u: Busy\n", jd->jd_jid); error = 0; - + default: goto fail; }; diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 5f8e225c5497..b261385c0065 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -896,7 +896,7 @@ static int get_local_rgrp(struct gfs2_inode *ip) rgd = recent_rgrp_first(sdp, ip->i_last_rg_alloc); while (rgd) { - error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, + error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, LM_FLAG_TRY, &al->al_rgd_gh); switch (error) { case 0: diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index fe207a3e206e..f6ce5e4eaf7e 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -650,8 +650,7 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free, l_sc->sc_total += total; l_sc->sc_free += free; l_sc->sc_dinodes += dinodes; - gfs2_statfs_change_out(l_sc, l_bh->b_data + - sizeof(struct gfs2_dinode)); + gfs2_statfs_change_out(l_sc, l_bh->b_data + sizeof(struct gfs2_dinode)); spin_unlock(&sdp->sd_statfs_spin); brelse(l_bh); @@ -678,7 +677,7 @@ int gfs2_statfs_sync(struct gfs2_sbd *sdp) spin_lock(&sdp->sd_statfs_spin); gfs2_statfs_change_in(m_sc, m_bh->b_data + - sizeof(struct gfs2_dinode)); + sizeof(struct gfs2_dinode)); if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) { spin_unlock(&sdp->sd_statfs_spin); goto out_bh; From 5e96f59f9b20373014abd5e30fba4805c5d4f53f Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 26 Sep 2006 17:14:02 -0400 Subject: [PATCH 275/292] [GFS2] Remove (extra) fs_subsys declaration This is already in Linus' tree, so we don't need to add another one. Signed-off-by: Steven Whitehouse --- include/linux/fs.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 48f982100f5a..1d3e601ece73 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1377,9 +1377,6 @@ extern struct subsystem fs_subsys; #define FLOCK_VERIFY_READ 1 #define FLOCK_VERIFY_WRITE 2 -/* /sys/fs */ -extern struct subsystem fs_subsys; - extern int locks_mandatory_locked(struct inode *); extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); From 7e18c02be7c83a8cfd1319f0117f63509c20aa8e Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 27 Sep 2006 12:20:06 -0400 Subject: [PATCH 276/292] [GFS2] Fix bug in Makefiles for lock modules The Makefile had the wrong CONFIG_ variable in it so that in case GFS2 was y and the lock modules were m, they were not getting built properly. Signed-off-by: Steven Whitehouse --- fs/gfs2/locking/dlm/Makefile | 2 +- fs/gfs2/locking/nolock/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/locking/dlm/Makefile b/fs/gfs2/locking/dlm/Makefile index a9733ff80371..89b93b6b45cf 100644 --- a/fs/gfs2/locking/dlm/Makefile +++ b/fs/gfs2/locking/dlm/Makefile @@ -1,3 +1,3 @@ -obj-$(CONFIG_GFS2_FS) += lock_dlm.o +obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o plock.o diff --git a/fs/gfs2/locking/nolock/Makefile b/fs/gfs2/locking/nolock/Makefile index cdadf956c831..35e9730bc3a8 100644 --- a/fs/gfs2/locking/nolock/Makefile +++ b/fs/gfs2/locking/nolock/Makefile @@ -1,3 +1,3 @@ -obj-$(CONFIG_GFS2_FS) += lock_nolock.o +obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += lock_nolock.o lock_nolock-y := main.o From 0e0bcae3bfb3c88dbe14735fa69d7d88794dc73a Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 27 Sep 2006 14:45:07 -0400 Subject: [PATCH 277/292] [GFS2] Fix direct i/o logic in filemap.c We shouldn't mark the file accessed in the case that it wasn't accessed. Signed-off-by: Steven Whitehouse --- mm/filemap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index d9bbea1e87d2..91a741ddd49d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1180,9 +1180,10 @@ __generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov, if (retval > 0) *ppos = pos + retval; } - file_accessed(filp); - if (retval != 0) + if (likely(retval != 0)) { + file_accessed(flip); goto out; + } } retval = 0; From 3f1a9aaeffd8d1cbc5ab9776c45cbd66af1c9699 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Wed, 27 Sep 2006 14:52:48 -0400 Subject: [PATCH 278/292] [GFS2] Fix typo in last patch Signed-off-by: Steven Whitehouse --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 91a741ddd49d..3195806d78e0 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1181,7 +1181,7 @@ __generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov, *ppos = pos + retval; } if (likely(retval != 0)) { - file_accessed(flip); + file_accessed(filp); goto out; } } From bba9dfd83587017de1c55a94c077983e0dfa0251 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 27 Sep 2006 01:50:31 -0700 Subject: [PATCH 279/292] [GFS2] inode_diet: Replace inode.u.generic_ip with inode.i_private (gfs) The following patches reduce the size of the VFS inode structure by 28 bytes on a UP x86. (It would be more on an x86_64 system). This is a 10% reduction in the inode size on a UP kernel that is configured in a production mode (i.e., with no spinlock or other debugging functions enabled; if you want to save memory taken up by in-core inodes, the first thing you should do is disable the debugging options; they are responsible for a huge amount of bloat in the VFS inode structure). This patch: The filesystem or device-specific pointer in the inode is inside a union, which is pretty pointless given that all 30+ users of this field have been using the void pointer. Get rid of the union and rename it to i_private, with a comment to explain who is allowed to use the void pointer. This is just a cleanup, but it allows us to reuse the union 'u' for something something where the union will actually be used. Signed-off-by: "Theodore Ts'o" Cc: Steven Whitehouse Signed-off-by: Andrew Morton --- fs/dlm/debug_fs.c | 4 ++-- fs/gfs2/inode.c | 2 +- fs/gfs2/meta_io.c | 2 +- fs/gfs2/ops_super.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index 9c3aeddc8667..ca94a837a5bb 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -282,7 +282,7 @@ static int rsb_open(struct inode *inode, struct file *file) return ret; seq = file->private_data; - seq->private = inode->u.generic_ip; + seq->private = inode->i_private; return 0; } @@ -301,7 +301,7 @@ static struct file_operations rsb_fops = { static int waiters_open(struct inode *inode, struct file *file) { - file->private_data = inode->u.generic_ip; + file->private_data = inode->i_private; return 0; } diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index ac9535be304f..784d145058cb 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -160,7 +160,7 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, struct gfs2_inum *inum, if (inode->i_state & I_NEW) { struct gfs2_sbd *sdp = GFS2_SB(inode); umode_t mode = DT2IF(type); - inode->u.generic_ip = ip; + inode->i_private = ip; inode->i_mode = mode; if (S_ISREG(mode)) { diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index d3708af0a4d1..731799153187 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -78,7 +78,7 @@ struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp) mapping_set_gfp_mask(aspace->i_mapping, GFP_NOFS); aspace->i_mapping->a_ops = &aspace_aops; aspace->i_size = ~0ULL; - aspace->u.generic_ip = NULL; + aspace->i_private = NULL; insert_inode_hash(aspace); } return aspace; diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c index 8cfda6452139..06f06f7773d0 100644 --- a/fs/gfs2/ops_super.c +++ b/fs/gfs2/ops_super.c @@ -53,7 +53,7 @@ static int gfs2_write_inode(struct inode *inode, int sync) struct gfs2_inode *ip = GFS2_I(inode); /* Check this is a "normal" inode */ - if (inode->u.generic_ip) { + if (inode->i_private) { if (current->flags & PF_MEMALLOC) return 0; if (sync) @@ -280,7 +280,7 @@ static void gfs2_clear_inode(struct inode *inode) * serves to contain an address space (see rgrp.c, meta_io.c) * which therefore doesn't have its own glocks. */ - if (inode->u.generic_ip) { + if (inode->i_private) { struct gfs2_inode *ip = GFS2_I(inode); gfs2_glock_inode_squish(inode); gfs2_assert(inode->i_sb->s_fs_info, ip->i_gl->gl_state == LM_ST_UNLOCKED); @@ -381,7 +381,7 @@ static void gfs2_delete_inode(struct inode *inode) struct gfs2_holder gh; int error; - if (!inode->u.generic_ip) + if (!inode->i_private) goto out; error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &gh); From 825f9075d74028d11d7f5932f04e1b5db3022b51 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 27 Sep 2006 01:50:32 -0700 Subject: [PATCH 280/292] [GFS2] inode-diet: Eliminate i_blksize from the inode structure This eliminates the i_blksize field from struct inode. Filesystems that want to provide a per-inode st_blksize can do so by providing their own getattr routine instead of using the generic_fillattr() function. Note that some filesystems were providing pretty much random (and incorrect) values for i_blksize. Signed-off-by: "Theodore Ts'o" Cc: Steven Whitehouse Signed-off-by: Andrew Morton --- fs/gfs2/inode.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 784d145058cb..57a4c8b68587 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -72,7 +72,6 @@ void gfs2_inode_attr_in(struct gfs2_inode *ip) inode->i_atime.tv_nsec = 0; inode->i_mtime.tv_nsec = 0; inode->i_ctime.tv_nsec = 0; - inode->i_blksize = PAGE_SIZE; inode->i_blocks = di->di_blocks << (GFS2_SB(inode)->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT); From 9c9eb21eee1790804ce407fd820f65be0b4fdd03 Mon Sep 17 00:00:00 2001 From: Badari Pulavarty Date: Sat, 30 Sep 2006 23:38:50 -0700 Subject: [PATCH 281/292] [GFS2] Remove readv/writev methods and use aio_read/aio_write instead (gfs bits) This patch removes readv() and writev() methods and replaces them with aio_read()/aio_write() methods. Signed-off-by: Badari Pulavarty Signed-off-by: Christoph Hellwig Signed-off-by: Andrew Morton Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index a9ac1358ce21..a05b75a7ed8e 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -613,10 +613,8 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) const struct file_operations gfs2_file_fops = { .llseek = gfs2_llseek, .read = generic_file_read, - .readv = generic_file_readv, .aio_read = generic_file_aio_read, .write = generic_file_write, - .writev = generic_file_writev, .aio_write = generic_file_aio_write, .unlocked_ioctl = gfs2_ioctl, .mmap = gfs2_mmap, From 930cc237d67dc62464fe71529631d16f51d7aee3 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sat, 30 Sep 2006 23:38:51 -0700 Subject: [PATCH 282/292] [GFS2] streamline-generic_file_-interfaces-and-filemap gfs fix Fix GFS for streamline-generic_file_-interfaces-and-filemap.patch Signed-off-by: Andrew Morton Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index a05b75a7ed8e..f2d0bd80a1c7 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -612,9 +612,9 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) const struct file_operations gfs2_file_fops = { .llseek = gfs2_llseek, - .read = generic_file_read, + .read = do_sync_read, .aio_read = generic_file_aio_read, - .write = generic_file_write, + .write = do_sync_write, .aio_write = generic_file_aio_write, .unlocked_ioctl = gfs2_ioctl, .mmap = gfs2_mmap, From d00223f1693173c7b51f867dd52049955a92d0ed Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 2 Oct 2006 10:28:05 -0400 Subject: [PATCH 283/292] [GFS2] Fix code style/indent in ops_file.c Fix a couple of minor issues. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index f2d0bd80a1c7..fafa48b9105e 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -606,15 +606,16 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) if (fl->fl_type == F_UNLCK) { do_unflock(file, fl); return 0; - } else + } else { return do_flock(file, cmd, fl); + } } const struct file_operations gfs2_file_fops = { .llseek = gfs2_llseek, - .read = do_sync_read, + .read = do_sync_read, .aio_read = generic_file_aio_read, - .write = do_sync_write, + .write = do_sync_write, .aio_write = generic_file_aio_write, .unlocked_ioctl = gfs2_ioctl, .mmap = gfs2_mmap, From 128e5ebaf8abbda375bba82690b09630003c9213 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 2 Oct 2006 11:24:43 -0400 Subject: [PATCH 284/292] [GFS2] Remove iflags.h, use FS_ Update GFS2 in the light of David Howells' patch: [PATCH] BLOCK: Move common FS-specific ioctls to linux/fs.h [try #6] 36695673b012096228ebdc1b39a6a5850daa474e which calls the filesystem independant flags FS_..._FL. As a result we no longer need the flags.h file and the conversion routine is moved into the GFS2 source code. Userland programs which used to include iflags.h should now include fs.h and use the new flag names. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_file.c | 74 +++++++++++++++++++----------- include/linux/Kbuild | 1 - include/linux/fs.h | 2 + include/linux/iflags.h | 102 ----------------------------------------- 4 files changed, 49 insertions(+), 130 deletions(-) delete mode 100644 include/linux/iflags.h diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c index fafa48b9105e..3064f133bf3c 100644 --- a/fs/gfs2/ops_file.c +++ b/fs/gfs2/ops_file.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -201,27 +200,48 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) return error; } +/** + * fsflags_cvt + * @table: A table of 32 u32 flags + * @val: a 32 bit value to convert + * + * This function can be used to convert between fsflags values and + * GFS2's own flags values. + * + * Returns: the converted flags + */ +static u32 fsflags_cvt(const u32 *table, u32 val) +{ + u32 res = 0; + while(val) { + if (val & 1) + res |= *table; + table++; + val >>= 1; + } + return res; +} -static const u32 iflags_to_gfs2[32] = { - [iflag_Sync] = GFS2_DIF_SYNC, - [iflag_Immutable] = GFS2_DIF_IMMUTABLE, - [iflag_Append] = GFS2_DIF_APPENDONLY, - [iflag_NoAtime] = GFS2_DIF_NOATIME, - [iflag_Index] = GFS2_DIF_EXHASH, - [iflag_JournalData] = GFS2_DIF_JDATA, - [iflag_DirectIO] = GFS2_DIF_DIRECTIO, +static const u32 fsflags_to_gfs2[32] = { + [3] = GFS2_DIF_SYNC, + [4] = GFS2_DIF_IMMUTABLE, + [5] = GFS2_DIF_APPENDONLY, + [7] = GFS2_DIF_NOATIME, + [12] = GFS2_DIF_EXHASH, + [14] = GFS2_DIF_JDATA, + [20] = GFS2_DIF_DIRECTIO, }; -static const u32 gfs2_to_iflags[32] = { - [gfs2fl_Sync] = IFLAG_SYNC, - [gfs2fl_Immutable] = IFLAG_IMMUTABLE, - [gfs2fl_AppendOnly] = IFLAG_APPEND, - [gfs2fl_NoAtime] = IFLAG_NOATIME, - [gfs2fl_ExHash] = IFLAG_INDEX, - [gfs2fl_Jdata] = IFLAG_JOURNAL_DATA, - [gfs2fl_Directio] = IFLAG_DIRECTIO, - [gfs2fl_InheritDirectio] = IFLAG_DIRECTIO, - [gfs2fl_InheritJdata] = IFLAG_JOURNAL_DATA, +static const u32 gfs2_to_fsflags[32] = { + [gfs2fl_Sync] = FS_SYNC_FL, + [gfs2fl_Immutable] = FS_IMMUTABLE_FL, + [gfs2fl_AppendOnly] = FS_APPEND_FL, + [gfs2fl_NoAtime] = FS_NOATIME_FL, + [gfs2fl_ExHash] = FS_INDEX_FL, + [gfs2fl_Jdata] = FS_JOURNAL_DATA_FL, + [gfs2fl_Directio] = FS_DIRECTIO_FL, + [gfs2fl_InheritDirectio] = FS_DIRECTIO_FL, + [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL, }; static int gfs2_get_flags(struct file *filp, u32 __user *ptr) @@ -230,15 +250,15 @@ static int gfs2_get_flags(struct file *filp, u32 __user *ptr) struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_holder gh; int error; - u32 iflags; + u32 fsflags; gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); error = gfs2_glock_nq_m_atime(1, &gh); if (error) return error; - iflags = iflags_cvt(gfs2_to_iflags, ip->i_di.di_flags); - if (put_user(iflags, ptr)) + fsflags = fsflags_cvt(gfs2_to_fsflags, ip->i_di.di_flags); + if (put_user(fsflags, ptr)) error = -EFAULT; gfs2_glock_dq_m(1, &gh); @@ -327,19 +347,19 @@ out: static int gfs2_set_flags(struct file *filp, u32 __user *ptr) { - u32 iflags, gfsflags; - if (get_user(iflags, ptr)) + u32 fsflags, gfsflags; + if (get_user(fsflags, ptr)) return -EFAULT; - gfsflags = iflags_cvt(iflags_to_gfs2, iflags); + gfsflags = fsflags_cvt(fsflags_to_gfs2, fsflags); return do_gfs2_set_flags(filp, gfsflags, ~0); } static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { switch(cmd) { - case IFLAGS_GET_IOC: + case FS_IOC_GETFLAGS: return gfs2_get_flags(filp, (u32 __user *)arg); - case IFLAGS_SET_IOC: + case FS_IOC_SETFLAGS: return gfs2_set_flags(filp, (u32 __user *)arg); } return -ENOTTY; diff --git a/include/linux/Kbuild b/include/linux/Kbuild index 839a97ee1f7c..15667cc947d5 100644 --- a/include/linux/Kbuild +++ b/include/linux/Kbuild @@ -223,7 +223,6 @@ unifdef-y += hpet.h unifdef-y += i2c.h unifdef-y += i2o-dev.h unifdef-y += icmpv6.h -unifdef-y += iflags.h unifdef-y += if_bridge.h unifdef-y += if_ec.h unifdef-y += if_eql.h diff --git a/include/linux/fs.h b/include/linux/fs.h index 2e29a2edaeec..bc0e645abb80 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -250,6 +250,8 @@ extern int dir_notify_enable; #define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */ #define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ #define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ +#define FS_EXTENT_FL 0x00080000 /* Extents */ +#define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */ #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ diff --git a/include/linux/iflags.h b/include/linux/iflags.h deleted file mode 100644 index 5b27102dfeaf..000000000000 --- a/include/linux/iflags.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef _LINUX_IFLAGS_H -#define _LINUX_IFLAGS_H - -/* - * A universal set of inode flags. - * - * Originally taken from ext2/3 with additions for other filesystems. - * Filesystems supporting this interface should interoperate with - * the lsattr and chattr command line tools. - * - * This interface is supported in whole or in part by: - * ext2 - * ext3 - * xfs - * jfs - * gfs2 - * - */ - -#define IFLAGS_GET_IOC _IOR('f', 1, long) -#define IFLAGS_SET_IOC _IOW('f', 2, long) - -/* - * These values are provided for use as indices of an array - * for use with the iflags_cvt function below - */ -enum { - iflag_SecureRm = 0, /* Secure deletion */ - iflag_Unrm = 1, /* Undelete */ - iflag_Compress = 2, /* Compress file */ - iflag_Sync = 3, /* Synchronous updates */ - iflag_Immutable = 4, /* Immutable */ - iflag_Append = 5, /* Append */ - iflag_NoDump = 6, /* Don't dump file */ - iflag_NoAtime = 7, /* No atime updates */ - /* Reserved for compression usage */ - iflag_Dirty = 8, - iflag_ComprBlk = 9, /* One or more compressed clusters */ - iflag_NoComp = 10, /* Don't compress */ - iflag_Ecompr = 11, /* Compression error */ - /* End of compression flags */ - iflag_Btree = 12, /* btree format dir */ - iflag_Index = 12, /* hash-indexed directory */ - iflag_Imagic = 13, /* AFS directory */ - iflag_JournalData = 14, /* file data should be journaled */ - iflag_NoTail = 15, /* file tail should not be merged */ - iflag_DirSync = 16, /* dirsync behaviour */ - iflag_TopDir = 17, /* Top of directory hierarchies */ - iflag_Extent = 19, /* Extents */ - iflag_DirectIO = 20, /* Always use direct I/O on this file */ - iflag_Reserved = 31 /* reserved for ext2/3 lib */ -}; - -#define __IFL(x) (1<<(iflag_##x)) -#define IFLAG_SECRM __IFL(SecureRm) /* 0x00000001 */ -#define IFLAG_UNRM __IFL(Unrm) /* 0x00000002 */ -#define IFLAG_COMPR __IFL(Compr) /* 0x00000004 */ -#define IFLAG_SYNC __IFL(Sync) /* 0x00000008 */ -#define IFLAG_IMMUTABLE __IFL(Immutable) /* 0x00000010 */ -#define IFLAG_APPEND __IFL(Append) /* 0x00000020 */ -#define IFLAG_NODUMP __IFL(NoDump) /* 0x00000040 */ -#define IFLAG_NOATIME __IFL(NoAtime) /* 0x00000080 */ -#define IFLAG_DIRTY __IFL(Dirty) /* 0x00000100 */ -#define IFLAG_COMPRBLK __IFL(ComprBlk) /* 0x00000200 */ -#define IFLAG_NOCOMP __IFL(NoComp) /* 0x00000400 */ -#define IFLAG_ECOMPR __IFL(Ecompr) /* 0x00000800 */ -#define IFLAG_BTREE __IFL(Btree) /* 0x00001000 */ -#define IFLAG_INDEX __IFL(Index) /* 0x00001000 */ -#define IFLAG_IMAGIC __IFL(Imagic) /* 0x00002000 */ -#define IFLAG_JOURNAL_DATA __IFL(JournalData) /* 0x00004000 */ -#define IFLAG_NOTAIL __IFL(NoTail) /* 0x00008000 */ -#define IFLAG_DIRSYNC __IFL(DirSync) /* 0x00010000 */ -#define IFLAG_TOPDIR __IFL(TopDir) /* 0x00020000 */ -#define IFLAG_EXTENT __IFL(Extent) /* 0x00080000 */ -#define IFLAG_DIRECTIO __IFL(DirectIO) /* 0x00100000 */ -#define IFLAG_RESERVED __IFL(Reserved) /* 0x80000000 */ - -#ifdef __KERNEL__ -/** - * iflags_cvt - * @table: A table of 32 u32 flags - * @val: a 32 bit value to convert - * - * This function can be used to convert between IFLAGS values and - * the filesystem's own flags values. - * - * Returns: the converted flags - */ -static inline u32 iflags_cvt(const u32 *table, u32 val) -{ - u32 res = 0; - while(val) { - if (val & 1) - res |= *table; - table++; - val >>= 1; - } - return res; -} -#endif /* __KERNEL__ */ - -#endif /* _LINUX_IFLAGS_H */ From 2e565bb69ce2184eabf4f43e64afc79c46f46204 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 2 Oct 2006 11:38:25 -0400 Subject: [PATCH 285/292] [GFS2] Mark metadata reads for blktrace Mark the metadata reads so that blktrace knows what they are. Signed-off-by: Steven Whitehouse --- fs/gfs2/meta_io.c | 7 ++++--- fs/gfs2/quota.c | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 731799153187..d0d981dac4cd 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -385,7 +386,7 @@ int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags, { *bhp = getbuf(gl->gl_sbd, gl->gl_aspace, blkno, CREATE); if (!buffer_uptodate(*bhp)) - ll_rw_block(READ, 1, bhp); + ll_rw_block(READ_META, 1, bhp); if (flags & DIO_WAIT) { int error = gfs2_meta_wait(gl->gl_sbd, *bhp); if (error) { @@ -659,7 +660,7 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num, } else { u32 mtype = height ? GFS2_METATYPE_IN : GFS2_METATYPE_DI; if (!buffer_uptodate(bh)) { - ll_rw_block(READ, 1, &bh); + ll_rw_block(READ_META, 1, &bh); if (gfs2_meta_wait(sdp, bh)) goto err; } @@ -712,7 +713,7 @@ struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen) if (buffer_uptodate(first_bh)) goto out; if (!buffer_locked(first_bh)) - ll_rw_block(READ, 1, &first_bh); + ll_rw_block(READ_META, 1, &first_bh); dblock++; extlen--; diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index c0a3c9a2a593..c69b94a55588 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -609,7 +610,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, set_buffer_uptodate(bh); if (!buffer_uptodate(bh)) { - ll_rw_block(READ, 1, &bh); + ll_rw_block(READ_META, 1, &bh); wait_on_buffer(bh); if (!buffer_uptodate(bh)) goto unlock; From 3cf1e7bed4681bdb1c14b6e146ae9c0afb6c1552 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 2 Oct 2006 11:49:41 -0400 Subject: [PATCH 286/292] [GFS2] Remove duplicate sb reading code For some reason we had two different sets of code for reading in the superblock. This removes one of them in favour of the other. Also we don't need the temporary buffer for the sb since we already have one in the gfs2 sb itself. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_fstype.c | 39 ++++++++++++--------------------------- fs/gfs2/super.c | 4 ++-- fs/gfs2/super.h | 1 + 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index a9aa2edd756f..178b33911843 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -116,7 +116,7 @@ static void init_vfs(struct super_block *sb, unsigned noatime) static int init_names(struct gfs2_sbd *sdp, int silent) { - struct gfs2_sb *sb = NULL; + struct page *page; char *proto, *table; int error = 0; @@ -126,37 +126,23 @@ static int init_names(struct gfs2_sbd *sdp, int silent) /* Try to autodetect */ if (!proto[0] || !table[0]) { - struct buffer_head *bh; - bh = sb_getblk(sdp->sd_vfs, - GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); - lock_buffer(bh); - clear_buffer_uptodate(bh); - clear_buffer_dirty(bh); - unlock_buffer(bh); - ll_rw_block(READ, 1, &bh); - wait_on_buffer(bh); + struct gfs2_sb *sb; + page = gfs2_read_super(sdp->sd_vfs, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); + if (!page) + return -ENOBUFS; + sb = kmap(page); + gfs2_sb_in(&sdp->sd_sb, sb); + kunmap(page); + __free_page(page); - if (!buffer_uptodate(bh)) { - brelse(bh); - return -EIO; - } - - sb = kmalloc(sizeof(struct gfs2_sb), GFP_KERNEL); - if (!sb) { - brelse(bh); - return -ENOMEM; - } - gfs2_sb_in(sb, bh->b_data); - brelse(bh); - - error = gfs2_check_sb(sdp, sb, silent); + error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); if (error) goto out; if (!proto[0]) - proto = sb->sb_lockproto; + proto = sdp->sd_sb.sb_lockproto; if (!table[0]) - table = sb->sb_locktable; + table = sdp->sd_sb.sb_locktable; } if (!table[0]) @@ -166,7 +152,6 @@ static int init_names(struct gfs2_sbd *sdp, int silent) snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table); out: - kfree(sb); return error; } diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index f6ce5e4eaf7e..6a78b1b32e25 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -180,7 +180,7 @@ static int end_bio_io_page(struct bio *bio, unsigned int bytes_done, int error) return 0; } -static struct page *gfs2_read_super(struct super_block *sb, sector_t sector) +struct page *gfs2_read_super(struct super_block *sb, sector_t sector) { struct page *page; struct bio *bio; @@ -205,7 +205,7 @@ static struct page *gfs2_read_super(struct super_block *sb, sector_t sector) bio->bi_end_io = end_bio_io_page; bio->bi_private = page; - submit_bio(READ_SYNC, bio); + submit_bio(READ_SYNC | (1 << BIO_RW_META), bio); wait_on_page_locked(page); bio_put(bio); if (!PageUptodate(page)) { diff --git a/fs/gfs2/super.h b/fs/gfs2/super.h index 5fa5119cfba6..5bb443ae0f59 100644 --- a/fs/gfs2/super.h +++ b/fs/gfs2/super.h @@ -16,6 +16,7 @@ void gfs2_tune_init(struct gfs2_tune *gt); int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent); int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent); +struct page *gfs2_read_super(struct super_block *sb, sector_t sector); static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp) { From 48516ced21e83a755ebae3d1ed03f1731befc391 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 2 Oct 2006 12:39:19 -0400 Subject: [PATCH 287/292] [GFS2] Remove uneeded endian conversion In many places GFS2 was calling the endian conversion routines for an inode even when only a single field, or a few fields might have changed. As a result we were copying lots of data needlessly. This patch replaces those calls with conversion of just the required fields in each case. This should be faster and easier to understand. There are still other places which suffer from this problem, but this is a start in the right direction. Signed-off-by: Steven Whitehouse --- fs/gfs2/bmap.c | 21 +++++++++++---------- fs/gfs2/inode.c | 4 +++- fs/gfs2/ops_address.c | 14 +++++++++++--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 92eef825167d..cc57f2ecd219 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -121,6 +121,7 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) { struct buffer_head *bh, *dibh; + struct gfs2_dinode *di; u64 block = 0; int isdir = gfs2_is_dir(ip); int error; @@ -141,8 +142,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) error = gfs2_dir_get_new_buffer(ip, block, &bh); if (error) goto out_brelse; - gfs2_buffer_copy_tail(bh, - sizeof(struct gfs2_meta_header), + gfs2_buffer_copy_tail(bh, sizeof(struct gfs2_meta_header), dibh, sizeof(struct gfs2_dinode)); brelse(bh); } else { @@ -157,18 +157,17 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) /* Set up the pointer to the new block */ gfs2_trans_add_bh(ip->i_gl, dibh, 1); - + di = (struct gfs2_dinode *)dibh->b_data; gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); if (ip->i_di.di_size) { - *(u64 *)(dibh->b_data + sizeof(struct gfs2_dinode)) = - cpu_to_be64(block); + *(__be64 *)(di + 1) = cpu_to_be64(block); ip->i_di.di_blocks++; + di->di_blocks = cpu_to_be64(ip->i_di.di_blocks); } ip->i_di.di_height = 1; - - gfs2_dinode_out(&ip->i_di, dibh->b_data); + di->di_height = cpu_to_be16(1); out_brelse: brelse(dibh); @@ -229,6 +228,7 @@ static int build_height(struct inode *inode, unsigned height) unsigned new_height = height - ip->i_di.di_height; struct buffer_head *dibh; struct buffer_head *blocks[GFS2_MAX_META_HEIGHT]; + struct gfs2_dinode *di; int error; u64 *bp; u64 bn; @@ -267,12 +267,13 @@ static int build_height(struct inode *inode, unsigned height) dibh, sizeof(struct gfs2_dinode)); brelse(blocks[n]); gfs2_trans_add_bh(ip->i_gl, dibh, 1); + di = (struct gfs2_dinode *)dibh->b_data; gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); - bp = (u64 *)(dibh->b_data + sizeof(struct gfs2_dinode)); - *bp = cpu_to_be64(bn); + *(__be64 *)(di + 1) = cpu_to_be64(bn); ip->i_di.di_height += new_height; ip->i_di.di_blocks += new_height; - gfs2_dinode_out(&ip->i_di, dibh->b_data); + di->di_height = cpu_to_be16(ip->i_di.di_height); + di->di_blocks = cpu_to_be64(ip->i_di.di_blocks); brelse(dibh); return error; } diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 57a4c8b68587..660dc81849a6 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -1166,6 +1166,7 @@ int gfs2_glock_nq_atime(struct gfs2_holder *gh) curtime = get_seconds(); if (curtime - ip->i_di.di_atime >= quantum) { struct buffer_head *dibh; + struct gfs2_dinode *di; error = gfs2_trans_begin(sdp, RES_DINODE, 0); if (error == -EROFS) @@ -1180,7 +1181,8 @@ int gfs2_glock_nq_atime(struct gfs2_holder *gh) ip->i_di.di_atime = curtime; gfs2_trans_add_bh(ip->i_gl, dibh, 1); - gfs2_dinode_out(&ip->i_di, dibh->b_data); + di = (struct gfs2_dinode *)dibh->b_data; + di->di_atime = cpu_to_be64(ip->i_di.di_atime); brelse(dibh); gfs2_trans_end(sdp); diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c index 811f4ada2a01..4fb743f4e4a4 100644 --- a/fs/gfs2/ops_address.c +++ b/fs/gfs2/ops_address.c @@ -460,7 +460,8 @@ static int gfs2_commit_write(struct file *file, struct page *page, struct gfs2_sbd *sdp = GFS2_SB(inode); int error = -EOPNOTSUPP; struct buffer_head *dibh; - struct gfs2_alloc *al = &ip->i_alloc;; + struct gfs2_alloc *al = &ip->i_alloc; + struct gfs2_dinode *di; if (gfs2_assert_withdraw(sdp, gfs2_glock_is_locked_by_me(ip->i_gl))) goto fail_nounlock; @@ -470,6 +471,7 @@ static int gfs2_commit_write(struct file *file, struct page *page, goto fail_endtrans; gfs2_trans_add_bh(ip->i_gl, dibh, 1); + di = (struct gfs2_dinode *)dibh->b_data; if (gfs2_is_stuffed(ip)) { u64 file_size; @@ -495,10 +497,16 @@ static int gfs2_commit_write(struct file *file, struct page *page, goto fail; } - if (ip->i_di.di_size < inode->i_size) + if (ip->i_di.di_size < inode->i_size) { ip->i_di.di_size = inode->i_size; + di->di_size = cpu_to_be64(inode->i_size); + } + + di->di_mode = cpu_to_be32(inode->i_mode); + di->di_atime = cpu_to_be64(inode->i_atime.tv_sec); + di->di_mtime = cpu_to_be64(inode->i_mtime.tv_sec); + di->di_ctime = cpu_to_be64(inode->i_ctime.tv_sec); - gfs2_dinode_out(&ip->i_di, dibh->b_data); brelse(dibh); gfs2_trans_end(sdp); if (al->al_requested) { From 409e185d2370356ac2e4c7160e002ac5340b6709 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 2 Oct 2006 14:20:43 -0400 Subject: [PATCH 288/292] [GFS2] Two redundant casts removed Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 57af0192b241..82432d8f7139 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -411,10 +411,10 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1)); gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent); - gfs2_inum_out(&dip->i_num, (char *) &dent->de_inum); + gfs2_inum_out(&dip->i_num, &dent->de_inum); dent->de_type = DT_DIR; - gfs2_dinode_out(&ip->i_di, (char *)di); + gfs2_dinode_out(&ip->i_di, di); brelse(dibh); } From f92a0b6ff43e8e07bbd5b1d2dd1cff130014f3c7 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 2 Oct 2006 16:01:53 -0400 Subject: [PATCH 289/292] [GFS2] Mark nlink cleared so VFS sees it happen This does nothing atm, but will be required for later support of r/o bind mounts. Signed-off-by: Steven Whitehouse --- fs/gfs2/inode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 660dc81849a6..81a921165941 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -353,6 +353,7 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff) if (error) goto out_norgrp; + clear_nlink(&ip->i_inode); gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */ gfs2_glock_dq_uninit(&rg_gh); out_norgrp: From ddacfaf76dd620af9b73343a975749778321b51c Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 3 Oct 2006 11:10:41 -0400 Subject: [PATCH 290/292] [GFS2] Move logging code into log.c (mostly) This moves the logging code from meta_io.c into log.c and glops.c. As a result the routines can now be static and all the logging code is together in log.c, leaving meta_io.c with just metadata i/o code in it. Signed-off-by: Steven Whitehouse --- fs/gfs2/glops.c | 51 ++++++++++++++ fs/gfs2/log.c | 109 ++++++++++++++++++++++++++++++ fs/gfs2/meta_io.c | 164 ---------------------------------------------- fs/gfs2/meta_io.h | 10 +-- 4 files changed, 165 insertions(+), 169 deletions(-) diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index ef1492e2d445..41a6b6818a50 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -26,7 +26,58 @@ #include "recovery.h" #include "rgrp.h" #include "util.h" +#include "trans.h" +/** + * ail_empty_gl - remove all buffers for a given lock from the AIL + * @gl: the glock + * + * None of the buffers should be dirty, locked, or pinned. + */ + +static void gfs2_ail_empty_gl(struct gfs2_glock *gl) +{ + struct gfs2_sbd *sdp = gl->gl_sbd; + unsigned int blocks; + struct list_head *head = &gl->gl_ail_list; + struct gfs2_bufdata *bd; + struct buffer_head *bh; + u64 blkno; + int error; + + blocks = atomic_read(&gl->gl_ail_count); + if (!blocks) + return; + + error = gfs2_trans_begin(sdp, 0, blocks); + if (gfs2_assert_withdraw(sdp, !error)) + return; + + gfs2_log_lock(sdp); + while (!list_empty(head)) { + bd = list_entry(head->next, struct gfs2_bufdata, + bd_ail_gl_list); + bh = bd->bd_bh; + blkno = bh->b_blocknr; + gfs2_assert_withdraw(sdp, !buffer_busy(bh)); + + bd->bd_ail = NULL; + list_del(&bd->bd_ail_st_list); + list_del(&bd->bd_ail_gl_list); + atomic_dec(&gl->gl_ail_count); + brelse(bh); + gfs2_log_unlock(sdp); + + gfs2_trans_add_revoke(sdp, blkno); + + gfs2_log_lock(sdp); + } + gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count)); + gfs2_log_unlock(sdp); + + gfs2_trans_end(sdp); + gfs2_log_flush(sdp, NULL); +} /** * gfs2_pte_inval - Sync and invalidate all PTEs associated with a glock diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 6112d648b7ee..554fe5bd1b72 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -58,6 +58,90 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, return blks; } +/** + * gfs2_ail1_start_one - Start I/O on a part of the AIL + * @sdp: the filesystem + * @tr: the part of the AIL + * + */ + +static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) +{ + struct gfs2_bufdata *bd, *s; + struct buffer_head *bh; + int retry; + + BUG_ON(!spin_is_locked(&sdp->sd_log_lock)); + + do { + retry = 0; + + list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, + bd_ail_st_list) { + bh = bd->bd_bh; + + gfs2_assert(sdp, bd->bd_ail == ai); + + if (!buffer_busy(bh)) { + if (!buffer_uptodate(bh)) { + gfs2_log_unlock(sdp); + gfs2_io_error_bh(sdp, bh); + gfs2_log_lock(sdp); + } + list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); + continue; + } + + if (!buffer_dirty(bh)) + continue; + + list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list); + + gfs2_log_unlock(sdp); + wait_on_buffer(bh); + ll_rw_block(WRITE, 1, &bh); + gfs2_log_lock(sdp); + + retry = 1; + break; + } + } while (retry); +} + +/** + * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced + * @sdp: the filesystem + * @ai: the AIL entry + * + */ + +static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags) +{ + struct gfs2_bufdata *bd, *s; + struct buffer_head *bh; + + list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, + bd_ail_st_list) { + bh = bd->bd_bh; + + gfs2_assert(sdp, bd->bd_ail == ai); + + if (buffer_busy(bh)) { + if (flags & DIO_ALL) + continue; + else + break; + } + + if (!buffer_uptodate(bh)) + gfs2_io_error_bh(sdp, bh); + + list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); + } + + return list_empty(&ai->ai_ail1_list); +} + void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags) { struct list_head *head = &sdp->sd_ail1_list; @@ -121,6 +205,31 @@ int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags) return ret; } + +/** + * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced + * @sdp: the filesystem + * @ai: the AIL entry + * + */ + +static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) +{ + struct list_head *head = &ai->ai_ail2_list; + struct gfs2_bufdata *bd; + + while (!list_empty(head)) { + bd = list_entry(head->prev, struct gfs2_bufdata, + bd_ail_st_list); + gfs2_assert(sdp, bd->bd_ail == ai); + bd->bd_ail = NULL; + list_del(&bd->bd_ail_st_list); + list_del(&bd->bd_ail_gl_list); + atomic_dec(&bd->bd_gl->gl_ail_count); + brelse(bd->bd_bh); + } +} + static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) { struct gfs2_ail *ai, *safe; diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index d0d981dac4cd..3912d6a4b1e6 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -34,11 +34,6 @@ #include "util.h" #include "ops_address.h" -#define buffer_busy(bh) \ -((bh)->b_state & ((1ul << BH_Dirty) | (1ul << BH_Lock) | (1ul << BH_Pinned))) -#define buffer_in_io(bh) \ -((bh)->b_state & ((1ul << BH_Dirty) | (1ul << BH_Lock))) - static int aspace_get_block(struct inode *inode, sector_t lblock, struct buffer_head *bh_result, int create) { @@ -91,165 +86,6 @@ void gfs2_aspace_put(struct inode *aspace) iput(aspace); } -/** - * gfs2_ail1_start_one - Start I/O on a part of the AIL - * @sdp: the filesystem - * @tr: the part of the AIL - * - */ - -void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) -{ - struct gfs2_bufdata *bd, *s; - struct buffer_head *bh; - int retry; - - BUG_ON(!spin_is_locked(&sdp->sd_log_lock)); - - do { - retry = 0; - - list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, - bd_ail_st_list) { - bh = bd->bd_bh; - - gfs2_assert(sdp, bd->bd_ail == ai); - - if (!buffer_busy(bh)) { - if (!buffer_uptodate(bh)) { - gfs2_log_unlock(sdp); - gfs2_io_error_bh(sdp, bh); - gfs2_log_lock(sdp); - } - list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); - continue; - } - - if (!buffer_dirty(bh)) - continue; - - list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list); - - gfs2_log_unlock(sdp); - wait_on_buffer(bh); - ll_rw_block(WRITE, 1, &bh); - gfs2_log_lock(sdp); - - retry = 1; - break; - } - } while (retry); -} - -/** - * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced - * @sdp: the filesystem - * @ai: the AIL entry - * - */ - -int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags) -{ - struct gfs2_bufdata *bd, *s; - struct buffer_head *bh; - - list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, - bd_ail_st_list) { - bh = bd->bd_bh; - - gfs2_assert(sdp, bd->bd_ail == ai); - - if (buffer_busy(bh)) { - if (flags & DIO_ALL) - continue; - else - break; - } - - if (!buffer_uptodate(bh)) - gfs2_io_error_bh(sdp, bh); - - list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); - } - - return list_empty(&ai->ai_ail1_list); -} - -/** - * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced - * @sdp: the filesystem - * @ai: the AIL entry - * - */ - -void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) -{ - struct list_head *head = &ai->ai_ail2_list; - struct gfs2_bufdata *bd; - - while (!list_empty(head)) { - bd = list_entry(head->prev, struct gfs2_bufdata, - bd_ail_st_list); - gfs2_assert(sdp, bd->bd_ail == ai); - bd->bd_ail = NULL; - list_del(&bd->bd_ail_st_list); - list_del(&bd->bd_ail_gl_list); - atomic_dec(&bd->bd_gl->gl_ail_count); - brelse(bd->bd_bh); - } -} - -/** - * ail_empty_gl - remove all buffers for a given lock from the AIL - * @gl: the glock - * - * None of the buffers should be dirty, locked, or pinned. - */ - -void gfs2_ail_empty_gl(struct gfs2_glock *gl) -{ - struct gfs2_sbd *sdp = gl->gl_sbd; - unsigned int blocks; - struct list_head *head = &gl->gl_ail_list; - struct gfs2_bufdata *bd; - struct buffer_head *bh; - u64 blkno; - int error; - - blocks = atomic_read(&gl->gl_ail_count); - if (!blocks) - return; - - error = gfs2_trans_begin(sdp, 0, blocks); - if (gfs2_assert_withdraw(sdp, !error)) - return; - - gfs2_log_lock(sdp); - while (!list_empty(head)) { - bd = list_entry(head->next, struct gfs2_bufdata, - bd_ail_gl_list); - bh = bd->bd_bh; - blkno = bh->b_blocknr; - gfs2_assert_withdraw(sdp, !buffer_busy(bh)); - - bd->bd_ail = NULL; - list_del(&bd->bd_ail_st_list); - list_del(&bd->bd_ail_gl_list); - atomic_dec(&gl->gl_ail_count); - brelse(bh); - gfs2_log_unlock(sdp); - - gfs2_trans_add_revoke(sdp, blkno); - - gfs2_log_lock(sdp); - } - gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count)); - gfs2_log_unlock(sdp); - - gfs2_trans_end(sdp); - gfs2_log_flush(sdp, NULL); -} - /** * gfs2_meta_inval - Invalidate all buffers associated with a glock * @gl: the glock diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index 3323e6d0ed8f..3ec939e20dff 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h @@ -40,11 +40,6 @@ static inline void gfs2_buffer_copy_tail(struct buffer_head *to_bh, struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp); void gfs2_aspace_put(struct inode *aspace); -void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai); -int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags); -void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai); -void gfs2_ail_empty_gl(struct gfs2_glock *gl); - void gfs2_meta_inval(struct gfs2_glock *gl); void gfs2_meta_sync(struct gfs2_glock *gl); @@ -74,5 +69,10 @@ static inline int gfs2_meta_inode_buffer(struct gfs2_inode *ip, struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen); void gfs2_meta_syncfs(struct gfs2_sbd *sdp); +#define buffer_busy(bh) \ +((bh)->b_state & ((1ul << BH_Dirty) | (1ul << BH_Lock) | (1ul << BH_Pinned))) +#define buffer_in_io(bh) \ +((bh)->b_state & ((1ul << BH_Dirty) | (1ul << BH_Lock))) + #endif /* __DIO_DOT_H__ */ From fcb47e0bd279cab5ba8299c0a1e3364d15413a6b Mon Sep 17 00:00:00 2001 From: Ryan O'Hara Date: Tue, 3 Oct 2006 11:57:35 -0400 Subject: [PATCH 291/292] [GFS2] Initialize SELinux extended attributes at inode creation time. This patch has gfs2_security_init declared as a static function, which is correct. As a result, the declaration of this function in inode.h is removed (and thus inode.h is unchanged). Also removed #include eaops.h, which is not needed. Signed-Off-By: Ryan O'Hara Signed-off-by: Steven Whitehouse --- fs/gfs2/inode.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 81a921165941..57c43ac47925 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "gfs2.h" #include "incore.h" @@ -806,6 +807,39 @@ fail: return error; } +static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip) +{ + int err; + size_t len; + void *value; + char *name; + struct gfs2_ea_request er; + + err = security_inode_init_security(&ip->i_inode, &dip->i_inode, + &name, &value, &len); + + if (err) { + if (err == -EOPNOTSUPP) + return 0; + return err; + } + + memset(&er, 0, sizeof(struct gfs2_ea_request)); + + er.er_type = GFS2_EATYPE_SECURITY; + er.er_name = name; + er.er_data = value; + er.er_name_len = strlen(name); + er.er_data_len = len; + + err = gfs2_ea_set_i(ip, &er); + + kfree(value); + kfree(name); + + return err; +} + /** * gfs2_createi - Create a new inode * @ghs: An array of two holders @@ -897,6 +931,10 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, if (error) goto fail_iput; + error = gfs2_security_init(dip, GFS2_I(inode)); + if (error) + goto fail_iput; + error = link_dinode(dip, name, GFS2_I(inode)); if (error) goto fail_iput; From 7ecdb70a0ea436c06540140242bfac6ac3babfc0 Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Tue, 3 Oct 2006 21:03:35 -0400 Subject: [PATCH 292/292] [GFS2] Fix endian bug for de_type Missing endian conversion for the de_type field. Signed-off-by: Steven Whitehouse --- fs/gfs2/ops_inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 82432d8f7139..ef6e5ed70e94 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c @@ -404,7 +404,7 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) gfs2_trans_add_bh(ip->i_gl, dibh, 1); gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent); dent->de_inum = di->di_num; /* already GFS2 endian */ - dent->de_type = DT_DIR; + dent->de_type = cpu_to_be16(DT_DIR); di->di_entries = cpu_to_be32(1); gfs2_str2qstr(&str, ".."); @@ -412,7 +412,7 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent); gfs2_inum_out(&dip->i_num, &dent->de_inum); - dent->de_type = DT_DIR; + dent->de_type = cpu_to_be16(DT_DIR); gfs2_dinode_out(&ip->i_di, di);