]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/cifs/inode.c
[CIFS] factoring out common code in get_inode_info functions
[linux-2.6-omap-h63xx.git] / fs / cifs / inode.c
index 7d907e84e0327d01d531ef9fa142670de04b1ccb..e7cd392a796a9ba06f081659772dde592e2c13b0 100644 (file)
 #include "cifs_debug.h"
 #include "cifs_fs_sb.h"
 
+
+static void cifs_set_ops(struct inode *inode)
+{
+       struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
+
+       switch (inode->i_mode & S_IFMT) {
+       case S_IFREG:
+               inode->i_op = &cifs_file_inode_ops;
+               if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
+                       if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
+                               inode->i_fop = &cifs_file_direct_nobrl_ops;
+                       else
+                               inode->i_fop = &cifs_file_direct_ops;
+               } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
+                       inode->i_fop = &cifs_file_nobrl_ops;
+               else { /* not direct, send byte range locks */
+                       inode->i_fop = &cifs_file_ops;
+               }
+
+
+               /* check if server can support readpages */
+               if (cifs_sb->tcon->ses->server->maxBuf <
+                               PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
+                       inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
+               else
+                       inode->i_data.a_ops = &cifs_addr_ops;
+               break;
+       case S_IFDIR:
+               inode->i_op = &cifs_dir_inode_ops;
+               inode->i_fop = &cifs_dir_ops;
+               break;
+       case S_IFLNK:
+               inode->i_op = &cifs_symlink_inode_ops;
+               break;
+       default:
+               init_special_inode(inode, inode->i_mode, inode->i_rdev);
+               break;
+       }
+}
+
 int cifs_get_inode_info_unix(struct inode **pinode,
        const unsigned char *search_path, struct super_block *sb, int xid)
 {
@@ -54,9 +94,9 @@ int cifs_get_inode_info_unix(struct inode **pinode,
                                            MAX_TREE_SIZE + 1) +
                                    strnlen(search_path, MAX_PATHCONF) + 1,
                                    GFP_KERNEL);
-                       if (tmp_path == NULL) {
+                       if (tmp_path == NULL)
                                return -ENOMEM;
-                       }
+
                        /* have to skip first of the double backslash of
                           UNC name */
                        strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
@@ -178,39 +218,8 @@ int cifs_get_inode_info_unix(struct inode **pinode,
                cFYI(1, ("Size %ld and blocks %llu",
                        (unsigned long) inode->i_size,
                        (unsigned long long)inode->i_blocks));
-               if (S_ISREG(inode->i_mode)) {
-                       cFYI(1, ("File inode"));
-                       inode->i_op = &cifs_file_inode_ops;
-                       if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
-                               if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
-                                       inode->i_fop =
-                                               &cifs_file_direct_nobrl_ops;
-                               else
-                                       inode->i_fop = &cifs_file_direct_ops;
-                       } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
-                               inode->i_fop = &cifs_file_nobrl_ops;
-                       else /* not direct, send byte range locks */
-                               inode->i_fop = &cifs_file_ops;
-
-                       /* check if server can support readpages */
-                       if (pTcon->ses->server->maxBuf <
-                           PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
-                               inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
-                       else
-                               inode->i_data.a_ops = &cifs_addr_ops;
-               } else if (S_ISDIR(inode->i_mode)) {
-                       cFYI(1, ("Directory inode"));
-                       inode->i_op = &cifs_dir_inode_ops;
-                       inode->i_fop = &cifs_dir_ops;
-               } else if (S_ISLNK(inode->i_mode)) {
-                       cFYI(1, ("Symbolic Link inode"));
-                       inode->i_op = &cifs_symlink_inode_ops;
-               /* tmp_inode->i_fop = */ /* do not need to set to anything */
-               } else {
-                       cFYI(1, ("Init special inode"));
-                       init_special_inode(inode, inode->i_mode,
-                                          inode->i_rdev);
-               }
+
+               cifs_set_ops(inode);
        }
        return rc;
 }
@@ -490,9 +499,9 @@ int cifs_get_inode_info(struct inode **pinode,
                        if (decode_sfu_inode(inode,
                                         le64_to_cpu(pfindData->EndOfFile),
                                         search_path,
-                                        cifs_sb, xid)) {
+                                        cifs_sb, xid))
                                cFYI(1, ("Unrecognized sfu inode type"));
-                       }
+
                        cFYI(1, ("sfu mode 0%o", inode->i_mode));
                } else {
                        inode->i_mode |= S_IFREG;
@@ -511,7 +520,8 @@ int cifs_get_inode_info(struct inode **pinode,
                }
 
                spin_lock(&inode->i_lock);
-               if (is_size_safe_to_change(cifsInfo, le64_to_cpu(pfindData->EndOfFile))) {
+               if (is_size_safe_to_change(cifsInfo,
+                                          le64_to_cpu(pfindData->EndOfFile))) {
                        /* can not safely shrink the file size here if the
                           client is writing to it due to potential races */
                        i_size_write(inode, le64_to_cpu(pfindData->EndOfFile));
@@ -545,36 +555,7 @@ int cifs_get_inode_info(struct inode **pinode,
                        atomic_set(&cifsInfo->inUse, 1);
                }
 
-               if (S_ISREG(inode->i_mode)) {
-                       cFYI(1, ("File inode"));
-                       inode->i_op = &cifs_file_inode_ops;
-                       if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
-                               if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
-                                       inode->i_fop =
-                                               &cifs_file_direct_nobrl_ops;
-                               else
-                                       inode->i_fop = &cifs_file_direct_ops;
-                       } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
-                               inode->i_fop = &cifs_file_nobrl_ops;
-                       else /* not direct, send byte range locks */
-                               inode->i_fop = &cifs_file_ops;
-
-                       if (pTcon->ses->server->maxBuf <
-                            PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
-                               inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
-                       else
-                               inode->i_data.a_ops = &cifs_addr_ops;
-               } else if (S_ISDIR(inode->i_mode)) {
-                       cFYI(1, ("Directory inode"));
-                       inode->i_op = &cifs_dir_inode_ops;
-                       inode->i_fop = &cifs_dir_ops;
-               } else if (S_ISLNK(inode->i_mode)) {
-                       cFYI(1, ("Symbolic Link inode"));
-                       inode->i_op = &cifs_symlink_inode_ops;
-               } else {
-                       init_special_inode(inode, inode->i_mode,
-                                          inode->i_rdev);
-               }
+               cifs_set_ops(inode);
        }
        kfree(buf);
        return rc;
@@ -836,9 +817,7 @@ static void posix_fill_in_inode(struct inode *tmp_inode,
                cFYI(1, ("unknown inode type %d", type));
        }
 
-#ifdef CONFIG_CIFS_DEBUG2
-       cFYI(1, ("object type: %d", type));
-#endif
+       cFYI(DBG2, ("object type: %d", type));
        tmp_inode->i_uid = le64_to_cpu(pData->Uid);
        tmp_inode->i_gid = le64_to_cpu(pData->Gid);
        tmp_inode->i_nlink = le64_to_cpu(pData->Nlinks);
@@ -931,7 +910,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
                (CIFS_UNIX_POSIX_PATH_OPS_CAP &
                        le64_to_cpu(pTcon->fsUnixInfo.Capability))) {
                u32 oplock = 0;
-               FILE_UNIX_BASIC_INFO * pInfo =
+               FILE_UNIX_BASIC_INFO *pInfo =
                        kzalloc(sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL);
                if (pInfo == NULL) {
                        rc = -ENOMEM;
@@ -1197,9 +1176,8 @@ int cifs_rename(struct inode *source_inode, struct dentry *source_direntry,
                } /* if we can not get memory just leave rc as EEXIST */
        }
 
-       if (rc) {
+       if (rc)
                cFYI(1, ("rename rc %d", rc));
-       }
 
        if ((rc == -EIO) || (rc == -EEXIST)) {
                int oplock = FALSE;
@@ -1233,7 +1211,7 @@ cifs_rename_exit:
 int cifs_revalidate(struct dentry *direntry)
 {
        int xid;
-       int rc = 0;
+       int rc = 0, wbrc = 0;
        char *full_path;
        struct cifs_sb_info *cifs_sb;
        struct cifsInodeInfo *cifsInode;
@@ -1333,7 +1311,9 @@ int cifs_revalidate(struct dentry *direntry)
        if (direntry->d_inode->i_mapping) {
                /* do we need to lock inode until after invalidate completes
                   below? */
-               filemap_fdatawrite(direntry->d_inode->i_mapping);
+               wbrc = filemap_fdatawrite(direntry->d_inode->i_mapping);
+               if (wbrc)
+                       CIFS_I(direntry->d_inode)->write_behind_rc = wbrc;
        }
        if (invalidate_inode) {
        /* shrink_dcache not necessary now that cifs dentry ops
@@ -1342,7 +1322,9 @@ int cifs_revalidate(struct dentry *direntry)
                        shrink_dcache_parent(direntry); */
                if (S_ISREG(direntry->d_inode->i_mode)) {
                        if (direntry->d_inode->i_mapping)
-                               filemap_fdatawait(direntry->d_inode->i_mapping);
+                               wbrc = filemap_fdatawait(direntry->d_inode->i_mapping);
+                               if (wbrc)
+                                       CIFS_I(direntry->d_inode)->write_behind_rc = wbrc;
                        /* may eventually have to do this for open files too */
                        if (list_empty(&(cifsInode->openFileList))) {
                                /* changed on server - flush read ahead pages */
@@ -1381,7 +1363,7 @@ static int cifs_truncate_page(struct address_space *mapping, loff_t from)
        if (!page)
                return -ENOMEM;
 
-       zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0);
+       zero_user_segment(page, offset, PAGE_CACHE_SIZE);
        unlock_page(page);
        page_cache_release(page);
        return rc;
@@ -1485,10 +1467,20 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
 
        /* BB check if we need to refresh inode from server now ? BB */
 
-       /* need to flush data before changing file size on server */
-       filemap_write_and_wait(direntry->d_inode->i_mapping);
-
        if (attrs->ia_valid & ATTR_SIZE) {
+               /*
+                  Flush data before changing file size on server. If the
+                  flush returns error, store it to report later and continue.
+                  BB: This should be smarter. Why bother flushing pages that
+                  will be truncated anyway? Also, should we error out here if
+                  the flush returns error?
+                */
+               rc = filemap_write_and_wait(direntry->d_inode->i_mapping);
+               if (rc != 0) {
+                       CIFS_I(direntry->d_inode)->write_behind_rc = rc;
+                       rc = 0;
+               }
+
                /* To avoid spurious oplock breaks from server, in the case of
                   inodes that we already have open, avoid doing path based
                   setting of file size if we can do it by handle.
@@ -1593,7 +1585,14 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
                                                CIFS_MOUNT_MAP_SPECIAL_CHR);
        else if (attrs->ia_valid & ATTR_MODE) {
                rc = 0;
-               if ((mode & S_IWUGO) == 0) /* not writeable */ {
+#ifdef CONFIG_CIFS_EXPERIMENTAL
+               if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
+                       rc = mode_to_acl(direntry->d_inode, full_path, mode);
+               else if ((mode & S_IWUGO) == 0) {
+#else
+               if ((mode & S_IWUGO) == 0) {
+#endif
+                       /* not writeable */
                        if ((cifsInode->cifsAttrs & ATTR_READONLY) == 0) {
                                set_dosattr = TRUE;
                                time_buf.Attributes =
@@ -1612,10 +1611,10 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
                        if (time_buf.Attributes == 0)
                                time_buf.Attributes |= cpu_to_le32(ATTR_NORMAL);
                }
-               /* BB to be implemented -
-                  via Windows security descriptors or streams */
-               /* CIFSSMBWinSetPerms(xid, pTcon, full_path, mode, uid, gid,
-                                     cifs_sb->local_nls); */
+#ifdef CONFIG_CIFS_EXPERIMENTAL
+               if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
+                       mode_to_acl(direntry->d_inode, full_path, mode);
+#endif
        }
 
        if (attrs->ia_valid & ATTR_ATIME) {