]> err.no Git - linux-2.6/blobdiff - fs/ocfs2/file.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/cpufreq
[linux-2.6] / fs / ocfs2 / file.c
index b32cdb3bf7c5abe7eeb5f9f9ac0f93049a52a258..f2cd3bf9efb2f6b2dff8b44c44592355e2b44a6e 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/uio.h>
 #include <linux/sched.h>
 #include <linux/pipe_fs_i.h>
+#include <linux/mount.h>
 
 #define MLOG_MASK_PREFIX ML_INODE
 #include <cluster/masklog.h>
@@ -67,7 +68,7 @@ static int ocfs2_file_open(struct inode *inode, struct file *file)
        struct ocfs2_inode_info *oi = OCFS2_I(inode);
 
        mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file,
-                  file->f_dentry->d_name.len, file->f_dentry->d_name.name);
+                  file->f_path.dentry->d_name.len, file->f_path.dentry->d_name.name);
 
        spin_lock(&oi->ip_lock);
 
@@ -97,8 +98,8 @@ static int ocfs2_file_release(struct inode *inode, struct file *file)
        struct ocfs2_inode_info *oi = OCFS2_I(inode);
 
        mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file,
-                      file->f_dentry->d_name.len,
-                      file->f_dentry->d_name.name);
+                      file->f_path.dentry->d_name.len,
+                      file->f_path.dentry->d_name.name);
 
        spin_lock(&oi->ip_lock);
        if (!--oi->ip_open_count)
@@ -135,6 +136,76 @@ bail:
        return (err < 0) ? -EIO : 0;
 }
 
+int ocfs2_should_update_atime(struct inode *inode,
+                             struct vfsmount *vfsmnt)
+{
+       struct timespec now;
+       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+
+       if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
+               return 0;
+
+       if ((inode->i_flags & S_NOATIME) ||
+           ((inode->i_sb->s_flags & MS_NODIRATIME) && S_ISDIR(inode->i_mode)))
+               return 0;
+
+       /*
+        * We can be called with no vfsmnt structure - NFSD will
+        * sometimes do this.
+        *
+        * Note that our action here is different than touch_atime() -
+        * if we can't tell whether this is a noatime mount, then we
+        * don't know whether to trust the value of s_atime_quantum.
+        */
+       if (vfsmnt == NULL)
+               return 0;
+
+       if ((vfsmnt->mnt_flags & MNT_NOATIME) ||
+           ((vfsmnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
+               return 0;
+
+       if (vfsmnt->mnt_flags & MNT_RELATIME) {
+               if ((timespec_compare(&inode->i_atime, &inode->i_mtime) <= 0) ||
+                   (timespec_compare(&inode->i_atime, &inode->i_ctime) <= 0))
+                       return 1;
+
+               return 0;
+       }
+
+       now = CURRENT_TIME;
+       if ((now.tv_sec - inode->i_atime.tv_sec <= osb->s_atime_quantum))
+               return 0;
+       else
+               return 1;
+}
+
+int ocfs2_update_inode_atime(struct inode *inode,
+                            struct buffer_head *bh)
+{
+       int ret;
+       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+       handle_t *handle;
+
+       mlog_entry_void();
+
+       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
+       if (handle == NULL) {
+               ret = -ENOMEM;
+               mlog_errno(ret);
+               goto out;
+       }
+
+       inode->i_atime = CURRENT_TIME;
+       ret = ocfs2_mark_inode_dirty(handle, inode, bh);
+       if (ret < 0)
+               mlog_errno(ret);
+
+       ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
+out:
+       mlog_exit(ret);
+       return ret;
+}
+
 int ocfs2_set_inode_size(handle_t *handle,
                         struct inode *inode,
                         struct buffer_head *fe_bh,
@@ -893,6 +964,26 @@ bail:
        return err;
 }
 
+int ocfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
+{
+       int ret;
+
+       mlog_entry_void();
+
+       ret = ocfs2_meta_lock(inode, NULL, 0);
+       if (ret) {
+               mlog_errno(ret);
+               goto out;
+       }
+
+       ret = generic_permission(inode, mask, NULL);
+
+       ocfs2_meta_unlock(inode, 0);
+out:
+       mlog_exit(ret);
+       return ret;
+}
+
 static int ocfs2_write_remove_suid(struct inode *inode)
 {
        int ret;
@@ -1057,13 +1148,13 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
 {
        int ret, rw_level, have_alloc_sem = 0;
        struct file *filp = iocb->ki_filp;
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        int appending = filp->f_flags & O_APPEND ? 1 : 0;
 
        mlog_entry("(0x%p, %u, '%.*s')\n", filp,
                   (unsigned int)nr_segs,
-                  filp->f_dentry->d_name.len,
-                  filp->f_dentry->d_name.name);
+                  filp->f_path.dentry->d_name.len,
+                  filp->f_path.dentry->d_name.name);
 
        /* happy write of zero bytes */
        if (iocb->ki_left == 0)
@@ -1085,7 +1176,7 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
                goto out;
        }
 
-       ret = ocfs2_prepare_inode_for_write(filp->f_dentry, &iocb->ki_pos,
+       ret = ocfs2_prepare_inode_for_write(filp->f_path.dentry, &iocb->ki_pos,
                                            iocb->ki_left, appending);
        if (ret < 0) {
                mlog_errno(ret);
@@ -1133,12 +1224,12 @@ static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,
                                       unsigned int flags)
 {
        int ret;
-       struct inode *inode = out->f_dentry->d_inode;
+       struct inode *inode = out->f_path.dentry->d_inode;
 
        mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", out, pipe,
                   (unsigned int)len,
-                  out->f_dentry->d_name.len,
-                  out->f_dentry->d_name.name);
+                  out->f_path.dentry->d_name.len,
+                  out->f_path.dentry->d_name.name);
 
        inode_double_lock(inode, pipe->inode);
 
@@ -1148,7 +1239,7 @@ static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,
                goto out;
        }
 
-       ret = ocfs2_prepare_inode_for_write(out->f_dentry, ppos, len, 0);
+       ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, ppos, len, 0);
        if (ret < 0) {
                mlog_errno(ret);
                goto out_unlock;
@@ -1173,12 +1264,12 @@ static ssize_t ocfs2_file_splice_read(struct file *in,
                                      unsigned int flags)
 {
        int ret = 0;
-       struct inode *inode = in->f_dentry->d_inode;
+       struct inode *inode = in->f_path.dentry->d_inode;
 
        mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", in, pipe,
                   (unsigned int)len,
-                  in->f_dentry->d_name.len,
-                  in->f_dentry->d_name.name);
+                  in->f_path.dentry->d_name.len,
+                  in->f_path.dentry->d_name.name);
 
        /*
         * See the comment in ocfs2_file_aio_read()
@@ -1202,14 +1293,14 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
                                   unsigned long nr_segs,
                                   loff_t pos)
 {
-       int ret = 0, rw_level = -1, have_alloc_sem = 0;
+       int ret = 0, rw_level = -1, have_alloc_sem = 0, lock_level = 0;
        struct file *filp = iocb->ki_filp;
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->f_path.dentry->d_inode;
 
        mlog_entry("(0x%p, %u, '%.*s')\n", filp,
                   (unsigned int)nr_segs,
-                  filp->f_dentry->d_name.len,
-                  filp->f_dentry->d_name.name);
+                  filp->f_path.dentry->d_name.len,
+                  filp->f_path.dentry->d_name.name);
 
        if (!inode) {
                ret = -EINVAL;
@@ -1244,12 +1335,12 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
         * like i_size. This allows the checks down below
         * generic_file_aio_read() a chance of actually working. 
         */
-       ret = ocfs2_meta_lock(inode, NULL, 0);
+       ret = ocfs2_meta_lock_atime(inode, filp->f_vfsmnt, &lock_level);
        if (ret < 0) {
                mlog_errno(ret);
                goto bail;
        }
-       ocfs2_meta_unlock(inode, 0);
+       ocfs2_meta_unlock(inode, lock_level);
 
        ret = generic_file_aio_read(iocb, iov, nr_segs, iocb->ki_pos);
        if (ret == -EINVAL)
@@ -1274,14 +1365,16 @@ bail:
        return ret;
 }
 
-struct inode_operations ocfs2_file_iops = {
+const struct inode_operations ocfs2_file_iops = {
        .setattr        = ocfs2_setattr,
        .getattr        = ocfs2_getattr,
+       .permission     = ocfs2_permission,
 };
 
-struct inode_operations ocfs2_special_file_iops = {
+const struct inode_operations ocfs2_special_file_iops = {
        .setattr        = ocfs2_setattr,
        .getattr        = ocfs2_getattr,
+       .permission     = ocfs2_permission,
 };
 
 const struct file_operations ocfs2_fops = {