Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
0004  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
0005  */
0006 
0007 #include <linux/spinlock.h>
0008 #include <linux/completion.h>
0009 #include <linux/buffer_head.h>
0010 #include <linux/gfs2_ondisk.h>
0011 #include <linux/namei.h>
0012 #include <linux/crc32.h>
0013 
0014 #include "gfs2.h"
0015 #include "incore.h"
0016 #include "dir.h"
0017 #include "glock.h"
0018 #include "super.h"
0019 #include "util.h"
0020 #include "inode.h"
0021 
0022 /**
0023  * gfs2_drevalidate - Check directory lookup consistency
0024  * @dentry: the mapping to check
0025  * @flags: lookup flags
0026  *
0027  * Check to make sure the lookup necessary to arrive at this inode from its
0028  * parent is still good.
0029  *
0030  * Returns: 1 if the dentry is ok, 0 if it isn't
0031  */
0032 
0033 static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
0034 {
0035     struct dentry *parent;
0036     struct gfs2_sbd *sdp;
0037     struct gfs2_inode *dip;
0038     struct inode *inode;
0039     struct gfs2_holder d_gh;
0040     struct gfs2_inode *ip = NULL;
0041     int error, valid = 0;
0042     int had_lock = 0;
0043 
0044     if (flags & LOOKUP_RCU)
0045         return -ECHILD;
0046 
0047     parent = dget_parent(dentry);
0048     sdp = GFS2_SB(d_inode(parent));
0049     dip = GFS2_I(d_inode(parent));
0050     inode = d_inode(dentry);
0051 
0052     if (inode) {
0053         if (is_bad_inode(inode))
0054             goto out;
0055         ip = GFS2_I(inode);
0056     }
0057 
0058     if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) {
0059         valid = 1;
0060         goto out;
0061     }
0062 
0063     had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
0064     if (!had_lock) {
0065         error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
0066         if (error)
0067             goto out;
0068     }
0069 
0070     error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip);
0071     valid = inode ? !error : (error == -ENOENT);
0072 
0073     if (!had_lock)
0074         gfs2_glock_dq_uninit(&d_gh);
0075 out:
0076     dput(parent);
0077     return valid;
0078 }
0079 
0080 static int gfs2_dhash(const struct dentry *dentry, struct qstr *str)
0081 {
0082     str->hash = gfs2_disk_hash(str->name, str->len);
0083     return 0;
0084 }
0085 
0086 static int gfs2_dentry_delete(const struct dentry *dentry)
0087 {
0088     struct gfs2_inode *ginode;
0089 
0090     if (d_really_is_negative(dentry))
0091         return 0;
0092 
0093     ginode = GFS2_I(d_inode(dentry));
0094     if (!gfs2_holder_initialized(&ginode->i_iopen_gh))
0095         return 0;
0096 
0097     if (test_bit(GLF_DEMOTE, &ginode->i_iopen_gh.gh_gl->gl_flags))
0098         return 1;
0099 
0100     return 0;
0101 }
0102 
0103 const struct dentry_operations gfs2_dops = {
0104     .d_revalidate = gfs2_drevalidate,
0105     .d_hash = gfs2_dhash,
0106     .d_delete = gfs2_dentry_delete,
0107 };
0108