static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir) { struct dentry *dentry = file->f_dentry; struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); int status; DPRINTK("file=%p dentry=%p %.*s", file, dentry, dentry->d_name.len, dentry->d_name.name); if (autofs4_oz_mode(sbi)) goto out; if (autofs4_ispending(dentry)) { DPRINTK("dentry busy"); return -EBUSY; } if (d_mountpoint(dentry)) { struct file *fp = file->private_data; if (!fp) return -ENOENT; if (!fp->f_op || !fp->f_op->readdir) goto out; status = vfs_readdir(fp, filldir, dirent); file->f_pos = fp->f_pos; if (status) autofs4_copy_atime(file, fp); return status; } out: return autofs4_dcache_readdir(file, dirent, filldir); }
static int autofs4_dir_close(struct inode *inode, struct file *file) { struct dentry *dentry = file->f_dentry; struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); DPRINTK("file=%p dentry=%p %.*s", file, dentry, dentry->d_name.len, dentry->d_name.name); if (autofs4_oz_mode(sbi)) goto out; if (autofs4_ispending(dentry)) { DPRINTK("dentry busy"); return -EBUSY; } if (d_mountpoint(dentry)) { struct file *fp = file->private_data; if (!fp) return -ENOENT; filp_close(fp, current->files); file->private_data = NULL; } out: return 0; }
static int autofs4_dir_open(struct inode *inode, struct file *file) { struct dentry *dentry = file->f_dentry; struct vfsmount *mnt = file->f_vfsmnt; struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); int status; DPRINTK("file=%p dentry=%p %.*s", file, dentry, dentry->d_name.len, dentry->d_name.name); if (autofs4_oz_mode(sbi)) goto out; if (autofs4_ispending(dentry)) { DPRINTK("dentry busy"); return -EBUSY; } if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) { struct nameidata nd; int empty; /* In case there are stale directory dentrys from a failed mount */ spin_lock(&dcache_lock); empty = list_empty(&dentry->d_subdirs); spin_unlock(&dcache_lock); if (!empty) d_invalidate(dentry); nd.flags = LOOKUP_DIRECTORY; status = (dentry->d_op->d_revalidate)(dentry, &nd); if (!status) return -ENOENT; } if (d_mountpoint(dentry)) { struct file *fp = NULL; struct vfsmount *fp_mnt = mntget(mnt); struct dentry *fp_dentry = dget(dentry); while (follow_down(&fp_mnt, &fp_dentry) && d_mountpoint(fp_dentry)); fp = dentry_open(fp_dentry, fp_mnt, file->f_flags); status = PTR_ERR(fp); if (IS_ERR(fp)) { file->private_data = NULL; return status; } file->private_data = fp; } out: return 0; }
/* * Revalidate is called on every cache lookup. Some of those * cache lookups may actually happen while the dentry is not * yet completely filled in, and revalidate has to delay such * lookups.. */ static int autofs4_root_revalidate(struct dentry * dentry, int flags) { struct inode * dir = dentry->d_parent->d_inode; struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); struct autofs_info *ino; int oz_mode = autofs4_oz_mode(sbi); /* Pending dentry */ if (autofs4_ispending(dentry)) { if (autofs4_oz_mode(sbi)) return 1; else return try_to_fill_dentry(dentry, dir->i_sb, sbi); } /* Negative dentry.. invalidate if "old" */ if (dentry->d_inode == NULL) return (dentry->d_time - jiffies <= AUTOFS_NEGATIVE_TIMEOUT); ino = autofs4_dentry_ino(dentry); /* Check for a non-mountpoint directory with no contents */ spin_lock(&dcache_lock); if (S_ISDIR(dentry->d_inode->i_mode) && !d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) { DPRINTK(("autofs_root_revalidate: dentry=%p %.*s, emptydir\n", dentry, dentry->d_name.len, dentry->d_name.name)); spin_unlock(&dcache_lock); if (oz_mode) return 1; else return try_to_fill_dentry(dentry, dir->i_sb, sbi); } spin_unlock(&dcache_lock); /* Update the usage list */ if (!oz_mode) autofs4_update_usage(dentry); return 1; }