cifs: add bdi backing to mount session
[safe/jmp/linux-2.6] / fs / cifs / cifsfs.c
index b5e9f39..ad235d6 100644 (file)
@@ -50,7 +50,7 @@
 #define CIFS_MAGIC_NUMBER 0xFF534D42   /* the first four bytes of SMB PDUs */
 
 #ifdef CONFIG_CIFS_QUOTA
-static struct quotactl_ops cifs_quotactl_ops;
+static const struct quotactl_ops cifs_quotactl_ops;
 #endif /* QUOTA */
 
 int cifsFYI = 0;
@@ -64,9 +64,6 @@ unsigned int multiuser_mount = 0;
 unsigned int extended_security = CIFSSEC_DEF;
 /* unsigned int ntlmv2_support = 0; */
 unsigned int sign_CIFS_PDUs = 1;
-extern struct task_struct *oplockThread; /* remove sparse warning */
-struct task_struct *oplockThread = NULL;
-/* extern struct task_struct * dnotifyThread; remove sparse warning */
 static const struct super_operations cifs_super_ops;
 unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
 module_param(CIFSMaxBufSize, int, 0);
@@ -106,6 +103,12 @@ cifs_read_super(struct super_block *sb, void *data,
        if (cifs_sb == NULL)
                return -ENOMEM;
 
+       rc = bdi_setup_and_register(&cifs_sb->bdi, "cifs", BDI_CAP_MAP_COPY);
+       if (rc) {
+               kfree(cifs_sb);
+               return rc;
+       }
+
 #ifdef CONFIG_CIFS_DFS_UPCALL
        /* copy mount params to sb for use in submounts */
        /* BB: should we move this after the mount so we
@@ -118,6 +121,7 @@ cifs_read_super(struct super_block *sb, void *data,
                int len = strlen(data);
                cifs_sb->mountdata = kzalloc(len + 1, GFP_KERNEL);
                if (cifs_sb->mountdata == NULL) {
+                       bdi_destroy(&cifs_sb->bdi);
                        kfree(sb->s_fs_info);
                        sb->s_fs_info = NULL;
                        return -ENOMEM;
@@ -138,6 +142,7 @@ cifs_read_super(struct super_block *sb, void *data,
 
        sb->s_magic = CIFS_MAGIC_NUMBER;
        sb->s_op = &cifs_super_ops;
+       sb->s_bdi = &cifs_sb->bdi;
 /*     if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
            sb->s_blocksize =
                cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
@@ -185,8 +190,8 @@ out_mount_failed:
                        cifs_sb->mountdata = NULL;
                }
 #endif
-               if (cifs_sb->local_nls)
-                       unload_nls(cifs_sb->local_nls);
+               unload_nls(cifs_sb->local_nls);
+               bdi_destroy(&cifs_sb->bdi);
                kfree(cifs_sb);
        }
        return rc;
@@ -218,6 +223,7 @@ cifs_put_super(struct super_block *sb)
 #endif
 
        unload_nls(cifs_sb->local_nls);
+       bdi_destroy(&cifs_sb->bdi);
        kfree(cifs_sb);
 
        unlock_kernel();
@@ -308,7 +314,6 @@ cifs_alloc_inode(struct super_block *sb)
        if (!cifs_inode)
                return NULL;
        cifs_inode->cifsAttrs = 0x20;   /* default */
-       atomic_set(&cifs_inode->inUse, 0);
        cifs_inode->time = 0;
        cifs_inode->write_behind_rc = 0;
        /* Until the file is open and we have gotten oplock
@@ -317,6 +322,7 @@ cifs_alloc_inode(struct super_block *sb)
        cifs_inode->clientCanCacheRead = false;
        cifs_inode->clientCanCacheAll = false;
        cifs_inode->delete_pending = false;
+       cifs_inode->invalid_mapping = false;
        cifs_inode->vfs_inode.i_blkbits = 14;  /* 2**14 = CIFS_MAX_MSGSIZE */
        cifs_inode->server_eof = 0;
 
@@ -362,13 +368,10 @@ cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
 static int
 cifs_show_options(struct seq_file *s, struct vfsmount *m)
 {
-       struct cifs_sb_info *cifs_sb;
-       struct cifsTconInfo *tcon;
-
-       cifs_sb = CIFS_SB(m->mnt_sb);
-       tcon = cifs_sb->tcon;
+       struct cifs_sb_info *cifs_sb = CIFS_SB(m->mnt_sb);
+       struct cifsTconInfo *tcon = cifs_sb->tcon;
 
-       seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName);
+       seq_printf(s, ",unc=%s", tcon->treeName);
        if (tcon->ses->userName)
                seq_printf(s, ",username=%s", tcon->ses->userName);
        if (tcon->ses->domainName)
@@ -377,10 +380,14 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m)
        seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
                seq_printf(s, ",forceuid");
+       else
+               seq_printf(s, ",noforceuid");
 
        seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
                seq_printf(s, ",forcegid");
+       else
+               seq_printf(s, ",noforcegid");
 
        cifs_show_address(s, tcon->ses->server);
 
@@ -517,7 +524,7 @@ int cifs_xstate_get(struct super_block *sb, struct fs_quota_stat *qstats)
        return rc;
 }
 
-static struct quotactl_ops cifs_quotactl_ops = {
+static const struct quotactl_ops cifs_quotactl_ops = {
        .set_xquota     = cifs_xquota_set,
        .get_xquota     = cifs_xquota_get,
        .set_xstate     = cifs_xstate_set,
@@ -537,9 +544,14 @@ static void cifs_umount_begin(struct super_block *sb)
        if (tcon == NULL)
                return;
 
-       lock_kernel();
        read_lock(&cifs_tcp_ses_lock);
-       if (tcon->tc_count == 1)
+       if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
+               /* we have other mounts to same share or we have
+                  already tried to force umount this and woken up
+                  all waiting network requests, nothing to do */
+               read_unlock(&cifs_tcp_ses_lock);
+               return;
+       } else if (tcon->tc_count == 1)
                tcon->tidStatus = CifsExiting;
        read_unlock(&cifs_tcp_ses_lock);
 
@@ -554,9 +566,7 @@ static void cifs_umount_begin(struct super_block *sb)
                wake_up_all(&tcon->ses->server->response_q);
                msleep(1);
        }
-/* BB FIXME - finish add checks for tidStatus BB */
 
-       unlock_kernel();
        return;
 }
 
@@ -639,7 +649,7 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
                   setting the revalidate time to zero */
                CIFS_I(file->f_path.dentry->d_inode)->time = 0;
 
-               retval = cifs_revalidate(file->f_path.dentry);
+               retval = cifs_revalidate_file(file);
                if (retval < 0)
                        return (loff_t)retval;
        }
@@ -759,7 +769,7 @@ const struct file_operations cifs_file_ops = {
 };
 
 const struct file_operations cifs_file_direct_ops = {
-       /* no mmap, no aio, no readv -
+       /* no aio, no readv -
           BB reevaluate whether they can be done with directio, no cache */
        .read = cifs_user_read,
        .write = cifs_user_write,
@@ -768,6 +778,7 @@ const struct file_operations cifs_file_direct_ops = {
        .lock = cifs_lock,
        .fsync = cifs_fsync,
        .flush = cifs_flush,
+       .mmap = cifs_file_mmap,
        .splice_read = generic_file_splice_read,
 #ifdef CONFIG_CIFS_POSIX
        .unlocked_ioctl  = cifs_ioctl,
@@ -807,6 +818,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = {
        .release = cifs_close,
        .fsync = cifs_fsync,
        .flush = cifs_flush,
+       .mmap = cifs_file_mmap,
        .splice_read = generic_file_splice_read,
 #ifdef CONFIG_CIFS_POSIX
        .unlocked_ioctl  = cifs_ioctl,
@@ -970,89 +982,12 @@ cifs_destroy_mids(void)
        kmem_cache_destroy(cifs_oplock_cachep);
 }
 
-static int cifs_oplock_thread(void *dummyarg)
-{
-       struct oplock_q_entry *oplock_item;
-       struct cifsTconInfo *pTcon;
-       struct inode *inode;
-       __u16  netfid;
-       int rc, waitrc = 0;
-
-       set_freezable();
-       do {
-               if (try_to_freeze())
-                       continue;
-
-               spin_lock(&GlobalMid_Lock);
-               if (list_empty(&GlobalOplock_Q)) {
-                       spin_unlock(&GlobalMid_Lock);
-                       set_current_state(TASK_INTERRUPTIBLE);
-                       schedule_timeout(39*HZ);
-               } else {
-                       oplock_item = list_entry(GlobalOplock_Q.next,
-                                               struct oplock_q_entry, qhead);
-                       cFYI(1, ("found oplock item to write out"));
-                       pTcon = oplock_item->tcon;
-                       inode = oplock_item->pinode;
-                       netfid = oplock_item->netfid;
-                       spin_unlock(&GlobalMid_Lock);
-                       DeleteOplockQEntry(oplock_item);
-                       /* can not grab inode sem here since it would
-                               deadlock when oplock received on delete
-                               since vfs_unlink holds the i_mutex across
-                               the call */
-                       /* mutex_lock(&inode->i_mutex);*/
-                       if (S_ISREG(inode->i_mode)) {
-#ifdef CONFIG_CIFS_EXPERIMENTAL
-                               if (CIFS_I(inode)->clientCanCacheAll == 0)
-                                       break_lease(inode, FMODE_READ);
-                               else if (CIFS_I(inode)->clientCanCacheRead == 0)
-                                       break_lease(inode, FMODE_WRITE);
-#endif
-                               rc = filemap_fdatawrite(inode->i_mapping);
-                               if (CIFS_I(inode)->clientCanCacheRead == 0) {
-                                       waitrc = filemap_fdatawait(
-                                                             inode->i_mapping);
-                                       invalidate_remote_inode(inode);
-                               }
-                               if (rc == 0)
-                                       rc = waitrc;
-                       } else
-                               rc = 0;
-                       /* mutex_unlock(&inode->i_mutex);*/
-                       if (rc)
-                               CIFS_I(inode)->write_behind_rc = rc;
-                       cFYI(1, ("Oplock flush inode %p rc %d",
-                               inode, rc));
-
-                               /* releasing stale oplock after recent reconnect
-                               of smb session using a now incorrect file
-                               handle is not a data integrity issue but do
-                               not bother sending an oplock release if session
-                               to server still is disconnected since oplock
-                               already released by the server in that case */
-                       if (!pTcon->need_reconnect) {
-                               rc = CIFSSMBLock(0, pTcon, netfid,
-                                               0 /* len */ , 0 /* offset */, 0,
-                                               0, LOCKING_ANDX_OPLOCK_RELEASE,
-                                               false /* wait flag */);
-                               cFYI(1, ("Oplock release rc = %d", rc));
-                       }
-                       set_current_state(TASK_INTERRUPTIBLE);
-                       schedule_timeout(1);  /* yield in case q were corrupt */
-               }
-       } while (!kthread_should_stop());
-
-       return 0;
-}
-
 static int __init
 init_cifs(void)
 {
        int rc = 0;
        cifs_proc_init();
        INIT_LIST_HEAD(&cifs_tcp_ses_list);
-       INIT_LIST_HEAD(&GlobalOplock_Q);
 #ifdef CONFIG_CIFS_EXPERIMENTAL
        INIT_LIST_HEAD(&GlobalDnotifyReqList);
        INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
@@ -1115,16 +1050,13 @@ init_cifs(void)
        if (rc)
                goto out_unregister_key_type;
 #endif
-       oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd");
-       if (IS_ERR(oplockThread)) {
-               rc = PTR_ERR(oplockThread);
-               cERROR(1, ("error %d create oplock thread", rc));
-               goto out_unregister_dfs_key_type;
-       }
+       rc = slow_work_register_user(THIS_MODULE);
+       if (rc)
+               goto out_unregister_resolver_key;
 
        return 0;
 
- out_unregister_dfs_key_type:
+ out_unregister_resolver_key:
 #ifdef CONFIG_CIFS_DFS_UPCALL
        unregister_key_type(&key_type_dns_resolver);
  out_unregister_key_type:
@@ -1161,7 +1093,6 @@ exit_cifs(void)
        cifs_destroy_inodecache();
        cifs_destroy_mids();
        cifs_destroy_request_bufs();
-       kthread_stop(oplockThread);
 }
 
 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");