diff options
Diffstat (limited to 'fs/cifs')
-rw-r--r-- | fs/cifs/Kconfig | 38 | ||||
-rw-r--r-- | fs/cifs/Makefile | 2 | ||||
-rw-r--r-- | fs/cifs/cifsacl.c | 2 | ||||
-rw-r--r-- | fs/cifs/cifsencrypt.c | 67 | ||||
-rw-r--r-- | fs/cifs/cifsfs.c | 63 | ||||
-rw-r--r-- | fs/cifs/cifsfs.h | 2 | ||||
-rw-r--r-- | fs/cifs/cifsglob.h | 268 | ||||
-rw-r--r-- | fs/cifs/cifspdu.h | 2 | ||||
-rw-r--r-- | fs/cifs/cifsproto.h | 136 | ||||
-rw-r--r-- | fs/cifs/cifssmb.c | 289 | ||||
-rw-r--r-- | fs/cifs/connect.c | 198 | ||||
-rw-r--r-- | fs/cifs/dir.c | 124 | ||||
-rw-r--r-- | fs/cifs/file.c | 1055 | ||||
-rw-r--r-- | fs/cifs/inode.c | 441 | ||||
-rw-r--r-- | fs/cifs/ioctl.c | 32 | ||||
-rw-r--r-- | fs/cifs/link.c | 74 | ||||
-rw-r--r-- | fs/cifs/misc.c | 32 | ||||
-rw-r--r-- | fs/cifs/netmisc.c | 9 | ||||
-rw-r--r-- | fs/cifs/readdir.c | 167 | ||||
-rw-r--r-- | fs/cifs/sess.c | 3 | ||||
-rw-r--r-- | fs/cifs/smb1ops.c | 328 | ||||
-rw-r--r-- | fs/cifs/smb2file.c | 302 | ||||
-rw-r--r-- | fs/cifs/smb2glob.h | 14 | ||||
-rw-r--r-- | fs/cifs/smb2inode.c | 98 | ||||
-rw-r--r-- | fs/cifs/smb2maperror.c | 6 | ||||
-rw-r--r-- | fs/cifs/smb2misc.c | 240 | ||||
-rw-r--r-- | fs/cifs/smb2ops.c | 346 | ||||
-rw-r--r-- | fs/cifs/smb2pdu.c | 1235 | ||||
-rw-r--r-- | fs/cifs/smb2pdu.h | 284 | ||||
-rw-r--r-- | fs/cifs/smb2proto.h | 87 | ||||
-rw-r--r-- | fs/cifs/smb2transport.c | 204 | ||||
-rw-r--r-- | fs/cifs/transport.c | 283 |
32 files changed, 4884 insertions, 1547 deletions
diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig index a08306a8bec9..2075ddfffa73 100644 --- a/fs/cifs/Kconfig +++ b/fs/cifs/Kconfig | |||
@@ -9,13 +9,14 @@ config CIFS | |||
9 | select CRYPTO_ARC4 | 9 | select CRYPTO_ARC4 |
10 | select CRYPTO_ECB | 10 | select CRYPTO_ECB |
11 | select CRYPTO_DES | 11 | select CRYPTO_DES |
12 | select CRYPTO_SHA256 | ||
12 | help | 13 | help |
13 | This is the client VFS module for the Common Internet File System | 14 | This is the client VFS module for the Common Internet File System |
14 | (CIFS) protocol which is the successor to the Server Message Block | 15 | (CIFS) protocol which is the successor to the Server Message Block |
15 | (SMB) protocol, the native file sharing mechanism for most early | 16 | (SMB) protocol, the native file sharing mechanism for most early |
16 | PC operating systems. The CIFS protocol is fully supported by | 17 | PC operating systems. The CIFS protocol is fully supported by |
17 | file servers such as Windows 2000 (including Windows 2003, NT 4 | 18 | file servers such as Windows 2000 (including Windows 2003, Windows 2008, |
18 | and Windows XP) as well by Samba (which provides excellent CIFS | 19 | NT 4 and Windows XP) as well by Samba (which provides excellent CIFS |
19 | server support for Linux and many other operating systems). Limited | 20 | server support for Linux and many other operating systems). Limited |
20 | support for OS/2 and Windows ME and similar servers is provided as | 21 | support for OS/2 and Windows ME and similar servers is provided as |
21 | well. | 22 | well. |
@@ -114,6 +115,13 @@ config CIFS_POSIX | |||
114 | (such as Samba 3.10 and later) which can negotiate | 115 | (such as Samba 3.10 and later) which can negotiate |
115 | CIFS POSIX ACL support. If unsure, say N. | 116 | CIFS POSIX ACL support. If unsure, say N. |
116 | 117 | ||
118 | config CIFS_ACL | ||
119 | bool "Provide CIFS ACL support" | ||
120 | depends on CIFS_XATTR && KEYS | ||
121 | help | ||
122 | Allows fetching CIFS/NTFS ACL from the server. The DACL blob | ||
123 | is handed over to the application/caller. | ||
124 | |||
117 | config CIFS_DEBUG2 | 125 | config CIFS_DEBUG2 |
118 | bool "Enable additional CIFS debugging routines" | 126 | bool "Enable additional CIFS debugging routines" |
119 | depends on CIFS | 127 | depends on CIFS |
@@ -138,21 +146,6 @@ config CIFS_DFS_UPCALL | |||
138 | IP addresses) which is needed for implicit mounts of DFS junction | 146 | IP addresses) which is needed for implicit mounts of DFS junction |
139 | points. If unsure, say N. | 147 | points. If unsure, say N. |
140 | 148 | ||
141 | config CIFS_FSCACHE | ||
142 | bool "Provide CIFS client caching support" | ||
143 | depends on CIFS=m && FSCACHE || CIFS=y && FSCACHE=y | ||
144 | help | ||
145 | Makes CIFS FS-Cache capable. Say Y here if you want your CIFS data | ||
146 | to be cached locally on disk through the general filesystem cache | ||
147 | manager. If unsure, say N. | ||
148 | |||
149 | config CIFS_ACL | ||
150 | bool "Provide CIFS ACL support" | ||
151 | depends on CIFS_XATTR && KEYS | ||
152 | help | ||
153 | Allows to fetch CIFS/NTFS ACL from the server. The DACL blob | ||
154 | is handed over to the application/caller. | ||
155 | |||
156 | config CIFS_NFSD_EXPORT | 149 | config CIFS_NFSD_EXPORT |
157 | bool "Allow nfsd to export CIFS file system (EXPERIMENTAL)" | 150 | bool "Allow nfsd to export CIFS file system (EXPERIMENTAL)" |
158 | depends on CIFS && EXPERIMENTAL && BROKEN | 151 | depends on CIFS && EXPERIMENTAL && BROKEN |
@@ -161,7 +154,7 @@ config CIFS_NFSD_EXPORT | |||
161 | 154 | ||
162 | config CIFS_SMB2 | 155 | config CIFS_SMB2 |
163 | bool "SMB2 network file system support (EXPERIMENTAL)" | 156 | bool "SMB2 network file system support (EXPERIMENTAL)" |
164 | depends on EXPERIMENTAL && INET && BROKEN | 157 | depends on CIFS && EXPERIMENTAL && INET |
165 | select NLS | 158 | select NLS |
166 | select KEYS | 159 | select KEYS |
167 | select FSCACHE | 160 | select FSCACHE |
@@ -178,3 +171,12 @@ config CIFS_SMB2 | |||
178 | (compared to cifs) due to protocol improvements. | 171 | (compared to cifs) due to protocol improvements. |
179 | 172 | ||
180 | Unless you are a developer or tester, say N. | 173 | Unless you are a developer or tester, say N. |
174 | |||
175 | config CIFS_FSCACHE | ||
176 | bool "Provide CIFS client caching support" | ||
177 | depends on CIFS=m && FSCACHE || CIFS=y && FSCACHE=y | ||
178 | help | ||
179 | Makes CIFS FS-Cache capable. Say Y here if you want your CIFS data | ||
180 | to be cached locally on disk through the general filesystem cache | ||
181 | manager. If unsure, say N. | ||
182 | |||
diff --git a/fs/cifs/Makefile b/fs/cifs/Makefile index feee94309271..aa0d68b086eb 100644 --- a/fs/cifs/Makefile +++ b/fs/cifs/Makefile | |||
@@ -17,4 +17,4 @@ cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o | |||
17 | cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o | 17 | cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o |
18 | 18 | ||
19 | cifs-$(CONFIG_CIFS_SMB2) += smb2ops.o smb2maperror.o smb2transport.o \ | 19 | cifs-$(CONFIG_CIFS_SMB2) += smb2ops.o smb2maperror.o smb2transport.o \ |
20 | smb2misc.o smb2pdu.o smb2inode.o | 20 | smb2misc.o smb2pdu.o smb2inode.o smb2file.o |
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c index 05f4dc263a23..2ee5c54797fa 100644 --- a/fs/cifs/cifsacl.c +++ b/fs/cifs/cifsacl.c | |||
@@ -1222,7 +1222,7 @@ struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb, | |||
1222 | if (!open_file) | 1222 | if (!open_file) |
1223 | return get_cifs_acl_by_path(cifs_sb, path, pacllen); | 1223 | return get_cifs_acl_by_path(cifs_sb, path, pacllen); |
1224 | 1224 | ||
1225 | pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->netfid, pacllen); | 1225 | pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->fid.netfid, pacllen); |
1226 | cifsFileInfo_put(open_file); | 1226 | cifsFileInfo_put(open_file); |
1227 | return pntsd; | 1227 | return pntsd; |
1228 | } | 1228 | } |
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index 6a0d741159f0..652f5051be09 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "ntlmssp.h" | 29 | #include "ntlmssp.h" |
30 | #include <linux/ctype.h> | 30 | #include <linux/ctype.h> |
31 | #include <linux/random.h> | 31 | #include <linux/random.h> |
32 | #include <linux/highmem.h> | ||
32 | 33 | ||
33 | /* | 34 | /* |
34 | * Calculate and return the CIFS signature based on the mac key and SMB PDU. | 35 | * Calculate and return the CIFS signature based on the mac key and SMB PDU. |
@@ -37,11 +38,13 @@ | |||
37 | * the sequence number before this function is called. Also, this function | 38 | * the sequence number before this function is called. Also, this function |
38 | * should be called with the server->srv_mutex held. | 39 | * should be called with the server->srv_mutex held. |
39 | */ | 40 | */ |
40 | static int cifs_calc_signature(const struct kvec *iov, int n_vec, | 41 | static int cifs_calc_signature(struct smb_rqst *rqst, |
41 | struct TCP_Server_Info *server, char *signature) | 42 | struct TCP_Server_Info *server, char *signature) |
42 | { | 43 | { |
43 | int i; | 44 | int i; |
44 | int rc; | 45 | int rc; |
46 | struct kvec *iov = rqst->rq_iov; | ||
47 | int n_vec = rqst->rq_nvec; | ||
45 | 48 | ||
46 | if (iov == NULL || signature == NULL || server == NULL) | 49 | if (iov == NULL || signature == NULL || server == NULL) |
47 | return -EINVAL; | 50 | return -EINVAL; |
@@ -91,6 +94,16 @@ static int cifs_calc_signature(const struct kvec *iov, int n_vec, | |||
91 | } | 94 | } |
92 | } | 95 | } |
93 | 96 | ||
97 | /* now hash over the rq_pages array */ | ||
98 | for (i = 0; i < rqst->rq_npages; i++) { | ||
99 | struct kvec p_iov; | ||
100 | |||
101 | cifs_rqst_page_to_kvec(rqst, i, &p_iov); | ||
102 | crypto_shash_update(&server->secmech.sdescmd5->shash, | ||
103 | p_iov.iov_base, p_iov.iov_len); | ||
104 | kunmap(rqst->rq_pages[i]); | ||
105 | } | ||
106 | |||
94 | rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature); | 107 | rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature); |
95 | if (rc) | 108 | if (rc) |
96 | cERROR(1, "%s: Could not generate md5 hash", __func__); | 109 | cERROR(1, "%s: Could not generate md5 hash", __func__); |
@@ -99,12 +112,12 @@ static int cifs_calc_signature(const struct kvec *iov, int n_vec, | |||
99 | } | 112 | } |
100 | 113 | ||
101 | /* must be called with server->srv_mutex held */ | 114 | /* must be called with server->srv_mutex held */ |
102 | int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | 115 | int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, |
103 | __u32 *pexpected_response_sequence_number) | 116 | __u32 *pexpected_response_sequence_number) |
104 | { | 117 | { |
105 | int rc = 0; | 118 | int rc = 0; |
106 | char smb_signature[20]; | 119 | char smb_signature[20]; |
107 | struct smb_hdr *cifs_pdu = (struct smb_hdr *)iov[0].iov_base; | 120 | struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
108 | 121 | ||
109 | if ((cifs_pdu == NULL) || (server == NULL)) | 122 | if ((cifs_pdu == NULL) || (server == NULL)) |
110 | return -EINVAL; | 123 | return -EINVAL; |
@@ -125,7 +138,7 @@ int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | |||
125 | *pexpected_response_sequence_number = server->sequence_number++; | 138 | *pexpected_response_sequence_number = server->sequence_number++; |
126 | server->sequence_number++; | 139 | server->sequence_number++; |
127 | 140 | ||
128 | rc = cifs_calc_signature(iov, n_vec, server, smb_signature); | 141 | rc = cifs_calc_signature(rqst, server, smb_signature); |
129 | if (rc) | 142 | if (rc) |
130 | memset(cifs_pdu->Signature.SecuritySignature, 0, 8); | 143 | memset(cifs_pdu->Signature.SecuritySignature, 0, 8); |
131 | else | 144 | else |
@@ -134,6 +147,15 @@ int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | |||
134 | return rc; | 147 | return rc; |
135 | } | 148 | } |
136 | 149 | ||
150 | int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | ||
151 | __u32 *pexpected_response_sequence) | ||
152 | { | ||
153 | struct smb_rqst rqst = { .rq_iov = iov, | ||
154 | .rq_nvec = n_vec }; | ||
155 | |||
156 | return cifs_sign_rqst(&rqst, server, pexpected_response_sequence); | ||
157 | } | ||
158 | |||
137 | /* must be called with server->srv_mutex held */ | 159 | /* must be called with server->srv_mutex held */ |
138 | int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, | 160 | int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, |
139 | __u32 *pexpected_response_sequence_number) | 161 | __u32 *pexpected_response_sequence_number) |
@@ -147,14 +169,14 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, | |||
147 | pexpected_response_sequence_number); | 169 | pexpected_response_sequence_number); |
148 | } | 170 | } |
149 | 171 | ||
150 | int cifs_verify_signature(struct kvec *iov, unsigned int nr_iov, | 172 | int cifs_verify_signature(struct smb_rqst *rqst, |
151 | struct TCP_Server_Info *server, | 173 | struct TCP_Server_Info *server, |
152 | __u32 expected_sequence_number) | 174 | __u32 expected_sequence_number) |
153 | { | 175 | { |
154 | unsigned int rc; | 176 | unsigned int rc; |
155 | char server_response_sig[8]; | 177 | char server_response_sig[8]; |
156 | char what_we_think_sig_should_be[20]; | 178 | char what_we_think_sig_should_be[20]; |
157 | struct smb_hdr *cifs_pdu = (struct smb_hdr *)iov[0].iov_base; | 179 | struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
158 | 180 | ||
159 | if (cifs_pdu == NULL || server == NULL) | 181 | if (cifs_pdu == NULL || server == NULL) |
160 | return -EINVAL; | 182 | return -EINVAL; |
@@ -186,8 +208,7 @@ int cifs_verify_signature(struct kvec *iov, unsigned int nr_iov, | |||
186 | cifs_pdu->Signature.Sequence.Reserved = 0; | 208 | cifs_pdu->Signature.Sequence.Reserved = 0; |
187 | 209 | ||
188 | mutex_lock(&server->srv_mutex); | 210 | mutex_lock(&server->srv_mutex); |
189 | rc = cifs_calc_signature(iov, nr_iov, server, | 211 | rc = cifs_calc_signature(rqst, server, what_we_think_sig_should_be); |
190 | what_we_think_sig_should_be); | ||
191 | mutex_unlock(&server->srv_mutex); | 212 | mutex_unlock(&server->srv_mutex); |
192 | 213 | ||
193 | if (rc) | 214 | if (rc) |
@@ -686,12 +707,17 @@ calc_seckey(struct cifs_ses *ses) | |||
686 | void | 707 | void |
687 | cifs_crypto_shash_release(struct TCP_Server_Info *server) | 708 | cifs_crypto_shash_release(struct TCP_Server_Info *server) |
688 | { | 709 | { |
710 | if (server->secmech.hmacsha256) | ||
711 | crypto_free_shash(server->secmech.hmacsha256); | ||
712 | |||
689 | if (server->secmech.md5) | 713 | if (server->secmech.md5) |
690 | crypto_free_shash(server->secmech.md5); | 714 | crypto_free_shash(server->secmech.md5); |
691 | 715 | ||
692 | if (server->secmech.hmacmd5) | 716 | if (server->secmech.hmacmd5) |
693 | crypto_free_shash(server->secmech.hmacmd5); | 717 | crypto_free_shash(server->secmech.hmacmd5); |
694 | 718 | ||
719 | kfree(server->secmech.sdeschmacsha256); | ||
720 | |||
695 | kfree(server->secmech.sdeschmacmd5); | 721 | kfree(server->secmech.sdeschmacmd5); |
696 | 722 | ||
697 | kfree(server->secmech.sdescmd5); | 723 | kfree(server->secmech.sdescmd5); |
@@ -716,6 +742,13 @@ cifs_crypto_shash_allocate(struct TCP_Server_Info *server) | |||
716 | goto crypto_allocate_md5_fail; | 742 | goto crypto_allocate_md5_fail; |
717 | } | 743 | } |
718 | 744 | ||
745 | server->secmech.hmacsha256 = crypto_alloc_shash("hmac(sha256)", 0, 0); | ||
746 | if (IS_ERR(server->secmech.hmacsha256)) { | ||
747 | cERROR(1, "could not allocate crypto hmacsha256\n"); | ||
748 | rc = PTR_ERR(server->secmech.hmacsha256); | ||
749 | goto crypto_allocate_hmacsha256_fail; | ||
750 | } | ||
751 | |||
719 | size = sizeof(struct shash_desc) + | 752 | size = sizeof(struct shash_desc) + |
720 | crypto_shash_descsize(server->secmech.hmacmd5); | 753 | crypto_shash_descsize(server->secmech.hmacmd5); |
721 | server->secmech.sdeschmacmd5 = kmalloc(size, GFP_KERNEL); | 754 | server->secmech.sdeschmacmd5 = kmalloc(size, GFP_KERNEL); |
@@ -727,7 +760,6 @@ cifs_crypto_shash_allocate(struct TCP_Server_Info *server) | |||
727 | server->secmech.sdeschmacmd5->shash.tfm = server->secmech.hmacmd5; | 760 | server->secmech.sdeschmacmd5->shash.tfm = server->secmech.hmacmd5; |
728 | server->secmech.sdeschmacmd5->shash.flags = 0x0; | 761 | server->secmech.sdeschmacmd5->shash.flags = 0x0; |
729 | 762 | ||
730 | |||
731 | size = sizeof(struct shash_desc) + | 763 | size = sizeof(struct shash_desc) + |
732 | crypto_shash_descsize(server->secmech.md5); | 764 | crypto_shash_descsize(server->secmech.md5); |
733 | server->secmech.sdescmd5 = kmalloc(size, GFP_KERNEL); | 765 | server->secmech.sdescmd5 = kmalloc(size, GFP_KERNEL); |
@@ -739,12 +771,29 @@ cifs_crypto_shash_allocate(struct TCP_Server_Info *server) | |||
739 | server->secmech.sdescmd5->shash.tfm = server->secmech.md5; | 771 | server->secmech.sdescmd5->shash.tfm = server->secmech.md5; |
740 | server->secmech.sdescmd5->shash.flags = 0x0; | 772 | server->secmech.sdescmd5->shash.flags = 0x0; |
741 | 773 | ||
774 | size = sizeof(struct shash_desc) + | ||
775 | crypto_shash_descsize(server->secmech.hmacsha256); | ||
776 | server->secmech.sdeschmacsha256 = kmalloc(size, GFP_KERNEL); | ||
777 | if (!server->secmech.sdeschmacsha256) { | ||
778 | cERROR(1, "%s: Can't alloc hmacsha256\n", __func__); | ||
779 | rc = -ENOMEM; | ||
780 | goto crypto_allocate_hmacsha256_sdesc_fail; | ||
781 | } | ||
782 | server->secmech.sdeschmacsha256->shash.tfm = server->secmech.hmacsha256; | ||
783 | server->secmech.sdeschmacsha256->shash.flags = 0x0; | ||
784 | |||
742 | return 0; | 785 | return 0; |
743 | 786 | ||
787 | crypto_allocate_hmacsha256_sdesc_fail: | ||
788 | kfree(server->secmech.sdescmd5); | ||
789 | |||
744 | crypto_allocate_md5_sdesc_fail: | 790 | crypto_allocate_md5_sdesc_fail: |
745 | kfree(server->secmech.sdeschmacmd5); | 791 | kfree(server->secmech.sdeschmacmd5); |
746 | 792 | ||
747 | crypto_allocate_hmacmd5_sdesc_fail: | 793 | crypto_allocate_hmacmd5_sdesc_fail: |
794 | crypto_free_shash(server->secmech.hmacsha256); | ||
795 | |||
796 | crypto_allocate_hmacsha256_fail: | ||
748 | crypto_free_shash(server->secmech.md5); | 797 | crypto_free_shash(server->secmech.md5); |
749 | 798 | ||
750 | crypto_allocate_md5_fail: | 799 | crypto_allocate_md5_fail: |
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index d4ce77a02327..e7931cc55d0c 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/kthread.h> | 36 | #include <linux/kthread.h> |
37 | #include <linux/freezer.h> | 37 | #include <linux/freezer.h> |
38 | #include <linux/namei.h> | 38 | #include <linux/namei.h> |
39 | #include <linux/random.h> | ||
39 | #include <net/ipv6.h> | 40 | #include <net/ipv6.h> |
40 | #include "cifsfs.h" | 41 | #include "cifsfs.h" |
41 | #include "cifspdu.h" | 42 | #include "cifspdu.h" |
@@ -51,7 +52,6 @@ | |||
51 | #ifdef CONFIG_CIFS_SMB2 | 52 | #ifdef CONFIG_CIFS_SMB2 |
52 | #include "smb2pdu.h" | 53 | #include "smb2pdu.h" |
53 | #endif | 54 | #endif |
54 | #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ | ||
55 | 55 | ||
56 | int cifsFYI = 0; | 56 | int cifsFYI = 0; |
57 | int cifsERROR = 1; | 57 | int cifsERROR = 1; |
@@ -89,6 +89,10 @@ extern mempool_t *cifs_mid_poolp; | |||
89 | 89 | ||
90 | struct workqueue_struct *cifsiod_wq; | 90 | struct workqueue_struct *cifsiod_wq; |
91 | 91 | ||
92 | #ifdef CONFIG_CIFS_SMB2 | ||
93 | __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE]; | ||
94 | #endif | ||
95 | |||
92 | static int | 96 | static int |
93 | cifs_read_super(struct super_block *sb) | 97 | cifs_read_super(struct super_block *sb) |
94 | { | 98 | { |
@@ -160,13 +164,12 @@ cifs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
160 | struct super_block *sb = dentry->d_sb; | 164 | struct super_block *sb = dentry->d_sb; |
161 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | 165 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
162 | struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); | 166 | struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); |
163 | int rc = -EOPNOTSUPP; | 167 | struct TCP_Server_Info *server = tcon->ses->server; |
164 | unsigned int xid; | 168 | unsigned int xid; |
169 | int rc = 0; | ||
165 | 170 | ||
166 | xid = get_xid(); | 171 | xid = get_xid(); |
167 | 172 | ||
168 | buf->f_type = CIFS_MAGIC_NUMBER; | ||
169 | |||
170 | /* | 173 | /* |
171 | * PATH_MAX may be too long - it would presumably be total path, | 174 | * PATH_MAX may be too long - it would presumably be total path, |
172 | * but note that some servers (includinng Samba 3) have a shorter | 175 | * but note that some servers (includinng Samba 3) have a shorter |
@@ -178,27 +181,8 @@ cifs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
178 | buf->f_files = 0; /* undefined */ | 181 | buf->f_files = 0; /* undefined */ |
179 | buf->f_ffree = 0; /* unlimited */ | 182 | buf->f_ffree = 0; /* unlimited */ |
180 | 183 | ||
181 | /* | 184 | if (server->ops->queryfs) |
182 | * We could add a second check for a QFS Unix capability bit | 185 | rc = server->ops->queryfs(xid, tcon, buf); |
183 | */ | ||
184 | if ((tcon->ses->capabilities & CAP_UNIX) && | ||
185 | (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability))) | ||
186 | rc = CIFSSMBQFSPosixInfo(xid, tcon, buf); | ||
187 | |||
188 | /* | ||
189 | * Only need to call the old QFSInfo if failed on newer one, | ||
190 | * e.g. by OS/2. | ||
191 | **/ | ||
192 | if (rc && (tcon->ses->capabilities & CAP_NT_SMBS)) | ||
193 | rc = CIFSSMBQFSInfo(xid, tcon, buf); | ||
194 | |||
195 | /* | ||
196 | * Some old Windows servers also do not support level 103, retry with | ||
197 | * older level one if old server failed the previous call or we | ||
198 | * bypassed it because we detected that this was an older LANMAN sess | ||
199 | */ | ||
200 | if (rc) | ||
201 | rc = SMBOldQFSInfo(xid, tcon, buf); | ||
202 | 186 | ||
203 | free_xid(xid); | 187 | free_xid(xid); |
204 | return 0; | 188 | return 0; |
@@ -239,9 +223,10 @@ cifs_alloc_inode(struct super_block *sb) | |||
239 | return NULL; | 223 | return NULL; |
240 | cifs_inode->cifsAttrs = 0x20; /* default */ | 224 | cifs_inode->cifsAttrs = 0x20; /* default */ |
241 | cifs_inode->time = 0; | 225 | cifs_inode->time = 0; |
242 | /* Until the file is open and we have gotten oplock | 226 | /* |
243 | info back from the server, can not assume caching of | 227 | * Until the file is open and we have gotten oplock info back from the |
244 | file data or metadata */ | 228 | * server, can not assume caching of file data or metadata. |
229 | */ | ||
245 | cifs_set_oplock_level(cifs_inode, 0); | 230 | cifs_set_oplock_level(cifs_inode, 0); |
246 | cifs_inode->delete_pending = false; | 231 | cifs_inode->delete_pending = false; |
247 | cifs_inode->invalid_mapping = false; | 232 | cifs_inode->invalid_mapping = false; |
@@ -249,11 +234,16 @@ cifs_alloc_inode(struct super_block *sb) | |||
249 | cifs_inode->server_eof = 0; | 234 | cifs_inode->server_eof = 0; |
250 | cifs_inode->uniqueid = 0; | 235 | cifs_inode->uniqueid = 0; |
251 | cifs_inode->createtime = 0; | 236 | cifs_inode->createtime = 0; |
252 | 237 | #ifdef CONFIG_CIFS_SMB2 | |
253 | /* Can not set i_flags here - they get immediately overwritten | 238 | get_random_bytes(cifs_inode->lease_key, SMB2_LEASE_KEY_SIZE); |
254 | to zero by the VFS */ | 239 | #endif |
255 | /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/ | 240 | /* |
241 | * Can not set i_flags here - they get immediately overwritten to zero | ||
242 | * by the VFS. | ||
243 | */ | ||
244 | /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME; */ | ||
256 | INIT_LIST_HEAD(&cifs_inode->openFileList); | 245 | INIT_LIST_HEAD(&cifs_inode->openFileList); |
246 | INIT_LIST_HEAD(&cifs_inode->llist); | ||
257 | return &cifs_inode->vfs_inode; | 247 | return &cifs_inode->vfs_inode; |
258 | } | 248 | } |
259 | 249 | ||
@@ -360,7 +350,8 @@ cifs_show_options(struct seq_file *s, struct dentry *root) | |||
360 | cifs_show_security(s, tcon->ses->server); | 350 | cifs_show_security(s, tcon->ses->server); |
361 | cifs_show_cache_flavor(s, cifs_sb); | 351 | cifs_show_cache_flavor(s, cifs_sb); |
362 | 352 | ||
363 | seq_printf(s, ",unc=%s", tcon->treeName); | 353 | seq_printf(s, ",unc="); |
354 | seq_escape(s, tcon->treeName, " \t\n\\"); | ||
364 | 355 | ||
365 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) | 356 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) |
366 | seq_printf(s, ",multiuser"); | 357 | seq_printf(s, ",multiuser"); |
@@ -957,7 +948,7 @@ cifs_init_once(void *inode) | |||
957 | struct cifsInodeInfo *cifsi = inode; | 948 | struct cifsInodeInfo *cifsi = inode; |
958 | 949 | ||
959 | inode_init_once(&cifsi->vfs_inode); | 950 | inode_init_once(&cifsi->vfs_inode); |
960 | mutex_init(&cifsi->lock_mutex); | 951 | init_rwsem(&cifsi->lock_sem); |
961 | } | 952 | } |
962 | 953 | ||
963 | static int | 954 | static int |
@@ -1132,6 +1123,10 @@ init_cifs(void) | |||
1132 | spin_lock_init(&cifs_file_list_lock); | 1123 | spin_lock_init(&cifs_file_list_lock); |
1133 | spin_lock_init(&GlobalMid_Lock); | 1124 | spin_lock_init(&GlobalMid_Lock); |
1134 | 1125 | ||
1126 | #ifdef CONFIG_CIFS_SMB2 | ||
1127 | get_random_bytes(cifs_client_guid, SMB2_CLIENT_GUID_SIZE); | ||
1128 | #endif | ||
1129 | |||
1135 | if (cifs_max_pending < 2) { | 1130 | if (cifs_max_pending < 2) { |
1136 | cifs_max_pending = 2; | 1131 | cifs_max_pending = 2; |
1137 | cFYI(1, "cifs_max_pending set to min of 2"); | 1132 | cFYI(1, "cifs_max_pending set to min of 2"); |
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index 1c49c5a9b27a..7163419cecd9 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h | |||
@@ -128,5 +128,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); | |||
128 | extern const struct export_operations cifs_export_ops; | 128 | extern const struct export_operations cifs_export_ops; |
129 | #endif /* CONFIG_CIFS_NFSD_EXPORT */ | 129 | #endif /* CONFIG_CIFS_NFSD_EXPORT */ |
130 | 130 | ||
131 | #define CIFS_VERSION "1.78" | 131 | #define CIFS_VERSION "2.0" |
132 | #endif /* _CIFSFS_H */ | 132 | #endif /* _CIFSFS_H */ |
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 977dc0e85ccb..f5af2527fc69 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
@@ -32,6 +32,8 @@ | |||
32 | #include "smb2pdu.h" | 32 | #include "smb2pdu.h" |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ | ||
36 | |||
35 | /* | 37 | /* |
36 | * The sizes of various internal tables and strings | 38 | * The sizes of various internal tables and strings |
37 | */ | 39 | */ |
@@ -128,8 +130,10 @@ struct sdesc { | |||
128 | struct cifs_secmech { | 130 | struct cifs_secmech { |
129 | struct crypto_shash *hmacmd5; /* hmac-md5 hash function */ | 131 | struct crypto_shash *hmacmd5; /* hmac-md5 hash function */ |
130 | struct crypto_shash *md5; /* md5 hash function */ | 132 | struct crypto_shash *md5; /* md5 hash function */ |
133 | struct crypto_shash *hmacsha256; /* hmac-sha256 hash function */ | ||
131 | struct sdesc *sdeschmacmd5; /* ctxt to generate ntlmv2 hash, CR1 */ | 134 | struct sdesc *sdeschmacmd5; /* ctxt to generate ntlmv2 hash, CR1 */ |
132 | struct sdesc *sdescmd5; /* ctxt to generate cifs/smb signature */ | 135 | struct sdesc *sdescmd5; /* ctxt to generate cifs/smb signature */ |
136 | struct sdesc *sdeschmacsha256; /* ctxt to generate smb2 signature */ | ||
133 | }; | 137 | }; |
134 | 138 | ||
135 | /* per smb session structure/fields */ | 139 | /* per smb session structure/fields */ |
@@ -158,9 +162,24 @@ struct cifs_cred { | |||
158 | ***************************************************************** | 162 | ***************************************************************** |
159 | */ | 163 | */ |
160 | 164 | ||
165 | /* | ||
166 | * A smb_rqst represents a complete request to be issued to a server. It's | ||
167 | * formed by a kvec array, followed by an array of pages. Page data is assumed | ||
168 | * to start at the beginning of the first page. | ||
169 | */ | ||
170 | struct smb_rqst { | ||
171 | struct kvec *rq_iov; /* array of kvecs */ | ||
172 | unsigned int rq_nvec; /* number of kvecs in array */ | ||
173 | struct page **rq_pages; /* pointer to array of page ptrs */ | ||
174 | unsigned int rq_npages; /* number pages in array */ | ||
175 | unsigned int rq_pagesz; /* page size to use */ | ||
176 | unsigned int rq_tailsz; /* length of last page */ | ||
177 | }; | ||
178 | |||
161 | enum smb_version { | 179 | enum smb_version { |
162 | Smb_1 = 1, | 180 | Smb_1 = 1, |
163 | Smb_21, | 181 | Smb_21, |
182 | Smb_30, | ||
164 | }; | 183 | }; |
165 | 184 | ||
166 | struct mid_q_entry; | 185 | struct mid_q_entry; |
@@ -171,17 +190,23 @@ struct cifs_tcon; | |||
171 | struct dfs_info3_param; | 190 | struct dfs_info3_param; |
172 | struct cifs_fattr; | 191 | struct cifs_fattr; |
173 | struct smb_vol; | 192 | struct smb_vol; |
193 | struct cifs_fid; | ||
194 | struct cifs_readdata; | ||
195 | struct cifs_writedata; | ||
196 | struct cifs_io_parms; | ||
197 | struct cifs_search_info; | ||
198 | struct cifsInodeInfo; | ||
174 | 199 | ||
175 | struct smb_version_operations { | 200 | struct smb_version_operations { |
176 | int (*send_cancel)(struct TCP_Server_Info *, void *, | 201 | int (*send_cancel)(struct TCP_Server_Info *, void *, |
177 | struct mid_q_entry *); | 202 | struct mid_q_entry *); |
178 | bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *); | 203 | bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *); |
179 | /* setup request: allocate mid, sign message */ | 204 | /* setup request: allocate mid, sign message */ |
180 | int (*setup_request)(struct cifs_ses *, struct kvec *, unsigned int, | 205 | struct mid_q_entry *(*setup_request)(struct cifs_ses *, |
181 | struct mid_q_entry **); | 206 | struct smb_rqst *); |
182 | /* setup async request: allocate mid, sign message */ | 207 | /* setup async request: allocate mid, sign message */ |
183 | int (*setup_async_request)(struct TCP_Server_Info *, struct kvec *, | 208 | struct mid_q_entry *(*setup_async_request)(struct TCP_Server_Info *, |
184 | unsigned int, struct mid_q_entry **); | 209 | struct smb_rqst *); |
185 | /* check response: verify signature, map error */ | 210 | /* check response: verify signature, map error */ |
186 | int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *, | 211 | int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *, |
187 | bool); | 212 | bool); |
@@ -212,6 +237,10 @@ struct smb_version_operations { | |||
212 | bool (*need_neg)(struct TCP_Server_Info *); | 237 | bool (*need_neg)(struct TCP_Server_Info *); |
213 | /* negotiate to the server */ | 238 | /* negotiate to the server */ |
214 | int (*negotiate)(const unsigned int, struct cifs_ses *); | 239 | int (*negotiate)(const unsigned int, struct cifs_ses *); |
240 | /* set negotiated write size */ | ||
241 | unsigned int (*negotiate_wsize)(struct cifs_tcon *, struct smb_vol *); | ||
242 | /* set negotiated read size */ | ||
243 | unsigned int (*negotiate_rsize)(struct cifs_tcon *, struct smb_vol *); | ||
215 | /* setup smb sessionn */ | 244 | /* setup smb sessionn */ |
216 | int (*sess_setup)(const unsigned int, struct cifs_ses *, | 245 | int (*sess_setup)(const unsigned int, struct cifs_ses *, |
217 | const struct nls_table *); | 246 | const struct nls_table *); |
@@ -235,10 +264,22 @@ struct smb_version_operations { | |||
235 | int (*query_path_info)(const unsigned int, struct cifs_tcon *, | 264 | int (*query_path_info)(const unsigned int, struct cifs_tcon *, |
236 | struct cifs_sb_info *, const char *, | 265 | struct cifs_sb_info *, const char *, |
237 | FILE_ALL_INFO *, bool *); | 266 | FILE_ALL_INFO *, bool *); |
267 | /* query file data from the server */ | ||
268 | int (*query_file_info)(const unsigned int, struct cifs_tcon *, | ||
269 | struct cifs_fid *, FILE_ALL_INFO *); | ||
238 | /* get server index number */ | 270 | /* get server index number */ |
239 | int (*get_srv_inum)(const unsigned int, struct cifs_tcon *, | 271 | int (*get_srv_inum)(const unsigned int, struct cifs_tcon *, |
240 | struct cifs_sb_info *, const char *, | 272 | struct cifs_sb_info *, const char *, |
241 | u64 *uniqueid, FILE_ALL_INFO *); | 273 | u64 *uniqueid, FILE_ALL_INFO *); |
274 | /* set size by path */ | ||
275 | int (*set_path_size)(const unsigned int, struct cifs_tcon *, | ||
276 | const char *, __u64, struct cifs_sb_info *, bool); | ||
277 | /* set size by file handle */ | ||
278 | int (*set_file_size)(const unsigned int, struct cifs_tcon *, | ||
279 | struct cifsFileInfo *, __u64, bool); | ||
280 | /* set attributes */ | ||
281 | int (*set_file_info)(struct inode *, const char *, FILE_BASIC_INFO *, | ||
282 | const unsigned int); | ||
242 | /* build a full path to the root of the mount */ | 283 | /* build a full path to the root of the mount */ |
243 | char * (*build_path_to_root)(struct smb_vol *, struct cifs_sb_info *, | 284 | char * (*build_path_to_root)(struct smb_vol *, struct cifs_sb_info *, |
244 | struct cifs_tcon *); | 285 | struct cifs_tcon *); |
@@ -256,10 +297,84 @@ struct smb_version_operations { | |||
256 | /* remove directory */ | 297 | /* remove directory */ |
257 | int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *, | 298 | int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *, |
258 | struct cifs_sb_info *); | 299 | struct cifs_sb_info *); |
300 | /* unlink file */ | ||
301 | int (*unlink)(const unsigned int, struct cifs_tcon *, const char *, | ||
302 | struct cifs_sb_info *); | ||
303 | /* open, rename and delete file */ | ||
304 | int (*rename_pending_delete)(const char *, struct dentry *, | ||
305 | const unsigned int); | ||
306 | /* send rename request */ | ||
307 | int (*rename)(const unsigned int, struct cifs_tcon *, const char *, | ||
308 | const char *, struct cifs_sb_info *); | ||
309 | /* send create hardlink request */ | ||
310 | int (*create_hardlink)(const unsigned int, struct cifs_tcon *, | ||
311 | const char *, const char *, | ||
312 | struct cifs_sb_info *); | ||
313 | /* open a file for non-posix mounts */ | ||
314 | int (*open)(const unsigned int, struct cifs_tcon *, const char *, int, | ||
315 | int, int, struct cifs_fid *, __u32 *, FILE_ALL_INFO *, | ||
316 | struct cifs_sb_info *); | ||
317 | /* set fid protocol-specific info */ | ||
318 | void (*set_fid)(struct cifsFileInfo *, struct cifs_fid *, __u32); | ||
319 | /* close a file */ | ||
320 | void (*close)(const unsigned int, struct cifs_tcon *, | ||
321 | struct cifs_fid *); | ||
322 | /* send a flush request to the server */ | ||
323 | int (*flush)(const unsigned int, struct cifs_tcon *, struct cifs_fid *); | ||
324 | /* async read from the server */ | ||
325 | int (*async_readv)(struct cifs_readdata *); | ||
326 | /* async write to the server */ | ||
327 | int (*async_writev)(struct cifs_writedata *); | ||
328 | /* sync read from the server */ | ||
329 | int (*sync_read)(const unsigned int, struct cifsFileInfo *, | ||
330 | struct cifs_io_parms *, unsigned int *, char **, | ||
331 | int *); | ||
332 | /* sync write to the server */ | ||
333 | int (*sync_write)(const unsigned int, struct cifsFileInfo *, | ||
334 | struct cifs_io_parms *, unsigned int *, struct kvec *, | ||
335 | unsigned long); | ||
336 | /* open dir, start readdir */ | ||
337 | int (*query_dir_first)(const unsigned int, struct cifs_tcon *, | ||
338 | const char *, struct cifs_sb_info *, | ||
339 | struct cifs_fid *, __u16, | ||
340 | struct cifs_search_info *); | ||
341 | /* continue readdir */ | ||
342 | int (*query_dir_next)(const unsigned int, struct cifs_tcon *, | ||
343 | struct cifs_fid *, | ||
344 | __u16, struct cifs_search_info *srch_inf); | ||
345 | /* close dir */ | ||
346 | int (*close_dir)(const unsigned int, struct cifs_tcon *, | ||
347 | struct cifs_fid *); | ||
348 | /* calculate a size of SMB message */ | ||
349 | unsigned int (*calc_smb_size)(void *); | ||
350 | /* check for STATUS_PENDING and process it in a positive case */ | ||
351 | bool (*is_status_pending)(char *, struct TCP_Server_Info *, int); | ||
352 | /* send oplock break response */ | ||
353 | int (*oplock_response)(struct cifs_tcon *, struct cifs_fid *, | ||
354 | struct cifsInodeInfo *); | ||
355 | /* query remote filesystem */ | ||
356 | int (*queryfs)(const unsigned int, struct cifs_tcon *, | ||
357 | struct kstatfs *); | ||
358 | /* send mandatory brlock to the server */ | ||
359 | int (*mand_lock)(const unsigned int, struct cifsFileInfo *, __u64, | ||
360 | __u64, __u32, int, int, bool); | ||
361 | /* unlock range of mandatory locks */ | ||
362 | int (*mand_unlock_range)(struct cifsFileInfo *, struct file_lock *, | ||
363 | const unsigned int); | ||
364 | /* push brlocks from the cache to the server */ | ||
365 | int (*push_mand_locks)(struct cifsFileInfo *); | ||
366 | /* get lease key of the inode */ | ||
367 | void (*get_lease_key)(struct inode *, struct cifs_fid *fid); | ||
368 | /* set lease key of the inode */ | ||
369 | void (*set_lease_key)(struct inode *, struct cifs_fid *fid); | ||
370 | /* generate new lease key */ | ||
371 | void (*new_lease_key)(struct cifs_fid *fid); | ||
259 | }; | 372 | }; |
260 | 373 | ||
261 | struct smb_version_values { | 374 | struct smb_version_values { |
262 | char *version_string; | 375 | char *version_string; |
376 | __u16 protocol_id; | ||
377 | __u32 req_capabilities; | ||
263 | __u32 large_lock_type; | 378 | __u32 large_lock_type; |
264 | __u32 exclusive_lock_type; | 379 | __u32 exclusive_lock_type; |
265 | __u32 shared_lock_type; | 380 | __u32 shared_lock_type; |
@@ -496,6 +611,51 @@ get_next_mid(struct TCP_Server_Info *server) | |||
496 | } | 611 | } |
497 | 612 | ||
498 | /* | 613 | /* |
614 | * When the server supports very large reads and writes via POSIX extensions, | ||
615 | * we can allow up to 2^24-1, minus the size of a READ/WRITE_AND_X header, not | ||
616 | * including the RFC1001 length. | ||
617 | * | ||
618 | * Note that this might make for "interesting" allocation problems during | ||
619 | * writeback however as we have to allocate an array of pointers for the | ||
620 | * pages. A 16M write means ~32kb page array with PAGE_CACHE_SIZE == 4096. | ||
621 | * | ||
622 | * For reads, there is a similar problem as we need to allocate an array | ||
623 | * of kvecs to handle the receive, though that should only need to be done | ||
624 | * once. | ||
625 | */ | ||
626 | #define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4) | ||
627 | #define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4) | ||
628 | |||
629 | /* | ||
630 | * When the server doesn't allow large posix writes, only allow a rsize/wsize | ||
631 | * of 2^17-1 minus the size of the call header. That allows for a read or | ||
632 | * write up to the maximum size described by RFC1002. | ||
633 | */ | ||
634 | #define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4) | ||
635 | #define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4) | ||
636 | |||
637 | /* | ||
638 | * The default wsize is 1M. find_get_pages seems to return a maximum of 256 | ||
639 | * pages in a single call. With PAGE_CACHE_SIZE == 4k, this means we can fill | ||
640 | * a single wsize request with a single call. | ||
641 | */ | ||
642 | #define CIFS_DEFAULT_IOSIZE (1024 * 1024) | ||
643 | |||
644 | /* | ||
645 | * Windows only supports a max of 60kb reads and 65535 byte writes. Default to | ||
646 | * those values when posix extensions aren't in force. In actuality here, we | ||
647 | * use 65536 to allow for a write that is a multiple of 4k. Most servers seem | ||
648 | * to be ok with the extra byte even though Windows doesn't send writes that | ||
649 | * are that large. | ||
650 | * | ||
651 | * Citation: | ||
652 | * | ||
653 | * http://blogs.msdn.com/b/openspecification/archive/2009/04/10/smb-maximum-transmit-buffer-size-and-performance-tuning.aspx | ||
654 | */ | ||
655 | #define CIFS_DEFAULT_NON_POSIX_RSIZE (60 * 1024) | ||
656 | #define CIFS_DEFAULT_NON_POSIX_WSIZE (65536) | ||
657 | |||
658 | /* | ||
499 | * Macros to allow the TCP_Server_Info->net field and related code to drop out | 659 | * Macros to allow the TCP_Server_Info->net field and related code to drop out |
500 | * when CONFIG_NET_NS isn't set. | 660 | * when CONFIG_NET_NS isn't set. |
501 | */ | 661 | */ |
@@ -559,6 +719,7 @@ struct cifs_ses { | |||
559 | __u16 session_flags; | 719 | __u16 session_flags; |
560 | #endif /* CONFIG_CIFS_SMB2 */ | 720 | #endif /* CONFIG_CIFS_SMB2 */ |
561 | }; | 721 | }; |
722 | |||
562 | /* no more than one of the following three session flags may be set */ | 723 | /* no more than one of the following three session flags may be set */ |
563 | #define CIFS_SES_NT4 1 | 724 | #define CIFS_SES_NT4 1 |
564 | #define CIFS_SES_OS2 2 | 725 | #define CIFS_SES_OS2 2 |
@@ -665,6 +826,7 @@ struct cifs_tcon { | |||
665 | u64 resource_id; /* server resource id */ | 826 | u64 resource_id; /* server resource id */ |
666 | struct fscache_cookie *fscache; /* cookie for share */ | 827 | struct fscache_cookie *fscache; /* cookie for share */ |
667 | #endif | 828 | #endif |
829 | struct list_head pending_opens; /* list of incomplete opens */ | ||
668 | /* BB add field for back pointer to sb struct(s)? */ | 830 | /* BB add field for back pointer to sb struct(s)? */ |
669 | }; | 831 | }; |
670 | 832 | ||
@@ -707,6 +869,15 @@ cifs_get_tlink(struct tcon_link *tlink) | |||
707 | /* This function is always expected to succeed */ | 869 | /* This function is always expected to succeed */ |
708 | extern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb); | 870 | extern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb); |
709 | 871 | ||
872 | #define CIFS_OPLOCK_NO_CHANGE 0xfe | ||
873 | |||
874 | struct cifs_pending_open { | ||
875 | struct list_head olist; | ||
876 | struct tcon_link *tlink; | ||
877 | __u8 lease_key[16]; | ||
878 | __u32 oplock; | ||
879 | }; | ||
880 | |||
710 | /* | 881 | /* |
711 | * This info hangs off the cifsFileInfo structure, pointed to by llist. | 882 | * This info hangs off the cifsFileInfo structure, pointed to by llist. |
712 | * This is used to track byte stream locks on the file | 883 | * This is used to track byte stream locks on the file |
@@ -740,16 +911,29 @@ struct cifs_search_info { | |||
740 | bool smallBuf:1; /* so we know which buf_release function to call */ | 911 | bool smallBuf:1; /* so we know which buf_release function to call */ |
741 | }; | 912 | }; |
742 | 913 | ||
914 | struct cifs_fid { | ||
915 | __u16 netfid; | ||
916 | #ifdef CONFIG_CIFS_SMB2 | ||
917 | __u64 persistent_fid; /* persist file id for smb2 */ | ||
918 | __u64 volatile_fid; /* volatile file id for smb2 */ | ||
919 | __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for smb2 */ | ||
920 | #endif | ||
921 | struct cifs_pending_open *pending_open; | ||
922 | }; | ||
923 | |||
924 | struct cifs_fid_locks { | ||
925 | struct list_head llist; | ||
926 | struct cifsFileInfo *cfile; /* fid that owns locks */ | ||
927 | struct list_head locks; /* locks held by fid above */ | ||
928 | }; | ||
929 | |||
743 | struct cifsFileInfo { | 930 | struct cifsFileInfo { |
744 | struct list_head tlist; /* pointer to next fid owned by tcon */ | 931 | struct list_head tlist; /* pointer to next fid owned by tcon */ |
745 | struct list_head flist; /* next fid (file instance) for this inode */ | 932 | struct list_head flist; /* next fid (file instance) for this inode */ |
746 | struct list_head llist; /* | 933 | struct cifs_fid_locks *llist; /* brlocks held by this fid */ |
747 | * brlocks held by this fid, protected by | ||
748 | * lock_mutex from cifsInodeInfo structure | ||
749 | */ | ||
750 | unsigned int uid; /* allows finding which FileInfo structure */ | 934 | unsigned int uid; /* allows finding which FileInfo structure */ |
751 | __u32 pid; /* process id who opened file */ | 935 | __u32 pid; /* process id who opened file */ |
752 | __u16 netfid; /* file id from remote */ | 936 | struct cifs_fid fid; /* file id from remote */ |
753 | /* BB add lock scope info here if needed */ ; | 937 | /* BB add lock scope info here if needed */ ; |
754 | /* lock scope id (0 if none) */ | 938 | /* lock scope id (0 if none) */ |
755 | struct dentry *dentry; | 939 | struct dentry *dentry; |
@@ -765,12 +949,60 @@ struct cifsFileInfo { | |||
765 | 949 | ||
766 | struct cifs_io_parms { | 950 | struct cifs_io_parms { |
767 | __u16 netfid; | 951 | __u16 netfid; |
952 | #ifdef CONFIG_CIFS_SMB2 | ||
953 | __u64 persistent_fid; /* persist file id for smb2 */ | ||
954 | __u64 volatile_fid; /* volatile file id for smb2 */ | ||
955 | #endif | ||
768 | __u32 pid; | 956 | __u32 pid; |
769 | __u64 offset; | 957 | __u64 offset; |
770 | unsigned int length; | 958 | unsigned int length; |
771 | struct cifs_tcon *tcon; | 959 | struct cifs_tcon *tcon; |
772 | }; | 960 | }; |
773 | 961 | ||
962 | struct cifs_readdata; | ||
963 | |||
964 | /* asynchronous read support */ | ||
965 | struct cifs_readdata { | ||
966 | struct kref refcount; | ||
967 | struct list_head list; | ||
968 | struct completion done; | ||
969 | struct cifsFileInfo *cfile; | ||
970 | struct address_space *mapping; | ||
971 | __u64 offset; | ||
972 | unsigned int bytes; | ||
973 | pid_t pid; | ||
974 | int result; | ||
975 | struct work_struct work; | ||
976 | int (*read_into_pages)(struct TCP_Server_Info *server, | ||
977 | struct cifs_readdata *rdata, | ||
978 | unsigned int len); | ||
979 | struct kvec iov; | ||
980 | unsigned int pagesz; | ||
981 | unsigned int tailsz; | ||
982 | unsigned int nr_pages; | ||
983 | struct page *pages[]; | ||
984 | }; | ||
985 | |||
986 | struct cifs_writedata; | ||
987 | |||
988 | /* asynchronous write support */ | ||
989 | struct cifs_writedata { | ||
990 | struct kref refcount; | ||
991 | struct list_head list; | ||
992 | struct completion done; | ||
993 | enum writeback_sync_modes sync_mode; | ||
994 | struct work_struct work; | ||
995 | struct cifsFileInfo *cfile; | ||
996 | __u64 offset; | ||
997 | pid_t pid; | ||
998 | unsigned int bytes; | ||
999 | int result; | ||
1000 | unsigned int pagesz; | ||
1001 | unsigned int tailsz; | ||
1002 | unsigned int nr_pages; | ||
1003 | struct page *pages[1]; | ||
1004 | }; | ||
1005 | |||
774 | /* | 1006 | /* |
775 | * Take a reference on the file private data. Must be called with | 1007 | * Take a reference on the file private data. Must be called with |
776 | * cifs_file_list_lock held. | 1008 | * cifs_file_list_lock held. |
@@ -790,11 +1022,8 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file); | |||
790 | 1022 | ||
791 | struct cifsInodeInfo { | 1023 | struct cifsInodeInfo { |
792 | bool can_cache_brlcks; | 1024 | bool can_cache_brlcks; |
793 | struct mutex lock_mutex; /* | 1025 | struct list_head llist; /* locks helb by this inode */ |
794 | * protect the field above and llist | 1026 | struct rw_semaphore lock_sem; /* protect the fields above */ |
795 | * from every cifsFileInfo structure | ||
796 | * from openFileList | ||
797 | */ | ||
798 | /* BB add in lists for dirty pages i.e. write caching info for oplock */ | 1027 | /* BB add in lists for dirty pages i.e. write caching info for oplock */ |
799 | struct list_head openFileList; | 1028 | struct list_head openFileList; |
800 | __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */ | 1029 | __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */ |
@@ -806,6 +1035,9 @@ struct cifsInodeInfo { | |||
806 | u64 server_eof; /* current file size on server -- protected by i_lock */ | 1035 | u64 server_eof; /* current file size on server -- protected by i_lock */ |
807 | u64 uniqueid; /* server inode number */ | 1036 | u64 uniqueid; /* server inode number */ |
808 | u64 createtime; /* creation time on server */ | 1037 | u64 createtime; /* creation time on server */ |
1038 | #ifdef CONFIG_CIFS_SMB2 | ||
1039 | __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for this inode */ | ||
1040 | #endif | ||
809 | #ifdef CONFIG_CIFS_FSCACHE | 1041 | #ifdef CONFIG_CIFS_FSCACHE |
810 | struct fscache_cookie *fscache; | 1042 | struct fscache_cookie *fscache; |
811 | #endif | 1043 | #endif |
@@ -1130,7 +1362,7 @@ require use of the stronger protocol */ | |||
1130 | #define CIFSSEC_MUST_SEAL 0x40040 /* not supported yet */ | 1362 | #define CIFSSEC_MUST_SEAL 0x40040 /* not supported yet */ |
1131 | #define CIFSSEC_MUST_NTLMSSP 0x80080 /* raw ntlmssp with ntlmv2 */ | 1363 | #define CIFSSEC_MUST_NTLMSSP 0x80080 /* raw ntlmssp with ntlmv2 */ |
1132 | 1364 | ||
1133 | #define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2) | 1365 | #define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_NTLMSSP) |
1134 | #define CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2) | 1366 | #define CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2) |
1135 | #define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP) | 1367 | #define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP) |
1136 | /* | 1368 | /* |
@@ -1267,7 +1499,13 @@ extern mempool_t *cifs_mid_poolp; | |||
1267 | #define SMB1_VERSION_STRING "1.0" | 1499 | #define SMB1_VERSION_STRING "1.0" |
1268 | extern struct smb_version_operations smb1_operations; | 1500 | extern struct smb_version_operations smb1_operations; |
1269 | extern struct smb_version_values smb1_values; | 1501 | extern struct smb_version_values smb1_values; |
1502 | #define SMB20_VERSION_STRING "2.0" | ||
1503 | /*extern struct smb_version_operations smb20_operations; */ /* not needed yet */ | ||
1504 | extern struct smb_version_values smb20_values; | ||
1270 | #define SMB21_VERSION_STRING "2.1" | 1505 | #define SMB21_VERSION_STRING "2.1" |
1271 | extern struct smb_version_operations smb21_operations; | 1506 | extern struct smb_version_operations smb21_operations; |
1272 | extern struct smb_version_values smb21_values; | 1507 | extern struct smb_version_values smb21_values; |
1508 | #define SMB30_VERSION_STRING "3.0" | ||
1509 | /*extern struct smb_version_operations smb30_operations; */ /* not needed yet */ | ||
1510 | extern struct smb_version_values smb30_values; | ||
1273 | #endif /* _CIFS_GLOB_H */ | 1511 | #endif /* _CIFS_GLOB_H */ |
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h index 3fb03e2c8e86..b9d59a948a2c 100644 --- a/fs/cifs/cifspdu.h +++ b/fs/cifs/cifspdu.h | |||
@@ -2210,7 +2210,7 @@ typedef struct { /* data block encoding of response to level 263 QPathInfo */ | |||
2210 | __u8 DeletePending; | 2210 | __u8 DeletePending; |
2211 | __u8 Directory; | 2211 | __u8 Directory; |
2212 | __u16 Pad2; | 2212 | __u16 Pad2; |
2213 | __u64 IndexNumber; | 2213 | __le64 IndexNumber; |
2214 | __le32 EASize; | 2214 | __le32 EASize; |
2215 | __le32 AccessFlags; | 2215 | __le32 AccessFlags; |
2216 | __u64 IndexNumber1; | 2216 | __u64 IndexNumber1; |
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index f1bbf8305d3a..5144e9fbeb8c 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | struct statfs; | 25 | struct statfs; |
26 | struct smb_vol; | 26 | struct smb_vol; |
27 | struct smb_rqst; | ||
27 | 28 | ||
28 | /* | 29 | /* |
29 | ***************************************************************** | 30 | ***************************************************************** |
@@ -35,6 +36,8 @@ extern struct smb_hdr *cifs_buf_get(void); | |||
35 | extern void cifs_buf_release(void *); | 36 | extern void cifs_buf_release(void *); |
36 | extern struct smb_hdr *cifs_small_buf_get(void); | 37 | extern struct smb_hdr *cifs_small_buf_get(void); |
37 | extern void cifs_small_buf_release(void *); | 38 | extern void cifs_small_buf_release(void *); |
39 | extern void cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx, | ||
40 | struct kvec *iov); | ||
38 | extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *, | 41 | extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *, |
39 | unsigned int /* length */); | 42 | unsigned int /* length */); |
40 | extern unsigned int _get_xid(void); | 43 | extern unsigned int _get_xid(void); |
@@ -65,21 +68,22 @@ extern char *cifs_compose_mount_options(const char *sb_mountdata, | |||
65 | extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer, | 68 | extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer, |
66 | struct TCP_Server_Info *server); | 69 | struct TCP_Server_Info *server); |
67 | extern void DeleteMidQEntry(struct mid_q_entry *midEntry); | 70 | extern void DeleteMidQEntry(struct mid_q_entry *midEntry); |
71 | extern void cifs_delete_mid(struct mid_q_entry *mid); | ||
68 | extern void cifs_wake_up_task(struct mid_q_entry *mid); | 72 | extern void cifs_wake_up_task(struct mid_q_entry *mid); |
69 | extern int cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, | 73 | extern int cifs_call_async(struct TCP_Server_Info *server, |
70 | unsigned int nvec, mid_receive_t *receive, | 74 | struct smb_rqst *rqst, |
71 | mid_callback_t *callback, void *cbdata, | 75 | mid_receive_t *receive, mid_callback_t *callback, |
72 | const int flags); | 76 | void *cbdata, const int flags); |
73 | extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *, | 77 | extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *, |
74 | struct smb_hdr * /* input */ , | 78 | struct smb_hdr * /* input */ , |
75 | struct smb_hdr * /* out */ , | 79 | struct smb_hdr * /* out */ , |
76 | int * /* bytes returned */ , const int); | 80 | int * /* bytes returned */ , const int); |
77 | extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, | 81 | extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, |
78 | char *in_buf, int flags); | 82 | char *in_buf, int flags); |
79 | extern int cifs_setup_request(struct cifs_ses *, struct kvec *, unsigned int, | 83 | extern struct mid_q_entry *cifs_setup_request(struct cifs_ses *, |
80 | struct mid_q_entry **); | 84 | struct smb_rqst *); |
81 | extern int cifs_setup_async_request(struct TCP_Server_Info *, struct kvec *, | 85 | extern struct mid_q_entry *cifs_setup_async_request(struct TCP_Server_Info *, |
82 | unsigned int, struct mid_q_entry **); | 86 | struct smb_rqst *); |
83 | extern int cifs_check_receive(struct mid_q_entry *mid, | 87 | extern int cifs_check_receive(struct mid_q_entry *mid, |
84 | struct TCP_Server_Info *server, bool log_error); | 88 | struct TCP_Server_Info *server, bool log_error); |
85 | extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, | 89 | extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, |
@@ -99,7 +103,7 @@ extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, | |||
99 | unsigned int bytes_written); | 103 | unsigned int bytes_written); |
100 | extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); | 104 | extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); |
101 | extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); | 105 | extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); |
102 | extern unsigned int smbCalcSize(struct smb_hdr *ptr); | 106 | extern unsigned int smbCalcSize(void *buf); |
103 | extern int decode_negTokenInit(unsigned char *security_blob, int length, | 107 | extern int decode_negTokenInit(unsigned char *security_blob, int length, |
104 | struct TCP_Server_Info *server); | 108 | struct TCP_Server_Info *server); |
105 | extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len); | 109 | extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len); |
@@ -120,10 +124,14 @@ extern u64 cifs_UnixTimeToNT(struct timespec); | |||
120 | extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, | 124 | extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, |
121 | int offset); | 125 | int offset); |
122 | extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock); | 126 | extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock); |
123 | 127 | extern int cifs_unlock_range(struct cifsFileInfo *cfile, | |
124 | extern struct cifsFileInfo *cifs_new_fileinfo(__u16 fileHandle, | 128 | struct file_lock *flock, const unsigned int xid); |
125 | struct file *file, struct tcon_link *tlink, | 129 | extern int cifs_push_mandatory_locks(struct cifsFileInfo *cfile); |
126 | __u32 oplock); | 130 | |
131 | extern struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, | ||
132 | struct file *file, | ||
133 | struct tcon_link *tlink, | ||
134 | __u32 oplock); | ||
127 | extern int cifs_posix_open(char *full_path, struct inode **inode, | 135 | extern int cifs_posix_open(char *full_path, struct inode **inode, |
128 | struct super_block *sb, int mode, | 136 | struct super_block *sb, int mode, |
129 | unsigned int f_flags, __u32 *oplock, __u16 *netfid, | 137 | unsigned int f_flags, __u32 *oplock, __u16 *netfid, |
@@ -132,18 +140,23 @@ void cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr); | |||
132 | extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, | 140 | extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, |
133 | FILE_UNIX_BASIC_INFO *info, | 141 | FILE_UNIX_BASIC_INFO *info, |
134 | struct cifs_sb_info *cifs_sb); | 142 | struct cifs_sb_info *cifs_sb); |
143 | extern void cifs_dir_info_to_fattr(struct cifs_fattr *, FILE_DIRECTORY_INFO *, | ||
144 | struct cifs_sb_info *); | ||
135 | extern void cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr); | 145 | extern void cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr); |
136 | extern struct inode *cifs_iget(struct super_block *sb, | 146 | extern struct inode *cifs_iget(struct super_block *sb, |
137 | struct cifs_fattr *fattr); | 147 | struct cifs_fattr *fattr); |
138 | 148 | ||
139 | extern int cifs_get_file_info(struct file *filp); | ||
140 | extern int cifs_get_inode_info(struct inode **inode, const char *full_path, | 149 | extern int cifs_get_inode_info(struct inode **inode, const char *full_path, |
141 | FILE_ALL_INFO *data, struct super_block *sb, | 150 | FILE_ALL_INFO *data, struct super_block *sb, |
142 | int xid, const __u16 *fid); | 151 | int xid, const __u16 *fid); |
143 | extern int cifs_get_file_info_unix(struct file *filp); | ||
144 | extern int cifs_get_inode_info_unix(struct inode **pinode, | 152 | extern int cifs_get_inode_info_unix(struct inode **pinode, |
145 | const unsigned char *search_path, | 153 | const unsigned char *search_path, |
146 | struct super_block *sb, unsigned int xid); | 154 | struct super_block *sb, unsigned int xid); |
155 | extern int cifs_set_file_info(struct inode *inode, struct iattr *attrs, | ||
156 | unsigned int xid, char *full_path, __u32 dosattr); | ||
157 | extern int cifs_rename_pending_delete(const char *full_path, | ||
158 | struct dentry *dentry, | ||
159 | const unsigned int xid); | ||
147 | extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, | 160 | extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, |
148 | struct cifs_fattr *fattr, struct inode *inode, | 161 | struct cifs_fattr *fattr, struct inode *inode, |
149 | const char *path, const __u16 *pfid); | 162 | const char *path, const __u16 *pfid); |
@@ -169,6 +182,17 @@ extern struct smb_vol *cifs_get_volume_info(char *mount_data, | |||
169 | extern int cifs_mount(struct cifs_sb_info *, struct smb_vol *); | 182 | extern int cifs_mount(struct cifs_sb_info *, struct smb_vol *); |
170 | extern void cifs_umount(struct cifs_sb_info *); | 183 | extern void cifs_umount(struct cifs_sb_info *); |
171 | extern void cifs_mark_open_files_invalid(struct cifs_tcon *tcon); | 184 | extern void cifs_mark_open_files_invalid(struct cifs_tcon *tcon); |
185 | extern bool cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, | ||
186 | __u64 length, __u8 type, | ||
187 | struct cifsLockInfo **conf_lock, | ||
188 | bool rw_check); | ||
189 | extern void cifs_add_pending_open(struct cifs_fid *fid, | ||
190 | struct tcon_link *tlink, | ||
191 | struct cifs_pending_open *open); | ||
192 | extern void cifs_add_pending_open_locked(struct cifs_fid *fid, | ||
193 | struct tcon_link *tlink, | ||
194 | struct cifs_pending_open *open); | ||
195 | extern void cifs_del_pending_open(struct cifs_pending_open *open); | ||
172 | 196 | ||
173 | #if IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) | 197 | #if IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) |
174 | extern void cifs_dfs_release_automount_timer(void); | 198 | extern void cifs_dfs_release_automount_timer(void); |
@@ -179,6 +203,10 @@ extern void cifs_dfs_release_automount_timer(void); | |||
179 | void cifs_proc_init(void); | 203 | void cifs_proc_init(void); |
180 | void cifs_proc_clean(void); | 204 | void cifs_proc_clean(void); |
181 | 205 | ||
206 | extern void cifs_move_llist(struct list_head *source, struct list_head *dest); | ||
207 | extern void cifs_free_llist(struct list_head *llist); | ||
208 | extern void cifs_del_lock_waiters(struct cifsLockInfo *lock); | ||
209 | |||
182 | extern int cifs_negotiate_protocol(const unsigned int xid, | 210 | extern int cifs_negotiate_protocol(const unsigned int xid, |
183 | struct cifs_ses *ses); | 211 | struct cifs_ses *ses); |
184 | extern int cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, | 212 | extern int cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, |
@@ -190,10 +218,10 @@ extern int CIFSTCon(const unsigned int xid, struct cifs_ses *ses, | |||
190 | const struct nls_table *); | 218 | const struct nls_table *); |
191 | 219 | ||
192 | extern int CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, | 220 | extern int CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, |
193 | const char *searchName, const struct nls_table *nls_codepage, | 221 | const char *searchName, struct cifs_sb_info *cifs_sb, |
194 | __u16 *searchHandle, __u16 search_flags, | 222 | __u16 *searchHandle, __u16 search_flags, |
195 | struct cifs_search_info *psrch_inf, | 223 | struct cifs_search_info *psrch_inf, |
196 | int map, const char dirsep); | 224 | bool msearch); |
197 | 225 | ||
198 | extern int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, | 226 | extern int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, |
199 | __u16 searchHandle, __u16 search_flags, | 227 | __u16 searchHandle, __u16 search_flags, |
@@ -265,13 +293,11 @@ extern int CIFSSMBSetAttrLegacy(unsigned int xid, struct cifs_tcon *tcon, | |||
265 | const struct nls_table *nls_codepage); | 293 | const struct nls_table *nls_codepage); |
266 | #endif /* possibly unneeded function */ | 294 | #endif /* possibly unneeded function */ |
267 | extern int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, | 295 | extern int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, |
268 | const char *fileName, __u64 size, | 296 | const char *file_name, __u64 size, |
269 | bool setAllocationSizeFlag, | 297 | struct cifs_sb_info *cifs_sb, bool set_allocation); |
270 | const struct nls_table *nls_codepage, | ||
271 | int remap_special_chars); | ||
272 | extern int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, | 298 | extern int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, |
273 | __u64 size, __u16 fileHandle, __u32 opener_pid, | 299 | struct cifsFileInfo *cfile, __u64 size, |
274 | bool AllocSizeFlag); | 300 | bool set_allocation); |
275 | 301 | ||
276 | struct cifs_unix_set_info_args { | 302 | struct cifs_unix_set_info_args { |
277 | __u64 ctime; | 303 | __u64 ctime; |
@@ -303,22 +329,17 @@ extern int CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, | |||
303 | const struct nls_table *nls_codepage, | 329 | const struct nls_table *nls_codepage, |
304 | int remap_special_chars); | 330 | int remap_special_chars); |
305 | extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, | 331 | extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, |
306 | const char *name, | 332 | const char *name, struct cifs_sb_info *cifs_sb); |
307 | const struct nls_table *nls_codepage, | ||
308 | int remap_special_chars); | ||
309 | extern int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, | 333 | extern int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, |
310 | const char *fromName, const char *toName, | 334 | const char *from_name, const char *to_name, |
311 | const struct nls_table *nls_codepage, | 335 | struct cifs_sb_info *cifs_sb); |
312 | int remap_special_chars); | ||
313 | extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *tcon, | 336 | extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *tcon, |
314 | int netfid, const char *target_name, | 337 | int netfid, const char *target_name, |
315 | const struct nls_table *nls_codepage, | 338 | const struct nls_table *nls_codepage, |
316 | int remap_special_chars); | 339 | int remap_special_chars); |
317 | extern int CIFSCreateHardLink(const unsigned int xid, | 340 | extern int CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
318 | struct cifs_tcon *tcon, | 341 | const char *from_name, const char *to_name, |
319 | const char *fromName, const char *toName, | 342 | struct cifs_sb_info *cifs_sb); |
320 | const struct nls_table *nls_codepage, | ||
321 | int remap_special_chars); | ||
322 | extern int CIFSUnixCreateHardLink(const unsigned int xid, | 343 | extern int CIFSUnixCreateHardLink(const unsigned int xid, |
323 | struct cifs_tcon *tcon, | 344 | struct cifs_tcon *tcon, |
324 | const char *fromName, const char *toName, | 345 | const char *fromName, const char *toName, |
@@ -367,8 +388,7 @@ extern int CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, | |||
367 | unsigned int *nbytes, const char *buf, | 388 | unsigned int *nbytes, const char *buf, |
368 | const char __user *ubuf, const int long_op); | 389 | const char __user *ubuf, const int long_op); |
369 | extern int CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, | 390 | extern int CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, |
370 | unsigned int *nbytes, struct kvec *iov, const int nvec, | 391 | unsigned int *nbytes, struct kvec *iov, const int nvec); |
371 | const int long_op); | ||
372 | extern int CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, | 392 | extern int CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, |
373 | const char *search_name, __u64 *inode_number, | 393 | const char *search_name, __u64 *inode_number, |
374 | const struct nls_table *nls_codepage, | 394 | const struct nls_table *nls_codepage, |
@@ -397,10 +417,12 @@ extern void sesInfoFree(struct cifs_ses *); | |||
397 | extern struct cifs_tcon *tconInfoAlloc(void); | 417 | extern struct cifs_tcon *tconInfoAlloc(void); |
398 | extern void tconInfoFree(struct cifs_tcon *); | 418 | extern void tconInfoFree(struct cifs_tcon *); |
399 | 419 | ||
400 | extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *); | 420 | extern int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, |
421 | __u32 *pexpected_response_sequence_number); | ||
401 | extern int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *, | 422 | extern int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *, |
402 | __u32 *); | 423 | __u32 *); |
403 | extern int cifs_verify_signature(struct kvec *iov, unsigned int nr_iov, | 424 | extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *); |
425 | extern int cifs_verify_signature(struct smb_rqst *rqst, | ||
404 | struct TCP_Server_Info *server, | 426 | struct TCP_Server_Info *server, |
405 | __u32 expected_sequence_number); | 427 | __u32 expected_sequence_number); |
406 | extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *, | 428 | extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *, |
@@ -462,45 +484,9 @@ extern int E_md4hash(const unsigned char *passwd, unsigned char *p16, | |||
462 | extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8, | 484 | extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8, |
463 | unsigned char *p24); | 485 | unsigned char *p24); |
464 | 486 | ||
465 | /* asynchronous read support */ | ||
466 | struct cifs_readdata { | ||
467 | struct kref refcount; | ||
468 | struct list_head list; | ||
469 | struct completion done; | ||
470 | struct cifsFileInfo *cfile; | ||
471 | struct address_space *mapping; | ||
472 | __u64 offset; | ||
473 | unsigned int bytes; | ||
474 | pid_t pid; | ||
475 | int result; | ||
476 | struct list_head pages; | ||
477 | struct work_struct work; | ||
478 | int (*marshal_iov) (struct cifs_readdata *rdata, | ||
479 | unsigned int remaining); | ||
480 | unsigned int nr_iov; | ||
481 | struct kvec iov[1]; | ||
482 | }; | ||
483 | |||
484 | void cifs_readdata_release(struct kref *refcount); | 487 | void cifs_readdata_release(struct kref *refcount); |
485 | int cifs_async_readv(struct cifs_readdata *rdata); | 488 | int cifs_async_readv(struct cifs_readdata *rdata); |
486 | 489 | int cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid); | |
487 | /* asynchronous write support */ | ||
488 | struct cifs_writedata { | ||
489 | struct kref refcount; | ||
490 | struct list_head list; | ||
491 | struct completion done; | ||
492 | enum writeback_sync_modes sync_mode; | ||
493 | struct work_struct work; | ||
494 | struct cifsFileInfo *cfile; | ||
495 | __u64 offset; | ||
496 | pid_t pid; | ||
497 | unsigned int bytes; | ||
498 | int result; | ||
499 | void (*marshal_iov) (struct kvec *iov, | ||
500 | struct cifs_writedata *wdata); | ||
501 | unsigned int nr_pages; | ||
502 | struct page *pages[1]; | ||
503 | }; | ||
504 | 490 | ||
505 | int cifs_async_writev(struct cifs_writedata *wdata); | 491 | int cifs_async_writev(struct cifs_writedata *wdata); |
506 | void cifs_writev_complete(struct work_struct *work); | 492 | void cifs_writev_complete(struct work_struct *work); |
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index f0cf934ba877..76d0d2998850 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
@@ -86,32 +86,6 @@ static struct { | |||
86 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ | 86 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
87 | #endif /* CIFS_POSIX */ | 87 | #endif /* CIFS_POSIX */ |
88 | 88 | ||
89 | #ifdef CONFIG_HIGHMEM | ||
90 | /* | ||
91 | * On arches that have high memory, kmap address space is limited. By | ||
92 | * serializing the kmap operations on those arches, we ensure that we don't | ||
93 | * end up with a bunch of threads in writeback with partially mapped page | ||
94 | * arrays, stuck waiting for kmap to come back. That situation prevents | ||
95 | * progress and can deadlock. | ||
96 | */ | ||
97 | static DEFINE_MUTEX(cifs_kmap_mutex); | ||
98 | |||
99 | static inline void | ||
100 | cifs_kmap_lock(void) | ||
101 | { | ||
102 | mutex_lock(&cifs_kmap_mutex); | ||
103 | } | ||
104 | |||
105 | static inline void | ||
106 | cifs_kmap_unlock(void) | ||
107 | { | ||
108 | mutex_unlock(&cifs_kmap_mutex); | ||
109 | } | ||
110 | #else /* !CONFIG_HIGHMEM */ | ||
111 | #define cifs_kmap_lock() do { ; } while(0) | ||
112 | #define cifs_kmap_unlock() do { ; } while(0) | ||
113 | #endif /* CONFIG_HIGHMEM */ | ||
114 | |||
115 | /* | 89 | /* |
116 | * Mark as invalid, all open files on tree connections since they | 90 | * Mark as invalid, all open files on tree connections since they |
117 | * were closed when session to server was lost. | 91 | * were closed when session to server was lost. |
@@ -751,6 +725,8 @@ CIFSSMBEcho(struct TCP_Server_Info *server) | |||
751 | ECHO_REQ *smb; | 725 | ECHO_REQ *smb; |
752 | int rc = 0; | 726 | int rc = 0; |
753 | struct kvec iov; | 727 | struct kvec iov; |
728 | struct smb_rqst rqst = { .rq_iov = &iov, | ||
729 | .rq_nvec = 1 }; | ||
754 | 730 | ||
755 | cFYI(1, "In echo request"); | 731 | cFYI(1, "In echo request"); |
756 | 732 | ||
@@ -768,7 +744,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server) | |||
768 | iov.iov_base = smb; | 744 | iov.iov_base = smb; |
769 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; | 745 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
770 | 746 | ||
771 | rc = cifs_call_async(server, &iov, 1, NULL, cifs_echo_callback, | 747 | rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, |
772 | server, CIFS_ASYNC_OP | CIFS_ECHO_OP); | 748 | server, CIFS_ASYNC_OP | CIFS_ECHO_OP); |
773 | if (rc) | 749 | if (rc) |
774 | cFYI(1, "Echo request failed: %d", rc); | 750 | cFYI(1, "Echo request failed: %d", rc); |
@@ -902,15 +878,15 @@ PsxDelete: | |||
902 | } | 878 | } |
903 | 879 | ||
904 | int | 880 | int |
905 | CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, | 881 | CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
906 | const char *fileName, const struct nls_table *nls_codepage, | 882 | struct cifs_sb_info *cifs_sb) |
907 | int remap) | ||
908 | { | 883 | { |
909 | DELETE_FILE_REQ *pSMB = NULL; | 884 | DELETE_FILE_REQ *pSMB = NULL; |
910 | DELETE_FILE_RSP *pSMBr = NULL; | 885 | DELETE_FILE_RSP *pSMBr = NULL; |
911 | int rc = 0; | 886 | int rc = 0; |
912 | int bytes_returned; | 887 | int bytes_returned; |
913 | int name_len; | 888 | int name_len; |
889 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; | ||
914 | 890 | ||
915 | DelFileRetry: | 891 | DelFileRetry: |
916 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, | 892 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
@@ -919,15 +895,15 @@ DelFileRetry: | |||
919 | return rc; | 895 | return rc; |
920 | 896 | ||
921 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 897 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
922 | name_len = | 898 | name_len = cifsConvertToUTF16((__le16 *) pSMB->fileName, name, |
923 | cifsConvertToUTF16((__le16 *) pSMB->fileName, fileName, | 899 | PATH_MAX, cifs_sb->local_nls, |
924 | PATH_MAX, nls_codepage, remap); | 900 | remap); |
925 | name_len++; /* trailing null */ | 901 | name_len++; /* trailing null */ |
926 | name_len *= 2; | 902 | name_len *= 2; |
927 | } else { /* BB improve check for buffer overruns BB */ | 903 | } else { /* BB improve check for buffer overruns BB */ |
928 | name_len = strnlen(fileName, PATH_MAX); | 904 | name_len = strnlen(name, PATH_MAX); |
929 | name_len++; /* trailing null */ | 905 | name_len++; /* trailing null */ |
930 | strncpy(pSMB->fileName, fileName, name_len); | 906 | strncpy(pSMB->fileName, name, name_len); |
931 | } | 907 | } |
932 | pSMB->SearchAttributes = | 908 | pSMB->SearchAttributes = |
933 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); | 909 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
@@ -1440,7 +1416,7 @@ cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
1440 | return 0; | 1416 | return 0; |
1441 | } | 1417 | } |
1442 | 1418 | ||
1443 | static int | 1419 | int |
1444 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) | 1420 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
1445 | { | 1421 | { |
1446 | int length, len; | 1422 | int length, len; |
@@ -1460,10 +1436,10 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
1460 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - | 1436 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - |
1461 | HEADER_SIZE(server) + 1; | 1437 | HEADER_SIZE(server) + 1; |
1462 | 1438 | ||
1463 | rdata->iov[0].iov_base = buf + HEADER_SIZE(server) - 1; | 1439 | rdata->iov.iov_base = buf + HEADER_SIZE(server) - 1; |
1464 | rdata->iov[0].iov_len = len; | 1440 | rdata->iov.iov_len = len; |
1465 | 1441 | ||
1466 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); | 1442 | length = cifs_readv_from_socket(server, &rdata->iov, 1, len); |
1467 | if (length < 0) | 1443 | if (length < 0) |
1468 | return length; | 1444 | return length; |
1469 | server->total_read += length; | 1445 | server->total_read += length; |
@@ -1509,19 +1485,19 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
1509 | len = data_offset - server->total_read; | 1485 | len = data_offset - server->total_read; |
1510 | if (len > 0) { | 1486 | if (len > 0) { |
1511 | /* read any junk before data into the rest of smallbuf */ | 1487 | /* read any junk before data into the rest of smallbuf */ |
1512 | rdata->iov[0].iov_base = buf + server->total_read; | 1488 | rdata->iov.iov_base = buf + server->total_read; |
1513 | rdata->iov[0].iov_len = len; | 1489 | rdata->iov.iov_len = len; |
1514 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); | 1490 | length = cifs_readv_from_socket(server, &rdata->iov, 1, len); |
1515 | if (length < 0) | 1491 | if (length < 0) |
1516 | return length; | 1492 | return length; |
1517 | server->total_read += length; | 1493 | server->total_read += length; |
1518 | } | 1494 | } |
1519 | 1495 | ||
1520 | /* set up first iov for signature check */ | 1496 | /* set up first iov for signature check */ |
1521 | rdata->iov[0].iov_base = buf; | 1497 | rdata->iov.iov_base = buf; |
1522 | rdata->iov[0].iov_len = server->total_read; | 1498 | rdata->iov.iov_len = server->total_read; |
1523 | cFYI(1, "0: iov_base=%p iov_len=%zu", | 1499 | cFYI(1, "0: iov_base=%p iov_len=%zu", |
1524 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); | 1500 | rdata->iov.iov_base, rdata->iov.iov_len); |
1525 | 1501 | ||
1526 | /* how much data is in the response? */ | 1502 | /* how much data is in the response? */ |
1527 | data_len = server->ops->read_data_length(buf); | 1503 | data_len = server->ops->read_data_length(buf); |
@@ -1531,23 +1507,11 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
1531 | return cifs_readv_discard(server, mid); | 1507 | return cifs_readv_discard(server, mid); |
1532 | } | 1508 | } |
1533 | 1509 | ||
1534 | /* marshal up the page array */ | 1510 | length = rdata->read_into_pages(server, rdata, data_len); |
1535 | cifs_kmap_lock(); | 1511 | if (length < 0) |
1536 | len = rdata->marshal_iov(rdata, data_len); | 1512 | return length; |
1537 | cifs_kmap_unlock(); | ||
1538 | data_len -= len; | ||
1539 | |||
1540 | /* issue the read if we have any iovecs left to fill */ | ||
1541 | if (rdata->nr_iov > 1) { | ||
1542 | length = cifs_readv_from_socket(server, &rdata->iov[1], | ||
1543 | rdata->nr_iov - 1, len); | ||
1544 | if (length < 0) | ||
1545 | return length; | ||
1546 | server->total_read += length; | ||
1547 | } else { | ||
1548 | length = 0; | ||
1549 | } | ||
1550 | 1513 | ||
1514 | server->total_read += length; | ||
1551 | rdata->bytes = length; | 1515 | rdata->bytes = length; |
1552 | 1516 | ||
1553 | cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read, | 1517 | cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read, |
@@ -1567,6 +1531,12 @@ cifs_readv_callback(struct mid_q_entry *mid) | |||
1567 | struct cifs_readdata *rdata = mid->callback_data; | 1531 | struct cifs_readdata *rdata = mid->callback_data; |
1568 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); | 1532 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
1569 | struct TCP_Server_Info *server = tcon->ses->server; | 1533 | struct TCP_Server_Info *server = tcon->ses->server; |
1534 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, | ||
1535 | .rq_nvec = 1, | ||
1536 | .rq_pages = rdata->pages, | ||
1537 | .rq_npages = rdata->nr_pages, | ||
1538 | .rq_pagesz = rdata->pagesz, | ||
1539 | .rq_tailsz = rdata->tailsz }; | ||
1570 | 1540 | ||
1571 | cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__, | 1541 | cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__, |
1572 | mid->mid, mid->mid_state, rdata->result, rdata->bytes); | 1542 | mid->mid, mid->mid_state, rdata->result, rdata->bytes); |
@@ -1578,9 +1548,8 @@ cifs_readv_callback(struct mid_q_entry *mid) | |||
1578 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { | 1548 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { |
1579 | int rc = 0; | 1549 | int rc = 0; |
1580 | 1550 | ||
1581 | rc = cifs_verify_signature(rdata->iov, rdata->nr_iov, | 1551 | rc = cifs_verify_signature(&rqst, server, |
1582 | server, | 1552 | mid->sequence_number + 1); |
1583 | mid->sequence_number + 1); | ||
1584 | if (rc) | 1553 | if (rc) |
1585 | cERROR(1, "SMB signature verification returned " | 1554 | cERROR(1, "SMB signature verification returned " |
1586 | "error = %d", rc); | 1555 | "error = %d", rc); |
@@ -1610,6 +1579,8 @@ cifs_async_readv(struct cifs_readdata *rdata) | |||
1610 | READ_REQ *smb = NULL; | 1579 | READ_REQ *smb = NULL; |
1611 | int wct; | 1580 | int wct; |
1612 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); | 1581 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
1582 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, | ||
1583 | .rq_nvec = 1 }; | ||
1613 | 1584 | ||
1614 | cFYI(1, "%s: offset=%llu bytes=%u", __func__, | 1585 | cFYI(1, "%s: offset=%llu bytes=%u", __func__, |
1615 | rdata->offset, rdata->bytes); | 1586 | rdata->offset, rdata->bytes); |
@@ -1632,7 +1603,7 @@ cifs_async_readv(struct cifs_readdata *rdata) | |||
1632 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); | 1603 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
1633 | 1604 | ||
1634 | smb->AndXCommand = 0xFF; /* none */ | 1605 | smb->AndXCommand = 0xFF; /* none */ |
1635 | smb->Fid = rdata->cfile->netfid; | 1606 | smb->Fid = rdata->cfile->fid.netfid; |
1636 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); | 1607 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
1637 | if (wct == 12) | 1608 | if (wct == 12) |
1638 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); | 1609 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
@@ -1649,13 +1620,12 @@ cifs_async_readv(struct cifs_readdata *rdata) | |||
1649 | } | 1620 | } |
1650 | 1621 | ||
1651 | /* 4 for RFC1001 length + 1 for BCC */ | 1622 | /* 4 for RFC1001 length + 1 for BCC */ |
1652 | rdata->iov[0].iov_base = smb; | 1623 | rdata->iov.iov_base = smb; |
1653 | rdata->iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; | 1624 | rdata->iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
1654 | 1625 | ||
1655 | kref_get(&rdata->refcount); | 1626 | kref_get(&rdata->refcount); |
1656 | rc = cifs_call_async(tcon->ses->server, rdata->iov, 1, | 1627 | rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive, |
1657 | cifs_readv_receive, cifs_readv_callback, | 1628 | cifs_readv_callback, rdata, 0); |
1658 | rdata, 0); | ||
1659 | 1629 | ||
1660 | if (rc == 0) | 1630 | if (rc == 0) |
1661 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); | 1631 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
@@ -1926,6 +1896,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata) | |||
1926 | { | 1896 | { |
1927 | int i, rc; | 1897 | int i, rc; |
1928 | struct inode *inode = wdata->cfile->dentry->d_inode; | 1898 | struct inode *inode = wdata->cfile->dentry->d_inode; |
1899 | struct TCP_Server_Info *server; | ||
1929 | 1900 | ||
1930 | for (i = 0; i < wdata->nr_pages; i++) { | 1901 | for (i = 0; i < wdata->nr_pages; i++) { |
1931 | lock_page(wdata->pages[i]); | 1902 | lock_page(wdata->pages[i]); |
@@ -1933,7 +1904,8 @@ cifs_writev_requeue(struct cifs_writedata *wdata) | |||
1933 | } | 1904 | } |
1934 | 1905 | ||
1935 | do { | 1906 | do { |
1936 | rc = cifs_async_writev(wdata); | 1907 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; |
1908 | rc = server->ops->async_writev(wdata); | ||
1937 | } while (rc == -EAGAIN); | 1909 | } while (rc == -EAGAIN); |
1938 | 1910 | ||
1939 | for (i = 0; i < wdata->nr_pages; i++) { | 1911 | for (i = 0; i < wdata->nr_pages; i++) { |
@@ -2053,11 +2025,12 @@ cifs_writev_callback(struct mid_q_entry *mid) | |||
2053 | int | 2025 | int |
2054 | cifs_async_writev(struct cifs_writedata *wdata) | 2026 | cifs_async_writev(struct cifs_writedata *wdata) |
2055 | { | 2027 | { |
2056 | int i, rc = -EACCES; | 2028 | int rc = -EACCES; |
2057 | WRITE_REQ *smb = NULL; | 2029 | WRITE_REQ *smb = NULL; |
2058 | int wct; | 2030 | int wct; |
2059 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); | 2031 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
2060 | struct kvec *iov = NULL; | 2032 | struct kvec iov; |
2033 | struct smb_rqst rqst = { }; | ||
2061 | 2034 | ||
2062 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { | 2035 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
2063 | wct = 14; | 2036 | wct = 14; |
@@ -2073,18 +2046,11 @@ cifs_async_writev(struct cifs_writedata *wdata) | |||
2073 | if (rc) | 2046 | if (rc) |
2074 | goto async_writev_out; | 2047 | goto async_writev_out; |
2075 | 2048 | ||
2076 | /* 1 iov per page + 1 for header */ | ||
2077 | iov = kzalloc((wdata->nr_pages + 1) * sizeof(*iov), GFP_NOFS); | ||
2078 | if (iov == NULL) { | ||
2079 | rc = -ENOMEM; | ||
2080 | goto async_writev_out; | ||
2081 | } | ||
2082 | |||
2083 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); | 2049 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
2084 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); | 2050 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
2085 | 2051 | ||
2086 | smb->AndXCommand = 0xFF; /* none */ | 2052 | smb->AndXCommand = 0xFF; /* none */ |
2087 | smb->Fid = wdata->cfile->netfid; | 2053 | smb->Fid = wdata->cfile->fid.netfid; |
2088 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); | 2054 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
2089 | if (wct == 14) | 2055 | if (wct == 14) |
2090 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); | 2056 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
@@ -2096,18 +2062,15 @@ cifs_async_writev(struct cifs_writedata *wdata) | |||
2096 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); | 2062 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
2097 | 2063 | ||
2098 | /* 4 for RFC1001 length + 1 for BCC */ | 2064 | /* 4 for RFC1001 length + 1 for BCC */ |
2099 | iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; | 2065 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; |
2100 | iov[0].iov_base = smb; | 2066 | iov.iov_base = smb; |
2101 | 2067 | ||
2102 | /* | 2068 | rqst.rq_iov = &iov; |
2103 | * This function should marshal up the page array into the kvec | 2069 | rqst.rq_nvec = 1; |
2104 | * array, reserving [0] for the header. It should kmap the pages | 2070 | rqst.rq_pages = wdata->pages; |
2105 | * and set the iov_len properly for each one. It may also set | 2071 | rqst.rq_npages = wdata->nr_pages; |
2106 | * wdata->bytes too. | 2072 | rqst.rq_pagesz = wdata->pagesz; |
2107 | */ | 2073 | rqst.rq_tailsz = wdata->tailsz; |
2108 | cifs_kmap_lock(); | ||
2109 | wdata->marshal_iov(iov, wdata); | ||
2110 | cifs_kmap_unlock(); | ||
2111 | 2074 | ||
2112 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); | 2075 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); |
2113 | 2076 | ||
@@ -2123,32 +2086,26 @@ cifs_async_writev(struct cifs_writedata *wdata) | |||
2123 | (struct smb_com_writex_req *)smb; | 2086 | (struct smb_com_writex_req *)smb; |
2124 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); | 2087 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
2125 | put_bcc(wdata->bytes + 5, &smbw->hdr); | 2088 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
2126 | iov[0].iov_len += 4; /* pad bigger by four bytes */ | 2089 | iov.iov_len += 4; /* pad bigger by four bytes */ |
2127 | } | 2090 | } |
2128 | 2091 | ||
2129 | kref_get(&wdata->refcount); | 2092 | kref_get(&wdata->refcount); |
2130 | rc = cifs_call_async(tcon->ses->server, iov, wdata->nr_pages + 1, | 2093 | rc = cifs_call_async(tcon->ses->server, &rqst, NULL, |
2131 | NULL, cifs_writev_callback, wdata, 0); | 2094 | cifs_writev_callback, wdata, 0); |
2132 | 2095 | ||
2133 | if (rc == 0) | 2096 | if (rc == 0) |
2134 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); | 2097 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
2135 | else | 2098 | else |
2136 | kref_put(&wdata->refcount, cifs_writedata_release); | 2099 | kref_put(&wdata->refcount, cifs_writedata_release); |
2137 | 2100 | ||
2138 | /* send is done, unmap pages */ | ||
2139 | for (i = 0; i < wdata->nr_pages; i++) | ||
2140 | kunmap(wdata->pages[i]); | ||
2141 | |||
2142 | async_writev_out: | 2101 | async_writev_out: |
2143 | cifs_small_buf_release(smb); | 2102 | cifs_small_buf_release(smb); |
2144 | kfree(iov); | ||
2145 | return rc; | 2103 | return rc; |
2146 | } | 2104 | } |
2147 | 2105 | ||
2148 | int | 2106 | int |
2149 | CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, | 2107 | CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, |
2150 | unsigned int *nbytes, struct kvec *iov, int n_vec, | 2108 | unsigned int *nbytes, struct kvec *iov, int n_vec) |
2151 | const int long_op) | ||
2152 | { | 2109 | { |
2153 | int rc = -EACCES; | 2110 | int rc = -EACCES; |
2154 | WRITE_REQ *pSMB = NULL; | 2111 | WRITE_REQ *pSMB = NULL; |
@@ -2219,8 +2176,7 @@ CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, | |||
2219 | iov[0].iov_len = smb_hdr_len + 8; | 2176 | iov[0].iov_len = smb_hdr_len + 8; |
2220 | 2177 | ||
2221 | 2178 | ||
2222 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, | 2179 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 0); |
2223 | long_op); | ||
2224 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); | 2180 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
2225 | if (rc) { | 2181 | if (rc) { |
2226 | cFYI(1, "Send error Write2 = %d", rc); | 2182 | cFYI(1, "Send error Write2 = %d", rc); |
@@ -2557,8 +2513,8 @@ CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id) | |||
2557 | 2513 | ||
2558 | int | 2514 | int |
2559 | CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, | 2515 | CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, |
2560 | const char *fromName, const char *toName, | 2516 | const char *from_name, const char *to_name, |
2561 | const struct nls_table *nls_codepage, int remap) | 2517 | struct cifs_sb_info *cifs_sb) |
2562 | { | 2518 | { |
2563 | int rc = 0; | 2519 | int rc = 0; |
2564 | RENAME_REQ *pSMB = NULL; | 2520 | RENAME_REQ *pSMB = NULL; |
@@ -2566,6 +2522,7 @@ CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, | |||
2566 | int bytes_returned; | 2522 | int bytes_returned; |
2567 | int name_len, name_len2; | 2523 | int name_len, name_len2; |
2568 | __u16 count; | 2524 | __u16 count; |
2525 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; | ||
2569 | 2526 | ||
2570 | cFYI(1, "In CIFSSMBRename"); | 2527 | cFYI(1, "In CIFSSMBRename"); |
2571 | renameRetry: | 2528 | renameRetry: |
@@ -2580,9 +2537,9 @@ renameRetry: | |||
2580 | ATTR_DIRECTORY); | 2537 | ATTR_DIRECTORY); |
2581 | 2538 | ||
2582 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 2539 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
2583 | name_len = | 2540 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
2584 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, | 2541 | from_name, PATH_MAX, |
2585 | PATH_MAX, nls_codepage, remap); | 2542 | cifs_sb->local_nls, remap); |
2586 | name_len++; /* trailing null */ | 2543 | name_len++; /* trailing null */ |
2587 | name_len *= 2; | 2544 | name_len *= 2; |
2588 | pSMB->OldFileName[name_len] = 0x04; /* pad */ | 2545 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
@@ -2590,17 +2547,18 @@ renameRetry: | |||
2590 | pSMB->OldFileName[name_len + 1] = 0x00; | 2547 | pSMB->OldFileName[name_len + 1] = 0x00; |
2591 | name_len2 = | 2548 | name_len2 = |
2592 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], | 2549 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
2593 | toName, PATH_MAX, nls_codepage, remap); | 2550 | to_name, PATH_MAX, cifs_sb->local_nls, |
2551 | remap); | ||
2594 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; | 2552 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
2595 | name_len2 *= 2; /* convert to bytes */ | 2553 | name_len2 *= 2; /* convert to bytes */ |
2596 | } else { /* BB improve the check for buffer overruns BB */ | 2554 | } else { /* BB improve the check for buffer overruns BB */ |
2597 | name_len = strnlen(fromName, PATH_MAX); | 2555 | name_len = strnlen(from_name, PATH_MAX); |
2598 | name_len++; /* trailing null */ | 2556 | name_len++; /* trailing null */ |
2599 | strncpy(pSMB->OldFileName, fromName, name_len); | 2557 | strncpy(pSMB->OldFileName, from_name, name_len); |
2600 | name_len2 = strnlen(toName, PATH_MAX); | 2558 | name_len2 = strnlen(to_name, PATH_MAX); |
2601 | name_len2++; /* trailing null */ | 2559 | name_len2++; /* trailing null */ |
2602 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ | 2560 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
2603 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); | 2561 | strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); |
2604 | name_len2++; /* trailing null */ | 2562 | name_len2++; /* trailing null */ |
2605 | name_len2++; /* signature byte */ | 2563 | name_len2++; /* signature byte */ |
2606 | } | 2564 | } |
@@ -2948,8 +2906,8 @@ createHardLinkRetry: | |||
2948 | 2906 | ||
2949 | int | 2907 | int |
2950 | CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, | 2908 | CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
2951 | const char *fromName, const char *toName, | 2909 | const char *from_name, const char *to_name, |
2952 | const struct nls_table *nls_codepage, int remap) | 2910 | struct cifs_sb_info *cifs_sb) |
2953 | { | 2911 | { |
2954 | int rc = 0; | 2912 | int rc = 0; |
2955 | NT_RENAME_REQ *pSMB = NULL; | 2913 | NT_RENAME_REQ *pSMB = NULL; |
@@ -2957,6 +2915,7 @@ CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, | |||
2957 | int bytes_returned; | 2915 | int bytes_returned; |
2958 | int name_len, name_len2; | 2916 | int name_len, name_len2; |
2959 | __u16 count; | 2917 | __u16 count; |
2918 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; | ||
2960 | 2919 | ||
2961 | cFYI(1, "In CIFSCreateHardLink"); | 2920 | cFYI(1, "In CIFSCreateHardLink"); |
2962 | winCreateHardLinkRetry: | 2921 | winCreateHardLinkRetry: |
@@ -2976,8 +2935,8 @@ winCreateHardLinkRetry: | |||
2976 | 2935 | ||
2977 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 2936 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
2978 | name_len = | 2937 | name_len = |
2979 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, | 2938 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, from_name, |
2980 | PATH_MAX, nls_codepage, remap); | 2939 | PATH_MAX, cifs_sb->local_nls, remap); |
2981 | name_len++; /* trailing null */ | 2940 | name_len++; /* trailing null */ |
2982 | name_len *= 2; | 2941 | name_len *= 2; |
2983 | 2942 | ||
@@ -2986,17 +2945,18 @@ winCreateHardLinkRetry: | |||
2986 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ | 2945 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
2987 | name_len2 = | 2946 | name_len2 = |
2988 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], | 2947 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
2989 | toName, PATH_MAX, nls_codepage, remap); | 2948 | to_name, PATH_MAX, cifs_sb->local_nls, |
2949 | remap); | ||
2990 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; | 2950 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
2991 | name_len2 *= 2; /* convert to bytes */ | 2951 | name_len2 *= 2; /* convert to bytes */ |
2992 | } else { /* BB improve the check for buffer overruns BB */ | 2952 | } else { /* BB improve the check for buffer overruns BB */ |
2993 | name_len = strnlen(fromName, PATH_MAX); | 2953 | name_len = strnlen(from_name, PATH_MAX); |
2994 | name_len++; /* trailing null */ | 2954 | name_len++; /* trailing null */ |
2995 | strncpy(pSMB->OldFileName, fromName, name_len); | 2955 | strncpy(pSMB->OldFileName, from_name, name_len); |
2996 | name_len2 = strnlen(toName, PATH_MAX); | 2956 | name_len2 = strnlen(to_name, PATH_MAX); |
2997 | name_len2++; /* trailing null */ | 2957 | name_len2++; /* trailing null */ |
2998 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ | 2958 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
2999 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); | 2959 | strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); |
3000 | name_len2++; /* trailing null */ | 2960 | name_len2++; /* trailing null */ |
3001 | name_len2++; /* signature byte */ | 2961 | name_len2++; /* signature byte */ |
3002 | } | 2962 | } |
@@ -4254,10 +4214,9 @@ UnixQPathInfoRetry: | |||
4254 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ | 4214 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
4255 | int | 4215 | int |
4256 | CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, | 4216 | CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, |
4257 | const char *searchName, | 4217 | const char *searchName, struct cifs_sb_info *cifs_sb, |
4258 | const struct nls_table *nls_codepage, | ||
4259 | __u16 *pnetfid, __u16 search_flags, | 4218 | __u16 *pnetfid, __u16 search_flags, |
4260 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) | 4219 | struct cifs_search_info *psrch_inf, bool msearch) |
4261 | { | 4220 | { |
4262 | /* level 257 SMB_ */ | 4221 | /* level 257 SMB_ */ |
4263 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; | 4222 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
@@ -4265,8 +4224,9 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, | |||
4265 | T2_FFIRST_RSP_PARMS *parms; | 4224 | T2_FFIRST_RSP_PARMS *parms; |
4266 | int rc = 0; | 4225 | int rc = 0; |
4267 | int bytes_returned = 0; | 4226 | int bytes_returned = 0; |
4268 | int name_len; | 4227 | int name_len, remap; |
4269 | __u16 params, byte_count; | 4228 | __u16 params, byte_count; |
4229 | struct nls_table *nls_codepage; | ||
4270 | 4230 | ||
4271 | cFYI(1, "In FindFirst for %s", searchName); | 4231 | cFYI(1, "In FindFirst for %s", searchName); |
4272 | 4232 | ||
@@ -4276,6 +4236,9 @@ findFirstRetry: | |||
4276 | if (rc) | 4236 | if (rc) |
4277 | return rc; | 4237 | return rc; |
4278 | 4238 | ||
4239 | nls_codepage = cifs_sb->local_nls; | ||
4240 | remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; | ||
4241 | |||
4279 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 4242 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
4280 | name_len = | 4243 | name_len = |
4281 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, | 4244 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
@@ -4284,24 +4247,29 @@ findFirstRetry: | |||
4284 | it got remapped to 0xF03A as if it were part of the | 4247 | it got remapped to 0xF03A as if it were part of the |
4285 | directory name instead of a wildcard */ | 4248 | directory name instead of a wildcard */ |
4286 | name_len *= 2; | 4249 | name_len *= 2; |
4287 | pSMB->FileName[name_len] = dirsep; | 4250 | if (msearch) { |
4288 | pSMB->FileName[name_len+1] = 0; | 4251 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
4289 | pSMB->FileName[name_len+2] = '*'; | 4252 | pSMB->FileName[name_len+1] = 0; |
4290 | pSMB->FileName[name_len+3] = 0; | 4253 | pSMB->FileName[name_len+2] = '*'; |
4291 | name_len += 4; /* now the trailing null */ | 4254 | pSMB->FileName[name_len+3] = 0; |
4292 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ | 4255 | name_len += 4; /* now the trailing null */ |
4293 | pSMB->FileName[name_len+1] = 0; | 4256 | /* null terminate just in case */ |
4294 | name_len += 2; | 4257 | pSMB->FileName[name_len] = 0; |
4258 | pSMB->FileName[name_len+1] = 0; | ||
4259 | name_len += 2; | ||
4260 | } | ||
4295 | } else { /* BB add check for overrun of SMB buf BB */ | 4261 | } else { /* BB add check for overrun of SMB buf BB */ |
4296 | name_len = strnlen(searchName, PATH_MAX); | 4262 | name_len = strnlen(searchName, PATH_MAX); |
4297 | /* BB fix here and in unicode clause above ie | 4263 | /* BB fix here and in unicode clause above ie |
4298 | if (name_len > buffersize-header) | 4264 | if (name_len > buffersize-header) |
4299 | free buffer exit; BB */ | 4265 | free buffer exit; BB */ |
4300 | strncpy(pSMB->FileName, searchName, name_len); | 4266 | strncpy(pSMB->FileName, searchName, name_len); |
4301 | pSMB->FileName[name_len] = dirsep; | 4267 | if (msearch) { |
4302 | pSMB->FileName[name_len+1] = '*'; | 4268 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
4303 | pSMB->FileName[name_len+2] = 0; | 4269 | pSMB->FileName[name_len+1] = '*'; |
4304 | name_len += 3; | 4270 | pSMB->FileName[name_len+2] = 0; |
4271 | name_len += 3; | ||
4272 | } | ||
4305 | } | 4273 | } |
4306 | 4274 | ||
4307 | params = 12 + name_len /* includes null */ ; | 4275 | params = 12 + name_len /* includes null */ ; |
@@ -4389,7 +4357,8 @@ findFirstRetry: | |||
4389 | psrch_inf->last_entry = psrch_inf->srch_entries_start + | 4357 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
4390 | lnoff; | 4358 | lnoff; |
4391 | 4359 | ||
4392 | *pnetfid = parms->SearchHandle; | 4360 | if (pnetfid) |
4361 | *pnetfid = parms->SearchHandle; | ||
4393 | } else { | 4362 | } else { |
4394 | cifs_buf_release(pSMB); | 4363 | cifs_buf_release(pSMB); |
4395 | } | 4364 | } |
@@ -5417,16 +5386,16 @@ QFSPosixRetry: | |||
5417 | } | 5386 | } |
5418 | 5387 | ||
5419 | 5388 | ||
5420 | /* We can not use write of zero bytes trick to | 5389 | /* |
5421 | set file size due to need for large file support. Also note that | 5390 | * We can not use write of zero bytes trick to set file size due to need for |
5422 | this SetPathInfo is preferred to SetFileInfo based method in next | 5391 | * large file support. Also note that this SetPathInfo is preferred to |
5423 | routine which is only needed to work around a sharing violation bug | 5392 | * SetFileInfo based method in next routine which is only needed to work around |
5424 | in Samba which this routine can run into */ | 5393 | * a sharing violation bugin Samba which this routine can run into. |
5425 | 5394 | */ | |
5426 | int | 5395 | int |
5427 | CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, | 5396 | CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, |
5428 | const char *fileName, __u64 size, bool SetAllocation, | 5397 | const char *file_name, __u64 size, struct cifs_sb_info *cifs_sb, |
5429 | const struct nls_table *nls_codepage, int remap) | 5398 | bool set_allocation) |
5430 | { | 5399 | { |
5431 | struct smb_com_transaction2_spi_req *pSMB = NULL; | 5400 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
5432 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; | 5401 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
@@ -5434,6 +5403,8 @@ CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, | |||
5434 | int name_len; | 5403 | int name_len; |
5435 | int rc = 0; | 5404 | int rc = 0; |
5436 | int bytes_returned = 0; | 5405 | int bytes_returned = 0; |
5406 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; | ||
5407 | |||
5437 | __u16 params, byte_count, data_count, param_offset, offset; | 5408 | __u16 params, byte_count, data_count, param_offset, offset; |
5438 | 5409 | ||
5439 | cFYI(1, "In SetEOF"); | 5410 | cFYI(1, "In SetEOF"); |
@@ -5445,14 +5416,14 @@ SetEOFRetry: | |||
5445 | 5416 | ||
5446 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 5417 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
5447 | name_len = | 5418 | name_len = |
5448 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, | 5419 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
5449 | PATH_MAX, nls_codepage, remap); | 5420 | PATH_MAX, cifs_sb->local_nls, remap); |
5450 | name_len++; /* trailing null */ | 5421 | name_len++; /* trailing null */ |
5451 | name_len *= 2; | 5422 | name_len *= 2; |
5452 | } else { /* BB improve the check for buffer overruns BB */ | 5423 | } else { /* BB improve the check for buffer overruns BB */ |
5453 | name_len = strnlen(fileName, PATH_MAX); | 5424 | name_len = strnlen(file_name, PATH_MAX); |
5454 | name_len++; /* trailing null */ | 5425 | name_len++; /* trailing null */ |
5455 | strncpy(pSMB->FileName, fileName, name_len); | 5426 | strncpy(pSMB->FileName, file_name, name_len); |
5456 | } | 5427 | } |
5457 | params = 6 + name_len; | 5428 | params = 6 + name_len; |
5458 | data_count = sizeof(struct file_end_of_file_info); | 5429 | data_count = sizeof(struct file_end_of_file_info); |
@@ -5466,7 +5437,7 @@ SetEOFRetry: | |||
5466 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | 5437 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
5467 | InformationLevel) - 4; | 5438 | InformationLevel) - 4; |
5468 | offset = param_offset + params; | 5439 | offset = param_offset + params; |
5469 | if (SetAllocation) { | 5440 | if (set_allocation) { |
5470 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) | 5441 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
5471 | pSMB->InformationLevel = | 5442 | pSMB->InformationLevel = |
5472 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); | 5443 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
@@ -5513,8 +5484,8 @@ SetEOFRetry: | |||
5513 | } | 5484 | } |
5514 | 5485 | ||
5515 | int | 5486 | int |
5516 | CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, __u64 size, | 5487 | CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, |
5517 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) | 5488 | struct cifsFileInfo *cfile, __u64 size, bool set_allocation) |
5518 | { | 5489 | { |
5519 | struct smb_com_transaction2_sfi_req *pSMB = NULL; | 5490 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
5520 | struct file_end_of_file_info *parm_data; | 5491 | struct file_end_of_file_info *parm_data; |
@@ -5528,8 +5499,8 @@ CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, __u64 size, | |||
5528 | if (rc) | 5499 | if (rc) |
5529 | return rc; | 5500 | return rc; |
5530 | 5501 | ||
5531 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); | 5502 | pSMB->hdr.Pid = cpu_to_le16((__u16)cfile->pid); |
5532 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); | 5503 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(cfile->pid >> 16)); |
5533 | 5504 | ||
5534 | params = 6; | 5505 | params = 6; |
5535 | pSMB->MaxSetupCount = 0; | 5506 | pSMB->MaxSetupCount = 0; |
@@ -5558,8 +5529,8 @@ CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, __u64 size, | |||
5558 | + offset); | 5529 | + offset); |
5559 | pSMB->DataOffset = cpu_to_le16(offset); | 5530 | pSMB->DataOffset = cpu_to_le16(offset); |
5560 | parm_data->FileSize = cpu_to_le64(size); | 5531 | parm_data->FileSize = cpu_to_le64(size); |
5561 | pSMB->Fid = fid; | 5532 | pSMB->Fid = cfile->fid.netfid; |
5562 | if (SetAllocation) { | 5533 | if (set_allocation) { |
5563 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) | 5534 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
5564 | pSMB->InformationLevel = | 5535 | pSMB->InformationLevel = |
5565 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); | 5536 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 6df6fa14cba8..2fdbe08a7a23 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -82,8 +82,7 @@ enum { | |||
82 | Opt_serverino, Opt_noserverino, | 82 | Opt_serverino, Opt_noserverino, |
83 | Opt_rwpidforward, Opt_cifsacl, Opt_nocifsacl, | 83 | Opt_rwpidforward, Opt_cifsacl, Opt_nocifsacl, |
84 | Opt_acl, Opt_noacl, Opt_locallease, | 84 | Opt_acl, Opt_noacl, Opt_locallease, |
85 | Opt_sign, Opt_seal, Opt_direct, | 85 | Opt_sign, Opt_seal, Opt_noac, |
86 | Opt_strictcache, Opt_noac, | ||
87 | Opt_fsc, Opt_mfsymlinks, | 86 | Opt_fsc, Opt_mfsymlinks, |
88 | Opt_multiuser, Opt_sloppy, | 87 | Opt_multiuser, Opt_sloppy, |
89 | 88 | ||
@@ -160,10 +159,6 @@ static const match_table_t cifs_mount_option_tokens = { | |||
160 | { Opt_locallease, "locallease" }, | 159 | { Opt_locallease, "locallease" }, |
161 | { Opt_sign, "sign" }, | 160 | { Opt_sign, "sign" }, |
162 | { Opt_seal, "seal" }, | 161 | { Opt_seal, "seal" }, |
163 | { Opt_direct, "direct" }, | ||
164 | { Opt_direct, "directio" }, | ||
165 | { Opt_direct, "forcedirectio" }, | ||
166 | { Opt_strictcache, "strictcache" }, | ||
167 | { Opt_noac, "noac" }, | 162 | { Opt_noac, "noac" }, |
168 | { Opt_fsc, "fsc" }, | 163 | { Opt_fsc, "fsc" }, |
169 | { Opt_mfsymlinks, "mfsymlinks" }, | 164 | { Opt_mfsymlinks, "mfsymlinks" }, |
@@ -277,6 +272,7 @@ static const match_table_t cifs_cacheflavor_tokens = { | |||
277 | static const match_table_t cifs_smb_version_tokens = { | 272 | static const match_table_t cifs_smb_version_tokens = { |
278 | { Smb_1, SMB1_VERSION_STRING }, | 273 | { Smb_1, SMB1_VERSION_STRING }, |
279 | { Smb_21, SMB21_VERSION_STRING }, | 274 | { Smb_21, SMB21_VERSION_STRING }, |
275 | { Smb_30, SMB30_VERSION_STRING }, | ||
280 | }; | 276 | }; |
281 | 277 | ||
282 | static int ip_connect(struct TCP_Server_Info *server); | 278 | static int ip_connect(struct TCP_Server_Info *server); |
@@ -819,6 +815,10 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
819 | cifs_dump_mem("Bad SMB: ", buf, | 815 | cifs_dump_mem("Bad SMB: ", buf, |
820 | min_t(unsigned int, server->total_read, 48)); | 816 | min_t(unsigned int, server->total_read, 48)); |
821 | 817 | ||
818 | if (server->ops->is_status_pending && | ||
819 | server->ops->is_status_pending(buf, server, length)) | ||
820 | return -1; | ||
821 | |||
822 | if (!mid) | 822 | if (!mid) |
823 | return length; | 823 | return length; |
824 | 824 | ||
@@ -1075,6 +1075,10 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol) | |||
1075 | vol->ops = &smb21_operations; | 1075 | vol->ops = &smb21_operations; |
1076 | vol->vals = &smb21_values; | 1076 | vol->vals = &smb21_values; |
1077 | break; | 1077 | break; |
1078 | case Smb_30: | ||
1079 | vol->ops = &smb21_operations; /* currently identical with 2.1 */ | ||
1080 | vol->vals = &smb30_values; | ||
1081 | break; | ||
1078 | #endif | 1082 | #endif |
1079 | default: | 1083 | default: |
1080 | cERROR(1, "Unknown vers= option specified: %s", value); | 1084 | cERROR(1, "Unknown vers= option specified: %s", value); |
@@ -1101,8 +1105,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1101 | char *string = NULL; | 1105 | char *string = NULL; |
1102 | char *tmp_end, *value; | 1106 | char *tmp_end, *value; |
1103 | char delim; | 1107 | char delim; |
1104 | bool cache_specified = false; | ||
1105 | static bool cache_warned = false; | ||
1106 | 1108 | ||
1107 | separator[0] = ','; | 1109 | separator[0] = ','; |
1108 | separator[1] = 0; | 1110 | separator[1] = 0; |
@@ -1134,6 +1136,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1134 | /* default to using server inode numbers where available */ | 1136 | /* default to using server inode numbers where available */ |
1135 | vol->server_ino = 1; | 1137 | vol->server_ino = 1; |
1136 | 1138 | ||
1139 | /* default is to use strict cifs caching semantics */ | ||
1140 | vol->strict_io = true; | ||
1141 | |||
1137 | vol->actimeo = CIFS_DEF_ACTIMEO; | 1142 | vol->actimeo = CIFS_DEF_ACTIMEO; |
1138 | 1143 | ||
1139 | /* FIXME: add autonegotiation -- for now, SMB1 is default */ | 1144 | /* FIXME: add autonegotiation -- for now, SMB1 is default */ |
@@ -1317,22 +1322,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1317 | */ | 1322 | */ |
1318 | vol->seal = 1; | 1323 | vol->seal = 1; |
1319 | break; | 1324 | break; |
1320 | case Opt_direct: | ||
1321 | cache_specified = true; | ||
1322 | vol->direct_io = true; | ||
1323 | vol->strict_io = false; | ||
1324 | cERROR(1, "The \"directio\" option will be removed in " | ||
1325 | "3.7. Please switch to the \"cache=none\" " | ||
1326 | "option."); | ||
1327 | break; | ||
1328 | case Opt_strictcache: | ||
1329 | cache_specified = true; | ||
1330 | vol->direct_io = false; | ||
1331 | vol->strict_io = true; | ||
1332 | cERROR(1, "The \"strictcache\" option will be removed " | ||
1333 | "in 3.7. Please switch to the \"cache=strict\" " | ||
1334 | "option."); | ||
1335 | break; | ||
1336 | case Opt_noac: | 1325 | case Opt_noac: |
1337 | printk(KERN_WARNING "CIFS: Mount option noac not " | 1326 | printk(KERN_WARNING "CIFS: Mount option noac not " |
1338 | "supported. Instead set " | 1327 | "supported. Instead set " |
@@ -1676,8 +1665,13 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1676 | if (string == NULL) | 1665 | if (string == NULL) |
1677 | goto out_nomem; | 1666 | goto out_nomem; |
1678 | 1667 | ||
1679 | if (strnicmp(string, "TCP_NODELAY", 11) == 0) | 1668 | if (strnicmp(string, "TCP_NODELAY", 11) == 0) { |
1669 | printk(KERN_WARNING "CIFS: the " | ||
1670 | "sockopt=TCP_NODELAY option has been " | ||
1671 | "deprecated and will be removed " | ||
1672 | "in 3.9\n"); | ||
1680 | vol->sockopt_tcp_nodelay = 1; | 1673 | vol->sockopt_tcp_nodelay = 1; |
1674 | } | ||
1681 | break; | 1675 | break; |
1682 | case Opt_netbiosname: | 1676 | case Opt_netbiosname: |
1683 | string = match_strdup(args); | 1677 | string = match_strdup(args); |
@@ -1762,7 +1756,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1762 | goto cifs_parse_mount_err; | 1756 | goto cifs_parse_mount_err; |
1763 | break; | 1757 | break; |
1764 | case Opt_cache: | 1758 | case Opt_cache: |
1765 | cache_specified = true; | ||
1766 | string = match_strdup(args); | 1759 | string = match_strdup(args); |
1767 | if (string == NULL) | 1760 | if (string == NULL) |
1768 | goto out_nomem; | 1761 | goto out_nomem; |
@@ -1813,14 +1806,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1813 | printk(KERN_NOTICE "CIFS: ignoring forcegid mount option " | 1806 | printk(KERN_NOTICE "CIFS: ignoring forcegid mount option " |
1814 | "specified with no gid= option.\n"); | 1807 | "specified with no gid= option.\n"); |
1815 | 1808 | ||
1816 | /* FIXME: remove this block in 3.7 */ | ||
1817 | if (!cache_specified && !cache_warned) { | ||
1818 | cache_warned = true; | ||
1819 | printk(KERN_NOTICE "CIFS: no cache= option specified, using " | ||
1820 | "\"cache=loose\". This default will change " | ||
1821 | "to \"cache=strict\" in 3.7.\n"); | ||
1822 | } | ||
1823 | |||
1824 | kfree(mountdata_copy); | 1809 | kfree(mountdata_copy); |
1825 | return 0; | 1810 | return 0; |
1826 | 1811 | ||
@@ -2636,6 +2621,7 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) | |||
2636 | tcon->retry = volume_info->retry; | 2621 | tcon->retry = volume_info->retry; |
2637 | tcon->nocase = volume_info->nocase; | 2622 | tcon->nocase = volume_info->nocase; |
2638 | tcon->local_lease = volume_info->local_lease; | 2623 | tcon->local_lease = volume_info->local_lease; |
2624 | INIT_LIST_HEAD(&tcon->pending_opens); | ||
2639 | 2625 | ||
2640 | spin_lock(&cifs_tcp_ses_lock); | 2626 | spin_lock(&cifs_tcp_ses_lock); |
2641 | list_add(&tcon->tcon_list, &ses->tcon_list); | 2627 | list_add(&tcon->tcon_list, &ses->tcon_list); |
@@ -3261,146 +3247,6 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info, | |||
3261 | "mount option supported"); | 3247 | "mount option supported"); |
3262 | } | 3248 | } |
3263 | 3249 | ||
3264 | /* | ||
3265 | * When the server supports very large reads and writes via POSIX extensions, | ||
3266 | * we can allow up to 2^24-1, minus the size of a READ/WRITE_AND_X header, not | ||
3267 | * including the RFC1001 length. | ||
3268 | * | ||
3269 | * Note that this might make for "interesting" allocation problems during | ||
3270 | * writeback however as we have to allocate an array of pointers for the | ||
3271 | * pages. A 16M write means ~32kb page array with PAGE_CACHE_SIZE == 4096. | ||
3272 | * | ||
3273 | * For reads, there is a similar problem as we need to allocate an array | ||
3274 | * of kvecs to handle the receive, though that should only need to be done | ||
3275 | * once. | ||
3276 | */ | ||
3277 | #define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4) | ||
3278 | #define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4) | ||
3279 | |||
3280 | /* | ||
3281 | * When the server doesn't allow large posix writes, only allow a rsize/wsize | ||
3282 | * of 2^17-1 minus the size of the call header. That allows for a read or | ||
3283 | * write up to the maximum size described by RFC1002. | ||
3284 | */ | ||
3285 | #define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4) | ||
3286 | #define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4) | ||
3287 | |||
3288 | /* | ||
3289 | * The default wsize is 1M. find_get_pages seems to return a maximum of 256 | ||
3290 | * pages in a single call. With PAGE_CACHE_SIZE == 4k, this means we can fill | ||
3291 | * a single wsize request with a single call. | ||
3292 | */ | ||
3293 | #define CIFS_DEFAULT_IOSIZE (1024 * 1024) | ||
3294 | |||
3295 | /* | ||
3296 | * Windows only supports a max of 60kb reads and 65535 byte writes. Default to | ||
3297 | * those values when posix extensions aren't in force. In actuality here, we | ||
3298 | * use 65536 to allow for a write that is a multiple of 4k. Most servers seem | ||
3299 | * to be ok with the extra byte even though Windows doesn't send writes that | ||
3300 | * are that large. | ||
3301 | * | ||
3302 | * Citation: | ||
3303 | * | ||
3304 | * http://blogs.msdn.com/b/openspecification/archive/2009/04/10/smb-maximum-transmit-buffer-size-and-performance-tuning.aspx | ||
3305 | */ | ||
3306 | #define CIFS_DEFAULT_NON_POSIX_RSIZE (60 * 1024) | ||
3307 | #define CIFS_DEFAULT_NON_POSIX_WSIZE (65536) | ||
3308 | |||
3309 | /* | ||
3310 | * On hosts with high memory, we can't currently support wsize/rsize that are | ||
3311 | * larger than we can kmap at once. Cap the rsize/wsize at | ||
3312 | * LAST_PKMAP * PAGE_SIZE. We'll never be able to fill a read or write request | ||
3313 | * larger than that anyway. | ||
3314 | */ | ||
3315 | #ifdef CONFIG_HIGHMEM | ||
3316 | #define CIFS_KMAP_SIZE_LIMIT (LAST_PKMAP * PAGE_CACHE_SIZE) | ||
3317 | #else /* CONFIG_HIGHMEM */ | ||
3318 | #define CIFS_KMAP_SIZE_LIMIT (1<<24) | ||
3319 | #endif /* CONFIG_HIGHMEM */ | ||
3320 | |||
3321 | static unsigned int | ||
3322 | cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info) | ||
3323 | { | ||
3324 | __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); | ||
3325 | struct TCP_Server_Info *server = tcon->ses->server; | ||
3326 | unsigned int wsize; | ||
3327 | |||
3328 | /* start with specified wsize, or default */ | ||
3329 | if (pvolume_info->wsize) | ||
3330 | wsize = pvolume_info->wsize; | ||
3331 | else if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_WRITE_CAP)) | ||
3332 | wsize = CIFS_DEFAULT_IOSIZE; | ||
3333 | else | ||
3334 | wsize = CIFS_DEFAULT_NON_POSIX_WSIZE; | ||
3335 | |||
3336 | /* can server support 24-bit write sizes? (via UNIX extensions) */ | ||
3337 | if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP)) | ||
3338 | wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1002_WSIZE); | ||
3339 | |||
3340 | /* | ||
3341 | * no CAP_LARGE_WRITE_X or is signing enabled without CAP_UNIX set? | ||
3342 | * Limit it to max buffer offered by the server, minus the size of the | ||
3343 | * WRITEX header, not including the 4 byte RFC1001 length. | ||
3344 | */ | ||
3345 | if (!(server->capabilities & CAP_LARGE_WRITE_X) || | ||
3346 | (!(server->capabilities & CAP_UNIX) && | ||
3347 | (server->sec_mode & (SECMODE_SIGN_ENABLED|SECMODE_SIGN_REQUIRED)))) | ||
3348 | wsize = min_t(unsigned int, wsize, | ||
3349 | server->maxBuf - sizeof(WRITE_REQ) + 4); | ||
3350 | |||
3351 | /* limit to the amount that we can kmap at once */ | ||
3352 | wsize = min_t(unsigned int, wsize, CIFS_KMAP_SIZE_LIMIT); | ||
3353 | |||
3354 | /* hard limit of CIFS_MAX_WSIZE */ | ||
3355 | wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE); | ||
3356 | |||
3357 | return wsize; | ||
3358 | } | ||
3359 | |||
3360 | static unsigned int | ||
3361 | cifs_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info) | ||
3362 | { | ||
3363 | __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); | ||
3364 | struct TCP_Server_Info *server = tcon->ses->server; | ||
3365 | unsigned int rsize, defsize; | ||
3366 | |||
3367 | /* | ||
3368 | * Set default value... | ||
3369 | * | ||
3370 | * HACK alert! Ancient servers have very small buffers. Even though | ||
3371 | * MS-CIFS indicates that servers are only limited by the client's | ||
3372 | * bufsize for reads, testing against win98se shows that it throws | ||
3373 | * INVALID_PARAMETER errors if you try to request too large a read. | ||
3374 | * OS/2 just sends back short reads. | ||
3375 | * | ||
3376 | * If the server doesn't advertise CAP_LARGE_READ_X, then assume that | ||
3377 | * it can't handle a read request larger than its MaxBufferSize either. | ||
3378 | */ | ||
3379 | if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_READ_CAP)) | ||
3380 | defsize = CIFS_DEFAULT_IOSIZE; | ||
3381 | else if (server->capabilities & CAP_LARGE_READ_X) | ||
3382 | defsize = CIFS_DEFAULT_NON_POSIX_RSIZE; | ||
3383 | else | ||
3384 | defsize = server->maxBuf - sizeof(READ_RSP); | ||
3385 | |||
3386 | rsize = pvolume_info->rsize ? pvolume_info->rsize : defsize; | ||
3387 | |||
3388 | /* | ||
3389 | * no CAP_LARGE_READ_X? Then MS-CIFS states that we must limit this to | ||
3390 | * the client's MaxBufferSize. | ||
3391 | */ | ||
3392 | if (!(server->capabilities & CAP_LARGE_READ_X)) | ||
3393 | rsize = min_t(unsigned int, CIFSMaxBufSize, rsize); | ||
3394 | |||
3395 | /* limit to the amount that we can kmap at once */ | ||
3396 | rsize = min_t(unsigned int, rsize, CIFS_KMAP_SIZE_LIMIT); | ||
3397 | |||
3398 | /* hard limit of CIFS_MAX_RSIZE */ | ||
3399 | rsize = min_t(unsigned int, rsize, CIFS_MAX_RSIZE); | ||
3400 | |||
3401 | return rsize; | ||
3402 | } | ||
3403 | |||
3404 | static void | 3250 | static void |
3405 | cleanup_volume_info_contents(struct smb_vol *volume_info) | 3251 | cleanup_volume_info_contents(struct smb_vol *volume_info) |
3406 | { | 3252 | { |
@@ -3651,8 +3497,8 @@ try_mount_again: | |||
3651 | if (!tcon->ipc && server->ops->qfs_tcon) | 3497 | if (!tcon->ipc && server->ops->qfs_tcon) |
3652 | server->ops->qfs_tcon(xid, tcon); | 3498 | server->ops->qfs_tcon(xid, tcon); |
3653 | 3499 | ||
3654 | cifs_sb->wsize = cifs_negotiate_wsize(tcon, volume_info); | 3500 | cifs_sb->wsize = server->ops->negotiate_wsize(tcon, volume_info); |
3655 | cifs_sb->rsize = cifs_negotiate_rsize(tcon, volume_info); | 3501 | cifs_sb->rsize = server->ops->negotiate_rsize(tcon, volume_info); |
3656 | 3502 | ||
3657 | /* tune readahead according to rsize */ | 3503 | /* tune readahead according to rsize */ |
3658 | cifs_sb->bdi.ra_pages = cifs_sb->rsize / PAGE_CACHE_SIZE; | 3504 | cifs_sb->bdi.ra_pages = cifs_sb->rsize / PAGE_CACHE_SIZE; |
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 781025be48bc..7c0a81283645 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c | |||
@@ -160,17 +160,18 @@ check_name(struct dentry *direntry) | |||
160 | static int | 160 | static int |
161 | cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | 161 | cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, |
162 | struct tcon_link *tlink, unsigned oflags, umode_t mode, | 162 | struct tcon_link *tlink, unsigned oflags, umode_t mode, |
163 | __u32 *oplock, __u16 *fileHandle, int *created) | 163 | __u32 *oplock, struct cifs_fid *fid, int *created) |
164 | { | 164 | { |
165 | int rc = -ENOENT; | 165 | int rc = -ENOENT; |
166 | int create_options = CREATE_NOT_DIR; | 166 | int create_options = CREATE_NOT_DIR; |
167 | int desiredAccess; | 167 | int desired_access; |
168 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 168 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
169 | struct cifs_tcon *tcon = tlink_tcon(tlink); | 169 | struct cifs_tcon *tcon = tlink_tcon(tlink); |
170 | char *full_path = NULL; | 170 | char *full_path = NULL; |
171 | FILE_ALL_INFO *buf = NULL; | 171 | FILE_ALL_INFO *buf = NULL; |
172 | struct inode *newinode = NULL; | 172 | struct inode *newinode = NULL; |
173 | int disposition; | 173 | int disposition; |
174 | struct TCP_Server_Info *server = tcon->ses->server; | ||
174 | 175 | ||
175 | *oplock = 0; | 176 | *oplock = 0; |
176 | if (tcon->ses->server->oplocks) | 177 | if (tcon->ses->server->oplocks) |
@@ -185,8 +186,8 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
185 | if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open && | 186 | if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open && |
186 | (CIFS_UNIX_POSIX_PATH_OPS_CAP & | 187 | (CIFS_UNIX_POSIX_PATH_OPS_CAP & |
187 | le64_to_cpu(tcon->fsUnixInfo.Capability))) { | 188 | le64_to_cpu(tcon->fsUnixInfo.Capability))) { |
188 | rc = cifs_posix_open(full_path, &newinode, | 189 | rc = cifs_posix_open(full_path, &newinode, inode->i_sb, mode, |
189 | inode->i_sb, mode, oflags, oplock, fileHandle, xid); | 190 | oflags, oplock, &fid->netfid, xid); |
190 | switch (rc) { | 191 | switch (rc) { |
191 | case 0: | 192 | case 0: |
192 | if (newinode == NULL) { | 193 | if (newinode == NULL) { |
@@ -202,7 +203,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
202 | * close it and proceed as if it were a normal | 203 | * close it and proceed as if it were a normal |
203 | * lookup. | 204 | * lookup. |
204 | */ | 205 | */ |
205 | CIFSSMBClose(xid, tcon, *fileHandle); | 206 | CIFSSMBClose(xid, tcon, fid->netfid); |
206 | goto cifs_create_get_file_info; | 207 | goto cifs_create_get_file_info; |
207 | } | 208 | } |
208 | /* success, no need to query */ | 209 | /* success, no need to query */ |
@@ -244,11 +245,11 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
244 | */ | 245 | */ |
245 | } | 246 | } |
246 | 247 | ||
247 | desiredAccess = 0; | 248 | desired_access = 0; |
248 | if (OPEN_FMODE(oflags) & FMODE_READ) | 249 | if (OPEN_FMODE(oflags) & FMODE_READ) |
249 | desiredAccess |= GENERIC_READ; /* is this too little? */ | 250 | desired_access |= GENERIC_READ; /* is this too little? */ |
250 | if (OPEN_FMODE(oflags) & FMODE_WRITE) | 251 | if (OPEN_FMODE(oflags) & FMODE_WRITE) |
251 | desiredAccess |= GENERIC_WRITE; | 252 | desired_access |= GENERIC_WRITE; |
252 | 253 | ||
253 | disposition = FILE_OVERWRITE_IF; | 254 | disposition = FILE_OVERWRITE_IF; |
254 | if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) | 255 | if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) |
@@ -260,8 +261,15 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
260 | else | 261 | else |
261 | cFYI(1, "Create flag not set in create function"); | 262 | cFYI(1, "Create flag not set in create function"); |
262 | 263 | ||
263 | /* BB add processing to set equivalent of mode - e.g. via CreateX with | 264 | /* |
264 | ACLs */ | 265 | * BB add processing to set equivalent of mode - e.g. via CreateX with |
266 | * ACLs | ||
267 | */ | ||
268 | |||
269 | if (!server->ops->open) { | ||
270 | rc = -ENOSYS; | ||
271 | goto out; | ||
272 | } | ||
265 | 273 | ||
266 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); | 274 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
267 | if (buf == NULL) { | 275 | if (buf == NULL) { |
@@ -279,28 +287,18 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
279 | if (backup_cred(cifs_sb)) | 287 | if (backup_cred(cifs_sb)) |
280 | create_options |= CREATE_OPEN_BACKUP_INTENT; | 288 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
281 | 289 | ||
282 | if (tcon->ses->capabilities & CAP_NT_SMBS) | 290 | rc = server->ops->open(xid, tcon, full_path, disposition, |
283 | rc = CIFSSMBOpen(xid, tcon, full_path, disposition, | 291 | desired_access, create_options, fid, oplock, |
284 | desiredAccess, create_options, | 292 | buf, cifs_sb); |
285 | fileHandle, oplock, buf, cifs_sb->local_nls, | ||
286 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
287 | else | ||
288 | rc = -EIO; /* no NT SMB support fall into legacy open below */ | ||
289 | |||
290 | if (rc == -EIO) { | ||
291 | /* old server, retry the open legacy style */ | ||
292 | rc = SMBLegacyOpen(xid, tcon, full_path, disposition, | ||
293 | desiredAccess, create_options, | ||
294 | fileHandle, oplock, buf, cifs_sb->local_nls, | ||
295 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
296 | } | ||
297 | if (rc) { | 293 | if (rc) { |
298 | cFYI(1, "cifs_create returned 0x%x", rc); | 294 | cFYI(1, "cifs_create returned 0x%x", rc); |
299 | goto out; | 295 | goto out; |
300 | } | 296 | } |
301 | 297 | ||
302 | /* If Open reported that we actually created a file | 298 | /* |
303 | then we now have to set the mode if possible */ | 299 | * If Open reported that we actually created a file then we now have to |
300 | * set the mode if possible. | ||
301 | */ | ||
304 | if ((tcon->unix_ext) && (*oplock & CIFS_CREATE_ACTION)) { | 302 | if ((tcon->unix_ext) && (*oplock & CIFS_CREATE_ACTION)) { |
305 | struct cifs_unix_set_info_args args = { | 303 | struct cifs_unix_set_info_args args = { |
306 | .mode = mode, | 304 | .mode = mode, |
@@ -321,11 +319,13 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
321 | args.uid = NO_CHANGE_64; | 319 | args.uid = NO_CHANGE_64; |
322 | args.gid = NO_CHANGE_64; | 320 | args.gid = NO_CHANGE_64; |
323 | } | 321 | } |
324 | CIFSSMBUnixSetFileInfo(xid, tcon, &args, *fileHandle, | 322 | CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid->netfid, |
325 | current->tgid); | 323 | current->tgid); |
326 | } else { | 324 | } else { |
327 | /* BB implement mode setting via Windows security | 325 | /* |
328 | descriptors e.g. */ | 326 | * BB implement mode setting via Windows security |
327 | * descriptors e.g. | ||
328 | */ | ||
329 | /* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/ | 329 | /* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/ |
330 | 330 | ||
331 | /* Could set r/o dos attribute if mode & 0222 == 0 */ | 331 | /* Could set r/o dos attribute if mode & 0222 == 0 */ |
@@ -334,12 +334,14 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
334 | cifs_create_get_file_info: | 334 | cifs_create_get_file_info: |
335 | /* server might mask mode so we have to query for it */ | 335 | /* server might mask mode so we have to query for it */ |
336 | if (tcon->unix_ext) | 336 | if (tcon->unix_ext) |
337 | rc = cifs_get_inode_info_unix(&newinode, full_path, | 337 | rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb, |
338 | inode->i_sb, xid); | 338 | xid); |
339 | else { | 339 | else { |
340 | rc = cifs_get_inode_info(&newinode, full_path, buf, | 340 | rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb, |
341 | inode->i_sb, xid, fileHandle); | 341 | xid, &fid->netfid); |
342 | if (newinode) { | 342 | if (newinode) { |
343 | if (server->ops->set_lease_key) | ||
344 | server->ops->set_lease_key(newinode, fid); | ||
343 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) | 345 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) |
344 | newinode->i_mode = mode; | 346 | newinode->i_mode = mode; |
345 | if ((*oplock & CIFS_CREATE_ACTION) && | 347 | if ((*oplock & CIFS_CREATE_ACTION) && |
@@ -356,7 +358,8 @@ cifs_create_get_file_info: | |||
356 | cifs_create_set_dentry: | 358 | cifs_create_set_dentry: |
357 | if (rc != 0) { | 359 | if (rc != 0) { |
358 | cFYI(1, "Create worked, get_inode_info failed rc = %d", rc); | 360 | cFYI(1, "Create worked, get_inode_info failed rc = %d", rc); |
359 | CIFSSMBClose(xid, tcon, *fileHandle); | 361 | if (server->ops->close) |
362 | server->ops->close(xid, tcon, fid); | ||
360 | goto out; | 363 | goto out; |
361 | } | 364 | } |
362 | d_drop(direntry); | 365 | d_drop(direntry); |
@@ -377,11 +380,14 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry, | |||
377 | unsigned int xid; | 380 | unsigned int xid; |
378 | struct tcon_link *tlink; | 381 | struct tcon_link *tlink; |
379 | struct cifs_tcon *tcon; | 382 | struct cifs_tcon *tcon; |
380 | __u16 fileHandle; | 383 | struct TCP_Server_Info *server; |
384 | struct cifs_fid fid; | ||
385 | struct cifs_pending_open open; | ||
381 | __u32 oplock; | 386 | __u32 oplock; |
382 | struct cifsFileInfo *pfile_info; | 387 | struct cifsFileInfo *file_info; |
383 | 388 | ||
384 | /* Posix open is only called (at lookup time) for file create now. For | 389 | /* |
390 | * Posix open is only called (at lookup time) for file create now. For | ||
385 | * opens (rather than creates), because we do not know if it is a file | 391 | * opens (rather than creates), because we do not know if it is a file |
386 | * or directory yet, and current Samba no longer allows us to do posix | 392 | * or directory yet, and current Samba no longer allows us to do posix |
387 | * open on dirs, we could end up wasting an open call on what turns out | 393 | * open on dirs, we could end up wasting an open call on what turns out |
@@ -413,22 +419,34 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry, | |||
413 | goto out_free_xid; | 419 | goto out_free_xid; |
414 | 420 | ||
415 | tcon = tlink_tcon(tlink); | 421 | tcon = tlink_tcon(tlink); |
422 | server = tcon->ses->server; | ||
423 | |||
424 | if (server->ops->new_lease_key) | ||
425 | server->ops->new_lease_key(&fid); | ||
426 | |||
427 | cifs_add_pending_open(&fid, tlink, &open); | ||
416 | 428 | ||
417 | rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, | 429 | rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, |
418 | &oplock, &fileHandle, opened); | 430 | &oplock, &fid, opened); |
419 | 431 | ||
420 | if (rc) | 432 | if (rc) { |
433 | cifs_del_pending_open(&open); | ||
421 | goto out; | 434 | goto out; |
435 | } | ||
422 | 436 | ||
423 | rc = finish_open(file, direntry, generic_file_open, opened); | 437 | rc = finish_open(file, direntry, generic_file_open, opened); |
424 | if (rc) { | 438 | if (rc) { |
425 | CIFSSMBClose(xid, tcon, fileHandle); | 439 | if (server->ops->close) |
440 | server->ops->close(xid, tcon, &fid); | ||
441 | cifs_del_pending_open(&open); | ||
426 | goto out; | 442 | goto out; |
427 | } | 443 | } |
428 | 444 | ||
429 | pfile_info = cifs_new_fileinfo(fileHandle, file, tlink, oplock); | 445 | file_info = cifs_new_fileinfo(&fid, file, tlink, oplock); |
430 | if (pfile_info == NULL) { | 446 | if (file_info == NULL) { |
431 | CIFSSMBClose(xid, tcon, fileHandle); | 447 | if (server->ops->close) |
448 | server->ops->close(xid, tcon, &fid); | ||
449 | cifs_del_pending_open(&open); | ||
432 | rc = -ENOMEM; | 450 | rc = -ENOMEM; |
433 | } | 451 | } |
434 | 452 | ||
@@ -453,7 +471,9 @@ int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode, | |||
453 | */ | 471 | */ |
454 | unsigned oflags = O_EXCL | O_CREAT | O_RDWR; | 472 | unsigned oflags = O_EXCL | O_CREAT | O_RDWR; |
455 | struct tcon_link *tlink; | 473 | struct tcon_link *tlink; |
456 | __u16 fileHandle; | 474 | struct cifs_tcon *tcon; |
475 | struct TCP_Server_Info *server; | ||
476 | struct cifs_fid fid; | ||
457 | __u32 oplock; | 477 | __u32 oplock; |
458 | int created = FILE_CREATED; | 478 | int created = FILE_CREATED; |
459 | 479 | ||
@@ -465,10 +485,16 @@ int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode, | |||
465 | if (IS_ERR(tlink)) | 485 | if (IS_ERR(tlink)) |
466 | goto out_free_xid; | 486 | goto out_free_xid; |
467 | 487 | ||
488 | tcon = tlink_tcon(tlink); | ||
489 | server = tcon->ses->server; | ||
490 | |||
491 | if (server->ops->new_lease_key) | ||
492 | server->ops->new_lease_key(&fid); | ||
493 | |||
468 | rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, | 494 | rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, |
469 | &oplock, &fileHandle, &created); | 495 | &oplock, &fid, &created); |
470 | if (!rc) | 496 | if (!rc && server->ops->close) |
471 | CIFSSMBClose(xid, tlink_tcon(tlink), fileHandle); | 497 | server->ops->close(xid, tcon, &fid); |
472 | 498 | ||
473 | cifs_put_tlink(tlink); | 499 | cifs_put_tlink(tlink); |
474 | out_free_xid: | 500 | out_free_xid: |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 71e9ad9f5961..7d7bbdc4c8e7 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -169,16 +169,20 @@ posix_open_ret: | |||
169 | 169 | ||
170 | static int | 170 | static int |
171 | cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, | 171 | cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, |
172 | struct cifs_tcon *tcon, unsigned int f_flags, __u32 *poplock, | 172 | struct cifs_tcon *tcon, unsigned int f_flags, __u32 *oplock, |
173 | __u16 *pnetfid, unsigned int xid) | 173 | struct cifs_fid *fid, unsigned int xid) |
174 | { | 174 | { |
175 | int rc; | 175 | int rc; |
176 | int desiredAccess; | 176 | int desired_access; |
177 | int disposition; | 177 | int disposition; |
178 | int create_options = CREATE_NOT_DIR; | 178 | int create_options = CREATE_NOT_DIR; |
179 | FILE_ALL_INFO *buf; | 179 | FILE_ALL_INFO *buf; |
180 | struct TCP_Server_Info *server = tcon->ses->server; | ||
181 | |||
182 | if (!server->ops->open) | ||
183 | return -ENOSYS; | ||
180 | 184 | ||
181 | desiredAccess = cifs_convert_flags(f_flags); | 185 | desired_access = cifs_convert_flags(f_flags); |
182 | 186 | ||
183 | /********************************************************************* | 187 | /********************************************************************* |
184 | * open flag mapping table: | 188 | * open flag mapping table: |
@@ -215,16 +219,9 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, | |||
215 | if (backup_cred(cifs_sb)) | 219 | if (backup_cred(cifs_sb)) |
216 | create_options |= CREATE_OPEN_BACKUP_INTENT; | 220 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
217 | 221 | ||
218 | if (tcon->ses->capabilities & CAP_NT_SMBS) | 222 | rc = server->ops->open(xid, tcon, full_path, disposition, |
219 | rc = CIFSSMBOpen(xid, tcon, full_path, disposition, | 223 | desired_access, create_options, fid, oplock, buf, |
220 | desiredAccess, create_options, pnetfid, poplock, buf, | 224 | cifs_sb); |
221 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags | ||
222 | & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
223 | else | ||
224 | rc = SMBLegacyOpen(xid, tcon, full_path, disposition, | ||
225 | desiredAccess, CREATE_NOT_DIR, pnetfid, poplock, buf, | ||
226 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags | ||
227 | & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
228 | 225 | ||
229 | if (rc) | 226 | if (rc) |
230 | goto out; | 227 | goto out; |
@@ -234,7 +231,7 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, | |||
234 | xid); | 231 | xid); |
235 | else | 232 | else |
236 | rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, | 233 | rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, |
237 | xid, pnetfid); | 234 | xid, &fid->netfid); |
238 | 235 | ||
239 | out: | 236 | out: |
240 | kfree(buf); | 237 | kfree(buf); |
@@ -242,48 +239,62 @@ out: | |||
242 | } | 239 | } |
243 | 240 | ||
244 | struct cifsFileInfo * | 241 | struct cifsFileInfo * |
245 | cifs_new_fileinfo(__u16 fileHandle, struct file *file, | 242 | cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, |
246 | struct tcon_link *tlink, __u32 oplock) | 243 | struct tcon_link *tlink, __u32 oplock) |
247 | { | 244 | { |
248 | struct dentry *dentry = file->f_path.dentry; | 245 | struct dentry *dentry = file->f_path.dentry; |
249 | struct inode *inode = dentry->d_inode; | 246 | struct inode *inode = dentry->d_inode; |
250 | struct cifsInodeInfo *pCifsInode = CIFS_I(inode); | 247 | struct cifsInodeInfo *cinode = CIFS_I(inode); |
251 | struct cifsFileInfo *pCifsFile; | 248 | struct cifsFileInfo *cfile; |
252 | 249 | struct cifs_fid_locks *fdlocks; | |
253 | pCifsFile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); | 250 | struct cifs_tcon *tcon = tlink_tcon(tlink); |
254 | if (pCifsFile == NULL) | 251 | |
255 | return pCifsFile; | 252 | cfile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); |
256 | 253 | if (cfile == NULL) | |
257 | pCifsFile->count = 1; | 254 | return cfile; |
258 | pCifsFile->netfid = fileHandle; | 255 | |
259 | pCifsFile->pid = current->tgid; | 256 | fdlocks = kzalloc(sizeof(struct cifs_fid_locks), GFP_KERNEL); |
260 | pCifsFile->uid = current_fsuid(); | 257 | if (!fdlocks) { |
261 | pCifsFile->dentry = dget(dentry); | 258 | kfree(cfile); |
262 | pCifsFile->f_flags = file->f_flags; | 259 | return NULL; |
263 | pCifsFile->invalidHandle = false; | 260 | } |
264 | pCifsFile->tlink = cifs_get_tlink(tlink); | 261 | |
265 | mutex_init(&pCifsFile->fh_mutex); | 262 | INIT_LIST_HEAD(&fdlocks->locks); |
266 | INIT_WORK(&pCifsFile->oplock_break, cifs_oplock_break); | 263 | fdlocks->cfile = cfile; |
267 | INIT_LIST_HEAD(&pCifsFile->llist); | 264 | cfile->llist = fdlocks; |
265 | down_write(&cinode->lock_sem); | ||
266 | list_add(&fdlocks->llist, &cinode->llist); | ||
267 | up_write(&cinode->lock_sem); | ||
268 | |||
269 | cfile->count = 1; | ||
270 | cfile->pid = current->tgid; | ||
271 | cfile->uid = current_fsuid(); | ||
272 | cfile->dentry = dget(dentry); | ||
273 | cfile->f_flags = file->f_flags; | ||
274 | cfile->invalidHandle = false; | ||
275 | cfile->tlink = cifs_get_tlink(tlink); | ||
276 | INIT_WORK(&cfile->oplock_break, cifs_oplock_break); | ||
277 | mutex_init(&cfile->fh_mutex); | ||
268 | 278 | ||
269 | spin_lock(&cifs_file_list_lock); | 279 | spin_lock(&cifs_file_list_lock); |
270 | list_add(&pCifsFile->tlist, &(tlink_tcon(tlink)->openFileList)); | 280 | if (fid->pending_open->oplock != CIFS_OPLOCK_NO_CHANGE) |
281 | oplock = fid->pending_open->oplock; | ||
282 | list_del(&fid->pending_open->olist); | ||
283 | |||
284 | tlink_tcon(tlink)->ses->server->ops->set_fid(cfile, fid, oplock); | ||
285 | |||
286 | list_add(&cfile->tlist, &tcon->openFileList); | ||
271 | /* if readable file instance put first in list*/ | 287 | /* if readable file instance put first in list*/ |
272 | if (file->f_mode & FMODE_READ) | 288 | if (file->f_mode & FMODE_READ) |
273 | list_add(&pCifsFile->flist, &pCifsInode->openFileList); | 289 | list_add(&cfile->flist, &cinode->openFileList); |
274 | else | 290 | else |
275 | list_add_tail(&pCifsFile->flist, &pCifsInode->openFileList); | 291 | list_add_tail(&cfile->flist, &cinode->openFileList); |
276 | spin_unlock(&cifs_file_list_lock); | 292 | spin_unlock(&cifs_file_list_lock); |
277 | 293 | ||
278 | cifs_set_oplock_level(pCifsInode, oplock); | 294 | file->private_data = cfile; |
279 | pCifsInode->can_cache_brlcks = pCifsInode->clientCanCacheAll; | 295 | return cfile; |
280 | |||
281 | file->private_data = pCifsFile; | ||
282 | return pCifsFile; | ||
283 | } | 296 | } |
284 | 297 | ||
285 | static void cifs_del_lock_waiters(struct cifsLockInfo *lock); | ||
286 | |||
287 | struct cifsFileInfo * | 298 | struct cifsFileInfo * |
288 | cifsFileInfo_get(struct cifsFileInfo *cifs_file) | 299 | cifsFileInfo_get(struct cifsFileInfo *cifs_file) |
289 | { | 300 | { |
@@ -302,9 +313,12 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
302 | { | 313 | { |
303 | struct inode *inode = cifs_file->dentry->d_inode; | 314 | struct inode *inode = cifs_file->dentry->d_inode; |
304 | struct cifs_tcon *tcon = tlink_tcon(cifs_file->tlink); | 315 | struct cifs_tcon *tcon = tlink_tcon(cifs_file->tlink); |
316 | struct TCP_Server_Info *server = tcon->ses->server; | ||
305 | struct cifsInodeInfo *cifsi = CIFS_I(inode); | 317 | struct cifsInodeInfo *cifsi = CIFS_I(inode); |
306 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 318 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
307 | struct cifsLockInfo *li, *tmp; | 319 | struct cifsLockInfo *li, *tmp; |
320 | struct cifs_fid fid; | ||
321 | struct cifs_pending_open open; | ||
308 | 322 | ||
309 | spin_lock(&cifs_file_list_lock); | 323 | spin_lock(&cifs_file_list_lock); |
310 | if (--cifs_file->count > 0) { | 324 | if (--cifs_file->count > 0) { |
@@ -312,6 +326,12 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
312 | return; | 326 | return; |
313 | } | 327 | } |
314 | 328 | ||
329 | if (server->ops->get_lease_key) | ||
330 | server->ops->get_lease_key(inode, &fid); | ||
331 | |||
332 | /* store open in pending opens to make sure we don't miss lease break */ | ||
333 | cifs_add_pending_open_locked(&fid, cifs_file->tlink, &open); | ||
334 | |||
315 | /* remove it from the lists */ | 335 | /* remove it from the lists */ |
316 | list_del(&cifs_file->flist); | 336 | list_del(&cifs_file->flist); |
317 | list_del(&cifs_file->tlist); | 337 | list_del(&cifs_file->tlist); |
@@ -319,13 +339,13 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
319 | if (list_empty(&cifsi->openFileList)) { | 339 | if (list_empty(&cifsi->openFileList)) { |
320 | cFYI(1, "closing last open instance for inode %p", | 340 | cFYI(1, "closing last open instance for inode %p", |
321 | cifs_file->dentry->d_inode); | 341 | cifs_file->dentry->d_inode); |
322 | 342 | /* | |
323 | /* in strict cache mode we need invalidate mapping on the last | 343 | * In strict cache mode we need invalidate mapping on the last |
324 | close because it may cause a error when we open this file | 344 | * close because it may cause a error when we open this file |
325 | again and get at least level II oplock */ | 345 | * again and get at least level II oplock. |
346 | */ | ||
326 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) | 347 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) |
327 | CIFS_I(inode)->invalid_mapping = true; | 348 | CIFS_I(inode)->invalid_mapping = true; |
328 | |||
329 | cifs_set_oplock_level(cifsi, 0); | 349 | cifs_set_oplock_level(cifsi, 0); |
330 | } | 350 | } |
331 | spin_unlock(&cifs_file_list_lock); | 351 | spin_unlock(&cifs_file_list_lock); |
@@ -333,23 +353,30 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
333 | cancel_work_sync(&cifs_file->oplock_break); | 353 | cancel_work_sync(&cifs_file->oplock_break); |
334 | 354 | ||
335 | if (!tcon->need_reconnect && !cifs_file->invalidHandle) { | 355 | if (!tcon->need_reconnect && !cifs_file->invalidHandle) { |
356 | struct TCP_Server_Info *server = tcon->ses->server; | ||
336 | unsigned int xid; | 357 | unsigned int xid; |
337 | int rc; | 358 | |
338 | xid = get_xid(); | 359 | xid = get_xid(); |
339 | rc = CIFSSMBClose(xid, tcon, cifs_file->netfid); | 360 | if (server->ops->close) |
340 | free_xid(xid); | 361 | server->ops->close(xid, tcon, &cifs_file->fid); |
362 | _free_xid(xid); | ||
341 | } | 363 | } |
342 | 364 | ||
343 | /* Delete any outstanding lock records. We'll lose them when the file | 365 | cifs_del_pending_open(&open); |
366 | |||
367 | /* | ||
368 | * Delete any outstanding lock records. We'll lose them when the file | ||
344 | * is closed anyway. | 369 | * is closed anyway. |
345 | */ | 370 | */ |
346 | mutex_lock(&cifsi->lock_mutex); | 371 | down_write(&cifsi->lock_sem); |
347 | list_for_each_entry_safe(li, tmp, &cifs_file->llist, llist) { | 372 | list_for_each_entry_safe(li, tmp, &cifs_file->llist->locks, llist) { |
348 | list_del(&li->llist); | 373 | list_del(&li->llist); |
349 | cifs_del_lock_waiters(li); | 374 | cifs_del_lock_waiters(li); |
350 | kfree(li); | 375 | kfree(li); |
351 | } | 376 | } |
352 | mutex_unlock(&cifsi->lock_mutex); | 377 | list_del(&cifs_file->llist->llist); |
378 | kfree(cifs_file->llist); | ||
379 | up_write(&cifsi->lock_sem); | ||
353 | 380 | ||
354 | cifs_put_tlink(cifs_file->tlink); | 381 | cifs_put_tlink(cifs_file->tlink); |
355 | dput(cifs_file->dentry); | 382 | dput(cifs_file->dentry); |
@@ -357,17 +384,20 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
357 | } | 384 | } |
358 | 385 | ||
359 | int cifs_open(struct inode *inode, struct file *file) | 386 | int cifs_open(struct inode *inode, struct file *file) |
387 | |||
360 | { | 388 | { |
361 | int rc = -EACCES; | 389 | int rc = -EACCES; |
362 | unsigned int xid; | 390 | unsigned int xid; |
363 | __u32 oplock; | 391 | __u32 oplock; |
364 | struct cifs_sb_info *cifs_sb; | 392 | struct cifs_sb_info *cifs_sb; |
393 | struct TCP_Server_Info *server; | ||
365 | struct cifs_tcon *tcon; | 394 | struct cifs_tcon *tcon; |
366 | struct tcon_link *tlink; | 395 | struct tcon_link *tlink; |
367 | struct cifsFileInfo *pCifsFile = NULL; | 396 | struct cifsFileInfo *cfile = NULL; |
368 | char *full_path = NULL; | 397 | char *full_path = NULL; |
369 | bool posix_open_ok = false; | 398 | bool posix_open_ok = false; |
370 | __u16 netfid; | 399 | struct cifs_fid fid; |
400 | struct cifs_pending_open open; | ||
371 | 401 | ||
372 | xid = get_xid(); | 402 | xid = get_xid(); |
373 | 403 | ||
@@ -378,6 +408,7 @@ int cifs_open(struct inode *inode, struct file *file) | |||
378 | return PTR_ERR(tlink); | 408 | return PTR_ERR(tlink); |
379 | } | 409 | } |
380 | tcon = tlink_tcon(tlink); | 410 | tcon = tlink_tcon(tlink); |
411 | server = tcon->ses->server; | ||
381 | 412 | ||
382 | full_path = build_path_from_dentry(file->f_path.dentry); | 413 | full_path = build_path_from_dentry(file->f_path.dentry); |
383 | if (full_path == NULL) { | 414 | if (full_path == NULL) { |
@@ -388,7 +419,7 @@ int cifs_open(struct inode *inode, struct file *file) | |||
388 | cFYI(1, "inode = 0x%p file flags are 0x%x for %s", | 419 | cFYI(1, "inode = 0x%p file flags are 0x%x for %s", |
389 | inode, file->f_flags, full_path); | 420 | inode, file->f_flags, full_path); |
390 | 421 | ||
391 | if (tcon->ses->server->oplocks) | 422 | if (server->oplocks) |
392 | oplock = REQ_OPLOCK; | 423 | oplock = REQ_OPLOCK; |
393 | else | 424 | else |
394 | oplock = 0; | 425 | oplock = 0; |
@@ -399,7 +430,7 @@ int cifs_open(struct inode *inode, struct file *file) | |||
399 | /* can not refresh inode info since size could be stale */ | 430 | /* can not refresh inode info since size could be stale */ |
400 | rc = cifs_posix_open(full_path, &inode, inode->i_sb, | 431 | rc = cifs_posix_open(full_path, &inode, inode->i_sb, |
401 | cifs_sb->mnt_file_mode /* ignored */, | 432 | cifs_sb->mnt_file_mode /* ignored */, |
402 | file->f_flags, &oplock, &netfid, xid); | 433 | file->f_flags, &oplock, &fid.netfid, xid); |
403 | if (rc == 0) { | 434 | if (rc == 0) { |
404 | cFYI(1, "posix open succeeded"); | 435 | cFYI(1, "posix open succeeded"); |
405 | posix_open_ok = true; | 436 | posix_open_ok = true; |
@@ -415,20 +446,34 @@ int cifs_open(struct inode *inode, struct file *file) | |||
415 | } else if ((rc != -EIO) && (rc != -EREMOTE) && | 446 | } else if ((rc != -EIO) && (rc != -EREMOTE) && |
416 | (rc != -EOPNOTSUPP)) /* path not found or net err */ | 447 | (rc != -EOPNOTSUPP)) /* path not found or net err */ |
417 | goto out; | 448 | goto out; |
418 | /* else fallthrough to retry open the old way on network i/o | 449 | /* |
419 | or DFS errors */ | 450 | * Else fallthrough to retry open the old way on network i/o |
451 | * or DFS errors. | ||
452 | */ | ||
420 | } | 453 | } |
421 | 454 | ||
455 | if (server->ops->get_lease_key) | ||
456 | server->ops->get_lease_key(inode, &fid); | ||
457 | |||
458 | cifs_add_pending_open(&fid, tlink, &open); | ||
459 | |||
422 | if (!posix_open_ok) { | 460 | if (!posix_open_ok) { |
461 | if (server->ops->get_lease_key) | ||
462 | server->ops->get_lease_key(inode, &fid); | ||
463 | |||
423 | rc = cifs_nt_open(full_path, inode, cifs_sb, tcon, | 464 | rc = cifs_nt_open(full_path, inode, cifs_sb, tcon, |
424 | file->f_flags, &oplock, &netfid, xid); | 465 | file->f_flags, &oplock, &fid, xid); |
425 | if (rc) | 466 | if (rc) { |
467 | cifs_del_pending_open(&open); | ||
426 | goto out; | 468 | goto out; |
469 | } | ||
427 | } | 470 | } |
428 | 471 | ||
429 | pCifsFile = cifs_new_fileinfo(netfid, file, tlink, oplock); | 472 | cfile = cifs_new_fileinfo(&fid, file, tlink, oplock); |
430 | if (pCifsFile == NULL) { | 473 | if (cfile == NULL) { |
431 | CIFSSMBClose(xid, tcon, netfid); | 474 | if (server->ops->close) |
475 | server->ops->close(xid, tcon, &fid); | ||
476 | cifs_del_pending_open(&open); | ||
432 | rc = -ENOMEM; | 477 | rc = -ENOMEM; |
433 | goto out; | 478 | goto out; |
434 | } | 479 | } |
@@ -436,8 +481,10 @@ int cifs_open(struct inode *inode, struct file *file) | |||
436 | cifs_fscache_set_inode_cookie(inode, file); | 481 | cifs_fscache_set_inode_cookie(inode, file); |
437 | 482 | ||
438 | if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) { | 483 | if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) { |
439 | /* time to set mode which we can not set earlier due to | 484 | /* |
440 | problems creating new read-only files */ | 485 | * Time to set mode which we can not set earlier due to |
486 | * problems creating new read-only files. | ||
487 | */ | ||
441 | struct cifs_unix_set_info_args args = { | 488 | struct cifs_unix_set_info_args args = { |
442 | .mode = inode->i_mode, | 489 | .mode = inode->i_mode, |
443 | .uid = NO_CHANGE_64, | 490 | .uid = NO_CHANGE_64, |
@@ -447,8 +494,8 @@ int cifs_open(struct inode *inode, struct file *file) | |||
447 | .mtime = NO_CHANGE_64, | 494 | .mtime = NO_CHANGE_64, |
448 | .device = 0, | 495 | .device = 0, |
449 | }; | 496 | }; |
450 | CIFSSMBUnixSetFileInfo(xid, tcon, &args, netfid, | 497 | CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid.netfid, |
451 | pCifsFile->pid); | 498 | cfile->pid); |
452 | } | 499 | } |
453 | 500 | ||
454 | out: | 501 | out: |
@@ -458,59 +505,66 @@ out: | |||
458 | return rc; | 505 | return rc; |
459 | } | 506 | } |
460 | 507 | ||
461 | /* Try to reacquire byte range locks that were released when session */ | 508 | /* |
462 | /* to server was lost */ | 509 | * Try to reacquire byte range locks that were released when session |
510 | * to server was lost | ||
511 | */ | ||
463 | static int cifs_relock_file(struct cifsFileInfo *cifsFile) | 512 | static int cifs_relock_file(struct cifsFileInfo *cifsFile) |
464 | { | 513 | { |
465 | int rc = 0; | 514 | int rc = 0; |
466 | 515 | ||
467 | /* BB list all locks open on this file and relock */ | 516 | /* BB list all locks open on this file and relock */ |
468 | 517 | ||
469 | return rc; | 518 | return rc; |
470 | } | 519 | } |
471 | 520 | ||
472 | static int cifs_reopen_file(struct cifsFileInfo *pCifsFile, bool can_flush) | 521 | static int |
522 | cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) | ||
473 | { | 523 | { |
474 | int rc = -EACCES; | 524 | int rc = -EACCES; |
475 | unsigned int xid; | 525 | unsigned int xid; |
476 | __u32 oplock; | 526 | __u32 oplock; |
477 | struct cifs_sb_info *cifs_sb; | 527 | struct cifs_sb_info *cifs_sb; |
478 | struct cifs_tcon *tcon; | 528 | struct cifs_tcon *tcon; |
479 | struct cifsInodeInfo *pCifsInode; | 529 | struct TCP_Server_Info *server; |
530 | struct cifsInodeInfo *cinode; | ||
480 | struct inode *inode; | 531 | struct inode *inode; |
481 | char *full_path = NULL; | 532 | char *full_path = NULL; |
482 | int desiredAccess; | 533 | int desired_access; |
483 | int disposition = FILE_OPEN; | 534 | int disposition = FILE_OPEN; |
484 | int create_options = CREATE_NOT_DIR; | 535 | int create_options = CREATE_NOT_DIR; |
485 | __u16 netfid; | 536 | struct cifs_fid fid; |
486 | 537 | ||
487 | xid = get_xid(); | 538 | xid = get_xid(); |
488 | mutex_lock(&pCifsFile->fh_mutex); | 539 | mutex_lock(&cfile->fh_mutex); |
489 | if (!pCifsFile->invalidHandle) { | 540 | if (!cfile->invalidHandle) { |
490 | mutex_unlock(&pCifsFile->fh_mutex); | 541 | mutex_unlock(&cfile->fh_mutex); |
491 | rc = 0; | 542 | rc = 0; |
492 | free_xid(xid); | 543 | free_xid(xid); |
493 | return rc; | 544 | return rc; |
494 | } | 545 | } |
495 | 546 | ||
496 | inode = pCifsFile->dentry->d_inode; | 547 | inode = cfile->dentry->d_inode; |
497 | cifs_sb = CIFS_SB(inode->i_sb); | 548 | cifs_sb = CIFS_SB(inode->i_sb); |
498 | tcon = tlink_tcon(pCifsFile->tlink); | 549 | tcon = tlink_tcon(cfile->tlink); |
550 | server = tcon->ses->server; | ||
499 | 551 | ||
500 | /* can not grab rename sem here because various ops, including | 552 | /* |
501 | those that already have the rename sem can end up causing writepage | 553 | * Can not grab rename sem here because various ops, including those |
502 | to get called and if the server was down that means we end up here, | 554 | * that already have the rename sem can end up causing writepage to get |
503 | and we can never tell if the caller already has the rename_sem */ | 555 | * called and if the server was down that means we end up here, and we |
504 | full_path = build_path_from_dentry(pCifsFile->dentry); | 556 | * can never tell if the caller already has the rename_sem. |
557 | */ | ||
558 | full_path = build_path_from_dentry(cfile->dentry); | ||
505 | if (full_path == NULL) { | 559 | if (full_path == NULL) { |
506 | rc = -ENOMEM; | 560 | rc = -ENOMEM; |
507 | mutex_unlock(&pCifsFile->fh_mutex); | 561 | mutex_unlock(&cfile->fh_mutex); |
508 | free_xid(xid); | 562 | free_xid(xid); |
509 | return rc; | 563 | return rc; |
510 | } | 564 | } |
511 | 565 | ||
512 | cFYI(1, "inode = 0x%p file flags 0x%x for %s", | 566 | cFYI(1, "inode = 0x%p file flags 0x%x for %s", inode, cfile->f_flags, |
513 | inode, pCifsFile->f_flags, full_path); | 567 | full_path); |
514 | 568 | ||
515 | if (tcon->ses->server->oplocks) | 569 | if (tcon->ses->server->oplocks) |
516 | oplock = REQ_OPLOCK; | 570 | oplock = REQ_OPLOCK; |
@@ -524,69 +578,72 @@ static int cifs_reopen_file(struct cifsFileInfo *pCifsFile, bool can_flush) | |||
524 | * O_CREAT, O_EXCL and O_TRUNC already had their effect on the | 578 | * O_CREAT, O_EXCL and O_TRUNC already had their effect on the |
525 | * original open. Must mask them off for a reopen. | 579 | * original open. Must mask them off for a reopen. |
526 | */ | 580 | */ |
527 | unsigned int oflags = pCifsFile->f_flags & | 581 | unsigned int oflags = cfile->f_flags & |
528 | ~(O_CREAT | O_EXCL | O_TRUNC); | 582 | ~(O_CREAT | O_EXCL | O_TRUNC); |
529 | 583 | ||
530 | rc = cifs_posix_open(full_path, NULL, inode->i_sb, | 584 | rc = cifs_posix_open(full_path, NULL, inode->i_sb, |
531 | cifs_sb->mnt_file_mode /* ignored */, | 585 | cifs_sb->mnt_file_mode /* ignored */, |
532 | oflags, &oplock, &netfid, xid); | 586 | oflags, &oplock, &fid.netfid, xid); |
533 | if (rc == 0) { | 587 | if (rc == 0) { |
534 | cFYI(1, "posix reopen succeeded"); | 588 | cFYI(1, "posix reopen succeeded"); |
535 | goto reopen_success; | 589 | goto reopen_success; |
536 | } | 590 | } |
537 | /* fallthrough to retry open the old way on errors, especially | 591 | /* |
538 | in the reconnect path it is important to retry hard */ | 592 | * fallthrough to retry open the old way on errors, especially |
593 | * in the reconnect path it is important to retry hard | ||
594 | */ | ||
539 | } | 595 | } |
540 | 596 | ||
541 | desiredAccess = cifs_convert_flags(pCifsFile->f_flags); | 597 | desired_access = cifs_convert_flags(cfile->f_flags); |
542 | 598 | ||
543 | if (backup_cred(cifs_sb)) | 599 | if (backup_cred(cifs_sb)) |
544 | create_options |= CREATE_OPEN_BACKUP_INTENT; | 600 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
545 | 601 | ||
546 | /* Can not refresh inode by passing in file_info buf to be returned | 602 | if (server->ops->get_lease_key) |
547 | by SMBOpen and then calling get_inode_info with returned buf | 603 | server->ops->get_lease_key(inode, &fid); |
548 | since file might have write behind data that needs to be flushed | ||
549 | and server version of file size can be stale. If we knew for sure | ||
550 | that inode was not dirty locally we could do this */ | ||
551 | 604 | ||
552 | rc = CIFSSMBOpen(xid, tcon, full_path, disposition, desiredAccess, | 605 | /* |
553 | create_options, &netfid, &oplock, NULL, | 606 | * Can not refresh inode by passing in file_info buf to be returned by |
554 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & | 607 | * CIFSSMBOpen and then calling get_inode_info with returned buf since |
555 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 608 | * file might have write behind data that needs to be flushed and server |
609 | * version of file size can be stale. If we knew for sure that inode was | ||
610 | * not dirty locally we could do this. | ||
611 | */ | ||
612 | rc = server->ops->open(xid, tcon, full_path, disposition, | ||
613 | desired_access, create_options, &fid, &oplock, | ||
614 | NULL, cifs_sb); | ||
556 | if (rc) { | 615 | if (rc) { |
557 | mutex_unlock(&pCifsFile->fh_mutex); | 616 | mutex_unlock(&cfile->fh_mutex); |
558 | cFYI(1, "cifs_open returned 0x%x", rc); | 617 | cFYI(1, "cifs_reopen returned 0x%x", rc); |
559 | cFYI(1, "oplock: %d", oplock); | 618 | cFYI(1, "oplock: %d", oplock); |
560 | goto reopen_error_exit; | 619 | goto reopen_error_exit; |
561 | } | 620 | } |
562 | 621 | ||
563 | reopen_success: | 622 | reopen_success: |
564 | pCifsFile->netfid = netfid; | 623 | cfile->invalidHandle = false; |
565 | pCifsFile->invalidHandle = false; | 624 | mutex_unlock(&cfile->fh_mutex); |
566 | mutex_unlock(&pCifsFile->fh_mutex); | 625 | cinode = CIFS_I(inode); |
567 | pCifsInode = CIFS_I(inode); | ||
568 | 626 | ||
569 | if (can_flush) { | 627 | if (can_flush) { |
570 | rc = filemap_write_and_wait(inode->i_mapping); | 628 | rc = filemap_write_and_wait(inode->i_mapping); |
571 | mapping_set_error(inode->i_mapping, rc); | 629 | mapping_set_error(inode->i_mapping, rc); |
572 | 630 | ||
573 | if (tcon->unix_ext) | 631 | if (tcon->unix_ext) |
574 | rc = cifs_get_inode_info_unix(&inode, | 632 | rc = cifs_get_inode_info_unix(&inode, full_path, |
575 | full_path, inode->i_sb, xid); | 633 | inode->i_sb, xid); |
576 | else | 634 | else |
577 | rc = cifs_get_inode_info(&inode, | 635 | rc = cifs_get_inode_info(&inode, full_path, NULL, |
578 | full_path, NULL, inode->i_sb, | 636 | inode->i_sb, xid, NULL); |
579 | xid, NULL); | 637 | } |
580 | } /* else we are writing out data to server already | 638 | /* |
581 | and could deadlock if we tried to flush data, and | 639 | * Else we are writing out data to server already and could deadlock if |
582 | since we do not know if we have data that would | 640 | * we tried to flush data, and since we do not know if we have data that |
583 | invalidate the current end of file on the server | 641 | * would invalidate the current end of file on the server we can not go |
584 | we can not go to the server to get the new inod | 642 | * to the server to get the new inode info. |
585 | info */ | 643 | */ |
586 | |||
587 | cifs_set_oplock_level(pCifsInode, oplock); | ||
588 | 644 | ||
589 | cifs_relock_file(pCifsFile); | 645 | server->ops->set_fid(cfile, &fid, oplock); |
646 | cifs_relock_file(cfile); | ||
590 | 647 | ||
591 | reopen_error_exit: | 648 | reopen_error_exit: |
592 | kfree(full_path); | 649 | kfree(full_path); |
@@ -609,42 +666,48 @@ int cifs_closedir(struct inode *inode, struct file *file) | |||
609 | { | 666 | { |
610 | int rc = 0; | 667 | int rc = 0; |
611 | unsigned int xid; | 668 | unsigned int xid; |
612 | struct cifsFileInfo *pCFileStruct = file->private_data; | 669 | struct cifsFileInfo *cfile = file->private_data; |
613 | char *ptmp; | 670 | struct cifs_tcon *tcon; |
671 | struct TCP_Server_Info *server; | ||
672 | char *buf; | ||
614 | 673 | ||
615 | cFYI(1, "Closedir inode = 0x%p", inode); | 674 | cFYI(1, "Closedir inode = 0x%p", inode); |
616 | 675 | ||
676 | if (cfile == NULL) | ||
677 | return rc; | ||
678 | |||
617 | xid = get_xid(); | 679 | xid = get_xid(); |
680 | tcon = tlink_tcon(cfile->tlink); | ||
681 | server = tcon->ses->server; | ||
618 | 682 | ||
619 | if (pCFileStruct) { | 683 | cFYI(1, "Freeing private data in close dir"); |
620 | struct cifs_tcon *pTcon = tlink_tcon(pCFileStruct->tlink); | 684 | spin_lock(&cifs_file_list_lock); |
685 | if (!cfile->srch_inf.endOfSearch && !cfile->invalidHandle) { | ||
686 | cfile->invalidHandle = true; | ||
687 | spin_unlock(&cifs_file_list_lock); | ||
688 | if (server->ops->close_dir) | ||
689 | rc = server->ops->close_dir(xid, tcon, &cfile->fid); | ||
690 | else | ||
691 | rc = -ENOSYS; | ||
692 | cFYI(1, "Closing uncompleted readdir with rc %d", rc); | ||
693 | /* not much we can do if it fails anyway, ignore rc */ | ||
694 | rc = 0; | ||
695 | } else | ||
696 | spin_unlock(&cifs_file_list_lock); | ||
621 | 697 | ||
622 | cFYI(1, "Freeing private data in close dir"); | 698 | buf = cfile->srch_inf.ntwrk_buf_start; |
623 | spin_lock(&cifs_file_list_lock); | 699 | if (buf) { |
624 | if (!pCFileStruct->srch_inf.endOfSearch && | 700 | cFYI(1, "closedir free smb buf in srch struct"); |
625 | !pCFileStruct->invalidHandle) { | 701 | cfile->srch_inf.ntwrk_buf_start = NULL; |
626 | pCFileStruct->invalidHandle = true; | 702 | if (cfile->srch_inf.smallBuf) |
627 | spin_unlock(&cifs_file_list_lock); | 703 | cifs_small_buf_release(buf); |
628 | rc = CIFSFindClose(xid, pTcon, pCFileStruct->netfid); | 704 | else |
629 | cFYI(1, "Closing uncompleted readdir with rc %d", | 705 | cifs_buf_release(buf); |
630 | rc); | ||
631 | /* not much we can do if it fails anyway, ignore rc */ | ||
632 | rc = 0; | ||
633 | } else | ||
634 | spin_unlock(&cifs_file_list_lock); | ||
635 | ptmp = pCFileStruct->srch_inf.ntwrk_buf_start; | ||
636 | if (ptmp) { | ||
637 | cFYI(1, "closedir free smb buf in srch struct"); | ||
638 | pCFileStruct->srch_inf.ntwrk_buf_start = NULL; | ||
639 | if (pCFileStruct->srch_inf.smallBuf) | ||
640 | cifs_small_buf_release(ptmp); | ||
641 | else | ||
642 | cifs_buf_release(ptmp); | ||
643 | } | ||
644 | cifs_put_tlink(pCFileStruct->tlink); | ||
645 | kfree(file->private_data); | ||
646 | file->private_data = NULL; | ||
647 | } | 706 | } |
707 | |||
708 | cifs_put_tlink(cfile->tlink); | ||
709 | kfree(file->private_data); | ||
710 | file->private_data = NULL; | ||
648 | /* BB can we lock the filestruct while this is going on? */ | 711 | /* BB can we lock the filestruct while this is going on? */ |
649 | free_xid(xid); | 712 | free_xid(xid); |
650 | return rc; | 713 | return rc; |
@@ -666,7 +729,7 @@ cifs_lock_init(__u64 offset, __u64 length, __u8 type) | |||
666 | return lock; | 729 | return lock; |
667 | } | 730 | } |
668 | 731 | ||
669 | static void | 732 | void |
670 | cifs_del_lock_waiters(struct cifsLockInfo *lock) | 733 | cifs_del_lock_waiters(struct cifsLockInfo *lock) |
671 | { | 734 | { |
672 | struct cifsLockInfo *li, *tmp; | 735 | struct cifsLockInfo *li, *tmp; |
@@ -677,45 +740,47 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock) | |||
677 | } | 740 | } |
678 | 741 | ||
679 | static bool | 742 | static bool |
680 | cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, | 743 | cifs_find_fid_lock_conflict(struct cifs_fid_locks *fdlocks, __u64 offset, |
681 | __u64 length, __u8 type, struct cifsFileInfo *cur, | 744 | __u64 length, __u8 type, struct cifsFileInfo *cfile, |
682 | struct cifsLockInfo **conf_lock) | 745 | struct cifsLockInfo **conf_lock, bool rw_check) |
683 | { | 746 | { |
684 | struct cifsLockInfo *li; | 747 | struct cifsLockInfo *li; |
748 | struct cifsFileInfo *cur_cfile = fdlocks->cfile; | ||
685 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; | 749 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
686 | 750 | ||
687 | list_for_each_entry(li, &cfile->llist, llist) { | 751 | list_for_each_entry(li, &fdlocks->locks, llist) { |
688 | if (offset + length <= li->offset || | 752 | if (offset + length <= li->offset || |
689 | offset >= li->offset + li->length) | 753 | offset >= li->offset + li->length) |
690 | continue; | 754 | continue; |
691 | else if ((type & server->vals->shared_lock_type) && | 755 | if (rw_check && server->ops->compare_fids(cfile, cur_cfile) && |
692 | ((server->ops->compare_fids(cur, cfile) && | 756 | current->tgid == li->pid) |
693 | current->tgid == li->pid) || type == li->type)) | ||
694 | continue; | 757 | continue; |
695 | else { | 758 | if ((type & server->vals->shared_lock_type) && |
759 | ((server->ops->compare_fids(cfile, cur_cfile) && | ||
760 | current->tgid == li->pid) || type == li->type)) | ||
761 | continue; | ||
762 | if (conf_lock) | ||
696 | *conf_lock = li; | 763 | *conf_lock = li; |
697 | return true; | 764 | return true; |
698 | } | ||
699 | } | 765 | } |
700 | return false; | 766 | return false; |
701 | } | 767 | } |
702 | 768 | ||
703 | static bool | 769 | bool |
704 | cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length, | 770 | cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length, |
705 | __u8 type, struct cifsLockInfo **conf_lock) | 771 | __u8 type, struct cifsLockInfo **conf_lock, |
772 | bool rw_check) | ||
706 | { | 773 | { |
707 | bool rc = false; | 774 | bool rc = false; |
708 | struct cifsFileInfo *fid, *tmp; | 775 | struct cifs_fid_locks *cur; |
709 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | 776 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); |
710 | 777 | ||
711 | spin_lock(&cifs_file_list_lock); | 778 | list_for_each_entry(cur, &cinode->llist, llist) { |
712 | list_for_each_entry_safe(fid, tmp, &cinode->openFileList, flist) { | 779 | rc = cifs_find_fid_lock_conflict(cur, offset, length, type, |
713 | rc = cifs_find_fid_lock_conflict(fid, offset, length, type, | 780 | cfile, conf_lock, rw_check); |
714 | cfile, conf_lock); | ||
715 | if (rc) | 781 | if (rc) |
716 | break; | 782 | break; |
717 | } | 783 | } |
718 | spin_unlock(&cifs_file_list_lock); | ||
719 | 784 | ||
720 | return rc; | 785 | return rc; |
721 | } | 786 | } |
@@ -737,10 +802,10 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length, | |||
737 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; | 802 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
738 | bool exist; | 803 | bool exist; |
739 | 804 | ||
740 | mutex_lock(&cinode->lock_mutex); | 805 | down_read(&cinode->lock_sem); |
741 | 806 | ||
742 | exist = cifs_find_lock_conflict(cfile, offset, length, type, | 807 | exist = cifs_find_lock_conflict(cfile, offset, length, type, |
743 | &conf_lock); | 808 | &conf_lock, false); |
744 | if (exist) { | 809 | if (exist) { |
745 | flock->fl_start = conf_lock->offset; | 810 | flock->fl_start = conf_lock->offset; |
746 | flock->fl_end = conf_lock->offset + conf_lock->length - 1; | 811 | flock->fl_end = conf_lock->offset + conf_lock->length - 1; |
@@ -754,7 +819,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length, | |||
754 | else | 819 | else |
755 | flock->fl_type = F_UNLCK; | 820 | flock->fl_type = F_UNLCK; |
756 | 821 | ||
757 | mutex_unlock(&cinode->lock_mutex); | 822 | up_read(&cinode->lock_sem); |
758 | return rc; | 823 | return rc; |
759 | } | 824 | } |
760 | 825 | ||
@@ -762,9 +827,9 @@ static void | |||
762 | cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock) | 827 | cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock) |
763 | { | 828 | { |
764 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | 829 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); |
765 | mutex_lock(&cinode->lock_mutex); | 830 | down_write(&cinode->lock_sem); |
766 | list_add_tail(&lock->llist, &cfile->llist); | 831 | list_add_tail(&lock->llist, &cfile->llist->locks); |
767 | mutex_unlock(&cinode->lock_mutex); | 832 | up_write(&cinode->lock_sem); |
768 | } | 833 | } |
769 | 834 | ||
770 | /* | 835 | /* |
@@ -784,13 +849,13 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock, | |||
784 | 849 | ||
785 | try_again: | 850 | try_again: |
786 | exist = false; | 851 | exist = false; |
787 | mutex_lock(&cinode->lock_mutex); | 852 | down_write(&cinode->lock_sem); |
788 | 853 | ||
789 | exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length, | 854 | exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length, |
790 | lock->type, &conf_lock); | 855 | lock->type, &conf_lock, false); |
791 | if (!exist && cinode->can_cache_brlcks) { | 856 | if (!exist && cinode->can_cache_brlcks) { |
792 | list_add_tail(&lock->llist, &cfile->llist); | 857 | list_add_tail(&lock->llist, &cfile->llist->locks); |
793 | mutex_unlock(&cinode->lock_mutex); | 858 | up_write(&cinode->lock_sem); |
794 | return rc; | 859 | return rc; |
795 | } | 860 | } |
796 | 861 | ||
@@ -800,17 +865,17 @@ try_again: | |||
800 | rc = -EACCES; | 865 | rc = -EACCES; |
801 | else { | 866 | else { |
802 | list_add_tail(&lock->blist, &conf_lock->blist); | 867 | list_add_tail(&lock->blist, &conf_lock->blist); |
803 | mutex_unlock(&cinode->lock_mutex); | 868 | up_write(&cinode->lock_sem); |
804 | rc = wait_event_interruptible(lock->block_q, | 869 | rc = wait_event_interruptible(lock->block_q, |
805 | (lock->blist.prev == &lock->blist) && | 870 | (lock->blist.prev == &lock->blist) && |
806 | (lock->blist.next == &lock->blist)); | 871 | (lock->blist.next == &lock->blist)); |
807 | if (!rc) | 872 | if (!rc) |
808 | goto try_again; | 873 | goto try_again; |
809 | mutex_lock(&cinode->lock_mutex); | 874 | down_write(&cinode->lock_sem); |
810 | list_del_init(&lock->blist); | 875 | list_del_init(&lock->blist); |
811 | } | 876 | } |
812 | 877 | ||
813 | mutex_unlock(&cinode->lock_mutex); | 878 | up_write(&cinode->lock_sem); |
814 | return rc; | 879 | return rc; |
815 | } | 880 | } |
816 | 881 | ||
@@ -831,7 +896,7 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock) | |||
831 | if ((flock->fl_flags & FL_POSIX) == 0) | 896 | if ((flock->fl_flags & FL_POSIX) == 0) |
832 | return 1; | 897 | return 1; |
833 | 898 | ||
834 | mutex_lock(&cinode->lock_mutex); | 899 | down_read(&cinode->lock_sem); |
835 | posix_test_lock(file, flock); | 900 | posix_test_lock(file, flock); |
836 | 901 | ||
837 | if (flock->fl_type == F_UNLCK && !cinode->can_cache_brlcks) { | 902 | if (flock->fl_type == F_UNLCK && !cinode->can_cache_brlcks) { |
@@ -839,7 +904,7 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock) | |||
839 | rc = 1; | 904 | rc = 1; |
840 | } | 905 | } |
841 | 906 | ||
842 | mutex_unlock(&cinode->lock_mutex); | 907 | up_read(&cinode->lock_sem); |
843 | return rc; | 908 | return rc; |
844 | } | 909 | } |
845 | 910 | ||
@@ -859,14 +924,14 @@ cifs_posix_lock_set(struct file *file, struct file_lock *flock) | |||
859 | return rc; | 924 | return rc; |
860 | 925 | ||
861 | try_again: | 926 | try_again: |
862 | mutex_lock(&cinode->lock_mutex); | 927 | down_write(&cinode->lock_sem); |
863 | if (!cinode->can_cache_brlcks) { | 928 | if (!cinode->can_cache_brlcks) { |
864 | mutex_unlock(&cinode->lock_mutex); | 929 | up_write(&cinode->lock_sem); |
865 | return rc; | 930 | return rc; |
866 | } | 931 | } |
867 | 932 | ||
868 | rc = posix_lock_file(file, flock, NULL); | 933 | rc = posix_lock_file(file, flock, NULL); |
869 | mutex_unlock(&cinode->lock_mutex); | 934 | up_write(&cinode->lock_sem); |
870 | if (rc == FILE_LOCK_DEFERRED) { | 935 | if (rc == FILE_LOCK_DEFERRED) { |
871 | rc = wait_event_interruptible(flock->fl_wait, !flock->fl_next); | 936 | rc = wait_event_interruptible(flock->fl_wait, !flock->fl_next); |
872 | if (!rc) | 937 | if (!rc) |
@@ -876,7 +941,7 @@ try_again: | |||
876 | return rc; | 941 | return rc; |
877 | } | 942 | } |
878 | 943 | ||
879 | static int | 944 | int |
880 | cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | 945 | cifs_push_mandatory_locks(struct cifsFileInfo *cfile) |
881 | { | 946 | { |
882 | unsigned int xid; | 947 | unsigned int xid; |
@@ -893,9 +958,10 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
893 | xid = get_xid(); | 958 | xid = get_xid(); |
894 | tcon = tlink_tcon(cfile->tlink); | 959 | tcon = tlink_tcon(cfile->tlink); |
895 | 960 | ||
896 | mutex_lock(&cinode->lock_mutex); | 961 | /* we are going to update can_cache_brlcks here - need a write access */ |
962 | down_write(&cinode->lock_sem); | ||
897 | if (!cinode->can_cache_brlcks) { | 963 | if (!cinode->can_cache_brlcks) { |
898 | mutex_unlock(&cinode->lock_mutex); | 964 | up_write(&cinode->lock_sem); |
899 | free_xid(xid); | 965 | free_xid(xid); |
900 | return rc; | 966 | return rc; |
901 | } | 967 | } |
@@ -906,7 +972,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
906 | */ | 972 | */ |
907 | max_buf = tcon->ses->server->maxBuf; | 973 | max_buf = tcon->ses->server->maxBuf; |
908 | if (!max_buf) { | 974 | if (!max_buf) { |
909 | mutex_unlock(&cinode->lock_mutex); | 975 | up_write(&cinode->lock_sem); |
910 | free_xid(xid); | 976 | free_xid(xid); |
911 | return -EINVAL; | 977 | return -EINVAL; |
912 | } | 978 | } |
@@ -915,7 +981,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
915 | sizeof(LOCKING_ANDX_RANGE); | 981 | sizeof(LOCKING_ANDX_RANGE); |
916 | buf = kzalloc(max_num * sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL); | 982 | buf = kzalloc(max_num * sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL); |
917 | if (!buf) { | 983 | if (!buf) { |
918 | mutex_unlock(&cinode->lock_mutex); | 984 | up_write(&cinode->lock_sem); |
919 | free_xid(xid); | 985 | free_xid(xid); |
920 | return -ENOMEM; | 986 | return -ENOMEM; |
921 | } | 987 | } |
@@ -923,7 +989,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
923 | for (i = 0; i < 2; i++) { | 989 | for (i = 0; i < 2; i++) { |
924 | cur = buf; | 990 | cur = buf; |
925 | num = 0; | 991 | num = 0; |
926 | list_for_each_entry_safe(li, tmp, &cfile->llist, llist) { | 992 | list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { |
927 | if (li->type != types[i]) | 993 | if (li->type != types[i]) |
928 | continue; | 994 | continue; |
929 | cur->Pid = cpu_to_le16(li->pid); | 995 | cur->Pid = cpu_to_le16(li->pid); |
@@ -932,7 +998,8 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
932 | cur->OffsetLow = cpu_to_le32((u32)li->offset); | 998 | cur->OffsetLow = cpu_to_le32((u32)li->offset); |
933 | cur->OffsetHigh = cpu_to_le32((u32)(li->offset>>32)); | 999 | cur->OffsetHigh = cpu_to_le32((u32)(li->offset>>32)); |
934 | if (++num == max_num) { | 1000 | if (++num == max_num) { |
935 | stored_rc = cifs_lockv(xid, tcon, cfile->netfid, | 1001 | stored_rc = cifs_lockv(xid, tcon, |
1002 | cfile->fid.netfid, | ||
936 | (__u8)li->type, 0, num, | 1003 | (__u8)li->type, 0, num, |
937 | buf); | 1004 | buf); |
938 | if (stored_rc) | 1005 | if (stored_rc) |
@@ -944,7 +1011,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
944 | } | 1011 | } |
945 | 1012 | ||
946 | if (num) { | 1013 | if (num) { |
947 | stored_rc = cifs_lockv(xid, tcon, cfile->netfid, | 1014 | stored_rc = cifs_lockv(xid, tcon, cfile->fid.netfid, |
948 | (__u8)types[i], 0, num, buf); | 1015 | (__u8)types[i], 0, num, buf); |
949 | if (stored_rc) | 1016 | if (stored_rc) |
950 | rc = stored_rc; | 1017 | rc = stored_rc; |
@@ -952,7 +1019,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
952 | } | 1019 | } |
953 | 1020 | ||
954 | cinode->can_cache_brlcks = false; | 1021 | cinode->can_cache_brlcks = false; |
955 | mutex_unlock(&cinode->lock_mutex); | 1022 | up_write(&cinode->lock_sem); |
956 | 1023 | ||
957 | kfree(buf); | 1024 | kfree(buf); |
958 | free_xid(xid); | 1025 | free_xid(xid); |
@@ -987,9 +1054,10 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) | |||
987 | 1054 | ||
988 | xid = get_xid(); | 1055 | xid = get_xid(); |
989 | 1056 | ||
990 | mutex_lock(&cinode->lock_mutex); | 1057 | /* we are going to update can_cache_brlcks here - need a write access */ |
1058 | down_write(&cinode->lock_sem); | ||
991 | if (!cinode->can_cache_brlcks) { | 1059 | if (!cinode->can_cache_brlcks) { |
992 | mutex_unlock(&cinode->lock_mutex); | 1060 | up_write(&cinode->lock_sem); |
993 | free_xid(xid); | 1061 | free_xid(xid); |
994 | return rc; | 1062 | return rc; |
995 | } | 1063 | } |
@@ -1005,7 +1073,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) | |||
1005 | 1073 | ||
1006 | /* | 1074 | /* |
1007 | * Allocating count locks is enough because no FL_POSIX locks can be | 1075 | * Allocating count locks is enough because no FL_POSIX locks can be |
1008 | * added to the list while we are holding cinode->lock_mutex that | 1076 | * added to the list while we are holding cinode->lock_sem that |
1009 | * protects locking operations of this inode. | 1077 | * protects locking operations of this inode. |
1010 | */ | 1078 | */ |
1011 | for (; i < count; i++) { | 1079 | for (; i < count; i++) { |
@@ -1038,7 +1106,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) | |||
1038 | type = CIFS_WRLCK; | 1106 | type = CIFS_WRLCK; |
1039 | lck = list_entry(el, struct lock_to_push, llist); | 1107 | lck = list_entry(el, struct lock_to_push, llist); |
1040 | lck->pid = flock->fl_pid; | 1108 | lck->pid = flock->fl_pid; |
1041 | lck->netfid = cfile->netfid; | 1109 | lck->netfid = cfile->fid.netfid; |
1042 | lck->length = length; | 1110 | lck->length = length; |
1043 | lck->type = type; | 1111 | lck->type = type; |
1044 | lck->offset = flock->fl_start; | 1112 | lck->offset = flock->fl_start; |
@@ -1060,7 +1128,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) | |||
1060 | 1128 | ||
1061 | out: | 1129 | out: |
1062 | cinode->can_cache_brlcks = false; | 1130 | cinode->can_cache_brlcks = false; |
1063 | mutex_unlock(&cinode->lock_mutex); | 1131 | up_write(&cinode->lock_sem); |
1064 | 1132 | ||
1065 | free_xid(xid); | 1133 | free_xid(xid); |
1066 | return rc; | 1134 | return rc; |
@@ -1083,7 +1151,7 @@ cifs_push_locks(struct cifsFileInfo *cfile) | |||
1083 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) | 1151 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) |
1084 | return cifs_push_posix_locks(cfile); | 1152 | return cifs_push_posix_locks(cfile); |
1085 | 1153 | ||
1086 | return cifs_push_mandatory_locks(cfile); | 1154 | return tcon->ses->server->ops->push_mand_locks(cfile); |
1087 | } | 1155 | } |
1088 | 1156 | ||
1089 | static void | 1157 | static void |
@@ -1104,7 +1172,8 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock, | |||
1104 | if (flock->fl_flags & FL_LEASE) | 1172 | if (flock->fl_flags & FL_LEASE) |
1105 | cFYI(1, "Lease on file - not implemented yet"); | 1173 | cFYI(1, "Lease on file - not implemented yet"); |
1106 | if (flock->fl_flags & | 1174 | if (flock->fl_flags & |
1107 | (~(FL_POSIX | FL_FLOCK | FL_SLEEP | FL_ACCESS | FL_LEASE))) | 1175 | (~(FL_POSIX | FL_FLOCK | FL_SLEEP | |
1176 | FL_ACCESS | FL_LEASE | FL_CLOSE))) | ||
1108 | cFYI(1, "Unknown lock flags 0x%x", flock->fl_flags); | 1177 | cFYI(1, "Unknown lock flags 0x%x", flock->fl_flags); |
1109 | 1178 | ||
1110 | *type = server->vals->large_lock_type; | 1179 | *type = server->vals->large_lock_type; |
@@ -1134,15 +1203,6 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock, | |||
1134 | } | 1203 | } |
1135 | 1204 | ||
1136 | static int | 1205 | static int |
1137 | cifs_mandatory_lock(unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, | ||
1138 | __u64 length, __u32 type, int lock, int unlock, bool wait) | ||
1139 | { | ||
1140 | return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->netfid, | ||
1141 | current->tgid, length, offset, unlock, lock, | ||
1142 | (__u8)type, wait, 0); | ||
1143 | } | ||
1144 | |||
1145 | static int | ||
1146 | cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, | 1206 | cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, |
1147 | bool wait_flag, bool posix_lck, unsigned int xid) | 1207 | bool wait_flag, bool posix_lck, unsigned int xid) |
1148 | { | 1208 | { |
@@ -1151,7 +1211,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1151 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; | 1211 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; |
1152 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | 1212 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
1153 | struct TCP_Server_Info *server = tcon->ses->server; | 1213 | struct TCP_Server_Info *server = tcon->ses->server; |
1154 | __u16 netfid = cfile->netfid; | 1214 | __u16 netfid = cfile->fid.netfid; |
1155 | 1215 | ||
1156 | if (posix_lck) { | 1216 | if (posix_lck) { |
1157 | int posix_lock_type; | 1217 | int posix_lock_type; |
@@ -1175,11 +1235,11 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1175 | return rc; | 1235 | return rc; |
1176 | 1236 | ||
1177 | /* BB we could chain these into one lock request BB */ | 1237 | /* BB we could chain these into one lock request BB */ |
1178 | rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, type, | 1238 | rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, type, |
1179 | 1, 0, false); | 1239 | 1, 0, false); |
1180 | if (rc == 0) { | 1240 | if (rc == 0) { |
1181 | rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, | 1241 | rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, |
1182 | type, 0, 1, false); | 1242 | type, 0, 1, false); |
1183 | flock->fl_type = F_UNLCK; | 1243 | flock->fl_type = F_UNLCK; |
1184 | if (rc != 0) | 1244 | if (rc != 0) |
1185 | cERROR(1, "Error unlocking previously locked " | 1245 | cERROR(1, "Error unlocking previously locked " |
@@ -1192,13 +1252,14 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1192 | return 0; | 1252 | return 0; |
1193 | } | 1253 | } |
1194 | 1254 | ||
1195 | rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, | 1255 | type &= ~server->vals->exclusive_lock_type; |
1196 | type | server->vals->shared_lock_type, 1, 0, | 1256 | |
1197 | false); | 1257 | rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, |
1258 | type | server->vals->shared_lock_type, | ||
1259 | 1, 0, false); | ||
1198 | if (rc == 0) { | 1260 | if (rc == 0) { |
1199 | rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, | 1261 | rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, |
1200 | type | server->vals->shared_lock_type, | 1262 | type | server->vals->shared_lock_type, 0, 1, false); |
1201 | 0, 1, false); | ||
1202 | flock->fl_type = F_RDLCK; | 1263 | flock->fl_type = F_RDLCK; |
1203 | if (rc != 0) | 1264 | if (rc != 0) |
1204 | cERROR(1, "Error unlocking previously locked " | 1265 | cERROR(1, "Error unlocking previously locked " |
@@ -1209,7 +1270,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1209 | return 0; | 1270 | return 0; |
1210 | } | 1271 | } |
1211 | 1272 | ||
1212 | static void | 1273 | void |
1213 | cifs_move_llist(struct list_head *source, struct list_head *dest) | 1274 | cifs_move_llist(struct list_head *source, struct list_head *dest) |
1214 | { | 1275 | { |
1215 | struct list_head *li, *tmp; | 1276 | struct list_head *li, *tmp; |
@@ -1217,7 +1278,7 @@ cifs_move_llist(struct list_head *source, struct list_head *dest) | |||
1217 | list_move(li, dest); | 1278 | list_move(li, dest); |
1218 | } | 1279 | } |
1219 | 1280 | ||
1220 | static void | 1281 | void |
1221 | cifs_free_llist(struct list_head *llist) | 1282 | cifs_free_llist(struct list_head *llist) |
1222 | { | 1283 | { |
1223 | struct cifsLockInfo *li, *tmp; | 1284 | struct cifsLockInfo *li, *tmp; |
@@ -1228,7 +1289,7 @@ cifs_free_llist(struct list_head *llist) | |||
1228 | } | 1289 | } |
1229 | } | 1290 | } |
1230 | 1291 | ||
1231 | static int | 1292 | int |
1232 | cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | 1293 | cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, |
1233 | unsigned int xid) | 1294 | unsigned int xid) |
1234 | { | 1295 | { |
@@ -1260,11 +1321,11 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | |||
1260 | if (!buf) | 1321 | if (!buf) |
1261 | return -ENOMEM; | 1322 | return -ENOMEM; |
1262 | 1323 | ||
1263 | mutex_lock(&cinode->lock_mutex); | 1324 | down_write(&cinode->lock_sem); |
1264 | for (i = 0; i < 2; i++) { | 1325 | for (i = 0; i < 2; i++) { |
1265 | cur = buf; | 1326 | cur = buf; |
1266 | num = 0; | 1327 | num = 0; |
1267 | list_for_each_entry_safe(li, tmp, &cfile->llist, llist) { | 1328 | list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { |
1268 | if (flock->fl_start > li->offset || | 1329 | if (flock->fl_start > li->offset || |
1269 | (flock->fl_start + length) < | 1330 | (flock->fl_start + length) < |
1270 | (li->offset + li->length)) | 1331 | (li->offset + li->length)) |
@@ -1295,7 +1356,8 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | |||
1295 | */ | 1356 | */ |
1296 | list_move(&li->llist, &tmp_llist); | 1357 | list_move(&li->llist, &tmp_llist); |
1297 | if (++num == max_num) { | 1358 | if (++num == max_num) { |
1298 | stored_rc = cifs_lockv(xid, tcon, cfile->netfid, | 1359 | stored_rc = cifs_lockv(xid, tcon, |
1360 | cfile->fid.netfid, | ||
1299 | li->type, num, 0, buf); | 1361 | li->type, num, 0, buf); |
1300 | if (stored_rc) { | 1362 | if (stored_rc) { |
1301 | /* | 1363 | /* |
@@ -1304,7 +1366,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | |||
1304 | * list to the head of the file's list. | 1366 | * list to the head of the file's list. |
1305 | */ | 1367 | */ |
1306 | cifs_move_llist(&tmp_llist, | 1368 | cifs_move_llist(&tmp_llist, |
1307 | &cfile->llist); | 1369 | &cfile->llist->locks); |
1308 | rc = stored_rc; | 1370 | rc = stored_rc; |
1309 | } else | 1371 | } else |
1310 | /* | 1372 | /* |
@@ -1318,23 +1380,24 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | |||
1318 | cur++; | 1380 | cur++; |
1319 | } | 1381 | } |
1320 | if (num) { | 1382 | if (num) { |
1321 | stored_rc = cifs_lockv(xid, tcon, cfile->netfid, | 1383 | stored_rc = cifs_lockv(xid, tcon, cfile->fid.netfid, |
1322 | types[i], num, 0, buf); | 1384 | types[i], num, 0, buf); |
1323 | if (stored_rc) { | 1385 | if (stored_rc) { |
1324 | cifs_move_llist(&tmp_llist, &cfile->llist); | 1386 | cifs_move_llist(&tmp_llist, |
1387 | &cfile->llist->locks); | ||
1325 | rc = stored_rc; | 1388 | rc = stored_rc; |
1326 | } else | 1389 | } else |
1327 | cifs_free_llist(&tmp_llist); | 1390 | cifs_free_llist(&tmp_llist); |
1328 | } | 1391 | } |
1329 | } | 1392 | } |
1330 | 1393 | ||
1331 | mutex_unlock(&cinode->lock_mutex); | 1394 | up_write(&cinode->lock_sem); |
1332 | kfree(buf); | 1395 | kfree(buf); |
1333 | return rc; | 1396 | return rc; |
1334 | } | 1397 | } |
1335 | 1398 | ||
1336 | static int | 1399 | static int |
1337 | cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, | 1400 | cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, |
1338 | bool wait_flag, bool posix_lck, int lock, int unlock, | 1401 | bool wait_flag, bool posix_lck, int lock, int unlock, |
1339 | unsigned int xid) | 1402 | unsigned int xid) |
1340 | { | 1403 | { |
@@ -1343,7 +1406,6 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1343 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; | 1406 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; |
1344 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | 1407 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
1345 | struct TCP_Server_Info *server = tcon->ses->server; | 1408 | struct TCP_Server_Info *server = tcon->ses->server; |
1346 | __u16 netfid = cfile->netfid; | ||
1347 | 1409 | ||
1348 | if (posix_lck) { | 1410 | if (posix_lck) { |
1349 | int posix_lock_type; | 1411 | int posix_lock_type; |
@@ -1360,9 +1422,9 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1360 | if (unlock == 1) | 1422 | if (unlock == 1) |
1361 | posix_lock_type = CIFS_UNLCK; | 1423 | posix_lock_type = CIFS_UNLCK; |
1362 | 1424 | ||
1363 | rc = CIFSSMBPosixLock(xid, tcon, netfid, current->tgid, | 1425 | rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid, |
1364 | flock->fl_start, length, NULL, | 1426 | current->tgid, flock->fl_start, length, |
1365 | posix_lock_type, wait_flag); | 1427 | NULL, posix_lock_type, wait_flag); |
1366 | goto out; | 1428 | goto out; |
1367 | } | 1429 | } |
1368 | 1430 | ||
@@ -1379,8 +1441,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1379 | if (rc <= 0) | 1441 | if (rc <= 0) |
1380 | goto out; | 1442 | goto out; |
1381 | 1443 | ||
1382 | rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, | 1444 | rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, |
1383 | type, 1, 0, wait_flag); | 1445 | type, 1, 0, wait_flag); |
1384 | if (rc) { | 1446 | if (rc) { |
1385 | kfree(lock); | 1447 | kfree(lock); |
1386 | goto out; | 1448 | goto out; |
@@ -1388,7 +1450,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1388 | 1450 | ||
1389 | cifs_lock_add(cfile, lock); | 1451 | cifs_lock_add(cfile, lock); |
1390 | } else if (unlock) | 1452 | } else if (unlock) |
1391 | rc = cifs_unlock_range(cfile, flock, xid); | 1453 | rc = server->ops->mand_unlock_range(cfile, flock, xid); |
1392 | 1454 | ||
1393 | out: | 1455 | out: |
1394 | if (flock->fl_flags & FL_POSIX) | 1456 | if (flock->fl_flags & FL_POSIX) |
@@ -1423,7 +1485,7 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock) | |||
1423 | tcon->ses->server); | 1485 | tcon->ses->server); |
1424 | 1486 | ||
1425 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 1487 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
1426 | netfid = cfile->netfid; | 1488 | netfid = cfile->fid.netfid; |
1427 | cinode = CIFS_I(file->f_path.dentry->d_inode); | 1489 | cinode = CIFS_I(file->f_path.dentry->d_inode); |
1428 | 1490 | ||
1429 | if (cap_unix(tcon->ses) && | 1491 | if (cap_unix(tcon->ses) && |
@@ -1469,15 +1531,16 @@ cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, | |||
1469 | cifsi->server_eof = end_of_write; | 1531 | cifsi->server_eof = end_of_write; |
1470 | } | 1532 | } |
1471 | 1533 | ||
1472 | static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid, | 1534 | static ssize_t |
1473 | const char *write_data, size_t write_size, | 1535 | cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data, |
1474 | loff_t *poffset) | 1536 | size_t write_size, loff_t *offset) |
1475 | { | 1537 | { |
1476 | int rc = 0; | 1538 | int rc = 0; |
1477 | unsigned int bytes_written = 0; | 1539 | unsigned int bytes_written = 0; |
1478 | unsigned int total_written; | 1540 | unsigned int total_written; |
1479 | struct cifs_sb_info *cifs_sb; | 1541 | struct cifs_sb_info *cifs_sb; |
1480 | struct cifs_tcon *pTcon; | 1542 | struct cifs_tcon *tcon; |
1543 | struct TCP_Server_Info *server; | ||
1481 | unsigned int xid; | 1544 | unsigned int xid; |
1482 | struct dentry *dentry = open_file->dentry; | 1545 | struct dentry *dentry = open_file->dentry; |
1483 | struct cifsInodeInfo *cifsi = CIFS_I(dentry->d_inode); | 1546 | struct cifsInodeInfo *cifsi = CIFS_I(dentry->d_inode); |
@@ -1486,9 +1549,13 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid, | |||
1486 | cifs_sb = CIFS_SB(dentry->d_sb); | 1549 | cifs_sb = CIFS_SB(dentry->d_sb); |
1487 | 1550 | ||
1488 | cFYI(1, "write %zd bytes to offset %lld of %s", write_size, | 1551 | cFYI(1, "write %zd bytes to offset %lld of %s", write_size, |
1489 | *poffset, dentry->d_name.name); | 1552 | *offset, dentry->d_name.name); |
1490 | 1553 | ||
1491 | pTcon = tlink_tcon(open_file->tlink); | 1554 | tcon = tlink_tcon(open_file->tlink); |
1555 | server = tcon->ses->server; | ||
1556 | |||
1557 | if (!server->ops->sync_write) | ||
1558 | return -ENOSYS; | ||
1492 | 1559 | ||
1493 | xid = get_xid(); | 1560 | xid = get_xid(); |
1494 | 1561 | ||
@@ -1514,13 +1581,12 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid, | |||
1514 | /* iov[0] is reserved for smb header */ | 1581 | /* iov[0] is reserved for smb header */ |
1515 | iov[1].iov_base = (char *)write_data + total_written; | 1582 | iov[1].iov_base = (char *)write_data + total_written; |
1516 | iov[1].iov_len = len; | 1583 | iov[1].iov_len = len; |
1517 | io_parms.netfid = open_file->netfid; | ||
1518 | io_parms.pid = pid; | 1584 | io_parms.pid = pid; |
1519 | io_parms.tcon = pTcon; | 1585 | io_parms.tcon = tcon; |
1520 | io_parms.offset = *poffset; | 1586 | io_parms.offset = *offset; |
1521 | io_parms.length = len; | 1587 | io_parms.length = len; |
1522 | rc = CIFSSMBWrite2(xid, &io_parms, &bytes_written, iov, | 1588 | rc = server->ops->sync_write(xid, open_file, &io_parms, |
1523 | 1, 0); | 1589 | &bytes_written, iov, 1); |
1524 | } | 1590 | } |
1525 | if (rc || (bytes_written == 0)) { | 1591 | if (rc || (bytes_written == 0)) { |
1526 | if (total_written) | 1592 | if (total_written) |
@@ -1531,18 +1597,18 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid, | |||
1531 | } | 1597 | } |
1532 | } else { | 1598 | } else { |
1533 | spin_lock(&dentry->d_inode->i_lock); | 1599 | spin_lock(&dentry->d_inode->i_lock); |
1534 | cifs_update_eof(cifsi, *poffset, bytes_written); | 1600 | cifs_update_eof(cifsi, *offset, bytes_written); |
1535 | spin_unlock(&dentry->d_inode->i_lock); | 1601 | spin_unlock(&dentry->d_inode->i_lock); |
1536 | *poffset += bytes_written; | 1602 | *offset += bytes_written; |
1537 | } | 1603 | } |
1538 | } | 1604 | } |
1539 | 1605 | ||
1540 | cifs_stats_bytes_written(pTcon, total_written); | 1606 | cifs_stats_bytes_written(tcon, total_written); |
1541 | 1607 | ||
1542 | if (total_written > 0) { | 1608 | if (total_written > 0) { |
1543 | spin_lock(&dentry->d_inode->i_lock); | 1609 | spin_lock(&dentry->d_inode->i_lock); |
1544 | if (*poffset > dentry->d_inode->i_size) | 1610 | if (*offset > dentry->d_inode->i_size) |
1545 | i_size_write(dentry->d_inode, *poffset); | 1611 | i_size_write(dentry->d_inode, *offset); |
1546 | spin_unlock(&dentry->d_inode->i_lock); | 1612 | spin_unlock(&dentry->d_inode->i_lock); |
1547 | } | 1613 | } |
1548 | mark_inode_dirty_sync(dentry->d_inode); | 1614 | mark_inode_dirty_sync(dentry->d_inode); |
@@ -1718,27 +1784,6 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) | |||
1718 | return rc; | 1784 | return rc; |
1719 | } | 1785 | } |
1720 | 1786 | ||
1721 | /* | ||
1722 | * Marshal up the iov array, reserving the first one for the header. Also, | ||
1723 | * set wdata->bytes. | ||
1724 | */ | ||
1725 | static void | ||
1726 | cifs_writepages_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata) | ||
1727 | { | ||
1728 | int i; | ||
1729 | struct inode *inode = wdata->cfile->dentry->d_inode; | ||
1730 | loff_t size = i_size_read(inode); | ||
1731 | |||
1732 | /* marshal up the pages into iov array */ | ||
1733 | wdata->bytes = 0; | ||
1734 | for (i = 0; i < wdata->nr_pages; i++) { | ||
1735 | iov[i + 1].iov_len = min(size - page_offset(wdata->pages[i]), | ||
1736 | (loff_t)PAGE_CACHE_SIZE); | ||
1737 | iov[i + 1].iov_base = kmap(wdata->pages[i]); | ||
1738 | wdata->bytes += iov[i + 1].iov_len; | ||
1739 | } | ||
1740 | } | ||
1741 | |||
1742 | static int cifs_writepages(struct address_space *mapping, | 1787 | static int cifs_writepages(struct address_space *mapping, |
1743 | struct writeback_control *wbc) | 1788 | struct writeback_control *wbc) |
1744 | { | 1789 | { |
@@ -1746,8 +1791,10 @@ static int cifs_writepages(struct address_space *mapping, | |||
1746 | bool done = false, scanned = false, range_whole = false; | 1791 | bool done = false, scanned = false, range_whole = false; |
1747 | pgoff_t end, index; | 1792 | pgoff_t end, index; |
1748 | struct cifs_writedata *wdata; | 1793 | struct cifs_writedata *wdata; |
1794 | struct TCP_Server_Info *server; | ||
1749 | struct page *page; | 1795 | struct page *page; |
1750 | int rc = 0; | 1796 | int rc = 0; |
1797 | loff_t isize = i_size_read(mapping->host); | ||
1751 | 1798 | ||
1752 | /* | 1799 | /* |
1753 | * If wsize is smaller than the page cache size, default to writing | 1800 | * If wsize is smaller than the page cache size, default to writing |
@@ -1852,7 +1899,7 @@ retry: | |||
1852 | */ | 1899 | */ |
1853 | set_page_writeback(page); | 1900 | set_page_writeback(page); |
1854 | 1901 | ||
1855 | if (page_offset(page) >= mapping->host->i_size) { | 1902 | if (page_offset(page) >= isize) { |
1856 | done = true; | 1903 | done = true; |
1857 | unlock_page(page); | 1904 | unlock_page(page); |
1858 | end_page_writeback(page); | 1905 | end_page_writeback(page); |
@@ -1883,7 +1930,12 @@ retry: | |||
1883 | wdata->sync_mode = wbc->sync_mode; | 1930 | wdata->sync_mode = wbc->sync_mode; |
1884 | wdata->nr_pages = nr_pages; | 1931 | wdata->nr_pages = nr_pages; |
1885 | wdata->offset = page_offset(wdata->pages[0]); | 1932 | wdata->offset = page_offset(wdata->pages[0]); |
1886 | wdata->marshal_iov = cifs_writepages_marshal_iov; | 1933 | wdata->pagesz = PAGE_CACHE_SIZE; |
1934 | wdata->tailsz = | ||
1935 | min(isize - page_offset(wdata->pages[nr_pages - 1]), | ||
1936 | (loff_t)PAGE_CACHE_SIZE); | ||
1937 | wdata->bytes = ((nr_pages - 1) * PAGE_CACHE_SIZE) + | ||
1938 | wdata->tailsz; | ||
1887 | 1939 | ||
1888 | do { | 1940 | do { |
1889 | if (wdata->cfile != NULL) | 1941 | if (wdata->cfile != NULL) |
@@ -1896,7 +1948,8 @@ retry: | |||
1896 | break; | 1948 | break; |
1897 | } | 1949 | } |
1898 | wdata->pid = wdata->cfile->pid; | 1950 | wdata->pid = wdata->cfile->pid; |
1899 | rc = cifs_async_writev(wdata); | 1951 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; |
1952 | rc = server->ops->async_writev(wdata); | ||
1900 | } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN); | 1953 | } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN); |
1901 | 1954 | ||
1902 | for (i = 0; i < nr_pages; ++i) | 1955 | for (i = 0; i < nr_pages; ++i) |
@@ -2054,6 +2107,7 @@ int cifs_strict_fsync(struct file *file, loff_t start, loff_t end, | |||
2054 | unsigned int xid; | 2107 | unsigned int xid; |
2055 | int rc = 0; | 2108 | int rc = 0; |
2056 | struct cifs_tcon *tcon; | 2109 | struct cifs_tcon *tcon; |
2110 | struct TCP_Server_Info *server; | ||
2057 | struct cifsFileInfo *smbfile = file->private_data; | 2111 | struct cifsFileInfo *smbfile = file->private_data; |
2058 | struct inode *inode = file->f_path.dentry->d_inode; | 2112 | struct inode *inode = file->f_path.dentry->d_inode; |
2059 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 2113 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
@@ -2077,8 +2131,13 @@ int cifs_strict_fsync(struct file *file, loff_t start, loff_t end, | |||
2077 | } | 2131 | } |
2078 | 2132 | ||
2079 | tcon = tlink_tcon(smbfile->tlink); | 2133 | tcon = tlink_tcon(smbfile->tlink); |
2080 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) | 2134 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) { |
2081 | rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); | 2135 | server = tcon->ses->server; |
2136 | if (server->ops->flush) | ||
2137 | rc = server->ops->flush(xid, tcon, &smbfile->fid); | ||
2138 | else | ||
2139 | rc = -ENOSYS; | ||
2140 | } | ||
2082 | 2141 | ||
2083 | free_xid(xid); | 2142 | free_xid(xid); |
2084 | mutex_unlock(&inode->i_mutex); | 2143 | mutex_unlock(&inode->i_mutex); |
@@ -2090,6 +2149,7 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync) | |||
2090 | unsigned int xid; | 2149 | unsigned int xid; |
2091 | int rc = 0; | 2150 | int rc = 0; |
2092 | struct cifs_tcon *tcon; | 2151 | struct cifs_tcon *tcon; |
2152 | struct TCP_Server_Info *server; | ||
2093 | struct cifsFileInfo *smbfile = file->private_data; | 2153 | struct cifsFileInfo *smbfile = file->private_data; |
2094 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 2154 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
2095 | struct inode *inode = file->f_mapping->host; | 2155 | struct inode *inode = file->f_mapping->host; |
@@ -2105,8 +2165,13 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync) | |||
2105 | file->f_path.dentry->d_name.name, datasync); | 2165 | file->f_path.dentry->d_name.name, datasync); |
2106 | 2166 | ||
2107 | tcon = tlink_tcon(smbfile->tlink); | 2167 | tcon = tlink_tcon(smbfile->tlink); |
2108 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) | 2168 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) { |
2109 | rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); | 2169 | server = tcon->ses->server; |
2170 | if (server->ops->flush) | ||
2171 | rc = server->ops->flush(xid, tcon, &smbfile->fid); | ||
2172 | else | ||
2173 | rc = -ENOSYS; | ||
2174 | } | ||
2110 | 2175 | ||
2111 | free_xid(xid); | 2176 | free_xid(xid); |
2112 | mutex_unlock(&inode->i_mutex); | 2177 | mutex_unlock(&inode->i_mutex); |
@@ -2172,20 +2237,6 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len) | |||
2172 | } | 2237 | } |
2173 | 2238 | ||
2174 | static void | 2239 | static void |
2175 | cifs_uncached_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata) | ||
2176 | { | ||
2177 | int i; | ||
2178 | size_t bytes = wdata->bytes; | ||
2179 | |||
2180 | /* marshal up the pages into iov array */ | ||
2181 | for (i = 0; i < wdata->nr_pages; i++) { | ||
2182 | iov[i + 1].iov_len = min_t(size_t, bytes, PAGE_SIZE); | ||
2183 | iov[i + 1].iov_base = kmap(wdata->pages[i]); | ||
2184 | bytes -= iov[i + 1].iov_len; | ||
2185 | } | ||
2186 | } | ||
2187 | |||
2188 | static void | ||
2189 | cifs_uncached_writev_complete(struct work_struct *work) | 2240 | cifs_uncached_writev_complete(struct work_struct *work) |
2190 | { | 2241 | { |
2191 | int i; | 2242 | int i; |
@@ -2215,6 +2266,9 @@ static int | |||
2215 | cifs_uncached_retry_writev(struct cifs_writedata *wdata) | 2266 | cifs_uncached_retry_writev(struct cifs_writedata *wdata) |
2216 | { | 2267 | { |
2217 | int rc; | 2268 | int rc; |
2269 | struct TCP_Server_Info *server; | ||
2270 | |||
2271 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; | ||
2218 | 2272 | ||
2219 | do { | 2273 | do { |
2220 | if (wdata->cfile->invalidHandle) { | 2274 | if (wdata->cfile->invalidHandle) { |
@@ -2222,7 +2276,7 @@ cifs_uncached_retry_writev(struct cifs_writedata *wdata) | |||
2222 | if (rc != 0) | 2276 | if (rc != 0) |
2223 | continue; | 2277 | continue; |
2224 | } | 2278 | } |
2225 | rc = cifs_async_writev(wdata); | 2279 | rc = server->ops->async_writev(wdata); |
2226 | } while (rc == -EAGAIN); | 2280 | } while (rc == -EAGAIN); |
2227 | 2281 | ||
2228 | return rc; | 2282 | return rc; |
@@ -2257,6 +2311,10 @@ cifs_iovec_write(struct file *file, const struct iovec *iov, | |||
2257 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 2311 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
2258 | open_file = file->private_data; | 2312 | open_file = file->private_data; |
2259 | tcon = tlink_tcon(open_file->tlink); | 2313 | tcon = tlink_tcon(open_file->tlink); |
2314 | |||
2315 | if (!tcon->ses->server->ops->async_writev) | ||
2316 | return -ENOSYS; | ||
2317 | |||
2260 | offset = *poffset; | 2318 | offset = *poffset; |
2261 | 2319 | ||
2262 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) | 2320 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
@@ -2298,7 +2356,8 @@ cifs_iovec_write(struct file *file, const struct iovec *iov, | |||
2298 | wdata->cfile = cifsFileInfo_get(open_file); | 2356 | wdata->cfile = cifsFileInfo_get(open_file); |
2299 | wdata->pid = pid; | 2357 | wdata->pid = pid; |
2300 | wdata->bytes = cur_len; | 2358 | wdata->bytes = cur_len; |
2301 | wdata->marshal_iov = cifs_uncached_marshal_iov; | 2359 | wdata->pagesz = PAGE_SIZE; |
2360 | wdata->tailsz = cur_len - ((nr_pages - 1) * PAGE_SIZE); | ||
2302 | rc = cifs_uncached_retry_writev(wdata); | 2361 | rc = cifs_uncached_retry_writev(wdata); |
2303 | if (rc) { | 2362 | if (rc) { |
2304 | kref_put(&wdata->refcount, cifs_writedata_release); | 2363 | kref_put(&wdata->refcount, cifs_writedata_release); |
@@ -2376,40 +2435,110 @@ ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, | |||
2376 | return written; | 2435 | return written; |
2377 | } | 2436 | } |
2378 | 2437 | ||
2379 | ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, | 2438 | static ssize_t |
2380 | unsigned long nr_segs, loff_t pos) | 2439 | cifs_writev(struct kiocb *iocb, const struct iovec *iov, |
2440 | unsigned long nr_segs, loff_t pos) | ||
2381 | { | 2441 | { |
2382 | struct inode *inode; | 2442 | struct file *file = iocb->ki_filp; |
2443 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; | ||
2444 | struct inode *inode = file->f_mapping->host; | ||
2445 | struct cifsInodeInfo *cinode = CIFS_I(inode); | ||
2446 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; | ||
2447 | ssize_t rc = -EACCES; | ||
2383 | 2448 | ||
2384 | inode = iocb->ki_filp->f_path.dentry->d_inode; | 2449 | BUG_ON(iocb->ki_pos != pos); |
2385 | 2450 | ||
2386 | if (CIFS_I(inode)->clientCanCacheAll) | 2451 | sb_start_write(inode->i_sb); |
2387 | return generic_file_aio_write(iocb, iov, nr_segs, pos); | 2452 | |
2453 | /* | ||
2454 | * We need to hold the sem to be sure nobody modifies lock list | ||
2455 | * with a brlock that prevents writing. | ||
2456 | */ | ||
2457 | down_read(&cinode->lock_sem); | ||
2458 | if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs), | ||
2459 | server->vals->exclusive_lock_type, NULL, | ||
2460 | true)) { | ||
2461 | mutex_lock(&inode->i_mutex); | ||
2462 | rc = __generic_file_aio_write(iocb, iov, nr_segs, | ||
2463 | &iocb->ki_pos); | ||
2464 | mutex_unlock(&inode->i_mutex); | ||
2465 | } | ||
2466 | |||
2467 | if (rc > 0 || rc == -EIOCBQUEUED) { | ||
2468 | ssize_t err; | ||
2469 | |||
2470 | err = generic_write_sync(file, pos, rc); | ||
2471 | if (err < 0 && rc > 0) | ||
2472 | rc = err; | ||
2473 | } | ||
2474 | |||
2475 | up_read(&cinode->lock_sem); | ||
2476 | sb_end_write(inode->i_sb); | ||
2477 | return rc; | ||
2478 | } | ||
2479 | |||
2480 | ssize_t | ||
2481 | cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, | ||
2482 | unsigned long nr_segs, loff_t pos) | ||
2483 | { | ||
2484 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; | ||
2485 | struct cifsInodeInfo *cinode = CIFS_I(inode); | ||
2486 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | ||
2487 | struct cifsFileInfo *cfile = (struct cifsFileInfo *) | ||
2488 | iocb->ki_filp->private_data; | ||
2489 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | ||
2388 | 2490 | ||
2491 | #ifdef CONFIG_CIFS_SMB2 | ||
2389 | /* | 2492 | /* |
2390 | * In strict cache mode we need to write the data to the server exactly | 2493 | * If we have an oplock for read and want to write a data to the file |
2391 | * from the pos to pos+len-1 rather than flush all affected pages | 2494 | * we need to store it in the page cache and then push it to the server |
2392 | * because it may cause a error with mandatory locks on these pages but | 2495 | * to be sure the next read will get a valid data. |
2393 | * not on the region from pos to ppos+len-1. | ||
2394 | */ | 2496 | */ |
2497 | if (!cinode->clientCanCacheAll && cinode->clientCanCacheRead) { | ||
2498 | ssize_t written; | ||
2499 | int rc; | ||
2395 | 2500 | ||
2396 | return cifs_user_writev(iocb, iov, nr_segs, pos); | 2501 | written = generic_file_aio_write(iocb, iov, nr_segs, pos); |
2502 | rc = filemap_fdatawrite(inode->i_mapping); | ||
2503 | if (rc) | ||
2504 | return (ssize_t)rc; | ||
2505 | |||
2506 | return written; | ||
2507 | } | ||
2508 | #endif | ||
2509 | |||
2510 | /* | ||
2511 | * For non-oplocked files in strict cache mode we need to write the data | ||
2512 | * to the server exactly from the pos to pos+len-1 rather than flush all | ||
2513 | * affected pages because it may cause a error with mandatory locks on | ||
2514 | * these pages but not on the region from pos to ppos+len-1. | ||
2515 | */ | ||
2516 | |||
2517 | if (!cinode->clientCanCacheAll) | ||
2518 | return cifs_user_writev(iocb, iov, nr_segs, pos); | ||
2519 | |||
2520 | if (cap_unix(tcon->ses) && | ||
2521 | (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && | ||
2522 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) | ||
2523 | return generic_file_aio_write(iocb, iov, nr_segs, pos); | ||
2524 | |||
2525 | return cifs_writev(iocb, iov, nr_segs, pos); | ||
2397 | } | 2526 | } |
2398 | 2527 | ||
2399 | static struct cifs_readdata * | 2528 | static struct cifs_readdata * |
2400 | cifs_readdata_alloc(unsigned int nr_vecs, work_func_t complete) | 2529 | cifs_readdata_alloc(unsigned int nr_pages, work_func_t complete) |
2401 | { | 2530 | { |
2402 | struct cifs_readdata *rdata; | 2531 | struct cifs_readdata *rdata; |
2403 | 2532 | ||
2404 | rdata = kzalloc(sizeof(*rdata) + | 2533 | rdata = kzalloc(sizeof(*rdata) + (sizeof(struct page *) * nr_pages), |
2405 | sizeof(struct kvec) * nr_vecs, GFP_KERNEL); | 2534 | GFP_KERNEL); |
2406 | if (rdata != NULL) { | 2535 | if (rdata != NULL) { |
2407 | kref_init(&rdata->refcount); | 2536 | kref_init(&rdata->refcount); |
2408 | INIT_LIST_HEAD(&rdata->list); | 2537 | INIT_LIST_HEAD(&rdata->list); |
2409 | init_completion(&rdata->done); | 2538 | init_completion(&rdata->done); |
2410 | INIT_WORK(&rdata->work, complete); | 2539 | INIT_WORK(&rdata->work, complete); |
2411 | INIT_LIST_HEAD(&rdata->pages); | ||
2412 | } | 2540 | } |
2541 | |||
2413 | return rdata; | 2542 | return rdata; |
2414 | } | 2543 | } |
2415 | 2544 | ||
@@ -2426,25 +2555,25 @@ cifs_readdata_release(struct kref *refcount) | |||
2426 | } | 2555 | } |
2427 | 2556 | ||
2428 | static int | 2557 | static int |
2429 | cifs_read_allocate_pages(struct list_head *list, unsigned int npages) | 2558 | cifs_read_allocate_pages(struct cifs_readdata *rdata, unsigned int nr_pages) |
2430 | { | 2559 | { |
2431 | int rc = 0; | 2560 | int rc = 0; |
2432 | struct page *page, *tpage; | 2561 | struct page *page; |
2433 | unsigned int i; | 2562 | unsigned int i; |
2434 | 2563 | ||
2435 | for (i = 0; i < npages; i++) { | 2564 | for (i = 0; i < nr_pages; i++) { |
2436 | page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); | 2565 | page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
2437 | if (!page) { | 2566 | if (!page) { |
2438 | rc = -ENOMEM; | 2567 | rc = -ENOMEM; |
2439 | break; | 2568 | break; |
2440 | } | 2569 | } |
2441 | list_add(&page->lru, list); | 2570 | rdata->pages[i] = page; |
2442 | } | 2571 | } |
2443 | 2572 | ||
2444 | if (rc) { | 2573 | if (rc) { |
2445 | list_for_each_entry_safe(page, tpage, list, lru) { | 2574 | for (i = 0; i < nr_pages; i++) { |
2446 | list_del(&page->lru); | 2575 | put_page(rdata->pages[i]); |
2447 | put_page(page); | 2576 | rdata->pages[i] = NULL; |
2448 | } | 2577 | } |
2449 | } | 2578 | } |
2450 | return rc; | 2579 | return rc; |
@@ -2453,13 +2582,13 @@ cifs_read_allocate_pages(struct list_head *list, unsigned int npages) | |||
2453 | static void | 2582 | static void |
2454 | cifs_uncached_readdata_release(struct kref *refcount) | 2583 | cifs_uncached_readdata_release(struct kref *refcount) |
2455 | { | 2584 | { |
2456 | struct page *page, *tpage; | ||
2457 | struct cifs_readdata *rdata = container_of(refcount, | 2585 | struct cifs_readdata *rdata = container_of(refcount, |
2458 | struct cifs_readdata, refcount); | 2586 | struct cifs_readdata, refcount); |
2587 | unsigned int i; | ||
2459 | 2588 | ||
2460 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { | 2589 | for (i = 0; i < rdata->nr_pages; i++) { |
2461 | list_del(&page->lru); | 2590 | put_page(rdata->pages[i]); |
2462 | put_page(page); | 2591 | rdata->pages[i] = NULL; |
2463 | } | 2592 | } |
2464 | cifs_readdata_release(refcount); | 2593 | cifs_readdata_release(refcount); |
2465 | } | 2594 | } |
@@ -2468,6 +2597,9 @@ static int | |||
2468 | cifs_retry_async_readv(struct cifs_readdata *rdata) | 2597 | cifs_retry_async_readv(struct cifs_readdata *rdata) |
2469 | { | 2598 | { |
2470 | int rc; | 2599 | int rc; |
2600 | struct TCP_Server_Info *server; | ||
2601 | |||
2602 | server = tlink_tcon(rdata->cfile->tlink)->ses->server; | ||
2471 | 2603 | ||
2472 | do { | 2604 | do { |
2473 | if (rdata->cfile->invalidHandle) { | 2605 | if (rdata->cfile->invalidHandle) { |
@@ -2475,7 +2607,7 @@ cifs_retry_async_readv(struct cifs_readdata *rdata) | |||
2475 | if (rc != 0) | 2607 | if (rc != 0) |
2476 | continue; | 2608 | continue; |
2477 | } | 2609 | } |
2478 | rc = cifs_async_readv(rdata); | 2610 | rc = server->ops->async_readv(rdata); |
2479 | } while (rc == -EAGAIN); | 2611 | } while (rc == -EAGAIN); |
2480 | 2612 | ||
2481 | return rc; | 2613 | return rc; |
@@ -2500,17 +2632,18 @@ cifs_readdata_to_iov(struct cifs_readdata *rdata, const struct iovec *iov, | |||
2500 | int rc = 0; | 2632 | int rc = 0; |
2501 | struct iov_iter ii; | 2633 | struct iov_iter ii; |
2502 | size_t pos = rdata->offset - offset; | 2634 | size_t pos = rdata->offset - offset; |
2503 | struct page *page, *tpage; | ||
2504 | ssize_t remaining = rdata->bytes; | 2635 | ssize_t remaining = rdata->bytes; |
2505 | unsigned char *pdata; | 2636 | unsigned char *pdata; |
2637 | unsigned int i; | ||
2506 | 2638 | ||
2507 | /* set up iov_iter and advance to the correct offset */ | 2639 | /* set up iov_iter and advance to the correct offset */ |
2508 | iov_iter_init(&ii, iov, nr_segs, iov_length(iov, nr_segs), 0); | 2640 | iov_iter_init(&ii, iov, nr_segs, iov_length(iov, nr_segs), 0); |
2509 | iov_iter_advance(&ii, pos); | 2641 | iov_iter_advance(&ii, pos); |
2510 | 2642 | ||
2511 | *copied = 0; | 2643 | *copied = 0; |
2512 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { | 2644 | for (i = 0; i < rdata->nr_pages; i++) { |
2513 | ssize_t copy; | 2645 | ssize_t copy; |
2646 | struct page *page = rdata->pages[i]; | ||
2514 | 2647 | ||
2515 | /* copy a whole page or whatever's left */ | 2648 | /* copy a whole page or whatever's left */ |
2516 | copy = min_t(ssize_t, remaining, PAGE_SIZE); | 2649 | copy = min_t(ssize_t, remaining, PAGE_SIZE); |
@@ -2530,9 +2663,6 @@ cifs_readdata_to_iov(struct cifs_readdata *rdata, const struct iovec *iov, | |||
2530 | iov_iter_advance(&ii, copy); | 2663 | iov_iter_advance(&ii, copy); |
2531 | } | 2664 | } |
2532 | } | 2665 | } |
2533 | |||
2534 | list_del(&page->lru); | ||
2535 | put_page(page); | ||
2536 | } | 2666 | } |
2537 | 2667 | ||
2538 | return rc; | 2668 | return rc; |
@@ -2544,59 +2674,56 @@ cifs_uncached_readv_complete(struct work_struct *work) | |||
2544 | struct cifs_readdata *rdata = container_of(work, | 2674 | struct cifs_readdata *rdata = container_of(work, |
2545 | struct cifs_readdata, work); | 2675 | struct cifs_readdata, work); |
2546 | 2676 | ||
2547 | /* if the result is non-zero then the pages weren't kmapped */ | ||
2548 | if (rdata->result == 0) { | ||
2549 | struct page *page; | ||
2550 | |||
2551 | list_for_each_entry(page, &rdata->pages, lru) | ||
2552 | kunmap(page); | ||
2553 | } | ||
2554 | |||
2555 | complete(&rdata->done); | 2677 | complete(&rdata->done); |
2556 | kref_put(&rdata->refcount, cifs_uncached_readdata_release); | 2678 | kref_put(&rdata->refcount, cifs_uncached_readdata_release); |
2557 | } | 2679 | } |
2558 | 2680 | ||
2559 | static int | 2681 | static int |
2560 | cifs_uncached_read_marshal_iov(struct cifs_readdata *rdata, | 2682 | cifs_uncached_read_into_pages(struct TCP_Server_Info *server, |
2561 | unsigned int remaining) | 2683 | struct cifs_readdata *rdata, unsigned int len) |
2562 | { | 2684 | { |
2563 | int len = 0; | 2685 | int total_read = 0, result = 0; |
2564 | struct page *page, *tpage; | 2686 | unsigned int i; |
2687 | unsigned int nr_pages = rdata->nr_pages; | ||
2688 | struct kvec iov; | ||
2689 | |||
2690 | rdata->tailsz = PAGE_SIZE; | ||
2691 | for (i = 0; i < nr_pages; i++) { | ||
2692 | struct page *page = rdata->pages[i]; | ||
2565 | 2693 | ||
2566 | rdata->nr_iov = 1; | 2694 | if (len >= PAGE_SIZE) { |
2567 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { | ||
2568 | if (remaining >= PAGE_SIZE) { | ||
2569 | /* enough data to fill the page */ | 2695 | /* enough data to fill the page */ |
2570 | rdata->iov[rdata->nr_iov].iov_base = kmap(page); | 2696 | iov.iov_base = kmap(page); |
2571 | rdata->iov[rdata->nr_iov].iov_len = PAGE_SIZE; | 2697 | iov.iov_len = PAGE_SIZE; |
2572 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", | 2698 | cFYI(1, "%u: iov_base=%p iov_len=%zu", |
2573 | rdata->nr_iov, page->index, | 2699 | i, iov.iov_base, iov.iov_len); |
2574 | rdata->iov[rdata->nr_iov].iov_base, | 2700 | len -= PAGE_SIZE; |
2575 | rdata->iov[rdata->nr_iov].iov_len); | 2701 | } else if (len > 0) { |
2576 | ++rdata->nr_iov; | ||
2577 | len += PAGE_SIZE; | ||
2578 | remaining -= PAGE_SIZE; | ||
2579 | } else if (remaining > 0) { | ||
2580 | /* enough for partial page, fill and zero the rest */ | 2702 | /* enough for partial page, fill and zero the rest */ |
2581 | rdata->iov[rdata->nr_iov].iov_base = kmap(page); | 2703 | iov.iov_base = kmap(page); |
2582 | rdata->iov[rdata->nr_iov].iov_len = remaining; | 2704 | iov.iov_len = len; |
2583 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", | 2705 | cFYI(1, "%u: iov_base=%p iov_len=%zu", |
2584 | rdata->nr_iov, page->index, | 2706 | i, iov.iov_base, iov.iov_len); |
2585 | rdata->iov[rdata->nr_iov].iov_base, | 2707 | memset(iov.iov_base + len, '\0', PAGE_SIZE - len); |
2586 | rdata->iov[rdata->nr_iov].iov_len); | 2708 | rdata->tailsz = len; |
2587 | memset(rdata->iov[rdata->nr_iov].iov_base + remaining, | 2709 | len = 0; |
2588 | '\0', PAGE_SIZE - remaining); | ||
2589 | ++rdata->nr_iov; | ||
2590 | len += remaining; | ||
2591 | remaining = 0; | ||
2592 | } else { | 2710 | } else { |
2593 | /* no need to hold page hostage */ | 2711 | /* no need to hold page hostage */ |
2594 | list_del(&page->lru); | 2712 | rdata->pages[i] = NULL; |
2713 | rdata->nr_pages--; | ||
2595 | put_page(page); | 2714 | put_page(page); |
2715 | continue; | ||
2596 | } | 2716 | } |
2717 | |||
2718 | result = cifs_readv_from_socket(server, &iov, 1, iov.iov_len); | ||
2719 | kunmap(page); | ||
2720 | if (result < 0) | ||
2721 | break; | ||
2722 | |||
2723 | total_read += result; | ||
2597 | } | 2724 | } |
2598 | 2725 | ||
2599 | return len; | 2726 | return total_read > 0 ? total_read : result; |
2600 | } | 2727 | } |
2601 | 2728 | ||
2602 | static ssize_t | 2729 | static ssize_t |
@@ -2627,6 +2754,9 @@ cifs_iovec_read(struct file *file, const struct iovec *iov, | |||
2627 | open_file = file->private_data; | 2754 | open_file = file->private_data; |
2628 | tcon = tlink_tcon(open_file->tlink); | 2755 | tcon = tlink_tcon(open_file->tlink); |
2629 | 2756 | ||
2757 | if (!tcon->ses->server->ops->async_readv) | ||
2758 | return -ENOSYS; | ||
2759 | |||
2630 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) | 2760 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
2631 | pid = open_file->pid; | 2761 | pid = open_file->pid; |
2632 | else | 2762 | else |
@@ -2647,15 +2777,17 @@ cifs_iovec_read(struct file *file, const struct iovec *iov, | |||
2647 | goto error; | 2777 | goto error; |
2648 | } | 2778 | } |
2649 | 2779 | ||
2650 | rc = cifs_read_allocate_pages(&rdata->pages, npages); | 2780 | rc = cifs_read_allocate_pages(rdata, npages); |
2651 | if (rc) | 2781 | if (rc) |
2652 | goto error; | 2782 | goto error; |
2653 | 2783 | ||
2654 | rdata->cfile = cifsFileInfo_get(open_file); | 2784 | rdata->cfile = cifsFileInfo_get(open_file); |
2785 | rdata->nr_pages = npages; | ||
2655 | rdata->offset = offset; | 2786 | rdata->offset = offset; |
2656 | rdata->bytes = cur_len; | 2787 | rdata->bytes = cur_len; |
2657 | rdata->pid = pid; | 2788 | rdata->pid = pid; |
2658 | rdata->marshal_iov = cifs_uncached_read_marshal_iov; | 2789 | rdata->pagesz = PAGE_SIZE; |
2790 | rdata->read_into_pages = cifs_uncached_read_into_pages; | ||
2659 | 2791 | ||
2660 | rc = cifs_retry_async_readv(rdata); | 2792 | rc = cifs_retry_async_readv(rdata); |
2661 | error: | 2793 | error: |
@@ -2706,6 +2838,10 @@ restart_loop: | |||
2706 | cifs_stats_bytes_read(tcon, total_read); | 2838 | cifs_stats_bytes_read(tcon, total_read); |
2707 | *poffset += total_read; | 2839 | *poffset += total_read; |
2708 | 2840 | ||
2841 | /* mask nodata case */ | ||
2842 | if (rc == -ENODATA) | ||
2843 | rc = 0; | ||
2844 | |||
2709 | return total_read ? total_read : rc; | 2845 | return total_read ? total_read : rc; |
2710 | } | 2846 | } |
2711 | 2847 | ||
@@ -2721,15 +2857,17 @@ ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov, | |||
2721 | return read; | 2857 | return read; |
2722 | } | 2858 | } |
2723 | 2859 | ||
2724 | ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, | 2860 | ssize_t |
2725 | unsigned long nr_segs, loff_t pos) | 2861 | cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, |
2862 | unsigned long nr_segs, loff_t pos) | ||
2726 | { | 2863 | { |
2727 | struct inode *inode; | 2864 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; |
2728 | 2865 | struct cifsInodeInfo *cinode = CIFS_I(inode); | |
2729 | inode = iocb->ki_filp->f_path.dentry->d_inode; | 2866 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
2730 | 2867 | struct cifsFileInfo *cfile = (struct cifsFileInfo *) | |
2731 | if (CIFS_I(inode)->clientCanCacheRead) | 2868 | iocb->ki_filp->private_data; |
2732 | return generic_file_aio_read(iocb, iov, nr_segs, pos); | 2869 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
2870 | int rc = -EACCES; | ||
2733 | 2871 | ||
2734 | /* | 2872 | /* |
2735 | * In strict cache mode we need to read from the server all the time | 2873 | * In strict cache mode we need to read from the server all the time |
@@ -2739,12 +2877,29 @@ ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, | |||
2739 | * on pages affected by this read but not on the region from pos to | 2877 | * on pages affected by this read but not on the region from pos to |
2740 | * pos+len-1. | 2878 | * pos+len-1. |
2741 | */ | 2879 | */ |
2880 | if (!cinode->clientCanCacheRead) | ||
2881 | return cifs_user_readv(iocb, iov, nr_segs, pos); | ||
2882 | |||
2883 | if (cap_unix(tcon->ses) && | ||
2884 | (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && | ||
2885 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) | ||
2886 | return generic_file_aio_read(iocb, iov, nr_segs, pos); | ||
2742 | 2887 | ||
2743 | return cifs_user_readv(iocb, iov, nr_segs, pos); | 2888 | /* |
2889 | * We need to hold the sem to be sure nobody modifies lock list | ||
2890 | * with a brlock that prevents reading. | ||
2891 | */ | ||
2892 | down_read(&cinode->lock_sem); | ||
2893 | if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs), | ||
2894 | tcon->ses->server->vals->shared_lock_type, | ||
2895 | NULL, true)) | ||
2896 | rc = generic_file_aio_read(iocb, iov, nr_segs, pos); | ||
2897 | up_read(&cinode->lock_sem); | ||
2898 | return rc; | ||
2744 | } | 2899 | } |
2745 | 2900 | ||
2746 | static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | 2901 | static ssize_t |
2747 | loff_t *poffset) | 2902 | cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset) |
2748 | { | 2903 | { |
2749 | int rc = -EACCES; | 2904 | int rc = -EACCES; |
2750 | unsigned int bytes_read = 0; | 2905 | unsigned int bytes_read = 0; |
@@ -2753,8 +2908,9 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
2753 | unsigned int rsize; | 2908 | unsigned int rsize; |
2754 | struct cifs_sb_info *cifs_sb; | 2909 | struct cifs_sb_info *cifs_sb; |
2755 | struct cifs_tcon *tcon; | 2910 | struct cifs_tcon *tcon; |
2911 | struct TCP_Server_Info *server; | ||
2756 | unsigned int xid; | 2912 | unsigned int xid; |
2757 | char *current_offset; | 2913 | char *cur_offset; |
2758 | struct cifsFileInfo *open_file; | 2914 | struct cifsFileInfo *open_file; |
2759 | struct cifs_io_parms io_parms; | 2915 | struct cifs_io_parms io_parms; |
2760 | int buf_type = CIFS_NO_BUFFER; | 2916 | int buf_type = CIFS_NO_BUFFER; |
@@ -2773,6 +2929,12 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
2773 | } | 2929 | } |
2774 | open_file = file->private_data; | 2930 | open_file = file->private_data; |
2775 | tcon = tlink_tcon(open_file->tlink); | 2931 | tcon = tlink_tcon(open_file->tlink); |
2932 | server = tcon->ses->server; | ||
2933 | |||
2934 | if (!server->ops->sync_read) { | ||
2935 | free_xid(xid); | ||
2936 | return -ENOSYS; | ||
2937 | } | ||
2776 | 2938 | ||
2777 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) | 2939 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
2778 | pid = open_file->pid; | 2940 | pid = open_file->pid; |
@@ -2782,9 +2944,8 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
2782 | if ((file->f_flags & O_ACCMODE) == O_WRONLY) | 2944 | if ((file->f_flags & O_ACCMODE) == O_WRONLY) |
2783 | cFYI(1, "attempting read on write only file instance"); | 2945 | cFYI(1, "attempting read on write only file instance"); |
2784 | 2946 | ||
2785 | for (total_read = 0, current_offset = read_data; | 2947 | for (total_read = 0, cur_offset = read_data; read_size > total_read; |
2786 | read_size > total_read; | 2948 | total_read += bytes_read, cur_offset += bytes_read) { |
2787 | total_read += bytes_read, current_offset += bytes_read) { | ||
2788 | current_read_size = min_t(uint, read_size - total_read, rsize); | 2949 | current_read_size = min_t(uint, read_size - total_read, rsize); |
2789 | /* | 2950 | /* |
2790 | * For windows me and 9x we do not want to request more than it | 2951 | * For windows me and 9x we do not want to request more than it |
@@ -2802,13 +2963,13 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
2802 | if (rc != 0) | 2963 | if (rc != 0) |
2803 | break; | 2964 | break; |
2804 | } | 2965 | } |
2805 | io_parms.netfid = open_file->netfid; | ||
2806 | io_parms.pid = pid; | 2966 | io_parms.pid = pid; |
2807 | io_parms.tcon = tcon; | 2967 | io_parms.tcon = tcon; |
2808 | io_parms.offset = *poffset; | 2968 | io_parms.offset = *offset; |
2809 | io_parms.length = current_read_size; | 2969 | io_parms.length = current_read_size; |
2810 | rc = CIFSSMBRead(xid, &io_parms, &bytes_read, | 2970 | rc = server->ops->sync_read(xid, open_file, &io_parms, |
2811 | ¤t_offset, &buf_type); | 2971 | &bytes_read, &cur_offset, |
2972 | &buf_type); | ||
2812 | } | 2973 | } |
2813 | if (rc || (bytes_read == 0)) { | 2974 | if (rc || (bytes_read == 0)) { |
2814 | if (total_read) { | 2975 | if (total_read) { |
@@ -2819,7 +2980,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
2819 | } | 2980 | } |
2820 | } else { | 2981 | } else { |
2821 | cifs_stats_bytes_read(tcon, total_read); | 2982 | cifs_stats_bytes_read(tcon, total_read); |
2822 | *poffset += bytes_read; | 2983 | *offset += bytes_read; |
2823 | } | 2984 | } |
2824 | } | 2985 | } |
2825 | free_xid(xid); | 2986 | free_xid(xid); |
@@ -2885,16 +3046,16 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
2885 | static void | 3046 | static void |
2886 | cifs_readv_complete(struct work_struct *work) | 3047 | cifs_readv_complete(struct work_struct *work) |
2887 | { | 3048 | { |
3049 | unsigned int i; | ||
2888 | struct cifs_readdata *rdata = container_of(work, | 3050 | struct cifs_readdata *rdata = container_of(work, |
2889 | struct cifs_readdata, work); | 3051 | struct cifs_readdata, work); |
2890 | struct page *page, *tpage; | ||
2891 | 3052 | ||
2892 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { | 3053 | for (i = 0; i < rdata->nr_pages; i++) { |
2893 | list_del(&page->lru); | 3054 | struct page *page = rdata->pages[i]; |
3055 | |||
2894 | lru_cache_add_file(page); | 3056 | lru_cache_add_file(page); |
2895 | 3057 | ||
2896 | if (rdata->result == 0) { | 3058 | if (rdata->result == 0) { |
2897 | kunmap(page); | ||
2898 | flush_dcache_page(page); | 3059 | flush_dcache_page(page); |
2899 | SetPageUptodate(page); | 3060 | SetPageUptodate(page); |
2900 | } | 3061 | } |
@@ -2905,49 +3066,48 @@ cifs_readv_complete(struct work_struct *work) | |||
2905 | cifs_readpage_to_fscache(rdata->mapping->host, page); | 3066 | cifs_readpage_to_fscache(rdata->mapping->host, page); |
2906 | 3067 | ||
2907 | page_cache_release(page); | 3068 | page_cache_release(page); |
3069 | rdata->pages[i] = NULL; | ||
2908 | } | 3070 | } |
2909 | kref_put(&rdata->refcount, cifs_readdata_release); | 3071 | kref_put(&rdata->refcount, cifs_readdata_release); |
2910 | } | 3072 | } |
2911 | 3073 | ||
2912 | static int | 3074 | static int |
2913 | cifs_readpages_marshal_iov(struct cifs_readdata *rdata, unsigned int remaining) | 3075 | cifs_readpages_read_into_pages(struct TCP_Server_Info *server, |
3076 | struct cifs_readdata *rdata, unsigned int len) | ||
2914 | { | 3077 | { |
2915 | int len = 0; | 3078 | int total_read = 0, result = 0; |
2916 | struct page *page, *tpage; | 3079 | unsigned int i; |
2917 | u64 eof; | 3080 | u64 eof; |
2918 | pgoff_t eof_index; | 3081 | pgoff_t eof_index; |
3082 | unsigned int nr_pages = rdata->nr_pages; | ||
3083 | struct kvec iov; | ||
2919 | 3084 | ||
2920 | /* determine the eof that the server (probably) has */ | 3085 | /* determine the eof that the server (probably) has */ |
2921 | eof = CIFS_I(rdata->mapping->host)->server_eof; | 3086 | eof = CIFS_I(rdata->mapping->host)->server_eof; |
2922 | eof_index = eof ? (eof - 1) >> PAGE_CACHE_SHIFT : 0; | 3087 | eof_index = eof ? (eof - 1) >> PAGE_CACHE_SHIFT : 0; |
2923 | cFYI(1, "eof=%llu eof_index=%lu", eof, eof_index); | 3088 | cFYI(1, "eof=%llu eof_index=%lu", eof, eof_index); |
2924 | 3089 | ||
2925 | rdata->nr_iov = 1; | 3090 | rdata->tailsz = PAGE_CACHE_SIZE; |
2926 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { | 3091 | for (i = 0; i < nr_pages; i++) { |
2927 | if (remaining >= PAGE_CACHE_SIZE) { | 3092 | struct page *page = rdata->pages[i]; |
3093 | |||
3094 | if (len >= PAGE_CACHE_SIZE) { | ||
2928 | /* enough data to fill the page */ | 3095 | /* enough data to fill the page */ |
2929 | rdata->iov[rdata->nr_iov].iov_base = kmap(page); | 3096 | iov.iov_base = kmap(page); |
2930 | rdata->iov[rdata->nr_iov].iov_len = PAGE_CACHE_SIZE; | 3097 | iov.iov_len = PAGE_CACHE_SIZE; |
2931 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", | 3098 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", |
2932 | rdata->nr_iov, page->index, | 3099 | i, page->index, iov.iov_base, iov.iov_len); |
2933 | rdata->iov[rdata->nr_iov].iov_base, | 3100 | len -= PAGE_CACHE_SIZE; |
2934 | rdata->iov[rdata->nr_iov].iov_len); | 3101 | } else if (len > 0) { |
2935 | ++rdata->nr_iov; | ||
2936 | len += PAGE_CACHE_SIZE; | ||
2937 | remaining -= PAGE_CACHE_SIZE; | ||
2938 | } else if (remaining > 0) { | ||
2939 | /* enough for partial page, fill and zero the rest */ | 3102 | /* enough for partial page, fill and zero the rest */ |
2940 | rdata->iov[rdata->nr_iov].iov_base = kmap(page); | 3103 | iov.iov_base = kmap(page); |
2941 | rdata->iov[rdata->nr_iov].iov_len = remaining; | 3104 | iov.iov_len = len; |
2942 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", | 3105 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", |
2943 | rdata->nr_iov, page->index, | 3106 | i, page->index, iov.iov_base, iov.iov_len); |
2944 | rdata->iov[rdata->nr_iov].iov_base, | 3107 | memset(iov.iov_base + len, |
2945 | rdata->iov[rdata->nr_iov].iov_len); | 3108 | '\0', PAGE_CACHE_SIZE - len); |
2946 | memset(rdata->iov[rdata->nr_iov].iov_base + remaining, | 3109 | rdata->tailsz = len; |
2947 | '\0', PAGE_CACHE_SIZE - remaining); | 3110 | len = 0; |
2948 | ++rdata->nr_iov; | ||
2949 | len += remaining; | ||
2950 | remaining = 0; | ||
2951 | } else if (page->index > eof_index) { | 3111 | } else if (page->index > eof_index) { |
2952 | /* | 3112 | /* |
2953 | * The VFS will not try to do readahead past the | 3113 | * The VFS will not try to do readahead past the |
@@ -2958,22 +3118,33 @@ cifs_readpages_marshal_iov(struct cifs_readdata *rdata, unsigned int remaining) | |||
2958 | * fill them until the writes are flushed. | 3118 | * fill them until the writes are flushed. |
2959 | */ | 3119 | */ |
2960 | zero_user(page, 0, PAGE_CACHE_SIZE); | 3120 | zero_user(page, 0, PAGE_CACHE_SIZE); |
2961 | list_del(&page->lru); | ||
2962 | lru_cache_add_file(page); | 3121 | lru_cache_add_file(page); |
2963 | flush_dcache_page(page); | 3122 | flush_dcache_page(page); |
2964 | SetPageUptodate(page); | 3123 | SetPageUptodate(page); |
2965 | unlock_page(page); | 3124 | unlock_page(page); |
2966 | page_cache_release(page); | 3125 | page_cache_release(page); |
3126 | rdata->pages[i] = NULL; | ||
3127 | rdata->nr_pages--; | ||
3128 | continue; | ||
2967 | } else { | 3129 | } else { |
2968 | /* no need to hold page hostage */ | 3130 | /* no need to hold page hostage */ |
2969 | list_del(&page->lru); | ||
2970 | lru_cache_add_file(page); | 3131 | lru_cache_add_file(page); |
2971 | unlock_page(page); | 3132 | unlock_page(page); |
2972 | page_cache_release(page); | 3133 | page_cache_release(page); |
3134 | rdata->pages[i] = NULL; | ||
3135 | rdata->nr_pages--; | ||
3136 | continue; | ||
2973 | } | 3137 | } |
3138 | |||
3139 | result = cifs_readv_from_socket(server, &iov, 1, iov.iov_len); | ||
3140 | kunmap(page); | ||
3141 | if (result < 0) | ||
3142 | break; | ||
3143 | |||
3144 | total_read += result; | ||
2974 | } | 3145 | } |
2975 | 3146 | ||
2976 | return len; | 3147 | return total_read > 0 ? total_read : result; |
2977 | } | 3148 | } |
2978 | 3149 | ||
2979 | static int cifs_readpages(struct file *file, struct address_space *mapping, | 3150 | static int cifs_readpages(struct file *file, struct address_space *mapping, |
@@ -3027,6 +3198,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
3027 | * the rdata->pages, then we want them in increasing order. | 3198 | * the rdata->pages, then we want them in increasing order. |
3028 | */ | 3199 | */ |
3029 | while (!list_empty(page_list)) { | 3200 | while (!list_empty(page_list)) { |
3201 | unsigned int i; | ||
3030 | unsigned int bytes = PAGE_CACHE_SIZE; | 3202 | unsigned int bytes = PAGE_CACHE_SIZE; |
3031 | unsigned int expected_index; | 3203 | unsigned int expected_index; |
3032 | unsigned int nr_pages = 1; | 3204 | unsigned int nr_pages = 1; |
@@ -3096,14 +3268,18 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
3096 | rdata->offset = offset; | 3268 | rdata->offset = offset; |
3097 | rdata->bytes = bytes; | 3269 | rdata->bytes = bytes; |
3098 | rdata->pid = pid; | 3270 | rdata->pid = pid; |
3099 | rdata->marshal_iov = cifs_readpages_marshal_iov; | 3271 | rdata->pagesz = PAGE_CACHE_SIZE; |
3100 | list_splice_init(&tmplist, &rdata->pages); | 3272 | rdata->read_into_pages = cifs_readpages_read_into_pages; |
3273 | |||
3274 | list_for_each_entry_safe(page, tpage, &tmplist, lru) { | ||
3275 | list_del(&page->lru); | ||
3276 | rdata->pages[rdata->nr_pages++] = page; | ||
3277 | } | ||
3101 | 3278 | ||
3102 | rc = cifs_retry_async_readv(rdata); | 3279 | rc = cifs_retry_async_readv(rdata); |
3103 | if (rc != 0) { | 3280 | if (rc != 0) { |
3104 | list_for_each_entry_safe(page, tpage, &rdata->pages, | 3281 | for (i = 0; i < rdata->nr_pages; i++) { |
3105 | lru) { | 3282 | page = rdata->pages[i]; |
3106 | list_del(&page->lru); | ||
3107 | lru_cache_add_file(page); | 3283 | lru_cache_add_file(page); |
3108 | unlock_page(page); | 3284 | unlock_page(page); |
3109 | page_cache_release(page); | 3285 | page_cache_release(page); |
@@ -3347,6 +3523,7 @@ void cifs_oplock_break(struct work_struct *work) | |||
3347 | oplock_break); | 3523 | oplock_break); |
3348 | struct inode *inode = cfile->dentry->d_inode; | 3524 | struct inode *inode = cfile->dentry->d_inode; |
3349 | struct cifsInodeInfo *cinode = CIFS_I(inode); | 3525 | struct cifsInodeInfo *cinode = CIFS_I(inode); |
3526 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | ||
3350 | int rc = 0; | 3527 | int rc = 0; |
3351 | 3528 | ||
3352 | if (inode && S_ISREG(inode->i_mode)) { | 3529 | if (inode && S_ISREG(inode->i_mode)) { |
@@ -3374,10 +3551,8 @@ void cifs_oplock_break(struct work_struct *work) | |||
3374 | * disconnected since oplock already released by the server | 3551 | * disconnected since oplock already released by the server |
3375 | */ | 3552 | */ |
3376 | if (!cfile->oplock_break_cancelled) { | 3553 | if (!cfile->oplock_break_cancelled) { |
3377 | rc = CIFSSMBLock(0, tlink_tcon(cfile->tlink), cfile->netfid, | 3554 | rc = tcon->ses->server->ops->oplock_response(tcon, &cfile->fid, |
3378 | current->tgid, 0, 0, 0, 0, | 3555 | cinode); |
3379 | LOCKING_ANDX_OPLOCK_RELEASE, false, | ||
3380 | cinode->clientCanCacheRead ? 1 : 0); | ||
3381 | cFYI(1, "Oplock release rc = %d", rc); | 3556 | cFYI(1, "Oplock release rc = %d", rc); |
3382 | } | 3557 | } |
3383 | } | 3558 | } |
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index cb79c7edecb0..afdff79651f1 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c | |||
@@ -282,7 +282,8 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb) | |||
282 | fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL; | 282 | fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL; |
283 | } | 283 | } |
284 | 284 | ||
285 | int cifs_get_file_info_unix(struct file *filp) | 285 | static int |
286 | cifs_get_file_info_unix(struct file *filp) | ||
286 | { | 287 | { |
287 | int rc; | 288 | int rc; |
288 | unsigned int xid; | 289 | unsigned int xid; |
@@ -294,7 +295,7 @@ int cifs_get_file_info_unix(struct file *filp) | |||
294 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | 295 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
295 | 296 | ||
296 | xid = get_xid(); | 297 | xid = get_xid(); |
297 | rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->netfid, &find_data); | 298 | rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->fid.netfid, &find_data); |
298 | if (!rc) { | 299 | if (!rc) { |
299 | cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb); | 300 | cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb); |
300 | } else if (rc == -EREMOTE) { | 301 | } else if (rc == -EREMOTE) { |
@@ -550,7 +551,8 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info, | |||
550 | fattr->cf_gid = cifs_sb->mnt_gid; | 551 | fattr->cf_gid = cifs_sb->mnt_gid; |
551 | } | 552 | } |
552 | 553 | ||
553 | int cifs_get_file_info(struct file *filp) | 554 | static int |
555 | cifs_get_file_info(struct file *filp) | ||
554 | { | 556 | { |
555 | int rc; | 557 | int rc; |
556 | unsigned int xid; | 558 | unsigned int xid; |
@@ -560,9 +562,13 @@ int cifs_get_file_info(struct file *filp) | |||
560 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 562 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
561 | struct cifsFileInfo *cfile = filp->private_data; | 563 | struct cifsFileInfo *cfile = filp->private_data; |
562 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | 564 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
565 | struct TCP_Server_Info *server = tcon->ses->server; | ||
566 | |||
567 | if (!server->ops->query_file_info) | ||
568 | return -ENOSYS; | ||
563 | 569 | ||
564 | xid = get_xid(); | 570 | xid = get_xid(); |
565 | rc = CIFSSMBQFileInfo(xid, tcon, cfile->netfid, &find_data); | 571 | rc = server->ops->query_file_info(xid, tcon, &cfile->fid, &find_data); |
566 | switch (rc) { | 572 | switch (rc) { |
567 | case 0: | 573 | case 0: |
568 | cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb, false); | 574 | cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb, false); |
@@ -601,7 +607,9 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, | |||
601 | FILE_ALL_INFO *data, struct super_block *sb, int xid, | 607 | FILE_ALL_INFO *data, struct super_block *sb, int xid, |
602 | const __u16 *fid) | 608 | const __u16 *fid) |
603 | { | 609 | { |
604 | int rc = 0, tmprc; | 610 | bool validinum = false; |
611 | __u16 srchflgs; | ||
612 | int rc = 0, tmprc = ENOSYS; | ||
605 | struct cifs_tcon *tcon; | 613 | struct cifs_tcon *tcon; |
606 | struct TCP_Server_Info *server; | 614 | struct TCP_Server_Info *server; |
607 | struct tcon_link *tlink; | 615 | struct tcon_link *tlink; |
@@ -609,6 +617,7 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, | |||
609 | char *buf = NULL; | 617 | char *buf = NULL; |
610 | bool adjust_tz = false; | 618 | bool adjust_tz = false; |
611 | struct cifs_fattr fattr; | 619 | struct cifs_fattr fattr; |
620 | struct cifs_search_info *srchinf = NULL; | ||
612 | 621 | ||
613 | tlink = cifs_sb_tlink(cifs_sb); | 622 | tlink = cifs_sb_tlink(cifs_sb); |
614 | if (IS_ERR(tlink)) | 623 | if (IS_ERR(tlink)) |
@@ -647,9 +656,38 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, | |||
647 | } else if (rc == -EREMOTE) { | 656 | } else if (rc == -EREMOTE) { |
648 | cifs_create_dfs_fattr(&fattr, sb); | 657 | cifs_create_dfs_fattr(&fattr, sb); |
649 | rc = 0; | 658 | rc = 0; |
650 | } else { | 659 | } else if (rc == -EACCES && backup_cred(cifs_sb)) { |
660 | srchinf = kzalloc(sizeof(struct cifs_search_info), | ||
661 | GFP_KERNEL); | ||
662 | if (srchinf == NULL) { | ||
663 | rc = -ENOMEM; | ||
664 | goto cgii_exit; | ||
665 | } | ||
666 | |||
667 | srchinf->endOfSearch = false; | ||
668 | srchinf->info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO; | ||
669 | |||
670 | srchflgs = CIFS_SEARCH_CLOSE_ALWAYS | | ||
671 | CIFS_SEARCH_CLOSE_AT_END | | ||
672 | CIFS_SEARCH_BACKUP_SEARCH; | ||
673 | |||
674 | rc = CIFSFindFirst(xid, tcon, full_path, | ||
675 | cifs_sb, NULL, srchflgs, srchinf, false); | ||
676 | if (!rc) { | ||
677 | data = | ||
678 | (FILE_ALL_INFO *)srchinf->srch_entries_start; | ||
679 | |||
680 | cifs_dir_info_to_fattr(&fattr, | ||
681 | (FILE_DIRECTORY_INFO *)data, cifs_sb); | ||
682 | fattr.cf_uniqueid = le64_to_cpu( | ||
683 | ((SEARCH_ID_FULL_DIR_INFO *)data)->UniqueId); | ||
684 | validinum = true; | ||
685 | |||
686 | cifs_buf_release(srchinf->ntwrk_buf_start); | ||
687 | } | ||
688 | kfree(srchinf); | ||
689 | } else | ||
651 | goto cgii_exit; | 690 | goto cgii_exit; |
652 | } | ||
653 | 691 | ||
654 | /* | 692 | /* |
655 | * If an inode wasn't passed in, then get the inode number | 693 | * If an inode wasn't passed in, then get the inode number |
@@ -660,23 +698,21 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, | |||
660 | */ | 698 | */ |
661 | if (*inode == NULL) { | 699 | if (*inode == NULL) { |
662 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { | 700 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { |
663 | if (server->ops->get_srv_inum) | 701 | if (validinum == false) { |
664 | tmprc = server->ops->get_srv_inum(xid, tcon, | 702 | if (server->ops->get_srv_inum) |
665 | cifs_sb, full_path, &fattr.cf_uniqueid, | 703 | tmprc = server->ops->get_srv_inum(xid, |
666 | data); | 704 | tcon, cifs_sb, full_path, |
667 | else | 705 | &fattr.cf_uniqueid, data); |
668 | tmprc = -ENOSYS; | 706 | if (tmprc) { |
669 | if (tmprc || !fattr.cf_uniqueid) { | 707 | cFYI(1, "GetSrvInodeNum rc %d", tmprc); |
670 | cFYI(1, "GetSrvInodeNum rc %d", tmprc); | 708 | fattr.cf_uniqueid = iunique(sb, ROOT_I); |
671 | fattr.cf_uniqueid = iunique(sb, ROOT_I); | 709 | cifs_autodisable_serverino(cifs_sb); |
672 | cifs_autodisable_serverino(cifs_sb); | 710 | } |
673 | } | 711 | } |
674 | } else { | 712 | } else |
675 | fattr.cf_uniqueid = iunique(sb, ROOT_I); | 713 | fattr.cf_uniqueid = iunique(sb, ROOT_I); |
676 | } | 714 | } else |
677 | } else { | ||
678 | fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; | 715 | fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; |
679 | } | ||
680 | 716 | ||
681 | /* query for SFU type info if supported and needed */ | 717 | /* query for SFU type info if supported and needed */ |
682 | if (fattr.cf_cifsattrs & ATTR_SYSTEM && | 718 | if (fattr.cf_cifsattrs & ATTR_SYSTEM && |
@@ -876,25 +912,22 @@ out: | |||
876 | return inode; | 912 | return inode; |
877 | } | 913 | } |
878 | 914 | ||
879 | static int | 915 | int |
880 | cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid, | 916 | cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid, |
881 | char *full_path, __u32 dosattr) | 917 | char *full_path, __u32 dosattr) |
882 | { | 918 | { |
883 | int rc; | ||
884 | int oplock = 0; | ||
885 | __u16 netfid; | ||
886 | __u32 netpid; | ||
887 | bool set_time = false; | 919 | bool set_time = false; |
888 | struct cifsFileInfo *open_file; | ||
889 | struct cifsInodeInfo *cifsInode = CIFS_I(inode); | ||
890 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 920 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
891 | struct tcon_link *tlink = NULL; | 921 | struct TCP_Server_Info *server; |
892 | struct cifs_tcon *pTcon; | ||
893 | FILE_BASIC_INFO info_buf; | 922 | FILE_BASIC_INFO info_buf; |
894 | 923 | ||
895 | if (attrs == NULL) | 924 | if (attrs == NULL) |
896 | return -EINVAL; | 925 | return -EINVAL; |
897 | 926 | ||
927 | server = cifs_sb_master_tcon(cifs_sb)->ses->server; | ||
928 | if (!server->ops->set_file_info) | ||
929 | return -ENOSYS; | ||
930 | |||
898 | if (attrs->ia_valid & ATTR_ATIME) { | 931 | if (attrs->ia_valid & ATTR_ATIME) { |
899 | set_time = true; | 932 | set_time = true; |
900 | info_buf.LastAccessTime = | 933 | info_buf.LastAccessTime = |
@@ -925,81 +958,17 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid, | |||
925 | info_buf.CreationTime = 0; /* don't change */ | 958 | info_buf.CreationTime = 0; /* don't change */ |
926 | info_buf.Attributes = cpu_to_le32(dosattr); | 959 | info_buf.Attributes = cpu_to_le32(dosattr); |
927 | 960 | ||
928 | /* | 961 | return server->ops->set_file_info(inode, full_path, &info_buf, xid); |
929 | * If the file is already open for write, just use that fileid | ||
930 | */ | ||
931 | open_file = find_writable_file(cifsInode, true); | ||
932 | if (open_file) { | ||
933 | netfid = open_file->netfid; | ||
934 | netpid = open_file->pid; | ||
935 | pTcon = tlink_tcon(open_file->tlink); | ||
936 | goto set_via_filehandle; | ||
937 | } | ||
938 | |||
939 | tlink = cifs_sb_tlink(cifs_sb); | ||
940 | if (IS_ERR(tlink)) { | ||
941 | rc = PTR_ERR(tlink); | ||
942 | tlink = NULL; | ||
943 | goto out; | ||
944 | } | ||
945 | pTcon = tlink_tcon(tlink); | ||
946 | |||
947 | /* | ||
948 | * NT4 apparently returns success on this call, but it doesn't | ||
949 | * really work. | ||
950 | */ | ||
951 | if (!(pTcon->ses->flags & CIFS_SES_NT4)) { | ||
952 | rc = CIFSSMBSetPathInfo(xid, pTcon, full_path, | ||
953 | &info_buf, cifs_sb->local_nls, | ||
954 | cifs_sb->mnt_cifs_flags & | ||
955 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
956 | if (rc == 0) { | ||
957 | cifsInode->cifsAttrs = dosattr; | ||
958 | goto out; | ||
959 | } else if (rc != -EOPNOTSUPP && rc != -EINVAL) | ||
960 | goto out; | ||
961 | } | ||
962 | |||
963 | cFYI(1, "calling SetFileInfo since SetPathInfo for " | ||
964 | "times not supported by this server"); | ||
965 | rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, | ||
966 | SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, | ||
967 | CREATE_NOT_DIR, &netfid, &oplock, | ||
968 | NULL, cifs_sb->local_nls, | ||
969 | cifs_sb->mnt_cifs_flags & | ||
970 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
971 | |||
972 | if (rc != 0) { | ||
973 | if (rc == -EIO) | ||
974 | rc = -EINVAL; | ||
975 | goto out; | ||
976 | } | ||
977 | |||
978 | netpid = current->tgid; | ||
979 | |||
980 | set_via_filehandle: | ||
981 | rc = CIFSSMBSetFileInfo(xid, pTcon, &info_buf, netfid, netpid); | ||
982 | if (!rc) | ||
983 | cifsInode->cifsAttrs = dosattr; | ||
984 | |||
985 | if (open_file == NULL) | ||
986 | CIFSSMBClose(xid, pTcon, netfid); | ||
987 | else | ||
988 | cifsFileInfo_put(open_file); | ||
989 | out: | ||
990 | if (tlink != NULL) | ||
991 | cifs_put_tlink(tlink); | ||
992 | return rc; | ||
993 | } | 962 | } |
994 | 963 | ||
995 | /* | 964 | /* |
996 | * open the given file (if it isn't already), set the DELETE_ON_CLOSE bit | 965 | * Open the given file (if it isn't already), set the DELETE_ON_CLOSE bit |
997 | * and rename it to a random name that hopefully won't conflict with | 966 | * and rename it to a random name that hopefully won't conflict with |
998 | * anything else. | 967 | * anything else. |
999 | */ | 968 | */ |
1000 | static int | 969 | int |
1001 | cifs_rename_pending_delete(char *full_path, struct dentry *dentry, | 970 | cifs_rename_pending_delete(const char *full_path, struct dentry *dentry, |
1002 | unsigned int xid) | 971 | const unsigned int xid) |
1003 | { | 972 | { |
1004 | int oplock = 0; | 973 | int oplock = 0; |
1005 | int rc; | 974 | int rc; |
@@ -1136,6 +1105,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) | |||
1136 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | 1105 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
1137 | struct tcon_link *tlink; | 1106 | struct tcon_link *tlink; |
1138 | struct cifs_tcon *tcon; | 1107 | struct cifs_tcon *tcon; |
1108 | struct TCP_Server_Info *server; | ||
1139 | struct iattr *attrs = NULL; | 1109 | struct iattr *attrs = NULL; |
1140 | __u32 dosattr = 0, origattr = 0; | 1110 | __u32 dosattr = 0, origattr = 0; |
1141 | 1111 | ||
@@ -1145,6 +1115,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) | |||
1145 | if (IS_ERR(tlink)) | 1115 | if (IS_ERR(tlink)) |
1146 | return PTR_ERR(tlink); | 1116 | return PTR_ERR(tlink); |
1147 | tcon = tlink_tcon(tlink); | 1117 | tcon = tlink_tcon(tlink); |
1118 | server = tcon->ses->server; | ||
1148 | 1119 | ||
1149 | xid = get_xid(); | 1120 | xid = get_xid(); |
1150 | 1121 | ||
@@ -1167,8 +1138,12 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) | |||
1167 | } | 1138 | } |
1168 | 1139 | ||
1169 | retry_std_delete: | 1140 | retry_std_delete: |
1170 | rc = CIFSSMBDelFile(xid, tcon, full_path, cifs_sb->local_nls, | 1141 | if (!server->ops->unlink) { |
1171 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 1142 | rc = -ENOSYS; |
1143 | goto psx_del_no_retry; | ||
1144 | } | ||
1145 | |||
1146 | rc = server->ops->unlink(xid, tcon, full_path, cifs_sb); | ||
1172 | 1147 | ||
1173 | psx_del_no_retry: | 1148 | psx_del_no_retry: |
1174 | if (!rc) { | 1149 | if (!rc) { |
@@ -1177,9 +1152,14 @@ psx_del_no_retry: | |||
1177 | } else if (rc == -ENOENT) { | 1152 | } else if (rc == -ENOENT) { |
1178 | d_drop(dentry); | 1153 | d_drop(dentry); |
1179 | } else if (rc == -ETXTBSY) { | 1154 | } else if (rc == -ETXTBSY) { |
1180 | rc = cifs_rename_pending_delete(full_path, dentry, xid); | 1155 | if (server->ops->rename_pending_delete) { |
1181 | if (rc == 0) | 1156 | rc = server->ops->rename_pending_delete(full_path, |
1182 | cifs_drop_nlink(inode); | 1157 | dentry, xid); |
1158 | if (rc == 0) | ||
1159 | cifs_drop_nlink(inode); | ||
1160 | } | ||
1161 | if (rc == -ETXTBSY) | ||
1162 | rc = -EBUSY; | ||
1183 | } else if ((rc == -EACCES) && (dosattr == 0) && inode) { | 1163 | } else if ((rc == -EACCES) && (dosattr == 0) && inode) { |
1184 | attrs = kzalloc(sizeof(*attrs), GFP_KERNEL); | 1164 | attrs = kzalloc(sizeof(*attrs), GFP_KERNEL); |
1185 | if (attrs == NULL) { | 1165 | if (attrs == NULL) { |
@@ -1227,34 +1207,33 @@ unlink_out: | |||
1227 | } | 1207 | } |
1228 | 1208 | ||
1229 | static int | 1209 | static int |
1230 | cifs_mkdir_qinfo(struct inode *inode, struct dentry *dentry, umode_t mode, | 1210 | cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, |
1231 | const char *full_path, struct cifs_sb_info *cifs_sb, | 1211 | const char *full_path, struct cifs_sb_info *cifs_sb, |
1232 | struct cifs_tcon *tcon, const unsigned int xid) | 1212 | struct cifs_tcon *tcon, const unsigned int xid) |
1233 | { | 1213 | { |
1234 | int rc = 0; | 1214 | int rc = 0; |
1235 | struct inode *newinode = NULL; | 1215 | struct inode *inode = NULL; |
1236 | 1216 | ||
1237 | if (tcon->unix_ext) | 1217 | if (tcon->unix_ext) |
1238 | rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb, | 1218 | rc = cifs_get_inode_info_unix(&inode, full_path, parent->i_sb, |
1239 | xid); | 1219 | xid); |
1240 | else | 1220 | else |
1241 | rc = cifs_get_inode_info(&newinode, full_path, NULL, | 1221 | rc = cifs_get_inode_info(&inode, full_path, NULL, parent->i_sb, |
1242 | inode->i_sb, xid, NULL); | 1222 | xid, NULL); |
1223 | |||
1243 | if (rc) | 1224 | if (rc) |
1244 | return rc; | 1225 | return rc; |
1245 | 1226 | ||
1246 | d_instantiate(dentry, newinode); | ||
1247 | /* | 1227 | /* |
1248 | * setting nlink not necessary except in cases where we failed to get it | 1228 | * setting nlink not necessary except in cases where we failed to get it |
1249 | * from the server or was set bogus | 1229 | * from the server or was set bogus. Also, since this is a brand new |
1230 | * inode, no need to grab the i_lock before setting the i_nlink. | ||
1250 | */ | 1231 | */ |
1251 | spin_lock(&dentry->d_inode->i_lock); | 1232 | if (inode->i_nlink < 2) |
1252 | if ((dentry->d_inode) && (dentry->d_inode->i_nlink < 2)) | 1233 | set_nlink(inode, 2); |
1253 | set_nlink(dentry->d_inode, 2); | ||
1254 | spin_unlock(&dentry->d_inode->i_lock); | ||
1255 | mode &= ~current_umask(); | 1234 | mode &= ~current_umask(); |
1256 | /* must turn on setgid bit if parent dir has it */ | 1235 | /* must turn on setgid bit if parent dir has it */ |
1257 | if (inode->i_mode & S_ISGID) | 1236 | if (parent->i_mode & S_ISGID) |
1258 | mode |= S_ISGID; | 1237 | mode |= S_ISGID; |
1259 | 1238 | ||
1260 | if (tcon->unix_ext) { | 1239 | if (tcon->unix_ext) { |
@@ -1267,8 +1246,8 @@ cifs_mkdir_qinfo(struct inode *inode, struct dentry *dentry, umode_t mode, | |||
1267 | }; | 1246 | }; |
1268 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { | 1247 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { |
1269 | args.uid = (__u64)current_fsuid(); | 1248 | args.uid = (__u64)current_fsuid(); |
1270 | if (inode->i_mode & S_ISGID) | 1249 | if (parent->i_mode & S_ISGID) |
1271 | args.gid = (__u64)inode->i_gid; | 1250 | args.gid = (__u64)parent->i_gid; |
1272 | else | 1251 | else |
1273 | args.gid = (__u64)current_fsgid(); | 1252 | args.gid = (__u64)current_fsgid(); |
1274 | } else { | 1253 | } else { |
@@ -1283,22 +1262,20 @@ cifs_mkdir_qinfo(struct inode *inode, struct dentry *dentry, umode_t mode, | |||
1283 | struct TCP_Server_Info *server = tcon->ses->server; | 1262 | struct TCP_Server_Info *server = tcon->ses->server; |
1284 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) && | 1263 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) && |
1285 | (mode & S_IWUGO) == 0 && server->ops->mkdir_setinfo) | 1264 | (mode & S_IWUGO) == 0 && server->ops->mkdir_setinfo) |
1286 | server->ops->mkdir_setinfo(newinode, full_path, cifs_sb, | 1265 | server->ops->mkdir_setinfo(inode, full_path, cifs_sb, |
1287 | tcon, xid); | 1266 | tcon, xid); |
1288 | if (dentry->d_inode) { | 1267 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) |
1289 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) | 1268 | inode->i_mode = (mode | S_IFDIR); |
1290 | dentry->d_inode->i_mode = (mode | S_IFDIR); | 1269 | |
1291 | 1270 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { | |
1292 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { | 1271 | inode->i_uid = current_fsuid(); |
1293 | dentry->d_inode->i_uid = current_fsuid(); | 1272 | if (inode->i_mode & S_ISGID) |
1294 | if (inode->i_mode & S_ISGID) | 1273 | inode->i_gid = parent->i_gid; |
1295 | dentry->d_inode->i_gid = inode->i_gid; | 1274 | else |
1296 | else | 1275 | inode->i_gid = current_fsgid(); |
1297 | dentry->d_inode->i_gid = | ||
1298 | current_fsgid(); | ||
1299 | } | ||
1300 | } | 1276 | } |
1301 | } | 1277 | } |
1278 | d_instantiate(dentry, inode); | ||
1302 | return rc; | 1279 | return rc; |
1303 | } | 1280 | } |
1304 | 1281 | ||
@@ -1495,29 +1472,32 @@ rmdir_exit: | |||
1495 | } | 1472 | } |
1496 | 1473 | ||
1497 | static int | 1474 | static int |
1498 | cifs_do_rename(unsigned int xid, struct dentry *from_dentry, | 1475 | cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, |
1499 | const char *fromPath, struct dentry *to_dentry, | 1476 | const char *from_path, struct dentry *to_dentry, |
1500 | const char *toPath) | 1477 | const char *to_path) |
1501 | { | 1478 | { |
1502 | struct cifs_sb_info *cifs_sb = CIFS_SB(from_dentry->d_sb); | 1479 | struct cifs_sb_info *cifs_sb = CIFS_SB(from_dentry->d_sb); |
1503 | struct tcon_link *tlink; | 1480 | struct tcon_link *tlink; |
1504 | struct cifs_tcon *pTcon; | 1481 | struct cifs_tcon *tcon; |
1482 | struct TCP_Server_Info *server; | ||
1505 | __u16 srcfid; | 1483 | __u16 srcfid; |
1506 | int oplock, rc; | 1484 | int oplock, rc; |
1507 | 1485 | ||
1508 | tlink = cifs_sb_tlink(cifs_sb); | 1486 | tlink = cifs_sb_tlink(cifs_sb); |
1509 | if (IS_ERR(tlink)) | 1487 | if (IS_ERR(tlink)) |
1510 | return PTR_ERR(tlink); | 1488 | return PTR_ERR(tlink); |
1511 | pTcon = tlink_tcon(tlink); | 1489 | tcon = tlink_tcon(tlink); |
1490 | server = tcon->ses->server; | ||
1491 | |||
1492 | if (!server->ops->rename) | ||
1493 | return -ENOSYS; | ||
1512 | 1494 | ||
1513 | /* try path-based rename first */ | 1495 | /* try path-based rename first */ |
1514 | rc = CIFSSMBRename(xid, pTcon, fromPath, toPath, cifs_sb->local_nls, | 1496 | rc = server->ops->rename(xid, tcon, from_path, to_path, cifs_sb); |
1515 | cifs_sb->mnt_cifs_flags & | ||
1516 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
1517 | 1497 | ||
1518 | /* | 1498 | /* |
1519 | * don't bother with rename by filehandle unless file is busy and | 1499 | * Don't bother with rename by filehandle unless file is busy and |
1520 | * source Note that cross directory moves do not work with | 1500 | * source. Note that cross directory moves do not work with |
1521 | * rename by filehandle to various Windows servers. | 1501 | * rename by filehandle to various Windows servers. |
1522 | */ | 1502 | */ |
1523 | if (rc == 0 || rc != -ETXTBSY) | 1503 | if (rc == 0 || rc != -ETXTBSY) |
@@ -1528,29 +1508,28 @@ cifs_do_rename(unsigned int xid, struct dentry *from_dentry, | |||
1528 | goto do_rename_exit; | 1508 | goto do_rename_exit; |
1529 | 1509 | ||
1530 | /* open the file to be renamed -- we need DELETE perms */ | 1510 | /* open the file to be renamed -- we need DELETE perms */ |
1531 | rc = CIFSSMBOpen(xid, pTcon, fromPath, FILE_OPEN, DELETE, | 1511 | rc = CIFSSMBOpen(xid, tcon, from_path, FILE_OPEN, DELETE, |
1532 | CREATE_NOT_DIR, &srcfid, &oplock, NULL, | 1512 | CREATE_NOT_DIR, &srcfid, &oplock, NULL, |
1533 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & | 1513 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & |
1534 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1514 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1535 | |||
1536 | if (rc == 0) { | 1515 | if (rc == 0) { |
1537 | rc = CIFSSMBRenameOpenFile(xid, pTcon, srcfid, | 1516 | rc = CIFSSMBRenameOpenFile(xid, tcon, srcfid, |
1538 | (const char *) to_dentry->d_name.name, | 1517 | (const char *) to_dentry->d_name.name, |
1539 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & | 1518 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & |
1540 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1519 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1541 | 1520 | CIFSSMBClose(xid, tcon, srcfid); | |
1542 | CIFSSMBClose(xid, pTcon, srcfid); | ||
1543 | } | 1521 | } |
1544 | do_rename_exit: | 1522 | do_rename_exit: |
1545 | cifs_put_tlink(tlink); | 1523 | cifs_put_tlink(tlink); |
1546 | return rc; | 1524 | return rc; |
1547 | } | 1525 | } |
1548 | 1526 | ||
1549 | int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, | 1527 | int |
1550 | struct inode *target_dir, struct dentry *target_dentry) | 1528 | cifs_rename(struct inode *source_dir, struct dentry *source_dentry, |
1529 | struct inode *target_dir, struct dentry *target_dentry) | ||
1551 | { | 1530 | { |
1552 | char *fromName = NULL; | 1531 | char *from_name = NULL; |
1553 | char *toName = NULL; | 1532 | char *to_name = NULL; |
1554 | struct cifs_sb_info *cifs_sb; | 1533 | struct cifs_sb_info *cifs_sb; |
1555 | struct tcon_link *tlink; | 1534 | struct tcon_link *tlink; |
1556 | struct cifs_tcon *tcon; | 1535 | struct cifs_tcon *tcon; |
@@ -1571,25 +1550,25 @@ int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, | |||
1571 | * we already have the rename sem so we do not need to | 1550 | * we already have the rename sem so we do not need to |
1572 | * grab it again here to protect the path integrity | 1551 | * grab it again here to protect the path integrity |
1573 | */ | 1552 | */ |
1574 | fromName = build_path_from_dentry(source_dentry); | 1553 | from_name = build_path_from_dentry(source_dentry); |
1575 | if (fromName == NULL) { | 1554 | if (from_name == NULL) { |
1576 | rc = -ENOMEM; | 1555 | rc = -ENOMEM; |
1577 | goto cifs_rename_exit; | 1556 | goto cifs_rename_exit; |
1578 | } | 1557 | } |
1579 | 1558 | ||
1580 | toName = build_path_from_dentry(target_dentry); | 1559 | to_name = build_path_from_dentry(target_dentry); |
1581 | if (toName == NULL) { | 1560 | if (to_name == NULL) { |
1582 | rc = -ENOMEM; | 1561 | rc = -ENOMEM; |
1583 | goto cifs_rename_exit; | 1562 | goto cifs_rename_exit; |
1584 | } | 1563 | } |
1585 | 1564 | ||
1586 | rc = cifs_do_rename(xid, source_dentry, fromName, | 1565 | rc = cifs_do_rename(xid, source_dentry, from_name, target_dentry, |
1587 | target_dentry, toName); | 1566 | to_name); |
1588 | 1567 | ||
1589 | if (rc == -EEXIST && tcon->unix_ext) { | 1568 | if (rc == -EEXIST && tcon->unix_ext) { |
1590 | /* | 1569 | /* |
1591 | * Are src and dst hardlinks of same inode? We can | 1570 | * Are src and dst hardlinks of same inode? We can only tell |
1592 | * only tell with unix extensions enabled | 1571 | * with unix extensions enabled. |
1593 | */ | 1572 | */ |
1594 | info_buf_source = | 1573 | info_buf_source = |
1595 | kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), | 1574 | kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), |
@@ -1600,19 +1579,19 @@ int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, | |||
1600 | } | 1579 | } |
1601 | 1580 | ||
1602 | info_buf_target = info_buf_source + 1; | 1581 | info_buf_target = info_buf_source + 1; |
1603 | tmprc = CIFSSMBUnixQPathInfo(xid, tcon, fromName, | 1582 | tmprc = CIFSSMBUnixQPathInfo(xid, tcon, from_name, |
1604 | info_buf_source, | 1583 | info_buf_source, |
1605 | cifs_sb->local_nls, | 1584 | cifs_sb->local_nls, |
1606 | cifs_sb->mnt_cifs_flags & | 1585 | cifs_sb->mnt_cifs_flags & |
1607 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1586 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1608 | if (tmprc != 0) | 1587 | if (tmprc != 0) |
1609 | goto unlink_target; | 1588 | goto unlink_target; |
1610 | 1589 | ||
1611 | tmprc = CIFSSMBUnixQPathInfo(xid, tcon, toName, | 1590 | tmprc = CIFSSMBUnixQPathInfo(xid, tcon, to_name, |
1612 | info_buf_target, | 1591 | info_buf_target, |
1613 | cifs_sb->local_nls, | 1592 | cifs_sb->local_nls, |
1614 | cifs_sb->mnt_cifs_flags & | 1593 | cifs_sb->mnt_cifs_flags & |
1615 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1594 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1616 | 1595 | ||
1617 | if (tmprc == 0 && (info_buf_source->UniqueId == | 1596 | if (tmprc == 0 && (info_buf_source->UniqueId == |
1618 | info_buf_target->UniqueId)) { | 1597 | info_buf_target->UniqueId)) { |
@@ -1620,8 +1599,11 @@ int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, | |||
1620 | rc = 0; | 1599 | rc = 0; |
1621 | goto cifs_rename_exit; | 1600 | goto cifs_rename_exit; |
1622 | } | 1601 | } |
1623 | } /* else ... BB we could add the same check for Windows by | 1602 | } |
1624 | checking the UniqueId via FILE_INTERNAL_INFO */ | 1603 | /* |
1604 | * else ... BB we could add the same check for Windows by | ||
1605 | * checking the UniqueId via FILE_INTERNAL_INFO | ||
1606 | */ | ||
1625 | 1607 | ||
1626 | unlink_target: | 1608 | unlink_target: |
1627 | /* Try unlinking the target dentry if it's not negative */ | 1609 | /* Try unlinking the target dentry if it's not negative */ |
@@ -1629,15 +1611,14 @@ unlink_target: | |||
1629 | tmprc = cifs_unlink(target_dir, target_dentry); | 1611 | tmprc = cifs_unlink(target_dir, target_dentry); |
1630 | if (tmprc) | 1612 | if (tmprc) |
1631 | goto cifs_rename_exit; | 1613 | goto cifs_rename_exit; |
1632 | 1614 | rc = cifs_do_rename(xid, source_dentry, from_name, | |
1633 | rc = cifs_do_rename(xid, source_dentry, fromName, | 1615 | target_dentry, to_name); |
1634 | target_dentry, toName); | ||
1635 | } | 1616 | } |
1636 | 1617 | ||
1637 | cifs_rename_exit: | 1618 | cifs_rename_exit: |
1638 | kfree(info_buf_source); | 1619 | kfree(info_buf_source); |
1639 | kfree(fromName); | 1620 | kfree(from_name); |
1640 | kfree(toName); | 1621 | kfree(to_name); |
1641 | free_xid(xid); | 1622 | free_xid(xid); |
1642 | cifs_put_tlink(tlink); | 1623 | cifs_put_tlink(tlink); |
1643 | return rc; | 1624 | return rc; |
@@ -1862,7 +1843,8 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, | |||
1862 | struct cifsInodeInfo *cifsInode = CIFS_I(inode); | 1843 | struct cifsInodeInfo *cifsInode = CIFS_I(inode); |
1863 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 1844 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
1864 | struct tcon_link *tlink = NULL; | 1845 | struct tcon_link *tlink = NULL; |
1865 | struct cifs_tcon *pTcon = NULL; | 1846 | struct cifs_tcon *tcon = NULL; |
1847 | struct TCP_Server_Info *server; | ||
1866 | struct cifs_io_parms io_parms; | 1848 | struct cifs_io_parms io_parms; |
1867 | 1849 | ||
1868 | /* | 1850 | /* |
@@ -1876,19 +1858,21 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, | |||
1876 | */ | 1858 | */ |
1877 | open_file = find_writable_file(cifsInode, true); | 1859 | open_file = find_writable_file(cifsInode, true); |
1878 | if (open_file) { | 1860 | if (open_file) { |
1879 | __u16 nfid = open_file->netfid; | 1861 | tcon = tlink_tcon(open_file->tlink); |
1880 | __u32 npid = open_file->pid; | 1862 | server = tcon->ses->server; |
1881 | pTcon = tlink_tcon(open_file->tlink); | 1863 | if (server->ops->set_file_size) |
1882 | rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size, nfid, | 1864 | rc = server->ops->set_file_size(xid, tcon, open_file, |
1883 | npid, false); | 1865 | attrs->ia_size, false); |
1866 | else | ||
1867 | rc = -ENOSYS; | ||
1884 | cifsFileInfo_put(open_file); | 1868 | cifsFileInfo_put(open_file); |
1885 | cFYI(1, "SetFSize for attrs rc = %d", rc); | 1869 | cFYI(1, "SetFSize for attrs rc = %d", rc); |
1886 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { | 1870 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { |
1887 | unsigned int bytes_written; | 1871 | unsigned int bytes_written; |
1888 | 1872 | ||
1889 | io_parms.netfid = nfid; | 1873 | io_parms.netfid = open_file->fid.netfid; |
1890 | io_parms.pid = npid; | 1874 | io_parms.pid = open_file->pid; |
1891 | io_parms.tcon = pTcon; | 1875 | io_parms.tcon = tcon; |
1892 | io_parms.offset = 0; | 1876 | io_parms.offset = 0; |
1893 | io_parms.length = attrs->ia_size; | 1877 | io_parms.length = attrs->ia_size; |
1894 | rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, | 1878 | rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, |
@@ -1898,52 +1882,55 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, | |||
1898 | } else | 1882 | } else |
1899 | rc = -EINVAL; | 1883 | rc = -EINVAL; |
1900 | 1884 | ||
1901 | if (rc != 0) { | 1885 | if (!rc) |
1902 | if (pTcon == NULL) { | 1886 | goto set_size_out; |
1903 | tlink = cifs_sb_tlink(cifs_sb); | ||
1904 | if (IS_ERR(tlink)) | ||
1905 | return PTR_ERR(tlink); | ||
1906 | pTcon = tlink_tcon(tlink); | ||
1907 | } | ||
1908 | 1887 | ||
1909 | /* Set file size by pathname rather than by handle | 1888 | if (tcon == NULL) { |
1910 | either because no valid, writeable file handle for | 1889 | tlink = cifs_sb_tlink(cifs_sb); |
1911 | it was found or because there was an error setting | 1890 | if (IS_ERR(tlink)) |
1912 | it by handle */ | 1891 | return PTR_ERR(tlink); |
1913 | rc = CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size, | 1892 | tcon = tlink_tcon(tlink); |
1914 | false, cifs_sb->local_nls, | 1893 | server = tcon->ses->server; |
1894 | } | ||
1895 | |||
1896 | /* | ||
1897 | * Set file size by pathname rather than by handle either because no | ||
1898 | * valid, writeable file handle for it was found or because there was | ||
1899 | * an error setting it by handle. | ||
1900 | */ | ||
1901 | if (server->ops->set_path_size) | ||
1902 | rc = server->ops->set_path_size(xid, tcon, full_path, | ||
1903 | attrs->ia_size, cifs_sb, false); | ||
1904 | else | ||
1905 | rc = -ENOSYS; | ||
1906 | cFYI(1, "SetEOF by path (setattrs) rc = %d", rc); | ||
1907 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { | ||
1908 | __u16 netfid; | ||
1909 | int oplock = 0; | ||
1910 | |||
1911 | rc = SMBLegacyOpen(xid, tcon, full_path, FILE_OPEN, | ||
1912 | GENERIC_WRITE, CREATE_NOT_DIR, &netfid, | ||
1913 | &oplock, NULL, cifs_sb->local_nls, | ||
1915 | cifs_sb->mnt_cifs_flags & | 1914 | cifs_sb->mnt_cifs_flags & |
1916 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1915 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1917 | cFYI(1, "SetEOF by path (setattrs) rc = %d", rc); | 1916 | if (rc == 0) { |
1918 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { | 1917 | unsigned int bytes_written; |
1919 | __u16 netfid; | 1918 | |
1920 | int oplock = 0; | 1919 | io_parms.netfid = netfid; |
1921 | 1920 | io_parms.pid = current->tgid; | |
1922 | rc = SMBLegacyOpen(xid, pTcon, full_path, | 1921 | io_parms.tcon = tcon; |
1923 | FILE_OPEN, GENERIC_WRITE, | 1922 | io_parms.offset = 0; |
1924 | CREATE_NOT_DIR, &netfid, &oplock, NULL, | 1923 | io_parms.length = attrs->ia_size; |
1925 | cifs_sb->local_nls, | 1924 | rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, NULL, |
1926 | cifs_sb->mnt_cifs_flags & | 1925 | NULL, 1); |
1927 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1926 | cFYI(1, "wrt seteof rc %d", rc); |
1928 | if (rc == 0) { | 1927 | CIFSSMBClose(xid, tcon, netfid); |
1929 | unsigned int bytes_written; | ||
1930 | |||
1931 | io_parms.netfid = netfid; | ||
1932 | io_parms.pid = current->tgid; | ||
1933 | io_parms.tcon = pTcon; | ||
1934 | io_parms.offset = 0; | ||
1935 | io_parms.length = attrs->ia_size; | ||
1936 | rc = CIFSSMBWrite(xid, &io_parms, | ||
1937 | &bytes_written, | ||
1938 | NULL, NULL, 1); | ||
1939 | cFYI(1, "wrt seteof rc %d", rc); | ||
1940 | CIFSSMBClose(xid, pTcon, netfid); | ||
1941 | } | ||
1942 | } | 1928 | } |
1943 | if (tlink) | ||
1944 | cifs_put_tlink(tlink); | ||
1945 | } | 1929 | } |
1930 | if (tlink) | ||
1931 | cifs_put_tlink(tlink); | ||
1946 | 1932 | ||
1933 | set_size_out: | ||
1947 | if (rc == 0) { | 1934 | if (rc == 0) { |
1948 | cifsInode->server_eof = attrs->ia_size; | 1935 | cifsInode->server_eof = attrs->ia_size; |
1949 | cifs_setsize(inode, attrs->ia_size); | 1936 | cifs_setsize(inode, attrs->ia_size); |
@@ -2050,7 +2037,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) | |||
2050 | args->device = 0; | 2037 | args->device = 0; |
2051 | open_file = find_writable_file(cifsInode, true); | 2038 | open_file = find_writable_file(cifsInode, true); |
2052 | if (open_file) { | 2039 | if (open_file) { |
2053 | u16 nfid = open_file->netfid; | 2040 | u16 nfid = open_file->fid.netfid; |
2054 | u32 npid = open_file->pid; | 2041 | u32 npid = open_file->pid; |
2055 | pTcon = tlink_tcon(open_file->tlink); | 2042 | pTcon = tlink_tcon(open_file->tlink); |
2056 | rc = CIFSSMBUnixSetFileInfo(xid, pTcon, args, nfid, npid); | 2043 | rc = CIFSSMBUnixSetFileInfo(xid, pTcon, args, nfid, npid); |
diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c index ae082a66de2f..fd5009d56f9f 100644 --- a/fs/cifs/ioctl.c +++ b/fs/cifs/ioctl.c | |||
@@ -28,8 +28,6 @@ | |||
28 | #include "cifs_debug.h" | 28 | #include "cifs_debug.h" |
29 | #include "cifsfs.h" | 29 | #include "cifsfs.h" |
30 | 30 | ||
31 | #define CIFS_IOC_CHECKUMOUNT _IO(0xCF, 2) | ||
32 | |||
33 | long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | 31 | long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) |
34 | { | 32 | { |
35 | struct inode *inode = filep->f_dentry->d_inode; | 33 | struct inode *inode = filep->f_dentry->d_inode; |
@@ -51,23 +49,6 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | |||
51 | cifs_sb = CIFS_SB(inode->i_sb); | 49 | cifs_sb = CIFS_SB(inode->i_sb); |
52 | 50 | ||
53 | switch (command) { | 51 | switch (command) { |
54 | static bool warned = false; | ||
55 | case CIFS_IOC_CHECKUMOUNT: | ||
56 | if (!warned) { | ||
57 | warned = true; | ||
58 | cERROR(1, "the CIFS_IOC_CHECKMOUNT ioctl will " | ||
59 | "be deprecated in 3.7. Please " | ||
60 | "migrate away from the use of " | ||
61 | "umount.cifs"); | ||
62 | } | ||
63 | cFYI(1, "User unmount attempted"); | ||
64 | if (cifs_sb->mnt_uid == current_uid()) | ||
65 | rc = 0; | ||
66 | else { | ||
67 | rc = -EACCES; | ||
68 | cFYI(1, "uids do not match"); | ||
69 | } | ||
70 | break; | ||
71 | #ifdef CONFIG_CIFS_POSIX | 52 | #ifdef CONFIG_CIFS_POSIX |
72 | case FS_IOC_GETFLAGS: | 53 | case FS_IOC_GETFLAGS: |
73 | if (pSMBFile == NULL) | 54 | if (pSMBFile == NULL) |
@@ -75,8 +56,9 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | |||
75 | tcon = tlink_tcon(pSMBFile->tlink); | 56 | tcon = tlink_tcon(pSMBFile->tlink); |
76 | caps = le64_to_cpu(tcon->fsUnixInfo.Capability); | 57 | caps = le64_to_cpu(tcon->fsUnixInfo.Capability); |
77 | if (CIFS_UNIX_EXTATTR_CAP & caps) { | 58 | if (CIFS_UNIX_EXTATTR_CAP & caps) { |
78 | rc = CIFSGetExtAttr(xid, tcon, pSMBFile->netfid, | 59 | rc = CIFSGetExtAttr(xid, tcon, |
79 | &ExtAttrBits, &ExtAttrMask); | 60 | pSMBFile->fid.netfid, |
61 | &ExtAttrBits, &ExtAttrMask); | ||
80 | if (rc == 0) | 62 | if (rc == 0) |
81 | rc = put_user(ExtAttrBits & | 63 | rc = put_user(ExtAttrBits & |
82 | FS_FL_USER_VISIBLE, | 64 | FS_FL_USER_VISIBLE, |
@@ -94,8 +76,12 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | |||
94 | rc = -EFAULT; | 76 | rc = -EFAULT; |
95 | break; | 77 | break; |
96 | } | 78 | } |
97 | /* rc= CIFSGetExtAttr(xid,tcon,pSMBFile->netfid, | 79 | /* |
98 | extAttrBits, &ExtAttrMask);*/ | 80 | * rc = CIFSGetExtAttr(xid, tcon, |
81 | * pSMBFile->fid.netfid, | ||
82 | * extAttrBits, | ||
83 | * &ExtAttrMask); | ||
84 | */ | ||
99 | } | 85 | } |
100 | cFYI(1, "set flags not implemented yet"); | 86 | cFYI(1, "set flags not implemented yet"); |
101 | break; | 87 | break; |
diff --git a/fs/cifs/link.c b/fs/cifs/link.c index e6ce3b112875..51dc2fb6e854 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c | |||
@@ -391,72 +391,86 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode, | |||
391 | { | 391 | { |
392 | int rc = -EACCES; | 392 | int rc = -EACCES; |
393 | unsigned int xid; | 393 | unsigned int xid; |
394 | char *fromName = NULL; | 394 | char *from_name = NULL; |
395 | char *toName = NULL; | 395 | char *to_name = NULL; |
396 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 396 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
397 | struct tcon_link *tlink; | 397 | struct tcon_link *tlink; |
398 | struct cifs_tcon *pTcon; | 398 | struct cifs_tcon *tcon; |
399 | struct TCP_Server_Info *server; | ||
399 | struct cifsInodeInfo *cifsInode; | 400 | struct cifsInodeInfo *cifsInode; |
400 | 401 | ||
401 | tlink = cifs_sb_tlink(cifs_sb); | 402 | tlink = cifs_sb_tlink(cifs_sb); |
402 | if (IS_ERR(tlink)) | 403 | if (IS_ERR(tlink)) |
403 | return PTR_ERR(tlink); | 404 | return PTR_ERR(tlink); |
404 | pTcon = tlink_tcon(tlink); | 405 | tcon = tlink_tcon(tlink); |
405 | 406 | ||
406 | xid = get_xid(); | 407 | xid = get_xid(); |
407 | 408 | ||
408 | fromName = build_path_from_dentry(old_file); | 409 | from_name = build_path_from_dentry(old_file); |
409 | toName = build_path_from_dentry(direntry); | 410 | to_name = build_path_from_dentry(direntry); |
410 | if ((fromName == NULL) || (toName == NULL)) { | 411 | if ((from_name == NULL) || (to_name == NULL)) { |
411 | rc = -ENOMEM; | 412 | rc = -ENOMEM; |
412 | goto cifs_hl_exit; | 413 | goto cifs_hl_exit; |
413 | } | 414 | } |
414 | 415 | ||
415 | if (pTcon->unix_ext) | 416 | if (tcon->unix_ext) |
416 | rc = CIFSUnixCreateHardLink(xid, pTcon, fromName, toName, | 417 | rc = CIFSUnixCreateHardLink(xid, tcon, from_name, to_name, |
417 | cifs_sb->local_nls, | 418 | cifs_sb->local_nls, |
418 | cifs_sb->mnt_cifs_flags & | 419 | cifs_sb->mnt_cifs_flags & |
419 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 420 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
420 | else { | 421 | else { |
421 | rc = CIFSCreateHardLink(xid, pTcon, fromName, toName, | 422 | server = tcon->ses->server; |
422 | cifs_sb->local_nls, | 423 | if (!server->ops->create_hardlink) |
423 | cifs_sb->mnt_cifs_flags & | 424 | return -ENOSYS; |
424 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 425 | rc = server->ops->create_hardlink(xid, tcon, from_name, to_name, |
426 | cifs_sb); | ||
425 | if ((rc == -EIO) || (rc == -EINVAL)) | 427 | if ((rc == -EIO) || (rc == -EINVAL)) |
426 | rc = -EOPNOTSUPP; | 428 | rc = -EOPNOTSUPP; |
427 | } | 429 | } |
428 | 430 | ||
429 | d_drop(direntry); /* force new lookup from server of target */ | 431 | d_drop(direntry); /* force new lookup from server of target */ |
430 | 432 | ||
431 | /* if source file is cached (oplocked) revalidate will not go to server | 433 | /* |
432 | until the file is closed or oplock broken so update nlinks locally */ | 434 | * if source file is cached (oplocked) revalidate will not go to server |
435 | * until the file is closed or oplock broken so update nlinks locally | ||
436 | */ | ||
433 | if (old_file->d_inode) { | 437 | if (old_file->d_inode) { |
434 | cifsInode = CIFS_I(old_file->d_inode); | 438 | cifsInode = CIFS_I(old_file->d_inode); |
435 | if (rc == 0) { | 439 | if (rc == 0) { |
436 | spin_lock(&old_file->d_inode->i_lock); | 440 | spin_lock(&old_file->d_inode->i_lock); |
437 | inc_nlink(old_file->d_inode); | 441 | inc_nlink(old_file->d_inode); |
438 | spin_unlock(&old_file->d_inode->i_lock); | 442 | spin_unlock(&old_file->d_inode->i_lock); |
439 | /* BB should we make this contingent on superblock flag NOATIME? */ | 443 | /* |
440 | /* old_file->d_inode->i_ctime = CURRENT_TIME;*/ | 444 | * BB should we make this contingent on superblock flag |
441 | /* parent dir timestamps will update from srv | 445 | * NOATIME? |
442 | within a second, would it really be worth it | 446 | */ |
443 | to set the parent dir cifs inode time to zero | 447 | /* old_file->d_inode->i_ctime = CURRENT_TIME; */ |
444 | to force revalidate (faster) for it too? */ | 448 | /* |
449 | * parent dir timestamps will update from srv within a | ||
450 | * second, would it really be worth it to set the parent | ||
451 | * dir cifs inode time to zero to force revalidate | ||
452 | * (faster) for it too? | ||
453 | */ | ||
445 | } | 454 | } |
446 | /* if not oplocked will force revalidate to get info | 455 | /* |
447 | on source file from srv */ | 456 | * if not oplocked will force revalidate to get info on source |
457 | * file from srv | ||
458 | */ | ||
448 | cifsInode->time = 0; | 459 | cifsInode->time = 0; |
449 | 460 | ||
450 | /* Will update parent dir timestamps from srv within a second. | 461 | /* |
451 | Would it really be worth it to set the parent dir (cifs | 462 | * Will update parent dir timestamps from srv within a second. |
452 | inode) time field to zero to force revalidate on parent | 463 | * Would it really be worth it to set the parent dir (cifs |
453 | directory faster ie | 464 | * inode) time field to zero to force revalidate on parent |
454 | CIFS_I(inode)->time = 0; */ | 465 | * directory faster ie |
466 | * | ||
467 | * CIFS_I(inode)->time = 0; | ||
468 | */ | ||
455 | } | 469 | } |
456 | 470 | ||
457 | cifs_hl_exit: | 471 | cifs_hl_exit: |
458 | kfree(fromName); | 472 | kfree(from_name); |
459 | kfree(toName); | 473 | kfree(to_name); |
460 | free_xid(xid); | 474 | free_xid(xid); |
461 | cifs_put_tlink(tlink); | 475 | cifs_put_tlink(tlink); |
462 | return rc; | 476 | return rc; |
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index ce41fee07e5b..3a00c0d0cead 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c | |||
@@ -466,7 +466,7 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv) | |||
466 | list_for_each(tmp2, &tcon->openFileList) { | 466 | list_for_each(tmp2, &tcon->openFileList) { |
467 | netfile = list_entry(tmp2, struct cifsFileInfo, | 467 | netfile = list_entry(tmp2, struct cifsFileInfo, |
468 | tlist); | 468 | tlist); |
469 | if (pSMB->Fid != netfile->netfid) | 469 | if (pSMB->Fid != netfile->fid.netfid) |
470 | continue; | 470 | continue; |
471 | 471 | ||
472 | cFYI(1, "file id match, oplock break"); | 472 | cFYI(1, "file id match, oplock break"); |
@@ -579,3 +579,33 @@ backup_cred(struct cifs_sb_info *cifs_sb) | |||
579 | 579 | ||
580 | return false; | 580 | return false; |
581 | } | 581 | } |
582 | |||
583 | void | ||
584 | cifs_del_pending_open(struct cifs_pending_open *open) | ||
585 | { | ||
586 | spin_lock(&cifs_file_list_lock); | ||
587 | list_del(&open->olist); | ||
588 | spin_unlock(&cifs_file_list_lock); | ||
589 | } | ||
590 | |||
591 | void | ||
592 | cifs_add_pending_open_locked(struct cifs_fid *fid, struct tcon_link *tlink, | ||
593 | struct cifs_pending_open *open) | ||
594 | { | ||
595 | #ifdef CONFIG_CIFS_SMB2 | ||
596 | memcpy(open->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); | ||
597 | #endif | ||
598 | open->oplock = CIFS_OPLOCK_NO_CHANGE; | ||
599 | open->tlink = tlink; | ||
600 | fid->pending_open = open; | ||
601 | list_add_tail(&open->olist, &tlink_tcon(tlink)->pending_opens); | ||
602 | } | ||
603 | |||
604 | void | ||
605 | cifs_add_pending_open(struct cifs_fid *fid, struct tcon_link *tlink, | ||
606 | struct cifs_pending_open *open) | ||
607 | { | ||
608 | spin_lock(&cifs_file_list_lock); | ||
609 | cifs_add_pending_open_locked(fid, tlink, open); | ||
610 | spin_unlock(&cifs_file_list_lock); | ||
611 | } | ||
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c index 581c225f7f50..d5ce9e26696c 100644 --- a/fs/cifs/netmisc.c +++ b/fs/cifs/netmisc.c | |||
@@ -110,7 +110,7 @@ static const struct smb_to_posix_error mapping_table_ERRSRV[] = { | |||
110 | {ERRnoroom, -ENOSPC}, | 110 | {ERRnoroom, -ENOSPC}, |
111 | {ERRrmuns, -EUSERS}, | 111 | {ERRrmuns, -EUSERS}, |
112 | {ERRtimeout, -ETIME}, | 112 | {ERRtimeout, -ETIME}, |
113 | {ERRnoresource, -ENOBUFS}, | 113 | {ERRnoresource, -EREMOTEIO}, |
114 | {ERRtoomanyuids, -EUSERS}, | 114 | {ERRtoomanyuids, -EUSERS}, |
115 | {ERRbaduid, -EACCES}, | 115 | {ERRbaduid, -EACCES}, |
116 | {ERRusempx, -EIO}, | 116 | {ERRusempx, -EIO}, |
@@ -412,7 +412,7 @@ static const struct { | |||
412 | from NT_STATUS_INSUFFICIENT_RESOURCES to | 412 | from NT_STATUS_INSUFFICIENT_RESOURCES to |
413 | NT_STATUS_INSUFF_SERVER_RESOURCES during the session setup } */ | 413 | NT_STATUS_INSUFF_SERVER_RESOURCES during the session setup } */ |
414 | { | 414 | { |
415 | ERRDOS, ERRnomem, NT_STATUS_INSUFFICIENT_RESOURCES}, { | 415 | ERRDOS, ERRnoresource, NT_STATUS_INSUFFICIENT_RESOURCES}, { |
416 | ERRDOS, ERRbadpath, NT_STATUS_DFS_EXIT_PATH_FOUND}, { | 416 | ERRDOS, ERRbadpath, NT_STATUS_DFS_EXIT_PATH_FOUND}, { |
417 | ERRDOS, 23, NT_STATUS_DEVICE_DATA_ERROR}, { | 417 | ERRDOS, 23, NT_STATUS_DEVICE_DATA_ERROR}, { |
418 | ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_CONNECTED}, { | 418 | ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_CONNECTED}, { |
@@ -682,7 +682,7 @@ static const struct { | |||
682 | ERRHRD, ERRgeneral, NT_STATUS_NO_USER_SESSION_KEY}, { | 682 | ERRHRD, ERRgeneral, NT_STATUS_NO_USER_SESSION_KEY}, { |
683 | ERRDOS, 59, NT_STATUS_USER_SESSION_DELETED}, { | 683 | ERRDOS, 59, NT_STATUS_USER_SESSION_DELETED}, { |
684 | ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_LANG_NOT_FOUND}, { | 684 | ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_LANG_NOT_FOUND}, { |
685 | ERRDOS, ERRnomem, NT_STATUS_INSUFF_SERVER_RESOURCES}, { | 685 | ERRDOS, ERRnoresource, NT_STATUS_INSUFF_SERVER_RESOURCES}, { |
686 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_BUFFER_SIZE}, { | 686 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_BUFFER_SIZE}, { |
687 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_COMPONENT}, { | 687 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_COMPONENT}, { |
688 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_WILDCARD}, { | 688 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_WILDCARD}, { |
@@ -913,8 +913,9 @@ map_smb_to_linux_error(char *buf, bool logErr) | |||
913 | * portion, the number of word parameters and the data portion of the message | 913 | * portion, the number of word parameters and the data portion of the message |
914 | */ | 914 | */ |
915 | unsigned int | 915 | unsigned int |
916 | smbCalcSize(struct smb_hdr *ptr) | 916 | smbCalcSize(void *buf) |
917 | { | 917 | { |
918 | struct smb_hdr *ptr = (struct smb_hdr *)buf; | ||
918 | return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) + | 919 | return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) + |
919 | 2 /* size of the bcc field */ + get_bcc(ptr)); | 920 | 2 /* size of the bcc field */ + get_bcc(ptr)); |
920 | } | 921 | } |
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c index d87f82678bc7..f9b5d3d6cf33 100644 --- a/fs/cifs/readdir.c +++ b/fs/cifs/readdir.c | |||
@@ -151,7 +151,7 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb) | |||
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | static void | 154 | void |
155 | cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info, | 155 | cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info, |
156 | struct cifs_sb_info *cifs_sb) | 156 | struct cifs_sb_info *cifs_sb) |
157 | { | 157 | { |
@@ -220,7 +220,8 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb, | |||
220 | } | 220 | } |
221 | */ | 221 | */ |
222 | 222 | ||
223 | static int initiate_cifs_search(const unsigned int xid, struct file *file) | 223 | static int |
224 | initiate_cifs_search(const unsigned int xid, struct file *file) | ||
224 | { | 225 | { |
225 | __u16 search_flags; | 226 | __u16 search_flags; |
226 | int rc = 0; | 227 | int rc = 0; |
@@ -229,6 +230,7 @@ static int initiate_cifs_search(const unsigned int xid, struct file *file) | |||
229 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 230 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
230 | struct tcon_link *tlink = NULL; | 231 | struct tcon_link *tlink = NULL; |
231 | struct cifs_tcon *tcon; | 232 | struct cifs_tcon *tcon; |
233 | struct TCP_Server_Info *server; | ||
232 | 234 | ||
233 | if (file->private_data == NULL) { | 235 | if (file->private_data == NULL) { |
234 | tlink = cifs_sb_tlink(cifs_sb); | 236 | tlink = cifs_sb_tlink(cifs_sb); |
@@ -248,6 +250,13 @@ static int initiate_cifs_search(const unsigned int xid, struct file *file) | |||
248 | tcon = tlink_tcon(cifsFile->tlink); | 250 | tcon = tlink_tcon(cifsFile->tlink); |
249 | } | 251 | } |
250 | 252 | ||
253 | server = tcon->ses->server; | ||
254 | |||
255 | if (!server->ops->query_dir_first) { | ||
256 | rc = -ENOSYS; | ||
257 | goto error_exit; | ||
258 | } | ||
259 | |||
251 | cifsFile->invalidHandle = true; | 260 | cifsFile->invalidHandle = true; |
252 | cifsFile->srch_inf.endOfSearch = false; | 261 | cifsFile->srch_inf.endOfSearch = false; |
253 | 262 | ||
@@ -278,10 +287,10 @@ ffirst_retry: | |||
278 | if (backup_cred(cifs_sb)) | 287 | if (backup_cred(cifs_sb)) |
279 | search_flags |= CIFS_SEARCH_BACKUP_SEARCH; | 288 | search_flags |= CIFS_SEARCH_BACKUP_SEARCH; |
280 | 289 | ||
281 | rc = CIFSFindFirst(xid, tcon, full_path, cifs_sb->local_nls, | 290 | rc = server->ops->query_dir_first(xid, tcon, full_path, cifs_sb, |
282 | &cifsFile->netfid, search_flags, &cifsFile->srch_inf, | 291 | &cifsFile->fid, search_flags, |
283 | cifs_sb->mnt_cifs_flags & | 292 | &cifsFile->srch_inf); |
284 | CIFS_MOUNT_MAP_SPECIAL_CHR, CIFS_DIR_SEP(cifs_sb)); | 293 | |
285 | if (rc == 0) | 294 | if (rc == 0) |
286 | cifsFile->invalidHandle = false; | 295 | cifsFile->invalidHandle = false; |
287 | /* BB add following call to handle readdir on new NTFS symlink errors | 296 | /* BB add following call to handle readdir on new NTFS symlink errors |
@@ -501,62 +510,67 @@ static int cifs_save_resume_key(const char *current_entry, | |||
501 | return rc; | 510 | return rc; |
502 | } | 511 | } |
503 | 512 | ||
504 | /* find the corresponding entry in the search */ | 513 | /* |
505 | /* Note that the SMB server returns search entries for . and .. which | 514 | * Find the corresponding entry in the search. Note that the SMB server returns |
506 | complicates logic here if we choose to parse for them and we do not | 515 | * search entries for . and .. which complicates logic here if we choose to |
507 | assume that they are located in the findfirst return buffer.*/ | 516 | * parse for them and we do not assume that they are located in the findfirst |
508 | /* We start counting in the buffer with entry 2 and increment for every | 517 | * return buffer. We start counting in the buffer with entry 2 and increment for |
509 | entry (do not increment for . or .. entry) */ | 518 | * every entry (do not increment for . or .. entry). |
510 | static int find_cifs_entry(const unsigned int xid, struct cifs_tcon *pTcon, | 519 | */ |
511 | struct file *file, char **ppCurrentEntry, int *num_to_ret) | 520 | static int |
521 | find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, | ||
522 | struct file *file, char **current_entry, int *num_to_ret) | ||
512 | { | 523 | { |
513 | __u16 search_flags; | 524 | __u16 search_flags; |
514 | int rc = 0; | 525 | int rc = 0; |
515 | int pos_in_buf = 0; | 526 | int pos_in_buf = 0; |
516 | loff_t first_entry_in_buffer; | 527 | loff_t first_entry_in_buffer; |
517 | loff_t index_to_find = file->f_pos; | 528 | loff_t index_to_find = file->f_pos; |
518 | struct cifsFileInfo *cifsFile = file->private_data; | 529 | struct cifsFileInfo *cfile = file->private_data; |
519 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 530 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
531 | struct TCP_Server_Info *server = tcon->ses->server; | ||
520 | /* check if index in the buffer */ | 532 | /* check if index in the buffer */ |
521 | 533 | ||
522 | if ((cifsFile == NULL) || (ppCurrentEntry == NULL) || | 534 | if (!server->ops->query_dir_first || !server->ops->query_dir_next) |
523 | (num_to_ret == NULL)) | 535 | return -ENOSYS; |
536 | |||
537 | if ((cfile == NULL) || (current_entry == NULL) || (num_to_ret == NULL)) | ||
524 | return -ENOENT; | 538 | return -ENOENT; |
525 | 539 | ||
526 | *ppCurrentEntry = NULL; | 540 | *current_entry = NULL; |
527 | first_entry_in_buffer = | 541 | first_entry_in_buffer = cfile->srch_inf.index_of_last_entry - |
528 | cifsFile->srch_inf.index_of_last_entry - | 542 | cfile->srch_inf.entries_in_buffer; |
529 | cifsFile->srch_inf.entries_in_buffer; | ||
530 | 543 | ||
531 | /* if first entry in buf is zero then is first buffer | 544 | /* |
532 | in search response data which means it is likely . and .. | 545 | * If first entry in buf is zero then is first buffer |
533 | will be in this buffer, although some servers do not return | 546 | * in search response data which means it is likely . and .. |
534 | . and .. for the root of a drive and for those we need | 547 | * will be in this buffer, although some servers do not return |
535 | to start two entries earlier */ | 548 | * . and .. for the root of a drive and for those we need |
549 | * to start two entries earlier. | ||
550 | */ | ||
536 | 551 | ||
537 | dump_cifs_file_struct(file, "In fce "); | 552 | dump_cifs_file_struct(file, "In fce "); |
538 | if (((index_to_find < cifsFile->srch_inf.index_of_last_entry) && | 553 | if (((index_to_find < cfile->srch_inf.index_of_last_entry) && |
539 | is_dir_changed(file)) || | 554 | is_dir_changed(file)) || (index_to_find < first_entry_in_buffer)) { |
540 | (index_to_find < first_entry_in_buffer)) { | ||
541 | /* close and restart search */ | 555 | /* close and restart search */ |
542 | cFYI(1, "search backing up - close and restart search"); | 556 | cFYI(1, "search backing up - close and restart search"); |
543 | spin_lock(&cifs_file_list_lock); | 557 | spin_lock(&cifs_file_list_lock); |
544 | if (!cifsFile->srch_inf.endOfSearch && | 558 | if (!cfile->srch_inf.endOfSearch && !cfile->invalidHandle) { |
545 | !cifsFile->invalidHandle) { | 559 | cfile->invalidHandle = true; |
546 | cifsFile->invalidHandle = true; | ||
547 | spin_unlock(&cifs_file_list_lock); | 560 | spin_unlock(&cifs_file_list_lock); |
548 | CIFSFindClose(xid, pTcon, cifsFile->netfid); | 561 | if (server->ops->close) |
562 | server->ops->close(xid, tcon, &cfile->fid); | ||
549 | } else | 563 | } else |
550 | spin_unlock(&cifs_file_list_lock); | 564 | spin_unlock(&cifs_file_list_lock); |
551 | if (cifsFile->srch_inf.ntwrk_buf_start) { | 565 | if (cfile->srch_inf.ntwrk_buf_start) { |
552 | cFYI(1, "freeing SMB ff cache buf on search rewind"); | 566 | cFYI(1, "freeing SMB ff cache buf on search rewind"); |
553 | if (cifsFile->srch_inf.smallBuf) | 567 | if (cfile->srch_inf.smallBuf) |
554 | cifs_small_buf_release(cifsFile->srch_inf. | 568 | cifs_small_buf_release(cfile->srch_inf. |
555 | ntwrk_buf_start); | 569 | ntwrk_buf_start); |
556 | else | 570 | else |
557 | cifs_buf_release(cifsFile->srch_inf. | 571 | cifs_buf_release(cfile->srch_inf. |
558 | ntwrk_buf_start); | 572 | ntwrk_buf_start); |
559 | cifsFile->srch_inf.ntwrk_buf_start = NULL; | 573 | cfile->srch_inf.ntwrk_buf_start = NULL; |
560 | } | 574 | } |
561 | rc = initiate_cifs_search(xid, file); | 575 | rc = initiate_cifs_search(xid, file); |
562 | if (rc) { | 576 | if (rc) { |
@@ -565,65 +579,64 @@ static int find_cifs_entry(const unsigned int xid, struct cifs_tcon *pTcon, | |||
565 | return rc; | 579 | return rc; |
566 | } | 580 | } |
567 | /* FindFirst/Next set last_entry to NULL on malformed reply */ | 581 | /* FindFirst/Next set last_entry to NULL on malformed reply */ |
568 | if (cifsFile->srch_inf.last_entry) | 582 | if (cfile->srch_inf.last_entry) |
569 | cifs_save_resume_key(cifsFile->srch_inf.last_entry, | 583 | cifs_save_resume_key(cfile->srch_inf.last_entry, cfile); |
570 | cifsFile); | ||
571 | } | 584 | } |
572 | 585 | ||
573 | search_flags = CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME; | 586 | search_flags = CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME; |
574 | if (backup_cred(cifs_sb)) | 587 | if (backup_cred(cifs_sb)) |
575 | search_flags |= CIFS_SEARCH_BACKUP_SEARCH; | 588 | search_flags |= CIFS_SEARCH_BACKUP_SEARCH; |
576 | 589 | ||
577 | while ((index_to_find >= cifsFile->srch_inf.index_of_last_entry) && | 590 | while ((index_to_find >= cfile->srch_inf.index_of_last_entry) && |
578 | (rc == 0) && !cifsFile->srch_inf.endOfSearch) { | 591 | (rc == 0) && !cfile->srch_inf.endOfSearch) { |
579 | cFYI(1, "calling findnext2"); | 592 | cFYI(1, "calling findnext2"); |
580 | rc = CIFSFindNext(xid, pTcon, cifsFile->netfid, search_flags, | 593 | rc = server->ops->query_dir_next(xid, tcon, &cfile->fid, |
581 | &cifsFile->srch_inf); | 594 | search_flags, |
595 | &cfile->srch_inf); | ||
582 | /* FindFirst/Next set last_entry to NULL on malformed reply */ | 596 | /* FindFirst/Next set last_entry to NULL on malformed reply */ |
583 | if (cifsFile->srch_inf.last_entry) | 597 | if (cfile->srch_inf.last_entry) |
584 | cifs_save_resume_key(cifsFile->srch_inf.last_entry, | 598 | cifs_save_resume_key(cfile->srch_inf.last_entry, cfile); |
585 | cifsFile); | ||
586 | if (rc) | 599 | if (rc) |
587 | return -ENOENT; | 600 | return -ENOENT; |
588 | } | 601 | } |
589 | if (index_to_find < cifsFile->srch_inf.index_of_last_entry) { | 602 | if (index_to_find < cfile->srch_inf.index_of_last_entry) { |
590 | /* we found the buffer that contains the entry */ | 603 | /* we found the buffer that contains the entry */ |
591 | /* scan and find it */ | 604 | /* scan and find it */ |
592 | int i; | 605 | int i; |
593 | char *current_entry; | 606 | char *cur_ent; |
594 | char *end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + | 607 | char *end_of_smb = cfile->srch_inf.ntwrk_buf_start + |
595 | smbCalcSize((struct smb_hdr *) | 608 | server->ops->calc_smb_size( |
596 | cifsFile->srch_inf.ntwrk_buf_start); | 609 | cfile->srch_inf.ntwrk_buf_start); |
597 | 610 | ||
598 | current_entry = cifsFile->srch_inf.srch_entries_start; | 611 | cur_ent = cfile->srch_inf.srch_entries_start; |
599 | first_entry_in_buffer = cifsFile->srch_inf.index_of_last_entry | 612 | first_entry_in_buffer = cfile->srch_inf.index_of_last_entry |
600 | - cifsFile->srch_inf.entries_in_buffer; | 613 | - cfile->srch_inf.entries_in_buffer; |
601 | pos_in_buf = index_to_find - first_entry_in_buffer; | 614 | pos_in_buf = index_to_find - first_entry_in_buffer; |
602 | cFYI(1, "found entry - pos_in_buf %d", pos_in_buf); | 615 | cFYI(1, "found entry - pos_in_buf %d", pos_in_buf); |
603 | 616 | ||
604 | for (i = 0; (i < (pos_in_buf)) && (current_entry != NULL); i++) { | 617 | for (i = 0; (i < (pos_in_buf)) && (cur_ent != NULL); i++) { |
605 | /* go entry by entry figuring out which is first */ | 618 | /* go entry by entry figuring out which is first */ |
606 | current_entry = nxt_dir_entry(current_entry, end_of_smb, | 619 | cur_ent = nxt_dir_entry(cur_ent, end_of_smb, |
607 | cifsFile->srch_inf.info_level); | 620 | cfile->srch_inf.info_level); |
608 | } | 621 | } |
609 | if ((current_entry == NULL) && (i < pos_in_buf)) { | 622 | if ((cur_ent == NULL) && (i < pos_in_buf)) { |
610 | /* BB fixme - check if we should flag this error */ | 623 | /* BB fixme - check if we should flag this error */ |
611 | cERROR(1, "reached end of buf searching for pos in buf" | 624 | cERROR(1, "reached end of buf searching for pos in buf" |
612 | " %d index to find %lld rc %d", | 625 | " %d index to find %lld rc %d", pos_in_buf, |
613 | pos_in_buf, index_to_find, rc); | 626 | index_to_find, rc); |
614 | } | 627 | } |
615 | rc = 0; | 628 | rc = 0; |
616 | *ppCurrentEntry = current_entry; | 629 | *current_entry = cur_ent; |
617 | } else { | 630 | } else { |
618 | cFYI(1, "index not in buffer - could not findnext into it"); | 631 | cFYI(1, "index not in buffer - could not findnext into it"); |
619 | return 0; | 632 | return 0; |
620 | } | 633 | } |
621 | 634 | ||
622 | if (pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) { | 635 | if (pos_in_buf >= cfile->srch_inf.entries_in_buffer) { |
623 | cFYI(1, "can not return entries pos_in_buf beyond last"); | 636 | cFYI(1, "can not return entries pos_in_buf beyond last"); |
624 | *num_to_ret = 0; | 637 | *num_to_ret = 0; |
625 | } else | 638 | } else |
626 | *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf; | 639 | *num_to_ret = cfile->srch_inf.entries_in_buffer - pos_in_buf; |
627 | 640 | ||
628 | return rc; | 641 | return rc; |
629 | } | 642 | } |
@@ -723,7 +736,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
723 | int rc = 0; | 736 | int rc = 0; |
724 | unsigned int xid; | 737 | unsigned int xid; |
725 | int i; | 738 | int i; |
726 | struct cifs_tcon *pTcon; | 739 | struct cifs_tcon *tcon; |
727 | struct cifsFileInfo *cifsFile = NULL; | 740 | struct cifsFileInfo *cifsFile = NULL; |
728 | char *current_entry; | 741 | char *current_entry; |
729 | int num_to_fill = 0; | 742 | int num_to_fill = 0; |
@@ -781,12 +794,12 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
781 | } | 794 | } |
782 | } /* else { | 795 | } /* else { |
783 | cifsFile->invalidHandle = true; | 796 | cifsFile->invalidHandle = true; |
784 | CIFSFindClose(xid, pTcon, cifsFile->netfid); | 797 | tcon->ses->server->close(xid, tcon, &cifsFile->fid); |
785 | } */ | 798 | } */ |
786 | 799 | ||
787 | pTcon = tlink_tcon(cifsFile->tlink); | 800 | tcon = tlink_tcon(cifsFile->tlink); |
788 | rc = find_cifs_entry(xid, pTcon, file, | 801 | rc = find_cifs_entry(xid, tcon, file, ¤t_entry, |
789 | ¤t_entry, &num_to_fill); | 802 | &num_to_fill); |
790 | if (rc) { | 803 | if (rc) { |
791 | cFYI(1, "fce error %d", rc); | 804 | cFYI(1, "fce error %d", rc); |
792 | goto rddir2_exit; | 805 | goto rddir2_exit; |
@@ -798,7 +811,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
798 | } | 811 | } |
799 | cFYI(1, "loop through %d times filling dir for net buf %p", | 812 | cFYI(1, "loop through %d times filling dir for net buf %p", |
800 | num_to_fill, cifsFile->srch_inf.ntwrk_buf_start); | 813 | num_to_fill, cifsFile->srch_inf.ntwrk_buf_start); |
801 | max_len = smbCalcSize((struct smb_hdr *) | 814 | max_len = tcon->ses->server->ops->calc_smb_size( |
802 | cifsFile->srch_inf.ntwrk_buf_start); | 815 | cifsFile->srch_inf.ntwrk_buf_start); |
803 | end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len; | 816 | end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len; |
804 | 817 | ||
@@ -815,10 +828,12 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
815 | num_to_fill, i); | 828 | num_to_fill, i); |
816 | break; | 829 | break; |
817 | } | 830 | } |
818 | /* if buggy server returns . and .. late do | 831 | /* |
819 | we want to check for that here? */ | 832 | * if buggy server returns . and .. late do we want to |
820 | rc = cifs_filldir(current_entry, file, | 833 | * check for that here? |
821 | filldir, direntry, tmp_buf, max_len); | 834 | */ |
835 | rc = cifs_filldir(current_entry, file, filldir, | ||
836 | direntry, tmp_buf, max_len); | ||
822 | if (rc == -EOVERFLOW) { | 837 | if (rc == -EOVERFLOW) { |
823 | rc = 0; | 838 | rc = 0; |
824 | break; | 839 | break; |
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c index 382c06d01b38..76809f4d3428 100644 --- a/fs/cifs/sess.c +++ b/fs/cifs/sess.c | |||
@@ -876,7 +876,8 @@ ssetup_ntlmssp_authenticate: | |||
876 | pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base; | 876 | pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base; |
877 | smb_buf = (struct smb_hdr *)iov[0].iov_base; | 877 | smb_buf = (struct smb_hdr *)iov[0].iov_base; |
878 | 878 | ||
879 | if ((type == RawNTLMSSP) && (smb_buf->Status.CifsError == | 879 | if ((type == RawNTLMSSP) && (resp_buf_type != CIFS_NO_BUFFER) && |
880 | (smb_buf->Status.CifsError == | ||
880 | cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))) { | 881 | cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))) { |
881 | if (phase != NtLmNegotiate) { | 882 | if (phase != NtLmNegotiate) { |
882 | cERROR(1, "Unexpected more processing error"); | 883 | cERROR(1, "Unexpected more processing error"); |
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c index 3129ac74b819..56cc4be87807 100644 --- a/fs/cifs/smb1ops.c +++ b/fs/cifs/smb1ops.c | |||
@@ -17,6 +17,8 @@ | |||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/pagemap.h> | ||
21 | #include <linux/vfs.h> | ||
20 | #include "cifsglob.h" | 22 | #include "cifsglob.h" |
21 | #include "cifsproto.h" | 23 | #include "cifsproto.h" |
22 | #include "cifs_debug.h" | 24 | #include "cifs_debug.h" |
@@ -63,7 +65,7 @@ send_nt_cancel(struct TCP_Server_Info *server, void *buf, | |||
63 | static bool | 65 | static bool |
64 | cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) | 66 | cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
65 | { | 67 | { |
66 | return ob1->netfid == ob2->netfid; | 68 | return ob1->fid.netfid == ob2->fid.netfid; |
67 | } | 69 | } |
68 | 70 | ||
69 | static unsigned int | 71 | static unsigned int |
@@ -410,6 +412,83 @@ cifs_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
410 | return rc; | 412 | return rc; |
411 | } | 413 | } |
412 | 414 | ||
415 | static unsigned int | ||
416 | cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | ||
417 | { | ||
418 | __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); | ||
419 | struct TCP_Server_Info *server = tcon->ses->server; | ||
420 | unsigned int wsize; | ||
421 | |||
422 | /* start with specified wsize, or default */ | ||
423 | if (volume_info->wsize) | ||
424 | wsize = volume_info->wsize; | ||
425 | else if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_WRITE_CAP)) | ||
426 | wsize = CIFS_DEFAULT_IOSIZE; | ||
427 | else | ||
428 | wsize = CIFS_DEFAULT_NON_POSIX_WSIZE; | ||
429 | |||
430 | /* can server support 24-bit write sizes? (via UNIX extensions) */ | ||
431 | if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP)) | ||
432 | wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1002_WSIZE); | ||
433 | |||
434 | /* | ||
435 | * no CAP_LARGE_WRITE_X or is signing enabled without CAP_UNIX set? | ||
436 | * Limit it to max buffer offered by the server, minus the size of the | ||
437 | * WRITEX header, not including the 4 byte RFC1001 length. | ||
438 | */ | ||
439 | if (!(server->capabilities & CAP_LARGE_WRITE_X) || | ||
440 | (!(server->capabilities & CAP_UNIX) && | ||
441 | (server->sec_mode & (SECMODE_SIGN_ENABLED|SECMODE_SIGN_REQUIRED)))) | ||
442 | wsize = min_t(unsigned int, wsize, | ||
443 | server->maxBuf - sizeof(WRITE_REQ) + 4); | ||
444 | |||
445 | /* hard limit of CIFS_MAX_WSIZE */ | ||
446 | wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE); | ||
447 | |||
448 | return wsize; | ||
449 | } | ||
450 | |||
451 | static unsigned int | ||
452 | cifs_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | ||
453 | { | ||
454 | __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); | ||
455 | struct TCP_Server_Info *server = tcon->ses->server; | ||
456 | unsigned int rsize, defsize; | ||
457 | |||
458 | /* | ||
459 | * Set default value... | ||
460 | * | ||
461 | * HACK alert! Ancient servers have very small buffers. Even though | ||
462 | * MS-CIFS indicates that servers are only limited by the client's | ||
463 | * bufsize for reads, testing against win98se shows that it throws | ||
464 | * INVALID_PARAMETER errors if you try to request too large a read. | ||
465 | * OS/2 just sends back short reads. | ||
466 | * | ||
467 | * If the server doesn't advertise CAP_LARGE_READ_X, then assume that | ||
468 | * it can't handle a read request larger than its MaxBufferSize either. | ||
469 | */ | ||
470 | if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_READ_CAP)) | ||
471 | defsize = CIFS_DEFAULT_IOSIZE; | ||
472 | else if (server->capabilities & CAP_LARGE_READ_X) | ||
473 | defsize = CIFS_DEFAULT_NON_POSIX_RSIZE; | ||
474 | else | ||
475 | defsize = server->maxBuf - sizeof(READ_RSP); | ||
476 | |||
477 | rsize = volume_info->rsize ? volume_info->rsize : defsize; | ||
478 | |||
479 | /* | ||
480 | * no CAP_LARGE_READ_X? Then MS-CIFS states that we must limit this to | ||
481 | * the client's MaxBufferSize. | ||
482 | */ | ||
483 | if (!(server->capabilities & CAP_LARGE_READ_X)) | ||
484 | rsize = min_t(unsigned int, CIFSMaxBufSize, rsize); | ||
485 | |||
486 | /* hard limit of CIFS_MAX_RSIZE */ | ||
487 | rsize = min_t(unsigned int, rsize, CIFS_MAX_RSIZE); | ||
488 | |||
489 | return rsize; | ||
490 | } | ||
491 | |||
413 | static void | 492 | static void |
414 | cifs_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) | 493 | cifs_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
415 | { | 494 | { |
@@ -489,6 +568,13 @@ cifs_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, | |||
489 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 568 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
490 | } | 569 | } |
491 | 570 | ||
571 | static int | ||
572 | cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
573 | struct cifs_fid *fid, FILE_ALL_INFO *data) | ||
574 | { | ||
575 | return CIFSSMBQFileInfo(xid, tcon, fid->netfid, data); | ||
576 | } | ||
577 | |||
492 | static char * | 578 | static char * |
493 | cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, | 579 | cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, |
494 | struct cifs_tcon *tcon) | 580 | struct cifs_tcon *tcon) |
@@ -607,6 +693,219 @@ cifs_mkdir_setinfo(struct inode *inode, const char *full_path, | |||
607 | cifsInode->cifsAttrs = dosattrs; | 693 | cifsInode->cifsAttrs = dosattrs; |
608 | } | 694 | } |
609 | 695 | ||
696 | static int | ||
697 | cifs_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path, | ||
698 | int disposition, int desired_access, int create_options, | ||
699 | struct cifs_fid *fid, __u32 *oplock, FILE_ALL_INFO *buf, | ||
700 | struct cifs_sb_info *cifs_sb) | ||
701 | { | ||
702 | if (!(tcon->ses->capabilities & CAP_NT_SMBS)) | ||
703 | return SMBLegacyOpen(xid, tcon, path, disposition, | ||
704 | desired_access, create_options, | ||
705 | &fid->netfid, oplock, buf, | ||
706 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags | ||
707 | & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
708 | return CIFSSMBOpen(xid, tcon, path, disposition, desired_access, | ||
709 | create_options, &fid->netfid, oplock, buf, | ||
710 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & | ||
711 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
712 | } | ||
713 | |||
714 | static void | ||
715 | cifs_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) | ||
716 | { | ||
717 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | ||
718 | cfile->fid.netfid = fid->netfid; | ||
719 | cifs_set_oplock_level(cinode, oplock); | ||
720 | cinode->can_cache_brlcks = cinode->clientCanCacheAll; | ||
721 | } | ||
722 | |||
723 | static void | ||
724 | cifs_close_file(const unsigned int xid, struct cifs_tcon *tcon, | ||
725 | struct cifs_fid *fid) | ||
726 | { | ||
727 | CIFSSMBClose(xid, tcon, fid->netfid); | ||
728 | } | ||
729 | |||
730 | static int | ||
731 | cifs_flush_file(const unsigned int xid, struct cifs_tcon *tcon, | ||
732 | struct cifs_fid *fid) | ||
733 | { | ||
734 | return CIFSSMBFlush(xid, tcon, fid->netfid); | ||
735 | } | ||
736 | |||
737 | static int | ||
738 | cifs_sync_read(const unsigned int xid, struct cifsFileInfo *cfile, | ||
739 | struct cifs_io_parms *parms, unsigned int *bytes_read, | ||
740 | char **buf, int *buf_type) | ||
741 | { | ||
742 | parms->netfid = cfile->fid.netfid; | ||
743 | return CIFSSMBRead(xid, parms, bytes_read, buf, buf_type); | ||
744 | } | ||
745 | |||
746 | static int | ||
747 | cifs_sync_write(const unsigned int xid, struct cifsFileInfo *cfile, | ||
748 | struct cifs_io_parms *parms, unsigned int *written, | ||
749 | struct kvec *iov, unsigned long nr_segs) | ||
750 | { | ||
751 | |||
752 | parms->netfid = cfile->fid.netfid; | ||
753 | return CIFSSMBWrite2(xid, parms, written, iov, nr_segs); | ||
754 | } | ||
755 | |||
756 | static int | ||
757 | smb_set_file_info(struct inode *inode, const char *full_path, | ||
758 | FILE_BASIC_INFO *buf, const unsigned int xid) | ||
759 | { | ||
760 | int oplock = 0; | ||
761 | int rc; | ||
762 | __u16 netfid; | ||
763 | __u32 netpid; | ||
764 | struct cifsFileInfo *open_file; | ||
765 | struct cifsInodeInfo *cinode = CIFS_I(inode); | ||
766 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | ||
767 | struct tcon_link *tlink = NULL; | ||
768 | struct cifs_tcon *tcon; | ||
769 | FILE_BASIC_INFO info_buf; | ||
770 | |||
771 | /* if the file is already open for write, just use that fileid */ | ||
772 | open_file = find_writable_file(cinode, true); | ||
773 | if (open_file) { | ||
774 | netfid = open_file->fid.netfid; | ||
775 | netpid = open_file->pid; | ||
776 | tcon = tlink_tcon(open_file->tlink); | ||
777 | goto set_via_filehandle; | ||
778 | } | ||
779 | |||
780 | tlink = cifs_sb_tlink(cifs_sb); | ||
781 | if (IS_ERR(tlink)) { | ||
782 | rc = PTR_ERR(tlink); | ||
783 | tlink = NULL; | ||
784 | goto out; | ||
785 | } | ||
786 | tcon = tlink_tcon(tlink); | ||
787 | |||
788 | /* | ||
789 | * NT4 apparently returns success on this call, but it doesn't really | ||
790 | * work. | ||
791 | */ | ||
792 | if (!(tcon->ses->flags & CIFS_SES_NT4)) { | ||
793 | rc = CIFSSMBSetPathInfo(xid, tcon, full_path, buf, | ||
794 | cifs_sb->local_nls, | ||
795 | cifs_sb->mnt_cifs_flags & | ||
796 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
797 | if (rc == 0) { | ||
798 | cinode->cifsAttrs = le32_to_cpu(buf->Attributes); | ||
799 | goto out; | ||
800 | } else if (rc != -EOPNOTSUPP && rc != -EINVAL) | ||
801 | goto out; | ||
802 | } | ||
803 | |||
804 | cFYI(1, "calling SetFileInfo since SetPathInfo for times not supported " | ||
805 | "by this server"); | ||
806 | rc = CIFSSMBOpen(xid, tcon, full_path, FILE_OPEN, | ||
807 | SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, CREATE_NOT_DIR, | ||
808 | &netfid, &oplock, NULL, cifs_sb->local_nls, | ||
809 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
810 | |||
811 | if (rc != 0) { | ||
812 | if (rc == -EIO) | ||
813 | rc = -EINVAL; | ||
814 | goto out; | ||
815 | } | ||
816 | |||
817 | netpid = current->tgid; | ||
818 | |||
819 | set_via_filehandle: | ||
820 | rc = CIFSSMBSetFileInfo(xid, tcon, &info_buf, netfid, netpid); | ||
821 | if (!rc) | ||
822 | cinode->cifsAttrs = le32_to_cpu(buf->Attributes); | ||
823 | |||
824 | if (open_file == NULL) | ||
825 | CIFSSMBClose(xid, tcon, netfid); | ||
826 | else | ||
827 | cifsFileInfo_put(open_file); | ||
828 | out: | ||
829 | if (tlink != NULL) | ||
830 | cifs_put_tlink(tlink); | ||
831 | return rc; | ||
832 | } | ||
833 | |||
834 | static int | ||
835 | cifs_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, | ||
836 | const char *path, struct cifs_sb_info *cifs_sb, | ||
837 | struct cifs_fid *fid, __u16 search_flags, | ||
838 | struct cifs_search_info *srch_inf) | ||
839 | { | ||
840 | return CIFSFindFirst(xid, tcon, path, cifs_sb, | ||
841 | &fid->netfid, search_flags, srch_inf, true); | ||
842 | } | ||
843 | |||
844 | static int | ||
845 | cifs_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, | ||
846 | struct cifs_fid *fid, __u16 search_flags, | ||
847 | struct cifs_search_info *srch_inf) | ||
848 | { | ||
849 | return CIFSFindNext(xid, tcon, fid->netfid, search_flags, srch_inf); | ||
850 | } | ||
851 | |||
852 | static int | ||
853 | cifs_close_dir(const unsigned int xid, struct cifs_tcon *tcon, | ||
854 | struct cifs_fid *fid) | ||
855 | { | ||
856 | return CIFSFindClose(xid, tcon, fid->netfid); | ||
857 | } | ||
858 | |||
859 | static int | ||
860 | cifs_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, | ||
861 | struct cifsInodeInfo *cinode) | ||
862 | { | ||
863 | return CIFSSMBLock(0, tcon, fid->netfid, current->tgid, 0, 0, 0, 0, | ||
864 | LOCKING_ANDX_OPLOCK_RELEASE, false, | ||
865 | cinode->clientCanCacheRead ? 1 : 0); | ||
866 | } | ||
867 | |||
868 | static int | ||
869 | cifs_queryfs(const unsigned int xid, struct cifs_tcon *tcon, | ||
870 | struct kstatfs *buf) | ||
871 | { | ||
872 | int rc = -EOPNOTSUPP; | ||
873 | |||
874 | buf->f_type = CIFS_MAGIC_NUMBER; | ||
875 | |||
876 | /* | ||
877 | * We could add a second check for a QFS Unix capability bit | ||
878 | */ | ||
879 | if ((tcon->ses->capabilities & CAP_UNIX) && | ||
880 | (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability))) | ||
881 | rc = CIFSSMBQFSPosixInfo(xid, tcon, buf); | ||
882 | |||
883 | /* | ||
884 | * Only need to call the old QFSInfo if failed on newer one, | ||
885 | * e.g. by OS/2. | ||
886 | **/ | ||
887 | if (rc && (tcon->ses->capabilities & CAP_NT_SMBS)) | ||
888 | rc = CIFSSMBQFSInfo(xid, tcon, buf); | ||
889 | |||
890 | /* | ||
891 | * Some old Windows servers also do not support level 103, retry with | ||
892 | * older level one if old server failed the previous call or we | ||
893 | * bypassed it because we detected that this was an older LANMAN sess | ||
894 | */ | ||
895 | if (rc) | ||
896 | rc = SMBOldQFSInfo(xid, tcon, buf); | ||
897 | return rc; | ||
898 | } | ||
899 | |||
900 | static int | ||
901 | cifs_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, | ||
902 | __u64 length, __u32 type, int lock, int unlock, bool wait) | ||
903 | { | ||
904 | return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->fid.netfid, | ||
905 | current->tgid, length, offset, unlock, lock, | ||
906 | (__u8)type, wait, 0); | ||
907 | } | ||
908 | |||
610 | struct smb_version_operations smb1_operations = { | 909 | struct smb_version_operations smb1_operations = { |
611 | .send_cancel = send_nt_cancel, | 910 | .send_cancel = send_nt_cancel, |
612 | .compare_fids = cifs_compare_fids, | 911 | .compare_fids = cifs_compare_fids, |
@@ -630,6 +929,8 @@ struct smb_version_operations smb1_operations = { | |||
630 | .check_trans2 = cifs_check_trans2, | 929 | .check_trans2 = cifs_check_trans2, |
631 | .need_neg = cifs_need_neg, | 930 | .need_neg = cifs_need_neg, |
632 | .negotiate = cifs_negotiate, | 931 | .negotiate = cifs_negotiate, |
932 | .negotiate_wsize = cifs_negotiate_wsize, | ||
933 | .negotiate_rsize = cifs_negotiate_rsize, | ||
633 | .sess_setup = CIFS_SessSetup, | 934 | .sess_setup = CIFS_SessSetup, |
634 | .logoff = CIFSSMBLogoff, | 935 | .logoff = CIFSSMBLogoff, |
635 | .tree_connect = CIFSTCon, | 936 | .tree_connect = CIFSTCon, |
@@ -638,12 +939,37 @@ struct smb_version_operations smb1_operations = { | |||
638 | .qfs_tcon = cifs_qfs_tcon, | 939 | .qfs_tcon = cifs_qfs_tcon, |
639 | .is_path_accessible = cifs_is_path_accessible, | 940 | .is_path_accessible = cifs_is_path_accessible, |
640 | .query_path_info = cifs_query_path_info, | 941 | .query_path_info = cifs_query_path_info, |
942 | .query_file_info = cifs_query_file_info, | ||
641 | .get_srv_inum = cifs_get_srv_inum, | 943 | .get_srv_inum = cifs_get_srv_inum, |
944 | .set_path_size = CIFSSMBSetEOF, | ||
945 | .set_file_size = CIFSSMBSetFileSize, | ||
946 | .set_file_info = smb_set_file_info, | ||
642 | .build_path_to_root = cifs_build_path_to_root, | 947 | .build_path_to_root = cifs_build_path_to_root, |
643 | .echo = CIFSSMBEcho, | 948 | .echo = CIFSSMBEcho, |
644 | .mkdir = CIFSSMBMkDir, | 949 | .mkdir = CIFSSMBMkDir, |
645 | .mkdir_setinfo = cifs_mkdir_setinfo, | 950 | .mkdir_setinfo = cifs_mkdir_setinfo, |
646 | .rmdir = CIFSSMBRmDir, | 951 | .rmdir = CIFSSMBRmDir, |
952 | .unlink = CIFSSMBDelFile, | ||
953 | .rename_pending_delete = cifs_rename_pending_delete, | ||
954 | .rename = CIFSSMBRename, | ||
955 | .create_hardlink = CIFSCreateHardLink, | ||
956 | .open = cifs_open_file, | ||
957 | .set_fid = cifs_set_fid, | ||
958 | .close = cifs_close_file, | ||
959 | .flush = cifs_flush_file, | ||
960 | .async_readv = cifs_async_readv, | ||
961 | .async_writev = cifs_async_writev, | ||
962 | .sync_read = cifs_sync_read, | ||
963 | .sync_write = cifs_sync_write, | ||
964 | .query_dir_first = cifs_query_dir_first, | ||
965 | .query_dir_next = cifs_query_dir_next, | ||
966 | .close_dir = cifs_close_dir, | ||
967 | .calc_smb_size = smbCalcSize, | ||
968 | .oplock_response = cifs_oplock_response, | ||
969 | .queryfs = cifs_queryfs, | ||
970 | .mand_lock = cifs_mand_lock, | ||
971 | .mand_unlock_range = cifs_unlock_range, | ||
972 | .push_mand_locks = cifs_push_mandatory_locks, | ||
647 | }; | 973 | }; |
648 | 974 | ||
649 | struct smb_version_values smb1_values = { | 975 | struct smb_version_values smb1_values = { |
diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c new file mode 100644 index 000000000000..a93eec30a50d --- /dev/null +++ b/fs/cifs/smb2file.c | |||
@@ -0,0 +1,302 @@ | |||
1 | /* | ||
2 | * fs/cifs/smb2file.c | ||
3 | * | ||
4 | * Copyright (C) International Business Machines Corp., 2002, 2011 | ||
5 | * Author(s): Steve French (sfrench@us.ibm.com), | ||
6 | * Pavel Shilovsky ((pshilovsky@samba.org) 2012 | ||
7 | * | ||
8 | * This library is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU Lesser General Public License as published | ||
10 | * by the Free Software Foundation; either version 2.1 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This library is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
16 | * the GNU Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public License | ||
19 | * along with this library; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | #include <linux/fs.h> | ||
23 | #include <linux/stat.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/pagemap.h> | ||
26 | #include <asm/div64.h> | ||
27 | #include "cifsfs.h" | ||
28 | #include "cifspdu.h" | ||
29 | #include "cifsglob.h" | ||
30 | #include "cifsproto.h" | ||
31 | #include "cifs_debug.h" | ||
32 | #include "cifs_fs_sb.h" | ||
33 | #include "cifs_unicode.h" | ||
34 | #include "fscache.h" | ||
35 | #include "smb2proto.h" | ||
36 | |||
37 | void | ||
38 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock) | ||
39 | { | ||
40 | oplock &= 0xFF; | ||
41 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) | ||
42 | return; | ||
43 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { | ||
44 | cinode->clientCanCacheAll = true; | ||
45 | cinode->clientCanCacheRead = true; | ||
46 | cFYI(1, "Exclusive Oplock granted on inode %p", | ||
47 | &cinode->vfs_inode); | ||
48 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { | ||
49 | cinode->clientCanCacheAll = false; | ||
50 | cinode->clientCanCacheRead = true; | ||
51 | cFYI(1, "Level II Oplock granted on inode %p", | ||
52 | &cinode->vfs_inode); | ||
53 | } else { | ||
54 | cinode->clientCanCacheAll = false; | ||
55 | cinode->clientCanCacheRead = false; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | int | ||
60 | smb2_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path, | ||
61 | int disposition, int desired_access, int create_options, | ||
62 | struct cifs_fid *fid, __u32 *oplock, FILE_ALL_INFO *buf, | ||
63 | struct cifs_sb_info *cifs_sb) | ||
64 | { | ||
65 | int rc; | ||
66 | __le16 *smb2_path; | ||
67 | struct smb2_file_all_info *smb2_data = NULL; | ||
68 | __u8 smb2_oplock[17]; | ||
69 | |||
70 | smb2_path = cifs_convert_path_to_utf16(path, cifs_sb); | ||
71 | if (smb2_path == NULL) { | ||
72 | rc = -ENOMEM; | ||
73 | goto out; | ||
74 | } | ||
75 | |||
76 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | ||
77 | GFP_KERNEL); | ||
78 | if (smb2_data == NULL) { | ||
79 | rc = -ENOMEM; | ||
80 | goto out; | ||
81 | } | ||
82 | |||
83 | desired_access |= FILE_READ_ATTRIBUTES; | ||
84 | *smb2_oplock = SMB2_OPLOCK_LEVEL_EXCLUSIVE; | ||
85 | |||
86 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) | ||
87 | memcpy(smb2_oplock + 1, fid->lease_key, SMB2_LEASE_KEY_SIZE); | ||
88 | |||
89 | rc = SMB2_open(xid, tcon, smb2_path, &fid->persistent_fid, | ||
90 | &fid->volatile_fid, desired_access, disposition, | ||
91 | 0, 0, smb2_oplock, smb2_data); | ||
92 | if (rc) | ||
93 | goto out; | ||
94 | |||
95 | if (buf) { | ||
96 | /* open response does not have IndexNumber field - get it */ | ||
97 | rc = SMB2_get_srv_num(xid, tcon, fid->persistent_fid, | ||
98 | fid->volatile_fid, | ||
99 | &smb2_data->IndexNumber); | ||
100 | if (rc) { | ||
101 | /* let get_inode_info disable server inode numbers */ | ||
102 | smb2_data->IndexNumber = 0; | ||
103 | rc = 0; | ||
104 | } | ||
105 | move_smb2_info_to_cifs(buf, smb2_data); | ||
106 | } | ||
107 | |||
108 | *oplock = *smb2_oplock; | ||
109 | out: | ||
110 | kfree(smb2_data); | ||
111 | kfree(smb2_path); | ||
112 | return rc; | ||
113 | } | ||
114 | |||
115 | int | ||
116 | smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | ||
117 | const unsigned int xid) | ||
118 | { | ||
119 | int rc = 0, stored_rc; | ||
120 | unsigned int max_num, num = 0, max_buf; | ||
121 | struct smb2_lock_element *buf, *cur; | ||
122 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | ||
123 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | ||
124 | struct cifsLockInfo *li, *tmp; | ||
125 | __u64 length = 1 + flock->fl_end - flock->fl_start; | ||
126 | struct list_head tmp_llist; | ||
127 | |||
128 | INIT_LIST_HEAD(&tmp_llist); | ||
129 | |||
130 | /* | ||
131 | * Accessing maxBuf is racy with cifs_reconnect - need to store value | ||
132 | * and check it for zero before using. | ||
133 | */ | ||
134 | max_buf = tcon->ses->server->maxBuf; | ||
135 | if (!max_buf) | ||
136 | return -EINVAL; | ||
137 | |||
138 | max_num = max_buf / sizeof(struct smb2_lock_element); | ||
139 | buf = kzalloc(max_num * sizeof(struct smb2_lock_element), GFP_KERNEL); | ||
140 | if (!buf) | ||
141 | return -ENOMEM; | ||
142 | |||
143 | cur = buf; | ||
144 | |||
145 | down_write(&cinode->lock_sem); | ||
146 | list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { | ||
147 | if (flock->fl_start > li->offset || | ||
148 | (flock->fl_start + length) < | ||
149 | (li->offset + li->length)) | ||
150 | continue; | ||
151 | if (current->tgid != li->pid) | ||
152 | continue; | ||
153 | if (cinode->can_cache_brlcks) { | ||
154 | /* | ||
155 | * We can cache brlock requests - simply remove a lock | ||
156 | * from the file's list. | ||
157 | */ | ||
158 | list_del(&li->llist); | ||
159 | cifs_del_lock_waiters(li); | ||
160 | kfree(li); | ||
161 | continue; | ||
162 | } | ||
163 | cur->Length = cpu_to_le64(li->length); | ||
164 | cur->Offset = cpu_to_le64(li->offset); | ||
165 | cur->Flags = cpu_to_le32(SMB2_LOCKFLAG_UNLOCK); | ||
166 | /* | ||
167 | * We need to save a lock here to let us add it again to the | ||
168 | * file's list if the unlock range request fails on the server. | ||
169 | */ | ||
170 | list_move(&li->llist, &tmp_llist); | ||
171 | if (++num == max_num) { | ||
172 | stored_rc = smb2_lockv(xid, tcon, | ||
173 | cfile->fid.persistent_fid, | ||
174 | cfile->fid.volatile_fid, | ||
175 | current->tgid, num, buf); | ||
176 | if (stored_rc) { | ||
177 | /* | ||
178 | * We failed on the unlock range request - add | ||
179 | * all locks from the tmp list to the head of | ||
180 | * the file's list. | ||
181 | */ | ||
182 | cifs_move_llist(&tmp_llist, | ||
183 | &cfile->llist->locks); | ||
184 | rc = stored_rc; | ||
185 | } else | ||
186 | /* | ||
187 | * The unlock range request succeed - free the | ||
188 | * tmp list. | ||
189 | */ | ||
190 | cifs_free_llist(&tmp_llist); | ||
191 | cur = buf; | ||
192 | num = 0; | ||
193 | } else | ||
194 | cur++; | ||
195 | } | ||
196 | if (num) { | ||
197 | stored_rc = smb2_lockv(xid, tcon, cfile->fid.persistent_fid, | ||
198 | cfile->fid.volatile_fid, current->tgid, | ||
199 | num, buf); | ||
200 | if (stored_rc) { | ||
201 | cifs_move_llist(&tmp_llist, &cfile->llist->locks); | ||
202 | rc = stored_rc; | ||
203 | } else | ||
204 | cifs_free_llist(&tmp_llist); | ||
205 | } | ||
206 | up_write(&cinode->lock_sem); | ||
207 | |||
208 | kfree(buf); | ||
209 | return rc; | ||
210 | } | ||
211 | |||
212 | static int | ||
213 | smb2_push_mand_fdlocks(struct cifs_fid_locks *fdlocks, const unsigned int xid, | ||
214 | struct smb2_lock_element *buf, unsigned int max_num) | ||
215 | { | ||
216 | int rc = 0, stored_rc; | ||
217 | struct cifsFileInfo *cfile = fdlocks->cfile; | ||
218 | struct cifsLockInfo *li; | ||
219 | unsigned int num = 0; | ||
220 | struct smb2_lock_element *cur = buf; | ||
221 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | ||
222 | |||
223 | list_for_each_entry(li, &fdlocks->locks, llist) { | ||
224 | cur->Length = cpu_to_le64(li->length); | ||
225 | cur->Offset = cpu_to_le64(li->offset); | ||
226 | cur->Flags = cpu_to_le32(li->type | | ||
227 | SMB2_LOCKFLAG_FAIL_IMMEDIATELY); | ||
228 | if (++num == max_num) { | ||
229 | stored_rc = smb2_lockv(xid, tcon, | ||
230 | cfile->fid.persistent_fid, | ||
231 | cfile->fid.volatile_fid, | ||
232 | current->tgid, num, buf); | ||
233 | if (stored_rc) | ||
234 | rc = stored_rc; | ||
235 | cur = buf; | ||
236 | num = 0; | ||
237 | } else | ||
238 | cur++; | ||
239 | } | ||
240 | if (num) { | ||
241 | stored_rc = smb2_lockv(xid, tcon, | ||
242 | cfile->fid.persistent_fid, | ||
243 | cfile->fid.volatile_fid, | ||
244 | current->tgid, num, buf); | ||
245 | if (stored_rc) | ||
246 | rc = stored_rc; | ||
247 | } | ||
248 | |||
249 | return rc; | ||
250 | } | ||
251 | |||
252 | int | ||
253 | smb2_push_mandatory_locks(struct cifsFileInfo *cfile) | ||
254 | { | ||
255 | int rc = 0, stored_rc; | ||
256 | unsigned int xid; | ||
257 | unsigned int max_num, max_buf; | ||
258 | struct smb2_lock_element *buf; | ||
259 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | ||
260 | struct cifs_fid_locks *fdlocks; | ||
261 | |||
262 | xid = get_xid(); | ||
263 | /* we are going to update can_cache_brlcks here - need a write access */ | ||
264 | down_write(&cinode->lock_sem); | ||
265 | if (!cinode->can_cache_brlcks) { | ||
266 | up_write(&cinode->lock_sem); | ||
267 | free_xid(xid); | ||
268 | return rc; | ||
269 | } | ||
270 | |||
271 | /* | ||
272 | * Accessing maxBuf is racy with cifs_reconnect - need to store value | ||
273 | * and check it for zero before using. | ||
274 | */ | ||
275 | max_buf = tlink_tcon(cfile->tlink)->ses->server->maxBuf; | ||
276 | if (!max_buf) { | ||
277 | up_write(&cinode->lock_sem); | ||
278 | free_xid(xid); | ||
279 | return -EINVAL; | ||
280 | } | ||
281 | |||
282 | max_num = max_buf / sizeof(struct smb2_lock_element); | ||
283 | buf = kzalloc(max_num * sizeof(struct smb2_lock_element), GFP_KERNEL); | ||
284 | if (!buf) { | ||
285 | up_write(&cinode->lock_sem); | ||
286 | free_xid(xid); | ||
287 | return -ENOMEM; | ||
288 | } | ||
289 | |||
290 | list_for_each_entry(fdlocks, &cinode->llist, llist) { | ||
291 | stored_rc = smb2_push_mand_fdlocks(fdlocks, xid, buf, max_num); | ||
292 | if (stored_rc) | ||
293 | rc = stored_rc; | ||
294 | } | ||
295 | |||
296 | cinode->can_cache_brlcks = false; | ||
297 | kfree(buf); | ||
298 | |||
299 | up_write(&cinode->lock_sem); | ||
300 | free_xid(xid); | ||
301 | return rc; | ||
302 | } | ||
diff --git a/fs/cifs/smb2glob.h b/fs/cifs/smb2glob.h index 33c1d89090c0..7c0e2143e775 100644 --- a/fs/cifs/smb2glob.h +++ b/fs/cifs/smb2glob.h | |||
@@ -23,6 +23,8 @@ | |||
23 | #ifndef _SMB2_GLOB_H | 23 | #ifndef _SMB2_GLOB_H |
24 | #define _SMB2_GLOB_H | 24 | #define _SMB2_GLOB_H |
25 | 25 | ||
26 | #define SMB2_MAGIC_NUMBER 0xFE534D42 | ||
27 | |||
26 | /* | 28 | /* |
27 | ***************************************************************** | 29 | ***************************************************************** |
28 | * Constants go here | 30 | * Constants go here |
@@ -40,5 +42,17 @@ | |||
40 | #define SMB2_OP_MKDIR 5 | 42 | #define SMB2_OP_MKDIR 5 |
41 | #define SMB2_OP_RENAME 6 | 43 | #define SMB2_OP_RENAME 6 |
42 | #define SMB2_OP_DELETE 7 | 44 | #define SMB2_OP_DELETE 7 |
45 | #define SMB2_OP_HARDLINK 8 | ||
46 | #define SMB2_OP_SET_EOF 9 | ||
47 | |||
48 | /* Used when constructing chained read requests. */ | ||
49 | #define CHAINED_REQUEST 1 | ||
50 | #define START_OF_CHAIN 2 | ||
51 | #define END_OF_CHAIN 4 | ||
52 | #define RELATED_REQUEST 8 | ||
53 | |||
54 | #define SMB2_SIGNATURE_SIZE (16) | ||
55 | #define SMB2_NTLMV2_SESSKEY_SIZE (16) | ||
56 | #define SMB2_HMACSHA256_SIZE (32) | ||
43 | 57 | ||
44 | #endif /* _SMB2_GLOB_H */ | 58 | #endif /* _SMB2_GLOB_H */ |
diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c index 2aa5cb08c526..706482452df4 100644 --- a/fs/cifs/smb2inode.c +++ b/fs/cifs/smb2inode.c | |||
@@ -47,6 +47,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
47 | int rc, tmprc = 0; | 47 | int rc, tmprc = 0; |
48 | u64 persistent_fid, volatile_fid; | 48 | u64 persistent_fid, volatile_fid; |
49 | __le16 *utf16_path; | 49 | __le16 *utf16_path; |
50 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | ||
50 | 51 | ||
51 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | 52 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
52 | if (!utf16_path) | 53 | if (!utf16_path) |
@@ -54,7 +55,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
54 | 55 | ||
55 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, | 56 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, |
56 | desired_access, create_disposition, file_attributes, | 57 | desired_access, create_disposition, file_attributes, |
57 | create_options); | 58 | create_options, &oplock, NULL); |
58 | if (rc) { | 59 | if (rc) { |
59 | kfree(utf16_path); | 60 | kfree(utf16_path); |
60 | return rc; | 61 | return rc; |
@@ -74,6 +75,22 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
74 | * SMB2_open() call. | 75 | * SMB2_open() call. |
75 | */ | 76 | */ |
76 | break; | 77 | break; |
78 | case SMB2_OP_RENAME: | ||
79 | tmprc = SMB2_rename(xid, tcon, persistent_fid, volatile_fid, | ||
80 | (__le16 *)data); | ||
81 | break; | ||
82 | case SMB2_OP_HARDLINK: | ||
83 | tmprc = SMB2_set_hardlink(xid, tcon, persistent_fid, | ||
84 | volatile_fid, (__le16 *)data); | ||
85 | break; | ||
86 | case SMB2_OP_SET_EOF: | ||
87 | tmprc = SMB2_set_eof(xid, tcon, persistent_fid, volatile_fid, | ||
88 | current->tgid, (__le64 *)data); | ||
89 | break; | ||
90 | case SMB2_OP_SET_INFO: | ||
91 | tmprc = SMB2_set_info(xid, tcon, persistent_fid, volatile_fid, | ||
92 | (FILE_BASIC_INFO *)data); | ||
93 | break; | ||
77 | default: | 94 | default: |
78 | cERROR(1, "Invalid command"); | 95 | cERROR(1, "Invalid command"); |
79 | break; | 96 | break; |
@@ -86,7 +103,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
86 | return rc; | 103 | return rc; |
87 | } | 104 | } |
88 | 105 | ||
89 | static void | 106 | void |
90 | move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src) | 107 | move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src) |
91 | { | 108 | { |
92 | memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src); | 109 | memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src); |
@@ -161,3 +178,80 @@ smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, | |||
161 | 0, CREATE_NOT_FILE | CREATE_DELETE_ON_CLOSE, | 178 | 0, CREATE_NOT_FILE | CREATE_DELETE_ON_CLOSE, |
162 | NULL, SMB2_OP_DELETE); | 179 | NULL, SMB2_OP_DELETE); |
163 | } | 180 | } |
181 | |||
182 | int | ||
183 | smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, | ||
184 | struct cifs_sb_info *cifs_sb) | ||
185 | { | ||
186 | return smb2_open_op_close(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, | ||
187 | 0, CREATE_DELETE_ON_CLOSE, NULL, | ||
188 | SMB2_OP_DELETE); | ||
189 | } | ||
190 | |||
191 | static int | ||
192 | smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon, | ||
193 | const char *from_name, const char *to_name, | ||
194 | struct cifs_sb_info *cifs_sb, __u32 access, int command) | ||
195 | { | ||
196 | __le16 *smb2_to_name = NULL; | ||
197 | int rc; | ||
198 | |||
199 | smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb); | ||
200 | if (smb2_to_name == NULL) { | ||
201 | rc = -ENOMEM; | ||
202 | goto smb2_rename_path; | ||
203 | } | ||
204 | |||
205 | rc = smb2_open_op_close(xid, tcon, cifs_sb, from_name, access, | ||
206 | FILE_OPEN, 0, 0, smb2_to_name, command); | ||
207 | smb2_rename_path: | ||
208 | kfree(smb2_to_name); | ||
209 | return rc; | ||
210 | } | ||
211 | |||
212 | int | ||
213 | smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon, | ||
214 | const char *from_name, const char *to_name, | ||
215 | struct cifs_sb_info *cifs_sb) | ||
216 | { | ||
217 | return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, | ||
218 | DELETE, SMB2_OP_RENAME); | ||
219 | } | ||
220 | |||
221 | int | ||
222 | smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon, | ||
223 | const char *from_name, const char *to_name, | ||
224 | struct cifs_sb_info *cifs_sb) | ||
225 | { | ||
226 | return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, | ||
227 | FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK); | ||
228 | } | ||
229 | |||
230 | int | ||
231 | smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, | ||
232 | const char *full_path, __u64 size, | ||
233 | struct cifs_sb_info *cifs_sb, bool set_alloc) | ||
234 | { | ||
235 | __le64 eof = cpu_to_le64(size); | ||
236 | return smb2_open_op_close(xid, tcon, cifs_sb, full_path, | ||
237 | FILE_WRITE_DATA, FILE_OPEN, 0, 0, &eof, | ||
238 | SMB2_OP_SET_EOF); | ||
239 | } | ||
240 | |||
241 | int | ||
242 | smb2_set_file_info(struct inode *inode, const char *full_path, | ||
243 | FILE_BASIC_INFO *buf, const unsigned int xid) | ||
244 | { | ||
245 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | ||
246 | struct tcon_link *tlink; | ||
247 | int rc; | ||
248 | |||
249 | tlink = cifs_sb_tlink(cifs_sb); | ||
250 | if (IS_ERR(tlink)) | ||
251 | return PTR_ERR(tlink); | ||
252 | rc = smb2_open_op_close(xid, tlink_tcon(tlink), cifs_sb, full_path, | ||
253 | FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, 0, buf, | ||
254 | SMB2_OP_SET_INFO); | ||
255 | cifs_put_tlink(tlink); | ||
256 | return rc; | ||
257 | } | ||
diff --git a/fs/cifs/smb2maperror.c b/fs/cifs/smb2maperror.c index be41478acc05..494c912c76fe 100644 --- a/fs/cifs/smb2maperror.c +++ b/fs/cifs/smb2maperror.c | |||
@@ -453,7 +453,8 @@ static const struct status_to_posix_error smb2_error_map_table[] = { | |||
453 | {STATUS_FILE_INVALID, -EIO, "STATUS_FILE_INVALID"}, | 453 | {STATUS_FILE_INVALID, -EIO, "STATUS_FILE_INVALID"}, |
454 | {STATUS_ALLOTTED_SPACE_EXCEEDED, -EIO, | 454 | {STATUS_ALLOTTED_SPACE_EXCEEDED, -EIO, |
455 | "STATUS_ALLOTTED_SPACE_EXCEEDED"}, | 455 | "STATUS_ALLOTTED_SPACE_EXCEEDED"}, |
456 | {STATUS_INSUFFICIENT_RESOURCES, -EIO, "STATUS_INSUFFICIENT_RESOURCES"}, | 456 | {STATUS_INSUFFICIENT_RESOURCES, -EREMOTEIO, |
457 | "STATUS_INSUFFICIENT_RESOURCES"}, | ||
457 | {STATUS_DFS_EXIT_PATH_FOUND, -EIO, "STATUS_DFS_EXIT_PATH_FOUND"}, | 458 | {STATUS_DFS_EXIT_PATH_FOUND, -EIO, "STATUS_DFS_EXIT_PATH_FOUND"}, |
458 | {STATUS_DEVICE_DATA_ERROR, -EIO, "STATUS_DEVICE_DATA_ERROR"}, | 459 | {STATUS_DEVICE_DATA_ERROR, -EIO, "STATUS_DEVICE_DATA_ERROR"}, |
459 | {STATUS_DEVICE_NOT_CONNECTED, -EIO, "STATUS_DEVICE_NOT_CONNECTED"}, | 460 | {STATUS_DEVICE_NOT_CONNECTED, -EIO, "STATUS_DEVICE_NOT_CONNECTED"}, |
@@ -2455,7 +2456,8 @@ map_smb2_to_linux_error(char *buf, bool log_err) | |||
2455 | return 0; | 2456 | return 0; |
2456 | 2457 | ||
2457 | /* mask facility */ | 2458 | /* mask facility */ |
2458 | if (log_err && (smb2err != (STATUS_MORE_PROCESSING_REQUIRED))) | 2459 | if (log_err && (smb2err != STATUS_MORE_PROCESSING_REQUIRED) && |
2460 | (smb2err != STATUS_END_OF_FILE)) | ||
2459 | smb2_print_status(smb2err); | 2461 | smb2_print_status(smb2err); |
2460 | else if (cifsFYI & CIFS_RC) | 2462 | else if (cifsFYI & CIFS_RC) |
2461 | smb2_print_status(smb2err); | 2463 | smb2_print_status(smb2err); |
diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c index e4d3b9964167..7b1c5e3287fb 100644 --- a/fs/cifs/smb2misc.c +++ b/fs/cifs/smb2misc.c | |||
@@ -142,12 +142,19 @@ smb2_check_message(char *buf, unsigned int length) | |||
142 | } | 142 | } |
143 | 143 | ||
144 | if (smb2_rsp_struct_sizes[command] != pdu->StructureSize2) { | 144 | if (smb2_rsp_struct_sizes[command] != pdu->StructureSize2) { |
145 | if (hdr->Status == 0 || | 145 | if (command != SMB2_OPLOCK_BREAK_HE && (hdr->Status == 0 || |
146 | pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2) { | 146 | pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2)) { |
147 | /* error packets have 9 byte structure size */ | 147 | /* error packets have 9 byte structure size */ |
148 | cERROR(1, "Illegal response size %u for command %d", | 148 | cERROR(1, "Illegal response size %u for command %d", |
149 | le16_to_cpu(pdu->StructureSize2), command); | 149 | le16_to_cpu(pdu->StructureSize2), command); |
150 | return 1; | 150 | return 1; |
151 | } else if (command == SMB2_OPLOCK_BREAK_HE && (hdr->Status == 0) | ||
152 | && (le16_to_cpu(pdu->StructureSize2) != 44) | ||
153 | && (le16_to_cpu(pdu->StructureSize2) != 36)) { | ||
154 | /* special case for SMB2.1 lease break message */ | ||
155 | cERROR(1, "Illegal response size %d for oplock break", | ||
156 | le16_to_cpu(pdu->StructureSize2)); | ||
157 | return 1; | ||
151 | } | 158 | } |
152 | } | 159 | } |
153 | 160 | ||
@@ -162,6 +169,9 @@ smb2_check_message(char *buf, unsigned int length) | |||
162 | if (4 + len != clc_len) { | 169 | if (4 + len != clc_len) { |
163 | cFYI(1, "Calculated size %u length %u mismatch mid %llu", | 170 | cFYI(1, "Calculated size %u length %u mismatch mid %llu", |
164 | clc_len, 4 + len, mid); | 171 | clc_len, 4 + len, mid); |
172 | /* Windows 7 server returns 24 bytes more */ | ||
173 | if (clc_len + 20 == len && command == SMB2_OPLOCK_BREAK_HE) | ||
174 | return 0; | ||
165 | /* server can return one byte more */ | 175 | /* server can return one byte more */ |
166 | if (clc_len == 4 + len + 1) | 176 | if (clc_len == 4 + len + 1) |
167 | return 0; | 177 | return 0; |
@@ -244,7 +254,15 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr) | |||
244 | ((struct smb2_query_info_rsp *)hdr)->OutputBufferLength); | 254 | ((struct smb2_query_info_rsp *)hdr)->OutputBufferLength); |
245 | break; | 255 | break; |
246 | case SMB2_READ: | 256 | case SMB2_READ: |
257 | *off = ((struct smb2_read_rsp *)hdr)->DataOffset; | ||
258 | *len = le32_to_cpu(((struct smb2_read_rsp *)hdr)->DataLength); | ||
259 | break; | ||
247 | case SMB2_QUERY_DIRECTORY: | 260 | case SMB2_QUERY_DIRECTORY: |
261 | *off = le16_to_cpu( | ||
262 | ((struct smb2_query_directory_rsp *)hdr)->OutputBufferOffset); | ||
263 | *len = le32_to_cpu( | ||
264 | ((struct smb2_query_directory_rsp *)hdr)->OutputBufferLength); | ||
265 | break; | ||
248 | case SMB2_IOCTL: | 266 | case SMB2_IOCTL: |
249 | case SMB2_CHANGE_NOTIFY: | 267 | case SMB2_CHANGE_NOTIFY: |
250 | default: | 268 | default: |
@@ -287,8 +305,9 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr) | |||
287 | * portion, the number of word parameters and the data portion of the message. | 305 | * portion, the number of word parameters and the data portion of the message. |
288 | */ | 306 | */ |
289 | unsigned int | 307 | unsigned int |
290 | smb2_calc_size(struct smb2_hdr *hdr) | 308 | smb2_calc_size(void *buf) |
291 | { | 309 | { |
310 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; | ||
292 | struct smb2_pdu *pdu = (struct smb2_pdu *)hdr; | 311 | struct smb2_pdu *pdu = (struct smb2_pdu *)hdr; |
293 | int offset; /* the offset from the beginning of SMB to data area */ | 312 | int offset; /* the offset from the beginning of SMB to data area */ |
294 | int data_length; /* the length of the variable length data area */ | 313 | int data_length; /* the length of the variable length data area */ |
@@ -347,3 +366,218 @@ cifs_convert_path_to_utf16(const char *from, struct cifs_sb_info *cifs_sb) | |||
347 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 366 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
348 | return to; | 367 | return to; |
349 | } | 368 | } |
369 | |||
370 | __le32 | ||
371 | smb2_get_lease_state(struct cifsInodeInfo *cinode) | ||
372 | { | ||
373 | if (cinode->clientCanCacheAll) | ||
374 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; | ||
375 | else if (cinode->clientCanCacheRead) | ||
376 | return SMB2_LEASE_READ_CACHING; | ||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | __u8 smb2_map_lease_to_oplock(__le32 lease_state) | ||
381 | { | ||
382 | if (lease_state & SMB2_LEASE_WRITE_CACHING) { | ||
383 | if (lease_state & SMB2_LEASE_HANDLE_CACHING) | ||
384 | return SMB2_OPLOCK_LEVEL_BATCH; | ||
385 | else | ||
386 | return SMB2_OPLOCK_LEVEL_EXCLUSIVE; | ||
387 | } else if (lease_state & SMB2_LEASE_READ_CACHING) | ||
388 | return SMB2_OPLOCK_LEVEL_II; | ||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | struct smb2_lease_break_work { | ||
393 | struct work_struct lease_break; | ||
394 | struct tcon_link *tlink; | ||
395 | __u8 lease_key[16]; | ||
396 | __le32 lease_state; | ||
397 | }; | ||
398 | |||
399 | static void | ||
400 | cifs_ses_oplock_break(struct work_struct *work) | ||
401 | { | ||
402 | struct smb2_lease_break_work *lw = container_of(work, | ||
403 | struct smb2_lease_break_work, lease_break); | ||
404 | int rc; | ||
405 | |||
406 | rc = SMB2_lease_break(0, tlink_tcon(lw->tlink), lw->lease_key, | ||
407 | lw->lease_state); | ||
408 | cFYI(1, "Lease release rc %d", rc); | ||
409 | cifs_put_tlink(lw->tlink); | ||
410 | kfree(lw); | ||
411 | } | ||
412 | |||
413 | static bool | ||
414 | smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server) | ||
415 | { | ||
416 | struct smb2_lease_break *rsp = (struct smb2_lease_break *)buffer; | ||
417 | struct list_head *tmp, *tmp1, *tmp2; | ||
418 | struct cifs_ses *ses; | ||
419 | struct cifs_tcon *tcon; | ||
420 | struct cifsInodeInfo *cinode; | ||
421 | struct cifsFileInfo *cfile; | ||
422 | struct cifs_pending_open *open; | ||
423 | struct smb2_lease_break_work *lw; | ||
424 | bool found; | ||
425 | int ack_req = le32_to_cpu(rsp->Flags & | ||
426 | SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED); | ||
427 | |||
428 | lw = kmalloc(sizeof(struct smb2_lease_break_work), GFP_KERNEL); | ||
429 | if (!lw) { | ||
430 | cERROR(1, "Memory allocation failed during lease break check"); | ||
431 | return false; | ||
432 | } | ||
433 | |||
434 | INIT_WORK(&lw->lease_break, cifs_ses_oplock_break); | ||
435 | lw->lease_state = rsp->NewLeaseState; | ||
436 | |||
437 | cFYI(1, "Checking for lease break"); | ||
438 | |||
439 | /* look up tcon based on tid & uid */ | ||
440 | spin_lock(&cifs_tcp_ses_lock); | ||
441 | list_for_each(tmp, &server->smb_ses_list) { | ||
442 | ses = list_entry(tmp, struct cifs_ses, smb_ses_list); | ||
443 | |||
444 | spin_lock(&cifs_file_list_lock); | ||
445 | list_for_each(tmp1, &ses->tcon_list) { | ||
446 | tcon = list_entry(tmp1, struct cifs_tcon, tcon_list); | ||
447 | |||
448 | cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks); | ||
449 | list_for_each(tmp2, &tcon->openFileList) { | ||
450 | cfile = list_entry(tmp2, struct cifsFileInfo, | ||
451 | tlist); | ||
452 | cinode = CIFS_I(cfile->dentry->d_inode); | ||
453 | |||
454 | if (memcmp(cinode->lease_key, rsp->LeaseKey, | ||
455 | SMB2_LEASE_KEY_SIZE)) | ||
456 | continue; | ||
457 | |||
458 | cFYI(1, "found in the open list"); | ||
459 | cFYI(1, "lease key match, lease break 0x%d", | ||
460 | le32_to_cpu(rsp->NewLeaseState)); | ||
461 | |||
462 | smb2_set_oplock_level(cinode, | ||
463 | smb2_map_lease_to_oplock(rsp->NewLeaseState)); | ||
464 | |||
465 | if (ack_req) | ||
466 | cfile->oplock_break_cancelled = false; | ||
467 | else | ||
468 | cfile->oplock_break_cancelled = true; | ||
469 | |||
470 | queue_work(cifsiod_wq, &cfile->oplock_break); | ||
471 | |||
472 | spin_unlock(&cifs_file_list_lock); | ||
473 | spin_unlock(&cifs_tcp_ses_lock); | ||
474 | return true; | ||
475 | } | ||
476 | |||
477 | found = false; | ||
478 | list_for_each_entry(open, &tcon->pending_opens, olist) { | ||
479 | if (memcmp(open->lease_key, rsp->LeaseKey, | ||
480 | SMB2_LEASE_KEY_SIZE)) | ||
481 | continue; | ||
482 | |||
483 | if (!found && ack_req) { | ||
484 | found = true; | ||
485 | memcpy(lw->lease_key, open->lease_key, | ||
486 | SMB2_LEASE_KEY_SIZE); | ||
487 | lw->tlink = cifs_get_tlink(open->tlink); | ||
488 | queue_work(cifsiod_wq, | ||
489 | &lw->lease_break); | ||
490 | } | ||
491 | |||
492 | cFYI(1, "found in the pending open list"); | ||
493 | cFYI(1, "lease key match, lease break 0x%d", | ||
494 | le32_to_cpu(rsp->NewLeaseState)); | ||
495 | |||
496 | open->oplock = | ||
497 | smb2_map_lease_to_oplock(rsp->NewLeaseState); | ||
498 | } | ||
499 | if (found) { | ||
500 | spin_unlock(&cifs_file_list_lock); | ||
501 | spin_unlock(&cifs_tcp_ses_lock); | ||
502 | return true; | ||
503 | } | ||
504 | } | ||
505 | spin_unlock(&cifs_file_list_lock); | ||
506 | } | ||
507 | spin_unlock(&cifs_tcp_ses_lock); | ||
508 | kfree(lw); | ||
509 | cFYI(1, "Can not process lease break - no lease matched"); | ||
510 | return false; | ||
511 | } | ||
512 | |||
513 | bool | ||
514 | smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server) | ||
515 | { | ||
516 | struct smb2_oplock_break *rsp = (struct smb2_oplock_break *)buffer; | ||
517 | struct list_head *tmp, *tmp1, *tmp2; | ||
518 | struct cifs_ses *ses; | ||
519 | struct cifs_tcon *tcon; | ||
520 | struct cifsInodeInfo *cinode; | ||
521 | struct cifsFileInfo *cfile; | ||
522 | |||
523 | cFYI(1, "Checking for oplock break"); | ||
524 | |||
525 | if (rsp->hdr.Command != SMB2_OPLOCK_BREAK) | ||
526 | return false; | ||
527 | |||
528 | if (rsp->StructureSize != | ||
529 | smb2_rsp_struct_sizes[SMB2_OPLOCK_BREAK_HE]) { | ||
530 | if (le16_to_cpu(rsp->StructureSize) == 44) | ||
531 | return smb2_is_valid_lease_break(buffer, server); | ||
532 | else | ||
533 | return false; | ||
534 | } | ||
535 | |||
536 | cFYI(1, "oplock level 0x%d", rsp->OplockLevel); | ||
537 | |||
538 | /* look up tcon based on tid & uid */ | ||
539 | spin_lock(&cifs_tcp_ses_lock); | ||
540 | list_for_each(tmp, &server->smb_ses_list) { | ||
541 | ses = list_entry(tmp, struct cifs_ses, smb_ses_list); | ||
542 | list_for_each(tmp1, &ses->tcon_list) { | ||
543 | tcon = list_entry(tmp1, struct cifs_tcon, tcon_list); | ||
544 | |||
545 | cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks); | ||
546 | spin_lock(&cifs_file_list_lock); | ||
547 | list_for_each(tmp2, &tcon->openFileList) { | ||
548 | cfile = list_entry(tmp2, struct cifsFileInfo, | ||
549 | tlist); | ||
550 | if (rsp->PersistentFid != | ||
551 | cfile->fid.persistent_fid || | ||
552 | rsp->VolatileFid != | ||
553 | cfile->fid.volatile_fid) | ||
554 | continue; | ||
555 | |||
556 | cFYI(1, "file id match, oplock break"); | ||
557 | cinode = CIFS_I(cfile->dentry->d_inode); | ||
558 | |||
559 | if (!cinode->clientCanCacheAll && | ||
560 | rsp->OplockLevel == SMB2_OPLOCK_LEVEL_NONE) | ||
561 | cfile->oplock_break_cancelled = true; | ||
562 | else | ||
563 | cfile->oplock_break_cancelled = false; | ||
564 | |||
565 | smb2_set_oplock_level(cinode, | ||
566 | rsp->OplockLevel ? SMB2_OPLOCK_LEVEL_II : 0); | ||
567 | |||
568 | queue_work(cifsiod_wq, &cfile->oplock_break); | ||
569 | |||
570 | spin_unlock(&cifs_file_list_lock); | ||
571 | spin_unlock(&cifs_tcp_ses_lock); | ||
572 | return true; | ||
573 | } | ||
574 | spin_unlock(&cifs_file_list_lock); | ||
575 | spin_unlock(&cifs_tcp_ses_lock); | ||
576 | cFYI(1, "No matching file for oplock break"); | ||
577 | return true; | ||
578 | } | ||
579 | } | ||
580 | spin_unlock(&cifs_tcp_ses_lock); | ||
581 | cFYI(1, "Can not process oplock break for non-existent connection"); | ||
582 | return false; | ||
583 | } | ||
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 826209bf3684..4d9dbe0b7385 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c | |||
@@ -17,11 +17,15 @@ | |||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/pagemap.h> | ||
21 | #include <linux/vfs.h> | ||
20 | #include "cifsglob.h" | 22 | #include "cifsglob.h" |
21 | #include "smb2pdu.h" | 23 | #include "smb2pdu.h" |
22 | #include "smb2proto.h" | 24 | #include "smb2proto.h" |
23 | #include "cifsproto.h" | 25 | #include "cifsproto.h" |
24 | #include "cifs_debug.h" | 26 | #include "cifs_debug.h" |
27 | #include "smb2status.h" | ||
28 | #include "smb2glob.h" | ||
25 | 29 | ||
26 | static int | 30 | static int |
27 | change_conf(struct TCP_Server_Info *server) | 31 | change_conf(struct TCP_Server_Info *server) |
@@ -63,6 +67,17 @@ smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, | |||
63 | server->in_flight--; | 67 | server->in_flight--; |
64 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) | 68 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) |
65 | rc = change_conf(server); | 69 | rc = change_conf(server); |
70 | /* | ||
71 | * Sometimes server returns 0 credits on oplock break ack - we need to | ||
72 | * rebalance credits in this case. | ||
73 | */ | ||
74 | else if (server->in_flight > 0 && server->oplock_credits == 0 && | ||
75 | server->oplocks) { | ||
76 | if (server->credits > 1) { | ||
77 | server->credits--; | ||
78 | server->oplock_credits++; | ||
79 | } | ||
80 | } | ||
66 | spin_unlock(&server->req_lock); | 81 | spin_unlock(&server->req_lock); |
67 | wake_up(&server->request_q); | 82 | wake_up(&server->request_q); |
68 | if (rc) | 83 | if (rc) |
@@ -157,6 +172,42 @@ smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
157 | return rc; | 172 | return rc; |
158 | } | 173 | } |
159 | 174 | ||
175 | static unsigned int | ||
176 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | ||
177 | { | ||
178 | struct TCP_Server_Info *server = tcon->ses->server; | ||
179 | unsigned int wsize; | ||
180 | |||
181 | /* start with specified wsize, or default */ | ||
182 | wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; | ||
183 | wsize = min_t(unsigned int, wsize, server->max_write); | ||
184 | /* | ||
185 | * limit write size to 2 ** 16, because we don't support multicredit | ||
186 | * requests now. | ||
187 | */ | ||
188 | wsize = min_t(unsigned int, wsize, 2 << 15); | ||
189 | |||
190 | return wsize; | ||
191 | } | ||
192 | |||
193 | static unsigned int | ||
194 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | ||
195 | { | ||
196 | struct TCP_Server_Info *server = tcon->ses->server; | ||
197 | unsigned int rsize; | ||
198 | |||
199 | /* start with specified rsize, or default */ | ||
200 | rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; | ||
201 | rsize = min_t(unsigned int, rsize, server->max_read); | ||
202 | /* | ||
203 | * limit write size to 2 ** 16, because we don't support multicredit | ||
204 | * requests now. | ||
205 | */ | ||
206 | rsize = min_t(unsigned int, rsize, 2 << 15); | ||
207 | |||
208 | return rsize; | ||
209 | } | ||
210 | |||
160 | static int | 211 | static int |
161 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, | 212 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, |
162 | struct cifs_sb_info *cifs_sb, const char *full_path) | 213 | struct cifs_sb_info *cifs_sb, const char *full_path) |
@@ -164,13 +215,14 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, | |||
164 | int rc; | 215 | int rc; |
165 | __u64 persistent_fid, volatile_fid; | 216 | __u64 persistent_fid, volatile_fid; |
166 | __le16 *utf16_path; | 217 | __le16 *utf16_path; |
218 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | ||
167 | 219 | ||
168 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | 220 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
169 | if (!utf16_path) | 221 | if (!utf16_path) |
170 | return -ENOMEM; | 222 | return -ENOMEM; |
171 | 223 | ||
172 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, | 224 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, |
173 | FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0); | 225 | FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL); |
174 | if (rc) { | 226 | if (rc) { |
175 | kfree(utf16_path); | 227 | kfree(utf16_path); |
176 | return rc; | 228 | return rc; |
@@ -190,6 +242,26 @@ smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, | |||
190 | return 0; | 242 | return 0; |
191 | } | 243 | } |
192 | 244 | ||
245 | static int | ||
246 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
247 | struct cifs_fid *fid, FILE_ALL_INFO *data) | ||
248 | { | ||
249 | int rc; | ||
250 | struct smb2_file_all_info *smb2_data; | ||
251 | |||
252 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | ||
253 | GFP_KERNEL); | ||
254 | if (smb2_data == NULL) | ||
255 | return -ENOMEM; | ||
256 | |||
257 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, | ||
258 | smb2_data); | ||
259 | if (!rc) | ||
260 | move_smb2_info_to_cifs(data, smb2_data); | ||
261 | kfree(smb2_data); | ||
262 | return rc; | ||
263 | } | ||
264 | |||
193 | static char * | 265 | static char * |
194 | smb2_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, | 266 | smb2_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, |
195 | struct cifs_tcon *tcon) | 267 | struct cifs_tcon *tcon) |
@@ -292,7 +364,221 @@ smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) | |||
292 | #endif | 364 | #endif |
293 | } | 365 | } |
294 | 366 | ||
367 | static void | ||
368 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) | ||
369 | { | ||
370 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | ||
371 | cfile->fid.persistent_fid = fid->persistent_fid; | ||
372 | cfile->fid.volatile_fid = fid->volatile_fid; | ||
373 | smb2_set_oplock_level(cinode, oplock); | ||
374 | cinode->can_cache_brlcks = cinode->clientCanCacheAll; | ||
375 | } | ||
376 | |||
377 | static void | ||
378 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, | ||
379 | struct cifs_fid *fid) | ||
380 | { | ||
381 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); | ||
382 | } | ||
383 | |||
384 | static int | ||
385 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, | ||
386 | struct cifs_fid *fid) | ||
387 | { | ||
388 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); | ||
389 | } | ||
390 | |||
391 | static unsigned int | ||
392 | smb2_read_data_offset(char *buf) | ||
393 | { | ||
394 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | ||
395 | return rsp->DataOffset; | ||
396 | } | ||
397 | |||
398 | static unsigned int | ||
399 | smb2_read_data_length(char *buf) | ||
400 | { | ||
401 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | ||
402 | return le32_to_cpu(rsp->DataLength); | ||
403 | } | ||
404 | |||
405 | |||
406 | static int | ||
407 | smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile, | ||
408 | struct cifs_io_parms *parms, unsigned int *bytes_read, | ||
409 | char **buf, int *buf_type) | ||
410 | { | ||
411 | parms->persistent_fid = cfile->fid.persistent_fid; | ||
412 | parms->volatile_fid = cfile->fid.volatile_fid; | ||
413 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); | ||
414 | } | ||
415 | |||
416 | static int | ||
417 | smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile, | ||
418 | struct cifs_io_parms *parms, unsigned int *written, | ||
419 | struct kvec *iov, unsigned long nr_segs) | ||
420 | { | ||
421 | |||
422 | parms->persistent_fid = cfile->fid.persistent_fid; | ||
423 | parms->volatile_fid = cfile->fid.volatile_fid; | ||
424 | return SMB2_write(xid, parms, written, iov, nr_segs); | ||
425 | } | ||
426 | |||
427 | static int | ||
428 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, | ||
429 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) | ||
430 | { | ||
431 | __le64 eof = cpu_to_le64(size); | ||
432 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, | ||
433 | cfile->fid.volatile_fid, cfile->pid, &eof); | ||
434 | } | ||
435 | |||
436 | static int | ||
437 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, | ||
438 | const char *path, struct cifs_sb_info *cifs_sb, | ||
439 | struct cifs_fid *fid, __u16 search_flags, | ||
440 | struct cifs_search_info *srch_inf) | ||
441 | { | ||
442 | __le16 *utf16_path; | ||
443 | int rc; | ||
444 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | ||
445 | __u64 persistent_fid, volatile_fid; | ||
446 | |||
447 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); | ||
448 | if (!utf16_path) | ||
449 | return -ENOMEM; | ||
450 | |||
451 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, | ||
452 | FILE_READ_ATTRIBUTES | FILE_READ_DATA, FILE_OPEN, 0, 0, | ||
453 | &oplock, NULL); | ||
454 | kfree(utf16_path); | ||
455 | if (rc) { | ||
456 | cERROR(1, "open dir failed"); | ||
457 | return rc; | ||
458 | } | ||
459 | |||
460 | srch_inf->entries_in_buffer = 0; | ||
461 | srch_inf->index_of_last_entry = 0; | ||
462 | fid->persistent_fid = persistent_fid; | ||
463 | fid->volatile_fid = volatile_fid; | ||
464 | |||
465 | rc = SMB2_query_directory(xid, tcon, persistent_fid, volatile_fid, 0, | ||
466 | srch_inf); | ||
467 | if (rc) { | ||
468 | cERROR(1, "query directory failed"); | ||
469 | SMB2_close(xid, tcon, persistent_fid, volatile_fid); | ||
470 | } | ||
471 | return rc; | ||
472 | } | ||
473 | |||
474 | static int | ||
475 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, | ||
476 | struct cifs_fid *fid, __u16 search_flags, | ||
477 | struct cifs_search_info *srch_inf) | ||
478 | { | ||
479 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, | ||
480 | fid->volatile_fid, 0, srch_inf); | ||
481 | } | ||
482 | |||
483 | static int | ||
484 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, | ||
485 | struct cifs_fid *fid) | ||
486 | { | ||
487 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); | ||
488 | } | ||
489 | |||
490 | /* | ||
491 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update | ||
492 | * the number of credits and return true. Otherwise - return false. | ||
493 | */ | ||
494 | static bool | ||
495 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) | ||
496 | { | ||
497 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; | ||
498 | |||
499 | if (hdr->Status != STATUS_PENDING) | ||
500 | return false; | ||
501 | |||
502 | if (!length) { | ||
503 | spin_lock(&server->req_lock); | ||
504 | server->credits += le16_to_cpu(hdr->CreditRequest); | ||
505 | spin_unlock(&server->req_lock); | ||
506 | wake_up(&server->request_q); | ||
507 | } | ||
508 | |||
509 | return true; | ||
510 | } | ||
511 | |||
512 | static int | ||
513 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, | ||
514 | struct cifsInodeInfo *cinode) | ||
515 | { | ||
516 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) | ||
517 | return SMB2_lease_break(0, tcon, cinode->lease_key, | ||
518 | smb2_get_lease_state(cinode)); | ||
519 | |||
520 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, | ||
521 | fid->volatile_fid, | ||
522 | cinode->clientCanCacheRead ? 1 : 0); | ||
523 | } | ||
524 | |||
525 | static int | ||
526 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, | ||
527 | struct kstatfs *buf) | ||
528 | { | ||
529 | int rc; | ||
530 | u64 persistent_fid, volatile_fid; | ||
531 | __le16 srch_path = 0; /* Null - open root of share */ | ||
532 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | ||
533 | |||
534 | rc = SMB2_open(xid, tcon, &srch_path, &persistent_fid, &volatile_fid, | ||
535 | FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL); | ||
536 | if (rc) | ||
537 | return rc; | ||
538 | buf->f_type = SMB2_MAGIC_NUMBER; | ||
539 | rc = SMB2_QFS_info(xid, tcon, persistent_fid, volatile_fid, buf); | ||
540 | SMB2_close(xid, tcon, persistent_fid, volatile_fid); | ||
541 | return rc; | ||
542 | } | ||
543 | |||
544 | static bool | ||
545 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) | ||
546 | { | ||
547 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && | ||
548 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; | ||
549 | } | ||
550 | |||
551 | static int | ||
552 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, | ||
553 | __u64 length, __u32 type, int lock, int unlock, bool wait) | ||
554 | { | ||
555 | if (unlock && !lock) | ||
556 | type = SMB2_LOCKFLAG_UNLOCK; | ||
557 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), | ||
558 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, | ||
559 | current->tgid, length, offset, type, wait); | ||
560 | } | ||
561 | |||
562 | static void | ||
563 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) | ||
564 | { | ||
565 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); | ||
566 | } | ||
567 | |||
568 | static void | ||
569 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) | ||
570 | { | ||
571 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); | ||
572 | } | ||
573 | |||
574 | static void | ||
575 | smb2_new_lease_key(struct cifs_fid *fid) | ||
576 | { | ||
577 | get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE); | ||
578 | } | ||
579 | |||
295 | struct smb_version_operations smb21_operations = { | 580 | struct smb_version_operations smb21_operations = { |
581 | .compare_fids = smb2_compare_fids, | ||
296 | .setup_request = smb2_setup_request, | 582 | .setup_request = smb2_setup_request, |
297 | .setup_async_request = smb2_setup_async_request, | 583 | .setup_async_request = smb2_setup_async_request, |
298 | .check_receive = smb2_check_receive, | 584 | .check_receive = smb2_check_receive, |
@@ -301,13 +587,19 @@ struct smb_version_operations smb21_operations = { | |||
301 | .get_credits_field = smb2_get_credits_field, | 587 | .get_credits_field = smb2_get_credits_field, |
302 | .get_credits = smb2_get_credits, | 588 | .get_credits = smb2_get_credits, |
303 | .get_next_mid = smb2_get_next_mid, | 589 | .get_next_mid = smb2_get_next_mid, |
590 | .read_data_offset = smb2_read_data_offset, | ||
591 | .read_data_length = smb2_read_data_length, | ||
592 | .map_error = map_smb2_to_linux_error, | ||
304 | .find_mid = smb2_find_mid, | 593 | .find_mid = smb2_find_mid, |
305 | .check_message = smb2_check_message, | 594 | .check_message = smb2_check_message, |
306 | .dump_detail = smb2_dump_detail, | 595 | .dump_detail = smb2_dump_detail, |
307 | .clear_stats = smb2_clear_stats, | 596 | .clear_stats = smb2_clear_stats, |
308 | .print_stats = smb2_print_stats, | 597 | .print_stats = smb2_print_stats, |
598 | .is_oplock_break = smb2_is_valid_oplock_break, | ||
309 | .need_neg = smb2_need_neg, | 599 | .need_neg = smb2_need_neg, |
310 | .negotiate = smb2_negotiate, | 600 | .negotiate = smb2_negotiate, |
601 | .negotiate_wsize = smb2_negotiate_wsize, | ||
602 | .negotiate_rsize = smb2_negotiate_rsize, | ||
311 | .sess_setup = SMB2_sess_setup, | 603 | .sess_setup = SMB2_sess_setup, |
312 | .logoff = SMB2_logoff, | 604 | .logoff = SMB2_logoff, |
313 | .tree_connect = SMB2_tcon, | 605 | .tree_connect = SMB2_tcon, |
@@ -317,16 +609,68 @@ struct smb_version_operations smb21_operations = { | |||
317 | .echo = SMB2_echo, | 609 | .echo = SMB2_echo, |
318 | .query_path_info = smb2_query_path_info, | 610 | .query_path_info = smb2_query_path_info, |
319 | .get_srv_inum = smb2_get_srv_inum, | 611 | .get_srv_inum = smb2_get_srv_inum, |
612 | .query_file_info = smb2_query_file_info, | ||
613 | .set_path_size = smb2_set_path_size, | ||
614 | .set_file_size = smb2_set_file_size, | ||
615 | .set_file_info = smb2_set_file_info, | ||
320 | .build_path_to_root = smb2_build_path_to_root, | 616 | .build_path_to_root = smb2_build_path_to_root, |
321 | .mkdir = smb2_mkdir, | 617 | .mkdir = smb2_mkdir, |
322 | .mkdir_setinfo = smb2_mkdir_setinfo, | 618 | .mkdir_setinfo = smb2_mkdir_setinfo, |
323 | .rmdir = smb2_rmdir, | 619 | .rmdir = smb2_rmdir, |
620 | .unlink = smb2_unlink, | ||
621 | .rename = smb2_rename_path, | ||
622 | .create_hardlink = smb2_create_hardlink, | ||
623 | .open = smb2_open_file, | ||
624 | .set_fid = smb2_set_fid, | ||
625 | .close = smb2_close_file, | ||
626 | .flush = smb2_flush_file, | ||
627 | .async_readv = smb2_async_readv, | ||
628 | .async_writev = smb2_async_writev, | ||
629 | .sync_read = smb2_sync_read, | ||
630 | .sync_write = smb2_sync_write, | ||
631 | .query_dir_first = smb2_query_dir_first, | ||
632 | .query_dir_next = smb2_query_dir_next, | ||
633 | .close_dir = smb2_close_dir, | ||
634 | .calc_smb_size = smb2_calc_size, | ||
635 | .is_status_pending = smb2_is_status_pending, | ||
636 | .oplock_response = smb2_oplock_response, | ||
637 | .queryfs = smb2_queryfs, | ||
638 | .mand_lock = smb2_mand_lock, | ||
639 | .mand_unlock_range = smb2_unlock_range, | ||
640 | .push_mand_locks = smb2_push_mandatory_locks, | ||
641 | .get_lease_key = smb2_get_lease_key, | ||
642 | .set_lease_key = smb2_set_lease_key, | ||
643 | .new_lease_key = smb2_new_lease_key, | ||
324 | }; | 644 | }; |
325 | 645 | ||
326 | struct smb_version_values smb21_values = { | 646 | struct smb_version_values smb21_values = { |
327 | .version_string = SMB21_VERSION_STRING, | 647 | .version_string = SMB21_VERSION_STRING, |
648 | .protocol_id = SMB21_PROT_ID, | ||
649 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ | ||
650 | .large_lock_type = 0, | ||
651 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | ||
652 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | ||
653 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | ||
654 | .header_size = sizeof(struct smb2_hdr), | ||
655 | .max_header_size = MAX_SMB2_HDR_SIZE, | ||
656 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | ||
657 | .lock_cmd = SMB2_LOCK, | ||
658 | .cap_unix = 0, | ||
659 | .cap_nt_find = SMB2_NT_FIND, | ||
660 | .cap_large_files = SMB2_LARGE_FILES, | ||
661 | }; | ||
662 | |||
663 | struct smb_version_values smb30_values = { | ||
664 | .version_string = SMB30_VERSION_STRING, | ||
665 | .protocol_id = SMB30_PROT_ID, | ||
666 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU, | ||
667 | .large_lock_type = 0, | ||
668 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | ||
669 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | ||
670 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | ||
328 | .header_size = sizeof(struct smb2_hdr), | 671 | .header_size = sizeof(struct smb2_hdr), |
329 | .max_header_size = MAX_SMB2_HDR_SIZE, | 672 | .max_header_size = MAX_SMB2_HDR_SIZE, |
673 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | ||
330 | .lock_cmd = SMB2_LOCK, | 674 | .lock_cmd = SMB2_LOCK, |
331 | .cap_unix = 0, | 675 | .cap_unix = 0, |
332 | .cap_nt_find = SMB2_NT_FIND, | 676 | .cap_nt_find = SMB2_NT_FIND, |
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 62b3f17d0613..cf33622cdac8 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * fs/cifs/smb2pdu.c | 2 | * fs/cifs/smb2pdu.c |
3 | * | 3 | * |
4 | * Copyright (C) International Business Machines Corp., 2009, 2011 | 4 | * Copyright (C) International Business Machines Corp., 2009, 2012 |
5 | * Etersoft, 2012 | 5 | * Etersoft, 2012 |
6 | * Author(s): Steve French (sfrench@us.ibm.com) | 6 | * Author(s): Steve French (sfrench@us.ibm.com) |
7 | * Pavel Shilovsky (pshilovsky@samba.org) 2012 | 7 | * Pavel Shilovsky (pshilovsky@samba.org) 2012 |
@@ -31,7 +31,9 @@ | |||
31 | #include <linux/fs.h> | 31 | #include <linux/fs.h> |
32 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
33 | #include <linux/vfs.h> | 33 | #include <linux/vfs.h> |
34 | #include <linux/task_io_accounting_ops.h> | ||
34 | #include <linux/uaccess.h> | 35 | #include <linux/uaccess.h> |
36 | #include <linux/pagemap.h> | ||
35 | #include <linux/xattr.h> | 37 | #include <linux/xattr.h> |
36 | #include "smb2pdu.h" | 38 | #include "smb2pdu.h" |
37 | #include "cifsglob.h" | 39 | #include "cifsglob.h" |
@@ -42,6 +44,8 @@ | |||
42 | #include "cifs_debug.h" | 44 | #include "cifs_debug.h" |
43 | #include "ntlmssp.h" | 45 | #include "ntlmssp.h" |
44 | #include "smb2status.h" | 46 | #include "smb2status.h" |
47 | #include "smb2glob.h" | ||
48 | #include "cifspdu.h" | ||
45 | 49 | ||
46 | /* | 50 | /* |
47 | * The following table defines the expected "StructureSize" of SMB2 requests | 51 | * The following table defines the expected "StructureSize" of SMB2 requests |
@@ -115,9 +119,9 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ , | |||
115 | /* BB how does SMB2 do case sensitive? */ | 119 | /* BB how does SMB2 do case sensitive? */ |
116 | /* if (tcon->nocase) | 120 | /* if (tcon->nocase) |
117 | hdr->Flags |= SMBFLG_CASELESS; */ | 121 | hdr->Flags |= SMBFLG_CASELESS; */ |
118 | /* if (tcon->ses && tcon->ses->server && | 122 | if (tcon->ses && tcon->ses->server && |
119 | (tcon->ses->server->sec_mode & SECMODE_SIGN_REQUIRED)) | 123 | (tcon->ses->server->sec_mode & SECMODE_SIGN_REQUIRED)) |
120 | hdr->Flags |= SMB2_FLAGS_SIGNED; */ | 124 | hdr->Flags |= SMB2_FLAGS_SIGNED; |
121 | out: | 125 | out: |
122 | pdu->StructureSize2 = cpu_to_le16(parmsize); | 126 | pdu->StructureSize2 = cpu_to_le16(parmsize); |
123 | return; | 127 | return; |
@@ -300,24 +304,6 @@ free_rsp_buf(int resp_buftype, void *rsp) | |||
300 | cifs_buf_release(rsp); | 304 | cifs_buf_release(rsp); |
301 | } | 305 | } |
302 | 306 | ||
303 | #define SMB2_NUM_PROT 1 | ||
304 | |||
305 | #define SMB2_PROT 0 | ||
306 | #define SMB21_PROT 1 | ||
307 | #define BAD_PROT 0xFFFF | ||
308 | |||
309 | #define SMB2_PROT_ID 0x0202 | ||
310 | #define SMB21_PROT_ID 0x0210 | ||
311 | #define BAD_PROT_ID 0xFFFF | ||
312 | |||
313 | static struct { | ||
314 | int index; | ||
315 | __le16 name; | ||
316 | } smb2protocols[] = { | ||
317 | {SMB2_PROT, cpu_to_le16(SMB2_PROT_ID)}, | ||
318 | {SMB21_PROT, cpu_to_le16(SMB21_PROT_ID)}, | ||
319 | {BAD_PROT, cpu_to_le16(BAD_PROT_ID)} | ||
320 | }; | ||
321 | 307 | ||
322 | /* | 308 | /* |
323 | * | 309 | * |
@@ -344,7 +330,6 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
344 | int resp_buftype; | 330 | int resp_buftype; |
345 | struct TCP_Server_Info *server; | 331 | struct TCP_Server_Info *server; |
346 | unsigned int sec_flags; | 332 | unsigned int sec_flags; |
347 | u16 i; | ||
348 | u16 temp = 0; | 333 | u16 temp = 0; |
349 | int blob_offset, blob_length; | 334 | int blob_offset, blob_length; |
350 | char *security_blob; | 335 | char *security_blob; |
@@ -373,11 +358,10 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
373 | 358 | ||
374 | req->hdr.SessionId = 0; | 359 | req->hdr.SessionId = 0; |
375 | 360 | ||
376 | for (i = 0; i < SMB2_NUM_PROT; i++) | 361 | req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id); |
377 | req->Dialects[i] = smb2protocols[i].name; | ||
378 | 362 | ||
379 | req->DialectCount = cpu_to_le16(i); | 363 | req->DialectCount = cpu_to_le16(1); /* One vers= at a time for now */ |
380 | inc_rfc1001_len(req, i * 2); | 364 | inc_rfc1001_len(req, 2); |
381 | 365 | ||
382 | /* only one of SMB2 signing flags may be set in SMB2 request */ | 366 | /* only one of SMB2 signing flags may be set in SMB2 request */ |
383 | if ((sec_flags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) | 367 | if ((sec_flags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) |
@@ -387,7 +371,9 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
387 | 371 | ||
388 | req->SecurityMode = cpu_to_le16(temp); | 372 | req->SecurityMode = cpu_to_le16(temp); |
389 | 373 | ||
390 | req->Capabilities = cpu_to_le32(SMB2_GLOBAL_CAP_DFS); | 374 | req->Capabilities = cpu_to_le32(ses->server->vals->req_capabilities); |
375 | |||
376 | memcpy(req->ClientGUID, cifs_client_guid, SMB2_CLIENT_GUID_SIZE); | ||
391 | 377 | ||
392 | iov[0].iov_base = (char *)req; | 378 | iov[0].iov_base = (char *)req; |
393 | /* 4 for rfc1002 length field */ | 379 | /* 4 for rfc1002 length field */ |
@@ -403,17 +389,16 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
403 | if (rc != 0) | 389 | if (rc != 0) |
404 | goto neg_exit; | 390 | goto neg_exit; |
405 | 391 | ||
406 | if (rsp == NULL) { | ||
407 | rc = -EIO; | ||
408 | goto neg_exit; | ||
409 | } | ||
410 | |||
411 | cFYI(1, "mode 0x%x", rsp->SecurityMode); | 392 | cFYI(1, "mode 0x%x", rsp->SecurityMode); |
412 | 393 | ||
413 | if (rsp->DialectRevision == smb2protocols[SMB21_PROT].name) | 394 | /* BB we may eventually want to match the negotiated vs. requested |
395 | dialect, even though we are only requesting one at a time */ | ||
396 | if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) | ||
397 | cFYI(1, "negotiated smb2.0 dialect"); | ||
398 | else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) | ||
414 | cFYI(1, "negotiated smb2.1 dialect"); | 399 | cFYI(1, "negotiated smb2.1 dialect"); |
415 | else if (rsp->DialectRevision == smb2protocols[SMB2_PROT].name) | 400 | else if (rsp->DialectRevision == cpu_to_le16(SMB30_PROT_ID)) |
416 | cFYI(1, "negotiated smb2 dialect"); | 401 | cFYI(1, "negotiated smb3.0 dialect"); |
417 | else { | 402 | else { |
418 | cERROR(1, "Illegal dialect returned by server %d", | 403 | cERROR(1, "Illegal dialect returned by server %d", |
419 | le16_to_cpu(rsp->DialectRevision)); | 404 | le16_to_cpu(rsp->DialectRevision)); |
@@ -438,6 +423,38 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
438 | rc = -EIO; | 423 | rc = -EIO; |
439 | goto neg_exit; | 424 | goto neg_exit; |
440 | } | 425 | } |
426 | |||
427 | cFYI(1, "sec_flags 0x%x", sec_flags); | ||
428 | if (sec_flags & CIFSSEC_MUST_SIGN) { | ||
429 | cFYI(1, "Signing required"); | ||
430 | if (!(server->sec_mode & (SMB2_NEGOTIATE_SIGNING_REQUIRED | | ||
431 | SMB2_NEGOTIATE_SIGNING_ENABLED))) { | ||
432 | cERROR(1, "signing required but server lacks support"); | ||
433 | rc = -EOPNOTSUPP; | ||
434 | goto neg_exit; | ||
435 | } | ||
436 | server->sec_mode |= SECMODE_SIGN_REQUIRED; | ||
437 | } else if (sec_flags & CIFSSEC_MAY_SIGN) { | ||
438 | cFYI(1, "Signing optional"); | ||
439 | if (server->sec_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED) { | ||
440 | cFYI(1, "Server requires signing"); | ||
441 | server->sec_mode |= SECMODE_SIGN_REQUIRED; | ||
442 | } else { | ||
443 | server->sec_mode &= | ||
444 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); | ||
445 | } | ||
446 | } else { | ||
447 | cFYI(1, "Signing disabled"); | ||
448 | if (server->sec_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED) { | ||
449 | cERROR(1, "Server requires packet signing to be enabled" | ||
450 | " in /proc/fs/cifs/SecurityFlags."); | ||
451 | rc = -EOPNOTSUPP; | ||
452 | goto neg_exit; | ||
453 | } | ||
454 | server->sec_mode &= | ||
455 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); | ||
456 | } | ||
457 | |||
441 | #ifdef CONFIG_SMB2_ASN1 /* BB REMOVEME when updated asn1.c ready */ | 458 | #ifdef CONFIG_SMB2_ASN1 /* BB REMOVEME when updated asn1.c ready */ |
442 | rc = decode_neg_token_init(security_blob, blob_length, | 459 | rc = decode_neg_token_init(security_blob, blob_length, |
443 | &server->sec_type); | 460 | &server->sec_type); |
@@ -599,13 +616,14 @@ ssetup_ntlmssp_authenticate: | |||
599 | 616 | ||
600 | kfree(security_blob); | 617 | kfree(security_blob); |
601 | rsp = (struct smb2_sess_setup_rsp *)iov[0].iov_base; | 618 | rsp = (struct smb2_sess_setup_rsp *)iov[0].iov_base; |
602 | if (rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) { | 619 | if (resp_buftype != CIFS_NO_BUFFER && |
620 | rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) { | ||
603 | if (phase != NtLmNegotiate) { | 621 | if (phase != NtLmNegotiate) { |
604 | cERROR(1, "Unexpected more processing error"); | 622 | cERROR(1, "Unexpected more processing error"); |
605 | goto ssetup_exit; | 623 | goto ssetup_exit; |
606 | } | 624 | } |
607 | if (offsetof(struct smb2_sess_setup_rsp, Buffer) - 4 != | 625 | if (offsetof(struct smb2_sess_setup_rsp, Buffer) - 4 != |
608 | le16_to_cpu(rsp->SecurityBufferOffset)) { | 626 | le16_to_cpu(rsp->SecurityBufferOffset)) { |
609 | cERROR(1, "Invalid security buffer offset %d", | 627 | cERROR(1, "Invalid security buffer offset %d", |
610 | le16_to_cpu(rsp->SecurityBufferOffset)); | 628 | le16_to_cpu(rsp->SecurityBufferOffset)); |
611 | rc = -EIO; | 629 | rc = -EIO; |
@@ -631,11 +649,6 @@ ssetup_ntlmssp_authenticate: | |||
631 | if (rc != 0) | 649 | if (rc != 0) |
632 | goto ssetup_exit; | 650 | goto ssetup_exit; |
633 | 651 | ||
634 | if (rsp == NULL) { | ||
635 | rc = -EIO; | ||
636 | goto ssetup_exit; | ||
637 | } | ||
638 | |||
639 | ses->session_flags = le16_to_cpu(rsp->SessionFlags); | 652 | ses->session_flags = le16_to_cpu(rsp->SessionFlags); |
640 | ssetup_exit: | 653 | ssetup_exit: |
641 | free_rsp_buf(resp_buftype, rsp); | 654 | free_rsp_buf(resp_buftype, rsp); |
@@ -666,6 +679,8 @@ SMB2_logoff(const unsigned int xid, struct cifs_ses *ses) | |||
666 | 679 | ||
667 | /* since no tcon, smb2_init can not do this, so do here */ | 680 | /* since no tcon, smb2_init can not do this, so do here */ |
668 | req->hdr.SessionId = ses->Suid; | 681 | req->hdr.SessionId = ses->Suid; |
682 | if (server->sec_mode & SECMODE_SIGN_REQUIRED) | ||
683 | req->hdr.Flags |= SMB2_FLAGS_SIGNED; | ||
669 | 684 | ||
670 | rc = SendReceiveNoRsp(xid, ses, (char *) &req->hdr, 0); | 685 | rc = SendReceiveNoRsp(xid, ses, (char *) &req->hdr, 0); |
671 | /* | 686 | /* |
@@ -753,11 +768,6 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, | |||
753 | goto tcon_error_exit; | 768 | goto tcon_error_exit; |
754 | } | 769 | } |
755 | 770 | ||
756 | if (rsp == NULL) { | ||
757 | rc = -EIO; | ||
758 | goto tcon_exit; | ||
759 | } | ||
760 | |||
761 | if (tcon == NULL) { | 771 | if (tcon == NULL) { |
762 | ses->ipc_tid = rsp->hdr.TreeId; | 772 | ses->ipc_tid = rsp->hdr.TreeId; |
763 | goto tcon_exit; | 773 | goto tcon_exit; |
@@ -830,18 +840,87 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon) | |||
830 | return rc; | 840 | return rc; |
831 | } | 841 | } |
832 | 842 | ||
843 | static struct create_lease * | ||
844 | create_lease_buf(u8 *lease_key, u8 oplock) | ||
845 | { | ||
846 | struct create_lease *buf; | ||
847 | |||
848 | buf = kmalloc(sizeof(struct create_lease), GFP_KERNEL); | ||
849 | if (!buf) | ||
850 | return NULL; | ||
851 | |||
852 | memset(buf, 0, sizeof(struct create_lease)); | ||
853 | |||
854 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); | ||
855 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); | ||
856 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) | ||
857 | buf->lcontext.LeaseState = SMB2_LEASE_WRITE_CACHING | | ||
858 | SMB2_LEASE_READ_CACHING; | ||
859 | else if (oplock == SMB2_OPLOCK_LEVEL_II) | ||
860 | buf->lcontext.LeaseState = SMB2_LEASE_READ_CACHING; | ||
861 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) | ||
862 | buf->lcontext.LeaseState = SMB2_LEASE_HANDLE_CACHING | | ||
863 | SMB2_LEASE_READ_CACHING | | ||
864 | SMB2_LEASE_WRITE_CACHING; | ||
865 | |||
866 | buf->ccontext.DataOffset = cpu_to_le16(offsetof | ||
867 | (struct create_lease, lcontext)); | ||
868 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); | ||
869 | buf->ccontext.NameOffset = cpu_to_le16(offsetof | ||
870 | (struct create_lease, Name)); | ||
871 | buf->ccontext.NameLength = cpu_to_le16(4); | ||
872 | buf->Name[0] = 'R'; | ||
873 | buf->Name[1] = 'q'; | ||
874 | buf->Name[2] = 'L'; | ||
875 | buf->Name[3] = 's'; | ||
876 | return buf; | ||
877 | } | ||
878 | |||
879 | static __u8 | ||
880 | parse_lease_state(struct smb2_create_rsp *rsp) | ||
881 | { | ||
882 | char *data_offset; | ||
883 | struct create_lease *lc; | ||
884 | bool found = false; | ||
885 | |||
886 | data_offset = (char *)rsp; | ||
887 | data_offset += 4 + le32_to_cpu(rsp->CreateContextsOffset); | ||
888 | lc = (struct create_lease *)data_offset; | ||
889 | do { | ||
890 | char *name = le16_to_cpu(lc->ccontext.NameOffset) + (char *)lc; | ||
891 | if (le16_to_cpu(lc->ccontext.NameLength) != 4 || | ||
892 | strncmp(name, "RqLs", 4)) { | ||
893 | lc = (struct create_lease *)((char *)lc | ||
894 | + le32_to_cpu(lc->ccontext.Next)); | ||
895 | continue; | ||
896 | } | ||
897 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) | ||
898 | return SMB2_OPLOCK_LEVEL_NOCHANGE; | ||
899 | found = true; | ||
900 | break; | ||
901 | } while (le32_to_cpu(lc->ccontext.Next) != 0); | ||
902 | |||
903 | if (!found) | ||
904 | return 0; | ||
905 | |||
906 | return smb2_map_lease_to_oplock(lc->lcontext.LeaseState); | ||
907 | } | ||
908 | |||
833 | int | 909 | int |
834 | SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | 910 | SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, |
835 | u64 *persistent_fid, u64 *volatile_fid, __u32 desired_access, | 911 | u64 *persistent_fid, u64 *volatile_fid, __u32 desired_access, |
836 | __u32 create_disposition, __u32 file_attributes, __u32 create_options) | 912 | __u32 create_disposition, __u32 file_attributes, __u32 create_options, |
913 | __u8 *oplock, struct smb2_file_all_info *buf) | ||
837 | { | 914 | { |
838 | struct smb2_create_req *req; | 915 | struct smb2_create_req *req; |
839 | struct smb2_create_rsp *rsp; | 916 | struct smb2_create_rsp *rsp; |
840 | struct TCP_Server_Info *server; | 917 | struct TCP_Server_Info *server; |
841 | struct cifs_ses *ses = tcon->ses; | 918 | struct cifs_ses *ses = tcon->ses; |
842 | struct kvec iov[2]; | 919 | struct kvec iov[3]; |
843 | int resp_buftype; | 920 | int resp_buftype; |
844 | int uni_path_len; | 921 | int uni_path_len; |
922 | __le16 *copy_path = NULL; | ||
923 | int copy_size; | ||
845 | int rc = 0; | 924 | int rc = 0; |
846 | int num_iovecs = 2; | 925 | int num_iovecs = 2; |
847 | 926 | ||
@@ -856,10 +935,6 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | |||
856 | if (rc) | 935 | if (rc) |
857 | return rc; | 936 | return rc; |
858 | 937 | ||
859 | if (enable_oplocks) | ||
860 | req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_BATCH; | ||
861 | else | ||
862 | req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_NONE; | ||
863 | req->ImpersonationLevel = IL_IMPERSONATION; | 938 | req->ImpersonationLevel = IL_IMPERSONATION; |
864 | req->DesiredAccess = cpu_to_le32(desired_access); | 939 | req->DesiredAccess = cpu_to_le32(desired_access); |
865 | /* File attributes ignored on open (used in create though) */ | 940 | /* File attributes ignored on open (used in create though) */ |
@@ -869,7 +944,7 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | |||
869 | req->CreateOptions = cpu_to_le32(create_options); | 944 | req->CreateOptions = cpu_to_le32(create_options); |
870 | uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2; | 945 | uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2; |
871 | req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req) | 946 | req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req) |
872 | - 1 /* pad */ - 4 /* do not count rfc1001 len field */); | 947 | - 8 /* pad */ - 4 /* do not count rfc1001 len field */); |
873 | 948 | ||
874 | iov[0].iov_base = (char *)req; | 949 | iov[0].iov_base = (char *)req; |
875 | /* 4 for rfc1002 length field */ | 950 | /* 4 for rfc1002 length field */ |
@@ -880,6 +955,20 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | |||
880 | req->NameLength = cpu_to_le16(uni_path_len - 2); | 955 | req->NameLength = cpu_to_le16(uni_path_len - 2); |
881 | /* -1 since last byte is buf[0] which is sent below (path) */ | 956 | /* -1 since last byte is buf[0] which is sent below (path) */ |
882 | iov[0].iov_len--; | 957 | iov[0].iov_len--; |
958 | if (uni_path_len % 8 != 0) { | ||
959 | copy_size = uni_path_len / 8 * 8; | ||
960 | if (copy_size < uni_path_len) | ||
961 | copy_size += 8; | ||
962 | |||
963 | copy_path = kzalloc(copy_size, GFP_KERNEL); | ||
964 | if (!copy_path) | ||
965 | return -ENOMEM; | ||
966 | memcpy((char *)copy_path, (const char *)path, | ||
967 | uni_path_len); | ||
968 | uni_path_len = copy_size; | ||
969 | path = copy_path; | ||
970 | } | ||
971 | |||
883 | iov[1].iov_len = uni_path_len; | 972 | iov[1].iov_len = uni_path_len; |
884 | iov[1].iov_base = path; | 973 | iov[1].iov_base = path; |
885 | /* | 974 | /* |
@@ -888,10 +977,37 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | |||
888 | */ | 977 | */ |
889 | inc_rfc1001_len(req, uni_path_len - 1); | 978 | inc_rfc1001_len(req, uni_path_len - 1); |
890 | } else { | 979 | } else { |
980 | iov[0].iov_len += 7; | ||
981 | req->hdr.smb2_buf_length = cpu_to_be32(be32_to_cpu( | ||
982 | req->hdr.smb2_buf_length) + 8 - 1); | ||
891 | num_iovecs = 1; | 983 | num_iovecs = 1; |
892 | req->NameLength = 0; | 984 | req->NameLength = 0; |
893 | } | 985 | } |
894 | 986 | ||
987 | if (!server->oplocks) | ||
988 | *oplock = SMB2_OPLOCK_LEVEL_NONE; | ||
989 | |||
990 | if (!(tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) || | ||
991 | *oplock == SMB2_OPLOCK_LEVEL_NONE) | ||
992 | req->RequestedOplockLevel = *oplock; | ||
993 | else { | ||
994 | iov[num_iovecs].iov_base = create_lease_buf(oplock+1, *oplock); | ||
995 | if (iov[num_iovecs].iov_base == NULL) { | ||
996 | cifs_small_buf_release(req); | ||
997 | kfree(copy_path); | ||
998 | return -ENOMEM; | ||
999 | } | ||
1000 | iov[num_iovecs].iov_len = sizeof(struct create_lease); | ||
1001 | req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE; | ||
1002 | req->CreateContextsOffset = cpu_to_le32( | ||
1003 | sizeof(struct smb2_create_req) - 4 - 8 + | ||
1004 | iov[num_iovecs-1].iov_len); | ||
1005 | req->CreateContextsLength = cpu_to_le32( | ||
1006 | sizeof(struct create_lease)); | ||
1007 | inc_rfc1001_len(&req->hdr, sizeof(struct create_lease)); | ||
1008 | num_iovecs++; | ||
1009 | } | ||
1010 | |||
895 | rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0); | 1011 | rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0); |
896 | rsp = (struct smb2_create_rsp *)iov[0].iov_base; | 1012 | rsp = (struct smb2_create_rsp *)iov[0].iov_base; |
897 | 1013 | ||
@@ -900,13 +1016,24 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | |||
900 | goto creat_exit; | 1016 | goto creat_exit; |
901 | } | 1017 | } |
902 | 1018 | ||
903 | if (rsp == NULL) { | ||
904 | rc = -EIO; | ||
905 | goto creat_exit; | ||
906 | } | ||
907 | *persistent_fid = rsp->PersistentFileId; | 1019 | *persistent_fid = rsp->PersistentFileId; |
908 | *volatile_fid = rsp->VolatileFileId; | 1020 | *volatile_fid = rsp->VolatileFileId; |
1021 | |||
1022 | if (buf) { | ||
1023 | memcpy(buf, &rsp->CreationTime, 32); | ||
1024 | buf->AllocationSize = rsp->AllocationSize; | ||
1025 | buf->EndOfFile = rsp->EndofFile; | ||
1026 | buf->Attributes = rsp->FileAttributes; | ||
1027 | buf->NumberOfLinks = cpu_to_le32(1); | ||
1028 | buf->DeletePending = 0; | ||
1029 | } | ||
1030 | |||
1031 | if (rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) | ||
1032 | *oplock = parse_lease_state(rsp); | ||
1033 | else | ||
1034 | *oplock = rsp->OplockLevel; | ||
909 | creat_exit: | 1035 | creat_exit: |
1036 | kfree(copy_path); | ||
910 | free_rsp_buf(resp_buftype, rsp); | 1037 | free_rsp_buf(resp_buftype, rsp); |
911 | return rc; | 1038 | return rc; |
912 | } | 1039 | } |
@@ -950,11 +1077,6 @@ SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
950 | goto close_exit; | 1077 | goto close_exit; |
951 | } | 1078 | } |
952 | 1079 | ||
953 | if (rsp == NULL) { | ||
954 | rc = -EIO; | ||
955 | goto close_exit; | ||
956 | } | ||
957 | |||
958 | /* BB FIXME - decode close response, update inode for caching */ | 1080 | /* BB FIXME - decode close response, update inode for caching */ |
959 | 1081 | ||
960 | close_exit: | 1082 | close_exit: |
@@ -1019,10 +1141,10 @@ validate_and_copy_buf(unsigned int offset, unsigned int buffer_length, | |||
1019 | return 0; | 1141 | return 0; |
1020 | } | 1142 | } |
1021 | 1143 | ||
1022 | int | 1144 | static int |
1023 | SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, | 1145 | query_info(const unsigned int xid, struct cifs_tcon *tcon, |
1024 | u64 persistent_fid, u64 volatile_fid, | 1146 | u64 persistent_fid, u64 volatile_fid, u8 info_class, |
1025 | struct smb2_file_all_info *data) | 1147 | size_t output_len, size_t min_len, void *data) |
1026 | { | 1148 | { |
1027 | struct smb2_query_info_req *req; | 1149 | struct smb2_query_info_req *req; |
1028 | struct smb2_query_info_rsp *rsp = NULL; | 1150 | struct smb2_query_info_rsp *rsp = NULL; |
@@ -1044,37 +1166,56 @@ SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, | |||
1044 | return rc; | 1166 | return rc; |
1045 | 1167 | ||
1046 | req->InfoType = SMB2_O_INFO_FILE; | 1168 | req->InfoType = SMB2_O_INFO_FILE; |
1047 | req->FileInfoClass = FILE_ALL_INFORMATION; | 1169 | req->FileInfoClass = info_class; |
1048 | req->PersistentFileId = persistent_fid; | 1170 | req->PersistentFileId = persistent_fid; |
1049 | req->VolatileFileId = volatile_fid; | 1171 | req->VolatileFileId = volatile_fid; |
1050 | /* 4 for rfc1002 length field and 1 for Buffer */ | 1172 | /* 4 for rfc1002 length field and 1 for Buffer */ |
1051 | req->InputBufferOffset = | 1173 | req->InputBufferOffset = |
1052 | cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4); | 1174 | cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4); |
1053 | req->OutputBufferLength = | 1175 | req->OutputBufferLength = cpu_to_le32(output_len); |
1054 | cpu_to_le32(sizeof(struct smb2_file_all_info) + MAX_NAME * 2); | ||
1055 | 1176 | ||
1056 | iov[0].iov_base = (char *)req; | 1177 | iov[0].iov_base = (char *)req; |
1057 | /* 4 for rfc1002 length field */ | 1178 | /* 4 for rfc1002 length field */ |
1058 | iov[0].iov_len = get_rfc1002_length(req) + 4; | 1179 | iov[0].iov_len = get_rfc1002_length(req) + 4; |
1059 | 1180 | ||
1060 | rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0); | 1181 | rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0); |
1182 | rsp = (struct smb2_query_info_rsp *)iov[0].iov_base; | ||
1183 | |||
1061 | if (rc) { | 1184 | if (rc) { |
1062 | cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); | 1185 | cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); |
1063 | goto qinf_exit; | 1186 | goto qinf_exit; |
1064 | } | 1187 | } |
1065 | 1188 | ||
1066 | rsp = (struct smb2_query_info_rsp *)iov[0].iov_base; | ||
1067 | |||
1068 | rc = validate_and_copy_buf(le16_to_cpu(rsp->OutputBufferOffset), | 1189 | rc = validate_and_copy_buf(le16_to_cpu(rsp->OutputBufferOffset), |
1069 | le32_to_cpu(rsp->OutputBufferLength), | 1190 | le32_to_cpu(rsp->OutputBufferLength), |
1070 | &rsp->hdr, sizeof(struct smb2_file_all_info), | 1191 | &rsp->hdr, min_len, data); |
1071 | (char *)data); | ||
1072 | 1192 | ||
1073 | qinf_exit: | 1193 | qinf_exit: |
1074 | free_rsp_buf(resp_buftype, rsp); | 1194 | free_rsp_buf(resp_buftype, rsp); |
1075 | return rc; | 1195 | return rc; |
1076 | } | 1196 | } |
1077 | 1197 | ||
1198 | int | ||
1199 | SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
1200 | u64 persistent_fid, u64 volatile_fid, | ||
1201 | struct smb2_file_all_info *data) | ||
1202 | { | ||
1203 | return query_info(xid, tcon, persistent_fid, volatile_fid, | ||
1204 | FILE_ALL_INFORMATION, | ||
1205 | sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | ||
1206 | sizeof(struct smb2_file_all_info), data); | ||
1207 | } | ||
1208 | |||
1209 | int | ||
1210 | SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon, | ||
1211 | u64 persistent_fid, u64 volatile_fid, __le64 *uniqueid) | ||
1212 | { | ||
1213 | return query_info(xid, tcon, persistent_fid, volatile_fid, | ||
1214 | FILE_INTERNAL_INFORMATION, | ||
1215 | sizeof(struct smb2_file_internal_info), | ||
1216 | sizeof(struct smb2_file_internal_info), uniqueid); | ||
1217 | } | ||
1218 | |||
1078 | /* | 1219 | /* |
1079 | * This is a no-op for now. We're not really interested in the reply, but | 1220 | * This is a no-op for now. We're not really interested in the reply, but |
1080 | * rather in the fact that the server sent one and that server->lstrp | 1221 | * rather in the fact that the server sent one and that server->lstrp |
@@ -1102,6 +1243,8 @@ SMB2_echo(struct TCP_Server_Info *server) | |||
1102 | struct smb2_echo_req *req; | 1243 | struct smb2_echo_req *req; |
1103 | int rc = 0; | 1244 | int rc = 0; |
1104 | struct kvec iov; | 1245 | struct kvec iov; |
1246 | struct smb_rqst rqst = { .rq_iov = &iov, | ||
1247 | .rq_nvec = 1 }; | ||
1105 | 1248 | ||
1106 | cFYI(1, "In echo request"); | 1249 | cFYI(1, "In echo request"); |
1107 | 1250 | ||
@@ -1115,7 +1258,7 @@ SMB2_echo(struct TCP_Server_Info *server) | |||
1115 | /* 4 for rfc1002 length field */ | 1258 | /* 4 for rfc1002 length field */ |
1116 | iov.iov_len = get_rfc1002_length(req) + 4; | 1259 | iov.iov_len = get_rfc1002_length(req) + 4; |
1117 | 1260 | ||
1118 | rc = cifs_call_async(server, &iov, 1, NULL, smb2_echo_callback, server, | 1261 | rc = cifs_call_async(server, &rqst, NULL, smb2_echo_callback, server, |
1119 | CIFS_ECHO_OP); | 1262 | CIFS_ECHO_OP); |
1120 | if (rc) | 1263 | if (rc) |
1121 | cFYI(1, "Echo request failed: %d", rc); | 1264 | cFYI(1, "Echo request failed: %d", rc); |
@@ -1123,3 +1266,945 @@ SMB2_echo(struct TCP_Server_Info *server) | |||
1123 | cifs_small_buf_release(req); | 1266 | cifs_small_buf_release(req); |
1124 | return rc; | 1267 | return rc; |
1125 | } | 1268 | } |
1269 | |||
1270 | int | ||
1271 | SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, | ||
1272 | u64 volatile_fid) | ||
1273 | { | ||
1274 | struct smb2_flush_req *req; | ||
1275 | struct TCP_Server_Info *server; | ||
1276 | struct cifs_ses *ses = tcon->ses; | ||
1277 | struct kvec iov[1]; | ||
1278 | int resp_buftype; | ||
1279 | int rc = 0; | ||
1280 | |||
1281 | cFYI(1, "Flush"); | ||
1282 | |||
1283 | if (ses && (ses->server)) | ||
1284 | server = ses->server; | ||
1285 | else | ||
1286 | return -EIO; | ||
1287 | |||
1288 | rc = small_smb2_init(SMB2_FLUSH, tcon, (void **) &req); | ||
1289 | if (rc) | ||
1290 | return rc; | ||
1291 | |||
1292 | req->PersistentFileId = persistent_fid; | ||
1293 | req->VolatileFileId = volatile_fid; | ||
1294 | |||
1295 | iov[0].iov_base = (char *)req; | ||
1296 | /* 4 for rfc1002 length field */ | ||
1297 | iov[0].iov_len = get_rfc1002_length(req) + 4; | ||
1298 | |||
1299 | rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0); | ||
1300 | |||
1301 | if ((rc != 0) && tcon) | ||
1302 | cifs_stats_fail_inc(tcon, SMB2_FLUSH_HE); | ||
1303 | |||
1304 | free_rsp_buf(resp_buftype, iov[0].iov_base); | ||
1305 | return rc; | ||
1306 | } | ||
1307 | |||
1308 | /* | ||
1309 | * To form a chain of read requests, any read requests after the first should | ||
1310 | * have the end_of_chain boolean set to true. | ||
1311 | */ | ||
1312 | static int | ||
1313 | smb2_new_read_req(struct kvec *iov, struct cifs_io_parms *io_parms, | ||
1314 | unsigned int remaining_bytes, int request_type) | ||
1315 | { | ||
1316 | int rc = -EACCES; | ||
1317 | struct smb2_read_req *req = NULL; | ||
1318 | |||
1319 | rc = small_smb2_init(SMB2_READ, io_parms->tcon, (void **) &req); | ||
1320 | if (rc) | ||
1321 | return rc; | ||
1322 | if (io_parms->tcon->ses->server == NULL) | ||
1323 | return -ECONNABORTED; | ||
1324 | |||
1325 | req->hdr.ProcessId = cpu_to_le32(io_parms->pid); | ||
1326 | |||
1327 | req->PersistentFileId = io_parms->persistent_fid; | ||
1328 | req->VolatileFileId = io_parms->volatile_fid; | ||
1329 | req->ReadChannelInfoOffset = 0; /* reserved */ | ||
1330 | req->ReadChannelInfoLength = 0; /* reserved */ | ||
1331 | req->Channel = 0; /* reserved */ | ||
1332 | req->MinimumCount = 0; | ||
1333 | req->Length = cpu_to_le32(io_parms->length); | ||
1334 | req->Offset = cpu_to_le64(io_parms->offset); | ||
1335 | |||
1336 | if (request_type & CHAINED_REQUEST) { | ||
1337 | if (!(request_type & END_OF_CHAIN)) { | ||
1338 | /* 4 for rfc1002 length field */ | ||
1339 | req->hdr.NextCommand = | ||
1340 | cpu_to_le32(get_rfc1002_length(req) + 4); | ||
1341 | } else /* END_OF_CHAIN */ | ||
1342 | req->hdr.NextCommand = 0; | ||
1343 | if (request_type & RELATED_REQUEST) { | ||
1344 | req->hdr.Flags |= SMB2_FLAGS_RELATED_OPERATIONS; | ||
1345 | /* | ||
1346 | * Related requests use info from previous read request | ||
1347 | * in chain. | ||
1348 | */ | ||
1349 | req->hdr.SessionId = 0xFFFFFFFF; | ||
1350 | req->hdr.TreeId = 0xFFFFFFFF; | ||
1351 | req->PersistentFileId = 0xFFFFFFFF; | ||
1352 | req->VolatileFileId = 0xFFFFFFFF; | ||
1353 | } | ||
1354 | } | ||
1355 | if (remaining_bytes > io_parms->length) | ||
1356 | req->RemainingBytes = cpu_to_le32(remaining_bytes); | ||
1357 | else | ||
1358 | req->RemainingBytes = 0; | ||
1359 | |||
1360 | iov[0].iov_base = (char *)req; | ||
1361 | /* 4 for rfc1002 length field */ | ||
1362 | iov[0].iov_len = get_rfc1002_length(req) + 4; | ||
1363 | return rc; | ||
1364 | } | ||
1365 | |||
1366 | static void | ||
1367 | smb2_readv_callback(struct mid_q_entry *mid) | ||
1368 | { | ||
1369 | struct cifs_readdata *rdata = mid->callback_data; | ||
1370 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); | ||
1371 | struct TCP_Server_Info *server = tcon->ses->server; | ||
1372 | struct smb2_hdr *buf = (struct smb2_hdr *)rdata->iov.iov_base; | ||
1373 | unsigned int credits_received = 1; | ||
1374 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, | ||
1375 | .rq_nvec = 1, | ||
1376 | .rq_pages = rdata->pages, | ||
1377 | .rq_npages = rdata->nr_pages, | ||
1378 | .rq_pagesz = rdata->pagesz, | ||
1379 | .rq_tailsz = rdata->tailsz }; | ||
1380 | |||
1381 | cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__, | ||
1382 | mid->mid, mid->mid_state, rdata->result, rdata->bytes); | ||
1383 | |||
1384 | switch (mid->mid_state) { | ||
1385 | case MID_RESPONSE_RECEIVED: | ||
1386 | credits_received = le16_to_cpu(buf->CreditRequest); | ||
1387 | /* result already set, check signature */ | ||
1388 | if (server->sec_mode & | ||
1389 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { | ||
1390 | int rc; | ||
1391 | |||
1392 | rc = smb2_verify_signature(&rqst, server); | ||
1393 | if (rc) | ||
1394 | cERROR(1, "SMB signature verification returned " | ||
1395 | "error = %d", rc); | ||
1396 | } | ||
1397 | /* FIXME: should this be counted toward the initiating task? */ | ||
1398 | task_io_account_read(rdata->bytes); | ||
1399 | cifs_stats_bytes_read(tcon, rdata->bytes); | ||
1400 | break; | ||
1401 | case MID_REQUEST_SUBMITTED: | ||
1402 | case MID_RETRY_NEEDED: | ||
1403 | rdata->result = -EAGAIN; | ||
1404 | break; | ||
1405 | default: | ||
1406 | if (rdata->result != -ENODATA) | ||
1407 | rdata->result = -EIO; | ||
1408 | } | ||
1409 | |||
1410 | if (rdata->result) | ||
1411 | cifs_stats_fail_inc(tcon, SMB2_READ_HE); | ||
1412 | |||
1413 | queue_work(cifsiod_wq, &rdata->work); | ||
1414 | DeleteMidQEntry(mid); | ||
1415 | add_credits(server, credits_received, 0); | ||
1416 | } | ||
1417 | |||
1418 | /* smb2_async_readv - send an async write, and set up mid to handle result */ | ||
1419 | int | ||
1420 | smb2_async_readv(struct cifs_readdata *rdata) | ||
1421 | { | ||
1422 | int rc; | ||
1423 | struct smb2_hdr *buf; | ||
1424 | struct cifs_io_parms io_parms; | ||
1425 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, | ||
1426 | .rq_nvec = 1 }; | ||
1427 | |||
1428 | cFYI(1, "%s: offset=%llu bytes=%u", __func__, | ||
1429 | rdata->offset, rdata->bytes); | ||
1430 | |||
1431 | io_parms.tcon = tlink_tcon(rdata->cfile->tlink); | ||
1432 | io_parms.offset = rdata->offset; | ||
1433 | io_parms.length = rdata->bytes; | ||
1434 | io_parms.persistent_fid = rdata->cfile->fid.persistent_fid; | ||
1435 | io_parms.volatile_fid = rdata->cfile->fid.volatile_fid; | ||
1436 | io_parms.pid = rdata->pid; | ||
1437 | rc = smb2_new_read_req(&rdata->iov, &io_parms, 0, 0); | ||
1438 | if (rc) | ||
1439 | return rc; | ||
1440 | |||
1441 | buf = (struct smb2_hdr *)rdata->iov.iov_base; | ||
1442 | /* 4 for rfc1002 length field */ | ||
1443 | rdata->iov.iov_len = get_rfc1002_length(rdata->iov.iov_base) + 4; | ||
1444 | |||
1445 | kref_get(&rdata->refcount); | ||
1446 | rc = cifs_call_async(io_parms.tcon->ses->server, &rqst, | ||
1447 | cifs_readv_receive, smb2_readv_callback, | ||
1448 | rdata, 0); | ||
1449 | if (rc) { | ||
1450 | kref_put(&rdata->refcount, cifs_readdata_release); | ||
1451 | cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE); | ||
1452 | } | ||
1453 | |||
1454 | cifs_small_buf_release(buf); | ||
1455 | return rc; | ||
1456 | } | ||
1457 | |||
1458 | int | ||
1459 | SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, | ||
1460 | unsigned int *nbytes, char **buf, int *buf_type) | ||
1461 | { | ||
1462 | int resp_buftype, rc = -EACCES; | ||
1463 | struct smb2_read_rsp *rsp = NULL; | ||
1464 | struct kvec iov[1]; | ||
1465 | |||
1466 | *nbytes = 0; | ||
1467 | rc = smb2_new_read_req(iov, io_parms, 0, 0); | ||
1468 | if (rc) | ||
1469 | return rc; | ||
1470 | |||
1471 | rc = SendReceive2(xid, io_parms->tcon->ses, iov, 1, | ||
1472 | &resp_buftype, CIFS_LOG_ERROR); | ||
1473 | |||
1474 | rsp = (struct smb2_read_rsp *)iov[0].iov_base; | ||
1475 | |||
1476 | if (rsp->hdr.Status == STATUS_END_OF_FILE) { | ||
1477 | free_rsp_buf(resp_buftype, iov[0].iov_base); | ||
1478 | return 0; | ||
1479 | } | ||
1480 | |||
1481 | if (rc) { | ||
1482 | cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE); | ||
1483 | cERROR(1, "Send error in read = %d", rc); | ||
1484 | } else { | ||
1485 | *nbytes = le32_to_cpu(rsp->DataLength); | ||
1486 | if ((*nbytes > CIFS_MAX_MSGSIZE) || | ||
1487 | (*nbytes > io_parms->length)) { | ||
1488 | cFYI(1, "bad length %d for count %d", *nbytes, | ||
1489 | io_parms->length); | ||
1490 | rc = -EIO; | ||
1491 | *nbytes = 0; | ||
1492 | } | ||
1493 | } | ||
1494 | |||
1495 | if (*buf) { | ||
1496 | memcpy(*buf, (char *)rsp->hdr.ProtocolId + rsp->DataOffset, | ||
1497 | *nbytes); | ||
1498 | free_rsp_buf(resp_buftype, iov[0].iov_base); | ||
1499 | } else if (resp_buftype != CIFS_NO_BUFFER) { | ||
1500 | *buf = iov[0].iov_base; | ||
1501 | if (resp_buftype == CIFS_SMALL_BUFFER) | ||
1502 | *buf_type = CIFS_SMALL_BUFFER; | ||
1503 | else if (resp_buftype == CIFS_LARGE_BUFFER) | ||
1504 | *buf_type = CIFS_LARGE_BUFFER; | ||
1505 | } | ||
1506 | return rc; | ||
1507 | } | ||
1508 | |||
1509 | /* | ||
1510 | * Check the mid_state and signature on received buffer (if any), and queue the | ||
1511 | * workqueue completion task. | ||
1512 | */ | ||
1513 | static void | ||
1514 | smb2_writev_callback(struct mid_q_entry *mid) | ||
1515 | { | ||
1516 | struct cifs_writedata *wdata = mid->callback_data; | ||
1517 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); | ||
1518 | unsigned int written; | ||
1519 | struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf; | ||
1520 | unsigned int credits_received = 1; | ||
1521 | |||
1522 | switch (mid->mid_state) { | ||
1523 | case MID_RESPONSE_RECEIVED: | ||
1524 | credits_received = le16_to_cpu(rsp->hdr.CreditRequest); | ||
1525 | wdata->result = smb2_check_receive(mid, tcon->ses->server, 0); | ||
1526 | if (wdata->result != 0) | ||
1527 | break; | ||
1528 | |||
1529 | written = le32_to_cpu(rsp->DataLength); | ||
1530 | /* | ||
1531 | * Mask off high 16 bits when bytes written as returned | ||
1532 | * by the server is greater than bytes requested by the | ||
1533 | * client. OS/2 servers are known to set incorrect | ||
1534 | * CountHigh values. | ||
1535 | */ | ||
1536 | if (written > wdata->bytes) | ||
1537 | written &= 0xFFFF; | ||
1538 | |||
1539 | if (written < wdata->bytes) | ||
1540 | wdata->result = -ENOSPC; | ||
1541 | else | ||
1542 | wdata->bytes = written; | ||
1543 | break; | ||
1544 | case MID_REQUEST_SUBMITTED: | ||
1545 | case MID_RETRY_NEEDED: | ||
1546 | wdata->result = -EAGAIN; | ||
1547 | break; | ||
1548 | default: | ||
1549 | wdata->result = -EIO; | ||
1550 | break; | ||
1551 | } | ||
1552 | |||
1553 | if (wdata->result) | ||
1554 | cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); | ||
1555 | |||
1556 | queue_work(cifsiod_wq, &wdata->work); | ||
1557 | DeleteMidQEntry(mid); | ||
1558 | add_credits(tcon->ses->server, credits_received, 0); | ||
1559 | } | ||
1560 | |||
1561 | /* smb2_async_writev - send an async write, and set up mid to handle result */ | ||
1562 | int | ||
1563 | smb2_async_writev(struct cifs_writedata *wdata) | ||
1564 | { | ||
1565 | int rc = -EACCES; | ||
1566 | struct smb2_write_req *req = NULL; | ||
1567 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); | ||
1568 | struct kvec iov; | ||
1569 | struct smb_rqst rqst; | ||
1570 | |||
1571 | rc = small_smb2_init(SMB2_WRITE, tcon, (void **) &req); | ||
1572 | if (rc) | ||
1573 | goto async_writev_out; | ||
1574 | |||
1575 | req->hdr.ProcessId = cpu_to_le32(wdata->cfile->pid); | ||
1576 | |||
1577 | req->PersistentFileId = wdata->cfile->fid.persistent_fid; | ||
1578 | req->VolatileFileId = wdata->cfile->fid.volatile_fid; | ||
1579 | req->WriteChannelInfoOffset = 0; | ||
1580 | req->WriteChannelInfoLength = 0; | ||
1581 | req->Channel = 0; | ||
1582 | req->Offset = cpu_to_le64(wdata->offset); | ||
1583 | /* 4 for rfc1002 length field */ | ||
1584 | req->DataOffset = cpu_to_le16( | ||
1585 | offsetof(struct smb2_write_req, Buffer) - 4); | ||
1586 | req->RemainingBytes = 0; | ||
1587 | |||
1588 | /* 4 for rfc1002 length field and 1 for Buffer */ | ||
1589 | iov.iov_len = get_rfc1002_length(req) + 4 - 1; | ||
1590 | iov.iov_base = req; | ||
1591 | |||
1592 | rqst.rq_iov = &iov; | ||
1593 | rqst.rq_nvec = 1; | ||
1594 | rqst.rq_pages = wdata->pages; | ||
1595 | rqst.rq_npages = wdata->nr_pages; | ||
1596 | rqst.rq_pagesz = wdata->pagesz; | ||
1597 | rqst.rq_tailsz = wdata->tailsz; | ||
1598 | |||
1599 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); | ||
1600 | |||
1601 | req->Length = cpu_to_le32(wdata->bytes); | ||
1602 | |||
1603 | inc_rfc1001_len(&req->hdr, wdata->bytes - 1 /* Buffer */); | ||
1604 | |||
1605 | kref_get(&wdata->refcount); | ||
1606 | rc = cifs_call_async(tcon->ses->server, &rqst, NULL, | ||
1607 | smb2_writev_callback, wdata, 0); | ||
1608 | |||
1609 | if (rc) { | ||
1610 | kref_put(&wdata->refcount, cifs_writedata_release); | ||
1611 | cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); | ||
1612 | } | ||
1613 | |||
1614 | async_writev_out: | ||
1615 | cifs_small_buf_release(req); | ||
1616 | return rc; | ||
1617 | } | ||
1618 | |||
1619 | /* | ||
1620 | * SMB2_write function gets iov pointer to kvec array with n_vec as a length. | ||
1621 | * The length field from io_parms must be at least 1 and indicates a number of | ||
1622 | * elements with data to write that begins with position 1 in iov array. All | ||
1623 | * data length is specified by count. | ||
1624 | */ | ||
1625 | int | ||
1626 | SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms, | ||
1627 | unsigned int *nbytes, struct kvec *iov, int n_vec) | ||
1628 | { | ||
1629 | int rc = 0; | ||
1630 | struct smb2_write_req *req = NULL; | ||
1631 | struct smb2_write_rsp *rsp = NULL; | ||
1632 | int resp_buftype; | ||
1633 | *nbytes = 0; | ||
1634 | |||
1635 | if (n_vec < 1) | ||
1636 | return rc; | ||
1637 | |||
1638 | rc = small_smb2_init(SMB2_WRITE, io_parms->tcon, (void **) &req); | ||
1639 | if (rc) | ||
1640 | return rc; | ||
1641 | |||
1642 | if (io_parms->tcon->ses->server == NULL) | ||
1643 | return -ECONNABORTED; | ||
1644 | |||
1645 | req->hdr.ProcessId = cpu_to_le32(io_parms->pid); | ||
1646 | |||
1647 | req->PersistentFileId = io_parms->persistent_fid; | ||
1648 | req->VolatileFileId = io_parms->volatile_fid; | ||
1649 | req->WriteChannelInfoOffset = 0; | ||
1650 | req->WriteChannelInfoLength = 0; | ||
1651 | req->Channel = 0; | ||
1652 | req->Length = cpu_to_le32(io_parms->length); | ||
1653 | req->Offset = cpu_to_le64(io_parms->offset); | ||
1654 | /* 4 for rfc1002 length field */ | ||
1655 | req->DataOffset = cpu_to_le16( | ||
1656 | offsetof(struct smb2_write_req, Buffer) - 4); | ||
1657 | req->RemainingBytes = 0; | ||
1658 | |||
1659 | iov[0].iov_base = (char *)req; | ||
1660 | /* 4 for rfc1002 length field and 1 for Buffer */ | ||
1661 | iov[0].iov_len = get_rfc1002_length(req) + 4 - 1; | ||
1662 | |||
1663 | /* length of entire message including data to be written */ | ||
1664 | inc_rfc1001_len(req, io_parms->length - 1 /* Buffer */); | ||
1665 | |||
1666 | rc = SendReceive2(xid, io_parms->tcon->ses, iov, n_vec + 1, | ||
1667 | &resp_buftype, 0); | ||
1668 | rsp = (struct smb2_write_rsp *)iov[0].iov_base; | ||
1669 | |||
1670 | if (rc) { | ||
1671 | cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE); | ||
1672 | cERROR(1, "Send error in write = %d", rc); | ||
1673 | } else | ||
1674 | *nbytes = le32_to_cpu(rsp->DataLength); | ||
1675 | |||
1676 | free_rsp_buf(resp_buftype, rsp); | ||
1677 | return rc; | ||
1678 | } | ||
1679 | |||
1680 | static unsigned int | ||
1681 | num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size) | ||
1682 | { | ||
1683 | int len; | ||
1684 | unsigned int entrycount = 0; | ||
1685 | unsigned int next_offset = 0; | ||
1686 | FILE_DIRECTORY_INFO *entryptr; | ||
1687 | |||
1688 | if (bufstart == NULL) | ||
1689 | return 0; | ||
1690 | |||
1691 | entryptr = (FILE_DIRECTORY_INFO *)bufstart; | ||
1692 | |||
1693 | while (1) { | ||
1694 | entryptr = (FILE_DIRECTORY_INFO *) | ||
1695 | ((char *)entryptr + next_offset); | ||
1696 | |||
1697 | if ((char *)entryptr + size > end_of_buf) { | ||
1698 | cERROR(1, "malformed search entry would overflow"); | ||
1699 | break; | ||
1700 | } | ||
1701 | |||
1702 | len = le32_to_cpu(entryptr->FileNameLength); | ||
1703 | if ((char *)entryptr + len + size > end_of_buf) { | ||
1704 | cERROR(1, "directory entry name would overflow frame " | ||
1705 | "end of buf %p", end_of_buf); | ||
1706 | break; | ||
1707 | } | ||
1708 | |||
1709 | *lastentry = (char *)entryptr; | ||
1710 | entrycount++; | ||
1711 | |||
1712 | next_offset = le32_to_cpu(entryptr->NextEntryOffset); | ||
1713 | if (!next_offset) | ||
1714 | break; | ||
1715 | } | ||
1716 | |||
1717 | return entrycount; | ||
1718 | } | ||
1719 | |||
1720 | /* | ||
1721 | * Readdir/FindFirst | ||
1722 | */ | ||
1723 | int | ||
1724 | SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, | ||
1725 | u64 persistent_fid, u64 volatile_fid, int index, | ||
1726 | struct cifs_search_info *srch_inf) | ||
1727 | { | ||
1728 | struct smb2_query_directory_req *req; | ||
1729 | struct smb2_query_directory_rsp *rsp = NULL; | ||
1730 | struct kvec iov[2]; | ||
1731 | int rc = 0; | ||
1732 | int len; | ||
1733 | int resp_buftype; | ||
1734 | unsigned char *bufptr; | ||
1735 | struct TCP_Server_Info *server; | ||
1736 | struct cifs_ses *ses = tcon->ses; | ||
1737 | __le16 asteriks = cpu_to_le16('*'); | ||
1738 | char *end_of_smb; | ||
1739 | unsigned int output_size = CIFSMaxBufSize; | ||
1740 | size_t info_buf_size; | ||
1741 | |||
1742 | if (ses && (ses->server)) | ||
1743 | server = ses->server; | ||
1744 | else | ||
1745 | return -EIO; | ||
1746 | |||
1747 | rc = small_smb2_init(SMB2_QUERY_DIRECTORY, tcon, (void **) &req); | ||
1748 | if (rc) | ||
1749 | return rc; | ||
1750 | |||
1751 | switch (srch_inf->info_level) { | ||
1752 | case SMB_FIND_FILE_DIRECTORY_INFO: | ||
1753 | req->FileInformationClass = FILE_DIRECTORY_INFORMATION; | ||
1754 | info_buf_size = sizeof(FILE_DIRECTORY_INFO) - 1; | ||
1755 | break; | ||
1756 | case SMB_FIND_FILE_ID_FULL_DIR_INFO: | ||
1757 | req->FileInformationClass = FILEID_FULL_DIRECTORY_INFORMATION; | ||
1758 | info_buf_size = sizeof(SEARCH_ID_FULL_DIR_INFO) - 1; | ||
1759 | break; | ||
1760 | default: | ||
1761 | cERROR(1, "info level %u isn't supported", | ||
1762 | srch_inf->info_level); | ||
1763 | rc = -EINVAL; | ||
1764 | goto qdir_exit; | ||
1765 | } | ||
1766 | |||
1767 | req->FileIndex = cpu_to_le32(index); | ||
1768 | req->PersistentFileId = persistent_fid; | ||
1769 | req->VolatileFileId = volatile_fid; | ||
1770 | |||
1771 | len = 0x2; | ||
1772 | bufptr = req->Buffer; | ||
1773 | memcpy(bufptr, &asteriks, len); | ||
1774 | |||
1775 | req->FileNameOffset = | ||
1776 | cpu_to_le16(sizeof(struct smb2_query_directory_req) - 1 - 4); | ||
1777 | req->FileNameLength = cpu_to_le16(len); | ||
1778 | /* | ||
1779 | * BB could be 30 bytes or so longer if we used SMB2 specific | ||
1780 | * buffer lengths, but this is safe and close enough. | ||
1781 | */ | ||
1782 | output_size = min_t(unsigned int, output_size, server->maxBuf); | ||
1783 | output_size = min_t(unsigned int, output_size, 2 << 15); | ||
1784 | req->OutputBufferLength = cpu_to_le32(output_size); | ||
1785 | |||
1786 | iov[0].iov_base = (char *)req; | ||
1787 | /* 4 for RFC1001 length and 1 for Buffer */ | ||
1788 | iov[0].iov_len = get_rfc1002_length(req) + 4 - 1; | ||
1789 | |||
1790 | iov[1].iov_base = (char *)(req->Buffer); | ||
1791 | iov[1].iov_len = len; | ||
1792 | |||
1793 | inc_rfc1001_len(req, len - 1 /* Buffer */); | ||
1794 | |||
1795 | rc = SendReceive2(xid, ses, iov, 2, &resp_buftype, 0); | ||
1796 | rsp = (struct smb2_query_directory_rsp *)iov[0].iov_base; | ||
1797 | |||
1798 | if (rc) { | ||
1799 | cifs_stats_fail_inc(tcon, SMB2_QUERY_DIRECTORY_HE); | ||
1800 | goto qdir_exit; | ||
1801 | } | ||
1802 | |||
1803 | rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset), | ||
1804 | le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr, | ||
1805 | info_buf_size); | ||
1806 | if (rc) | ||
1807 | goto qdir_exit; | ||
1808 | |||
1809 | srch_inf->unicode = true; | ||
1810 | |||
1811 | if (srch_inf->ntwrk_buf_start) { | ||
1812 | if (srch_inf->smallBuf) | ||
1813 | cifs_small_buf_release(srch_inf->ntwrk_buf_start); | ||
1814 | else | ||
1815 | cifs_buf_release(srch_inf->ntwrk_buf_start); | ||
1816 | } | ||
1817 | srch_inf->ntwrk_buf_start = (char *)rsp; | ||
1818 | srch_inf->srch_entries_start = srch_inf->last_entry = 4 /* rfclen */ + | ||
1819 | (char *)&rsp->hdr + le16_to_cpu(rsp->OutputBufferOffset); | ||
1820 | /* 4 for rfc1002 length field */ | ||
1821 | end_of_smb = get_rfc1002_length(rsp) + 4 + (char *)&rsp->hdr; | ||
1822 | srch_inf->entries_in_buffer = | ||
1823 | num_entries(srch_inf->srch_entries_start, end_of_smb, | ||
1824 | &srch_inf->last_entry, info_buf_size); | ||
1825 | srch_inf->index_of_last_entry += srch_inf->entries_in_buffer; | ||
1826 | cFYI(1, "num entries %d last_index %lld srch start %p srch end %p", | ||
1827 | srch_inf->entries_in_buffer, srch_inf->index_of_last_entry, | ||
1828 | srch_inf->srch_entries_start, srch_inf->last_entry); | ||
1829 | if (resp_buftype == CIFS_LARGE_BUFFER) | ||
1830 | srch_inf->smallBuf = false; | ||
1831 | else if (resp_buftype == CIFS_SMALL_BUFFER) | ||
1832 | srch_inf->smallBuf = true; | ||
1833 | else | ||
1834 | cERROR(1, "illegal search buffer type"); | ||
1835 | |||
1836 | if (rsp->hdr.Status == STATUS_NO_MORE_FILES) | ||
1837 | srch_inf->endOfSearch = 1; | ||
1838 | else | ||
1839 | srch_inf->endOfSearch = 0; | ||
1840 | |||
1841 | return rc; | ||
1842 | |||
1843 | qdir_exit: | ||
1844 | free_rsp_buf(resp_buftype, rsp); | ||
1845 | return rc; | ||
1846 | } | ||
1847 | |||
1848 | static int | ||
1849 | send_set_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
1850 | u64 persistent_fid, u64 volatile_fid, u32 pid, int info_class, | ||
1851 | unsigned int num, void **data, unsigned int *size) | ||
1852 | { | ||
1853 | struct smb2_set_info_req *req; | ||
1854 | struct smb2_set_info_rsp *rsp = NULL; | ||
1855 | struct kvec *iov; | ||
1856 | int rc = 0; | ||
1857 | int resp_buftype; | ||
1858 | unsigned int i; | ||
1859 | struct TCP_Server_Info *server; | ||
1860 | struct cifs_ses *ses = tcon->ses; | ||
1861 | |||
1862 | if (ses && (ses->server)) | ||
1863 | server = ses->server; | ||
1864 | else | ||
1865 | return -EIO; | ||
1866 | |||
1867 | if (!num) | ||
1868 | return -EINVAL; | ||
1869 | |||
1870 | iov = kmalloc(sizeof(struct kvec) * num, GFP_KERNEL); | ||
1871 | if (!iov) | ||
1872 | return -ENOMEM; | ||
1873 | |||
1874 | rc = small_smb2_init(SMB2_SET_INFO, tcon, (void **) &req); | ||
1875 | if (rc) { | ||
1876 | kfree(iov); | ||
1877 | return rc; | ||
1878 | } | ||
1879 | |||
1880 | req->hdr.ProcessId = cpu_to_le32(pid); | ||
1881 | |||
1882 | req->InfoType = SMB2_O_INFO_FILE; | ||
1883 | req->FileInfoClass = info_class; | ||
1884 | req->PersistentFileId = persistent_fid; | ||
1885 | req->VolatileFileId = volatile_fid; | ||
1886 | |||
1887 | /* 4 for RFC1001 length and 1 for Buffer */ | ||
1888 | req->BufferOffset = | ||
1889 | cpu_to_le16(sizeof(struct smb2_set_info_req) - 1 - 4); | ||
1890 | req->BufferLength = cpu_to_le32(*size); | ||
1891 | |||
1892 | inc_rfc1001_len(req, *size - 1 /* Buffer */); | ||
1893 | |||
1894 | memcpy(req->Buffer, *data, *size); | ||
1895 | |||
1896 | iov[0].iov_base = (char *)req; | ||
1897 | /* 4 for RFC1001 length */ | ||
1898 | iov[0].iov_len = get_rfc1002_length(req) + 4; | ||
1899 | |||
1900 | for (i = 1; i < num; i++) { | ||
1901 | inc_rfc1001_len(req, size[i]); | ||
1902 | le32_add_cpu(&req->BufferLength, size[i]); | ||
1903 | iov[i].iov_base = (char *)data[i]; | ||
1904 | iov[i].iov_len = size[i]; | ||
1905 | } | ||
1906 | |||
1907 | rc = SendReceive2(xid, ses, iov, num, &resp_buftype, 0); | ||
1908 | rsp = (struct smb2_set_info_rsp *)iov[0].iov_base; | ||
1909 | |||
1910 | if (rc != 0) { | ||
1911 | cifs_stats_fail_inc(tcon, SMB2_SET_INFO_HE); | ||
1912 | goto out; | ||
1913 | } | ||
1914 | out: | ||
1915 | free_rsp_buf(resp_buftype, rsp); | ||
1916 | kfree(iov); | ||
1917 | return rc; | ||
1918 | } | ||
1919 | |||
1920 | int | ||
1921 | SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon, | ||
1922 | u64 persistent_fid, u64 volatile_fid, __le16 *target_file) | ||
1923 | { | ||
1924 | struct smb2_file_rename_info info; | ||
1925 | void **data; | ||
1926 | unsigned int size[2]; | ||
1927 | int rc; | ||
1928 | int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX)); | ||
1929 | |||
1930 | data = kmalloc(sizeof(void *) * 2, GFP_KERNEL); | ||
1931 | if (!data) | ||
1932 | return -ENOMEM; | ||
1933 | |||
1934 | info.ReplaceIfExists = 1; /* 1 = replace existing target with new */ | ||
1935 | /* 0 = fail if target already exists */ | ||
1936 | info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */ | ||
1937 | info.FileNameLength = cpu_to_le32(len); | ||
1938 | |||
1939 | data[0] = &info; | ||
1940 | size[0] = sizeof(struct smb2_file_rename_info); | ||
1941 | |||
1942 | data[1] = target_file; | ||
1943 | size[1] = len + 2 /* null */; | ||
1944 | |||
1945 | rc = send_set_info(xid, tcon, persistent_fid, volatile_fid, | ||
1946 | current->tgid, FILE_RENAME_INFORMATION, 2, data, | ||
1947 | size); | ||
1948 | kfree(data); | ||
1949 | return rc; | ||
1950 | } | ||
1951 | |||
1952 | int | ||
1953 | SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon, | ||
1954 | u64 persistent_fid, u64 volatile_fid, __le16 *target_file) | ||
1955 | { | ||
1956 | struct smb2_file_link_info info; | ||
1957 | void **data; | ||
1958 | unsigned int size[2]; | ||
1959 | int rc; | ||
1960 | int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX)); | ||
1961 | |||
1962 | data = kmalloc(sizeof(void *) * 2, GFP_KERNEL); | ||
1963 | if (!data) | ||
1964 | return -ENOMEM; | ||
1965 | |||
1966 | info.ReplaceIfExists = 0; /* 1 = replace existing link with new */ | ||
1967 | /* 0 = fail if link already exists */ | ||
1968 | info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */ | ||
1969 | info.FileNameLength = cpu_to_le32(len); | ||
1970 | |||
1971 | data[0] = &info; | ||
1972 | size[0] = sizeof(struct smb2_file_link_info); | ||
1973 | |||
1974 | data[1] = target_file; | ||
1975 | size[1] = len + 2 /* null */; | ||
1976 | |||
1977 | rc = send_set_info(xid, tcon, persistent_fid, volatile_fid, | ||
1978 | current->tgid, FILE_LINK_INFORMATION, 2, data, size); | ||
1979 | kfree(data); | ||
1980 | return rc; | ||
1981 | } | ||
1982 | |||
1983 | int | ||
1984 | SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, | ||
1985 | u64 volatile_fid, u32 pid, __le64 *eof) | ||
1986 | { | ||
1987 | struct smb2_file_eof_info info; | ||
1988 | void *data; | ||
1989 | unsigned int size; | ||
1990 | |||
1991 | info.EndOfFile = *eof; | ||
1992 | |||
1993 | data = &info; | ||
1994 | size = sizeof(struct smb2_file_eof_info); | ||
1995 | |||
1996 | return send_set_info(xid, tcon, persistent_fid, volatile_fid, pid, | ||
1997 | FILE_END_OF_FILE_INFORMATION, 1, &data, &size); | ||
1998 | } | ||
1999 | |||
2000 | int | ||
2001 | SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
2002 | u64 persistent_fid, u64 volatile_fid, FILE_BASIC_INFO *buf) | ||
2003 | { | ||
2004 | unsigned int size; | ||
2005 | size = sizeof(FILE_BASIC_INFO); | ||
2006 | return send_set_info(xid, tcon, persistent_fid, volatile_fid, | ||
2007 | current->tgid, FILE_BASIC_INFORMATION, 1, | ||
2008 | (void **)&buf, &size); | ||
2009 | } | ||
2010 | |||
2011 | int | ||
2012 | SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, | ||
2013 | const u64 persistent_fid, const u64 volatile_fid, | ||
2014 | __u8 oplock_level) | ||
2015 | { | ||
2016 | int rc; | ||
2017 | struct smb2_oplock_break *req = NULL; | ||
2018 | |||
2019 | cFYI(1, "SMB2_oplock_break"); | ||
2020 | rc = small_smb2_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req); | ||
2021 | |||
2022 | if (rc) | ||
2023 | return rc; | ||
2024 | |||
2025 | req->VolatileFid = volatile_fid; | ||
2026 | req->PersistentFid = persistent_fid; | ||
2027 | req->OplockLevel = oplock_level; | ||
2028 | req->hdr.CreditRequest = cpu_to_le16(1); | ||
2029 | |||
2030 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP); | ||
2031 | /* SMB2 buffer freed by function above */ | ||
2032 | |||
2033 | if (rc) { | ||
2034 | cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE); | ||
2035 | cFYI(1, "Send error in Oplock Break = %d", rc); | ||
2036 | } | ||
2037 | |||
2038 | return rc; | ||
2039 | } | ||
2040 | |||
2041 | static void | ||
2042 | copy_fs_info_to_kstatfs(struct smb2_fs_full_size_info *pfs_inf, | ||
2043 | struct kstatfs *kst) | ||
2044 | { | ||
2045 | kst->f_bsize = le32_to_cpu(pfs_inf->BytesPerSector) * | ||
2046 | le32_to_cpu(pfs_inf->SectorsPerAllocationUnit); | ||
2047 | kst->f_blocks = le64_to_cpu(pfs_inf->TotalAllocationUnits); | ||
2048 | kst->f_bfree = le64_to_cpu(pfs_inf->ActualAvailableAllocationUnits); | ||
2049 | kst->f_bavail = le64_to_cpu(pfs_inf->CallerAvailableAllocationUnits); | ||
2050 | return; | ||
2051 | } | ||
2052 | |||
2053 | static int | ||
2054 | build_qfs_info_req(struct kvec *iov, struct cifs_tcon *tcon, int level, | ||
2055 | int outbuf_len, u64 persistent_fid, u64 volatile_fid) | ||
2056 | { | ||
2057 | int rc; | ||
2058 | struct smb2_query_info_req *req; | ||
2059 | |||
2060 | cFYI(1, "Query FSInfo level %d", level); | ||
2061 | |||
2062 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) | ||
2063 | return -EIO; | ||
2064 | |||
2065 | rc = small_smb2_init(SMB2_QUERY_INFO, tcon, (void **) &req); | ||
2066 | if (rc) | ||
2067 | return rc; | ||
2068 | |||
2069 | req->InfoType = SMB2_O_INFO_FILESYSTEM; | ||
2070 | req->FileInfoClass = level; | ||
2071 | req->PersistentFileId = persistent_fid; | ||
2072 | req->VolatileFileId = volatile_fid; | ||
2073 | /* 4 for rfc1002 length field and 1 for pad */ | ||
2074 | req->InputBufferOffset = | ||
2075 | cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4); | ||
2076 | req->OutputBufferLength = cpu_to_le32( | ||
2077 | outbuf_len + sizeof(struct smb2_query_info_rsp) - 1 - 4); | ||
2078 | |||
2079 | iov->iov_base = (char *)req; | ||
2080 | /* 4 for rfc1002 length field */ | ||
2081 | iov->iov_len = get_rfc1002_length(req) + 4; | ||
2082 | return 0; | ||
2083 | } | ||
2084 | |||
2085 | int | ||
2086 | SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
2087 | u64 persistent_fid, u64 volatile_fid, struct kstatfs *fsdata) | ||
2088 | { | ||
2089 | struct smb2_query_info_rsp *rsp = NULL; | ||
2090 | struct kvec iov; | ||
2091 | int rc = 0; | ||
2092 | int resp_buftype; | ||
2093 | struct cifs_ses *ses = tcon->ses; | ||
2094 | struct smb2_fs_full_size_info *info = NULL; | ||
2095 | |||
2096 | rc = build_qfs_info_req(&iov, tcon, FS_FULL_SIZE_INFORMATION, | ||
2097 | sizeof(struct smb2_fs_full_size_info), | ||
2098 | persistent_fid, volatile_fid); | ||
2099 | if (rc) | ||
2100 | return rc; | ||
2101 | |||
2102 | rc = SendReceive2(xid, ses, &iov, 1, &resp_buftype, 0); | ||
2103 | if (rc) { | ||
2104 | cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); | ||
2105 | goto qinf_exit; | ||
2106 | } | ||
2107 | rsp = (struct smb2_query_info_rsp *)iov.iov_base; | ||
2108 | |||
2109 | info = (struct smb2_fs_full_size_info *)(4 /* RFC1001 len */ + | ||
2110 | le16_to_cpu(rsp->OutputBufferOffset) + (char *)&rsp->hdr); | ||
2111 | rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset), | ||
2112 | le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr, | ||
2113 | sizeof(struct smb2_fs_full_size_info)); | ||
2114 | if (!rc) | ||
2115 | copy_fs_info_to_kstatfs(info, fsdata); | ||
2116 | |||
2117 | qinf_exit: | ||
2118 | free_rsp_buf(resp_buftype, iov.iov_base); | ||
2119 | return rc; | ||
2120 | } | ||
2121 | |||
2122 | int | ||
2123 | smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon, | ||
2124 | const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid, | ||
2125 | const __u32 num_lock, struct smb2_lock_element *buf) | ||
2126 | { | ||
2127 | int rc = 0; | ||
2128 | struct smb2_lock_req *req = NULL; | ||
2129 | struct kvec iov[2]; | ||
2130 | int resp_buf_type; | ||
2131 | unsigned int count; | ||
2132 | |||
2133 | cFYI(1, "smb2_lockv num lock %d", num_lock); | ||
2134 | |||
2135 | rc = small_smb2_init(SMB2_LOCK, tcon, (void **) &req); | ||
2136 | if (rc) | ||
2137 | return rc; | ||
2138 | |||
2139 | req->hdr.ProcessId = cpu_to_le32(pid); | ||
2140 | req->LockCount = cpu_to_le16(num_lock); | ||
2141 | |||
2142 | req->PersistentFileId = persist_fid; | ||
2143 | req->VolatileFileId = volatile_fid; | ||
2144 | |||
2145 | count = num_lock * sizeof(struct smb2_lock_element); | ||
2146 | inc_rfc1001_len(req, count - sizeof(struct smb2_lock_element)); | ||
2147 | |||
2148 | iov[0].iov_base = (char *)req; | ||
2149 | /* 4 for rfc1002 length field and count for all locks */ | ||
2150 | iov[0].iov_len = get_rfc1002_length(req) + 4 - count; | ||
2151 | iov[1].iov_base = (char *)buf; | ||
2152 | iov[1].iov_len = count; | ||
2153 | |||
2154 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); | ||
2155 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP); | ||
2156 | if (rc) { | ||
2157 | cFYI(1, "Send error in smb2_lockv = %d", rc); | ||
2158 | cifs_stats_fail_inc(tcon, SMB2_LOCK_HE); | ||
2159 | } | ||
2160 | |||
2161 | return rc; | ||
2162 | } | ||
2163 | |||
2164 | int | ||
2165 | SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon, | ||
2166 | const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid, | ||
2167 | const __u64 length, const __u64 offset, const __u32 lock_flags, | ||
2168 | const bool wait) | ||
2169 | { | ||
2170 | struct smb2_lock_element lock; | ||
2171 | |||
2172 | lock.Offset = cpu_to_le64(offset); | ||
2173 | lock.Length = cpu_to_le64(length); | ||
2174 | lock.Flags = cpu_to_le32(lock_flags); | ||
2175 | if (!wait && lock_flags != SMB2_LOCKFLAG_UNLOCK) | ||
2176 | lock.Flags |= cpu_to_le32(SMB2_LOCKFLAG_FAIL_IMMEDIATELY); | ||
2177 | |||
2178 | return smb2_lockv(xid, tcon, persist_fid, volatile_fid, pid, 1, &lock); | ||
2179 | } | ||
2180 | |||
2181 | int | ||
2182 | SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon, | ||
2183 | __u8 *lease_key, const __le32 lease_state) | ||
2184 | { | ||
2185 | int rc; | ||
2186 | struct smb2_lease_ack *req = NULL; | ||
2187 | |||
2188 | cFYI(1, "SMB2_lease_break"); | ||
2189 | rc = small_smb2_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req); | ||
2190 | |||
2191 | if (rc) | ||
2192 | return rc; | ||
2193 | |||
2194 | req->hdr.CreditRequest = cpu_to_le16(1); | ||
2195 | req->StructureSize = cpu_to_le16(36); | ||
2196 | inc_rfc1001_len(req, 12); | ||
2197 | |||
2198 | memcpy(req->LeaseKey, lease_key, 16); | ||
2199 | req->LeaseState = lease_state; | ||
2200 | |||
2201 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP); | ||
2202 | /* SMB2 buffer freed by function above */ | ||
2203 | |||
2204 | if (rc) { | ||
2205 | cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE); | ||
2206 | cFYI(1, "Send error in Lease Break = %d", rc); | ||
2207 | } | ||
2208 | |||
2209 | return rc; | ||
2210 | } | ||
diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h index 15dc8eea8273..4cb4ced258cb 100644 --- a/fs/cifs/smb2pdu.h +++ b/fs/cifs/smb2pdu.h | |||
@@ -150,6 +150,10 @@ struct smb2_err_rsp { | |||
150 | __u8 ErrorData[1]; /* variable length */ | 150 | __u8 ErrorData[1]; /* variable length */ |
151 | } __packed; | 151 | } __packed; |
152 | 152 | ||
153 | #define SMB2_CLIENT_GUID_SIZE 16 | ||
154 | |||
155 | extern __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE]; | ||
156 | |||
153 | struct smb2_negotiate_req { | 157 | struct smb2_negotiate_req { |
154 | struct smb2_hdr hdr; | 158 | struct smb2_hdr hdr; |
155 | __le16 StructureSize; /* Must be 36 */ | 159 | __le16 StructureSize; /* Must be 36 */ |
@@ -157,11 +161,17 @@ struct smb2_negotiate_req { | |||
157 | __le16 SecurityMode; | 161 | __le16 SecurityMode; |
158 | __le16 Reserved; /* MBZ */ | 162 | __le16 Reserved; /* MBZ */ |
159 | __le32 Capabilities; | 163 | __le32 Capabilities; |
160 | __u8 ClientGUID[16]; /* MBZ */ | 164 | __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE]; |
161 | __le64 ClientStartTime; /* MBZ */ | 165 | __le64 ClientStartTime; /* MBZ */ |
162 | __le16 Dialects[2]; /* variable length */ | 166 | __le16 Dialects[1]; /* One dialect (vers=) at a time for now */ |
163 | } __packed; | 167 | } __packed; |
164 | 168 | ||
169 | /* Dialects */ | ||
170 | #define SMB20_PROT_ID 0x0202 | ||
171 | #define SMB21_PROT_ID 0x0210 | ||
172 | #define SMB30_PROT_ID 0x0300 | ||
173 | #define BAD_PROT_ID 0xFFFF | ||
174 | |||
165 | /* SecurityMode flags */ | 175 | /* SecurityMode flags */ |
166 | #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001 | 176 | #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001 |
167 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002 | 177 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002 |
@@ -169,6 +179,10 @@ struct smb2_negotiate_req { | |||
169 | #define SMB2_GLOBAL_CAP_DFS 0x00000001 | 179 | #define SMB2_GLOBAL_CAP_DFS 0x00000001 |
170 | #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */ | 180 | #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */ |
171 | #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */ | 181 | #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */ |
182 | #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */ | ||
183 | #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */ | ||
184 | #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */ | ||
185 | #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */ | ||
172 | /* Internal types */ | 186 | /* Internal types */ |
173 | #define SMB2_NT_FIND 0x00100000 | 187 | #define SMB2_NT_FIND 0x00100000 |
174 | #define SMB2_LARGE_FILES 0x00200000 | 188 | #define SMB2_LARGE_FILES 0x00200000 |
@@ -307,6 +321,8 @@ struct smb2_tree_disconnect_rsp { | |||
307 | #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08 | 321 | #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08 |
308 | #define SMB2_OPLOCK_LEVEL_BATCH 0x09 | 322 | #define SMB2_OPLOCK_LEVEL_BATCH 0x09 |
309 | #define SMB2_OPLOCK_LEVEL_LEASE 0xFF | 323 | #define SMB2_OPLOCK_LEVEL_LEASE 0xFF |
324 | /* Non-spec internal type */ | ||
325 | #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99 | ||
310 | 326 | ||
311 | /* Desired Access Flags */ | 327 | /* Desired Access Flags */ |
312 | #define FILE_READ_DATA_LE cpu_to_le32(0x00000001) | 328 | #define FILE_READ_DATA_LE cpu_to_le32(0x00000001) |
@@ -404,7 +420,7 @@ struct smb2_create_req { | |||
404 | __le16 NameLength; | 420 | __le16 NameLength; |
405 | __le32 CreateContextsOffset; | 421 | __le32 CreateContextsOffset; |
406 | __le32 CreateContextsLength; | 422 | __le32 CreateContextsLength; |
407 | __u8 Buffer[1]; | 423 | __u8 Buffer[8]; |
408 | } __packed; | 424 | } __packed; |
409 | 425 | ||
410 | struct smb2_create_rsp { | 426 | struct smb2_create_rsp { |
@@ -428,6 +444,39 @@ struct smb2_create_rsp { | |||
428 | __u8 Buffer[1]; | 444 | __u8 Buffer[1]; |
429 | } __packed; | 445 | } __packed; |
430 | 446 | ||
447 | struct create_context { | ||
448 | __le32 Next; | ||
449 | __le16 NameOffset; | ||
450 | __le16 NameLength; | ||
451 | __le16 Reserved; | ||
452 | __le16 DataOffset; | ||
453 | __le32 DataLength; | ||
454 | __u8 Buffer[0]; | ||
455 | } __packed; | ||
456 | |||
457 | #define SMB2_LEASE_NONE __constant_cpu_to_le32(0x00) | ||
458 | #define SMB2_LEASE_READ_CACHING __constant_cpu_to_le32(0x01) | ||
459 | #define SMB2_LEASE_HANDLE_CACHING __constant_cpu_to_le32(0x02) | ||
460 | #define SMB2_LEASE_WRITE_CACHING __constant_cpu_to_le32(0x04) | ||
461 | |||
462 | #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS __constant_cpu_to_le32(0x02) | ||
463 | |||
464 | #define SMB2_LEASE_KEY_SIZE 16 | ||
465 | |||
466 | struct lease_context { | ||
467 | __le64 LeaseKeyLow; | ||
468 | __le64 LeaseKeyHigh; | ||
469 | __le32 LeaseState; | ||
470 | __le32 LeaseFlags; | ||
471 | __le64 LeaseDuration; | ||
472 | } __packed; | ||
473 | |||
474 | struct create_lease { | ||
475 | struct create_context ccontext; | ||
476 | __u8 Name[8]; | ||
477 | struct lease_context lcontext; | ||
478 | } __packed; | ||
479 | |||
431 | /* Currently defined values for close flags */ | 480 | /* Currently defined values for close flags */ |
432 | #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001) | 481 | #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001) |
433 | struct smb2_close_req { | 482 | struct smb2_close_req { |
@@ -453,6 +502,108 @@ struct smb2_close_rsp { | |||
453 | __le32 Attributes; | 502 | __le32 Attributes; |
454 | } __packed; | 503 | } __packed; |
455 | 504 | ||
505 | struct smb2_flush_req { | ||
506 | struct smb2_hdr hdr; | ||
507 | __le16 StructureSize; /* Must be 24 */ | ||
508 | __le16 Reserved1; | ||
509 | __le32 Reserved2; | ||
510 | __u64 PersistentFileId; /* opaque endianness */ | ||
511 | __u64 VolatileFileId; /* opaque endianness */ | ||
512 | } __packed; | ||
513 | |||
514 | struct smb2_flush_rsp { | ||
515 | struct smb2_hdr hdr; | ||
516 | __le16 StructureSize; | ||
517 | __le16 Reserved; | ||
518 | } __packed; | ||
519 | |||
520 | struct smb2_read_req { | ||
521 | struct smb2_hdr hdr; | ||
522 | __le16 StructureSize; /* Must be 49 */ | ||
523 | __u8 Padding; /* offset from start of SMB2 header to place read */ | ||
524 | __u8 Reserved; | ||
525 | __le32 Length; | ||
526 | __le64 Offset; | ||
527 | __u64 PersistentFileId; /* opaque endianness */ | ||
528 | __u64 VolatileFileId; /* opaque endianness */ | ||
529 | __le32 MinimumCount; | ||
530 | __le32 Channel; /* Reserved MBZ */ | ||
531 | __le32 RemainingBytes; | ||
532 | __le16 ReadChannelInfoOffset; /* Reserved MBZ */ | ||
533 | __le16 ReadChannelInfoLength; /* Reserved MBZ */ | ||
534 | __u8 Buffer[1]; | ||
535 | } __packed; | ||
536 | |||
537 | struct smb2_read_rsp { | ||
538 | struct smb2_hdr hdr; | ||
539 | __le16 StructureSize; /* Must be 17 */ | ||
540 | __u8 DataOffset; | ||
541 | __u8 Reserved; | ||
542 | __le32 DataLength; | ||
543 | __le32 DataRemaining; | ||
544 | __u32 Reserved2; | ||
545 | __u8 Buffer[1]; | ||
546 | } __packed; | ||
547 | |||
548 | /* For write request Flags field below the following flag is defined: */ | ||
549 | #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 | ||
550 | |||
551 | struct smb2_write_req { | ||
552 | struct smb2_hdr hdr; | ||
553 | __le16 StructureSize; /* Must be 49 */ | ||
554 | __le16 DataOffset; /* offset from start of SMB2 header to write data */ | ||
555 | __le32 Length; | ||
556 | __le64 Offset; | ||
557 | __u64 PersistentFileId; /* opaque endianness */ | ||
558 | __u64 VolatileFileId; /* opaque endianness */ | ||
559 | __le32 Channel; /* Reserved MBZ */ | ||
560 | __le32 RemainingBytes; | ||
561 | __le16 WriteChannelInfoOffset; /* Reserved MBZ */ | ||
562 | __le16 WriteChannelInfoLength; /* Reserved MBZ */ | ||
563 | __le32 Flags; | ||
564 | __u8 Buffer[1]; | ||
565 | } __packed; | ||
566 | |||
567 | struct smb2_write_rsp { | ||
568 | struct smb2_hdr hdr; | ||
569 | __le16 StructureSize; /* Must be 17 */ | ||
570 | __u8 DataOffset; | ||
571 | __u8 Reserved; | ||
572 | __le32 DataLength; | ||
573 | __le32 DataRemaining; | ||
574 | __u32 Reserved2; | ||
575 | __u8 Buffer[1]; | ||
576 | } __packed; | ||
577 | |||
578 | #define SMB2_LOCKFLAG_SHARED_LOCK 0x0001 | ||
579 | #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002 | ||
580 | #define SMB2_LOCKFLAG_UNLOCK 0x0004 | ||
581 | #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010 | ||
582 | |||
583 | struct smb2_lock_element { | ||
584 | __le64 Offset; | ||
585 | __le64 Length; | ||
586 | __le32 Flags; | ||
587 | __le32 Reserved; | ||
588 | } __packed; | ||
589 | |||
590 | struct smb2_lock_req { | ||
591 | struct smb2_hdr hdr; | ||
592 | __le16 StructureSize; /* Must be 48 */ | ||
593 | __le16 LockCount; | ||
594 | __le32 Reserved; | ||
595 | __u64 PersistentFileId; /* opaque endianness */ | ||
596 | __u64 VolatileFileId; /* opaque endianness */ | ||
597 | /* Followed by at least one */ | ||
598 | struct smb2_lock_element locks[1]; | ||
599 | } __packed; | ||
600 | |||
601 | struct smb2_lock_rsp { | ||
602 | struct smb2_hdr hdr; | ||
603 | __le16 StructureSize; /* Must be 4 */ | ||
604 | __le16 Reserved; | ||
605 | } __packed; | ||
606 | |||
456 | struct smb2_echo_req { | 607 | struct smb2_echo_req { |
457 | struct smb2_hdr hdr; | 608 | struct smb2_hdr hdr; |
458 | __le16 StructureSize; /* Must be 4 */ | 609 | __le16 StructureSize; /* Must be 4 */ |
@@ -465,6 +616,34 @@ struct smb2_echo_rsp { | |||
465 | __u16 Reserved; | 616 | __u16 Reserved; |
466 | } __packed; | 617 | } __packed; |
467 | 618 | ||
619 | /* search (query_directory) Flags field */ | ||
620 | #define SMB2_RESTART_SCANS 0x01 | ||
621 | #define SMB2_RETURN_SINGLE_ENTRY 0x02 | ||
622 | #define SMB2_INDEX_SPECIFIED 0x04 | ||
623 | #define SMB2_REOPEN 0x10 | ||
624 | |||
625 | struct smb2_query_directory_req { | ||
626 | struct smb2_hdr hdr; | ||
627 | __le16 StructureSize; /* Must be 33 */ | ||
628 | __u8 FileInformationClass; | ||
629 | __u8 Flags; | ||
630 | __le32 FileIndex; | ||
631 | __u64 PersistentFileId; /* opaque endianness */ | ||
632 | __u64 VolatileFileId; /* opaque endianness */ | ||
633 | __le16 FileNameOffset; | ||
634 | __le16 FileNameLength; | ||
635 | __le32 OutputBufferLength; | ||
636 | __u8 Buffer[1]; | ||
637 | } __packed; | ||
638 | |||
639 | struct smb2_query_directory_rsp { | ||
640 | struct smb2_hdr hdr; | ||
641 | __le16 StructureSize; /* Must be 9 */ | ||
642 | __le16 OutputBufferOffset; | ||
643 | __le32 OutputBufferLength; | ||
644 | __u8 Buffer[1]; | ||
645 | } __packed; | ||
646 | |||
468 | /* Possible InfoType values */ | 647 | /* Possible InfoType values */ |
469 | #define SMB2_O_INFO_FILE 0x01 | 648 | #define SMB2_O_INFO_FILE 0x01 |
470 | #define SMB2_O_INFO_FILESYSTEM 0x02 | 649 | #define SMB2_O_INFO_FILESYSTEM 0x02 |
@@ -495,11 +674,84 @@ struct smb2_query_info_rsp { | |||
495 | __u8 Buffer[1]; | 674 | __u8 Buffer[1]; |
496 | } __packed; | 675 | } __packed; |
497 | 676 | ||
677 | struct smb2_set_info_req { | ||
678 | struct smb2_hdr hdr; | ||
679 | __le16 StructureSize; /* Must be 33 */ | ||
680 | __u8 InfoType; | ||
681 | __u8 FileInfoClass; | ||
682 | __le32 BufferLength; | ||
683 | __le16 BufferOffset; | ||
684 | __u16 Reserved; | ||
685 | __le32 AdditionalInformation; | ||
686 | __u64 PersistentFileId; /* opaque endianness */ | ||
687 | __u64 VolatileFileId; /* opaque endianness */ | ||
688 | __u8 Buffer[1]; | ||
689 | } __packed; | ||
690 | |||
691 | struct smb2_set_info_rsp { | ||
692 | struct smb2_hdr hdr; | ||
693 | __le16 StructureSize; /* Must be 2 */ | ||
694 | } __packed; | ||
695 | |||
696 | struct smb2_oplock_break { | ||
697 | struct smb2_hdr hdr; | ||
698 | __le16 StructureSize; /* Must be 24 */ | ||
699 | __u8 OplockLevel; | ||
700 | __u8 Reserved; | ||
701 | __le32 Reserved2; | ||
702 | __u64 PersistentFid; | ||
703 | __u64 VolatileFid; | ||
704 | } __packed; | ||
705 | |||
706 | #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01) | ||
707 | |||
708 | struct smb2_lease_break { | ||
709 | struct smb2_hdr hdr; | ||
710 | __le16 StructureSize; /* Must be 44 */ | ||
711 | __le16 Reserved; | ||
712 | __le32 Flags; | ||
713 | __u8 LeaseKey[16]; | ||
714 | __le32 CurrentLeaseState; | ||
715 | __le32 NewLeaseState; | ||
716 | __le32 BreakReason; | ||
717 | __le32 AccessMaskHint; | ||
718 | __le32 ShareMaskHint; | ||
719 | } __packed; | ||
720 | |||
721 | struct smb2_lease_ack { | ||
722 | struct smb2_hdr hdr; | ||
723 | __le16 StructureSize; /* Must be 36 */ | ||
724 | __le16 Reserved; | ||
725 | __le32 Flags; | ||
726 | __u8 LeaseKey[16]; | ||
727 | __le32 LeaseState; | ||
728 | __le64 LeaseDuration; | ||
729 | } __packed; | ||
730 | |||
498 | /* | 731 | /* |
499 | * PDU infolevel structure definitions | 732 | * PDU infolevel structure definitions |
500 | * BB consider moving to a different header | 733 | * BB consider moving to a different header |
501 | */ | 734 | */ |
502 | 735 | ||
736 | /* File System Information Classes */ | ||
737 | #define FS_VOLUME_INFORMATION 1 /* Query */ | ||
738 | #define FS_LABEL_INFORMATION 2 /* Set */ | ||
739 | #define FS_SIZE_INFORMATION 3 /* Query */ | ||
740 | #define FS_DEVICE_INFORMATION 4 /* Query */ | ||
741 | #define FS_ATTRIBUTE_INFORMATION 5 /* Query */ | ||
742 | #define FS_CONTROL_INFORMATION 6 /* Query, Set */ | ||
743 | #define FS_FULL_SIZE_INFORMATION 7 /* Query */ | ||
744 | #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */ | ||
745 | #define FS_DRIVER_PATH_INFORMATION 9 /* Query */ | ||
746 | |||
747 | struct smb2_fs_full_size_info { | ||
748 | __le64 TotalAllocationUnits; | ||
749 | __le64 CallerAvailableAllocationUnits; | ||
750 | __le64 ActualAvailableAllocationUnits; | ||
751 | __le32 SectorsPerAllocationUnit; | ||
752 | __le32 BytesPerSector; | ||
753 | } __packed; | ||
754 | |||
503 | /* partial list of QUERY INFO levels */ | 755 | /* partial list of QUERY INFO levels */ |
504 | #define FILE_DIRECTORY_INFORMATION 1 | 756 | #define FILE_DIRECTORY_INFORMATION 1 |
505 | #define FILE_FULL_DIRECTORY_INFORMATION 2 | 757 | #define FILE_FULL_DIRECTORY_INFORMATION 2 |
@@ -548,6 +800,28 @@ struct smb2_query_info_rsp { | |||
548 | #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50 | 800 | #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50 |
549 | #define FILE_STANDARD_LINK_INFORMATION 54 | 801 | #define FILE_STANDARD_LINK_INFORMATION 54 |
550 | 802 | ||
803 | struct smb2_file_internal_info { | ||
804 | __le64 IndexNumber; | ||
805 | } __packed; /* level 6 Query */ | ||
806 | |||
807 | struct smb2_file_rename_info { /* encoding of request for level 10 */ | ||
808 | __u8 ReplaceIfExists; /* 1 = replace existing target with new */ | ||
809 | /* 0 = fail if target already exists */ | ||
810 | __u8 Reserved[7]; | ||
811 | __u64 RootDirectory; /* MBZ for network operations (why says spec?) */ | ||
812 | __le32 FileNameLength; | ||
813 | char FileName[0]; /* New name to be assigned */ | ||
814 | } __packed; /* level 10 Set */ | ||
815 | |||
816 | struct smb2_file_link_info { /* encoding of request for level 11 */ | ||
817 | __u8 ReplaceIfExists; /* 1 = replace existing link with new */ | ||
818 | /* 0 = fail if link already exists */ | ||
819 | __u8 Reserved[7]; | ||
820 | __u64 RootDirectory; /* MBZ for network operations (why says spec?) */ | ||
821 | __le32 FileNameLength; | ||
822 | char FileName[0]; /* Name to be assigned to new link */ | ||
823 | } __packed; /* level 11 Set */ | ||
824 | |||
551 | /* | 825 | /* |
552 | * This level 18, although with struct with same name is different from cifs | 826 | * This level 18, although with struct with same name is different from cifs |
553 | * level 0x107. Level 0x107 has an extra u64 between AccessFlags and | 827 | * level 0x107. Level 0x107 has an extra u64 between AccessFlags and |
@@ -576,4 +850,8 @@ struct smb2_file_all_info { /* data block encoding of response to level 18 */ | |||
576 | char FileName[1]; | 850 | char FileName[1]; |
577 | } __packed; /* level 18 Query */ | 851 | } __packed; /* level 18 Query */ |
578 | 852 | ||
853 | struct smb2_file_eof_info { /* encoding of request for level 10 */ | ||
854 | __le64 EndOfFile; /* new end of file value */ | ||
855 | } __packed; /* level 20 Set */ | ||
856 | |||
579 | #endif /* _SMB2PDU_H */ | 857 | #endif /* _SMB2PDU_H */ |
diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h index bfaa7b148afd..7d25f8b14f93 100644 --- a/fs/cifs/smb2proto.h +++ b/fs/cifs/smb2proto.h | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/key-type.h> | 26 | #include <linux/key-type.h> |
27 | 27 | ||
28 | struct statfs; | 28 | struct statfs; |
29 | struct smb_rqst; | ||
29 | 30 | ||
30 | /* | 31 | /* |
31 | ***************************************************************** | 32 | ***************************************************************** |
@@ -34,24 +35,35 @@ struct statfs; | |||
34 | */ | 35 | */ |
35 | extern int map_smb2_to_linux_error(char *buf, bool log_err); | 36 | extern int map_smb2_to_linux_error(char *buf, bool log_err); |
36 | extern int smb2_check_message(char *buf, unsigned int length); | 37 | extern int smb2_check_message(char *buf, unsigned int length); |
37 | extern unsigned int smb2_calc_size(struct smb2_hdr *hdr); | 38 | extern unsigned int smb2_calc_size(void *buf); |
38 | extern char *smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr); | 39 | extern char *smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr); |
39 | extern __le16 *cifs_convert_path_to_utf16(const char *from, | 40 | extern __le16 *cifs_convert_path_to_utf16(const char *from, |
40 | struct cifs_sb_info *cifs_sb); | 41 | struct cifs_sb_info *cifs_sb); |
41 | 42 | ||
43 | extern int smb2_verify_signature(struct smb_rqst *, struct TCP_Server_Info *); | ||
42 | extern int smb2_check_receive(struct mid_q_entry *mid, | 44 | extern int smb2_check_receive(struct mid_q_entry *mid, |
43 | struct TCP_Server_Info *server, bool log_error); | 45 | struct TCP_Server_Info *server, bool log_error); |
44 | extern int smb2_setup_request(struct cifs_ses *ses, struct kvec *iov, | 46 | extern struct mid_q_entry *smb2_setup_request(struct cifs_ses *ses, |
45 | unsigned int nvec, struct mid_q_entry **ret_mid); | 47 | struct smb_rqst *rqst); |
46 | extern int smb2_setup_async_request(struct TCP_Server_Info *server, | 48 | extern struct mid_q_entry *smb2_setup_async_request( |
47 | struct kvec *iov, unsigned int nvec, | 49 | struct TCP_Server_Info *server, struct smb_rqst *rqst); |
48 | struct mid_q_entry **ret_mid); | ||
49 | extern void smb2_echo_request(struct work_struct *work); | 50 | extern void smb2_echo_request(struct work_struct *work); |
51 | extern __le32 smb2_get_lease_state(struct cifsInodeInfo *cinode); | ||
52 | extern __u8 smb2_map_lease_to_oplock(__le32 lease_state); | ||
53 | extern bool smb2_is_valid_oplock_break(char *buffer, | ||
54 | struct TCP_Server_Info *srv); | ||
50 | 55 | ||
56 | extern void move_smb2_info_to_cifs(FILE_ALL_INFO *dst, | ||
57 | struct smb2_file_all_info *src); | ||
51 | extern int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, | 58 | extern int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, |
52 | struct cifs_sb_info *cifs_sb, | 59 | struct cifs_sb_info *cifs_sb, |
53 | const char *full_path, FILE_ALL_INFO *data, | 60 | const char *full_path, FILE_ALL_INFO *data, |
54 | bool *adjust_tz); | 61 | bool *adjust_tz); |
62 | extern int smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, | ||
63 | const char *full_path, __u64 size, | ||
64 | struct cifs_sb_info *cifs_sb, bool set_alloc); | ||
65 | extern int smb2_set_file_info(struct inode *inode, const char *full_path, | ||
66 | FILE_BASIC_INFO *buf, const unsigned int xid); | ||
55 | extern int smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon, | 67 | extern int smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon, |
56 | const char *name, struct cifs_sb_info *cifs_sb); | 68 | const char *name, struct cifs_sb_info *cifs_sb); |
57 | extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path, | 69 | extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path, |
@@ -59,6 +71,24 @@ extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path, | |||
59 | struct cifs_tcon *tcon, const unsigned int xid); | 71 | struct cifs_tcon *tcon, const unsigned int xid); |
60 | extern int smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, | 72 | extern int smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, |
61 | const char *name, struct cifs_sb_info *cifs_sb); | 73 | const char *name, struct cifs_sb_info *cifs_sb); |
74 | extern int smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, | ||
75 | const char *name, struct cifs_sb_info *cifs_sb); | ||
76 | extern int smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon, | ||
77 | const char *from_name, const char *to_name, | ||
78 | struct cifs_sb_info *cifs_sb); | ||
79 | extern int smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon, | ||
80 | const char *from_name, const char *to_name, | ||
81 | struct cifs_sb_info *cifs_sb); | ||
82 | |||
83 | extern int smb2_open_file(const unsigned int xid, struct cifs_tcon *tcon, | ||
84 | const char *full_path, int disposition, | ||
85 | int desired_access, int create_options, | ||
86 | struct cifs_fid *fid, __u32 *oplock, | ||
87 | FILE_ALL_INFO *buf, struct cifs_sb_info *cifs_sb); | ||
88 | extern void smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock); | ||
89 | extern int smb2_unlock_range(struct cifsFileInfo *cfile, | ||
90 | struct file_lock *flock, const unsigned int xid); | ||
91 | extern int smb2_push_mandatory_locks(struct cifsFileInfo *cfile); | ||
62 | 92 | ||
63 | /* | 93 | /* |
64 | * SMB2 Worker functions - most of protocol specific implementation details | 94 | * SMB2 Worker functions - most of protocol specific implementation details |
@@ -75,12 +105,55 @@ extern int SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon); | |||
75 | extern int SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, | 105 | extern int SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, |
76 | __le16 *path, u64 *persistent_fid, u64 *volatile_fid, | 106 | __le16 *path, u64 *persistent_fid, u64 *volatile_fid, |
77 | __u32 desired_access, __u32 create_disposition, | 107 | __u32 desired_access, __u32 create_disposition, |
78 | __u32 file_attributes, __u32 create_options); | 108 | __u32 file_attributes, __u32 create_options, |
109 | __u8 *oplock, struct smb2_file_all_info *buf); | ||
79 | extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, | 110 | extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, |
80 | u64 persistent_file_id, u64 volatile_file_id); | 111 | u64 persistent_file_id, u64 volatile_file_id); |
112 | extern int SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, | ||
113 | u64 persistent_file_id, u64 volatile_file_id); | ||
81 | extern int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, | 114 | extern int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, |
82 | u64 persistent_file_id, u64 volatile_file_id, | 115 | u64 persistent_file_id, u64 volatile_file_id, |
83 | struct smb2_file_all_info *data); | 116 | struct smb2_file_all_info *data); |
117 | extern int SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon, | ||
118 | u64 persistent_fid, u64 volatile_fid, | ||
119 | __le64 *uniqueid); | ||
120 | extern int smb2_async_readv(struct cifs_readdata *rdata); | ||
121 | extern int SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, | ||
122 | unsigned int *nbytes, char **buf, int *buf_type); | ||
123 | extern int smb2_async_writev(struct cifs_writedata *wdata); | ||
124 | extern int SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms, | ||
125 | unsigned int *nbytes, struct kvec *iov, int n_vec); | ||
84 | extern int SMB2_echo(struct TCP_Server_Info *server); | 126 | extern int SMB2_echo(struct TCP_Server_Info *server); |
127 | extern int SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, | ||
128 | u64 persistent_fid, u64 volatile_fid, int index, | ||
129 | struct cifs_search_info *srch_inf); | ||
130 | extern int SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon, | ||
131 | u64 persistent_fid, u64 volatile_fid, | ||
132 | __le16 *target_file); | ||
133 | extern int SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon, | ||
134 | u64 persistent_fid, u64 volatile_fid, | ||
135 | __le16 *target_file); | ||
136 | extern int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, | ||
137 | u64 persistent_fid, u64 volatile_fid, u32 pid, | ||
138 | __le64 *eof); | ||
139 | extern int SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
140 | u64 persistent_fid, u64 volatile_fid, | ||
141 | FILE_BASIC_INFO *buf); | ||
142 | extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, | ||
143 | const u64 persistent_fid, const u64 volatile_fid, | ||
144 | const __u8 oplock_level); | ||
145 | extern int SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
146 | u64 persistent_file_id, u64 volatile_file_id, | ||
147 | struct kstatfs *FSData); | ||
148 | extern int SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon, | ||
149 | const __u64 persist_fid, const __u64 volatile_fid, | ||
150 | const __u32 pid, const __u64 length, const __u64 offset, | ||
151 | const __u32 lockFlags, const bool wait); | ||
152 | extern int smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon, | ||
153 | const __u64 persist_fid, const __u64 volatile_fid, | ||
154 | const __u32 pid, const __u32 num_lock, | ||
155 | struct smb2_lock_element *buf); | ||
156 | extern int SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon, | ||
157 | __u8 *lease_key, const __le32 lease_state); | ||
85 | 158 | ||
86 | #endif /* _SMB2PROTO_H */ | 159 | #endif /* _SMB2PROTO_H */ |
diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c index 31f5d420b3ea..2a5fdf26f79f 100644 --- a/fs/cifs/smb2transport.c +++ b/fs/cifs/smb2transport.c | |||
@@ -30,12 +30,156 @@ | |||
30 | #include <linux/uaccess.h> | 30 | #include <linux/uaccess.h> |
31 | #include <asm/processor.h> | 31 | #include <asm/processor.h> |
32 | #include <linux/mempool.h> | 32 | #include <linux/mempool.h> |
33 | #include <linux/highmem.h> | ||
33 | #include "smb2pdu.h" | 34 | #include "smb2pdu.h" |
34 | #include "cifsglob.h" | 35 | #include "cifsglob.h" |
35 | #include "cifsproto.h" | 36 | #include "cifsproto.h" |
36 | #include "smb2proto.h" | 37 | #include "smb2proto.h" |
37 | #include "cifs_debug.h" | 38 | #include "cifs_debug.h" |
38 | #include "smb2status.h" | 39 | #include "smb2status.h" |
40 | #include "smb2glob.h" | ||
41 | |||
42 | static int | ||
43 | smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) | ||
44 | { | ||
45 | int i, rc; | ||
46 | unsigned char smb2_signature[SMB2_HMACSHA256_SIZE]; | ||
47 | unsigned char *sigptr = smb2_signature; | ||
48 | struct kvec *iov = rqst->rq_iov; | ||
49 | int n_vec = rqst->rq_nvec; | ||
50 | struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base; | ||
51 | |||
52 | memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE); | ||
53 | memset(smb2_pdu->Signature, 0x0, SMB2_SIGNATURE_SIZE); | ||
54 | |||
55 | rc = crypto_shash_setkey(server->secmech.hmacsha256, | ||
56 | server->session_key.response, SMB2_NTLMV2_SESSKEY_SIZE); | ||
57 | if (rc) { | ||
58 | cERROR(1, "%s: Could not update with response\n", __func__); | ||
59 | return rc; | ||
60 | } | ||
61 | |||
62 | rc = crypto_shash_init(&server->secmech.sdeschmacsha256->shash); | ||
63 | if (rc) { | ||
64 | cERROR(1, "%s: Could not init md5\n", __func__); | ||
65 | return rc; | ||
66 | } | ||
67 | |||
68 | for (i = 0; i < n_vec; i++) { | ||
69 | if (iov[i].iov_len == 0) | ||
70 | continue; | ||
71 | if (iov[i].iov_base == NULL) { | ||
72 | cERROR(1, "null iovec entry"); | ||
73 | return -EIO; | ||
74 | } | ||
75 | /* | ||
76 | * The first entry includes a length field (which does not get | ||
77 | * signed that occupies the first 4 bytes before the header). | ||
78 | */ | ||
79 | if (i == 0) { | ||
80 | if (iov[0].iov_len <= 8) /* cmd field at offset 9 */ | ||
81 | break; /* nothing to sign or corrupt header */ | ||
82 | rc = | ||
83 | crypto_shash_update( | ||
84 | &server->secmech.sdeschmacsha256->shash, | ||
85 | iov[i].iov_base + 4, iov[i].iov_len - 4); | ||
86 | } else { | ||
87 | rc = | ||
88 | crypto_shash_update( | ||
89 | &server->secmech.sdeschmacsha256->shash, | ||
90 | iov[i].iov_base, iov[i].iov_len); | ||
91 | } | ||
92 | if (rc) { | ||
93 | cERROR(1, "%s: Could not update with payload\n", | ||
94 | __func__); | ||
95 | return rc; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | /* now hash over the rq_pages array */ | ||
100 | for (i = 0; i < rqst->rq_npages; i++) { | ||
101 | struct kvec p_iov; | ||
102 | |||
103 | cifs_rqst_page_to_kvec(rqst, i, &p_iov); | ||
104 | crypto_shash_update(&server->secmech.sdeschmacsha256->shash, | ||
105 | p_iov.iov_base, p_iov.iov_len); | ||
106 | kunmap(rqst->rq_pages[i]); | ||
107 | } | ||
108 | |||
109 | rc = crypto_shash_final(&server->secmech.sdeschmacsha256->shash, | ||
110 | sigptr); | ||
111 | if (rc) | ||
112 | cERROR(1, "%s: Could not generate sha256 hash\n", __func__); | ||
113 | |||
114 | memcpy(smb2_pdu->Signature, sigptr, SMB2_SIGNATURE_SIZE); | ||
115 | |||
116 | return rc; | ||
117 | } | ||
118 | |||
119 | /* must be called with server->srv_mutex held */ | ||
120 | static int | ||
121 | smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) | ||
122 | { | ||
123 | int rc = 0; | ||
124 | struct smb2_hdr *smb2_pdu = rqst->rq_iov[0].iov_base; | ||
125 | |||
126 | if (!(smb2_pdu->Flags & SMB2_FLAGS_SIGNED) || | ||
127 | server->tcpStatus == CifsNeedNegotiate) | ||
128 | return rc; | ||
129 | |||
130 | if (!server->session_estab) { | ||
131 | strncpy(smb2_pdu->Signature, "BSRSPYL", 8); | ||
132 | return rc; | ||
133 | } | ||
134 | |||
135 | rc = smb2_calc_signature(rqst, server); | ||
136 | |||
137 | return rc; | ||
138 | } | ||
139 | |||
140 | int | ||
141 | smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) | ||
142 | { | ||
143 | unsigned int rc; | ||
144 | char server_response_sig[16]; | ||
145 | struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)rqst->rq_iov[0].iov_base; | ||
146 | |||
147 | if ((smb2_pdu->Command == SMB2_NEGOTIATE) || | ||
148 | (smb2_pdu->Command == SMB2_OPLOCK_BREAK) || | ||
149 | (!server->session_estab)) | ||
150 | return 0; | ||
151 | |||
152 | /* | ||
153 | * BB what if signatures are supposed to be on for session but | ||
154 | * server does not send one? BB | ||
155 | */ | ||
156 | |||
157 | /* Do not need to verify session setups with signature "BSRSPYL " */ | ||
158 | if (memcmp(smb2_pdu->Signature, "BSRSPYL ", 8) == 0) | ||
159 | cFYI(1, "dummy signature received for smb command 0x%x", | ||
160 | smb2_pdu->Command); | ||
161 | |||
162 | /* | ||
163 | * Save off the origiginal signature so we can modify the smb and check | ||
164 | * our calculated signature against what the server sent. | ||
165 | */ | ||
166 | memcpy(server_response_sig, smb2_pdu->Signature, SMB2_SIGNATURE_SIZE); | ||
167 | |||
168 | memset(smb2_pdu->Signature, 0, SMB2_SIGNATURE_SIZE); | ||
169 | |||
170 | mutex_lock(&server->srv_mutex); | ||
171 | rc = smb2_calc_signature(rqst, server); | ||
172 | mutex_unlock(&server->srv_mutex); | ||
173 | |||
174 | if (rc) | ||
175 | return rc; | ||
176 | |||
177 | if (memcmp(server_response_sig, smb2_pdu->Signature, | ||
178 | SMB2_SIGNATURE_SIZE)) | ||
179 | return -EACCES; | ||
180 | else | ||
181 | return 0; | ||
182 | } | ||
39 | 183 | ||
40 | /* | 184 | /* |
41 | * Set message id for the request. Should be called after wait_for_free_request | 185 | * Set message id for the request. Should be called after wait_for_free_request |
@@ -115,58 +259,66 @@ smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, | |||
115 | bool log_error) | 259 | bool log_error) |
116 | { | 260 | { |
117 | unsigned int len = get_rfc1002_length(mid->resp_buf); | 261 | unsigned int len = get_rfc1002_length(mid->resp_buf); |
262 | struct kvec iov; | ||
263 | struct smb_rqst rqst = { .rq_iov = &iov, | ||
264 | .rq_nvec = 1 }; | ||
265 | |||
266 | iov.iov_base = (char *)mid->resp_buf; | ||
267 | iov.iov_len = get_rfc1002_length(mid->resp_buf) + 4; | ||
118 | 268 | ||
119 | dump_smb(mid->resp_buf, min_t(u32, 80, len)); | 269 | dump_smb(mid->resp_buf, min_t(u32, 80, len)); |
120 | /* convert the length into a more usable form */ | 270 | /* convert the length into a more usable form */ |
121 | /* BB - uncomment with SMB2 signing implementation */ | 271 | if ((len > 24) && |
122 | /* if ((len > 24) && | ||
123 | (server->sec_mode & (SECMODE_SIGN_REQUIRED|SECMODE_SIGN_ENABLED))) { | 272 | (server->sec_mode & (SECMODE_SIGN_REQUIRED|SECMODE_SIGN_ENABLED))) { |
124 | if (smb2_verify_signature(mid->resp_buf, server)) | 273 | int rc; |
125 | cERROR(1, "Unexpected SMB signature"); | 274 | |
126 | } */ | 275 | rc = smb2_verify_signature(&rqst, server); |
276 | if (rc) | ||
277 | cERROR(1, "SMB signature verification returned error = " | ||
278 | "%d", rc); | ||
279 | } | ||
127 | 280 | ||
128 | return map_smb2_to_linux_error(mid->resp_buf, log_error); | 281 | return map_smb2_to_linux_error(mid->resp_buf, log_error); |
129 | } | 282 | } |
130 | 283 | ||
131 | int | 284 | struct mid_q_entry * |
132 | smb2_setup_request(struct cifs_ses *ses, struct kvec *iov, | 285 | smb2_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst) |
133 | unsigned int nvec, struct mid_q_entry **ret_mid) | ||
134 | { | 286 | { |
135 | int rc; | 287 | int rc; |
136 | struct smb2_hdr *hdr = (struct smb2_hdr *)iov[0].iov_base; | 288 | struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base; |
137 | struct mid_q_entry *mid; | 289 | struct mid_q_entry *mid; |
138 | 290 | ||
139 | smb2_seq_num_into_buf(ses->server, hdr); | 291 | smb2_seq_num_into_buf(ses->server, hdr); |
140 | 292 | ||
141 | rc = smb2_get_mid_entry(ses, hdr, &mid); | 293 | rc = smb2_get_mid_entry(ses, hdr, &mid); |
142 | if (rc) | 294 | if (rc) |
143 | return rc; | 295 | return ERR_PTR(rc); |
144 | /* rc = smb2_sign_smb2(iov, nvec, ses->server); | 296 | rc = smb2_sign_rqst(rqst, ses->server); |
145 | if (rc) | 297 | if (rc) { |
146 | delete_mid(mid); */ | 298 | cifs_delete_mid(mid); |
147 | *ret_mid = mid; | 299 | return ERR_PTR(rc); |
148 | return rc; | 300 | } |
301 | return mid; | ||
149 | } | 302 | } |
150 | 303 | ||
151 | int | 304 | struct mid_q_entry * |
152 | smb2_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, | 305 | smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) |
153 | unsigned int nvec, struct mid_q_entry **ret_mid) | ||
154 | { | 306 | { |
155 | int rc = 0; | 307 | int rc; |
156 | struct smb2_hdr *hdr = (struct smb2_hdr *)iov[0].iov_base; | 308 | struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base; |
157 | struct mid_q_entry *mid; | 309 | struct mid_q_entry *mid; |
158 | 310 | ||
159 | smb2_seq_num_into_buf(server, hdr); | 311 | smb2_seq_num_into_buf(server, hdr); |
160 | 312 | ||
161 | mid = smb2_mid_entry_alloc(hdr, server); | 313 | mid = smb2_mid_entry_alloc(hdr, server); |
162 | if (mid == NULL) | 314 | if (mid == NULL) |
163 | return -ENOMEM; | 315 | return ERR_PTR(-ENOMEM); |
164 | 316 | ||
165 | /* rc = smb2_sign_smb2(iov, nvec, server); | 317 | rc = smb2_sign_rqst(rqst, server); |
166 | if (rc) { | 318 | if (rc) { |
167 | DeleteMidQEntry(mid); | 319 | DeleteMidQEntry(mid); |
168 | return rc; | 320 | return ERR_PTR(rc); |
169 | }*/ | 321 | } |
170 | *ret_mid = mid; | 322 | |
171 | return rc; | 323 | return mid; |
172 | } | 324 | } |
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index d9b639b95fa8..2126ab185045 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include <linux/net.h> | 27 | #include <linux/net.h> |
28 | #include <linux/delay.h> | 28 | #include <linux/delay.h> |
29 | #include <linux/freezer.h> | 29 | #include <linux/freezer.h> |
30 | #include <linux/tcp.h> | ||
31 | #include <linux/highmem.h> | ||
30 | #include <asm/uaccess.h> | 32 | #include <asm/uaccess.h> |
31 | #include <asm/processor.h> | 33 | #include <asm/processor.h> |
32 | #include <linux/mempool.h> | 34 | #include <linux/mempool.h> |
@@ -109,8 +111,8 @@ DeleteMidQEntry(struct mid_q_entry *midEntry) | |||
109 | mempool_free(midEntry, cifs_mid_poolp); | 111 | mempool_free(midEntry, cifs_mid_poolp); |
110 | } | 112 | } |
111 | 113 | ||
112 | static void | 114 | void |
113 | delete_mid(struct mid_q_entry *mid) | 115 | cifs_delete_mid(struct mid_q_entry *mid) |
114 | { | 116 | { |
115 | spin_lock(&GlobalMid_Lock); | 117 | spin_lock(&GlobalMid_Lock); |
116 | list_del(&mid->qhead); | 118 | list_del(&mid->qhead); |
@@ -119,18 +121,29 @@ delete_mid(struct mid_q_entry *mid) | |||
119 | DeleteMidQEntry(mid); | 121 | DeleteMidQEntry(mid); |
120 | } | 122 | } |
121 | 123 | ||
124 | /* | ||
125 | * smb_send_kvec - send an array of kvecs to the server | ||
126 | * @server: Server to send the data to | ||
127 | * @iov: Pointer to array of kvecs | ||
128 | * @n_vec: length of kvec array | ||
129 | * @sent: amount of data sent on socket is stored here | ||
130 | * | ||
131 | * Our basic "send data to server" function. Should be called with srv_mutex | ||
132 | * held. The caller is responsible for handling the results. | ||
133 | */ | ||
122 | static int | 134 | static int |
123 | smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | 135 | smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec, |
136 | size_t *sent) | ||
124 | { | 137 | { |
125 | int rc = 0; | 138 | int rc = 0; |
126 | int i = 0; | 139 | int i = 0; |
127 | struct msghdr smb_msg; | 140 | struct msghdr smb_msg; |
128 | unsigned int len = iov[0].iov_len; | 141 | unsigned int remaining; |
129 | unsigned int total_len; | 142 | size_t first_vec = 0; |
130 | int first_vec = 0; | ||
131 | unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base); | ||
132 | struct socket *ssocket = server->ssocket; | 143 | struct socket *ssocket = server->ssocket; |
133 | 144 | ||
145 | *sent = 0; | ||
146 | |||
134 | if (ssocket == NULL) | 147 | if (ssocket == NULL) |
135 | return -ENOTSOCK; /* BB eventually add reconnect code here */ | 148 | return -ENOTSOCK; /* BB eventually add reconnect code here */ |
136 | 149 | ||
@@ -143,56 +156,60 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
143 | else | 156 | else |
144 | smb_msg.msg_flags = MSG_NOSIGNAL; | 157 | smb_msg.msg_flags = MSG_NOSIGNAL; |
145 | 158 | ||
146 | total_len = 0; | 159 | remaining = 0; |
147 | for (i = 0; i < n_vec; i++) | 160 | for (i = 0; i < n_vec; i++) |
148 | total_len += iov[i].iov_len; | 161 | remaining += iov[i].iov_len; |
149 | |||
150 | cFYI(1, "Sending smb: total_len %d", total_len); | ||
151 | dump_smb(iov[0].iov_base, len); | ||
152 | 162 | ||
153 | i = 0; | 163 | i = 0; |
154 | while (total_len) { | 164 | while (remaining) { |
165 | /* | ||
166 | * If blocking send, we try 3 times, since each can block | ||
167 | * for 5 seconds. For nonblocking we have to try more | ||
168 | * but wait increasing amounts of time allowing time for | ||
169 | * socket to clear. The overall time we wait in either | ||
170 | * case to send on the socket is about 15 seconds. | ||
171 | * Similarly we wait for 15 seconds for a response from | ||
172 | * the server in SendReceive[2] for the server to send | ||
173 | * a response back for most types of requests (except | ||
174 | * SMB Write past end of file which can be slow, and | ||
175 | * blocking lock operations). NFS waits slightly longer | ||
176 | * than CIFS, but this can make it take longer for | ||
177 | * nonresponsive servers to be detected and 15 seconds | ||
178 | * is more than enough time for modern networks to | ||
179 | * send a packet. In most cases if we fail to send | ||
180 | * after the retries we will kill the socket and | ||
181 | * reconnect which may clear the network problem. | ||
182 | */ | ||
155 | rc = kernel_sendmsg(ssocket, &smb_msg, &iov[first_vec], | 183 | rc = kernel_sendmsg(ssocket, &smb_msg, &iov[first_vec], |
156 | n_vec - first_vec, total_len); | 184 | n_vec - first_vec, remaining); |
157 | if ((rc == -ENOSPC) || (rc == -EAGAIN)) { | 185 | if (rc == -ENOSPC || rc == -EAGAIN) { |
158 | i++; | 186 | i++; |
159 | /* | 187 | if (i >= 14 || (!server->noblocksnd && (i > 2))) { |
160 | * If blocking send we try 3 times, since each can block | 188 | cERROR(1, "sends on sock %p stuck for 15 " |
161 | * for 5 seconds. For nonblocking we have to try more | 189 | "seconds", ssocket); |
162 | * but wait increasing amounts of time allowing time for | ||
163 | * socket to clear. The overall time we wait in either | ||
164 | * case to send on the socket is about 15 seconds. | ||
165 | * Similarly we wait for 15 seconds for a response from | ||
166 | * the server in SendReceive[2] for the server to send | ||
167 | * a response back for most types of requests (except | ||
168 | * SMB Write past end of file which can be slow, and | ||
169 | * blocking lock operations). NFS waits slightly longer | ||
170 | * than CIFS, but this can make it take longer for | ||
171 | * nonresponsive servers to be detected and 15 seconds | ||
172 | * is more than enough time for modern networks to | ||
173 | * send a packet. In most cases if we fail to send | ||
174 | * after the retries we will kill the socket and | ||
175 | * reconnect which may clear the network problem. | ||
176 | */ | ||
177 | if ((i >= 14) || (!server->noblocksnd && (i > 2))) { | ||
178 | cERROR(1, "sends on sock %p stuck for 15 seconds", | ||
179 | ssocket); | ||
180 | rc = -EAGAIN; | 190 | rc = -EAGAIN; |
181 | break; | 191 | break; |
182 | } | 192 | } |
183 | msleep(1 << i); | 193 | msleep(1 << i); |
184 | continue; | 194 | continue; |
185 | } | 195 | } |
196 | |||
186 | if (rc < 0) | 197 | if (rc < 0) |
187 | break; | 198 | break; |
188 | 199 | ||
189 | if (rc == total_len) { | 200 | /* send was at least partially successful */ |
190 | total_len = 0; | 201 | *sent += rc; |
202 | |||
203 | if (rc == remaining) { | ||
204 | remaining = 0; | ||
191 | break; | 205 | break; |
192 | } else if (rc > total_len) { | 206 | } |
193 | cERROR(1, "sent %d requested %d", rc, total_len); | 207 | |
208 | if (rc > remaining) { | ||
209 | cERROR(1, "sent %d requested %d", rc, remaining); | ||
194 | break; | 210 | break; |
195 | } | 211 | } |
212 | |||
196 | if (rc == 0) { | 213 | if (rc == 0) { |
197 | /* should never happen, letting socket clear before | 214 | /* should never happen, letting socket clear before |
198 | retrying is our only obvious option here */ | 215 | retrying is our only obvious option here */ |
@@ -200,7 +217,9 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
200 | msleep(500); | 217 | msleep(500); |
201 | continue; | 218 | continue; |
202 | } | 219 | } |
203 | total_len -= rc; | 220 | |
221 | remaining -= rc; | ||
222 | |||
204 | /* the line below resets i */ | 223 | /* the line below resets i */ |
205 | for (i = first_vec; i < n_vec; i++) { | 224 | for (i = first_vec; i < n_vec; i++) { |
206 | if (iov[i].iov_len) { | 225 | if (iov[i].iov_len) { |
@@ -215,16 +234,97 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
215 | } | 234 | } |
216 | } | 235 | } |
217 | } | 236 | } |
237 | |||
218 | i = 0; /* in case we get ENOSPC on the next send */ | 238 | i = 0; /* in case we get ENOSPC on the next send */ |
239 | rc = 0; | ||
219 | } | 240 | } |
241 | return rc; | ||
242 | } | ||
243 | |||
244 | /** | ||
245 | * rqst_page_to_kvec - Turn a slot in the smb_rqst page array into a kvec | ||
246 | * @rqst: pointer to smb_rqst | ||
247 | * @idx: index into the array of the page | ||
248 | * @iov: pointer to struct kvec that will hold the result | ||
249 | * | ||
250 | * Helper function to convert a slot in the rqst->rq_pages array into a kvec. | ||
251 | * The page will be kmapped and the address placed into iov_base. The length | ||
252 | * will then be adjusted according to the ptailoff. | ||
253 | */ | ||
254 | void | ||
255 | cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx, | ||
256 | struct kvec *iov) | ||
257 | { | ||
258 | /* | ||
259 | * FIXME: We could avoid this kmap altogether if we used | ||
260 | * kernel_sendpage instead of kernel_sendmsg. That will only | ||
261 | * work if signing is disabled though as sendpage inlines the | ||
262 | * page directly into the fraglist. If userspace modifies the | ||
263 | * page after we calculate the signature, then the server will | ||
264 | * reject it and may break the connection. kernel_sendmsg does | ||
265 | * an extra copy of the data and avoids that issue. | ||
266 | */ | ||
267 | iov->iov_base = kmap(rqst->rq_pages[idx]); | ||
268 | |||
269 | /* if last page, don't send beyond this offset into page */ | ||
270 | if (idx == (rqst->rq_npages - 1)) | ||
271 | iov->iov_len = rqst->rq_tailsz; | ||
272 | else | ||
273 | iov->iov_len = rqst->rq_pagesz; | ||
274 | } | ||
275 | |||
276 | static int | ||
277 | smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) | ||
278 | { | ||
279 | int rc; | ||
280 | struct kvec *iov = rqst->rq_iov; | ||
281 | int n_vec = rqst->rq_nvec; | ||
282 | unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base); | ||
283 | unsigned int i; | ||
284 | size_t total_len = 0, sent; | ||
285 | struct socket *ssocket = server->ssocket; | ||
286 | int val = 1; | ||
287 | |||
288 | cFYI(1, "Sending smb: smb_len=%u", smb_buf_length); | ||
289 | dump_smb(iov[0].iov_base, iov[0].iov_len); | ||
290 | |||
291 | /* cork the socket */ | ||
292 | kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, | ||
293 | (char *)&val, sizeof(val)); | ||
294 | |||
295 | rc = smb_send_kvec(server, iov, n_vec, &sent); | ||
296 | if (rc < 0) | ||
297 | goto uncork; | ||
298 | |||
299 | total_len += sent; | ||
300 | |||
301 | /* now walk the page array and send each page in it */ | ||
302 | for (i = 0; i < rqst->rq_npages; i++) { | ||
303 | struct kvec p_iov; | ||
304 | |||
305 | cifs_rqst_page_to_kvec(rqst, i, &p_iov); | ||
306 | rc = smb_send_kvec(server, &p_iov, 1, &sent); | ||
307 | kunmap(rqst->rq_pages[i]); | ||
308 | if (rc < 0) | ||
309 | break; | ||
310 | |||
311 | total_len += sent; | ||
312 | } | ||
313 | |||
314 | uncork: | ||
315 | /* uncork it */ | ||
316 | val = 0; | ||
317 | kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, | ||
318 | (char *)&val, sizeof(val)); | ||
220 | 319 | ||
221 | if ((total_len > 0) && (total_len != smb_buf_length + 4)) { | 320 | if ((total_len > 0) && (total_len != smb_buf_length + 4)) { |
222 | cFYI(1, "partial send (%d remaining), terminating session", | 321 | cFYI(1, "partial send (wanted=%u sent=%zu): terminating " |
223 | total_len); | 322 | "session", smb_buf_length + 4, total_len); |
224 | /* If we have only sent part of an SMB then the next SMB | 323 | /* |
225 | could be taken as the remainder of this one. We need | 324 | * If we have only sent part of an SMB then the next SMB could |
226 | to kill the socket so the server throws away the partial | 325 | * be taken as the remainder of this one. We need to kill the |
227 | SMB */ | 326 | * socket so the server throws away the partial SMB |
327 | */ | ||
228 | server->tcpStatus = CifsNeedReconnect; | 328 | server->tcpStatus = CifsNeedReconnect; |
229 | } | 329 | } |
230 | 330 | ||
@@ -236,6 +336,15 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
236 | return rc; | 336 | return rc; |
237 | } | 337 | } |
238 | 338 | ||
339 | static int | ||
340 | smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | ||
341 | { | ||
342 | struct smb_rqst rqst = { .rq_iov = iov, | ||
343 | .rq_nvec = n_vec }; | ||
344 | |||
345 | return smb_send_rqst(server, &rqst); | ||
346 | } | ||
347 | |||
239 | int | 348 | int |
240 | smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, | 349 | smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, |
241 | unsigned int smb_buf_length) | 350 | unsigned int smb_buf_length) |
@@ -345,12 +454,11 @@ wait_for_response(struct TCP_Server_Info *server, struct mid_q_entry *midQ) | |||
345 | return 0; | 454 | return 0; |
346 | } | 455 | } |
347 | 456 | ||
348 | int | 457 | struct mid_q_entry * |
349 | cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, | 458 | cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) |
350 | unsigned int nvec, struct mid_q_entry **ret_mid) | ||
351 | { | 459 | { |
352 | int rc; | 460 | int rc; |
353 | struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base; | 461 | struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
354 | struct mid_q_entry *mid; | 462 | struct mid_q_entry *mid; |
355 | 463 | ||
356 | /* enable signing if server requires it */ | 464 | /* enable signing if server requires it */ |
@@ -359,16 +467,15 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, | |||
359 | 467 | ||
360 | mid = AllocMidQEntry(hdr, server); | 468 | mid = AllocMidQEntry(hdr, server); |
361 | if (mid == NULL) | 469 | if (mid == NULL) |
362 | return -ENOMEM; | 470 | return ERR_PTR(-ENOMEM); |
363 | 471 | ||
364 | rc = cifs_sign_smbv(iov, nvec, server, &mid->sequence_number); | 472 | rc = cifs_sign_rqst(rqst, server, &mid->sequence_number); |
365 | if (rc) { | 473 | if (rc) { |
366 | DeleteMidQEntry(mid); | 474 | DeleteMidQEntry(mid); |
367 | return rc; | 475 | return ERR_PTR(rc); |
368 | } | 476 | } |
369 | 477 | ||
370 | *ret_mid = mid; | 478 | return mid; |
371 | return 0; | ||
372 | } | 479 | } |
373 | 480 | ||
374 | /* | 481 | /* |
@@ -376,9 +483,9 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, | |||
376 | * the result. Caller is responsible for dealing with timeouts. | 483 | * the result. Caller is responsible for dealing with timeouts. |
377 | */ | 484 | */ |
378 | int | 485 | int |
379 | cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, | 486 | cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, |
380 | unsigned int nvec, mid_receive_t *receive, | 487 | mid_receive_t *receive, mid_callback_t *callback, |
381 | mid_callback_t *callback, void *cbdata, const int flags) | 488 | void *cbdata, const int flags) |
382 | { | 489 | { |
383 | int rc, timeout, optype; | 490 | int rc, timeout, optype; |
384 | struct mid_q_entry *mid; | 491 | struct mid_q_entry *mid; |
@@ -391,12 +498,12 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, | |||
391 | return rc; | 498 | return rc; |
392 | 499 | ||
393 | mutex_lock(&server->srv_mutex); | 500 | mutex_lock(&server->srv_mutex); |
394 | rc = server->ops->setup_async_request(server, iov, nvec, &mid); | 501 | mid = server->ops->setup_async_request(server, rqst); |
395 | if (rc) { | 502 | if (IS_ERR(mid)) { |
396 | mutex_unlock(&server->srv_mutex); | 503 | mutex_unlock(&server->srv_mutex); |
397 | add_credits(server, 1, optype); | 504 | add_credits(server, 1, optype); |
398 | wake_up(&server->request_q); | 505 | wake_up(&server->request_q); |
399 | return rc; | 506 | return PTR_ERR(mid); |
400 | } | 507 | } |
401 | 508 | ||
402 | mid->receive = receive; | 509 | mid->receive = receive; |
@@ -411,7 +518,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, | |||
411 | 518 | ||
412 | 519 | ||
413 | cifs_in_send_inc(server); | 520 | cifs_in_send_inc(server); |
414 | rc = smb_sendv(server, iov, nvec); | 521 | rc = smb_send_rqst(server, rqst); |
415 | cifs_in_send_dec(server); | 522 | cifs_in_send_dec(server); |
416 | cifs_save_when_sent(mid); | 523 | cifs_save_when_sent(mid); |
417 | mutex_unlock(&server->srv_mutex); | 524 | mutex_unlock(&server->srv_mutex); |
@@ -419,7 +526,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, | |||
419 | if (rc == 0) | 526 | if (rc == 0) |
420 | return 0; | 527 | return 0; |
421 | 528 | ||
422 | delete_mid(mid); | 529 | cifs_delete_mid(mid); |
423 | add_credits(server, 1, optype); | 530 | add_credits(server, 1, optype); |
424 | wake_up(&server->request_q); | 531 | wake_up(&server->request_q); |
425 | return rc; | 532 | return rc; |
@@ -504,11 +611,13 @@ cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, | |||
504 | if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { | 611 | if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { |
505 | struct kvec iov; | 612 | struct kvec iov; |
506 | int rc = 0; | 613 | int rc = 0; |
614 | struct smb_rqst rqst = { .rq_iov = &iov, | ||
615 | .rq_nvec = 1 }; | ||
507 | 616 | ||
508 | iov.iov_base = mid->resp_buf; | 617 | iov.iov_base = mid->resp_buf; |
509 | iov.iov_len = len; | 618 | iov.iov_len = len; |
510 | /* FIXME: add code to kill session */ | 619 | /* FIXME: add code to kill session */ |
511 | rc = cifs_verify_signature(&iov, 1, server, | 620 | rc = cifs_verify_signature(&rqst, server, |
512 | mid->sequence_number + 1); | 621 | mid->sequence_number + 1); |
513 | if (rc) | 622 | if (rc) |
514 | cERROR(1, "SMB signature verification returned error = " | 623 | cERROR(1, "SMB signature verification returned error = " |
@@ -519,22 +628,22 @@ cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, | |||
519 | return map_smb_to_linux_error(mid->resp_buf, log_error); | 628 | return map_smb_to_linux_error(mid->resp_buf, log_error); |
520 | } | 629 | } |
521 | 630 | ||
522 | int | 631 | struct mid_q_entry * |
523 | cifs_setup_request(struct cifs_ses *ses, struct kvec *iov, | 632 | cifs_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst) |
524 | unsigned int nvec, struct mid_q_entry **ret_mid) | ||
525 | { | 633 | { |
526 | int rc; | 634 | int rc; |
527 | struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base; | 635 | struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
528 | struct mid_q_entry *mid; | 636 | struct mid_q_entry *mid; |
529 | 637 | ||
530 | rc = allocate_mid(ses, hdr, &mid); | 638 | rc = allocate_mid(ses, hdr, &mid); |
531 | if (rc) | 639 | if (rc) |
532 | return rc; | 640 | return ERR_PTR(rc); |
533 | rc = cifs_sign_smbv(iov, nvec, ses->server, &mid->sequence_number); | 641 | rc = cifs_sign_rqst(rqst, ses->server, &mid->sequence_number); |
534 | if (rc) | 642 | if (rc) { |
535 | delete_mid(mid); | 643 | cifs_delete_mid(mid); |
536 | *ret_mid = mid; | 644 | return ERR_PTR(rc); |
537 | return rc; | 645 | } |
646 | return mid; | ||
538 | } | 647 | } |
539 | 648 | ||
540 | int | 649 | int |
@@ -547,6 +656,8 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, | |||
547 | struct mid_q_entry *midQ; | 656 | struct mid_q_entry *midQ; |
548 | char *buf = iov[0].iov_base; | 657 | char *buf = iov[0].iov_base; |
549 | unsigned int credits = 1; | 658 | unsigned int credits = 1; |
659 | struct smb_rqst rqst = { .rq_iov = iov, | ||
660 | .rq_nvec = n_vec }; | ||
550 | 661 | ||
551 | timeout = flags & CIFS_TIMEOUT_MASK; | 662 | timeout = flags & CIFS_TIMEOUT_MASK; |
552 | optype = flags & CIFS_OP_MASK; | 663 | optype = flags & CIFS_OP_MASK; |
@@ -584,13 +695,13 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, | |||
584 | 695 | ||
585 | mutex_lock(&ses->server->srv_mutex); | 696 | mutex_lock(&ses->server->srv_mutex); |
586 | 697 | ||
587 | rc = ses->server->ops->setup_request(ses, iov, n_vec, &midQ); | 698 | midQ = ses->server->ops->setup_request(ses, &rqst); |
588 | if (rc) { | 699 | if (IS_ERR(midQ)) { |
589 | mutex_unlock(&ses->server->srv_mutex); | 700 | mutex_unlock(&ses->server->srv_mutex); |
590 | cifs_small_buf_release(buf); | 701 | cifs_small_buf_release(buf); |
591 | /* Update # of requests on wire to server */ | 702 | /* Update # of requests on wire to server */ |
592 | add_credits(ses->server, 1, optype); | 703 | add_credits(ses->server, 1, optype); |
593 | return rc; | 704 | return PTR_ERR(midQ); |
594 | } | 705 | } |
595 | 706 | ||
596 | midQ->mid_state = MID_REQUEST_SUBMITTED; | 707 | midQ->mid_state = MID_REQUEST_SUBMITTED; |
@@ -652,11 +763,11 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, | |||
652 | rc = ses->server->ops->check_receive(midQ, ses->server, | 763 | rc = ses->server->ops->check_receive(midQ, ses->server, |
653 | flags & CIFS_LOG_ERROR); | 764 | flags & CIFS_LOG_ERROR); |
654 | 765 | ||
655 | /* mark it so buf will not be freed by delete_mid */ | 766 | /* mark it so buf will not be freed by cifs_delete_mid */ |
656 | if ((flags & CIFS_NO_RESP) == 0) | 767 | if ((flags & CIFS_NO_RESP) == 0) |
657 | midQ->resp_buf = NULL; | 768 | midQ->resp_buf = NULL; |
658 | out: | 769 | out: |
659 | delete_mid(midQ); | 770 | cifs_delete_mid(midQ); |
660 | add_credits(ses->server, credits, optype); | 771 | add_credits(ses->server, credits, optype); |
661 | 772 | ||
662 | return rc; | 773 | return rc; |
@@ -762,7 +873,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, | |||
762 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); | 873 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); |
763 | rc = cifs_check_receive(midQ, ses->server, 0); | 874 | rc = cifs_check_receive(midQ, ses->server, 0); |
764 | out: | 875 | out: |
765 | delete_mid(midQ); | 876 | cifs_delete_mid(midQ); |
766 | add_credits(ses->server, 1, 0); | 877 | add_credits(ses->server, 1, 0); |
767 | 878 | ||
768 | return rc; | 879 | return rc; |
@@ -846,7 +957,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, | |||
846 | 957 | ||
847 | rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); | 958 | rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); |
848 | if (rc) { | 959 | if (rc) { |
849 | delete_mid(midQ); | 960 | cifs_delete_mid(midQ); |
850 | mutex_unlock(&ses->server->srv_mutex); | 961 | mutex_unlock(&ses->server->srv_mutex); |
851 | return rc; | 962 | return rc; |
852 | } | 963 | } |
@@ -859,7 +970,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, | |||
859 | mutex_unlock(&ses->server->srv_mutex); | 970 | mutex_unlock(&ses->server->srv_mutex); |
860 | 971 | ||
861 | if (rc < 0) { | 972 | if (rc < 0) { |
862 | delete_mid(midQ); | 973 | cifs_delete_mid(midQ); |
863 | return rc; | 974 | return rc; |
864 | } | 975 | } |
865 | 976 | ||
@@ -880,7 +991,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, | |||
880 | blocking lock to return. */ | 991 | blocking lock to return. */ |
881 | rc = send_cancel(ses->server, in_buf, midQ); | 992 | rc = send_cancel(ses->server, in_buf, midQ); |
882 | if (rc) { | 993 | if (rc) { |
883 | delete_mid(midQ); | 994 | cifs_delete_mid(midQ); |
884 | return rc; | 995 | return rc; |
885 | } | 996 | } |
886 | } else { | 997 | } else { |
@@ -892,7 +1003,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, | |||
892 | /* If we get -ENOLCK back the lock may have | 1003 | /* If we get -ENOLCK back the lock may have |
893 | already been removed. Don't exit in this case. */ | 1004 | already been removed. Don't exit in this case. */ |
894 | if (rc && rc != -ENOLCK) { | 1005 | if (rc && rc != -ENOLCK) { |
895 | delete_mid(midQ); | 1006 | cifs_delete_mid(midQ); |
896 | return rc; | 1007 | return rc; |
897 | } | 1008 | } |
898 | } | 1009 | } |
@@ -929,7 +1040,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, | |||
929 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); | 1040 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); |
930 | rc = cifs_check_receive(midQ, ses->server, 0); | 1041 | rc = cifs_check_receive(midQ, ses->server, 0); |
931 | out: | 1042 | out: |
932 | delete_mid(midQ); | 1043 | cifs_delete_mid(midQ); |
933 | if (rstart && rc == -EACCES) | 1044 | if (rstart && rc == -EACCES) |
934 | return -ERESTARTSYS; | 1045 | return -ERESTARTSYS; |
935 | return rc; | 1046 | return rc; |