diff --git a/kmod/src/dlmglue.c b/kmod/src/dlmglue.c index 7f729239..ffcf264d 100644 --- a/kmod/src/dlmglue.c +++ b/kmod/src/dlmglue.c @@ -57,31 +57,6 @@ BUG(); \ } \ } while (0) -#if 0 -#define MLOG_MASK_PREFIX ML_DLM_GLUE -#include - -#include "ocfs2.h" -#include "ocfs2_lockingver.h" - -#include "alloc.h" -#include "dcache.h" -#include "dlmglue.h" -#include "extent_map.h" -#include "file.h" -#include "heartbeat.h" -#include "inode.h" -#include "journal.h" -#include "stackglue.h" -#include "slot_map.h" -#include "super.h" -#include "uptodate.h" -#include "quota.h" -#include "refcounttree.h" -#include "acl.h" - -#include "buffer_head_io.h" -#endif struct ocfs2_mask_waiter { struct list_head mw_item; @@ -94,29 +69,6 @@ struct ocfs2_mask_waiter { #endif }; -#if 0 -static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres); -static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres); -static struct ocfs2_super *ocfs2_get_file_osb(struct ocfs2_lock_res *lockres); -static struct ocfs2_super *ocfs2_get_qinfo_osb(struct ocfs2_lock_res *lockres); -#endif - -#if 0 -/* - * Return value from ->downconvert_worker functions. - * - * These control the precise actions of ocfs2_unblock_lock() - * and ocfs2_process_blocked_lock() - * - */ -enum ocfs2_unblock_action { - UNBLOCK_CONTINUE = 0, /* Continue downconvert */ - UNBLOCK_CONTINUE_POST = 1, /* Continue downconvert, fire - * ->post_unlock callback */ - UNBLOCK_STOP_POST = 2, /* Do not downconvert, fire - * ->post_unlock() callback. */ -}; -#endif struct ocfs2_unblock_ctl { int requeue; enum ocfs2_unblock_action unblock_action; @@ -127,241 +79,10 @@ struct ocfs2_unblock_ctl { struct lock_class_key lockdep_keys[OCFS2_NUM_LOCK_TYPES]; #endif -#if 0 -static int ocfs2_check_meta_downconvert(struct ocfs2_lock_res *lockres, - int new_level); -static void ocfs2_set_meta_lvb(struct ocfs2_lock_res *lockres); - -static int ocfs2_data_convert_worker(struct ocfs2_lock_res *lockres, - int blocking); - -static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres, - int blocking); - -static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb, - struct ocfs2_lock_res *lockres); - -static void ocfs2_set_qinfo_lvb(struct ocfs2_lock_res *lockres); - -static int ocfs2_check_refcount_downconvert(struct ocfs2_lock_res *lockres, - int new_level); -static int ocfs2_refcount_convert_worker(struct ocfs2_lock_res *lockres, - int blocking); - -#define mlog_meta_lvb(__level, __lockres) ocfs2_dump_meta_lvb_info(__level, __PRETTY_FUNCTION__, __LINE__, __lockres) - -/* This aids in debugging situations where a bad LVB might be involved. */ -static void ocfs2_dump_meta_lvb_info(u64 level, - const char *function, - unsigned int line, - struct ocfs2_lock_res *lockres) -{ - struct ocfs2_meta_lvb *lvb = ocfs2_dlm_lvb(&lockres->l_lksb); - - mlog(level, "LVB information for %s (called from %s:%u):\n", - lockres->l_name, function, line); - mlog(level, "version: %u, clusters: %u, generation: 0x%x\n", - lvb->lvb_version, be32_to_cpu(lvb->lvb_iclusters), - be32_to_cpu(lvb->lvb_igeneration)); - mlog(level, "size: %llu, uid %u, gid %u, mode 0x%x\n", - (unsigned long long)be64_to_cpu(lvb->lvb_isize), - be32_to_cpu(lvb->lvb_iuid), be32_to_cpu(lvb->lvb_igid), - be16_to_cpu(lvb->lvb_imode)); - mlog(level, "nlink %u, atime_packed 0x%llx, ctime_packed 0x%llx, " - "mtime_packed 0x%llx iattr 0x%x\n", be16_to_cpu(lvb->lvb_inlink), - (long long)be64_to_cpu(lvb->lvb_iatime_packed), - (long long)be64_to_cpu(lvb->lvb_ictime_packed), - (long long)be64_to_cpu(lvb->lvb_imtime_packed), - be32_to_cpu(lvb->lvb_iattr)); -} - - -/* - * OCFS2 Lock Resource Operations - * - * These fine tune the behavior of the generic dlmglue locking infrastructure. - * - * The most basic of lock types can point ->l_priv to their respective - * struct ocfs2_super and allow the default actions to manage things. - * - * Right now, each lock type also needs to implement an init function, - * and trivial lock/unlock wrappers. ocfs2_simple_drop_lockres() - * should be called when the lock is no longer needed (i.e., object - * destruction time). - */ -struct ocfs2_lock_res_ops { - /* - * Translate an ocfs2_lock_res * into an ocfs2_super *. Define - * this callback if ->l_priv is not an ocfs2_super pointer - */ - struct ocfs2_super * (*get_osb)(struct ocfs2_lock_res *); - - /* - * Optionally called in the downconvert thread after a - * successful downconvert. The lockres will not be referenced - * after this callback is called, so it is safe to free - * memory, etc. - * - * The exact semantics of when this is called are controlled - * by ->downconvert_worker() - */ - void (*post_unlock)(struct ocfs2_super *, struct ocfs2_lock_res *); - - /* - * Allow a lock type to add checks to determine whether it is - * safe to downconvert a lock. Return 0 to re-queue the - * downconvert at a later time, nonzero to continue. - * - * For most locks, the default checks that there are no - * incompatible holders are sufficient. - * - * Called with the lockres spinlock held. - */ - int (*check_downconvert)(struct ocfs2_lock_res *, int); - - /* - * Allows a lock type to populate the lock value block. This - * is called on downconvert, and when we drop a lock. - * - * Locks that want to use this should set LOCK_TYPE_USES_LVB - * in the flags field. - * - * Called with the lockres spinlock held. - */ - void (*set_lvb)(struct ocfs2_lock_res *); - - /* - * Called from the downconvert thread when it is determined - * that a lock will be downconverted. This is called without - * any locks held so the function can do work that might - * schedule (syncing out data, etc). - * - * This should return any one of the ocfs2_unblock_action - * values, depending on what it wants the thread to do. - */ - int (*downconvert_worker)(struct ocfs2_lock_res *, int); - - /* - * LOCK_TYPE_* flags which describe the specific requirements - * of a lock type. Descriptions of each individual flag follow. - */ - int flags; -}; - -/* - * Some locks want to "refresh" potentially stale data when a - * meaningful (PRMODE or EXMODE) lock level is first obtained. If this - * flag is set, the OCFS2_LOCK_NEEDS_REFRESH flag will be set on the - * individual lockres l_flags member from the ast function. It is - * expected that the locking wrapper will clear the - * OCFS2_LOCK_NEEDS_REFRESH flag when done. - */ -#define LOCK_TYPE_REQUIRES_REFRESH 0x1 - -/* - * Indicate that a lock type makes use of the lock value block. The - * ->set_lvb lock type callback must be defined. - */ -#define LOCK_TYPE_USES_LVB 0x2 - -static struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = { - .get_osb = ocfs2_get_inode_osb, - .flags = 0, -}; - -static struct ocfs2_lock_res_ops ocfs2_inode_inode_lops = { - .get_osb = ocfs2_get_inode_osb, - .check_downconvert = ocfs2_check_meta_downconvert, - .set_lvb = ocfs2_set_meta_lvb, - .downconvert_worker = ocfs2_data_convert_worker, - .flags = LOCK_TYPE_REQUIRES_REFRESH|LOCK_TYPE_USES_LVB, -}; - -static struct ocfs2_lock_res_ops ocfs2_super_lops = { - .flags = LOCK_TYPE_REQUIRES_REFRESH, -}; - -static struct ocfs2_lock_res_ops ocfs2_rename_lops = { - .flags = 0, -}; - -static struct ocfs2_lock_res_ops ocfs2_nfs_sync_lops = { - .flags = 0, -}; - -static struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops = { - .flags = LOCK_TYPE_REQUIRES_REFRESH|LOCK_TYPE_USES_LVB, -}; - -static struct ocfs2_lock_res_ops ocfs2_dentry_lops = { - .get_osb = ocfs2_get_dentry_osb, - .post_unlock = ocfs2_dentry_post_unlock, - .downconvert_worker = ocfs2_dentry_convert_worker, - .flags = 0, -}; - -static struct ocfs2_lock_res_ops ocfs2_inode_open_lops = { - .get_osb = ocfs2_get_inode_osb, - .flags = 0, -}; - -static struct ocfs2_lock_res_ops ocfs2_flock_lops = { - .get_osb = ocfs2_get_file_osb, - .flags = 0, -}; - -static struct ocfs2_lock_res_ops ocfs2_qinfo_lops = { - .set_lvb = ocfs2_set_qinfo_lvb, - .get_osb = ocfs2_get_qinfo_osb, - .flags = LOCK_TYPE_REQUIRES_REFRESH | LOCK_TYPE_USES_LVB, -}; - -static struct ocfs2_lock_res_ops ocfs2_refcount_block_lops = { - .check_downconvert = ocfs2_check_refcount_downconvert, - .downconvert_worker = ocfs2_refcount_convert_worker, - .flags = 0, -}; - -static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres) -{ - return lockres->l_type == OCFS2_LOCK_TYPE_META || - lockres->l_type == OCFS2_LOCK_TYPE_RW || - lockres->l_type == OCFS2_LOCK_TYPE_OPEN; -} -#endif - static inline struct ocfs2_lock_res *ocfs2_lksb_to_lock_res(struct ocfs2_dlm_lksb *lksb) { return container_of(lksb, struct ocfs2_lock_res, l_lksb); } -#if 0 -static inline struct inode *ocfs2_lock_res_inode(struct ocfs2_lock_res *lockres) -{ - BUG_ON(!ocfs2_is_inode_lock(lockres)); - - return (struct inode *) lockres->l_priv; -} - -static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res *lockres) -{ - BUG_ON(lockres->l_type != OCFS2_LOCK_TYPE_DENTRY); - - return (struct ocfs2_dentry_lock *)lockres->l_priv; -} - -static inline struct ocfs2_mem_dqinfo *ocfs2_lock_res_qinfo(struct ocfs2_lock_res *lockres) -{ - BUG_ON(lockres->l_type != OCFS2_LOCK_TYPE_QINFO); - - return (struct ocfs2_mem_dqinfo *)lockres->l_priv; -} - -static inline struct ocfs2_refcount_tree * -ocfs2_lock_res_refcount_tree(struct ocfs2_lock_res *res) -{ - return container_of(res, struct ocfs2_refcount_tree, rf_lockres); -} -#endif static inline struct ocfs2_super *ocfs2_get_lockres_osb(struct ocfs2_lock_res *lockres) { @@ -371,12 +92,6 @@ static inline struct ocfs2_super *ocfs2_get_lockres_osb(struct ocfs2_lock_res *l return (struct ocfs2_super *)lockres->l_priv; } -#if 0 -static int ocfs2_lock_create(struct ocfs2_super *osb, - struct ocfs2_lock_res *lockres, - int level, - u32 dlm_flags); -#endif static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres, int wanted); static void __ocfs2_cluster_unlock(struct ocfs2_super *osb, @@ -415,11 +130,6 @@ static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres, static int ocfs2_downconvert_thread(void *arg); static void ocfs2_downconvert_on_unlock(struct ocfs2_super *osb, struct ocfs2_lock_res *lockres); -#if 0 -static int ocfs2_inode_lock_update(struct inode *inode, - struct buffer_head **bh); -static void ocfs2_drop_osb_locks(struct ocfs2_super *osb); -#endif static inline int ocfs2_highest_compat_lock_level(int level); static unsigned int ocfs2_prepare_downconvert(struct ocfs2_lock_res *lockres, int new_level); @@ -433,25 +143,6 @@ static int ocfs2_prepare_cancel_convert(struct ocfs2_super *osb, static int ocfs2_cancel_convert(struct ocfs2_super *osb, struct ocfs2_lock_res *lockres); -#if 0 -static void ocfs2_build_lock_name(enum ocfs2_lock_type type, - u64 blkno, - u32 generation, - char *name) -{ - int len; - - BUG_ON(type >= OCFS2_NUM_LOCK_TYPES); - - len = snprintf(name, OCFS2_LOCK_ID_MAX_LEN, "%c%s%016llx%08x", - ocfs2_lock_type_char(type), OCFS2_LOCK_ID_PAD, - (long long)blkno, generation); - - BUG_ON(len != (OCFS2_LOCK_ID_MAX_LEN - 1)); - - mlog(0, "built lock resource with name: %s\n", name); -} -#endif static DEFINE_SPINLOCK(ocfs2_dlm_tracking_lock); static void ocfs2_add_lockres_tracking(struct ocfs2_lock_res *res, @@ -578,194 +269,6 @@ void ocfs2_lock_res_init_once(struct ocfs2_lock_res *res) INIT_LIST_HEAD(&res->l_debug_list); } -#if 0 -void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res, - enum ocfs2_lock_type type, - unsigned int generation, - struct inode *inode) -{ - struct ocfs2_lock_res_ops *ops; - - switch(type) { - case OCFS2_LOCK_TYPE_RW: - ops = &ocfs2_inode_rw_lops; - break; - case OCFS2_LOCK_TYPE_META: - ops = &ocfs2_inode_inode_lops; - break; - case OCFS2_LOCK_TYPE_OPEN: - ops = &ocfs2_inode_open_lops; - break; - default: - mlog_bug_on_msg(1, "type: %d\n", type); - ops = NULL; /* thanks, gcc */ - break; - }; - - ocfs2_build_lock_name(type, OCFS2_I(inode)->ip_blkno, - generation, res->l_name); - ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), res, type, ops, inode); -} - -static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres) -{ - struct inode *inode = ocfs2_lock_res_inode(lockres); - - return OCFS2_SB(inode->i_sb); -} - -static struct ocfs2_super *ocfs2_get_qinfo_osb(struct ocfs2_lock_res *lockres) -{ - struct ocfs2_mem_dqinfo *info = lockres->l_priv; - - return OCFS2_SB(info->dqi_gi.dqi_sb); -} - -static struct ocfs2_super *ocfs2_get_file_osb(struct ocfs2_lock_res *lockres) -{ - struct ocfs2_file_private *fp = lockres->l_priv; - - return OCFS2_SB(fp->fp_file->f_mapping->host->i_sb); -} - -static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres) -{ - __be64 inode_blkno_be; - - memcpy(&inode_blkno_be, &lockres->l_name[OCFS2_DENTRY_LOCK_INO_START], - sizeof(__be64)); - - return be64_to_cpu(inode_blkno_be); -} - -static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres) -{ - struct ocfs2_dentry_lock *dl = lockres->l_priv; - - return OCFS2_SB(dl->dl_inode->i_sb); -} - -void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl, - u64 parent, struct inode *inode) -{ - int len; - u64 inode_blkno = OCFS2_I(inode)->ip_blkno; - __be64 inode_blkno_be = cpu_to_be64(inode_blkno); - struct ocfs2_lock_res *lockres = &dl->dl_lockres; - - ocfs2_lock_res_init_once(lockres); - - /* - * Unfortunately, the standard lock naming scheme won't work - * here because we have two 16 byte values to use. Instead, - * we'll stuff the inode number as a binary value. We still - * want error prints to show something without garbling the - * display, so drop a null byte in there before the inode - * number. A future version of OCFS2 will likely use all - * binary lock names. The stringified names have been a - * tremendous aid in debugging, but now that the debugfs - * interface exists, we can mangle things there if need be. - * - * NOTE: We also drop the standard "pad" value (the total lock - * name size stays the same though - the last part is all - * zeros due to the memset in ocfs2_lock_res_init_once() - */ - len = snprintf(lockres->l_name, OCFS2_DENTRY_LOCK_INO_START, - "%c%016llx", - ocfs2_lock_type_char(OCFS2_LOCK_TYPE_DENTRY), - (long long)parent); - - BUG_ON(len != (OCFS2_DENTRY_LOCK_INO_START - 1)); - - memcpy(&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START], &inode_blkno_be, - sizeof(__be64)); - - ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), lockres, - OCFS2_LOCK_TYPE_DENTRY, &ocfs2_dentry_lops, - dl); -} - -static void ocfs2_super_lock_res_init(struct ocfs2_lock_res *res, - struct ocfs2_super *osb) -{ - /* Superblock lockres doesn't come from a slab so we call init - * once on it manually. */ - ocfs2_lock_res_init_once(res); - ocfs2_build_lock_name(OCFS2_LOCK_TYPE_SUPER, OCFS2_SUPER_BLOCK_BLKNO, - 0, res->l_name); - ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_SUPER, - &ocfs2_super_lops, osb); -} - -static void ocfs2_rename_lock_res_init(struct ocfs2_lock_res *res, - struct ocfs2_super *osb) -{ - /* Rename lockres doesn't come from a slab so we call init - * once on it manually. */ - ocfs2_lock_res_init_once(res); - ocfs2_build_lock_name(OCFS2_LOCK_TYPE_RENAME, 0, 0, res->l_name); - ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_RENAME, - &ocfs2_rename_lops, osb); -} - -static void ocfs2_nfs_sync_lock_res_init(struct ocfs2_lock_res *res, - struct ocfs2_super *osb) -{ - /* nfs_sync lockres doesn't come from a slab so we call init - * once on it manually. */ - ocfs2_lock_res_init_once(res); - ocfs2_build_lock_name(OCFS2_LOCK_TYPE_NFS_SYNC, 0, 0, res->l_name); - ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_NFS_SYNC, - &ocfs2_nfs_sync_lops, osb); -} - -static void ocfs2_orphan_scan_lock_res_init(struct ocfs2_lock_res *res, - struct ocfs2_super *osb) -{ - ocfs2_lock_res_init_once(res); - ocfs2_build_lock_name(OCFS2_LOCK_TYPE_ORPHAN_SCAN, 0, 0, res->l_name); - ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_ORPHAN_SCAN, - &ocfs2_orphan_scan_lops, osb); -} - -void ocfs2_file_lock_res_init(struct ocfs2_lock_res *lockres, - struct ocfs2_file_private *fp) -{ - struct inode *inode = fp->fp_file->f_mapping->host; - struct ocfs2_inode_info *oi = OCFS2_I(inode); - - ocfs2_lock_res_init_once(lockres); - ocfs2_build_lock_name(OCFS2_LOCK_TYPE_FLOCK, oi->ip_blkno, - inode->i_generation, lockres->l_name); - ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), lockres, - OCFS2_LOCK_TYPE_FLOCK, &ocfs2_flock_lops, - fp); - lockres->l_flags |= OCFS2_LOCK_NOCACHE; -} - -void ocfs2_qinfo_lock_res_init(struct ocfs2_lock_res *lockres, - struct ocfs2_mem_dqinfo *info) -{ - ocfs2_lock_res_init_once(lockres); - ocfs2_build_lock_name(OCFS2_LOCK_TYPE_QINFO, info->dqi_gi.dqi_type, - 0, lockres->l_name); - ocfs2_lock_res_init_common(OCFS2_SB(info->dqi_gi.dqi_sb), lockres, - OCFS2_LOCK_TYPE_QINFO, &ocfs2_qinfo_lops, - info); -} - -void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res *lockres, - struct ocfs2_super *osb, u64 ref_blkno, - unsigned int generation) -{ - ocfs2_lock_res_init_once(lockres); - ocfs2_build_lock_name(OCFS2_LOCK_TYPE_REFCOUNT, ref_blkno, - generation, lockres->l_name); - ocfs2_lock_res_init_common(osb, lockres, OCFS2_LOCK_TYPE_REFCOUNT, - &ocfs2_refcount_block_lops, osb); -} -#endif - void ocfs2_lock_res_free(struct ocfs2_lock_res *res) { if (!(res->l_flags & OCFS2_LOCK_INITIALIZED)) @@ -1143,11 +646,6 @@ static void ocfs2_blocking_ast(struct ocfs2_dlm_lksb *lksb, int level) BUG_ON(level <= DLM_LOCK_NL); -#if 0 - mlog(ML_BASTS, "BAST fired for lockres %s, blocking %d, level %d, " - "type %s\n", lockres->l_name, level, lockres->l_level, - ocfs2_lock_type_string(lockres->l_type)); -#endif mlog(ML_BASTS, "BAST fired for lockres %s, blocking %d, level %d\n", lockres->l_name, level, lockres->l_level); @@ -1750,179 +1248,6 @@ static int ocfs2_create_new_lock(struct ocfs2_super *osb, #endif #if 0 -/* Grants us an EX lock on the data and metadata resources, skipping - * the normal cluster directory lookup. Use this ONLY on newly created - * inodes which other nodes can't possibly see, and which haven't been - * hashed in the inode hash yet. This can give us a good performance - * increase as it'll skip the network broadcast normally associated - * with creating a new lock resource. */ -int ocfs2_create_new_inode_locks(struct inode *inode) -{ - int ret; - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); - - BUG_ON(!ocfs2_inode_is_new(inode)); - - mlog(0, "Inode %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno); - - /* NOTE: That we don't increment any of the holder counts, nor - * do we add anything to a journal handle. Since this is - * supposed to be a new inode which the cluster doesn't know - * about yet, there is no need to. As far as the LVB handling - * is concerned, this is basically like acquiring an EX lock - * on a resource which has an invalid one -- we'll set it - * valid when we release the EX. */ - - ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_rw_lockres, 1, 1); - if (ret) { - mlog_errno(ret); - goto bail; - } - - /* - * We don't want to use DLM_LKF_LOCAL on a meta data lock as they - * don't use a generation in their lock names. - */ - ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_inode_lockres, 1, 0); - if (ret) { - mlog_errno(ret); - goto bail; - } - - ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_open_lockres, 0, 0); - if (ret) - mlog_errno(ret); - -bail: - return ret; -} - -int ocfs2_rw_lock(struct inode *inode, int write) -{ - int status, level; - struct ocfs2_lock_res *lockres; - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); - - mlog(0, "inode %llu take %s RW lock\n", - (unsigned long long)OCFS2_I(inode)->ip_blkno, - write ? "EXMODE" : "PRMODE"); - - if (ocfs2_mount_local(osb)) - return 0; - - lockres = &OCFS2_I(inode)->ip_rw_lockres; - - level = write ? DLM_LOCK_EX : DLM_LOCK_PR; - - status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level, 0, - 0); - if (status < 0) - mlog_errno(status); - - return status; -} - -void ocfs2_rw_unlock(struct inode *inode, int write) -{ - int level = write ? DLM_LOCK_EX : DLM_LOCK_PR; - struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_rw_lockres; - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); - - mlog(0, "inode %llu drop %s RW lock\n", - (unsigned long long)OCFS2_I(inode)->ip_blkno, - write ? "EXMODE" : "PRMODE"); - - if (!ocfs2_mount_local(osb)) - ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level); -} - -/* - * ocfs2_open_lock always get PR mode lock. - */ -int ocfs2_open_lock(struct inode *inode) -{ - int status = 0; - struct ocfs2_lock_res *lockres; - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); - - mlog(0, "inode %llu take PRMODE open lock\n", - (unsigned long long)OCFS2_I(inode)->ip_blkno); - - if (ocfs2_is_hard_readonly(osb) || ocfs2_mount_local(osb)) - goto out; - - lockres = &OCFS2_I(inode)->ip_open_lockres; - - status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, - DLM_LOCK_PR, 0, 0); - if (status < 0) - mlog_errno(status); - -out: - return status; -} - -int ocfs2_try_open_lock(struct inode *inode, int write) -{ - int status = 0, level; - struct ocfs2_lock_res *lockres; - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); - - mlog(0, "inode %llu try to take %s open lock\n", - (unsigned long long)OCFS2_I(inode)->ip_blkno, - write ? "EXMODE" : "PRMODE"); - - if (ocfs2_is_hard_readonly(osb)) { - if (write) - status = -EROFS; - goto out; - } - - if (ocfs2_mount_local(osb)) - goto out; - - lockres = &OCFS2_I(inode)->ip_open_lockres; - - level = write ? DLM_LOCK_EX : DLM_LOCK_PR; - - /* - * The file system may already holding a PRMODE/EXMODE open lock. - * Since we pass DLM_LKF_NOQUEUE, the request won't block waiting on - * other nodes and the -EAGAIN will indicate to the caller that - * this inode is still in use. - */ - status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, - level, DLM_LKF_NOQUEUE, 0); - -out: - return status; -} - -/* - * ocfs2_open_unlock unlock PR and EX mode open locks. - */ -void ocfs2_open_unlock(struct inode *inode) -{ - struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_open_lockres; - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); - - mlog(0, "inode %llu drop open lock\n", - (unsigned long long)OCFS2_I(inode)->ip_blkno); - - if (ocfs2_mount_local(osb)) - goto out; - - if(lockres->l_ro_holders) - ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, - DLM_LOCK_PR); - if(lockres->l_ex_holders) - ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, - DLM_LOCK_EX); - -out: - return; -} - static int ocfs2_flock_handle_signal(struct ocfs2_lock_res *lockres, int level) { @@ -2159,125 +1484,6 @@ static void ocfs2_downconvert_on_unlock(struct ocfs2_super *osb, ocfs2_wake_downconvert_thread(osb); } -#if 0 -#define OCFS2_SEC_BITS 34 -#define OCFS2_SEC_SHIFT (64 - 34) -#define OCFS2_NSEC_MASK ((1ULL << OCFS2_SEC_SHIFT) - 1) - -/* LVB only has room for 64 bits of time here so we pack it for - * now. */ -static u64 ocfs2_pack_timespec(struct timespec *spec) -{ - u64 res; - u64 sec = spec->tv_sec; - u32 nsec = spec->tv_nsec; - - res = (sec << OCFS2_SEC_SHIFT) | (nsec & OCFS2_NSEC_MASK); - - return res; -} - -/* Call this with the lockres locked. I am reasonably sure we don't - * need ip_lock in this function as anyone who would be changing those - * values is supposed to be blocked in ocfs2_inode_lock right now. */ -static void __ocfs2_stuff_meta_lvb(struct inode *inode) -{ - struct ocfs2_inode_info *oi = OCFS2_I(inode); - struct ocfs2_lock_res *lockres = &oi->ip_inode_lockres; - struct ocfs2_meta_lvb *lvb; - - lvb = ocfs2_dlm_lvb(&lockres->l_lksb); - - /* - * Invalidate the LVB of a deleted inode - this way other - * nodes are forced to go to disk and discover the new inode - * status. - */ - if (oi->ip_flags & OCFS2_INODE_DELETED) { - lvb->lvb_version = 0; - goto out; - } - - lvb->lvb_version = OCFS2_LVB_VERSION; - lvb->lvb_isize = cpu_to_be64(i_size_read(inode)); - lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters); - lvb->lvb_iuid = cpu_to_be32(i_uid_read(inode)); - lvb->lvb_igid = cpu_to_be32(i_gid_read(inode)); - lvb->lvb_imode = cpu_to_be16(inode->i_mode); - lvb->lvb_inlink = cpu_to_be16(inode->i_nlink); - lvb->lvb_iatime_packed = - cpu_to_be64(ocfs2_pack_timespec(&inode->i_atime)); - lvb->lvb_ictime_packed = - cpu_to_be64(ocfs2_pack_timespec(&inode->i_ctime)); - lvb->lvb_imtime_packed = - cpu_to_be64(ocfs2_pack_timespec(&inode->i_mtime)); - lvb->lvb_iattr = cpu_to_be32(oi->ip_attr); - lvb->lvb_idynfeatures = cpu_to_be16(oi->ip_dyn_features); - lvb->lvb_igeneration = cpu_to_be32(inode->i_generation); - -out: - mlog_meta_lvb(0, lockres); -} - -static void ocfs2_unpack_timespec(struct timespec *spec, - u64 packed_time) -{ - spec->tv_sec = packed_time >> OCFS2_SEC_SHIFT; - spec->tv_nsec = packed_time & OCFS2_NSEC_MASK; -} - -static void ocfs2_refresh_inode_from_lvb(struct inode *inode) -{ - struct ocfs2_inode_info *oi = OCFS2_I(inode); - struct ocfs2_lock_res *lockres = &oi->ip_inode_lockres; - struct ocfs2_meta_lvb *lvb; - - mlog_meta_lvb(0, lockres); - - lvb = ocfs2_dlm_lvb(&lockres->l_lksb); - - /* We're safe here without the lockres lock... */ - spin_lock(&oi->ip_lock); - oi->ip_clusters = be32_to_cpu(lvb->lvb_iclusters); - i_size_write(inode, be64_to_cpu(lvb->lvb_isize)); - - oi->ip_attr = be32_to_cpu(lvb->lvb_iattr); - oi->ip_dyn_features = be16_to_cpu(lvb->lvb_idynfeatures); - ocfs2_set_inode_flags(inode); - - /* fast-symlinks are a special case */ - if (S_ISLNK(inode->i_mode) && !oi->ip_clusters) - inode->i_blocks = 0; - else - inode->i_blocks = ocfs2_inode_sector_count(inode); - - i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid)); - i_gid_write(inode, be32_to_cpu(lvb->lvb_igid)); - inode->i_mode = be16_to_cpu(lvb->lvb_imode); - set_nlink(inode, be16_to_cpu(lvb->lvb_inlink)); - ocfs2_unpack_timespec(&inode->i_atime, - be64_to_cpu(lvb->lvb_iatime_packed)); - ocfs2_unpack_timespec(&inode->i_mtime, - be64_to_cpu(lvb->lvb_imtime_packed)); - ocfs2_unpack_timespec(&inode->i_ctime, - be64_to_cpu(lvb->lvb_ictime_packed)); - spin_unlock(&oi->ip_lock); -} - -static inline int ocfs2_meta_lvb_is_trustable(struct inode *inode, - struct ocfs2_lock_res *lockres) -{ - struct ocfs2_meta_lvb *lvb = ocfs2_dlm_lvb(&lockres->l_lksb); - - if (ocfs2_dlm_lvb_valid(&lockres->l_lksb) - && lvb->lvb_version == OCFS2_LVB_VERSION - && be32_to_cpu(lvb->lvb_igeneration) == inode->i_generation) - return 1; - return 0; -} -#endif - - #if 0 /* Determine whether a lock resource needs to be refreshed, and * arbitrate who gets to refresh it. @@ -2337,542 +1543,6 @@ u64 ocfs2_lock_refresh_gen(struct ocfs2_lock_res *lockres) return lockres->l_refresh_gen; } -#if 0 -/* may or may not return a bh if it went to disk. */ -static int ocfs2_inode_lock_update(struct inode *inode, - struct buffer_head **bh) -{ - int status = 0; - struct ocfs2_inode_info *oi = OCFS2_I(inode); - struct ocfs2_lock_res *lockres = &oi->ip_inode_lockres; - struct ocfs2_dinode *fe; - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); - - if (ocfs2_mount_local(osb)) - goto bail; - - spin_lock(&oi->ip_lock); - if (oi->ip_flags & OCFS2_INODE_DELETED) { - mlog(0, "Orphaned inode %llu was deleted while we " - "were waiting on a lock. ip_flags = 0x%x\n", - (unsigned long long)oi->ip_blkno, oi->ip_flags); - spin_unlock(&oi->ip_lock); - status = -ENOENT; - goto bail; - } - spin_unlock(&oi->ip_lock); - - if (!ocfs2_should_refresh_lock_res(lockres)) - goto bail; - - /* This will discard any caching information we might have had - * for the inode metadata. */ - ocfs2_metadata_cache_purge(INODE_CACHE(inode)); - - ocfs2_extent_map_trunc(inode, 0); - - if (ocfs2_meta_lvb_is_trustable(inode, lockres)) { - mlog(0, "Trusting LVB on inode %llu\n", - (unsigned long long)oi->ip_blkno); - ocfs2_refresh_inode_from_lvb(inode); - } else { - /* Boo, we have to go to disk. */ - /* read bh, cast, ocfs2_refresh_inode */ - status = ocfs2_read_inode_block(inode, bh); - if (status < 0) { - mlog_errno(status); - goto bail_refresh; - } - fe = (struct ocfs2_dinode *) (*bh)->b_data; - - /* This is a good chance to make sure we're not - * locking an invalid object. ocfs2_read_inode_block() - * already checked that the inode block is sane. - * - * We bug on a stale inode here because we checked - * above whether it was wiped from disk. The wiping - * node provides a guarantee that we receive that - * message and can mark the inode before dropping any - * locks associated with it. */ - mlog_bug_on_msg(inode->i_generation != - le32_to_cpu(fe->i_generation), - "Invalid dinode %llu disk generation: %u " - "inode->i_generation: %u\n", - (unsigned long long)oi->ip_blkno, - le32_to_cpu(fe->i_generation), - inode->i_generation); - mlog_bug_on_msg(le64_to_cpu(fe->i_dtime) || - !(fe->i_flags & cpu_to_le32(OCFS2_VALID_FL)), - "Stale dinode %llu dtime: %llu flags: 0x%x\n", - (unsigned long long)oi->ip_blkno, - (unsigned long long)le64_to_cpu(fe->i_dtime), - le32_to_cpu(fe->i_flags)); - - ocfs2_refresh_inode(inode, fe); - ocfs2_track_lock_refresh(lockres); - } - - status = 0; -bail_refresh: - ocfs2_complete_lock_res_refresh(lockres, status); -bail: - return status; -} - -static int ocfs2_assign_bh(struct inode *inode, - struct buffer_head **ret_bh, - struct buffer_head *passed_bh) -{ - int status; - - if (passed_bh) { - /* Ok, the update went to disk for us, use the - * returned bh. */ - *ret_bh = passed_bh; - get_bh(*ret_bh); - - return 0; - } - - status = ocfs2_read_inode_block(inode, ret_bh); - if (status < 0) - mlog_errno(status); - - return status; -} - -/* - * returns < 0 error if the callback will never be called, otherwise - * the result of the lock will be communicated via the callback. - */ -int ocfs2_inode_lock_full_nested(struct inode *inode, - struct buffer_head **ret_bh, - int ex, - int arg_flags, - int subclass) -{ - int status, level, acquired; - u32 dlm_flags; - struct ocfs2_lock_res *lockres = NULL; - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); - struct buffer_head *local_bh = NULL; - - mlog(0, "inode %llu, take %s META lock\n", - (unsigned long long)OCFS2_I(inode)->ip_blkno, - ex ? "EXMODE" : "PRMODE"); - - status = 0; - acquired = 0; - /* We'll allow faking a readonly metadata lock for - * rodevices. */ - if (ocfs2_is_hard_readonly(osb)) { - if (ex) - status = -EROFS; - goto getbh; - } - - if ((arg_flags & OCFS2_META_LOCK_GETBH) || - ocfs2_mount_local(osb)) - goto update; - - if (!(arg_flags & OCFS2_META_LOCK_RECOVERY)) - ocfs2_wait_for_recovery(osb); - - lockres = &OCFS2_I(inode)->ip_inode_lockres; - level = ex ? DLM_LOCK_EX : DLM_LOCK_PR; - dlm_flags = 0; - if (arg_flags & OCFS2_META_LOCK_NOQUEUE) - dlm_flags |= DLM_LKF_NOQUEUE; - - status = __ocfs2_cluster_lock(osb, lockres, level, dlm_flags, - arg_flags, subclass, _RET_IP_); - if (status < 0) { - if (status != -EAGAIN) - mlog_errno(status); - goto bail; - } - - /* Notify the error cleanup path to drop the cluster lock. */ - acquired = 1; - - /* We wait twice because a node may have died while we were in - * the lower dlm layers. The second time though, we've - * committed to owning this lock so we don't allow signals to - * abort the operation. */ - if (!(arg_flags & OCFS2_META_LOCK_RECOVERY)) - ocfs2_wait_for_recovery(osb); - -update: - /* - * We only see this flag if we're being called from - * ocfs2_read_locked_inode(). It means we're locking an inode - * which hasn't been populated yet, so clear the refresh flag - * and let the caller handle it. - */ - if (inode->i_state & I_NEW) { - status = 0; - if (lockres) - ocfs2_complete_lock_res_refresh(lockres, 0); - goto bail; - } - - /* This is fun. The caller may want a bh back, or it may - * not. ocfs2_inode_lock_update definitely wants one in, but - * may or may not read one, depending on what's in the - * LVB. The result of all of this is that we've *only* gone to - * disk if we have to, so the complexity is worthwhile. */ - status = ocfs2_inode_lock_update(inode, &local_bh); - if (status < 0) { - if (status != -ENOENT) - mlog_errno(status); - goto bail; - } -getbh: - if (ret_bh) { - status = ocfs2_assign_bh(inode, ret_bh, local_bh); - if (status < 0) { - mlog_errno(status); - goto bail; - } - } - -bail: - if (status < 0) { - if (ret_bh && (*ret_bh)) { - brelse(*ret_bh); - *ret_bh = NULL; - } - if (acquired) - ocfs2_inode_unlock(inode, ex); - } - - if (local_bh) - brelse(local_bh); - - return status; -} - -/* - * This is working around a lock inversion between tasks acquiring DLM - * locks while holding a page lock and the downconvert thread which - * blocks dlm lock acquiry while acquiring page locks. - * - * ** These _with_page variantes are only intended to be called from aop - * methods that hold page locks and return a very specific *positive* error - * code that aop methods pass up to the VFS -- test for errors with != 0. ** - * - * The DLM is called such that it returns -EAGAIN if it would have - * blocked waiting for the downconvert thread. In that case we unlock - * our page so the downconvert thread can make progress. Once we've - * done this we have to return AOP_TRUNCATED_PAGE so the aop method - * that called us can bubble that back up into the VFS who will then - * immediately retry the aop call. - */ -int ocfs2_inode_lock_with_page(struct inode *inode, - struct buffer_head **ret_bh, - int ex, - struct page *page) -{ - int ret; - - ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK); - if (ret == -EAGAIN) { - unlock_page(page); - ret = AOP_TRUNCATED_PAGE; - } - - return ret; -} - -int ocfs2_inode_lock_atime(struct inode *inode, - struct vfsmount *vfsmnt, - int *level) -{ - int ret; - - ret = ocfs2_inode_lock(inode, NULL, 0); - if (ret < 0) { - mlog_errno(ret); - return ret; - } - - /* - * If we should update atime, we will get EX lock, - * otherwise we just get PR lock. - */ - if (ocfs2_should_update_atime(inode, vfsmnt)) { - struct buffer_head *bh = NULL; - - ocfs2_inode_unlock(inode, 0); - ret = ocfs2_inode_lock(inode, &bh, 1); - if (ret < 0) { - mlog_errno(ret); - return ret; - } - *level = 1; - if (ocfs2_should_update_atime(inode, vfsmnt)) - ocfs2_update_inode_atime(inode, bh); - if (bh) - brelse(bh); - } else - *level = 0; - - return ret; -} - -void ocfs2_inode_unlock(struct inode *inode, - int ex) -{ - int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR; - struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_inode_lockres; - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); - - mlog(0, "inode %llu drop %s META lock\n", - (unsigned long long)OCFS2_I(inode)->ip_blkno, - ex ? "EXMODE" : "PRMODE"); - - if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)) && - !ocfs2_mount_local(osb)) - ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level); -} - -/* - * This _tracker variantes are introduced to deal with the recursive cluster - * locking issue. The idea is to keep track of a lock holder on the stack of - * the current process. If there's a lock holder on the stack, we know the - * task context is already protected by cluster locking. Currently, they're - * used in some VFS entry routines. - * - * return < 0 on error, return == 0 if there's no lock holder on the stack - * before this call, return == 1 if this call would be a recursive locking. - */ -int ocfs2_inode_lock_tracker(struct inode *inode, - struct buffer_head **ret_bh, - int ex, - struct ocfs2_lock_holder *oh) -{ - int status; - int arg_flags = 0, has_locked; - struct ocfs2_lock_res *lockres; - - lockres = &OCFS2_I(inode)->ip_inode_lockres; - has_locked = ocfs2_is_locked_by_me(lockres); - /* Just get buffer head if the cluster lock has been taken */ - if (has_locked) - arg_flags = OCFS2_META_LOCK_GETBH; - - if (likely(!has_locked || ret_bh)) { - status = ocfs2_inode_lock_full(inode, ret_bh, ex, arg_flags); - if (status < 0) { - if (status != -ENOENT) - mlog_errno(status); - return status; - } - } - if (!has_locked) - ocfs2_add_holder(lockres, oh); - - return has_locked; -} - -void ocfs2_inode_unlock_tracker(struct inode *inode, - int ex, - struct ocfs2_lock_holder *oh, - int had_lock) -{ - struct ocfs2_lock_res *lockres; - - lockres = &OCFS2_I(inode)->ip_inode_lockres; - /* had_lock means that the currect process already takes the cluster - * lock previously. If had_lock is 1, we have nothing to do here, and - * it will get unlocked where we got the lock. - */ - if (!had_lock) { - ocfs2_remove_holder(lockres, oh); - ocfs2_inode_unlock(inode, ex); - } -} - -int ocfs2_orphan_scan_lock(struct ocfs2_super *osb, u32 *seqno) -{ - struct ocfs2_lock_res *lockres; - struct ocfs2_orphan_scan_lvb *lvb; - int status = 0; - - if (ocfs2_is_hard_readonly(osb)) - return -EROFS; - - if (ocfs2_mount_local(osb)) - return 0; - - lockres = &osb->osb_orphan_scan.os_lockres; - status = ocfs2_cluster_lock(osb, lockres, DLM_LOCK_EX, 0, 0); - if (status < 0) - return status; - - lvb = ocfs2_dlm_lvb(&lockres->l_lksb); - if (ocfs2_dlm_lvb_valid(&lockres->l_lksb) && - lvb->lvb_version == OCFS2_ORPHAN_LVB_VERSION) - *seqno = be32_to_cpu(lvb->lvb_os_seqno); - else - *seqno = osb->osb_orphan_scan.os_seqno + 1; - - return status; -} - -void ocfs2_orphan_scan_unlock(struct ocfs2_super *osb, u32 seqno) -{ - struct ocfs2_lock_res *lockres; - struct ocfs2_orphan_scan_lvb *lvb; - - if (!ocfs2_is_hard_readonly(osb) && !ocfs2_mount_local(osb)) { - lockres = &osb->osb_orphan_scan.os_lockres; - lvb = ocfs2_dlm_lvb(&lockres->l_lksb); - lvb->lvb_version = OCFS2_ORPHAN_LVB_VERSION; - lvb->lvb_os_seqno = cpu_to_be32(seqno); - ocfs2_cluster_unlock(osb, lockres, DLM_LOCK_EX); - } -} - -int ocfs2_super_lock(struct ocfs2_super *osb, - int ex) -{ - int status = 0; - int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR; - struct ocfs2_lock_res *lockres = &osb->osb_super_lockres; - - if (ocfs2_is_hard_readonly(osb)) - return -EROFS; - - if (ocfs2_mount_local(osb)) - goto bail; - - status = ocfs2_cluster_lock(osb, lockres, level, 0, 0); - if (status < 0) { - mlog_errno(status); - goto bail; - } - - /* The super block lock path is really in the best position to - * know when resources covered by the lock need to be - * refreshed, so we do it here. Of course, making sense of - * everything is up to the caller :) */ - status = ocfs2_should_refresh_lock_res(lockres); - if (status) { - status = ocfs2_refresh_slot_info(osb); - - ocfs2_complete_lock_res_refresh(lockres, status); - - if (status < 0) { - ocfs2_cluster_unlock(osb, lockres, level); - mlog_errno(status); - } - ocfs2_track_lock_refresh(lockres); - } -bail: - return status; -} - -void ocfs2_super_unlock(struct ocfs2_super *osb, - int ex) -{ - int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR; - struct ocfs2_lock_res *lockres = &osb->osb_super_lockres; - - if (!ocfs2_mount_local(osb)) - ocfs2_cluster_unlock(osb, lockres, level); -} - -int ocfs2_rename_lock(struct ocfs2_super *osb) -{ - int status; - struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres; - - if (ocfs2_is_hard_readonly(osb)) - return -EROFS; - - if (ocfs2_mount_local(osb)) - return 0; - - status = ocfs2_cluster_lock(osb, lockres, DLM_LOCK_EX, 0, 0); - if (status < 0) - mlog_errno(status); - - return status; -} - -void ocfs2_rename_unlock(struct ocfs2_super *osb) -{ - struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres; - - if (!ocfs2_mount_local(osb)) - ocfs2_cluster_unlock(osb, lockres, DLM_LOCK_EX); -} - -int ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int ex) -{ - int status; - struct ocfs2_lock_res *lockres = &osb->osb_nfs_sync_lockres; - - if (ocfs2_is_hard_readonly(osb)) - return -EROFS; - - if (ocfs2_mount_local(osb)) - return 0; - - status = ocfs2_cluster_lock(osb, lockres, ex ? LKM_EXMODE : LKM_PRMODE, - 0, 0); - if (status < 0) - mlog(ML_ERROR, "lock on nfs sync lock failed %d\n", status); - - return status; -} - -void ocfs2_nfs_sync_unlock(struct ocfs2_super *osb, int ex) -{ - struct ocfs2_lock_res *lockres = &osb->osb_nfs_sync_lockres; - - if (!ocfs2_mount_local(osb)) - ocfs2_cluster_unlock(osb, lockres, - ex ? LKM_EXMODE : LKM_PRMODE); -} - -int ocfs2_dentry_lock(struct dentry *dentry, int ex) -{ - int ret; - int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR; - struct ocfs2_dentry_lock *dl = dentry->d_fsdata; - struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); - - BUG_ON(!dl); - - if (ocfs2_is_hard_readonly(osb)) { - if (ex) - return -EROFS; - return 0; - } - - if (ocfs2_mount_local(osb)) - return 0; - - ret = ocfs2_cluster_lock(osb, &dl->dl_lockres, level, 0, 0); - if (ret < 0) - mlog_errno(ret); - - return ret; -} - -void ocfs2_dentry_unlock(struct dentry *dentry, int ex) -{ - int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR; - struct ocfs2_dentry_lock *dl = dentry->d_fsdata; - struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); - - if (!ocfs2_is_hard_readonly(osb) && !ocfs2_mount_local(osb)) - ocfs2_cluster_unlock(osb, &dl->dl_lockres, level); -} -#endif - /* Reference counting of the dlm debug structure. We want this because * open references on the debug inodes can live on after a mount, so * we can't rely on the ocfs2_super to always exist. */ @@ -3433,47 +2103,6 @@ void ocfs2_simple_drop_lockres(struct ocfs2_super *osb, mlog_errno(ret); } -#if 0 -static void ocfs2_drop_osb_locks(struct ocfs2_super *osb) -{ - ocfs2_simple_drop_lockres(osb, &osb->osb_super_lockres); - ocfs2_simple_drop_lockres(osb, &osb->osb_rename_lockres); - ocfs2_simple_drop_lockres(osb, &osb->osb_nfs_sync_lockres); - ocfs2_simple_drop_lockres(osb, &osb->osb_orphan_scan.os_lockres); -} - -int ocfs2_drop_inode_locks(struct inode *inode) -{ - int status, err; - - /* No need to call ocfs2_mark_lockres_freeing here - - * ocfs2_clear_inode has done it for us. */ - - err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb), - &OCFS2_I(inode)->ip_open_lockres); - if (err < 0) - mlog_errno(err); - - status = err; - - err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb), - &OCFS2_I(inode)->ip_inode_lockres); - if (err < 0) - mlog_errno(err); - if (err < 0 && !status) - status = err; - - err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb), - &OCFS2_I(inode)->ip_rw_lockres); - if (err < 0) - mlog_errno(err); - if (err < 0 && !status) - status = err; - - return status; -} -#endif - static unsigned int ocfs2_prepare_downconvert(struct ocfs2_lock_res *lockres, int new_level) { @@ -3790,369 +2419,6 @@ leave_requeue: return 0; } -#if 0 -static int ocfs2_data_convert_worker(struct ocfs2_lock_res *lockres, - int blocking) -{ - struct inode *inode; - struct address_space *mapping; - struct ocfs2_inode_info *oi; - - inode = ocfs2_lock_res_inode(lockres); - mapping = inode->i_mapping; - - if (S_ISDIR(inode->i_mode)) { - oi = OCFS2_I(inode); - oi->ip_dir_lock_gen++; - mlog(0, "generation: %u\n", oi->ip_dir_lock_gen); - goto out; - } - - if (!S_ISREG(inode->i_mode)) - goto out; - - /* - * We need this before the filemap_fdatawrite() so that it can - * transfer the dirty bit from the PTE to the - * page. Unfortunately this means that even for EX->PR - * downconverts, we'll lose our mappings and have to build - * them up again. - */ - unmap_mapping_range(mapping, 0, 0, 0); - - if (filemap_fdatawrite(mapping)) { - mlog(ML_ERROR, "Could not sync inode %llu for downconvert!", - (unsigned long long)OCFS2_I(inode)->ip_blkno); - } - sync_mapping_buffers(mapping); - if (blocking == DLM_LOCK_EX) { - truncate_inode_pages(mapping, 0); - } else { - /* We only need to wait on the I/O if we're not also - * truncating pages because truncate_inode_pages waits - * for us above. We don't truncate pages if we're - * blocking anything < EXMODE because we want to keep - * them around in that case. */ - filemap_fdatawait(mapping); - } - - forget_all_cached_acls(inode); - -out: - return UNBLOCK_CONTINUE; -} - -static int ocfs2_ci_checkpointed(struct ocfs2_caching_info *ci, - struct ocfs2_lock_res *lockres, - int new_level) -{ - int checkpointed = ocfs2_ci_fully_checkpointed(ci); - - BUG_ON(new_level != DLM_LOCK_NL && new_level != DLM_LOCK_PR); - BUG_ON(lockres->l_level != DLM_LOCK_EX && !checkpointed); - - if (checkpointed) - return 1; - - ocfs2_start_checkpoint(OCFS2_SB(ocfs2_metadata_cache_get_super(ci))); - return 0; -} - -static int ocfs2_check_meta_downconvert(struct ocfs2_lock_res *lockres, - int new_level) -{ - struct inode *inode = ocfs2_lock_res_inode(lockres); - - return ocfs2_ci_checkpointed(INODE_CACHE(inode), lockres, new_level); -} - -static void ocfs2_set_meta_lvb(struct ocfs2_lock_res *lockres) -{ - struct inode *inode = ocfs2_lock_res_inode(lockres); - - __ocfs2_stuff_meta_lvb(inode); -} - -/* - * Does the final reference drop on our dentry lock. Right now this - * happens in the downconvert thread, but we could choose to simplify the - * dlmglue API and push these off to the ocfs2_wq in the future. - */ -static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb, - struct ocfs2_lock_res *lockres) -{ - struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres); - ocfs2_dentry_lock_put(osb, dl); -} - -/* - * d_delete() matching dentries before the lock downconvert. - * - * At this point, any process waiting to destroy the - * dentry_lock due to last ref count is stopped by the - * OCFS2_LOCK_QUEUED flag. - * - * We have two potential problems - * - * 1) If we do the last reference drop on our dentry_lock (via dput) - * we'll wind up in ocfs2_release_dentry_lock(), waiting on - * the downconvert to finish. Instead we take an elevated - * reference and push the drop until after we've completed our - * unblock processing. - * - * 2) There might be another process with a final reference, - * waiting on us to finish processing. If this is the case, we - * detect it and exit out - there's no more dentries anyway. - */ -static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres, - int blocking) -{ - struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres); - struct ocfs2_inode_info *oi = OCFS2_I(dl->dl_inode); - struct dentry *dentry; - unsigned long flags; - int extra_ref = 0; - - /* - * This node is blocking another node from getting a read - * lock. This happens when we've renamed within a - * directory. We've forced the other nodes to d_delete(), but - * we never actually dropped our lock because it's still - * valid. The downconvert code will retain a PR for this node, - * so there's no further work to do. - */ - if (blocking == DLM_LOCK_PR) - return UNBLOCK_CONTINUE; - - /* - * Mark this inode as potentially orphaned. The code in - * ocfs2_delete_inode() will figure out whether it actually - * needs to be freed or not. - */ - spin_lock(&oi->ip_lock); - oi->ip_flags |= OCFS2_INODE_MAYBE_ORPHANED; - spin_unlock(&oi->ip_lock); - - /* - * Yuck. We need to make sure however that the check of - * OCFS2_LOCK_FREEING and the extra reference are atomic with - * respect to a reference decrement or the setting of that - * flag. - */ - spin_lock_irqsave(&lockres->l_lock, flags); - spin_lock(&dentry_attach_lock); - if (!(lockres->l_flags & OCFS2_LOCK_FREEING) - && dl->dl_count) { - dl->dl_count++; - extra_ref = 1; - } - spin_unlock(&dentry_attach_lock); - spin_unlock_irqrestore(&lockres->l_lock, flags); - - mlog(0, "extra_ref = %d\n", extra_ref); - - /* - * We have a process waiting on us in ocfs2_dentry_iput(), - * which means we can't have any more outstanding - * aliases. There's no need to do any more work. - */ - if (!extra_ref) - return UNBLOCK_CONTINUE; - - spin_lock(&dentry_attach_lock); - while (1) { - dentry = ocfs2_find_local_alias(dl->dl_inode, - dl->dl_parent_blkno, 1); - if (!dentry) - break; - spin_unlock(&dentry_attach_lock); - - if (S_ISDIR(dl->dl_inode->i_mode)) - shrink_dcache_parent(dentry); - - mlog(0, "d_delete(%pd);\n", dentry); - - /* - * The following dcache calls may do an - * iput(). Normally we don't want that from the - * downconverting thread, but in this case it's ok - * because the requesting node already has an - * exclusive lock on the inode, so it can't be queued - * for a downconvert. - */ - d_delete(dentry); - dput(dentry); - - spin_lock(&dentry_attach_lock); - } - spin_unlock(&dentry_attach_lock); - - /* - * If we are the last holder of this dentry lock, there is no - * reason to downconvert so skip straight to the unlock. - */ - if (dl->dl_count == 1) - return UNBLOCK_STOP_POST; - - return UNBLOCK_CONTINUE_POST; -} - -static int ocfs2_check_refcount_downconvert(struct ocfs2_lock_res *lockres, - int new_level) -{ - struct ocfs2_refcount_tree *tree = - ocfs2_lock_res_refcount_tree(lockres); - - return ocfs2_ci_checkpointed(&tree->rf_ci, lockres, new_level); -} - -static int ocfs2_refcount_convert_worker(struct ocfs2_lock_res *lockres, - int blocking) -{ - struct ocfs2_refcount_tree *tree = - ocfs2_lock_res_refcount_tree(lockres); - - ocfs2_metadata_cache_purge(&tree->rf_ci); - - return UNBLOCK_CONTINUE; -} - -static void ocfs2_set_qinfo_lvb(struct ocfs2_lock_res *lockres) -{ - struct ocfs2_qinfo_lvb *lvb; - struct ocfs2_mem_dqinfo *oinfo = ocfs2_lock_res_qinfo(lockres); - struct mem_dqinfo *info = sb_dqinfo(oinfo->dqi_gi.dqi_sb, - oinfo->dqi_gi.dqi_type); - - lvb = ocfs2_dlm_lvb(&lockres->l_lksb); - lvb->lvb_version = OCFS2_QINFO_LVB_VERSION; - lvb->lvb_bgrace = cpu_to_be32(info->dqi_bgrace); - lvb->lvb_igrace = cpu_to_be32(info->dqi_igrace); - lvb->lvb_syncms = cpu_to_be32(oinfo->dqi_syncms); - lvb->lvb_blocks = cpu_to_be32(oinfo->dqi_gi.dqi_blocks); - lvb->lvb_free_blk = cpu_to_be32(oinfo->dqi_gi.dqi_free_blk); - lvb->lvb_free_entry = cpu_to_be32(oinfo->dqi_gi.dqi_free_entry); -} - -void ocfs2_qinfo_unlock(struct ocfs2_mem_dqinfo *oinfo, int ex) -{ - struct ocfs2_lock_res *lockres = &oinfo->dqi_gqlock; - struct ocfs2_super *osb = OCFS2_SB(oinfo->dqi_gi.dqi_sb); - int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR; - - if (!ocfs2_is_hard_readonly(osb) && !ocfs2_mount_local(osb)) - ocfs2_cluster_unlock(osb, lockres, level); -} - -static int ocfs2_refresh_qinfo(struct ocfs2_mem_dqinfo *oinfo) -{ - struct mem_dqinfo *info = sb_dqinfo(oinfo->dqi_gi.dqi_sb, - oinfo->dqi_gi.dqi_type); - struct ocfs2_lock_res *lockres = &oinfo->dqi_gqlock; - struct ocfs2_qinfo_lvb *lvb = ocfs2_dlm_lvb(&lockres->l_lksb); - struct buffer_head *bh = NULL; - struct ocfs2_global_disk_dqinfo *gdinfo; - int status = 0; - - if (ocfs2_dlm_lvb_valid(&lockres->l_lksb) && - lvb->lvb_version == OCFS2_QINFO_LVB_VERSION) { - info->dqi_bgrace = be32_to_cpu(lvb->lvb_bgrace); - info->dqi_igrace = be32_to_cpu(lvb->lvb_igrace); - oinfo->dqi_syncms = be32_to_cpu(lvb->lvb_syncms); - oinfo->dqi_gi.dqi_blocks = be32_to_cpu(lvb->lvb_blocks); - oinfo->dqi_gi.dqi_free_blk = be32_to_cpu(lvb->lvb_free_blk); - oinfo->dqi_gi.dqi_free_entry = - be32_to_cpu(lvb->lvb_free_entry); - } else { - status = ocfs2_read_quota_phys_block(oinfo->dqi_gqinode, - oinfo->dqi_giblk, &bh); - if (status) { - mlog_errno(status); - goto bail; - } - gdinfo = (struct ocfs2_global_disk_dqinfo *) - (bh->b_data + OCFS2_GLOBAL_INFO_OFF); - info->dqi_bgrace = le32_to_cpu(gdinfo->dqi_bgrace); - info->dqi_igrace = le32_to_cpu(gdinfo->dqi_igrace); - oinfo->dqi_syncms = le32_to_cpu(gdinfo->dqi_syncms); - oinfo->dqi_gi.dqi_blocks = le32_to_cpu(gdinfo->dqi_blocks); - oinfo->dqi_gi.dqi_free_blk = le32_to_cpu(gdinfo->dqi_free_blk); - oinfo->dqi_gi.dqi_free_entry = - le32_to_cpu(gdinfo->dqi_free_entry); - brelse(bh); - ocfs2_track_lock_refresh(lockres); - } - -bail: - return status; -} - -/* Lock quota info, this function expects at least shared lock on the quota file - * so that we can safely refresh quota info from disk. */ -int ocfs2_qinfo_lock(struct ocfs2_mem_dqinfo *oinfo, int ex) -{ - struct ocfs2_lock_res *lockres = &oinfo->dqi_gqlock; - struct ocfs2_super *osb = OCFS2_SB(oinfo->dqi_gi.dqi_sb); - int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR; - int status = 0; - - /* On RO devices, locking really isn't needed... */ - if (ocfs2_is_hard_readonly(osb)) { - if (ex) - status = -EROFS; - goto bail; - } - if (ocfs2_mount_local(osb)) - goto bail; - - status = ocfs2_cluster_lock(osb, lockres, level, 0, 0); - if (status < 0) { - mlog_errno(status); - goto bail; - } - if (!ocfs2_should_refresh_lock_res(lockres)) - goto bail; - /* OK, we have the lock but we need to refresh the quota info */ - status = ocfs2_refresh_qinfo(oinfo); - if (status) - ocfs2_qinfo_unlock(oinfo, ex); - ocfs2_complete_lock_res_refresh(lockres, status); -bail: - return status; -} - -int ocfs2_refcount_lock(struct ocfs2_refcount_tree *ref_tree, int ex) -{ - int status; - int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR; - struct ocfs2_lock_res *lockres = &ref_tree->rf_lockres; - struct ocfs2_super *osb = lockres->l_priv; - - - if (ocfs2_is_hard_readonly(osb)) - return -EROFS; - - if (ocfs2_mount_local(osb)) - return 0; - - status = ocfs2_cluster_lock(osb, lockres, level, 0, 0); - if (status < 0) - mlog_errno(status); - - return status; -} - -void ocfs2_refcount_unlock(struct ocfs2_refcount_tree *ref_tree, int ex) -{ - int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR; - struct ocfs2_lock_res *lockres = &ref_tree->rf_lockres; - struct ocfs2_super *osb = lockres->l_priv; - - if (!ocfs2_mount_local(osb)) - ocfs2_cluster_unlock(osb, lockres, level); -} -#endif - static void ocfs2_process_blocked_lock(struct ocfs2_super *osb, struct ocfs2_lock_res *lockres) {