#include <linux/pagemap.h>
#include <linux/security.h>
#include <linux/user_namespace.h>
-#ifdef HAVE_UIDGID_HEADER
-# include <linux/uidgid.h>
-#endif
+#include <linux/uidgid.h>
#define DEBUG_SUBSYSTEM S_LLITE
static void ll_invalidate_negative_children(struct inode *dir)
{
struct dentry *dentry, *tmp_subdir;
- DECLARE_LL_D_HLIST_NODE_PTR(p);
spin_lock(&dir->i_lock);
- ll_d_hlist_for_each_entry(dentry, p, &dir->i_dentry) {
+ hlist_for_each_entry(dentry, &dir->i_dentry, d_alias) {
spin_lock(&dentry->d_lock);
if (!list_empty(&dentry->d_subdirs)) {
struct dentry *child;
lli = ll_i2info(inode);
if (bits & MDS_INODELOCK_UPDATE)
- lli->lli_update_atime = 1;
+ ll_file_set_flag(lli, LLIF_UPDATE_ATIME);
if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) {
CDEBUG(D_INODE, "invalidating inode "DFID" lli = %p, "
/* is lock is too old to be converted? */
lock_res_and_lock(lock);
if (ktime_after(ktime_get(),
- ktime_add(lock->l_last_used,
- ktime_set(ns->ns_dirty_age_limit, 0)))) {
+ ktime_add(lock->l_last_used, ns->ns_dirty_age_limit))) {
unlock_res_and_lock(lock);
return 0;
}
return !!(bits);
}
-int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
+int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *ld,
void *data, int flag)
{
struct lustre_handle lockh;
- __u64 bits = lock->l_policy_data.l_inodebits.bits;
int rc;
ENTRY;
{
__u64 cancel_flags = LCF_ASYNC;
- if (ll_md_need_convert(lock)) {
- cancel_flags |= LCF_CONVERT;
- /* For lock convert some cancel actions may require
- * this lock with non-dropped canceled bits, e.g. page
- * flush for DOM lock. So call ll_lock_cancel_bits()
- * here while canceled bits are still set.
- */
- bits = lock->l_policy_data.l_inodebits.cancel_bits;
- if (bits & MDS_INODELOCK_DOM)
- ll_lock_cancel_bits(lock, MDS_INODELOCK_DOM);
+ /* if lock convert is not needed then still have to
+ * pass lock via ldlm_cli_convert() to keep all states
+ * correct, set cancel_bits to full lock bits to cause
+ * full cancel to happen.
+ */
+ if (!ll_md_need_convert(lock)) {
+ lock_res_and_lock(lock);
+ lock->l_policy_data.l_inodebits.cancel_bits =
+ lock->l_policy_data.l_inodebits.bits;
+ unlock_res_and_lock(lock);
}
+ rc = ldlm_cli_convert(lock, cancel_flags);
+ if (!rc)
+ RETURN(0);
+ /* continue with cancel otherwise */
ldlm_lock2handle(lock, &lockh);
rc = ldlm_cli_cancel(&lockh, cancel_flags);
if (rc < 0) {
break;
}
case LDLM_CB_CANCELING:
+ {
+ __u64 to_cancel = lock->l_policy_data.l_inodebits.bits;
+
/* Nothing to do for non-granted locks */
if (!ldlm_is_granted(lock))
break;
- if (ldlm_is_converting(lock)) {
- /* this is called on already converted lock, so
- * ibits has remained bits only and cancel_bits
- * are bits that were dropped.
- * Note that DOM lock is handled prior lock convert
- * and is excluded here.
+ /* If 'ld' is supplied then bits to be cancelled are passed
+ * implicitly by lock converting and cancel_bits from 'ld'
+ * should be used. Otherwise full cancel is being performed
+ * and lock inodebits are used.
+ *
+ * Note: we cannot rely on cancel_bits in lock itself at this
+ * moment because they can be changed by concurrent thread,
+ * so ldlm_cli_inodebits_convert() pass cancel bits implicitly
+ * in 'ld' parameter.
+ */
+ if (ld) {
+ /* partial bits cancel allowed only during convert */
+ LASSERT(ldlm_is_converting(lock));
+ /* mask cancel bits by lock bits so only no any unused
+ * bits are passed to ll_lock_cancel_bits()
*/
- bits = lock->l_policy_data.l_inodebits.cancel_bits &
- ~MDS_INODELOCK_DOM;
- } else {
- LASSERT(ldlm_is_canceling(lock));
+ to_cancel &= ld->l_policy_data.l_inodebits.cancel_bits;
}
- ll_lock_cancel_bits(lock, bits);
+ ll_lock_cancel_bits(lock, to_cancel);
break;
+ }
default:
LBUG();
}
static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
{
struct dentry *alias, *discon_alias, *invalid_alias;
- DECLARE_LL_D_HLIST_NODE_PTR(p);
- if (ll_d_hlist_empty(&inode->i_dentry))
+ if (hlist_empty(&inode->i_dentry))
return NULL;
discon_alias = invalid_alias = NULL;
spin_lock(&inode->i_lock);
- ll_d_hlist_for_each_entry(alias, p, &inode->i_dentry) {
+ hlist_for_each_entry(alias, &inode->i_dentry, d_alias) {
LASSERT(alias != dentry);
spin_lock(&alias->d_lock);
static int ll_lookup_it_finish(struct ptlrpc_request *request,
struct lookup_intent *it,
struct inode *parent, struct dentry **de,
- void *secctx, __u32 secctxlen)
+ void *secctx, __u32 secctxlen,
+ ktime_t kstart)
{
struct inode *inode = NULL;
__u64 bits = 0;
}
}
+ if (it_disposition(it, DISP_OPEN_CREATE)) {
+ ll_stats_ops_tally(ll_i2sbi(parent), LPROC_LL_MKNOD,
+ ktime_us_delta(ktime_get(), kstart));
+ }
+
GOTO(out, rc = 0);
out:
- if (rc != 0 && it->it_op & IT_OPEN)
+ if (rc != 0 && it->it_op & IT_OPEN) {
+ ll_intent_drop_lock(it);
ll_open_cleanup((*de)->d_sb, request);
+ }
return rc;
}
void **secctx, __u32 *secctxlen,
struct pcc_create_attach *pca)
{
+ ktime_t kstart = ktime_get();
struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
struct dentry *save = dentry, *retval;
struct ptlrpc_request *req = NULL;
ll_unlock_md_op_lsm(op_data);
rc = ll_lookup_it_finish(req, it, parent, &dentry,
secctx != NULL ? *secctx : NULL,
- secctxlen != NULL ? *secctxlen : 0);
+ secctxlen != NULL ? *secctxlen : 0,
+ kstart);
if (rc != 0) {
ll_intent_release(it);
GOTO(out, retval = ERR_PTR(rc));
return retval;
}
-#ifdef HAVE_IOP_ATOMIC_OPEN
static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
unsigned int flags)
{
int rc = 0;
ENTRY;
- CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), file %p,"
- "open_flags %x, mode %x opened %d\n",
+ CDEBUG(D_VFSTRACE,
+ "VFS Op:name=%.*s, dir="DFID"(%p), file %p, open_flags %x, mode %x opened %d\n",
dentry->d_name.len, dentry->d_name.name,
PFID(ll_inode2fid(dir)), dir, file, open_flags, mode,
ll_is_opened(opened, file));
RETURN(rc);
}
-#else /* !HAVE_IOP_ATOMIC_OPEN */
-static struct lookup_intent *
-ll_convert_intent(struct open_intent *oit, int lookup_flags, bool is_readonly)
-{
- struct lookup_intent *it;
-
- OBD_ALLOC_PTR(it);
- if (!it)
- return ERR_PTR(-ENOMEM);
-
- if (lookup_flags & LOOKUP_OPEN) {
- it->it_op = IT_OPEN;
- /* Avoid file creation for ro bind mount point(is_readonly) */
- if ((lookup_flags & LOOKUP_CREATE) && !is_readonly)
- it->it_op |= IT_CREAT;
- it->it_create_mode = (oit->create_mode & S_IALLUGO) | S_IFREG;
- it->it_flags = ll_namei_to_lookup_intent_flag(oit->flags &
- ~(is_readonly ? O_CREAT : 0));
- it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
- } else {
- it->it_op = IT_GETATTR;
- }
-
- return it;
-}
-
-static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
- struct nameidata *nd)
-{
- struct dentry *de;
- ENTRY;
-
- if (nd && !(nd->flags & (LOOKUP_CONTINUE|LOOKUP_PARENT))) {
- struct lookup_intent *it;
-
- if (ll_d2d(dentry) && ll_d2d(dentry)->lld_it) {
- it = ll_d2d(dentry)->lld_it;
- ll_d2d(dentry)->lld_it = NULL;
- } else {
- /*
- * Optimize away (CREATE && !OPEN). Let .create handle
- * the race. But only if we have write permissions
- * there, otherwise we need to proceed with lookup.
- * LU-4185
- */
- if ((nd->flags & LOOKUP_CREATE) &&
- !(nd->flags & LOOKUP_OPEN) &&
- (inode_permission(parent,
- MAY_WRITE | MAY_EXEC) == 0))
- RETURN(NULL);
-
- it = ll_convert_intent(&nd->intent.open, nd->flags,
- (nd->path.mnt->mnt_flags & MNT_READONLY) ||
- (nd->path.mnt->mnt_sb->s_flags & SB_RDONLY));
- if (IS_ERR(it))
- RETURN((struct dentry *)it);
- }
-
- de = ll_lookup_it(parent, dentry, it, NULL, NULL, NULL);
- if (de)
- dentry = de;
- if ((nd->flags & LOOKUP_OPEN) && !IS_ERR(dentry)) { /* Open */
- if (dentry->d_inode &&
- it_disposition(it, DISP_OPEN_OPEN)) { /* nocreate */
- if (S_ISFIFO(dentry->d_inode->i_mode)) {
- /* We cannot call open here as it might
- * deadlock. This case is unreachable in
- * practice because of
- * OBD_CONNECT_NODEVOH. */
- } else {
- struct file *filp;
-
- nd->intent.open.file->private_data = it;
- filp = lookup_instantiate_filp(nd,
- dentry,
- NULL);
- if (IS_ERR(filp)) {
- if (de)
- dput(de);
- de = (struct dentry *)filp;
- }
- }
- } else if (it_disposition(it, DISP_OPEN_CREATE)) {
- /* XXX This can only reliably work on assumption
- * that there are NO hashed negative dentries.*/
- ll_d2d(dentry)->lld_it = it;
- it = NULL; /* Will be freed in ll_create_nd */
- /* We absolutely depend on ll_create_nd to be
- * called to not leak this intent and possible
- * data attached to it */
- }
- }
-
- if (it) {
- ll_intent_release(it);
- OBD_FREE(it, sizeof(*it));
- }
- } else {
- de = ll_lookup_it(parent, dentry, NULL, NULL, NULL, NULL);
- }
-
- RETURN(de);
-}
-#endif /* HAVE_IOP_ATOMIC_OPEN */
-
/* We depend on "mode" being set with the proper file type/umask by now */
static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
{
return err;
}
-static int ll_mknod(struct inode *dir, struct dentry *dchild, ll_umode_t mode,
+static int ll_mknod(struct inode *dir, struct dentry *dchild, umode_t mode,
dev_t rdev)
{
struct qstr *name = &dchild->d_name;
RETURN(err);
}
-#ifdef HAVE_IOP_ATOMIC_OPEN
/*
* Plain create. Intent create is handled in atomic_open.
*/
return rc;
}
-#else /* !HAVE_IOP_ATOMIC_OPEN */
-static int ll_create_nd(struct inode *dir, struct dentry *dentry,
- ll_umode_t mode, struct nameidata *nd)
-{
- struct ll_dentry_data *lld = ll_d2d(dentry);
- struct lookup_intent *it = NULL;
- ktime_t kstart = ktime_get();
- int rc;
-
- CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
-
- if (lld != NULL)
- it = lld->lld_it;
-
- if (!it) {
- /* LU-8559: use LUSTRE_OPC_CREATE for non atomic open case
- * so that volatile file name is recoginized.
- * Mknod(2), however, is designed to not recognize volatile
- * file name to avoid inode leak under orphan directory until
- * MDT reboot */
- return ll_new_node(dir, dentry, NULL, mode, 0,
- LUSTRE_OPC_CREATE);
- }
-
- lld->lld_it = NULL;
-
- /* Was there an error? Propagate it! */
- if (it->it_status) {
- rc = it->it_status;
- goto out;
- }
-
- rc = ll_create_it(dir, dentry, it, NULL, 0);
- if (nd && (nd->flags & LOOKUP_OPEN) && dentry->d_inode) { /* Open */
- struct file *filp;
-
- nd->intent.open.file->private_data = it;
- filp = lookup_instantiate_filp(nd, dentry, NULL);
- if (IS_ERR(filp))
- rc = PTR_ERR(filp);
- }
-
-out:
- ll_intent_release(it);
- OBD_FREE(it, sizeof(*it));
-
- if (!rc)
- ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE,
- ktime_us_delta(ktime_get(), kstart));
-
- return rc;
-}
-#endif /* HAVE_IOP_ATOMIC_OPEN */
static int ll_symlink(struct inode *dir, struct dentry *dchild,
const char *oldpath)
RETURN(err);
}
-static int ll_mkdir(struct inode *dir, struct dentry *dchild, ll_umode_t mode)
+static int ll_mkdir(struct inode *dir, struct dentry *dchild, umode_t mode)
{
struct qstr *name = &dchild->d_name;
ktime_t kstart = ktime_get();
RETURN(PTR_ERR(op_data));
op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
-
+ /* notify lower layer if inode has dirty pages */
+ if (S_ISREG(dchild->d_inode->i_mode) &&
+ ll_i2info(dchild->d_inode)->lli_clob &&
+ dirty_cnt(dchild->d_inode))
+ op_data->op_cli_flags |= CLI_DIRTY_DATA;
op_data->op_fid2 = op_data->op_fid3;
rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
ll_finish_md_op_data(op_data);
const struct inode_operations ll_dir_inode_operations = {
.mknod = ll_mknod,
-#ifdef HAVE_IOP_ATOMIC_OPEN
.atomic_open = ll_atomic_open,
-#endif
.lookup = ll_lookup_nd,
.create = ll_create_nd,
/* We need all these non-raw things for NFSD, to not patch it. */
.removexattr = ll_removexattr,
#endif
.listxattr = ll_listxattr,
-#ifdef HAVE_IOP_GET_ACL
.get_acl = ll_get_acl,
-#endif
#ifdef HAVE_IOP_SET_ACL
.set_acl = ll_set_acl,
#endif
.removexattr = ll_removexattr,
#endif
.listxattr = ll_listxattr,
-#ifdef HAVE_IOP_GET_ACL
.get_acl = ll_get_acl,
-#endif
#ifdef HAVE_IOP_SET_ACL
.set_acl = ll_set_acl,
#endif