Merge branch 'upstream-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/linvil...
[pandora-kernel.git] / fs / nfs / inode.c
index 63e4702..93d046c 100644 (file)
@@ -65,13 +65,18 @@ nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
 
 int nfs_write_inode(struct inode *inode, int sync)
 {
-       int flags = sync ? FLUSH_SYNC : 0;
        int ret;
 
-       ret = nfs_commit_inode(inode, flags);
-       if (ret < 0)
-               return ret;
-       return 0;
+       if (sync) {
+               ret = filemap_fdatawait(inode->i_mapping);
+               if (ret == 0)
+                       ret = nfs_commit_inode(inode, FLUSH_SYNC);
+       } else
+               ret = nfs_commit_inode(inode, 0);
+       if (ret >= 0)
+               return 0;
+       __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
+       return ret;
 }
 
 void nfs_clear_inode(struct inode *inode)
@@ -235,6 +240,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
 
        if (inode->i_state & I_NEW) {
                struct nfs_inode *nfsi = NFS_I(inode);
+               unsigned long now = jiffies;
 
                /* We set i_ino for the few things that still rely on it,
                 * such as stat(2) */
@@ -271,7 +277,8 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                        init_special_inode(inode, inode->i_mode, fattr->rdev);
 
                nfsi->read_cache_jiffies = fattr->time_start;
-               nfsi->last_updated = jiffies;
+               nfsi->last_updated = now;
+               nfsi->cache_change_attribute = now;
                inode->i_atime = fattr->atime;
                inode->i_mtime = fattr->mtime;
                inode->i_ctime = fattr->ctime;
@@ -290,7 +297,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                        inode->i_blocks = fattr->du.nfs2.blocks;
                }
                nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
-               nfsi->attrtimeo_timestamp = jiffies;
+               nfsi->attrtimeo_timestamp = now;
                memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
                nfsi->access_cache = RB_ROOT;
 
@@ -422,7 +429,8 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
        int err;
 
        /* Flush out writes to the server in order to update c/mtime */
-       nfs_sync_mapping_range(inode->i_mapping, 0, 0, FLUSH_NOCOMMIT);
+       if (S_ISREG(inode->i_mode))
+               nfs_sync_mapping_range(inode->i_mapping, 0, 0, FLUSH_NOCOMMIT);
 
        /*
         * We may force a getattr if the user cares about atime.
@@ -665,49 +673,86 @@ int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        return __nfs_revalidate_inode(server, inode);
 }
 
+static int nfs_invalidate_mapping_nolock(struct inode *inode, struct address_space *mapping)
+{
+       struct nfs_inode *nfsi = NFS_I(inode);
+       
+       if (mapping->nrpages != 0) {
+               int ret = invalidate_inode_pages2(mapping);
+               if (ret < 0)
+                       return ret;
+       }
+       spin_lock(&inode->i_lock);
+       nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
+       if (S_ISDIR(inode->i_mode)) {
+               memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
+               /* This ensures we revalidate child dentries */
+               nfsi->cache_change_attribute = jiffies;
+       }
+       spin_unlock(&inode->i_lock);
+       nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
+       dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n",
+                       inode->i_sb->s_id, (long long)NFS_FILEID(inode));
+       return 0;
+}
+
+static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
+{
+       int ret = 0;
+
+       mutex_lock(&inode->i_mutex);
+       if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_DATA) {
+               ret = nfs_sync_mapping(mapping);
+               if (ret == 0)
+                       ret = nfs_invalidate_mapping_nolock(inode, mapping);
+       }
+       mutex_unlock(&inode->i_mutex);
+       return ret;
+}
+
 /**
- * nfs_revalidate_mapping - Revalidate the pagecache
+ * nfs_revalidate_mapping_nolock - Revalidate the pagecache
  * @inode - pointer to host inode
  * @mapping - pointer to mapping
  */
-int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
+int nfs_revalidate_mapping_nolock(struct inode *inode, struct address_space *mapping)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
        int ret = 0;
 
-       if (NFS_STALE(inode))
-               ret = -ESTALE;
        if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
-                       || nfs_attribute_timeout(inode))
+                       || nfs_attribute_timeout(inode) || NFS_STALE(inode)) {
                ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
-       if (ret < 0)
-               goto out;
+               if (ret < 0)
+                       goto out;
+       }
+       if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
+               ret = nfs_invalidate_mapping_nolock(inode, mapping);
+out:
+       return ret;
+}
 
-       if (nfsi->cache_validity & NFS_INO_INVALID_DATA) {
-               if (mapping->nrpages != 0) {
-                       if (S_ISREG(inode->i_mode)) {
-                               ret = nfs_sync_mapping(mapping);
-                               if (ret < 0)
-                                       goto out;
-                       }
-                       ret = invalidate_inode_pages2(mapping);
-                       if (ret < 0)
-                               goto out;
-               }
-               spin_lock(&inode->i_lock);
-               nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
-               if (S_ISDIR(inode->i_mode)) {
-                       memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
-                       /* This ensures we revalidate child dentries */
-                       nfsi->cache_change_attribute = jiffies;
-               }
-               spin_unlock(&inode->i_lock);
+/**
+ * nfs_revalidate_mapping - Revalidate the pagecache
+ * @inode - pointer to host inode
+ * @mapping - pointer to mapping
+ *
+ * This version of the function will take the inode->i_mutex and attempt to
+ * flush out all dirty data if it needs to invalidate the page cache.
+ */
+int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
+{
+       struct nfs_inode *nfsi = NFS_I(inode);
+       int ret = 0;
 
-               nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
-               dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n",
-                               inode->i_sb->s_id,
-                               (long long)NFS_FILEID(inode));
+       if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
+                       || nfs_attribute_timeout(inode) || NFS_STALE(inode)) {
+               ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
+               if (ret < 0)
+                       goto out;
        }
+       if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
+               ret = nfs_invalidate_mapping(inode, mapping);
 out:
        return ret;
 }
@@ -746,20 +791,21 @@ void nfs_end_data_update(struct inode *inode)
 static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
+       unsigned long now = jiffies;
 
        /* If we have atomic WCC data, we may update some attributes */
        if ((fattr->valid & NFS_ATTR_WCC) != 0) {
                if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) {
                        memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
-                       nfsi->cache_change_attribute = jiffies;
+                       nfsi->cache_change_attribute = now;
                }
                if (timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) {
                        memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
-                       nfsi->cache_change_attribute = jiffies;
+                       nfsi->cache_change_attribute = now;
                }
                if (inode->i_size == fattr->pre_size && nfsi->npages == 0) {
                        inode->i_size = fattr->size;
-                       nfsi->cache_change_attribute = jiffies;
+                       nfsi->cache_change_attribute = now;
                }
        }
 }
@@ -897,6 +943,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
        struct nfs_inode *nfsi = NFS_I(inode);
        loff_t cur_isize, new_isize;
        unsigned int    invalid = 0;
+       unsigned long now = jiffies;
        int data_stable;
 
        dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
@@ -922,7 +969,11 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
         * Update the read time so we don't revalidate too often.
         */
        nfsi->read_cache_jiffies = fattr->time_start;
-       nfsi->last_updated = jiffies;
+       nfsi->last_updated = now;
+
+       /* Fix a wraparound issue with nfsi->cache_change_attribute */
+       if (time_before(now, nfsi->cache_change_attribute))
+               nfsi->cache_change_attribute = now - 600*HZ;
 
        /* Are we racing with known updates of the metadata on the server? */
        data_stable = nfs_verify_change_attribute(inode, fattr->time_start);
@@ -948,7 +999,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                        inode->i_size = new_isize;
                        invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
                }
-               nfsi->cache_change_attribute = jiffies;
+               nfsi->cache_change_attribute = now;
                dprintk("NFS: isize change on server for file %s/%ld\n",
                                inode->i_sb->s_id, inode->i_ino);
        }
@@ -959,14 +1010,14 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                dprintk("NFS: mtime change on server for file %s/%ld\n",
                                inode->i_sb->s_id, inode->i_ino);
                invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
-               nfsi->cache_change_attribute = jiffies;
+               nfsi->cache_change_attribute = now;
        }
 
        /* If ctime has changed we should definitely clear access+acl caches */
        if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) {
                invalid |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
                memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
-               nfsi->cache_change_attribute = jiffies;
+               nfsi->cache_change_attribute = now;
        }
        memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
 
@@ -995,18 +1046,18 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                                inode->i_sb->s_id, inode->i_ino);
                nfsi->change_attr = fattr->change_attr;
                invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
-               nfsi->cache_change_attribute = jiffies;
+               nfsi->cache_change_attribute = now;
        }
 
        /* Update attrtimeo value if we're out of the unstable period */
        if (invalid & NFS_INO_INVALID_ATTR) {
                nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
                nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
-               nfsi->attrtimeo_timestamp = jiffies;
-       } else if (time_after(jiffies, nfsi->attrtimeo_timestamp+nfsi->attrtimeo)) {
+               nfsi->attrtimeo_timestamp = now;
+       } else if (time_after(now, nfsi->attrtimeo_timestamp+nfsi->attrtimeo)) {
                if ((nfsi->attrtimeo <<= 1) > NFS_MAXATTRTIMEO(inode))
                        nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
-               nfsi->attrtimeo_timestamp = jiffies;
+               nfsi->attrtimeo_timestamp = now;
        }
        /* Don't invalidate the data if we were to blame */
        if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
@@ -1085,7 +1136,6 @@ struct inode *nfs_alloc_inode(struct super_block *sb)
                return NULL;
        nfsi->flags = 0UL;
        nfsi->cache_validity = 0UL;
-       nfsi->cache_change_attribute = jiffies;
 #ifdef CONFIG_NFS_V3_ACL
        nfsi->acl_access = ERR_PTR(-EAGAIN);
        nfsi->acl_default = ERR_PTR(-EAGAIN);