]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - fs/cifs/readdir.c
Merge tag 'v2.6.37' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[mv-sheeva.git] / fs / cifs / readdir.c
index d5e591fab4753bf48bde4e9d7883f1051d2dc280..a73eb9f4bdaf3608c2bf6f5dc124b5fabdd4445b 100644 (file)
@@ -102,7 +102,7 @@ cifs_readdir_lookup(struct dentry *parent, struct qstr *name,
                return NULL;
        }
 
-       if (CIFS_SB(sb)->tcon->nocase)
+       if (cifs_sb_master_tcon(CIFS_SB(sb))->nocase)
                dentry->d_op = &cifs_ci_dentry_ops;
        else
                dentry->d_op = &cifs_dentry_ops;
@@ -171,7 +171,7 @@ static void
 cifs_std_info_to_fattr(struct cifs_fattr *fattr, FIND_FILE_STANDARD_INFO *info,
                       struct cifs_sb_info *cifs_sb)
 {
-       int offset = cifs_sb->tcon->ses->server->timeAdj;
+       int offset = cifs_sb_master_tcon(cifs_sb)->ses->server->timeAdj;
 
        memset(fattr, 0, sizeof(*fattr));
        fattr->cf_atime = cnvrtDosUnixTm(info->LastAccessDate,
@@ -199,7 +199,7 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb,
        int len;
        int oplock = 0;
        int rc;
-       struct cifsTconInfo *ptcon = cifs_sb->tcon;
+       struct cifsTconInfo *ptcon = cifs_sb_tcon(cifs_sb);
        char *tmpbuffer;
 
        rc = CIFSSMBOpen(xid, ptcon, full_path, FILE_OPEN, GENERIC_READ,
@@ -223,34 +223,38 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb,
 static int initiate_cifs_search(const int xid, struct file *file)
 {
        int rc = 0;
-       char *full_path;
+       char *full_path = NULL;
        struct cifsFileInfo *cifsFile;
-       struct cifs_sb_info *cifs_sb;
+       struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
+       struct tcon_link *tlink = NULL;
        struct cifsTconInfo *pTcon;
 
        if (file->private_data == NULL) {
-               file->private_data =
-                       kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
+               tlink = cifs_sb_tlink(cifs_sb);
+               if (IS_ERR(tlink))
+                       return PTR_ERR(tlink);
+
+               cifsFile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
+               if (cifsFile == NULL) {
+                       rc = -ENOMEM;
+                       goto error_exit;
+               }
+               file->private_data = cifsFile;
+               cifsFile->tlink = cifs_get_tlink(tlink);
+               pTcon = tlink_tcon(tlink);
+       } else {
+               cifsFile = file->private_data;
+               pTcon = tlink_tcon(cifsFile->tlink);
        }
 
-       if (file->private_data == NULL)
-               return -ENOMEM;
-       cifsFile = file->private_data;
        cifsFile->invalidHandle = true;
        cifsFile->srch_inf.endOfSearch = false;
 
-       cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
-       if (cifs_sb == NULL)
-               return -EINVAL;
-
-       pTcon = cifs_sb->tcon;
-       if (pTcon == NULL)
-               return -EINVAL;
-
        full_path = build_path_from_dentry(file->f_path.dentry);
-
-       if (full_path == NULL)
-               return -ENOMEM;
+       if (full_path == NULL) {
+               rc = -ENOMEM;
+               goto error_exit;
+       }
 
        cFYI(1, "Full path: %s start at: %lld", full_path, file->f_pos);
 
@@ -283,7 +287,9 @@ ffirst_retry:
                cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM;
                goto ffirst_retry;
        }
+error_exit:
        kfree(full_path);
+       cifs_put_tlink(tlink);
        return rc;
 }
 
@@ -525,14 +531,14 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
           (index_to_find < first_entry_in_buffer)) {
                /* close and restart search */
                cFYI(1, "search backing up - close and restart search");
-               write_lock(&GlobalSMBSeslock);
+               spin_lock(&cifs_file_list_lock);
                if (!cifsFile->srch_inf.endOfSearch &&
                    !cifsFile->invalidHandle) {
                        cifsFile->invalidHandle = true;
-                       write_unlock(&GlobalSMBSeslock);
+                       spin_unlock(&cifs_file_list_lock);
                        CIFSFindClose(xid, pTcon, cifsFile->netfid);
                } else
-                       write_unlock(&GlobalSMBSeslock);
+                       spin_unlock(&cifs_file_list_lock);
                if (cifsFile->srch_inf.ntwrk_buf_start) {
                        cFYI(1, "freeing SMB ff cache buf on search rewind");
                        if (cifsFile->srch_inf.smallBuf)
@@ -738,24 +744,21 @@ static int cifs_filldir(char *pfindEntry, struct file *file, filldir_t filldir,
                cifs_autodisable_serverino(cifs_sb);
        }
 
+       if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) &&
+           CIFSCouldBeMFSymlink(&fattr))
+               /*
+                * trying to get the type and mode can be slow,
+                * so just call those regular files for now, and mark
+                * for reval
+                */
+               fattr.cf_flags |= CIFS_FATTR_NEED_REVAL;
+
        ino = cifs_uniqueid_to_ino_t(fattr.cf_uniqueid);
        tmp_dentry = cifs_readdir_lookup(file->f_dentry, &qstring, &fattr);
 
        rc = filldir(direntry, qstring.name, qstring.len, file->f_pos,
                     ino, fattr.cf_dtype);
 
-       /*
-        * we can not return filldir errors to the caller since they are
-        * "normal" when the stat blocksize is too small - we return remapped
-        * error instead
-        *
-        * FIXME: This looks bogus. filldir returns -EOVERFLOW in the above
-        * case already. Why should we be clobbering other errors from it?
-        */
-       if (rc) {
-               cFYI(1, "filldir rc = %d", rc);
-               rc = -EOVERFLOW;
-       }
        dput(tmp_dentry);
        return rc;
 }
@@ -777,9 +780,17 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
        xid = GetXid();
 
        cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
-       pTcon = cifs_sb->tcon;
-       if (pTcon == NULL)
-               return -EINVAL;
+
+       /*
+        * Ensure FindFirst doesn't fail before doing filldir() for '.' and
+        * '..'. Otherwise we won't be able to notify VFS in case of failure.
+        */
+       if (file->private_data == NULL) {
+               rc = initiate_cifs_search(xid, file);
+               cFYI(1, "initiate cifs search rc %d", rc);
+               if (rc)
+                       goto rddir2_exit;
+       }
 
        switch ((int) file->f_pos) {
        case 0:
@@ -804,14 +815,6 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
                        if it before then restart search
                        if after then keep searching till find it */
 
-               if (file->private_data == NULL) {
-                       rc = initiate_cifs_search(xid, file);
-                       cFYI(1, "initiate cifs search rc %d", rc);
-                       if (rc) {
-                               FreeXid(xid);
-                               return rc;
-                       }
-               }
                if (file->private_data == NULL) {
                        rc = -EINVAL;
                        FreeXid(xid);
@@ -829,6 +832,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
                        CIFSFindClose(xid, pTcon, cifsFile->netfid);
                } */
 
+               pTcon = tlink_tcon(cifsFile->tlink);
                rc = find_cifs_entry(xid, pTcon, file,
                                &current_entry, &num_to_fill);
                if (rc) {