aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorSteve French <sfrench@us.ibm.com>2012-03-26 22:14:05 -0400
committerSteve French <sfrench@us.ibm.com>2012-03-26 22:14:05 -0400
commit8f09c3d8dbb8ba35c579e426b3f30bf7bafe0a85 (patch)
tree76cded7c7626281e0f05742ce0f90c0086ee7743 /fs
parente22057c8599373e5caef0bc42bdb95d2a361ab0d (diff)
parentc7ad42b52d866b238ebb311d32ac80338f5c39d4 (diff)
Merge branch 'for-3.4'
Diffstat (limited to 'fs')
-rw-r--r--fs/cifs/cifs_debug.c68
-rw-r--r--fs/cifs/cifs_debug.h4
-rw-r--r--fs/cifs/cifsfs.c13
-rw-r--r--fs/cifs/cifsglob.h39
-rw-r--r--fs/cifs/cifsproto.h20
-rw-r--r--fs/cifs/cifssmb.c126
-rw-r--r--fs/cifs/connect.c1449
-rw-r--r--fs/cifs/file.c271
-rw-r--r--fs/cifs/misc.c100
-rw-r--r--fs/cifs/netmisc.c3
-rw-r--r--fs/cifs/transport.c227
11 files changed, 1376 insertions, 944 deletions
diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
index 573b899b5a5..27046462941 100644
--- a/fs/cifs/cifs_debug.c
+++ b/fs/cifs/cifs_debug.c
@@ -58,15 +58,16 @@ cifs_dump_mem(char *label, void *data, int length)
58} 58}
59 59
60#ifdef CONFIG_CIFS_DEBUG2 60#ifdef CONFIG_CIFS_DEBUG2
61void cifs_dump_detail(struct smb_hdr *smb) 61void cifs_dump_detail(void *buf)
62{ 62{
63 struct smb_hdr *smb = (struct smb_hdr *)buf;
64
63 cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d", 65 cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
64 smb->Command, smb->Status.CifsError, 66 smb->Command, smb->Status.CifsError,
65 smb->Flags, smb->Flags2, smb->Mid, smb->Pid); 67 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
66 cERROR(1, "smb buf %p len %d", smb, smbCalcSize(smb)); 68 cERROR(1, "smb buf %p len %d", smb, smbCalcSize(smb));
67} 69}
68 70
69
70void cifs_dump_mids(struct TCP_Server_Info *server) 71void cifs_dump_mids(struct TCP_Server_Info *server)
71{ 72{
72 struct list_head *tmp; 73 struct list_head *tmp;
@@ -79,15 +80,15 @@ void cifs_dump_mids(struct TCP_Server_Info *server)
79 spin_lock(&GlobalMid_Lock); 80 spin_lock(&GlobalMid_Lock);
80 list_for_each(tmp, &server->pending_mid_q) { 81 list_for_each(tmp, &server->pending_mid_q) {
81 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 82 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
82 cERROR(1, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %d", 83 cERROR(1, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu",
83 mid_entry->midState, 84 mid_entry->mid_state,
84 (int)mid_entry->command, 85 le16_to_cpu(mid_entry->command),
85 mid_entry->pid, 86 mid_entry->pid,
86 mid_entry->callback_data, 87 mid_entry->callback_data,
87 mid_entry->mid); 88 mid_entry->mid);
88#ifdef CONFIG_CIFS_STATS2 89#ifdef CONFIG_CIFS_STATS2
89 cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld", 90 cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld",
90 mid_entry->largeBuf, 91 mid_entry->large_buf,
91 mid_entry->resp_buf, 92 mid_entry->resp_buf,
92 mid_entry->when_received, 93 mid_entry->when_received,
93 jiffies); 94 jiffies);
@@ -217,12 +218,12 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
217 mid_entry = list_entry(tmp3, struct mid_q_entry, 218 mid_entry = list_entry(tmp3, struct mid_q_entry,
218 qhead); 219 qhead);
219 seq_printf(m, "\tState: %d com: %d pid:" 220 seq_printf(m, "\tState: %d com: %d pid:"
220 " %d cbdata: %p mid %d\n", 221 " %d cbdata: %p mid %llu\n",
221 mid_entry->midState, 222 mid_entry->mid_state,
222 (int)mid_entry->command, 223 le16_to_cpu(mid_entry->command),
223 mid_entry->pid, 224 mid_entry->pid,
224 mid_entry->callback_data, 225 mid_entry->callback_data,
225 mid_entry->mid); 226 mid_entry->mid);
226 } 227 }
227 spin_unlock(&GlobalMid_Lock); 228 spin_unlock(&GlobalMid_Lock);
228 } 229 }
@@ -417,7 +418,6 @@ static const struct file_operations cifs_stats_proc_fops = {
417 418
418static struct proc_dir_entry *proc_fs_cifs; 419static struct proc_dir_entry *proc_fs_cifs;
419static const struct file_operations cifsFYI_proc_fops; 420static const struct file_operations cifsFYI_proc_fops;
420static const struct file_operations cifs_oplock_proc_fops;
421static const struct file_operations cifs_lookup_cache_proc_fops; 421static const struct file_operations cifs_lookup_cache_proc_fops;
422static const struct file_operations traceSMB_proc_fops; 422static const struct file_operations traceSMB_proc_fops;
423static const struct file_operations cifs_multiuser_mount_proc_fops; 423static const struct file_operations cifs_multiuser_mount_proc_fops;
@@ -438,7 +438,6 @@ cifs_proc_init(void)
438#endif /* STATS */ 438#endif /* STATS */
439 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops); 439 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
440 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops); 440 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
441 proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops);
442 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs, 441 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
443 &cifs_linux_ext_proc_fops); 442 &cifs_linux_ext_proc_fops);
444 proc_create("MultiuserMount", 0, proc_fs_cifs, 443 proc_create("MultiuserMount", 0, proc_fs_cifs,
@@ -462,7 +461,6 @@ cifs_proc_clean(void)
462 remove_proc_entry("Stats", proc_fs_cifs); 461 remove_proc_entry("Stats", proc_fs_cifs);
463#endif 462#endif
464 remove_proc_entry("MultiuserMount", proc_fs_cifs); 463 remove_proc_entry("MultiuserMount", proc_fs_cifs);
465 remove_proc_entry("OplockEnabled", proc_fs_cifs);
466 remove_proc_entry("SecurityFlags", proc_fs_cifs); 464 remove_proc_entry("SecurityFlags", proc_fs_cifs);
467 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs); 465 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
468 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs); 466 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
@@ -508,46 +506,6 @@ static const struct file_operations cifsFYI_proc_fops = {
508 .write = cifsFYI_proc_write, 506 .write = cifsFYI_proc_write,
509}; 507};
510 508
511static int cifs_oplock_proc_show(struct seq_file *m, void *v)
512{
513 seq_printf(m, "%d\n", enable_oplocks);
514 return 0;
515}
516
517static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
518{
519 return single_open(file, cifs_oplock_proc_show, NULL);
520}
521
522static ssize_t cifs_oplock_proc_write(struct file *file,
523 const char __user *buffer, size_t count, loff_t *ppos)
524{
525 char c;
526 int rc;
527
528 printk(KERN_WARNING "CIFS: The /proc/fs/cifs/OplockEnabled interface "
529 "will be removed in kernel version 3.4. Please migrate to "
530 "using the 'enable_oplocks' module parameter in cifs.ko.\n");
531 rc = get_user(c, buffer);
532 if (rc)
533 return rc;
534 if (c == '0' || c == 'n' || c == 'N')
535 enable_oplocks = false;
536 else if (c == '1' || c == 'y' || c == 'Y')
537 enable_oplocks = true;
538
539 return count;
540}
541
542static const struct file_operations cifs_oplock_proc_fops = {
543 .owner = THIS_MODULE,
544 .open = cifs_oplock_proc_open,
545 .read = seq_read,
546 .llseek = seq_lseek,
547 .release = single_release,
548 .write = cifs_oplock_proc_write,
549};
550
551static int cifs_linux_ext_proc_show(struct seq_file *m, void *v) 509static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
552{ 510{
553 seq_printf(m, "%d\n", linuxExtEnabled); 511 seq_printf(m, "%d\n", linuxExtEnabled);
diff --git a/fs/cifs/cifs_debug.h b/fs/cifs/cifs_debug.h
index 8942b28cf80..566e0ae8dc2 100644
--- a/fs/cifs/cifs_debug.h
+++ b/fs/cifs/cifs_debug.h
@@ -26,13 +26,13 @@
26void cifs_dump_mem(char *label, void *data, int length); 26void cifs_dump_mem(char *label, void *data, int length);
27#ifdef CONFIG_CIFS_DEBUG2 27#ifdef CONFIG_CIFS_DEBUG2
28#define DBG2 2 28#define DBG2 2
29void cifs_dump_detail(struct smb_hdr *); 29void cifs_dump_detail(void *);
30void cifs_dump_mids(struct TCP_Server_Info *); 30void cifs_dump_mids(struct TCP_Server_Info *);
31#else 31#else
32#define DBG2 0 32#define DBG2 0
33#endif 33#endif
34extern int traceSMB; /* flag which enables the function below */ 34extern int traceSMB; /* flag which enables the function below */
35void dump_smb(struct smb_hdr *, int); 35void dump_smb(void *, int);
36#define CIFS_INFO 0x01 36#define CIFS_INFO 0x01
37#define CIFS_RC 0x02 37#define CIFS_RC 0x02
38#define CIFS_TIMER 0x04 38#define CIFS_TIMER 0x04
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index eee522c56ef..d3421282244 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -85,6 +85,8 @@ extern mempool_t *cifs_sm_req_poolp;
85extern mempool_t *cifs_req_poolp; 85extern mempool_t *cifs_req_poolp;
86extern mempool_t *cifs_mid_poolp; 86extern mempool_t *cifs_mid_poolp;
87 87
88struct workqueue_struct *cifsiod_wq;
89
88static int 90static int
89cifs_read_super(struct super_block *sb) 91cifs_read_super(struct super_block *sb)
90{ 92{
@@ -1111,9 +1113,15 @@ init_cifs(void)
1111 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ); 1113 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ);
1112 } 1114 }
1113 1115
1116 cifsiod_wq = alloc_workqueue("cifsiod", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1117 if (!cifsiod_wq) {
1118 rc = -ENOMEM;
1119 goto out_clean_proc;
1120 }
1121
1114 rc = cifs_fscache_register(); 1122 rc = cifs_fscache_register();
1115 if (rc) 1123 if (rc)
1116 goto out_clean_proc; 1124 goto out_destroy_wq;
1117 1125
1118 rc = cifs_init_inodecache(); 1126 rc = cifs_init_inodecache();
1119 if (rc) 1127 if (rc)
@@ -1161,6 +1169,8 @@ out_destroy_inodecache:
1161 cifs_destroy_inodecache(); 1169 cifs_destroy_inodecache();
1162out_unreg_fscache: 1170out_unreg_fscache:
1163 cifs_fscache_unregister(); 1171 cifs_fscache_unregister();
1172out_destroy_wq:
1173 destroy_workqueue(cifsiod_wq);
1164out_clean_proc: 1174out_clean_proc:
1165 cifs_proc_clean(); 1175 cifs_proc_clean();
1166 return rc; 1176 return rc;
@@ -1183,6 +1193,7 @@ exit_cifs(void)
1183 cifs_destroy_mids(); 1193 cifs_destroy_mids();
1184 cifs_destroy_inodecache(); 1194 cifs_destroy_inodecache();
1185 cifs_fscache_unregister(); 1195 cifs_fscache_unregister();
1196 destroy_workqueue(cifsiod_wq);
1186 cifs_proc_clean(); 1197 cifs_proc_clean();
1187} 1198}
1188 1199
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 339ebe3ebc0..4ff6313f0a9 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -230,6 +230,12 @@ struct cifs_mnt_data {
230 int flags; 230 int flags;
231}; 231};
232 232
233static inline unsigned int
234get_rfc1002_length(void *buf)
235{
236 return be32_to_cpu(*((__be32 *)buf));
237}
238
233struct TCP_Server_Info { 239struct TCP_Server_Info {
234 struct list_head tcp_ses_list; 240 struct list_head tcp_ses_list;
235 struct list_head smb_ses_list; 241 struct list_head smb_ses_list;
@@ -276,7 +282,7 @@ struct TCP_Server_Info {
276 vcnumbers */ 282 vcnumbers */
277 int capabilities; /* allow selective disabling of caps by smb sess */ 283 int capabilities; /* allow selective disabling of caps by smb sess */
278 int timeAdj; /* Adjust for difference in server time zone in sec */ 284 int timeAdj; /* Adjust for difference in server time zone in sec */
279 __u16 CurrentMid; /* multiplex id - rotating counter */ 285 __u64 CurrentMid; /* multiplex id - rotating counter */
280 char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */ 286 char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */
281 /* 16th byte of RFC1001 workstation name is always null */ 287 /* 16th byte of RFC1001 workstation name is always null */
282 char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; 288 char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
@@ -335,6 +341,18 @@ has_credits(struct TCP_Server_Info *server, int *credits)
335 return num > 0; 341 return num > 0;
336} 342}
337 343
344static inline size_t
345header_size(void)
346{
347 return sizeof(struct smb_hdr);
348}
349
350static inline size_t
351max_header_size(void)
352{
353 return MAX_CIFS_HDR_SIZE;
354}
355
338/* 356/*
339 * Macros to allow the TCP_Server_Info->net field and related code to drop out 357 * Macros to allow the TCP_Server_Info->net field and related code to drop out
340 * when CONFIG_NET_NS isn't set. 358 * when CONFIG_NET_NS isn't set.
@@ -583,9 +601,11 @@ struct cifs_io_parms {
583 * Take a reference on the file private data. Must be called with 601 * Take a reference on the file private data. Must be called with
584 * cifs_file_list_lock held. 602 * cifs_file_list_lock held.
585 */ 603 */
586static inline void cifsFileInfo_get(struct cifsFileInfo *cifs_file) 604static inline
605struct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file)
587{ 606{
588 ++cifs_file->count; 607 ++cifs_file->count;
608 return cifs_file;
589} 609}
590 610
591void cifsFileInfo_put(struct cifsFileInfo *cifs_file); 611void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
@@ -606,7 +626,7 @@ struct cifsInodeInfo {
606 bool delete_pending; /* DELETE_ON_CLOSE is set */ 626 bool delete_pending; /* DELETE_ON_CLOSE is set */
607 bool invalid_mapping; /* pagecache is invalid */ 627 bool invalid_mapping; /* pagecache is invalid */
608 unsigned long time; /* jiffies of last update of inode */ 628 unsigned long time; /* jiffies of last update of inode */
609 u64 server_eof; /* current file size on server */ 629 u64 server_eof; /* current file size on server -- protected by i_lock */
610 u64 uniqueid; /* server inode number */ 630 u64 uniqueid; /* server inode number */
611 u64 createtime; /* creation time on server */ 631 u64 createtime; /* creation time on server */
612#ifdef CONFIG_CIFS_FSCACHE 632#ifdef CONFIG_CIFS_FSCACHE
@@ -713,8 +733,8 @@ typedef void (mid_callback_t)(struct mid_q_entry *mid);
713/* one of these for every pending CIFS request to the server */ 733/* one of these for every pending CIFS request to the server */
714struct mid_q_entry { 734struct mid_q_entry {
715 struct list_head qhead; /* mids waiting on reply from this server */ 735 struct list_head qhead; /* mids waiting on reply from this server */
716 __u16 mid; /* multiplex id */ 736 __u64 mid; /* multiplex id */
717 __u16 pid; /* process id */ 737 __u32 pid; /* process id */
718 __u32 sequence_number; /* for CIFS signing */ 738 __u32 sequence_number; /* for CIFS signing */
719 unsigned long when_alloc; /* when mid was created */ 739 unsigned long when_alloc; /* when mid was created */
720#ifdef CONFIG_CIFS_STATS2 740#ifdef CONFIG_CIFS_STATS2
@@ -724,10 +744,10 @@ struct mid_q_entry {
724 mid_receive_t *receive; /* call receive callback */ 744 mid_receive_t *receive; /* call receive callback */
725 mid_callback_t *callback; /* call completion callback */ 745 mid_callback_t *callback; /* call completion callback */
726 void *callback_data; /* general purpose pointer for callback */ 746 void *callback_data; /* general purpose pointer for callback */
727 struct smb_hdr *resp_buf; /* pointer to received SMB header */ 747 void *resp_buf; /* pointer to received SMB header */
728 int midState; /* wish this were enum but can not pass to wait_event */ 748 int mid_state; /* wish this were enum but can not pass to wait_event */
729 __u8 command; /* smb command code */ 749 __le16 command; /* smb command code */
730 bool largeBuf:1; /* if valid response, is pointer to large buf */ 750 bool large_buf:1; /* if valid response, is pointer to large buf */
731 bool multiRsp:1; /* multiple trans2 responses for one request */ 751 bool multiRsp:1; /* multiple trans2 responses for one request */
732 bool multiEnd:1; /* both received */ 752 bool multiEnd:1; /* both received */
733}; 753};
@@ -1052,5 +1072,6 @@ GLOBAL_EXTERN spinlock_t gidsidlock;
1052void cifs_oplock_break(struct work_struct *work); 1072void cifs_oplock_break(struct work_struct *work);
1053 1073
1054extern const struct slow_work_ops cifs_oplock_break_ops; 1074extern const struct slow_work_ops cifs_oplock_break_ops;
1075extern struct workqueue_struct *cifsiod_wq;
1055 1076
1056#endif /* _CIFS_GLOB_H */ 1077#endif /* _CIFS_GLOB_H */
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 503e73d8bdb..96192c1e380 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -77,7 +77,7 @@ extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *,
77 struct smb_hdr * /* out */ , 77 struct smb_hdr * /* out */ ,
78 int * /* bytes returned */ , const int long_op); 78 int * /* bytes returned */ , const int long_op);
79extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, 79extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses,
80 struct smb_hdr *in_buf, int flags); 80 char *in_buf, int flags);
81extern int cifs_check_receive(struct mid_q_entry *mid, 81extern int cifs_check_receive(struct mid_q_entry *mid,
82 struct TCP_Server_Info *server, bool log_error); 82 struct TCP_Server_Info *server, bool log_error);
83extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, 83extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *,
@@ -91,9 +91,8 @@ extern int SendReceiveBlockingLock(const unsigned int xid,
91extern void cifs_add_credits(struct TCP_Server_Info *server, 91extern void cifs_add_credits(struct TCP_Server_Info *server,
92 const unsigned int add); 92 const unsigned int add);
93extern void cifs_set_credits(struct TCP_Server_Info *server, const int val); 93extern void cifs_set_credits(struct TCP_Server_Info *server, const int val);
94extern int checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length); 94extern int checkSMB(char *buf, unsigned int length);
95extern bool is_valid_oplock_break(struct smb_hdr *smb, 95extern bool is_valid_oplock_break(char *, struct TCP_Server_Info *);
96 struct TCP_Server_Info *);
97extern bool backup_cred(struct cifs_sb_info *); 96extern bool backup_cred(struct cifs_sb_info *);
98extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof); 97extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof);
99extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, 98extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
@@ -107,7 +106,7 @@ extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
107extern int cifs_set_port(struct sockaddr *addr, const unsigned short int port); 106extern int cifs_set_port(struct sockaddr *addr, const unsigned short int port);
108extern int cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len, 107extern int cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len,
109 const unsigned short int port); 108 const unsigned short int port);
110extern int map_smb_to_linux_error(struct smb_hdr *smb, bool logErr); 109extern int map_smb_to_linux_error(char *buf, bool logErr);
111extern void header_assemble(struct smb_hdr *, char /* command */ , 110extern void header_assemble(struct smb_hdr *, char /* command */ ,
112 const struct cifs_tcon *, int /* length of 111 const struct cifs_tcon *, int /* length of
113 fixed section (word count) in two byte units */); 112 fixed section (word count) in two byte units */);
@@ -116,7 +115,7 @@ extern int small_smb_init_no_tc(const int smb_cmd, const int wct,
116 void **request_buf); 115 void **request_buf);
117extern int CIFS_SessSetup(unsigned int xid, struct cifs_ses *ses, 116extern int CIFS_SessSetup(unsigned int xid, struct cifs_ses *ses,
118 const struct nls_table *nls_cp); 117 const struct nls_table *nls_cp);
119extern __u16 GetNextMid(struct TCP_Server_Info *server); 118extern __u64 GetNextMid(struct TCP_Server_Info *server);
120extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601); 119extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601);
121extern u64 cifs_UnixTimeToNT(struct timespec); 120extern u64 cifs_UnixTimeToNT(struct timespec);
122extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, 121extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time,
@@ -484,18 +483,25 @@ int cifs_async_readv(struct cifs_readdata *rdata);
484/* asynchronous write support */ 483/* asynchronous write support */
485struct cifs_writedata { 484struct cifs_writedata {
486 struct kref refcount; 485 struct kref refcount;
486 struct list_head list;
487 struct completion done;
487 enum writeback_sync_modes sync_mode; 488 enum writeback_sync_modes sync_mode;
488 struct work_struct work; 489 struct work_struct work;
489 struct cifsFileInfo *cfile; 490 struct cifsFileInfo *cfile;
490 __u64 offset; 491 __u64 offset;
492 pid_t pid;
491 unsigned int bytes; 493 unsigned int bytes;
492 int result; 494 int result;
495 void (*marshal_iov) (struct kvec *iov,
496 struct cifs_writedata *wdata);
493 unsigned int nr_pages; 497 unsigned int nr_pages;
494 struct page *pages[1]; 498 struct page *pages[1];
495}; 499};
496 500
497int cifs_async_writev(struct cifs_writedata *wdata); 501int cifs_async_writev(struct cifs_writedata *wdata);
498struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages); 502void cifs_writev_complete(struct work_struct *work);
503struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages,
504 work_func_t complete);
499void cifs_writedata_release(struct kref *refcount); 505void cifs_writedata_release(struct kref *refcount);
500 506
501#endif /* _CIFSPROTO_H */ 507#endif /* _CIFSPROTO_H */
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 70aac35c398..8fecc99be34 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -696,7 +696,7 @@ CIFSSMBTDis(const int xid, struct cifs_tcon *tcon)
696 if (rc) 696 if (rc)
697 return rc; 697 return rc;
698 698
699 rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0); 699 rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0);
700 if (rc) 700 if (rc)
701 cFYI(1, "Tree disconnect failed %d", rc); 701 cFYI(1, "Tree disconnect failed %d", rc);
702 702
@@ -792,7 +792,7 @@ CIFSSMBLogoff(const int xid, struct cifs_ses *ses)
792 pSMB->hdr.Uid = ses->Suid; 792 pSMB->hdr.Uid = ses->Suid;
793 793
794 pSMB->AndXCommand = 0xFF; 794 pSMB->AndXCommand = 0xFF;
795 rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); 795 rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0);
796session_already_dead: 796session_already_dead:
797 mutex_unlock(&ses->session_mutex); 797 mutex_unlock(&ses->session_mutex);
798 798
@@ -1414,8 +1414,7 @@ cifs_readdata_free(struct cifs_readdata *rdata)
1414static int 1414static int
1415cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) 1415cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1416{ 1416{
1417 READ_RSP *rsp = (READ_RSP *)server->smallbuf; 1417 unsigned int rfclen = get_rfc1002_length(server->smallbuf);
1418 unsigned int rfclen = be32_to_cpu(rsp->hdr.smb_buf_length);
1419 int remaining = rfclen + 4 - server->total_read; 1418 int remaining = rfclen + 4 - server->total_read;
1420 struct cifs_readdata *rdata = mid->callback_data; 1419 struct cifs_readdata *rdata = mid->callback_data;
1421 1420
@@ -1424,7 +1423,7 @@ cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1424 1423
1425 length = cifs_read_from_socket(server, server->bigbuf, 1424 length = cifs_read_from_socket(server, server->bigbuf,
1426 min_t(unsigned int, remaining, 1425 min_t(unsigned int, remaining,
1427 CIFSMaxBufSize + MAX_CIFS_HDR_SIZE)); 1426 CIFSMaxBufSize + max_header_size()));
1428 if (length < 0) 1427 if (length < 0)
1429 return length; 1428 return length;
1430 server->total_read += length; 1429 server->total_read += length;
@@ -1435,19 +1434,40 @@ cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1435 return 0; 1434 return 0;
1436} 1435}
1437 1436
1437static inline size_t
1438read_rsp_size(void)
1439{
1440 return sizeof(READ_RSP);
1441}
1442
1443static inline unsigned int
1444read_data_offset(char *buf)
1445{
1446 READ_RSP *rsp = (READ_RSP *)buf;
1447 return le16_to_cpu(rsp->DataOffset);
1448}
1449
1450static inline unsigned int
1451read_data_length(char *buf)
1452{
1453 READ_RSP *rsp = (READ_RSP *)buf;
1454 return (le16_to_cpu(rsp->DataLengthHigh) << 16) +
1455 le16_to_cpu(rsp->DataLength);
1456}
1457
1438static int 1458static int
1439cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) 1459cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1440{ 1460{
1441 int length, len; 1461 int length, len;
1442 unsigned int data_offset, remaining, data_len; 1462 unsigned int data_offset, remaining, data_len;
1443 struct cifs_readdata *rdata = mid->callback_data; 1463 struct cifs_readdata *rdata = mid->callback_data;
1444 READ_RSP *rsp = (READ_RSP *)server->smallbuf; 1464 char *buf = server->smallbuf;
1445 unsigned int rfclen = be32_to_cpu(rsp->hdr.smb_buf_length) + 4; 1465 unsigned int buflen = get_rfc1002_length(buf) + 4;
1446 u64 eof; 1466 u64 eof;
1447 pgoff_t eof_index; 1467 pgoff_t eof_index;
1448 struct page *page, *tpage; 1468 struct page *page, *tpage;
1449 1469
1450 cFYI(1, "%s: mid=%u offset=%llu bytes=%u", __func__, 1470 cFYI(1, "%s: mid=%llu offset=%llu bytes=%u", __func__,
1451 mid->mid, rdata->offset, rdata->bytes); 1471 mid->mid, rdata->offset, rdata->bytes);
1452 1472
1453 /* 1473 /*
@@ -1455,10 +1475,9 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1455 * can if there's not enough data. At this point, we've read down to 1475 * can if there's not enough data. At this point, we've read down to
1456 * the Mid. 1476 * the Mid.
1457 */ 1477 */
1458 len = min_t(unsigned int, rfclen, sizeof(*rsp)) - 1478 len = min_t(unsigned int, buflen, read_rsp_size()) - header_size() + 1;
1459 sizeof(struct smb_hdr) + 1;
1460 1479
1461 rdata->iov[0].iov_base = server->smallbuf + sizeof(struct smb_hdr) - 1; 1480 rdata->iov[0].iov_base = buf + header_size() - 1;
1462 rdata->iov[0].iov_len = len; 1481 rdata->iov[0].iov_len = len;
1463 1482
1464 length = cifs_readv_from_socket(server, rdata->iov, 1, len); 1483 length = cifs_readv_from_socket(server, rdata->iov, 1, len);
@@ -1467,7 +1486,7 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1467 server->total_read += length; 1486 server->total_read += length;
1468 1487
1469 /* Was the SMB read successful? */ 1488 /* Was the SMB read successful? */
1470 rdata->result = map_smb_to_linux_error(&rsp->hdr, false); 1489 rdata->result = map_smb_to_linux_error(buf, false);
1471 if (rdata->result != 0) { 1490 if (rdata->result != 0) {
1472 cFYI(1, "%s: server returned error %d", __func__, 1491 cFYI(1, "%s: server returned error %d", __func__,
1473 rdata->result); 1492 rdata->result);
@@ -1475,14 +1494,14 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1475 } 1494 }
1476 1495
1477 /* Is there enough to get to the rest of the READ_RSP header? */ 1496 /* Is there enough to get to the rest of the READ_RSP header? */
1478 if (server->total_read < sizeof(READ_RSP)) { 1497 if (server->total_read < read_rsp_size()) {
1479 cFYI(1, "%s: server returned short header. got=%u expected=%zu", 1498 cFYI(1, "%s: server returned short header. got=%u expected=%zu",
1480 __func__, server->total_read, sizeof(READ_RSP)); 1499 __func__, server->total_read, read_rsp_size());
1481 rdata->result = -EIO; 1500 rdata->result = -EIO;
1482 return cifs_readv_discard(server, mid); 1501 return cifs_readv_discard(server, mid);
1483 } 1502 }
1484 1503
1485 data_offset = le16_to_cpu(rsp->DataOffset) + 4; 1504 data_offset = read_data_offset(buf) + 4;
1486 if (data_offset < server->total_read) { 1505 if (data_offset < server->total_read) {
1487 /* 1506 /*
1488 * win2k8 sometimes sends an offset of 0 when the read 1507 * win2k8 sometimes sends an offset of 0 when the read
@@ -1506,7 +1525,7 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1506 len = data_offset - server->total_read; 1525 len = data_offset - server->total_read;
1507 if (len > 0) { 1526 if (len > 0) {
1508 /* read any junk before data into the rest of smallbuf */ 1527 /* read any junk before data into the rest of smallbuf */
1509 rdata->iov[0].iov_base = server->smallbuf + server->total_read; 1528 rdata->iov[0].iov_base = buf + server->total_read;
1510 rdata->iov[0].iov_len = len; 1529 rdata->iov[0].iov_len = len;
1511 length = cifs_readv_from_socket(server, rdata->iov, 1, len); 1530 length = cifs_readv_from_socket(server, rdata->iov, 1, len);
1512 if (length < 0) 1531 if (length < 0)
@@ -1515,15 +1534,14 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1515 } 1534 }
1516 1535
1517 /* set up first iov for signature check */ 1536 /* set up first iov for signature check */
1518 rdata->iov[0].iov_base = server->smallbuf; 1537 rdata->iov[0].iov_base = buf;
1519 rdata->iov[0].iov_len = server->total_read; 1538 rdata->iov[0].iov_len = server->total_read;
1520 cFYI(1, "0: iov_base=%p iov_len=%zu", 1539 cFYI(1, "0: iov_base=%p iov_len=%zu",
1521 rdata->iov[0].iov_base, rdata->iov[0].iov_len); 1540 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
1522 1541
1523 /* how much data is in the response? */ 1542 /* how much data is in the response? */
1524 data_len = le16_to_cpu(rsp->DataLengthHigh) << 16; 1543 data_len = read_data_length(buf);
1525 data_len += le16_to_cpu(rsp->DataLength); 1544 if (data_offset + data_len > buflen) {
1526 if (data_offset + data_len > rfclen) {
1527 /* data_len is corrupt -- discard frame */ 1545 /* data_len is corrupt -- discard frame */
1528 rdata->result = -EIO; 1546 rdata->result = -EIO;
1529 return cifs_readv_discard(server, mid); 1547 return cifs_readv_discard(server, mid);
@@ -1602,11 +1620,11 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1602 1620
1603 rdata->bytes = length; 1621 rdata->bytes = length;
1604 1622
1605 cFYI(1, "total_read=%u rfclen=%u remaining=%u", server->total_read, 1623 cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read,
1606 rfclen, remaining); 1624 buflen, remaining);
1607 1625
1608 /* discard anything left over */ 1626 /* discard anything left over */
1609 if (server->total_read < rfclen) 1627 if (server->total_read < buflen)
1610 return cifs_readv_discard(server, mid); 1628 return cifs_readv_discard(server, mid);
1611 1629
1612 dequeue_mid(mid, false); 1630 dequeue_mid(mid, false);
@@ -1647,10 +1665,10 @@ cifs_readv_callback(struct mid_q_entry *mid)
1647 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); 1665 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink);
1648 struct TCP_Server_Info *server = tcon->ses->server; 1666 struct TCP_Server_Info *server = tcon->ses->server;
1649 1667
1650 cFYI(1, "%s: mid=%u state=%d result=%d bytes=%u", __func__, 1668 cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__,
1651 mid->mid, mid->midState, rdata->result, rdata->bytes); 1669 mid->mid, mid->mid_state, rdata->result, rdata->bytes);
1652 1670
1653 switch (mid->midState) { 1671 switch (mid->mid_state) {
1654 case MID_RESPONSE_RECEIVED: 1672 case MID_RESPONSE_RECEIVED:
1655 /* result already set, check signature */ 1673 /* result already set, check signature */
1656 if (server->sec_mode & 1674 if (server->sec_mode &
@@ -1671,7 +1689,7 @@ cifs_readv_callback(struct mid_q_entry *mid)
1671 rdata->result = -EIO; 1689 rdata->result = -EIO;
1672 } 1690 }
1673 1691
1674 queue_work(system_nrt_wq, &rdata->work); 1692 queue_work(cifsiod_wq, &rdata->work);
1675 DeleteMidQEntry(mid); 1693 DeleteMidQEntry(mid);
1676 cifs_add_credits(server, 1); 1694 cifs_add_credits(server, 1);
1677} 1695}
@@ -2017,7 +2035,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
2017 kref_put(&wdata->refcount, cifs_writedata_release); 2035 kref_put(&wdata->refcount, cifs_writedata_release);
2018} 2036}
2019 2037
2020static void 2038void
2021cifs_writev_complete(struct work_struct *work) 2039cifs_writev_complete(struct work_struct *work)
2022{ 2040{
2023 struct cifs_writedata *wdata = container_of(work, 2041 struct cifs_writedata *wdata = container_of(work,
@@ -2026,7 +2044,9 @@ cifs_writev_complete(struct work_struct *work)
2026 int i = 0; 2044 int i = 0;
2027 2045
2028 if (wdata->result == 0) { 2046 if (wdata->result == 0) {
2047 spin_lock(&inode->i_lock);
2029 cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); 2048 cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes);
2049 spin_unlock(&inode->i_lock);
2030 cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), 2050 cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink),
2031 wdata->bytes); 2051 wdata->bytes);
2032 } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) 2052 } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN)
@@ -2047,7 +2067,7 @@ cifs_writev_complete(struct work_struct *work)
2047} 2067}
2048 2068
2049struct cifs_writedata * 2069struct cifs_writedata *
2050cifs_writedata_alloc(unsigned int nr_pages) 2070cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
2051{ 2071{
2052 struct cifs_writedata *wdata; 2072 struct cifs_writedata *wdata;
2053 2073
@@ -2061,14 +2081,16 @@ cifs_writedata_alloc(unsigned int nr_pages)
2061 wdata = kzalloc(sizeof(*wdata) + 2081 wdata = kzalloc(sizeof(*wdata) +
2062 sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); 2082 sizeof(struct page *) * (nr_pages - 1), GFP_NOFS);
2063 if (wdata != NULL) { 2083 if (wdata != NULL) {
2064 INIT_WORK(&wdata->work, cifs_writev_complete);
2065 kref_init(&wdata->refcount); 2084 kref_init(&wdata->refcount);
2085 INIT_LIST_HEAD(&wdata->list);
2086 init_completion(&wdata->done);
2087 INIT_WORK(&wdata->work, complete);
2066 } 2088 }
2067 return wdata; 2089 return wdata;
2068} 2090}
2069 2091
2070/* 2092/*
2071 * Check the midState and signature on received buffer (if any), and queue the 2093 * Check the mid_state and signature on received buffer (if any), and queue the
2072 * workqueue completion task. 2094 * workqueue completion task.
2073 */ 2095 */
2074static void 2096static void
@@ -2079,7 +2101,7 @@ cifs_writev_callback(struct mid_q_entry *mid)
2079 unsigned int written; 2101 unsigned int written;
2080 WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; 2102 WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf;
2081 2103
2082 switch (mid->midState) { 2104 switch (mid->mid_state) {
2083 case MID_RESPONSE_RECEIVED: 2105 case MID_RESPONSE_RECEIVED:
2084 wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); 2106 wdata->result = cifs_check_receive(mid, tcon->ses->server, 0);
2085 if (wdata->result != 0) 2107 if (wdata->result != 0)
@@ -2111,7 +2133,7 @@ cifs_writev_callback(struct mid_q_entry *mid)
2111 break; 2133 break;
2112 } 2134 }
2113 2135
2114 queue_work(system_nrt_wq, &wdata->work); 2136 queue_work(cifsiod_wq, &wdata->work);
2115 DeleteMidQEntry(mid); 2137 DeleteMidQEntry(mid);
2116 cifs_add_credits(tcon->ses->server, 1); 2138 cifs_add_credits(tcon->ses->server, 1);
2117} 2139}
@@ -2124,7 +2146,6 @@ cifs_async_writev(struct cifs_writedata *wdata)
2124 WRITE_REQ *smb = NULL; 2146 WRITE_REQ *smb = NULL;
2125 int wct; 2147 int wct;
2126 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); 2148 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
2127 struct inode *inode = wdata->cfile->dentry->d_inode;
2128 struct kvec *iov = NULL; 2149 struct kvec *iov = NULL;
2129 2150
2130 if (tcon->ses->capabilities & CAP_LARGE_FILES) { 2151 if (tcon->ses->capabilities & CAP_LARGE_FILES) {
@@ -2148,8 +2169,8 @@ cifs_async_writev(struct cifs_writedata *wdata)
2148 goto async_writev_out; 2169 goto async_writev_out;
2149 } 2170 }
2150 2171
2151 smb->hdr.Pid = cpu_to_le16((__u16)wdata->cfile->pid); 2172 smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid);
2152 smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->cfile->pid >> 16)); 2173 smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16));
2153 2174
2154 smb->AndXCommand = 0xFF; /* none */ 2175 smb->AndXCommand = 0xFF; /* none */
2155 smb->Fid = wdata->cfile->netfid; 2176 smb->Fid = wdata->cfile->netfid;
@@ -2167,15 +2188,13 @@ cifs_async_writev(struct cifs_writedata *wdata)
2167 iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; 2188 iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1;
2168 iov[0].iov_base = smb; 2189 iov[0].iov_base = smb;
2169 2190
2170 /* marshal up the pages into iov array */ 2191 /*
2171 wdata->bytes = 0; 2192 * This function should marshal up the page array into the kvec
2172 for (i = 0; i < wdata->nr_pages; i++) { 2193 * array, reserving [0] for the header. It should kmap the pages
2173 iov[i + 1].iov_len = min(inode->i_size - 2194 * and set the iov_len properly for each one. It may also set
2174 page_offset(wdata->pages[i]), 2195 * wdata->bytes too.
2175 (loff_t)PAGE_CACHE_SIZE); 2196 */
2176 iov[i + 1].iov_base = kmap(wdata->pages[i]); 2197 wdata->marshal_iov(iov, wdata);
2177 wdata->bytes += iov[i + 1].iov_len;
2178 }
2179 2198
2180 cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); 2199 cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes);
2181 2200
@@ -2420,8 +2439,7 @@ CIFSSMBLock(const int xid, struct cifs_tcon *tcon,
2420 (struct smb_hdr *) pSMB, &bytes_returned); 2439 (struct smb_hdr *) pSMB, &bytes_returned);
2421 cifs_small_buf_release(pSMB); 2440 cifs_small_buf_release(pSMB);
2422 } else { 2441 } else {
2423 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *)pSMB, 2442 rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, timeout);
2424 timeout);
2425 /* SMB buffer freed by function above */ 2443 /* SMB buffer freed by function above */
2426 } 2444 }
2427 cifs_stats_inc(&tcon->num_locks); 2445 cifs_stats_inc(&tcon->num_locks);
@@ -2588,7 +2606,7 @@ CIFSSMBClose(const int xid, struct cifs_tcon *tcon, int smb_file_id)
2588 pSMB->FileID = (__u16) smb_file_id; 2606 pSMB->FileID = (__u16) smb_file_id;
2589 pSMB->LastWriteTime = 0xFFFFFFFF; 2607 pSMB->LastWriteTime = 0xFFFFFFFF;
2590 pSMB->ByteCount = 0; 2608 pSMB->ByteCount = 0;
2591 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); 2609 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0);
2592 cifs_stats_inc(&tcon->num_closes); 2610 cifs_stats_inc(&tcon->num_closes);
2593 if (rc) { 2611 if (rc) {
2594 if (rc != -EINTR) { 2612 if (rc != -EINTR) {
@@ -2617,7 +2635,7 @@ CIFSSMBFlush(const int xid, struct cifs_tcon *tcon, int smb_file_id)
2617 2635
2618 pSMB->FileID = (__u16) smb_file_id; 2636 pSMB->FileID = (__u16) smb_file_id;
2619 pSMB->ByteCount = 0; 2637 pSMB->ByteCount = 0;
2620 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); 2638 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0);
2621 cifs_stats_inc(&tcon->num_flushes); 2639 cifs_stats_inc(&tcon->num_flushes);
2622 if (rc) 2640 if (rc)
2623 cERROR(1, "Send error in Flush = %d", rc); 2641 cERROR(1, "Send error in Flush = %d", rc);
@@ -4625,7 +4643,7 @@ CIFSFindClose(const int xid, struct cifs_tcon *tcon,
4625 4643
4626 pSMB->FileID = searchHandle; 4644 pSMB->FileID = searchHandle;
4627 pSMB->ByteCount = 0; 4645 pSMB->ByteCount = 0;
4628 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); 4646 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0);
4629 if (rc) 4647 if (rc)
4630 cERROR(1, "Send error in FindClose = %d", rc); 4648 cERROR(1, "Send error in FindClose = %d", rc);
4631 4649
@@ -5646,7 +5664,7 @@ CIFSSMBSetFileSize(const int xid, struct cifs_tcon *tcon, __u64 size,
5646 pSMB->Reserved4 = 0; 5664 pSMB->Reserved4 = 0;
5647 inc_rfc1001_len(pSMB, byte_count); 5665 inc_rfc1001_len(pSMB, byte_count);
5648 pSMB->ByteCount = cpu_to_le16(byte_count); 5666 pSMB->ByteCount = cpu_to_le16(byte_count);
5649 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); 5667 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0);
5650 if (rc) { 5668 if (rc) {
5651 cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc); 5669 cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc);
5652 } 5670 }
@@ -5715,7 +5733,7 @@ CIFSSMBSetFileInfo(const int xid, struct cifs_tcon *tcon,
5715 inc_rfc1001_len(pSMB, byte_count); 5733 inc_rfc1001_len(pSMB, byte_count);
5716 pSMB->ByteCount = cpu_to_le16(byte_count); 5734 pSMB->ByteCount = cpu_to_le16(byte_count);
5717 memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); 5735 memcpy(data_offset, data, sizeof(FILE_BASIC_INFO));
5718 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); 5736 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0);
5719 if (rc) 5737 if (rc)
5720 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); 5738 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc);
5721 5739
@@ -5774,7 +5792,7 @@ CIFSSMBSetFileDisposition(const int xid, struct cifs_tcon *tcon,
5774 inc_rfc1001_len(pSMB, byte_count); 5792 inc_rfc1001_len(pSMB, byte_count);
5775 pSMB->ByteCount = cpu_to_le16(byte_count); 5793 pSMB->ByteCount = cpu_to_le16(byte_count);
5776 *data_offset = delete_file ? 1 : 0; 5794 *data_offset = delete_file ? 1 : 0;
5777 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); 5795 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0);
5778 if (rc) 5796 if (rc)
5779 cFYI(1, "Send error in SetFileDisposition = %d", rc); 5797 cFYI(1, "Send error in SetFileDisposition = %d", rc);
5780 5798
@@ -6006,7 +6024,7 @@ CIFSSMBUnixSetFileInfo(const int xid, struct cifs_tcon *tcon,
6006 6024
6007 cifs_fill_unix_set_info(data_offset, args); 6025 cifs_fill_unix_set_info(data_offset, args);
6008 6026
6009 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); 6027 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0);
6010 if (rc) 6028 if (rc)
6011 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); 6029 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc);
6012 6030
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 5560e1d5e54..980815426ac 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -40,6 +40,8 @@
40#include <linux/module.h> 40#include <linux/module.h>
41#include <keys/user-type.h> 41#include <keys/user-type.h>
42#include <net/ipv6.h> 42#include <net/ipv6.h>
43#include <linux/parser.h>
44
43#include "cifspdu.h" 45#include "cifspdu.h"
44#include "cifsglob.h" 46#include "cifsglob.h"
45#include "cifsproto.h" 47#include "cifsproto.h"
@@ -63,6 +65,192 @@ extern mempool_t *cifs_req_poolp;
63#define TLINK_ERROR_EXPIRE (1 * HZ) 65#define TLINK_ERROR_EXPIRE (1 * HZ)
64#define TLINK_IDLE_EXPIRE (600 * HZ) 66#define TLINK_IDLE_EXPIRE (600 * HZ)
65 67
68enum {
69
70 /* Mount options that take no arguments */
71 Opt_user_xattr, Opt_nouser_xattr,
72 Opt_forceuid, Opt_noforceuid,
73 Opt_noblocksend, Opt_noautotune,
74 Opt_hard, Opt_soft, Opt_perm, Opt_noperm,
75 Opt_mapchars, Opt_nomapchars, Opt_sfu,
76 Opt_nosfu, Opt_nodfs, Opt_posixpaths,
77 Opt_noposixpaths, Opt_nounix,
78 Opt_nocase,
79 Opt_brl, Opt_nobrl,
80 Opt_forcemandatorylock, Opt_setuids,
81 Opt_nosetuids, Opt_dynperm, Opt_nodynperm,
82 Opt_nohard, Opt_nosoft,
83 Opt_nointr, Opt_intr,
84 Opt_nostrictsync, Opt_strictsync,
85 Opt_serverino, Opt_noserverino,
86 Opt_rwpidforward, Opt_cifsacl, Opt_nocifsacl,
87 Opt_acl, Opt_noacl, Opt_locallease,
88 Opt_sign, Opt_seal, Opt_direct,
89 Opt_strictcache, Opt_noac,
90 Opt_fsc, Opt_mfsymlinks,
91 Opt_multiuser, Opt_sloppy,
92
93 /* Mount options which take numeric value */
94 Opt_backupuid, Opt_backupgid, Opt_uid,
95 Opt_cruid, Opt_gid, Opt_file_mode,
96 Opt_dirmode, Opt_port,
97 Opt_rsize, Opt_wsize, Opt_actimeo,
98
99 /* Mount options which take string value */
100 Opt_user, Opt_pass, Opt_ip,
101 Opt_unc, Opt_domain,
102 Opt_srcaddr, Opt_prefixpath,
103 Opt_iocharset, Opt_sockopt,
104 Opt_netbiosname, Opt_servern,
105 Opt_ver, Opt_sec,
106
107 /* Mount options to be ignored */
108 Opt_ignore,
109
110 /* Options which could be blank */
111 Opt_blank_pass,
112
113 Opt_err
114};
115
116static const match_table_t cifs_mount_option_tokens = {
117
118 { Opt_user_xattr, "user_xattr" },
119 { Opt_nouser_xattr, "nouser_xattr" },
120 { Opt_forceuid, "forceuid" },
121 { Opt_noforceuid, "noforceuid" },
122 { Opt_noblocksend, "noblocksend" },
123 { Opt_noautotune, "noautotune" },
124 { Opt_hard, "hard" },
125 { Opt_soft, "soft" },
126 { Opt_perm, "perm" },
127 { Opt_noperm, "noperm" },
128 { Opt_mapchars, "mapchars" },
129 { Opt_nomapchars, "nomapchars" },
130 { Opt_sfu, "sfu" },
131 { Opt_nosfu, "nosfu" },
132 { Opt_nodfs, "nodfs" },
133 { Opt_posixpaths, "posixpaths" },
134 { Opt_noposixpaths, "noposixpaths" },
135 { Opt_nounix, "nounix" },
136 { Opt_nounix, "nolinux" },
137 { Opt_nocase, "nocase" },
138 { Opt_nocase, "ignorecase" },
139 { Opt_brl, "brl" },
140 { Opt_nobrl, "nobrl" },
141 { Opt_nobrl, "nolock" },
142 { Opt_forcemandatorylock, "forcemandatorylock" },
143 { Opt_setuids, "setuids" },
144 { Opt_nosetuids, "nosetuids" },
145 { Opt_dynperm, "dynperm" },
146 { Opt_nodynperm, "nodynperm" },
147 { Opt_nohard, "nohard" },
148 { Opt_nosoft, "nosoft" },
149 { Opt_nointr, "nointr" },
150 { Opt_intr, "intr" },
151 { Opt_nostrictsync, "nostrictsync" },
152 { Opt_strictsync, "strictsync" },
153 { Opt_serverino, "serverino" },
154 { Opt_noserverino, "noserverino" },
155 { Opt_rwpidforward, "rwpidforward" },
156 { Opt_cifsacl, "cifsacl" },
157 { Opt_nocifsacl, "nocifsacl" },
158 { Opt_acl, "acl" },
159 { Opt_noacl, "noacl" },
160 { Opt_locallease, "locallease" },
161 { Opt_sign, "sign" },
162 { Opt_seal, "seal" },
163 { Opt_direct, "direct" },
164 { Opt_direct, "forceddirectio" },
165 { Opt_strictcache, "strictcache" },
166 { Opt_noac, "noac" },
167 { Opt_fsc, "fsc" },
168 { Opt_mfsymlinks, "mfsymlinks" },
169 { Opt_multiuser, "multiuser" },
170 { Opt_sloppy, "sloppy" },
171
172 { Opt_backupuid, "backupuid=%s" },
173 { Opt_backupgid, "backupgid=%s" },
174 { Opt_uid, "uid=%s" },
175 { Opt_cruid, "cruid=%s" },
176 { Opt_gid, "gid=%s" },
177 { Opt_file_mode, "file_mode=%s" },
178 { Opt_dirmode, "dirmode=%s" },
179 { Opt_dirmode, "dir_mode=%s" },
180 { Opt_port, "port=%s" },
181 { Opt_rsize, "rsize=%s" },
182 { Opt_wsize, "wsize=%s" },
183 { Opt_actimeo, "actimeo=%s" },
184
185 { Opt_user, "user=%s" },
186 { Opt_user, "username=%s" },
187 { Opt_blank_pass, "pass=" },
188 { Opt_pass, "pass=%s" },
189 { Opt_pass, "password=%s" },
190 { Opt_ip, "ip=%s" },
191 { Opt_ip, "addr=%s" },
192 { Opt_unc, "unc=%s" },
193 { Opt_unc, "target=%s" },
194 { Opt_unc, "path=%s" },
195 { Opt_domain, "dom=%s" },
196 { Opt_domain, "domain=%s" },
197 { Opt_domain, "workgroup=%s" },
198 { Opt_srcaddr, "srcaddr=%s" },
199 { Opt_prefixpath, "prefixpath=%s" },
200 { Opt_iocharset, "iocharset=%s" },
201 { Opt_sockopt, "sockopt=%s" },
202 { Opt_netbiosname, "netbiosname=%s" },
203 { Opt_servern, "servern=%s" },
204 { Opt_ver, "ver=%s" },
205 { Opt_ver, "vers=%s" },
206 { Opt_ver, "version=%s" },
207 { Opt_sec, "sec=%s" },
208
209 { Opt_ignore, "cred" },
210 { Opt_ignore, "credentials" },
211 { Opt_ignore, "guest" },
212 { Opt_ignore, "rw" },
213 { Opt_ignore, "ro" },
214 { Opt_ignore, "suid" },
215 { Opt_ignore, "nosuid" },
216 { Opt_ignore, "exec" },
217 { Opt_ignore, "noexec" },
218 { Opt_ignore, "nodev" },
219 { Opt_ignore, "noauto" },
220 { Opt_ignore, "dev" },
221 { Opt_ignore, "mand" },
222 { Opt_ignore, "nomand" },
223 { Opt_ignore, "_netdev" },
224
225 { Opt_err, NULL }
226};
227
228enum {
229 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
230 Opt_sec_ntlmsspi, Opt_sec_ntlmssp,
231 Opt_ntlm, Opt_sec_ntlmi, Opt_sec_ntlmv2i,
232 Opt_sec_nontlm, Opt_sec_lanman,
233 Opt_sec_none,
234
235 Opt_sec_err
236};
237
238static const match_table_t cifs_secflavor_tokens = {
239 { Opt_sec_krb5, "krb5" },
240 { Opt_sec_krb5i, "krb5i" },
241 { Opt_sec_krb5p, "krb5p" },
242 { Opt_sec_ntlmsspi, "ntlmsspi" },
243 { Opt_sec_ntlmssp, "ntlmssp" },
244 { Opt_ntlm, "ntlm" },
245 { Opt_sec_ntlmi, "ntlmi" },
246 { Opt_sec_ntlmv2i, "ntlmv2i" },
247 { Opt_sec_nontlm, "nontlm" },
248 { Opt_sec_lanman, "lanman" },
249 { Opt_sec_none, "none" },
250
251 { Opt_sec_err, NULL }
252};
253
66static int ip_connect(struct TCP_Server_Info *server); 254static int ip_connect(struct TCP_Server_Info *server);
67static int generic_ip_connect(struct TCP_Server_Info *server); 255static int generic_ip_connect(struct TCP_Server_Info *server);
68static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink); 256static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
@@ -143,8 +331,8 @@ cifs_reconnect(struct TCP_Server_Info *server)
143 spin_lock(&GlobalMid_Lock); 331 spin_lock(&GlobalMid_Lock);
144 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { 332 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
145 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 333 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
146 if (mid_entry->midState == MID_REQUEST_SUBMITTED) 334 if (mid_entry->mid_state == MID_REQUEST_SUBMITTED)
147 mid_entry->midState = MID_RETRY_NEEDED; 335 mid_entry->mid_state = MID_RETRY_NEEDED;
148 list_move(&mid_entry->qhead, &retry_list); 336 list_move(&mid_entry->qhead, &retry_list);
149 } 337 }
150 spin_unlock(&GlobalMid_Lock); 338 spin_unlock(&GlobalMid_Lock);
@@ -183,8 +371,9 @@ cifs_reconnect(struct TCP_Server_Info *server)
183 -EINVAL = invalid transact2 371 -EINVAL = invalid transact2
184 372
185 */ 373 */
186static int check2ndT2(struct smb_hdr *pSMB) 374static int check2ndT2(char *buf)
187{ 375{
376 struct smb_hdr *pSMB = (struct smb_hdr *)buf;
188 struct smb_t2_rsp *pSMBt; 377 struct smb_t2_rsp *pSMBt;
189 int remaining; 378 int remaining;
190 __u16 total_data_size, data_in_this_rsp; 379 __u16 total_data_size, data_in_this_rsp;
@@ -224,10 +413,10 @@ static int check2ndT2(struct smb_hdr *pSMB)
224 return remaining; 413 return remaining;
225} 414}
226 415
227static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB) 416static int coalesce_t2(char *second_buf, struct smb_hdr *target_hdr)
228{ 417{
229 struct smb_t2_rsp *pSMBs = (struct smb_t2_rsp *)psecond; 418 struct smb_t2_rsp *pSMBs = (struct smb_t2_rsp *)second_buf;
230 struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)pTargetSMB; 419 struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)target_hdr;
231 char *data_area_of_tgt; 420 char *data_area_of_tgt;
232 char *data_area_of_src; 421 char *data_area_of_src;
233 int remaining; 422 int remaining;
@@ -280,23 +469,23 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
280 put_unaligned_le16(total_in_tgt, &pSMBt->t2_rsp.DataCount); 469 put_unaligned_le16(total_in_tgt, &pSMBt->t2_rsp.DataCount);
281 470
282 /* fix up the BCC */ 471 /* fix up the BCC */
283 byte_count = get_bcc(pTargetSMB); 472 byte_count = get_bcc(target_hdr);
284 byte_count += total_in_src; 473 byte_count += total_in_src;
285 /* is the result too big for the field? */ 474 /* is the result too big for the field? */
286 if (byte_count > USHRT_MAX) { 475 if (byte_count > USHRT_MAX) {
287 cFYI(1, "coalesced BCC too large (%u)", byte_count); 476 cFYI(1, "coalesced BCC too large (%u)", byte_count);
288 return -EPROTO; 477 return -EPROTO;
289 } 478 }
290 put_bcc(byte_count, pTargetSMB); 479 put_bcc(byte_count, target_hdr);
291 480
292 byte_count = be32_to_cpu(pTargetSMB->smb_buf_length); 481 byte_count = be32_to_cpu(target_hdr->smb_buf_length);
293 byte_count += total_in_src; 482 byte_count += total_in_src;
294 /* don't allow buffer to overflow */ 483 /* don't allow buffer to overflow */
295 if (byte_count > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { 484 if (byte_count > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) {
296 cFYI(1, "coalesced BCC exceeds buffer size (%u)", byte_count); 485 cFYI(1, "coalesced BCC exceeds buffer size (%u)", byte_count);
297 return -ENOBUFS; 486 return -ENOBUFS;
298 } 487 }
299 pTargetSMB->smb_buf_length = cpu_to_be32(byte_count); 488 target_hdr->smb_buf_length = cpu_to_be32(byte_count);
300 489
301 /* copy second buffer into end of first buffer */ 490 /* copy second buffer into end of first buffer */
302 memcpy(data_area_of_tgt, data_area_of_src, total_in_src); 491 memcpy(data_area_of_tgt, data_area_of_src, total_in_src);
@@ -334,7 +523,7 @@ cifs_echo_request(struct work_struct *work)
334 server->hostname); 523 server->hostname);
335 524
336requeue_echo: 525requeue_echo:
337 queue_delayed_work(system_nrt_wq, &server->echo, SMB_ECHO_INTERVAL); 526 queue_delayed_work(cifsiod_wq, &server->echo, SMB_ECHO_INTERVAL);
338} 527}
339 528
340static bool 529static bool
@@ -350,7 +539,7 @@ allocate_buffers(struct TCP_Server_Info *server)
350 } 539 }
351 } else if (server->large_buf) { 540 } else if (server->large_buf) {
352 /* we are reusing a dirty large buf, clear its start */ 541 /* we are reusing a dirty large buf, clear its start */
353 memset(server->bigbuf, 0, sizeof(struct smb_hdr)); 542 memset(server->bigbuf, 0, header_size());
354 } 543 }
355 544
356 if (!server->smallbuf) { 545 if (!server->smallbuf) {
@@ -364,7 +553,7 @@ allocate_buffers(struct TCP_Server_Info *server)
364 /* beginning of smb buffer is cleared in our buf_get */ 553 /* beginning of smb buffer is cleared in our buf_get */
365 } else { 554 } else {
366 /* if existing small buf clear beginning */ 555 /* if existing small buf clear beginning */
367 memset(server->smallbuf, 0, sizeof(struct smb_hdr)); 556 memset(server->smallbuf, 0, header_size());
368 } 557 }
369 558
370 return true; 559 return true;
@@ -566,15 +755,16 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)
566} 755}
567 756
568static struct mid_q_entry * 757static struct mid_q_entry *
569find_mid(struct TCP_Server_Info *server, struct smb_hdr *buf) 758find_mid(struct TCP_Server_Info *server, char *buffer)
570{ 759{
760 struct smb_hdr *buf = (struct smb_hdr *)buffer;
571 struct mid_q_entry *mid; 761 struct mid_q_entry *mid;
572 762
573 spin_lock(&GlobalMid_Lock); 763 spin_lock(&GlobalMid_Lock);
574 list_for_each_entry(mid, &server->pending_mid_q, qhead) { 764 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
575 if (mid->mid == buf->Mid && 765 if (mid->mid == buf->Mid &&
576 mid->midState == MID_REQUEST_SUBMITTED && 766 mid->mid_state == MID_REQUEST_SUBMITTED &&
577 mid->command == buf->Command) { 767 le16_to_cpu(mid->command) == buf->Command) {
578 spin_unlock(&GlobalMid_Lock); 768 spin_unlock(&GlobalMid_Lock);
579 return mid; 769 return mid;
580 } 770 }
@@ -591,16 +781,16 @@ dequeue_mid(struct mid_q_entry *mid, bool malformed)
591#endif 781#endif
592 spin_lock(&GlobalMid_Lock); 782 spin_lock(&GlobalMid_Lock);
593 if (!malformed) 783 if (!malformed)
594 mid->midState = MID_RESPONSE_RECEIVED; 784 mid->mid_state = MID_RESPONSE_RECEIVED;
595 else 785 else
596 mid->midState = MID_RESPONSE_MALFORMED; 786 mid->mid_state = MID_RESPONSE_MALFORMED;
597 list_del_init(&mid->qhead); 787 list_del_init(&mid->qhead);
598 spin_unlock(&GlobalMid_Lock); 788 spin_unlock(&GlobalMid_Lock);
599} 789}
600 790
601static void 791static void
602handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server, 792handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server,
603 struct smb_hdr *buf, int malformed) 793 char *buf, int malformed)
604{ 794{
605 if (malformed == 0 && check2ndT2(buf) > 0) { 795 if (malformed == 0 && check2ndT2(buf) > 0) {
606 mid->multiRsp = true; 796 mid->multiRsp = true;
@@ -620,13 +810,13 @@ handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server,
620 } else { 810 } else {
621 /* Have first buffer */ 811 /* Have first buffer */
622 mid->resp_buf = buf; 812 mid->resp_buf = buf;
623 mid->largeBuf = true; 813 mid->large_buf = true;
624 server->bigbuf = NULL; 814 server->bigbuf = NULL;
625 } 815 }
626 return; 816 return;
627 } 817 }
628 mid->resp_buf = buf; 818 mid->resp_buf = buf;
629 mid->largeBuf = server->large_buf; 819 mid->large_buf = server->large_buf;
630 /* Was previous buf put in mpx struct for multi-rsp? */ 820 /* Was previous buf put in mpx struct for multi-rsp? */
631 if (!mid->multiRsp) { 821 if (!mid->multiRsp) {
632 /* smb buffer will be freed by user thread */ 822 /* smb buffer will be freed by user thread */
@@ -682,8 +872,8 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
682 spin_lock(&GlobalMid_Lock); 872 spin_lock(&GlobalMid_Lock);
683 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { 873 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
684 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 874 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
685 cFYI(1, "Clearing mid 0x%x", mid_entry->mid); 875 cFYI(1, "Clearing mid 0x%llx", mid_entry->mid);
686 mid_entry->midState = MID_SHUTDOWN; 876 mid_entry->mid_state = MID_SHUTDOWN;
687 list_move(&mid_entry->qhead, &dispose_list); 877 list_move(&mid_entry->qhead, &dispose_list);
688 } 878 }
689 spin_unlock(&GlobalMid_Lock); 879 spin_unlock(&GlobalMid_Lock);
@@ -691,7 +881,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
691 /* now walk dispose list and issue callbacks */ 881 /* now walk dispose list and issue callbacks */
692 list_for_each_safe(tmp, tmp2, &dispose_list) { 882 list_for_each_safe(tmp, tmp2, &dispose_list) {
693 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 883 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
694 cFYI(1, "Callback mid 0x%x", mid_entry->mid); 884 cFYI(1, "Callback mid 0x%llx", mid_entry->mid);
695 list_del_init(&mid_entry->qhead); 885 list_del_init(&mid_entry->qhead);
696 mid_entry->callback(mid_entry); 886 mid_entry->callback(mid_entry);
697 } 887 }
@@ -731,11 +921,10 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid)
731{ 921{
732 int length; 922 int length;
733 char *buf = server->smallbuf; 923 char *buf = server->smallbuf;
734 struct smb_hdr *smb_buffer = (struct smb_hdr *)buf; 924 unsigned int pdu_length = get_rfc1002_length(buf);
735 unsigned int pdu_length = be32_to_cpu(smb_buffer->smb_buf_length);
736 925
737 /* make sure this will fit in a large buffer */ 926 /* make sure this will fit in a large buffer */
738 if (pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { 927 if (pdu_length > CIFSMaxBufSize + max_header_size() - 4) {
739 cERROR(1, "SMB response too long (%u bytes)", 928 cERROR(1, "SMB response too long (%u bytes)",
740 pdu_length); 929 pdu_length);
741 cifs_reconnect(server); 930 cifs_reconnect(server);
@@ -746,20 +935,18 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid)
746 /* switch to large buffer if too big for a small one */ 935 /* switch to large buffer if too big for a small one */
747 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) { 936 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) {
748 server->large_buf = true; 937 server->large_buf = true;
749 memcpy(server->bigbuf, server->smallbuf, server->total_read); 938 memcpy(server->bigbuf, buf, server->total_read);
750 buf = server->bigbuf; 939 buf = server->bigbuf;
751 smb_buffer = (struct smb_hdr *)buf;
752 } 940 }
753 941
754 /* now read the rest */ 942 /* now read the rest */
755 length = cifs_read_from_socket(server, 943 length = cifs_read_from_socket(server, buf + header_size() - 1,
756 buf + sizeof(struct smb_hdr) - 1, 944 pdu_length - header_size() + 1 + 4);
757 pdu_length - sizeof(struct smb_hdr) + 1 + 4);
758 if (length < 0) 945 if (length < 0)
759 return length; 946 return length;
760 server->total_read += length; 947 server->total_read += length;
761 948
762 dump_smb(smb_buffer, server->total_read); 949 dump_smb(buf, server->total_read);
763 950
764 /* 951 /*
765 * We know that we received enough to get to the MID as we 952 * We know that we received enough to get to the MID as we
@@ -770,7 +957,7 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid)
770 * 48 bytes is enough to display the header and a little bit 957 * 48 bytes is enough to display the header and a little bit
771 * into the payload for debugging purposes. 958 * into the payload for debugging purposes.
772 */ 959 */
773 length = checkSMB(smb_buffer, smb_buffer->Mid, server->total_read); 960 length = checkSMB(buf, server->total_read);
774 if (length != 0) 961 if (length != 0)
775 cifs_dump_mem("Bad SMB: ", buf, 962 cifs_dump_mem("Bad SMB: ", buf,
776 min_t(unsigned int, server->total_read, 48)); 963 min_t(unsigned int, server->total_read, 48));
@@ -778,7 +965,7 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid)
778 if (!mid) 965 if (!mid)
779 return length; 966 return length;
780 967
781 handle_mid(mid, server, smb_buffer, length); 968 handle_mid(mid, server, buf, length);
782 return 0; 969 return 0;
783} 970}
784 971
@@ -789,7 +976,6 @@ cifs_demultiplex_thread(void *p)
789 struct TCP_Server_Info *server = p; 976 struct TCP_Server_Info *server = p;
790 unsigned int pdu_length; 977 unsigned int pdu_length;
791 char *buf = NULL; 978 char *buf = NULL;
792 struct smb_hdr *smb_buffer = NULL;
793 struct task_struct *task_to_wake = NULL; 979 struct task_struct *task_to_wake = NULL;
794 struct mid_q_entry *mid_entry; 980 struct mid_q_entry *mid_entry;
795 981
@@ -810,7 +996,6 @@ cifs_demultiplex_thread(void *p)
810 continue; 996 continue;
811 997
812 server->large_buf = false; 998 server->large_buf = false;
813 smb_buffer = (struct smb_hdr *)server->smallbuf;
814 buf = server->smallbuf; 999 buf = server->smallbuf;
815 pdu_length = 4; /* enough to get RFC1001 header */ 1000 pdu_length = 4; /* enough to get RFC1001 header */
816 1001
@@ -823,14 +1008,14 @@ cifs_demultiplex_thread(void *p)
823 * The right amount was read from socket - 4 bytes, 1008 * The right amount was read from socket - 4 bytes,
824 * so we can now interpret the length field. 1009 * so we can now interpret the length field.
825 */ 1010 */
826 pdu_length = be32_to_cpu(smb_buffer->smb_buf_length); 1011 pdu_length = get_rfc1002_length(buf);
827 1012
828 cFYI(1, "RFC1002 header 0x%x", pdu_length); 1013 cFYI(1, "RFC1002 header 0x%x", pdu_length);
829 if (!is_smb_response(server, buf[0])) 1014 if (!is_smb_response(server, buf[0]))
830 continue; 1015 continue;
831 1016
832 /* make sure we have enough to get to the MID */ 1017 /* make sure we have enough to get to the MID */
833 if (pdu_length < sizeof(struct smb_hdr) - 1 - 4) { 1018 if (pdu_length < header_size() - 1 - 4) {
834 cERROR(1, "SMB response too short (%u bytes)", 1019 cERROR(1, "SMB response too short (%u bytes)",
835 pdu_length); 1020 pdu_length);
836 cifs_reconnect(server); 1021 cifs_reconnect(server);
@@ -840,12 +1025,12 @@ cifs_demultiplex_thread(void *p)
840 1025
841 /* read down to the MID */ 1026 /* read down to the MID */
842 length = cifs_read_from_socket(server, buf + 4, 1027 length = cifs_read_from_socket(server, buf + 4,
843 sizeof(struct smb_hdr) - 1 - 4); 1028 header_size() - 1 - 4);
844 if (length < 0) 1029 if (length < 0)
845 continue; 1030 continue;
846 server->total_read += length; 1031 server->total_read += length;
847 1032
848 mid_entry = find_mid(server, smb_buffer); 1033 mid_entry = find_mid(server, buf);
849 1034
850 if (!mid_entry || !mid_entry->receive) 1035 if (!mid_entry || !mid_entry->receive)
851 length = standard_receive3(server, mid_entry); 1036 length = standard_receive3(server, mid_entry);
@@ -855,22 +1040,19 @@ cifs_demultiplex_thread(void *p)
855 if (length < 0) 1040 if (length < 0)
856 continue; 1041 continue;
857 1042
858 if (server->large_buf) { 1043 if (server->large_buf)
859 buf = server->bigbuf; 1044 buf = server->bigbuf;
860 smb_buffer = (struct smb_hdr *)buf;
861 }
862 1045
863 server->lstrp = jiffies; 1046 server->lstrp = jiffies;
864 if (mid_entry != NULL) { 1047 if (mid_entry != NULL) {
865 if (!mid_entry->multiRsp || mid_entry->multiEnd) 1048 if (!mid_entry->multiRsp || mid_entry->multiEnd)
866 mid_entry->callback(mid_entry); 1049 mid_entry->callback(mid_entry);
867 } else if (!is_valid_oplock_break(smb_buffer, server)) { 1050 } else if (!is_valid_oplock_break(buf, server)) {
868 cERROR(1, "No task to wake, unknown frame received! " 1051 cERROR(1, "No task to wake, unknown frame received! "
869 "NumMids %d", atomic_read(&midCount)); 1052 "NumMids %d", atomic_read(&midCount));
870 cifs_dump_mem("Received Data is: ", buf, 1053 cifs_dump_mem("Received Data is: ", buf, header_size());
871 sizeof(struct smb_hdr));
872#ifdef CONFIG_CIFS_DEBUG2 1054#ifdef CONFIG_CIFS_DEBUG2
873 cifs_dump_detail(smb_buffer); 1055 cifs_dump_detail(buf);
874 cifs_dump_mids(server); 1056 cifs_dump_mids(server);
875#endif /* CIFS_DEBUG2 */ 1057#endif /* CIFS_DEBUG2 */
876 1058
@@ -926,23 +1108,95 @@ extract_hostname(const char *unc)
926 return dst; 1108 return dst;
927} 1109}
928 1110
1111static int get_option_ul(substring_t args[], unsigned long *option)
1112{
1113 int rc;
1114 char *string;
1115
1116 string = match_strdup(args);
1117 if (string == NULL)
1118 return -ENOMEM;
1119 rc = kstrtoul(string, 10, option);
1120 kfree(string);
1121
1122 return rc;
1123}
1124
1125
1126static int cifs_parse_security_flavors(char *value,
1127 struct smb_vol *vol)
1128{
1129
1130 substring_t args[MAX_OPT_ARGS];
1131
1132 switch (match_token(value, cifs_secflavor_tokens, args)) {
1133 case Opt_sec_krb5:
1134 vol->secFlg |= CIFSSEC_MAY_KRB5;
1135 break;
1136 case Opt_sec_krb5i:
1137 vol->secFlg |= CIFSSEC_MAY_KRB5 | CIFSSEC_MUST_SIGN;
1138 break;
1139 case Opt_sec_krb5p:
1140 /* vol->secFlg |= CIFSSEC_MUST_SEAL | CIFSSEC_MAY_KRB5; */
1141 cERROR(1, "Krb5 cifs privacy not supported");
1142 break;
1143 case Opt_sec_ntlmssp:
1144 vol->secFlg |= CIFSSEC_MAY_NTLMSSP;
1145 break;
1146 case Opt_sec_ntlmsspi:
1147 vol->secFlg |= CIFSSEC_MAY_NTLMSSP | CIFSSEC_MUST_SIGN;
1148 break;
1149 case Opt_ntlm:
1150 /* ntlm is default so can be turned off too */
1151 vol->secFlg |= CIFSSEC_MAY_NTLM;
1152 break;
1153 case Opt_sec_ntlmi:
1154 vol->secFlg |= CIFSSEC_MAY_NTLM | CIFSSEC_MUST_SIGN;
1155 break;
1156 case Opt_sec_nontlm:
1157 vol->secFlg |= CIFSSEC_MAY_NTLMV2;
1158 break;
1159 case Opt_sec_ntlmv2i:
1160 vol->secFlg |= CIFSSEC_MAY_NTLMV2 | CIFSSEC_MUST_SIGN;
1161 break;
1162#ifdef CONFIG_CIFS_WEAK_PW_HASH
1163 case Opt_sec_lanman:
1164 vol->secFlg |= CIFSSEC_MAY_LANMAN;
1165 break;
1166#endif
1167 case Opt_sec_none:
1168 vol->nullauth = 1;
1169 break;
1170 default:
1171 cERROR(1, "bad security option: %s", value);
1172 return 1;
1173 }
1174
1175 return 0;
1176}
1177
929static int 1178static int
930cifs_parse_mount_options(const char *mountdata, const char *devname, 1179cifs_parse_mount_options(const char *mountdata, const char *devname,
931 struct smb_vol *vol) 1180 struct smb_vol *vol)
932{ 1181{
933 char *value, *data, *end; 1182 char *data, *end;
934 char *mountdata_copy = NULL, *options; 1183 char *mountdata_copy = NULL, *options;
935 int err;
936 unsigned int temp_len, i, j; 1184 unsigned int temp_len, i, j;
937 char separator[2]; 1185 char separator[2];
938 short int override_uid = -1; 1186 short int override_uid = -1;
939 short int override_gid = -1; 1187 short int override_gid = -1;
940 bool uid_specified = false; 1188 bool uid_specified = false;
941 bool gid_specified = false; 1189 bool gid_specified = false;
1190 bool sloppy = false;
1191 char *invalid = NULL;
942 char *nodename = utsname()->nodename; 1192 char *nodename = utsname()->nodename;
1193 char *string = NULL;
1194 char *tmp_end, *value;
1195 char delim;
943 1196
944 separator[0] = ','; 1197 separator[0] = ',';
945 separator[1] = 0; 1198 separator[1] = 0;
1199 delim = separator[0];
946 1200
947 /* 1201 /*
948 * does not have to be perfect mapping since field is 1202 * does not have to be perfect mapping since field is
@@ -981,6 +1235,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
981 1235
982 options = mountdata_copy; 1236 options = mountdata_copy;
983 end = options + strlen(options); 1237 end = options + strlen(options);
1238
984 if (strncmp(options, "sep=", 4) == 0) { 1239 if (strncmp(options, "sep=", 4) == 0) {
985 if (options[4] != 0) { 1240 if (options[4] != 0) {
986 separator[0] = options[4]; 1241 separator[0] = options[4];
@@ -993,609 +1248,650 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
993 vol->backupgid_specified = false; /* no backup intent for a group */ 1248 vol->backupgid_specified = false; /* no backup intent for a group */
994 1249
995 while ((data = strsep(&options, separator)) != NULL) { 1250 while ((data = strsep(&options, separator)) != NULL) {
1251 substring_t args[MAX_OPT_ARGS];
1252 unsigned long option;
1253 int token;
1254
996 if (!*data) 1255 if (!*data)
997 continue; 1256 continue;
998 if ((value = strchr(data, '=')) != NULL)
999 *value++ = '\0';
1000 1257
1001 /* Have to parse this before we parse for "user" */ 1258 token = match_token(data, cifs_mount_option_tokens, args);
1002 if (strnicmp(data, "user_xattr", 10) == 0) { 1259
1260 switch (token) {
1261
1262 /* Ingnore the following */
1263 case Opt_ignore:
1264 break;
1265
1266 /* Boolean values */
1267 case Opt_user_xattr:
1003 vol->no_xattr = 0; 1268 vol->no_xattr = 0;
1004 } else if (strnicmp(data, "nouser_xattr", 12) == 0) { 1269 break;
1270 case Opt_nouser_xattr:
1005 vol->no_xattr = 1; 1271 vol->no_xattr = 1;
1006 } else if (strnicmp(data, "user", 4) == 0) { 1272 break;
1007 if (!value) { 1273 case Opt_forceuid:
1008 printk(KERN_WARNING
1009 "CIFS: invalid or missing username\n");
1010 goto cifs_parse_mount_err;
1011 } else if (!*value) {
1012 /* null user, ie anonymous, authentication */
1013 vol->nullauth = 1;
1014 }
1015 if (strnlen(value, MAX_USERNAME_SIZE) <
1016 MAX_USERNAME_SIZE) {
1017 vol->username = kstrdup(value, GFP_KERNEL);
1018 if (!vol->username) {
1019 printk(KERN_WARNING "CIFS: no memory "
1020 "for username\n");
1021 goto cifs_parse_mount_err;
1022 }
1023 } else {
1024 printk(KERN_WARNING "CIFS: username too long\n");
1025 goto cifs_parse_mount_err;
1026 }
1027 } else if (strnicmp(data, "pass", 4) == 0) {
1028 if (!value) {
1029 vol->password = NULL;
1030 continue;
1031 } else if (value[0] == 0) {
1032 /* check if string begins with double comma
1033 since that would mean the password really
1034 does start with a comma, and would not
1035 indicate an empty string */
1036 if (value[1] != separator[0]) {
1037 vol->password = NULL;
1038 continue;
1039 }
1040 }
1041 temp_len = strlen(value);
1042 /* removed password length check, NTLM passwords
1043 can be arbitrarily long */
1044
1045 /* if comma in password, the string will be
1046 prematurely null terminated. Commas in password are
1047 specified across the cifs mount interface by a double
1048 comma ie ,, and a comma used as in other cases ie ','
1049 as a parameter delimiter/separator is single and due
1050 to the strsep above is temporarily zeroed. */
1051
1052 /* NB: password legally can have multiple commas and
1053 the only illegal character in a password is null */
1054
1055 if ((value[temp_len] == 0) &&
1056 (value + temp_len < end) &&
1057 (value[temp_len+1] == separator[0])) {
1058 /* reinsert comma */
1059 value[temp_len] = separator[0];
1060 temp_len += 2; /* move after second comma */
1061 while (value[temp_len] != 0) {
1062 if (value[temp_len] == separator[0]) {
1063 if (value[temp_len+1] ==
1064 separator[0]) {
1065 /* skip second comma */
1066 temp_len++;
1067 } else {
1068 /* single comma indicating start
1069 of next parm */
1070 break;
1071 }
1072 }
1073 temp_len++;
1074 }
1075 if (value[temp_len] == 0) {
1076 options = NULL;
1077 } else {
1078 value[temp_len] = 0;
1079 /* point option to start of next parm */
1080 options = value + temp_len + 1;
1081 }
1082 /* go from value to value + temp_len condensing
1083 double commas to singles. Note that this ends up
1084 allocating a few bytes too many, which is ok */
1085 vol->password = kzalloc(temp_len, GFP_KERNEL);
1086 if (vol->password == NULL) {
1087 printk(KERN_WARNING "CIFS: no memory "
1088 "for password\n");
1089 goto cifs_parse_mount_err;
1090 }
1091 for (i = 0, j = 0; i < temp_len; i++, j++) {
1092 vol->password[j] = value[i];
1093 if (value[i] == separator[0]
1094 && value[i+1] == separator[0]) {
1095 /* skip second comma */
1096 i++;
1097 }
1098 }
1099 vol->password[j] = 0;
1100 } else {
1101 vol->password = kzalloc(temp_len+1, GFP_KERNEL);
1102 if (vol->password == NULL) {
1103 printk(KERN_WARNING "CIFS: no memory "
1104 "for password\n");
1105 goto cifs_parse_mount_err;
1106 }
1107 strcpy(vol->password, value);
1108 }
1109 } else if (!strnicmp(data, "ip", 2) ||
1110 !strnicmp(data, "addr", 4)) {
1111 if (!value || !*value) {
1112 vol->UNCip = NULL;
1113 } else if (strnlen(value, INET6_ADDRSTRLEN) <
1114 INET6_ADDRSTRLEN) {
1115 vol->UNCip = kstrdup(value, GFP_KERNEL);
1116 if (!vol->UNCip) {
1117 printk(KERN_WARNING "CIFS: no memory "
1118 "for UNC IP\n");
1119 goto cifs_parse_mount_err;
1120 }
1121 } else {
1122 printk(KERN_WARNING "CIFS: ip address "
1123 "too long\n");
1124 goto cifs_parse_mount_err;
1125 }
1126 } else if (strnicmp(data, "sec", 3) == 0) {
1127 if (!value || !*value) {
1128 cERROR(1, "no security value specified");
1129 continue;
1130 } else if (strnicmp(value, "krb5i", 5) == 0) {
1131 vol->secFlg |= CIFSSEC_MAY_KRB5 |
1132 CIFSSEC_MUST_SIGN;
1133 } else if (strnicmp(value, "krb5p", 5) == 0) {
1134 /* vol->secFlg |= CIFSSEC_MUST_SEAL |
1135 CIFSSEC_MAY_KRB5; */
1136 cERROR(1, "Krb5 cifs privacy not supported");
1137 goto cifs_parse_mount_err;
1138 } else if (strnicmp(value, "krb5", 4) == 0) {
1139 vol->secFlg |= CIFSSEC_MAY_KRB5;
1140 } else if (strnicmp(value, "ntlmsspi", 8) == 0) {
1141 vol->secFlg |= CIFSSEC_MAY_NTLMSSP |
1142 CIFSSEC_MUST_SIGN;
1143 } else if (strnicmp(value, "ntlmssp", 7) == 0) {
1144 vol->secFlg |= CIFSSEC_MAY_NTLMSSP;
1145 } else if (strnicmp(value, "ntlmv2i", 7) == 0) {
1146 vol->secFlg |= CIFSSEC_MAY_NTLMV2 |
1147 CIFSSEC_MUST_SIGN;
1148 } else if (strnicmp(value, "ntlmv2", 6) == 0) {
1149 vol->secFlg |= CIFSSEC_MAY_NTLMV2;
1150 } else if (strnicmp(value, "ntlmi", 5) == 0) {
1151 vol->secFlg |= CIFSSEC_MAY_NTLM |
1152 CIFSSEC_MUST_SIGN;
1153 } else if (strnicmp(value, "ntlm", 4) == 0) {
1154 /* ntlm is default so can be turned off too */
1155 vol->secFlg |= CIFSSEC_MAY_NTLM;
1156 } else if (strnicmp(value, "nontlm", 6) == 0) {
1157 /* BB is there a better way to do this? */
1158 vol->secFlg |= CIFSSEC_MAY_NTLMV2;
1159#ifdef CONFIG_CIFS_WEAK_PW_HASH
1160 } else if (strnicmp(value, "lanman", 6) == 0) {
1161 vol->secFlg |= CIFSSEC_MAY_LANMAN;
1162#endif
1163 } else if (strnicmp(value, "none", 4) == 0) {
1164 vol->nullauth = 1;
1165 } else {
1166 cERROR(1, "bad security option: %s", value);
1167 goto cifs_parse_mount_err;
1168 }
1169 } else if (strnicmp(data, "vers", 3) == 0) {
1170 if (!value || !*value) {
1171 cERROR(1, "no protocol version specified"
1172 " after vers= mount option");
1173 } else if ((strnicmp(value, "cifs", 4) == 0) ||
1174 (strnicmp(value, "1", 1) == 0)) {
1175 /* this is the default */
1176 continue;
1177 }
1178 } else if ((strnicmp(data, "unc", 3) == 0)
1179 || (strnicmp(data, "target", 6) == 0)
1180 || (strnicmp(data, "path", 4) == 0)) {
1181 if (!value || !*value) {
1182 printk(KERN_WARNING "CIFS: invalid path to "
1183 "network resource\n");
1184 goto cifs_parse_mount_err;
1185 }
1186 if ((temp_len = strnlen(value, 300)) < 300) {
1187 vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
1188 if (vol->UNC == NULL)
1189 goto cifs_parse_mount_err;
1190 strcpy(vol->UNC, value);
1191 if (strncmp(vol->UNC, "//", 2) == 0) {
1192 vol->UNC[0] = '\\';
1193 vol->UNC[1] = '\\';
1194 } else if (strncmp(vol->UNC, "\\\\", 2) != 0) {
1195 printk(KERN_WARNING
1196 "CIFS: UNC Path does not begin "
1197 "with // or \\\\ \n");
1198 goto cifs_parse_mount_err;
1199 }
1200 } else {
1201 printk(KERN_WARNING "CIFS: UNC name too long\n");
1202 goto cifs_parse_mount_err;
1203 }
1204 } else if ((strnicmp(data, "domain", 3) == 0)
1205 || (strnicmp(data, "workgroup", 5) == 0)) {
1206 if (!value || !*value) {
1207 printk(KERN_WARNING "CIFS: invalid domain name\n");
1208 goto cifs_parse_mount_err;
1209 }
1210 /* BB are there cases in which a comma can be valid in
1211 a domain name and need special handling? */
1212 if (strnlen(value, 256) < 256) {
1213 vol->domainname = kstrdup(value, GFP_KERNEL);
1214 if (!vol->domainname) {
1215 printk(KERN_WARNING "CIFS: no memory "
1216 "for domainname\n");
1217 goto cifs_parse_mount_err;
1218 }
1219 cFYI(1, "Domain name set");
1220 } else {
1221 printk(KERN_WARNING "CIFS: domain name too "
1222 "long\n");
1223 goto cifs_parse_mount_err;
1224 }
1225 } else if (strnicmp(data, "srcaddr", 7) == 0) {
1226 vol->srcaddr.ss_family = AF_UNSPEC;
1227
1228 if (!value || !*value) {
1229 printk(KERN_WARNING "CIFS: srcaddr value"
1230 " not specified.\n");
1231 goto cifs_parse_mount_err;
1232 }
1233 i = cifs_convert_address((struct sockaddr *)&vol->srcaddr,
1234 value, strlen(value));
1235 if (i == 0) {
1236 printk(KERN_WARNING "CIFS: Could not parse"
1237 " srcaddr: %s\n",
1238 value);
1239 goto cifs_parse_mount_err;
1240 }
1241 } else if (strnicmp(data, "prefixpath", 10) == 0) {
1242 if (!value || !*value) {
1243 printk(KERN_WARNING
1244 "CIFS: invalid path prefix\n");
1245 goto cifs_parse_mount_err;
1246 }
1247 if ((temp_len = strnlen(value, 1024)) < 1024) {
1248 if (value[0] != '/')
1249 temp_len++; /* missing leading slash */
1250 vol->prepath = kmalloc(temp_len+1, GFP_KERNEL);
1251 if (vol->prepath == NULL)
1252 goto cifs_parse_mount_err;
1253 if (value[0] != '/') {
1254 vol->prepath[0] = '/';
1255 strcpy(vol->prepath+1, value);
1256 } else
1257 strcpy(vol->prepath, value);
1258 cFYI(1, "prefix path %s", vol->prepath);
1259 } else {
1260 printk(KERN_WARNING "CIFS: prefix too long\n");
1261 goto cifs_parse_mount_err;
1262 }
1263 } else if (strnicmp(data, "iocharset", 9) == 0) {
1264 if (!value || !*value) {
1265 printk(KERN_WARNING "CIFS: invalid iocharset "
1266 "specified\n");
1267 goto cifs_parse_mount_err;
1268 }
1269 if (strnlen(value, 65) < 65) {
1270 if (strnicmp(value, "default", 7)) {
1271 vol->iocharset = kstrdup(value,
1272 GFP_KERNEL);
1273
1274 if (!vol->iocharset) {
1275 printk(KERN_WARNING "CIFS: no "
1276 "memory for"
1277 "charset\n");
1278 goto cifs_parse_mount_err;
1279 }
1280 }
1281 /* if iocharset not set then load_nls_default
1282 is used by caller */
1283 cFYI(1, "iocharset set to %s", value);
1284 } else {
1285 printk(KERN_WARNING "CIFS: iocharset name "
1286 "too long.\n");
1287 goto cifs_parse_mount_err;
1288 }
1289 } else if (!strnicmp(data, "uid", 3) && value && *value) {
1290 vol->linux_uid = simple_strtoul(value, &value, 0);
1291 uid_specified = true;
1292 } else if (!strnicmp(data, "cruid", 5) && value && *value) {
1293 vol->cred_uid = simple_strtoul(value, &value, 0);
1294 } else if (!strnicmp(data, "forceuid", 8)) {
1295 override_uid = 1; 1274 override_uid = 1;
1296 } else if (!strnicmp(data, "noforceuid", 10)) { 1275 break;
1276 case Opt_noforceuid:
1297 override_uid = 0; 1277 override_uid = 0;
1298 } else if (!strnicmp(data, "gid", 3) && value && *value) { 1278 break;
1299 vol->linux_gid = simple_strtoul(value, &value, 0); 1279 case Opt_noblocksend:
1300 gid_specified = true;
1301 } else if (!strnicmp(data, "forcegid", 8)) {
1302 override_gid = 1;
1303 } else if (!strnicmp(data, "noforcegid", 10)) {
1304 override_gid = 0;
1305 } else if (strnicmp(data, "file_mode", 4) == 0) {
1306 if (value && *value) {
1307 vol->file_mode =
1308 simple_strtoul(value, &value, 0);
1309 }
1310 } else if (strnicmp(data, "dir_mode", 4) == 0) {
1311 if (value && *value) {
1312 vol->dir_mode =
1313 simple_strtoul(value, &value, 0);
1314 }
1315 } else if (strnicmp(data, "dirmode", 4) == 0) {
1316 if (value && *value) {
1317 vol->dir_mode =
1318 simple_strtoul(value, &value, 0);
1319 }
1320 } else if (strnicmp(data, "port", 4) == 0) {
1321 if (value && *value) {
1322 vol->port =
1323 simple_strtoul(value, &value, 0);
1324 }
1325 } else if (strnicmp(data, "rsize", 5) == 0) {
1326 if (value && *value) {
1327 vol->rsize =
1328 simple_strtoul(value, &value, 0);
1329 }
1330 } else if (strnicmp(data, "wsize", 5) == 0) {
1331 if (value && *value) {
1332 vol->wsize =
1333 simple_strtoul(value, &value, 0);
1334 }
1335 } else if (strnicmp(data, "sockopt", 5) == 0) {
1336 if (!value || !*value) {
1337 cERROR(1, "no socket option specified");
1338 continue;
1339 } else if (strnicmp(value, "TCP_NODELAY", 11) == 0) {
1340 vol->sockopt_tcp_nodelay = 1;
1341 }
1342 } else if (strnicmp(data, "netbiosname", 4) == 0) {
1343 if (!value || !*value || (*value == ' ')) {
1344 cFYI(1, "invalid (empty) netbiosname");
1345 } else {
1346 memset(vol->source_rfc1001_name, 0x20,
1347 RFC1001_NAME_LEN);
1348 /*
1349 * FIXME: are there cases in which a comma can
1350 * be valid in workstation netbios name (and
1351 * need special handling)?
1352 */
1353 for (i = 0; i < RFC1001_NAME_LEN; i++) {
1354 /* don't ucase netbiosname for user */
1355 if (value[i] == 0)
1356 break;
1357 vol->source_rfc1001_name[i] = value[i];
1358 }
1359 /* The string has 16th byte zero still from
1360 set at top of the function */
1361 if (i == RFC1001_NAME_LEN && value[i] != 0)
1362 printk(KERN_WARNING "CIFS: netbiosname"
1363 " longer than 15 truncated.\n");
1364 }
1365 } else if (strnicmp(data, "servern", 7) == 0) {
1366 /* servernetbiosname specified override *SMBSERVER */
1367 if (!value || !*value || (*value == ' ')) {
1368 cFYI(1, "empty server netbiosname specified");
1369 } else {
1370 /* last byte, type, is 0x20 for servr type */
1371 memset(vol->target_rfc1001_name, 0x20,
1372 RFC1001_NAME_LEN_WITH_NULL);
1373
1374 for (i = 0; i < 15; i++) {
1375 /* BB are there cases in which a comma can be
1376 valid in this workstation netbios name
1377 (and need special handling)? */
1378
1379 /* user or mount helper must uppercase
1380 the netbiosname */
1381 if (value[i] == 0)
1382 break;
1383 else
1384 vol->target_rfc1001_name[i] =
1385 value[i];
1386 }
1387 /* The string has 16th byte zero still from
1388 set at top of the function */
1389 if (i == RFC1001_NAME_LEN && value[i] != 0)
1390 printk(KERN_WARNING "CIFS: server net"
1391 "biosname longer than 15 truncated.\n");
1392 }
1393 } else if (strnicmp(data, "actimeo", 7) == 0) {
1394 if (value && *value) {
1395 vol->actimeo = HZ * simple_strtoul(value,
1396 &value, 0);
1397 if (vol->actimeo > CIFS_MAX_ACTIMEO) {
1398 cERROR(1, "CIFS: attribute cache"
1399 "timeout too large");
1400 goto cifs_parse_mount_err;
1401 }
1402 }
1403 } else if (strnicmp(data, "credentials", 4) == 0) {
1404 /* ignore */
1405 } else if (strnicmp(data, "version", 3) == 0) {
1406 /* ignore */
1407 } else if (strnicmp(data, "guest", 5) == 0) {
1408 /* ignore */
1409 } else if (strnicmp(data, "rw", 2) == 0 && strlen(data) == 2) {
1410 /* ignore */
1411 } else if (strnicmp(data, "ro", 2) == 0) {
1412 /* ignore */
1413 } else if (strnicmp(data, "noblocksend", 11) == 0) {
1414 vol->noblocksnd = 1; 1280 vol->noblocksnd = 1;
1415 } else if (strnicmp(data, "noautotune", 10) == 0) { 1281 break;
1282 case Opt_noautotune:
1416 vol->noautotune = 1; 1283 vol->noautotune = 1;
1417 } else if ((strnicmp(data, "suid", 4) == 0) || 1284 break;
1418 (strnicmp(data, "nosuid", 6) == 0) || 1285 case Opt_hard:
1419 (strnicmp(data, "exec", 4) == 0) ||
1420 (strnicmp(data, "noexec", 6) == 0) ||
1421 (strnicmp(data, "nodev", 5) == 0) ||
1422 (strnicmp(data, "noauto", 6) == 0) ||
1423 (strnicmp(data, "dev", 3) == 0)) {
1424 /* The mount tool or mount.cifs helper (if present)
1425 uses these opts to set flags, and the flags are read
1426 by the kernel vfs layer before we get here (ie
1427 before read super) so there is no point trying to
1428 parse these options again and set anything and it
1429 is ok to just ignore them */
1430 continue;
1431 } else if (strnicmp(data, "hard", 4) == 0) {
1432 vol->retry = 1; 1286 vol->retry = 1;
1433 } else if (strnicmp(data, "soft", 4) == 0) { 1287 break;
1288 case Opt_soft:
1434 vol->retry = 0; 1289 vol->retry = 0;
1435 } else if (strnicmp(data, "perm", 4) == 0) { 1290 break;
1291 case Opt_perm:
1436 vol->noperm = 0; 1292 vol->noperm = 0;
1437 } else if (strnicmp(data, "noperm", 6) == 0) { 1293 break;
1294 case Opt_noperm:
1438 vol->noperm = 1; 1295 vol->noperm = 1;
1439 } else if (strnicmp(data, "mapchars", 8) == 0) { 1296 break;
1297 case Opt_mapchars:
1440 vol->remap = 1; 1298 vol->remap = 1;
1441 } else if (strnicmp(data, "nomapchars", 10) == 0) { 1299 break;
1300 case Opt_nomapchars:
1442 vol->remap = 0; 1301 vol->remap = 0;
1443 } else if (strnicmp(data, "sfu", 3) == 0) { 1302 break;
1303 case Opt_sfu:
1444 vol->sfu_emul = 1; 1304 vol->sfu_emul = 1;
1445 } else if (strnicmp(data, "nosfu", 5) == 0) { 1305 break;
1306 case Opt_nosfu:
1446 vol->sfu_emul = 0; 1307 vol->sfu_emul = 0;
1447 } else if (strnicmp(data, "nodfs", 5) == 0) { 1308 break;
1309 case Opt_nodfs:
1448 vol->nodfs = 1; 1310 vol->nodfs = 1;
1449 } else if (strnicmp(data, "posixpaths", 10) == 0) { 1311 break;
1312 case Opt_posixpaths:
1450 vol->posix_paths = 1; 1313 vol->posix_paths = 1;
1451 } else if (strnicmp(data, "noposixpaths", 12) == 0) { 1314 break;
1315 case Opt_noposixpaths:
1452 vol->posix_paths = 0; 1316 vol->posix_paths = 0;
1453 } else if (strnicmp(data, "nounix", 6) == 0) { 1317 break;
1454 vol->no_linux_ext = 1; 1318 case Opt_nounix:
1455 } else if (strnicmp(data, "nolinux", 7) == 0) {
1456 vol->no_linux_ext = 1; 1319 vol->no_linux_ext = 1;
1457 } else if ((strnicmp(data, "nocase", 6) == 0) || 1320 break;
1458 (strnicmp(data, "ignorecase", 10) == 0)) { 1321 case Opt_nocase:
1459 vol->nocase = 1; 1322 vol->nocase = 1;
1460 } else if (strnicmp(data, "mand", 4) == 0) { 1323 break;
1461 /* ignore */ 1324 case Opt_brl:
1462 } else if (strnicmp(data, "nomand", 6) == 0) {
1463 /* ignore */
1464 } else if (strnicmp(data, "_netdev", 7) == 0) {
1465 /* ignore */
1466 } else if (strnicmp(data, "brl", 3) == 0) {
1467 vol->nobrl = 0; 1325 vol->nobrl = 0;
1468 } else if ((strnicmp(data, "nobrl", 5) == 0) || 1326 break;
1469 (strnicmp(data, "nolock", 6) == 0)) { 1327 case Opt_nobrl:
1470 vol->nobrl = 1; 1328 vol->nobrl = 1;
1471 /* turn off mandatory locking in mode 1329 /* turn off mandatory locking in mode
1472 if remote locking is turned off since the 1330 * if remote locking is turned off since the
1473 local vfs will do advisory */ 1331 * local vfs will do advisory */
1474 if (vol->file_mode == 1332 if (vol->file_mode ==
1475 (S_IALLUGO & ~(S_ISUID | S_IXGRP))) 1333 (S_IALLUGO & ~(S_ISUID | S_IXGRP)))
1476 vol->file_mode = S_IALLUGO; 1334 vol->file_mode = S_IALLUGO;
1477 } else if (strnicmp(data, "forcemandatorylock", 9) == 0) { 1335 break;
1478 /* will take the shorter form "forcemand" as well */ 1336 case Opt_forcemandatorylock:
1479 /* This mount option will force use of mandatory
1480 (DOS/Windows style) byte range locks, instead of
1481 using posix advisory byte range locks, even if the
1482 Unix extensions are available and posix locks would
1483 be supported otherwise. If Unix extensions are not
1484 negotiated this has no effect since mandatory locks
1485 would be used (mandatory locks is all that those
1486 those servers support) */
1487 vol->mand_lock = 1; 1337 vol->mand_lock = 1;
1488 } else if (strnicmp(data, "setuids", 7) == 0) { 1338 break;
1339 case Opt_setuids:
1489 vol->setuids = 1; 1340 vol->setuids = 1;
1490 } else if (strnicmp(data, "nosetuids", 9) == 0) { 1341 break;
1342 case Opt_nosetuids:
1491 vol->setuids = 0; 1343 vol->setuids = 0;
1492 } else if (strnicmp(data, "dynperm", 7) == 0) { 1344 break;
1345 case Opt_dynperm:
1493 vol->dynperm = true; 1346 vol->dynperm = true;
1494 } else if (strnicmp(data, "nodynperm", 9) == 0) { 1347 break;
1348 case Opt_nodynperm:
1495 vol->dynperm = false; 1349 vol->dynperm = false;
1496 } else if (strnicmp(data, "nohard", 6) == 0) { 1350 break;
1351 case Opt_nohard:
1497 vol->retry = 0; 1352 vol->retry = 0;
1498 } else if (strnicmp(data, "nosoft", 6) == 0) { 1353 break;
1354 case Opt_nosoft:
1499 vol->retry = 1; 1355 vol->retry = 1;
1500 } else if (strnicmp(data, "nointr", 6) == 0) { 1356 break;
1357 case Opt_nointr:
1501 vol->intr = 0; 1358 vol->intr = 0;
1502 } else if (strnicmp(data, "intr", 4) == 0) { 1359 break;
1360 case Opt_intr:
1503 vol->intr = 1; 1361 vol->intr = 1;
1504 } else if (strnicmp(data, "nostrictsync", 12) == 0) { 1362 break;
1363 case Opt_nostrictsync:
1505 vol->nostrictsync = 1; 1364 vol->nostrictsync = 1;
1506 } else if (strnicmp(data, "strictsync", 10) == 0) { 1365 break;
1366 case Opt_strictsync:
1507 vol->nostrictsync = 0; 1367 vol->nostrictsync = 0;
1508 } else if (strnicmp(data, "serverino", 7) == 0) { 1368 break;
1369 case Opt_serverino:
1509 vol->server_ino = 1; 1370 vol->server_ino = 1;
1510 } else if (strnicmp(data, "noserverino", 9) == 0) { 1371 break;
1372 case Opt_noserverino:
1511 vol->server_ino = 0; 1373 vol->server_ino = 0;
1512 } else if (strnicmp(data, "rwpidforward", 12) == 0) { 1374 break;
1375 case Opt_rwpidforward:
1513 vol->rwpidforward = 1; 1376 vol->rwpidforward = 1;
1514 } else if (strnicmp(data, "cifsacl", 7) == 0) { 1377 break;
1378 case Opt_cifsacl:
1515 vol->cifs_acl = 1; 1379 vol->cifs_acl = 1;
1516 } else if (strnicmp(data, "nocifsacl", 9) == 0) { 1380 break;
1381 case Opt_nocifsacl:
1517 vol->cifs_acl = 0; 1382 vol->cifs_acl = 0;
1518 } else if (strnicmp(data, "acl", 3) == 0) { 1383 break;
1384 case Opt_acl:
1519 vol->no_psx_acl = 0; 1385 vol->no_psx_acl = 0;
1520 } else if (strnicmp(data, "noacl", 5) == 0) { 1386 break;
1387 case Opt_noacl:
1521 vol->no_psx_acl = 1; 1388 vol->no_psx_acl = 1;
1522 } else if (strnicmp(data, "locallease", 6) == 0) { 1389 break;
1390 case Opt_locallease:
1523 vol->local_lease = 1; 1391 vol->local_lease = 1;
1524 } else if (strnicmp(data, "sign", 4) == 0) { 1392 break;
1393 case Opt_sign:
1525 vol->secFlg |= CIFSSEC_MUST_SIGN; 1394 vol->secFlg |= CIFSSEC_MUST_SIGN;
1526 } else if (strnicmp(data, "seal", 4) == 0) { 1395 break;
1396 case Opt_seal:
1527 /* we do not do the following in secFlags because seal 1397 /* we do not do the following in secFlags because seal
1528 is a per tree connection (mount) not a per socket 1398 * is a per tree connection (mount) not a per socket
1529 or per-smb connection option in the protocol */ 1399 * or per-smb connection option in the protocol
1530 /* vol->secFlg |= CIFSSEC_MUST_SEAL; */ 1400 * vol->secFlg |= CIFSSEC_MUST_SEAL;
1401 */
1531 vol->seal = 1; 1402 vol->seal = 1;
1532 } else if (strnicmp(data, "direct", 6) == 0) { 1403 break;
1533 vol->direct_io = 1; 1404 case Opt_direct:
1534 } else if (strnicmp(data, "forcedirectio", 13) == 0) {
1535 vol->direct_io = 1; 1405 vol->direct_io = 1;
1536 } else if (strnicmp(data, "strictcache", 11) == 0) { 1406 break;
1407 case Opt_strictcache:
1537 vol->strict_io = 1; 1408 vol->strict_io = 1;
1538 } else if (strnicmp(data, "noac", 4) == 0) { 1409 break;
1410 case Opt_noac:
1539 printk(KERN_WARNING "CIFS: Mount option noac not " 1411 printk(KERN_WARNING "CIFS: Mount option noac not "
1540 "supported. Instead set " 1412 "supported. Instead set "
1541 "/proc/fs/cifs/LookupCacheEnabled to 0\n"); 1413 "/proc/fs/cifs/LookupCacheEnabled to 0\n");
1542 } else if (strnicmp(data, "fsc", 3) == 0) { 1414 break;
1415 case Opt_fsc:
1543#ifndef CONFIG_CIFS_FSCACHE 1416#ifndef CONFIG_CIFS_FSCACHE
1544 cERROR(1, "FS-Cache support needs CONFIG_CIFS_FSCACHE " 1417 cERROR(1, "FS-Cache support needs CONFIG_CIFS_FSCACHE "
1545 "kernel config option set"); 1418 "kernel config option set");
1546 goto cifs_parse_mount_err; 1419 goto cifs_parse_mount_err;
1547#endif 1420#endif
1548 vol->fsc = true; 1421 vol->fsc = true;
1549 } else if (strnicmp(data, "mfsymlinks", 10) == 0) { 1422 break;
1423 case Opt_mfsymlinks:
1550 vol->mfsymlinks = true; 1424 vol->mfsymlinks = true;
1551 } else if (strnicmp(data, "multiuser", 8) == 0) { 1425 break;
1426 case Opt_multiuser:
1552 vol->multiuser = true; 1427 vol->multiuser = true;
1553 } else if (!strnicmp(data, "backupuid", 9) && value && *value) { 1428 break;
1554 err = kstrtouint(value, 0, &vol->backupuid); 1429 case Opt_sloppy:
1555 if (err < 0) { 1430 sloppy = true;
1431 break;
1432
1433 /* Numeric Values */
1434 case Opt_backupuid:
1435 if (get_option_ul(args, &option)) {
1556 cERROR(1, "%s: Invalid backupuid value", 1436 cERROR(1, "%s: Invalid backupuid value",
1557 __func__); 1437 __func__);
1558 goto cifs_parse_mount_err; 1438 goto cifs_parse_mount_err;
1559 } 1439 }
1440 vol->backupuid = option;
1560 vol->backupuid_specified = true; 1441 vol->backupuid_specified = true;
1561 } else if (!strnicmp(data, "backupgid", 9) && value && *value) { 1442 break;
1562 err = kstrtouint(value, 0, &vol->backupgid); 1443 case Opt_backupgid:
1563 if (err < 0) { 1444 if (get_option_ul(args, &option)) {
1564 cERROR(1, "%s: Invalid backupgid value", 1445 cERROR(1, "%s: Invalid backupgid value",
1565 __func__); 1446 __func__);
1566 goto cifs_parse_mount_err; 1447 goto cifs_parse_mount_err;
1567 } 1448 }
1449 vol->backupgid = option;
1568 vol->backupgid_specified = true; 1450 vol->backupgid_specified = true;
1569 } else 1451 break;
1570 printk(KERN_WARNING "CIFS: Unknown mount option %s\n", 1452 case Opt_uid:
1571 data); 1453 if (get_option_ul(args, &option)) {
1572 } 1454 cERROR(1, "%s: Invalid uid value",
1573 if (vol->UNC == NULL) { 1455 __func__);
1574 if (devname == NULL) { 1456 goto cifs_parse_mount_err;
1575 printk(KERN_WARNING "CIFS: Missing UNC name for mount " 1457 }
1576 "target\n"); 1458 vol->linux_uid = option;
1577 goto cifs_parse_mount_err; 1459 uid_specified = true;
1578 } 1460 break;
1579 if ((temp_len = strnlen(devname, 300)) < 300) { 1461 case Opt_cruid:
1580 vol->UNC = kmalloc(temp_len+1, GFP_KERNEL); 1462 if (get_option_ul(args, &option)) {
1581 if (vol->UNC == NULL) 1463 cERROR(1, "%s: Invalid cruid value",
1464 __func__);
1465 goto cifs_parse_mount_err;
1466 }
1467 vol->cred_uid = option;
1468 break;
1469 case Opt_gid:
1470 if (get_option_ul(args, &option)) {
1471 cERROR(1, "%s: Invalid gid value",
1472 __func__);
1473 goto cifs_parse_mount_err;
1474 }
1475 vol->linux_gid = option;
1476 gid_specified = true;
1477 break;
1478 case Opt_file_mode:
1479 if (get_option_ul(args, &option)) {
1480 cERROR(1, "%s: Invalid file_mode value",
1481 __func__);
1482 goto cifs_parse_mount_err;
1483 }
1484 vol->file_mode = option;
1485 break;
1486 case Opt_dirmode:
1487 if (get_option_ul(args, &option)) {
1488 cERROR(1, "%s: Invalid dir_mode value",
1489 __func__);
1490 goto cifs_parse_mount_err;
1491 }
1492 vol->dir_mode = option;
1493 break;
1494 case Opt_port:
1495 if (get_option_ul(args, &option)) {
1496 cERROR(1, "%s: Invalid port value",
1497 __func__);
1498 goto cifs_parse_mount_err;
1499 }
1500 vol->port = option;
1501 break;
1502 case Opt_rsize:
1503 if (get_option_ul(args, &option)) {
1504 cERROR(1, "%s: Invalid rsize value",
1505 __func__);
1506 goto cifs_parse_mount_err;
1507 }
1508 vol->rsize = option;
1509 break;
1510 case Opt_wsize:
1511 if (get_option_ul(args, &option)) {
1512 cERROR(1, "%s: Invalid wsize value",
1513 __func__);
1514 goto cifs_parse_mount_err;
1515 }
1516 vol->wsize = option;
1517 break;
1518 case Opt_actimeo:
1519 if (get_option_ul(args, &option)) {
1520 cERROR(1, "%s: Invalid actimeo value",
1521 __func__);
1522 goto cifs_parse_mount_err;
1523 }
1524 vol->actimeo = HZ * option;
1525 if (vol->actimeo > CIFS_MAX_ACTIMEO) {
1526 cERROR(1, "CIFS: attribute cache"
1527 "timeout too large");
1528 goto cifs_parse_mount_err;
1529 }
1530 break;
1531
1532 /* String Arguments */
1533
1534 case Opt_user:
1535 string = match_strdup(args);
1536 if (string == NULL)
1537 goto out_nomem;
1538
1539 if (!*string) {
1540 /* null user, ie. anonymous authentication */
1541 vol->nullauth = 1;
1542 } else if (strnlen(string, MAX_USERNAME_SIZE) >
1543 MAX_USERNAME_SIZE) {
1544 printk(KERN_WARNING "CIFS: username too long\n");
1545 goto cifs_parse_mount_err;
1546 }
1547 vol->username = kstrdup(string, GFP_KERNEL);
1548 if (!vol->username) {
1549 printk(KERN_WARNING "CIFS: no memory "
1550 "for username\n");
1551 goto cifs_parse_mount_err;
1552 }
1553 break;
1554 case Opt_blank_pass:
1555 vol->password = NULL;
1556 break;
1557 case Opt_pass:
1558 /* passwords have to be handled differently
1559 * to allow the character used for deliminator
1560 * to be passed within them
1561 */
1562
1563 /* Obtain the value string */
1564 value = strchr(data, '=');
1565 if (value != NULL)
1566 *value++ = '\0';
1567
1568 /* Set tmp_end to end of the string */
1569 tmp_end = (char *) value + strlen(value);
1570
1571 /* Check if following character is the deliminator
1572 * If yes, we have encountered a double deliminator
1573 * reset the NULL character to the deliminator
1574 */
1575 if (tmp_end < end && tmp_end[1] == delim)
1576 tmp_end[0] = delim;
1577
1578 /* Keep iterating until we get to a single deliminator
1579 * OR the end
1580 */
1581 while ((tmp_end = strchr(tmp_end, delim)) != NULL &&
1582 (tmp_end[1] == delim)) {
1583 tmp_end = (char *) &tmp_end[2];
1584 }
1585
1586 /* Reset var options to point to next element */
1587 if (tmp_end) {
1588 tmp_end[0] = '\0';
1589 options = (char *) &tmp_end[1];
1590 } else
1591 /* Reached the end of the mount option string */
1592 options = end;
1593
1594 /* Now build new password string */
1595 temp_len = strlen(value);
1596 vol->password = kzalloc(temp_len+1, GFP_KERNEL);
1597 if (vol->password == NULL) {
1598 printk(KERN_WARNING "CIFS: no memory "
1599 "for password\n");
1600 goto cifs_parse_mount_err;
1601 }
1602
1603 for (i = 0, j = 0; i < temp_len; i++, j++) {
1604 vol->password[j] = value[i];
1605 if ((value[i] == delim) &&
1606 value[i+1] == delim)
1607 /* skip the second deliminator */
1608 i++;
1609 }
1610 vol->password[j] = '\0';
1611 break;
1612 case Opt_ip:
1613 string = match_strdup(args);
1614 if (string == NULL)
1615 goto out_nomem;
1616
1617 if (!*string) {
1618 vol->UNCip = NULL;
1619 } else if (strnlen(string, INET6_ADDRSTRLEN) >
1620 INET6_ADDRSTRLEN) {
1621 printk(KERN_WARNING "CIFS: ip address "
1622 "too long\n");
1623 goto cifs_parse_mount_err;
1624 }
1625 vol->UNCip = kstrdup(string, GFP_KERNEL);
1626 if (!vol->UNCip) {
1627 printk(KERN_WARNING "CIFS: no memory "
1628 "for UNC IP\n");
1629 goto cifs_parse_mount_err;
1630 }
1631 break;
1632 case Opt_unc:
1633 string = match_strdup(args);
1634 if (string == NULL)
1635 goto out_nomem;
1636
1637 if (!*string) {
1638 printk(KERN_WARNING "CIFS: invalid path to "
1639 "network resource\n");
1640 goto cifs_parse_mount_err;
1641 }
1642
1643 temp_len = strnlen(string, 300);
1644 if (temp_len == 300) {
1645 printk(KERN_WARNING "CIFS: UNC name too long\n");
1582 goto cifs_parse_mount_err; 1646 goto cifs_parse_mount_err;
1583 strcpy(vol->UNC, devname); 1647 }
1584 if (strncmp(vol->UNC, "//", 2) == 0) { 1648
1649 if (strncmp(string, "//", 2) == 0) {
1585 vol->UNC[0] = '\\'; 1650 vol->UNC[0] = '\\';
1586 vol->UNC[1] = '\\'; 1651 vol->UNC[1] = '\\';
1587 } else if (strncmp(vol->UNC, "\\\\", 2) != 0) { 1652 } else if (strncmp(string, "\\\\", 2) != 0) {
1588 printk(KERN_WARNING "CIFS: UNC Path does not " 1653 printk(KERN_WARNING "CIFS: UNC Path does not "
1589 "begin with // or \\\\ \n"); 1654 "begin with // or \\\\\n");
1590 goto cifs_parse_mount_err; 1655 goto cifs_parse_mount_err;
1591 } 1656 }
1592 value = strpbrk(vol->UNC+2, "/\\"); 1657
1593 if (value) 1658 vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
1594 *value = '\\'; 1659 if (vol->UNC == NULL) {
1595 } else { 1660 printk(KERN_WARNING "CIFS: no memory "
1596 printk(KERN_WARNING "CIFS: UNC name too long\n"); 1661 "for UNC\n");
1662 goto cifs_parse_mount_err;
1663 }
1664 strcpy(vol->UNC, string);
1665 break;
1666 case Opt_domain:
1667 string = match_strdup(args);
1668 if (string == NULL)
1669 goto out_nomem;
1670
1671 if (!*string) {
1672 printk(KERN_WARNING "CIFS: invalid domain"
1673 " name\n");
1674 goto cifs_parse_mount_err;
1675 } else if (strnlen(string, 256) == 256) {
1676 printk(KERN_WARNING "CIFS: domain name too"
1677 " long\n");
1678 goto cifs_parse_mount_err;
1679 }
1680
1681 vol->domainname = kstrdup(string, GFP_KERNEL);
1682 if (!vol->domainname) {
1683 printk(KERN_WARNING "CIFS: no memory "
1684 "for domainname\n");
1685 goto cifs_parse_mount_err;
1686 }
1687 cFYI(1, "Domain name set");
1688 break;
1689 case Opt_srcaddr:
1690 string = match_strdup(args);
1691 if (string == NULL)
1692 goto out_nomem;
1693
1694 if (!*string) {
1695 printk(KERN_WARNING "CIFS: srcaddr value not"
1696 " specified\n");
1697 goto cifs_parse_mount_err;
1698 } else if (!cifs_convert_address(
1699 (struct sockaddr *)&vol->srcaddr,
1700 string, strlen(string))) {
1701 printk(KERN_WARNING "CIFS: Could not parse"
1702 " srcaddr: %s\n", string);
1703 goto cifs_parse_mount_err;
1704 }
1705 break;
1706 case Opt_prefixpath:
1707 string = match_strdup(args);
1708 if (string == NULL)
1709 goto out_nomem;
1710
1711 if (!*string) {
1712 printk(KERN_WARNING "CIFS: Invalid path"
1713 " prefix\n");
1714 goto cifs_parse_mount_err;
1715 }
1716 temp_len = strnlen(string, 1024);
1717 if (string[0] != '/')
1718 temp_len++; /* missing leading slash */
1719 if (temp_len > 1024) {
1720 printk(KERN_WARNING "CIFS: prefix too long\n");
1721 goto cifs_parse_mount_err;
1722 }
1723
1724 vol->prepath = kmalloc(temp_len+1, GFP_KERNEL);
1725 if (vol->prepath == NULL) {
1726 printk(KERN_WARNING "CIFS: no memory "
1727 "for path prefix\n");
1728 goto cifs_parse_mount_err;
1729 }
1730
1731 if (string[0] != '/') {
1732 vol->prepath[0] = '/';
1733 strcpy(vol->prepath+1, string);
1734 } else
1735 strcpy(vol->prepath, string);
1736
1737 break;
1738 case Opt_iocharset:
1739 string = match_strdup(args);
1740 if (string == NULL)
1741 goto out_nomem;
1742
1743 if (!*string) {
1744 printk(KERN_WARNING "CIFS: Invalid iocharset"
1745 " specified\n");
1746 goto cifs_parse_mount_err;
1747 } else if (strnlen(string, 1024) >= 65) {
1748 printk(KERN_WARNING "CIFS: iocharset name "
1749 "too long.\n");
1750 goto cifs_parse_mount_err;
1751 }
1752
1753 if (strnicmp(string, "default", 7) != 0) {
1754 vol->iocharset = kstrdup(string,
1755 GFP_KERNEL);
1756 if (!vol->iocharset) {
1757 printk(KERN_WARNING "CIFS: no memory"
1758 "for charset\n");
1759 goto cifs_parse_mount_err;
1760 }
1761 }
1762 /* if iocharset not set then load_nls_default
1763 * is used by caller
1764 */
1765 cFYI(1, "iocharset set to %s", string);
1766 break;
1767 case Opt_sockopt:
1768 string = match_strdup(args);
1769 if (string == NULL)
1770 goto out_nomem;
1771
1772 if (!*string) {
1773 printk(KERN_WARNING "CIFS: No socket option"
1774 " specified\n");
1775 goto cifs_parse_mount_err;
1776 }
1777 if (strnicmp(string, "TCP_NODELAY", 11) == 0)
1778 vol->sockopt_tcp_nodelay = 1;
1779 break;
1780 case Opt_netbiosname:
1781 string = match_strdup(args);
1782 if (string == NULL)
1783 goto out_nomem;
1784
1785 if (!*string) {
1786 printk(KERN_WARNING "CIFS: Invalid (empty)"
1787 " netbiosname\n");
1788 break;
1789 }
1790
1791 memset(vol->source_rfc1001_name, 0x20,
1792 RFC1001_NAME_LEN);
1793 /*
1794 * FIXME: are there cases in which a comma can
1795 * be valid in workstation netbios name (and
1796 * need special handling)?
1797 */
1798 for (i = 0; i < RFC1001_NAME_LEN; i++) {
1799 /* don't ucase netbiosname for user */
1800 if (string[i] == 0)
1801 break;
1802 vol->source_rfc1001_name[i] = string[i];
1803 }
1804 /* The string has 16th byte zero still from
1805 * set at top of the function
1806 */
1807 if (i == RFC1001_NAME_LEN && string[i] != 0)
1808 printk(KERN_WARNING "CIFS: netbiosname"
1809 " longer than 15 truncated.\n");
1810
1811 break;
1812 case Opt_servern:
1813 /* servernetbiosname specified override *SMBSERVER */
1814 string = match_strdup(args);
1815 if (string == NULL)
1816 goto out_nomem;
1817
1818 if (!*string) {
1819 printk(KERN_WARNING "CIFS: Empty server"
1820 " netbiosname specified\n");
1821 break;
1822 }
1823 /* last byte, type, is 0x20 for servr type */
1824 memset(vol->target_rfc1001_name, 0x20,
1825 RFC1001_NAME_LEN_WITH_NULL);
1826
1827 /* BB are there cases in which a comma can be
1828 valid in this workstation netbios name
1829 (and need special handling)? */
1830
1831 /* user or mount helper must uppercase the
1832 netbios name */
1833 for (i = 0; i < 15; i++) {
1834 if (string[i] == 0)
1835 break;
1836 vol->target_rfc1001_name[i] = string[i];
1837 }
1838 /* The string has 16th byte zero still from
1839 set at top of the function */
1840 if (i == RFC1001_NAME_LEN && string[i] != 0)
1841 printk(KERN_WARNING "CIFS: server net"
1842 "biosname longer than 15 truncated.\n");
1843 break;
1844 case Opt_ver:
1845 string = match_strdup(args);
1846 if (string == NULL)
1847 goto out_nomem;
1848
1849 if (!*string) {
1850 cERROR(1, "no protocol version specified"
1851 " after vers= mount option");
1852 goto cifs_parse_mount_err;
1853 }
1854
1855 if (strnicmp(string, "cifs", 4) == 0 ||
1856 strnicmp(string, "1", 1) == 0) {
1857 /* This is the default */
1858 break;
1859 }
1860 /* For all other value, error */
1861 printk(KERN_WARNING "CIFS: Invalid version"
1862 " specified\n");
1597 goto cifs_parse_mount_err; 1863 goto cifs_parse_mount_err;
1864 case Opt_sec:
1865 string = match_strdup(args);
1866 if (string == NULL)
1867 goto out_nomem;
1868
1869 if (!*string) {
1870 printk(KERN_WARNING "CIFS: no security flavor"
1871 " specified\n");
1872 break;
1873 }
1874
1875 if (cifs_parse_security_flavors(string, vol) != 0)
1876 goto cifs_parse_mount_err;
1877 break;
1878 default:
1879 /*
1880 * An option we don't recognize. Save it off for later
1881 * if we haven't already found one
1882 */
1883 if (!invalid)
1884 invalid = data;
1885 break;
1598 } 1886 }
1887 /* Free up any allocated string */
1888 kfree(string);
1889 string = NULL;
1890 }
1891
1892 if (!sloppy && invalid) {
1893 printk(KERN_ERR "CIFS: Unknown mount option \"%s\"\n", invalid);
1894 goto cifs_parse_mount_err;
1599 } 1895 }
1600 1896
1601#ifndef CONFIG_KEYS 1897#ifndef CONFIG_KEYS
@@ -1625,7 +1921,10 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1625 kfree(mountdata_copy); 1921 kfree(mountdata_copy);
1626 return 0; 1922 return 0;
1627 1923
1924out_nomem:
1925 printk(KERN_WARNING "Could not allocate temporary buffer\n");
1628cifs_parse_mount_err: 1926cifs_parse_mount_err:
1927 kfree(string);
1629 kfree(mountdata_copy); 1928 kfree(mountdata_copy);
1630 return 1; 1929 return 1;
1631} 1930}
@@ -1977,7 +2276,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
1977 cifs_fscache_get_client_cookie(tcp_ses); 2276 cifs_fscache_get_client_cookie(tcp_ses);
1978 2277
1979 /* queue echo request delayed work */ 2278 /* queue echo request delayed work */
1980 queue_delayed_work(system_nrt_wq, &tcp_ses->echo, SMB_ECHO_INTERVAL); 2279 queue_delayed_work(cifsiod_wq, &tcp_ses->echo, SMB_ECHO_INTERVAL);
1981 2280
1982 return tcp_ses; 2281 return tcp_ses;
1983 2282
@@ -3543,7 +3842,7 @@ remote_path_check:
3543 tlink_rb_insert(&cifs_sb->tlink_tree, tlink); 3842 tlink_rb_insert(&cifs_sb->tlink_tree, tlink);
3544 spin_unlock(&cifs_sb->tlink_tree_lock); 3843 spin_unlock(&cifs_sb->tlink_tree_lock);
3545 3844
3546 queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks, 3845 queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks,
3547 TLINK_IDLE_EXPIRE); 3846 TLINK_IDLE_EXPIRE);
3548 3847
3549mount_fail_check: 3848mount_fail_check:
@@ -4097,6 +4396,6 @@ cifs_prune_tlinks(struct work_struct *work)
4097 } 4396 }
4098 spin_unlock(&cifs_sb->tlink_tree_lock); 4397 spin_unlock(&cifs_sb->tlink_tree_lock);
4099 4398
4100 queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks, 4399 queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks,
4101 TLINK_IDLE_EXPIRE); 4400 TLINK_IDLE_EXPIRE);
4102} 4401}
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 159fcc56dc2..460d87b7cda 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -1399,7 +1399,10 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
1399 return rc; 1399 return rc;
1400} 1400}
1401 1401
1402/* update the file size (if needed) after a write */ 1402/*
1403 * update the file size (if needed) after a write. Should be called with
1404 * the inode->i_lock held
1405 */
1403void 1406void
1404cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, 1407cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
1405 unsigned int bytes_written) 1408 unsigned int bytes_written)
@@ -1471,7 +1474,9 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid,
1471 return rc; 1474 return rc;
1472 } 1475 }
1473 } else { 1476 } else {
1477 spin_lock(&dentry->d_inode->i_lock);
1474 cifs_update_eof(cifsi, *poffset, bytes_written); 1478 cifs_update_eof(cifsi, *poffset, bytes_written);
1479 spin_unlock(&dentry->d_inode->i_lock);
1475 *poffset += bytes_written; 1480 *poffset += bytes_written;
1476 } 1481 }
1477 } 1482 }
@@ -1648,6 +1653,27 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
1648 return rc; 1653 return rc;
1649} 1654}
1650 1655
1656/*
1657 * Marshal up the iov array, reserving the first one for the header. Also,
1658 * set wdata->bytes.
1659 */
1660static void
1661cifs_writepages_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata)
1662{
1663 int i;
1664 struct inode *inode = wdata->cfile->dentry->d_inode;
1665 loff_t size = i_size_read(inode);
1666
1667 /* marshal up the pages into iov array */
1668 wdata->bytes = 0;
1669 for (i = 0; i < wdata->nr_pages; i++) {
1670 iov[i + 1].iov_len = min(size - page_offset(wdata->pages[i]),
1671 (loff_t)PAGE_CACHE_SIZE);
1672 iov[i + 1].iov_base = kmap(wdata->pages[i]);
1673 wdata->bytes += iov[i + 1].iov_len;
1674 }
1675}
1676
1651static int cifs_writepages(struct address_space *mapping, 1677static int cifs_writepages(struct address_space *mapping,
1652 struct writeback_control *wbc) 1678 struct writeback_control *wbc)
1653{ 1679{
@@ -1684,7 +1710,8 @@ retry:
1684 tofind = min((cifs_sb->wsize / PAGE_CACHE_SIZE) - 1, 1710 tofind = min((cifs_sb->wsize / PAGE_CACHE_SIZE) - 1,
1685 end - index) + 1; 1711 end - index) + 1;
1686 1712
1687 wdata = cifs_writedata_alloc((unsigned int)tofind); 1713 wdata = cifs_writedata_alloc((unsigned int)tofind,
1714 cifs_writev_complete);
1688 if (!wdata) { 1715 if (!wdata) {
1689 rc = -ENOMEM; 1716 rc = -ENOMEM;
1690 break; 1717 break;
@@ -1791,6 +1818,7 @@ retry:
1791 wdata->sync_mode = wbc->sync_mode; 1818 wdata->sync_mode = wbc->sync_mode;
1792 wdata->nr_pages = nr_pages; 1819 wdata->nr_pages = nr_pages;
1793 wdata->offset = page_offset(wdata->pages[0]); 1820 wdata->offset = page_offset(wdata->pages[0]);
1821 wdata->marshal_iov = cifs_writepages_marshal_iov;
1794 1822
1795 do { 1823 do {
1796 if (wdata->cfile != NULL) 1824 if (wdata->cfile != NULL)
@@ -1802,6 +1830,7 @@ retry:
1802 rc = -EBADF; 1830 rc = -EBADF;
1803 break; 1831 break;
1804 } 1832 }
1833 wdata->pid = wdata->cfile->pid;
1805 rc = cifs_async_writev(wdata); 1834 rc = cifs_async_writev(wdata);
1806 } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN); 1835 } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN);
1807 1836
@@ -2043,7 +2072,7 @@ cifs_write_allocate_pages(struct page **pages, unsigned long num_pages)
2043 unsigned long i; 2072 unsigned long i;
2044 2073
2045 for (i = 0; i < num_pages; i++) { 2074 for (i = 0; i < num_pages; i++) {
2046 pages[i] = alloc_page(__GFP_HIGHMEM); 2075 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2047 if (!pages[i]) { 2076 if (!pages[i]) {
2048 /* 2077 /*
2049 * save number of pages we have already allocated and 2078 * save number of pages we have already allocated and
@@ -2051,15 +2080,14 @@ cifs_write_allocate_pages(struct page **pages, unsigned long num_pages)
2051 */ 2080 */
2052 num_pages = i; 2081 num_pages = i;
2053 rc = -ENOMEM; 2082 rc = -ENOMEM;
2054 goto error; 2083 break;
2055 } 2084 }
2056 } 2085 }
2057 2086
2058 return rc; 2087 if (rc) {
2059 2088 for (i = 0; i < num_pages; i++)
2060error: 2089 put_page(pages[i]);
2061 for (i = 0; i < num_pages; i++) 2090 }
2062 put_page(pages[i]);
2063 return rc; 2091 return rc;
2064} 2092}
2065 2093
@@ -2070,9 +2098,7 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
2070 size_t clen; 2098 size_t clen;
2071 2099
2072 clen = min_t(const size_t, len, wsize); 2100 clen = min_t(const size_t, len, wsize);
2073 num_pages = clen / PAGE_CACHE_SIZE; 2101 num_pages = DIV_ROUND_UP(clen, PAGE_SIZE);
2074 if (clen % PAGE_CACHE_SIZE)
2075 num_pages++;
2076 2102
2077 if (cur_len) 2103 if (cur_len)
2078 *cur_len = clen; 2104 *cur_len = clen;
@@ -2080,24 +2106,79 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
2080 return num_pages; 2106 return num_pages;
2081} 2107}
2082 2108
2109static void
2110cifs_uncached_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata)
2111{
2112 int i;
2113 size_t bytes = wdata->bytes;
2114
2115 /* marshal up the pages into iov array */
2116 for (i = 0; i < wdata->nr_pages; i++) {
2117 iov[i + 1].iov_len = min_t(size_t, bytes, PAGE_SIZE);
2118 iov[i + 1].iov_base = kmap(wdata->pages[i]);
2119 bytes -= iov[i + 1].iov_len;
2120 }
2121}
2122
2123static void
2124cifs_uncached_writev_complete(struct work_struct *work)
2125{
2126 int i;
2127 struct cifs_writedata *wdata = container_of(work,
2128 struct cifs_writedata, work);
2129 struct inode *inode = wdata->cfile->dentry->d_inode;
2130 struct cifsInodeInfo *cifsi = CIFS_I(inode);
2131
2132 spin_lock(&inode->i_lock);
2133 cifs_update_eof(cifsi, wdata->offset, wdata->bytes);
2134 if (cifsi->server_eof > inode->i_size)
2135 i_size_write(inode, cifsi->server_eof);
2136 spin_unlock(&inode->i_lock);
2137
2138 complete(&wdata->done);
2139
2140 if (wdata->result != -EAGAIN) {
2141 for (i = 0; i < wdata->nr_pages; i++)
2142 put_page(wdata->pages[i]);
2143 }
2144
2145 kref_put(&wdata->refcount, cifs_writedata_release);
2146}
2147
2148/* attempt to send write to server, retry on any -EAGAIN errors */
2149static int
2150cifs_uncached_retry_writev(struct cifs_writedata *wdata)
2151{
2152 int rc;
2153
2154 do {
2155 if (wdata->cfile->invalidHandle) {
2156 rc = cifs_reopen_file(wdata->cfile, false);
2157 if (rc != 0)
2158 continue;
2159 }
2160 rc = cifs_async_writev(wdata);
2161 } while (rc == -EAGAIN);
2162
2163 return rc;
2164}
2165
2083static ssize_t 2166static ssize_t
2084cifs_iovec_write(struct file *file, const struct iovec *iov, 2167cifs_iovec_write(struct file *file, const struct iovec *iov,
2085 unsigned long nr_segs, loff_t *poffset) 2168 unsigned long nr_segs, loff_t *poffset)
2086{ 2169{
2087 unsigned int written; 2170 unsigned long nr_pages, i;
2088 unsigned long num_pages, npages, i;
2089 size_t copied, len, cur_len; 2171 size_t copied, len, cur_len;
2090 ssize_t total_written = 0; 2172 ssize_t total_written = 0;
2091 struct kvec *to_send; 2173 loff_t offset = *poffset;
2092 struct page **pages;
2093 struct iov_iter it; 2174 struct iov_iter it;
2094 struct inode *inode;
2095 struct cifsFileInfo *open_file; 2175 struct cifsFileInfo *open_file;
2096 struct cifs_tcon *pTcon; 2176 struct cifs_tcon *tcon;
2097 struct cifs_sb_info *cifs_sb; 2177 struct cifs_sb_info *cifs_sb;
2098 struct cifs_io_parms io_parms; 2178 struct cifs_writedata *wdata, *tmp;
2099 int xid, rc; 2179 struct list_head wdata_list;
2100 __u32 pid; 2180 int rc;
2181 pid_t pid;
2101 2182
2102 len = iov_length(iov, nr_segs); 2183 len = iov_length(iov, nr_segs);
2103 if (!len) 2184 if (!len)
@@ -2107,103 +2188,103 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
2107 if (rc) 2188 if (rc)
2108 return rc; 2189 return rc;
2109 2190
2191 INIT_LIST_HEAD(&wdata_list);
2110 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 2192 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
2111 num_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
2112
2113 pages = kmalloc(sizeof(struct pages *)*num_pages, GFP_KERNEL);
2114 if (!pages)
2115 return -ENOMEM;
2116
2117 to_send = kmalloc(sizeof(struct kvec)*(num_pages + 1), GFP_KERNEL);
2118 if (!to_send) {
2119 kfree(pages);
2120 return -ENOMEM;
2121 }
2122
2123 rc = cifs_write_allocate_pages(pages, num_pages);
2124 if (rc) {
2125 kfree(pages);
2126 kfree(to_send);
2127 return rc;
2128 }
2129
2130 xid = GetXid();
2131 open_file = file->private_data; 2193 open_file = file->private_data;
2194 tcon = tlink_tcon(open_file->tlink);
2132 2195
2133 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) 2196 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
2134 pid = open_file->pid; 2197 pid = open_file->pid;
2135 else 2198 else
2136 pid = current->tgid; 2199 pid = current->tgid;
2137 2200
2138 pTcon = tlink_tcon(open_file->tlink);
2139 inode = file->f_path.dentry->d_inode;
2140
2141 iov_iter_init(&it, iov, nr_segs, len, 0); 2201 iov_iter_init(&it, iov, nr_segs, len, 0);
2142 npages = num_pages;
2143
2144 do { 2202 do {
2145 size_t save_len = cur_len; 2203 size_t save_len;
2146 for (i = 0; i < npages; i++) { 2204
2147 copied = min_t(const size_t, cur_len, PAGE_CACHE_SIZE); 2205 nr_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
2148 copied = iov_iter_copy_from_user(pages[i], &it, 0, 2206 wdata = cifs_writedata_alloc(nr_pages,
2149 copied); 2207 cifs_uncached_writev_complete);
2208 if (!wdata) {
2209 rc = -ENOMEM;
2210 break;
2211 }
2212
2213 rc = cifs_write_allocate_pages(wdata->pages, nr_pages);
2214 if (rc) {
2215 kfree(wdata);
2216 break;
2217 }
2218
2219 save_len = cur_len;
2220 for (i = 0; i < nr_pages; i++) {
2221 copied = min_t(const size_t, cur_len, PAGE_SIZE);
2222 copied = iov_iter_copy_from_user(wdata->pages[i], &it,
2223 0, copied);
2150 cur_len -= copied; 2224 cur_len -= copied;
2151 iov_iter_advance(&it, copied); 2225 iov_iter_advance(&it, copied);
2152 to_send[i+1].iov_base = kmap(pages[i]);
2153 to_send[i+1].iov_len = copied;
2154 } 2226 }
2155
2156 cur_len = save_len - cur_len; 2227 cur_len = save_len - cur_len;
2157 2228
2158 do { 2229 wdata->sync_mode = WB_SYNC_ALL;
2159 if (open_file->invalidHandle) { 2230 wdata->nr_pages = nr_pages;
2160 rc = cifs_reopen_file(open_file, false); 2231 wdata->offset = (__u64)offset;
2161 if (rc != 0) 2232 wdata->cfile = cifsFileInfo_get(open_file);
2162 break; 2233 wdata->pid = pid;
2163 } 2234 wdata->bytes = cur_len;
2164 io_parms.netfid = open_file->netfid; 2235 wdata->marshal_iov = cifs_uncached_marshal_iov;
2165 io_parms.pid = pid; 2236 rc = cifs_uncached_retry_writev(wdata);
2166 io_parms.tcon = pTcon; 2237 if (rc) {
2167 io_parms.offset = *poffset; 2238 kref_put(&wdata->refcount, cifs_writedata_release);
2168 io_parms.length = cur_len;
2169 rc = CIFSSMBWrite2(xid, &io_parms, &written, to_send,
2170 npages, 0);
2171 } while (rc == -EAGAIN);
2172
2173 for (i = 0; i < npages; i++)
2174 kunmap(pages[i]);
2175
2176 if (written) {
2177 len -= written;
2178 total_written += written;
2179 cifs_update_eof(CIFS_I(inode), *poffset, written);
2180 *poffset += written;
2181 } else if (rc < 0) {
2182 if (!total_written)
2183 total_written = rc;
2184 break; 2239 break;
2185 } 2240 }
2186 2241
2187 /* get length and number of kvecs of the next write */ 2242 list_add_tail(&wdata->list, &wdata_list);
2188 npages = get_numpages(cifs_sb->wsize, len, &cur_len); 2243 offset += cur_len;
2244 len -= cur_len;
2189 } while (len > 0); 2245 } while (len > 0);
2190 2246
2191 if (total_written > 0) { 2247 /*
2192 spin_lock(&inode->i_lock); 2248 * If at least one write was successfully sent, then discard any rc
2193 if (*poffset > inode->i_size) 2249 * value from the later writes. If the other write succeeds, then
2194 i_size_write(inode, *poffset); 2250 * we'll end up returning whatever was written. If it fails, then
2195 spin_unlock(&inode->i_lock); 2251 * we'll get a new rc value from that.
2252 */
2253 if (!list_empty(&wdata_list))
2254 rc = 0;
2255
2256 /*
2257 * Wait for and collect replies for any successful sends in order of
2258 * increasing offset. Once an error is hit or we get a fatal signal
2259 * while waiting, then return without waiting for any more replies.
2260 */
2261restart_loop:
2262 list_for_each_entry_safe(wdata, tmp, &wdata_list, list) {
2263 if (!rc) {
2264 /* FIXME: freezable too? */
2265 rc = wait_for_completion_killable(&wdata->done);
2266 if (rc)
2267 rc = -EINTR;
2268 else if (wdata->result)
2269 rc = wdata->result;
2270 else
2271 total_written += wdata->bytes;
2272
2273 /* resend call if it's a retryable error */
2274 if (rc == -EAGAIN) {
2275 rc = cifs_uncached_retry_writev(wdata);
2276 goto restart_loop;
2277 }
2278 }
2279 list_del_init(&wdata->list);
2280 kref_put(&wdata->refcount, cifs_writedata_release);
2196 } 2281 }
2197 2282
2198 cifs_stats_bytes_written(pTcon, total_written); 2283 if (total_written > 0)
2199 mark_inode_dirty_sync(inode); 2284 *poffset += total_written;
2200 2285
2201 for (i = 0; i < num_pages; i++) 2286 cifs_stats_bytes_written(tcon, total_written);
2202 put_page(pages[i]); 2287 return total_written ? total_written : (ssize_t)rc;
2203 kfree(to_send);
2204 kfree(pages);
2205 FreeXid(xid);
2206 return total_written;
2207} 2288}
2208 2289
2209ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, 2290ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov,
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index c273c12de98..c29d1aa2c54 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -213,55 +213,62 @@ cifs_small_buf_release(void *buf_to_free)
213} 213}
214 214
215/* 215/*
216 Find a free multiplex id (SMB mid). Otherwise there could be 216 * Find a free multiplex id (SMB mid). Otherwise there could be
217 mid collisions which might cause problems, demultiplexing the 217 * mid collisions which might cause problems, demultiplexing the
218 wrong response to this request. Multiplex ids could collide if 218 * wrong response to this request. Multiplex ids could collide if
219 one of a series requests takes much longer than the others, or 219 * one of a series requests takes much longer than the others, or
220 if a very large number of long lived requests (byte range 220 * if a very large number of long lived requests (byte range
221 locks or FindNotify requests) are pending. No more than 221 * locks or FindNotify requests) are pending. No more than
222 64K-1 requests can be outstanding at one time. If no 222 * 64K-1 requests can be outstanding at one time. If no
223 mids are available, return zero. A future optimization 223 * mids are available, return zero. A future optimization
224 could make the combination of mids and uid the key we use 224 * could make the combination of mids and uid the key we use
225 to demultiplex on (rather than mid alone). 225 * to demultiplex on (rather than mid alone).
226 In addition to the above check, the cifs demultiplex 226 * In addition to the above check, the cifs demultiplex
227 code already used the command code as a secondary 227 * code already used the command code as a secondary
228 check of the frame and if signing is negotiated the 228 * check of the frame and if signing is negotiated the
229 response would be discarded if the mid were the same 229 * response would be discarded if the mid were the same
230 but the signature was wrong. Since the mid is not put in the 230 * but the signature was wrong. Since the mid is not put in the
231 pending queue until later (when it is about to be dispatched) 231 * pending queue until later (when it is about to be dispatched)
232 we do have to limit the number of outstanding requests 232 * we do have to limit the number of outstanding requests
233 to somewhat less than 64K-1 although it is hard to imagine 233 * to somewhat less than 64K-1 although it is hard to imagine
234 so many threads being in the vfs at one time. 234 * so many threads being in the vfs at one time.
235*/ 235 */
236__u16 GetNextMid(struct TCP_Server_Info *server) 236__u64 GetNextMid(struct TCP_Server_Info *server)
237{ 237{
238 __u16 mid = 0; 238 __u64 mid = 0;
239 __u16 last_mid; 239 __u16 last_mid, cur_mid;
240 bool collision; 240 bool collision;
241 241
242 spin_lock(&GlobalMid_Lock); 242 spin_lock(&GlobalMid_Lock);
243 last_mid = server->CurrentMid; /* we do not want to loop forever */ 243
244 server->CurrentMid++; 244 /* mid is 16 bit only for CIFS/SMB */
245 /* This nested loop looks more expensive than it is. 245 cur_mid = (__u16)((server->CurrentMid) & 0xffff);
246 In practice the list of pending requests is short, 246 /* we do not want to loop forever */
247 fewer than 50, and the mids are likely to be unique 247 last_mid = cur_mid;
248 on the first pass through the loop unless some request 248 cur_mid++;
249 takes longer than the 64 thousand requests before it 249
250 (and it would also have to have been a request that 250 /*
251 did not time out) */ 251 * This nested loop looks more expensive than it is.
252 while (server->CurrentMid != last_mid) { 252 * In practice the list of pending requests is short,
253 * fewer than 50, and the mids are likely to be unique
254 * on the first pass through the loop unless some request
255 * takes longer than the 64 thousand requests before it
256 * (and it would also have to have been a request that
257 * did not time out).
258 */
259 while (cur_mid != last_mid) {
253 struct mid_q_entry *mid_entry; 260 struct mid_q_entry *mid_entry;
254 unsigned int num_mids; 261 unsigned int num_mids;
255 262
256 collision = false; 263 collision = false;
257 if (server->CurrentMid == 0) 264 if (cur_mid == 0)
258 server->CurrentMid++; 265 cur_mid++;
259 266
260 num_mids = 0; 267 num_mids = 0;
261 list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) { 268 list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
262 ++num_mids; 269 ++num_mids;
263 if (mid_entry->mid == server->CurrentMid && 270 if (mid_entry->mid == cur_mid &&
264 mid_entry->midState == MID_REQUEST_SUBMITTED) { 271 mid_entry->mid_state == MID_REQUEST_SUBMITTED) {
265 /* This mid is in use, try a different one */ 272 /* This mid is in use, try a different one */
266 collision = true; 273 collision = true;
267 break; 274 break;
@@ -282,10 +289,11 @@ __u16 GetNextMid(struct TCP_Server_Info *server)
282 server->tcpStatus = CifsNeedReconnect; 289 server->tcpStatus = CifsNeedReconnect;
283 290
284 if (!collision) { 291 if (!collision) {
285 mid = server->CurrentMid; 292 mid = (__u64)cur_mid;
293 server->CurrentMid = mid;
286 break; 294 break;
287 } 295 }
288 server->CurrentMid++; 296 cur_mid++;
289 } 297 }
290 spin_unlock(&GlobalMid_Lock); 298 spin_unlock(&GlobalMid_Lock);
291 return mid; 299 return mid;
@@ -420,8 +428,10 @@ check_smb_hdr(struct smb_hdr *smb, __u16 mid)
420} 428}
421 429
422int 430int
423checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int total_read) 431checkSMB(char *buf, unsigned int total_read)
424{ 432{
433 struct smb_hdr *smb = (struct smb_hdr *)buf;
434 __u16 mid = smb->Mid;
425 __u32 rfclen = be32_to_cpu(smb->smb_buf_length); 435 __u32 rfclen = be32_to_cpu(smb->smb_buf_length);
426 __u32 clc_len; /* calculated length */ 436 __u32 clc_len; /* calculated length */
427 cFYI(0, "checkSMB Length: 0x%x, smb_buf_length: 0x%x", 437 cFYI(0, "checkSMB Length: 0x%x, smb_buf_length: 0x%x",
@@ -502,8 +512,9 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int total_read)
502} 512}
503 513
504bool 514bool
505is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) 515is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
506{ 516{
517 struct smb_hdr *buf = (struct smb_hdr *)buffer;
507 struct smb_com_lock_req *pSMB = (struct smb_com_lock_req *)buf; 518 struct smb_com_lock_req *pSMB = (struct smb_com_lock_req *)buf;
508 struct list_head *tmp, *tmp1, *tmp2; 519 struct list_head *tmp, *tmp1, *tmp2;
509 struct cifs_ses *ses; 520 struct cifs_ses *ses;
@@ -584,7 +595,7 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
584 595
585 cifs_set_oplock_level(pCifsInode, 596 cifs_set_oplock_level(pCifsInode,
586 pSMB->OplockLevel ? OPLOCK_READ : 0); 597 pSMB->OplockLevel ? OPLOCK_READ : 0);
587 queue_work(system_nrt_wq, 598 queue_work(cifsiod_wq,
588 &netfile->oplock_break); 599 &netfile->oplock_break);
589 netfile->oplock_break_cancelled = false; 600 netfile->oplock_break_cancelled = false;
590 601
@@ -604,16 +615,15 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
604} 615}
605 616
606void 617void
607dump_smb(struct smb_hdr *smb_buf, int smb_buf_length) 618dump_smb(void *buf, int smb_buf_length)
608{ 619{
609 int i, j; 620 int i, j;
610 char debug_line[17]; 621 char debug_line[17];
611 unsigned char *buffer; 622 unsigned char *buffer = buf;
612 623
613 if (traceSMB == 0) 624 if (traceSMB == 0)
614 return; 625 return;
615 626
616 buffer = (unsigned char *) smb_buf;
617 for (i = 0, j = 0; i < smb_buf_length; i++, j++) { 627 for (i = 0, j = 0; i < smb_buf_length; i++, j++) {
618 if (i % 8 == 0) { 628 if (i % 8 == 0) {
619 /* have reached the beginning of line */ 629 /* have reached the beginning of line */
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index 73e47e84b61..dd23a321bdd 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -836,8 +836,9 @@ ntstatus_to_dos(__u32 ntstatus, __u8 *eclass, __u16 *ecode)
836} 836}
837 837
838int 838int
839map_smb_to_linux_error(struct smb_hdr *smb, bool logErr) 839map_smb_to_linux_error(char *buf, bool logErr)
840{ 840{
841 struct smb_hdr *smb = (struct smb_hdr *)buf;
841 unsigned int i; 842 unsigned int i;
842 int rc = -EIO; /* if transport error smb error may not be set */ 843 int rc = -EIO; /* if transport error smb error may not be set */
843 __u8 smberrclass; 844 __u8 smberrclass;
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index 310918b6fcb..0961336513d 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -60,8 +60,8 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
60 memset(temp, 0, sizeof(struct mid_q_entry)); 60 memset(temp, 0, sizeof(struct mid_q_entry));
61 temp->mid = smb_buffer->Mid; /* always LE */ 61 temp->mid = smb_buffer->Mid; /* always LE */
62 temp->pid = current->pid; 62 temp->pid = current->pid;
63 temp->command = smb_buffer->Command; 63 temp->command = cpu_to_le16(smb_buffer->Command);
64 cFYI(1, "For smb_command %d", temp->command); 64 cFYI(1, "For smb_command %d", smb_buffer->Command);
65 /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */ 65 /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */
66 /* when mid allocated can be before when sent */ 66 /* when mid allocated can be before when sent */
67 temp->when_alloc = jiffies; 67 temp->when_alloc = jiffies;
@@ -75,7 +75,7 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
75 } 75 }
76 76
77 atomic_inc(&midCount); 77 atomic_inc(&midCount);
78 temp->midState = MID_REQUEST_ALLOCATED; 78 temp->mid_state = MID_REQUEST_ALLOCATED;
79 return temp; 79 return temp;
80} 80}
81 81
@@ -85,9 +85,9 @@ DeleteMidQEntry(struct mid_q_entry *midEntry)
85#ifdef CONFIG_CIFS_STATS2 85#ifdef CONFIG_CIFS_STATS2
86 unsigned long now; 86 unsigned long now;
87#endif 87#endif
88 midEntry->midState = MID_FREE; 88 midEntry->mid_state = MID_FREE;
89 atomic_dec(&midCount); 89 atomic_dec(&midCount);
90 if (midEntry->largeBuf) 90 if (midEntry->large_buf)
91 cifs_buf_release(midEntry->resp_buf); 91 cifs_buf_release(midEntry->resp_buf);
92 else 92 else
93 cifs_small_buf_release(midEntry->resp_buf); 93 cifs_small_buf_release(midEntry->resp_buf);
@@ -97,8 +97,8 @@ DeleteMidQEntry(struct mid_q_entry *midEntry)
97 something is wrong, unless it is quite a slow link or server */ 97 something is wrong, unless it is quite a slow link or server */
98 if ((now - midEntry->when_alloc) > HZ) { 98 if ((now - midEntry->when_alloc) > HZ) {
99 if ((cifsFYI & CIFS_TIMER) && 99 if ((cifsFYI & CIFS_TIMER) &&
100 (midEntry->command != SMB_COM_LOCKING_ANDX)) { 100 (midEntry->command != cpu_to_le16(SMB_COM_LOCKING_ANDX))) {
101 printk(KERN_DEBUG " CIFS slow rsp: cmd %d mid %d", 101 printk(KERN_DEBUG " CIFS slow rsp: cmd %d mid %llu",
102 midEntry->command, midEntry->mid); 102 midEntry->command, midEntry->mid);
103 printk(" A: 0x%lx S: 0x%lx R: 0x%lx\n", 103 printk(" A: 0x%lx S: 0x%lx R: 0x%lx\n",
104 now - midEntry->when_alloc, 104 now - midEntry->when_alloc,
@@ -126,11 +126,11 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
126 int rc = 0; 126 int rc = 0;
127 int i = 0; 127 int i = 0;
128 struct msghdr smb_msg; 128 struct msghdr smb_msg;
129 struct smb_hdr *smb_buffer = iov[0].iov_base; 129 __be32 *buf_len = (__be32 *)(iov[0].iov_base);
130 unsigned int len = iov[0].iov_len; 130 unsigned int len = iov[0].iov_len;
131 unsigned int total_len; 131 unsigned int total_len;
132 int first_vec = 0; 132 int first_vec = 0;
133 unsigned int smb_buf_length = be32_to_cpu(smb_buffer->smb_buf_length); 133 unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base);
134 struct socket *ssocket = server->ssocket; 134 struct socket *ssocket = server->ssocket;
135 135
136 if (ssocket == NULL) 136 if (ssocket == NULL)
@@ -150,7 +150,7 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
150 total_len += iov[i].iov_len; 150 total_len += iov[i].iov_len;
151 151
152 cFYI(1, "Sending smb: total_len %d", total_len); 152 cFYI(1, "Sending smb: total_len %d", total_len);
153 dump_smb(smb_buffer, len); 153 dump_smb(iov[0].iov_base, len);
154 154
155 i = 0; 155 i = 0;
156 while (total_len) { 156 while (total_len) {
@@ -158,24 +158,24 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
158 n_vec - first_vec, total_len); 158 n_vec - first_vec, total_len);
159 if ((rc == -ENOSPC) || (rc == -EAGAIN)) { 159 if ((rc == -ENOSPC) || (rc == -EAGAIN)) {
160 i++; 160 i++;
161 /* if blocking send we try 3 times, since each can block 161 /*
162 for 5 seconds. For nonblocking we have to try more 162 * If blocking send we try 3 times, since each can block
163 but wait increasing amounts of time allowing time for 163 * for 5 seconds. For nonblocking we have to try more
164 socket to clear. The overall time we wait in either 164 * but wait increasing amounts of time allowing time for
165 case to send on the socket is about 15 seconds. 165 * socket to clear. The overall time we wait in either
166 Similarly we wait for 15 seconds for 166 * case to send on the socket is about 15 seconds.
167 a response from the server in SendReceive[2] 167 * Similarly we wait for 15 seconds for a response from
168 for the server to send a response back for 168 * the server in SendReceive[2] for the server to send
169 most types of requests (except SMB Write 169 * a response back for most types of requests (except
170 past end of file which can be slow, and 170 * SMB Write past end of file which can be slow, and
171 blocking lock operations). NFS waits slightly longer 171 * blocking lock operations). NFS waits slightly longer
172 than CIFS, but this can make it take longer for 172 * than CIFS, but this can make it take longer for
173 nonresponsive servers to be detected and 15 seconds 173 * nonresponsive servers to be detected and 15 seconds
174 is more than enough time for modern networks to 174 * is more than enough time for modern networks to
175 send a packet. In most cases if we fail to send 175 * send a packet. In most cases if we fail to send
176 after the retries we will kill the socket and 176 * after the retries we will kill the socket and
177 reconnect which may clear the network problem. 177 * reconnect which may clear the network problem.
178 */ 178 */
179 if ((i >= 14) || (!server->noblocksnd && (i > 2))) { 179 if ((i >= 14) || (!server->noblocksnd && (i > 2))) {
180 cERROR(1, "sends on sock %p stuck for 15 seconds", 180 cERROR(1, "sends on sock %p stuck for 15 seconds",
181 ssocket); 181 ssocket);
@@ -235,9 +235,8 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
235 else 235 else
236 rc = 0; 236 rc = 0;
237 237
238 /* Don't want to modify the buffer as a 238 /* Don't want to modify the buffer as a side effect of this call. */
239 side effect of this call. */ 239 *buf_len = cpu_to_be32(smb_buf_length);
240 smb_buffer->smb_buf_length = cpu_to_be32(smb_buf_length);
241 240
242 return rc; 241 return rc;
243} 242}
@@ -342,13 +341,40 @@ wait_for_response(struct TCP_Server_Info *server, struct mid_q_entry *midQ)
342 int error; 341 int error;
343 342
344 error = wait_event_freezekillable(server->response_q, 343 error = wait_event_freezekillable(server->response_q,
345 midQ->midState != MID_REQUEST_SUBMITTED); 344 midQ->mid_state != MID_REQUEST_SUBMITTED);
346 if (error < 0) 345 if (error < 0)
347 return -ERESTARTSYS; 346 return -ERESTARTSYS;
348 347
349 return 0; 348 return 0;
350} 349}
351 350
351static int
352cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov,
353 unsigned int nvec, struct mid_q_entry **ret_mid)
354{
355 int rc;
356 struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base;
357 struct mid_q_entry *mid;
358
359 /* enable signing if server requires it */
360 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
361 hdr->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
362
363 mid = AllocMidQEntry(hdr, server);
364 if (mid == NULL)
365 return -ENOMEM;
366
367 /* put it on the pending_mid_q */
368 spin_lock(&GlobalMid_Lock);
369 list_add_tail(&mid->qhead, &server->pending_mid_q);
370 spin_unlock(&GlobalMid_Lock);
371
372 rc = cifs_sign_smb2(iov, nvec, server, &mid->sequence_number);
373 if (rc)
374 delete_mid(mid);
375 *ret_mid = mid;
376 return rc;
377}
352 378
353/* 379/*
354 * Send a SMB request and set the callback function in the mid to handle 380 * Send a SMB request and set the callback function in the mid to handle
@@ -361,40 +387,24 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
361{ 387{
362 int rc; 388 int rc;
363 struct mid_q_entry *mid; 389 struct mid_q_entry *mid;
364 struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base;
365 390
366 rc = wait_for_free_request(server, ignore_pend ? CIFS_ASYNC_OP : 0); 391 rc = wait_for_free_request(server, ignore_pend ? CIFS_ASYNC_OP : 0);
367 if (rc) 392 if (rc)
368 return rc; 393 return rc;
369 394
370 /* enable signing if server requires it */
371 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
372 hdr->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
373
374 mutex_lock(&server->srv_mutex); 395 mutex_lock(&server->srv_mutex);
375 mid = AllocMidQEntry(hdr, server); 396 rc = cifs_setup_async_request(server, iov, nvec, &mid);
376 if (mid == NULL) { 397 if (rc) {
377 mutex_unlock(&server->srv_mutex); 398 mutex_unlock(&server->srv_mutex);
378 cifs_add_credits(server, 1); 399 cifs_add_credits(server, 1);
379 wake_up(&server->request_q); 400 wake_up(&server->request_q);
380 return -ENOMEM; 401 return rc;
381 }
382
383 /* put it on the pending_mid_q */
384 spin_lock(&GlobalMid_Lock);
385 list_add_tail(&mid->qhead, &server->pending_mid_q);
386 spin_unlock(&GlobalMid_Lock);
387
388 rc = cifs_sign_smb2(iov, nvec, server, &mid->sequence_number);
389 if (rc) {
390 mutex_unlock(&server->srv_mutex);
391 goto out_err;
392 } 402 }
393 403
394 mid->receive = receive; 404 mid->receive = receive;
395 mid->callback = callback; 405 mid->callback = callback;
396 mid->callback_data = cbdata; 406 mid->callback_data = cbdata;
397 mid->midState = MID_REQUEST_SUBMITTED; 407 mid->mid_state = MID_REQUEST_SUBMITTED;
398 408
399 cifs_in_send_inc(server); 409 cifs_in_send_inc(server);
400 rc = smb_sendv(server, iov, nvec); 410 rc = smb_sendv(server, iov, nvec);
@@ -424,14 +434,14 @@ out_err:
424 */ 434 */
425int 435int
426SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, 436SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses,
427 struct smb_hdr *in_buf, int flags) 437 char *in_buf, int flags)
428{ 438{
429 int rc; 439 int rc;
430 struct kvec iov[1]; 440 struct kvec iov[1];
431 int resp_buf_type; 441 int resp_buf_type;
432 442
433 iov[0].iov_base = (char *)in_buf; 443 iov[0].iov_base = in_buf;
434 iov[0].iov_len = be32_to_cpu(in_buf->smb_buf_length) + 4; 444 iov[0].iov_len = get_rfc1002_length(in_buf) + 4;
435 flags |= CIFS_NO_RESP; 445 flags |= CIFS_NO_RESP;
436 rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags); 446 rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags);
437 cFYI(DBG2, "SendRcvNoRsp flags %d rc %d", flags, rc); 447 cFYI(DBG2, "SendRcvNoRsp flags %d rc %d", flags, rc);
@@ -444,11 +454,11 @@ cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
444{ 454{
445 int rc = 0; 455 int rc = 0;
446 456
447 cFYI(1, "%s: cmd=%d mid=%d state=%d", __func__, mid->command, 457 cFYI(1, "%s: cmd=%d mid=%llu state=%d", __func__,
448 mid->mid, mid->midState); 458 le16_to_cpu(mid->command), mid->mid, mid->mid_state);
449 459
450 spin_lock(&GlobalMid_Lock); 460 spin_lock(&GlobalMid_Lock);
451 switch (mid->midState) { 461 switch (mid->mid_state) {
452 case MID_RESPONSE_RECEIVED: 462 case MID_RESPONSE_RECEIVED:
453 spin_unlock(&GlobalMid_Lock); 463 spin_unlock(&GlobalMid_Lock);
454 return rc; 464 return rc;
@@ -463,8 +473,8 @@ cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
463 break; 473 break;
464 default: 474 default:
465 list_del_init(&mid->qhead); 475 list_del_init(&mid->qhead);
466 cERROR(1, "%s: invalid mid state mid=%d state=%d", __func__, 476 cERROR(1, "%s: invalid mid state mid=%llu state=%d", __func__,
467 mid->mid, mid->midState); 477 mid->mid, mid->mid_state);
468 rc = -EIO; 478 rc = -EIO;
469 } 479 }
470 spin_unlock(&GlobalMid_Lock); 480 spin_unlock(&GlobalMid_Lock);
@@ -514,7 +524,7 @@ int
514cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, 524cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
515 bool log_error) 525 bool log_error)
516{ 526{
517 unsigned int len = be32_to_cpu(mid->resp_buf->smb_buf_length) + 4; 527 unsigned int len = get_rfc1002_length(mid->resp_buf) + 4;
518 528
519 dump_smb(mid->resp_buf, min_t(u32, 92, len)); 529 dump_smb(mid->resp_buf, min_t(u32, 92, len));
520 530
@@ -534,6 +544,24 @@ cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
534 return map_smb_to_linux_error(mid->resp_buf, log_error); 544 return map_smb_to_linux_error(mid->resp_buf, log_error);
535} 545}
536 546
547static int
548cifs_setup_request(struct cifs_ses *ses, struct kvec *iov,
549 unsigned int nvec, struct mid_q_entry **ret_mid)
550{
551 int rc;
552 struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base;
553 struct mid_q_entry *mid;
554
555 rc = allocate_mid(ses, hdr, &mid);
556 if (rc)
557 return rc;
558 rc = cifs_sign_smb2(iov, nvec, ses->server, &mid->sequence_number);
559 if (rc)
560 delete_mid(mid);
561 *ret_mid = mid;
562 return rc;
563}
564
537int 565int
538SendReceive2(const unsigned int xid, struct cifs_ses *ses, 566SendReceive2(const unsigned int xid, struct cifs_ses *ses,
539 struct kvec *iov, int n_vec, int *pRespBufType /* ret */, 567 struct kvec *iov, int n_vec, int *pRespBufType /* ret */,
@@ -542,55 +570,53 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
542 int rc = 0; 570 int rc = 0;
543 int long_op; 571 int long_op;
544 struct mid_q_entry *midQ; 572 struct mid_q_entry *midQ;
545 struct smb_hdr *in_buf = iov[0].iov_base; 573 char *buf = iov[0].iov_base;
546 574
547 long_op = flags & CIFS_TIMEOUT_MASK; 575 long_op = flags & CIFS_TIMEOUT_MASK;
548 576
549 *pRespBufType = CIFS_NO_BUFFER; /* no response buf yet */ 577 *pRespBufType = CIFS_NO_BUFFER; /* no response buf yet */
550 578
551 if ((ses == NULL) || (ses->server == NULL)) { 579 if ((ses == NULL) || (ses->server == NULL)) {
552 cifs_small_buf_release(in_buf); 580 cifs_small_buf_release(buf);
553 cERROR(1, "Null session"); 581 cERROR(1, "Null session");
554 return -EIO; 582 return -EIO;
555 } 583 }
556 584
557 if (ses->server->tcpStatus == CifsExiting) { 585 if (ses->server->tcpStatus == CifsExiting) {
558 cifs_small_buf_release(in_buf); 586 cifs_small_buf_release(buf);
559 return -ENOENT; 587 return -ENOENT;
560 } 588 }
561 589
562 /* Ensure that we do not send more than 50 overlapping requests 590 /*
563 to the same server. We may make this configurable later or 591 * Ensure that we do not send more than 50 overlapping requests
564 use ses->maxReq */ 592 * to the same server. We may make this configurable later or
593 * use ses->maxReq.
594 */
565 595
566 rc = wait_for_free_request(ses->server, long_op); 596 rc = wait_for_free_request(ses->server, long_op);
567 if (rc) { 597 if (rc) {
568 cifs_small_buf_release(in_buf); 598 cifs_small_buf_release(buf);
569 return rc; 599 return rc;
570 } 600 }
571 601
572 /* make sure that we sign in the same order that we send on this socket 602 /*
573 and avoid races inside tcp sendmsg code that could cause corruption 603 * Make sure that we sign in the same order that we send on this socket
574 of smb data */ 604 * and avoid races inside tcp sendmsg code that could cause corruption
605 * of smb data.
606 */
575 607
576 mutex_lock(&ses->server->srv_mutex); 608 mutex_lock(&ses->server->srv_mutex);
577 609
578 rc = allocate_mid(ses, in_buf, &midQ); 610 rc = cifs_setup_request(ses, iov, n_vec, &midQ);
579 if (rc) { 611 if (rc) {
580 mutex_unlock(&ses->server->srv_mutex); 612 mutex_unlock(&ses->server->srv_mutex);
581 cifs_small_buf_release(in_buf); 613 cifs_small_buf_release(buf);
582 /* Update # of requests on wire to server */ 614 /* Update # of requests on wire to server */
583 cifs_add_credits(ses->server, 1); 615 cifs_add_credits(ses->server, 1);
584 return rc; 616 return rc;
585 } 617 }
586 rc = cifs_sign_smb2(iov, n_vec, ses->server, &midQ->sequence_number);
587 if (rc) {
588 mutex_unlock(&ses->server->srv_mutex);
589 cifs_small_buf_release(in_buf);
590 goto out;
591 }
592 618
593 midQ->midState = MID_REQUEST_SUBMITTED; 619 midQ->mid_state = MID_REQUEST_SUBMITTED;
594 cifs_in_send_inc(ses->server); 620 cifs_in_send_inc(ses->server);
595 rc = smb_sendv(ses->server, iov, n_vec); 621 rc = smb_sendv(ses->server, iov, n_vec);
596 cifs_in_send_dec(ses->server); 622 cifs_in_send_dec(ses->server);
@@ -599,30 +625,30 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
599 mutex_unlock(&ses->server->srv_mutex); 625 mutex_unlock(&ses->server->srv_mutex);
600 626
601 if (rc < 0) { 627 if (rc < 0) {
602 cifs_small_buf_release(in_buf); 628 cifs_small_buf_release(buf);
603 goto out; 629 goto out;
604 } 630 }
605 631
606 if (long_op == CIFS_ASYNC_OP) { 632 if (long_op == CIFS_ASYNC_OP) {
607 cifs_small_buf_release(in_buf); 633 cifs_small_buf_release(buf);
608 goto out; 634 goto out;
609 } 635 }
610 636
611 rc = wait_for_response(ses->server, midQ); 637 rc = wait_for_response(ses->server, midQ);
612 if (rc != 0) { 638 if (rc != 0) {
613 send_nt_cancel(ses->server, in_buf, midQ); 639 send_nt_cancel(ses->server, (struct smb_hdr *)buf, midQ);
614 spin_lock(&GlobalMid_Lock); 640 spin_lock(&GlobalMid_Lock);
615 if (midQ->midState == MID_REQUEST_SUBMITTED) { 641 if (midQ->mid_state == MID_REQUEST_SUBMITTED) {
616 midQ->callback = DeleteMidQEntry; 642 midQ->callback = DeleteMidQEntry;
617 spin_unlock(&GlobalMid_Lock); 643 spin_unlock(&GlobalMid_Lock);
618 cifs_small_buf_release(in_buf); 644 cifs_small_buf_release(buf);
619 cifs_add_credits(ses->server, 1); 645 cifs_add_credits(ses->server, 1);
620 return rc; 646 return rc;
621 } 647 }
622 spin_unlock(&GlobalMid_Lock); 648 spin_unlock(&GlobalMid_Lock);
623 } 649 }
624 650
625 cifs_small_buf_release(in_buf); 651 cifs_small_buf_release(buf);
626 652
627 rc = cifs_sync_mid_result(midQ, ses->server); 653 rc = cifs_sync_mid_result(midQ, ses->server);
628 if (rc != 0) { 654 if (rc != 0) {
@@ -630,15 +656,16 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
630 return rc; 656 return rc;
631 } 657 }
632 658
633 if (!midQ->resp_buf || midQ->midState != MID_RESPONSE_RECEIVED) { 659 if (!midQ->resp_buf || midQ->mid_state != MID_RESPONSE_RECEIVED) {
634 rc = -EIO; 660 rc = -EIO;
635 cFYI(1, "Bad MID state?"); 661 cFYI(1, "Bad MID state?");
636 goto out; 662 goto out;
637 } 663 }
638 664
639 iov[0].iov_base = (char *)midQ->resp_buf; 665 buf = (char *)midQ->resp_buf;
640 iov[0].iov_len = be32_to_cpu(midQ->resp_buf->smb_buf_length) + 4; 666 iov[0].iov_base = buf;
641 if (midQ->largeBuf) 667 iov[0].iov_len = get_rfc1002_length(buf) + 4;
668 if (midQ->large_buf)
642 *pRespBufType = CIFS_LARGE_BUFFER; 669 *pRespBufType = CIFS_LARGE_BUFFER;
643 else 670 else
644 *pRespBufType = CIFS_SMALL_BUFFER; 671 *pRespBufType = CIFS_SMALL_BUFFER;
@@ -710,7 +737,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
710 goto out; 737 goto out;
711 } 738 }
712 739
713 midQ->midState = MID_REQUEST_SUBMITTED; 740 midQ->mid_state = MID_REQUEST_SUBMITTED;
714 741
715 cifs_in_send_inc(ses->server); 742 cifs_in_send_inc(ses->server);
716 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length)); 743 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
@@ -728,7 +755,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
728 if (rc != 0) { 755 if (rc != 0) {
729 send_nt_cancel(ses->server, in_buf, midQ); 756 send_nt_cancel(ses->server, in_buf, midQ);
730 spin_lock(&GlobalMid_Lock); 757 spin_lock(&GlobalMid_Lock);
731 if (midQ->midState == MID_REQUEST_SUBMITTED) { 758 if (midQ->mid_state == MID_REQUEST_SUBMITTED) {
732 /* no longer considered to be "in-flight" */ 759 /* no longer considered to be "in-flight" */
733 midQ->callback = DeleteMidQEntry; 760 midQ->callback = DeleteMidQEntry;
734 spin_unlock(&GlobalMid_Lock); 761 spin_unlock(&GlobalMid_Lock);
@@ -745,13 +772,13 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
745 } 772 }
746 773
747 if (!midQ->resp_buf || !out_buf || 774 if (!midQ->resp_buf || !out_buf ||
748 midQ->midState != MID_RESPONSE_RECEIVED) { 775 midQ->mid_state != MID_RESPONSE_RECEIVED) {
749 rc = -EIO; 776 rc = -EIO;
750 cERROR(1, "Bad MID state?"); 777 cERROR(1, "Bad MID state?");
751 goto out; 778 goto out;
752 } 779 }
753 780
754 *pbytes_returned = be32_to_cpu(midQ->resp_buf->smb_buf_length); 781 *pbytes_returned = get_rfc1002_length(midQ->resp_buf);
755 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); 782 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4);
756 rc = cifs_check_receive(midQ, ses->server, 0); 783 rc = cifs_check_receive(midQ, ses->server, 0);
757out: 784out:
@@ -844,7 +871,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
844 return rc; 871 return rc;
845 } 872 }
846 873
847 midQ->midState = MID_REQUEST_SUBMITTED; 874 midQ->mid_state = MID_REQUEST_SUBMITTED;
848 cifs_in_send_inc(ses->server); 875 cifs_in_send_inc(ses->server);
849 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length)); 876 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
850 cifs_in_send_dec(ses->server); 877 cifs_in_send_dec(ses->server);
@@ -858,13 +885,13 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
858 885
859 /* Wait for a reply - allow signals to interrupt. */ 886 /* Wait for a reply - allow signals to interrupt. */
860 rc = wait_event_interruptible(ses->server->response_q, 887 rc = wait_event_interruptible(ses->server->response_q,
861 (!(midQ->midState == MID_REQUEST_SUBMITTED)) || 888 (!(midQ->mid_state == MID_REQUEST_SUBMITTED)) ||
862 ((ses->server->tcpStatus != CifsGood) && 889 ((ses->server->tcpStatus != CifsGood) &&
863 (ses->server->tcpStatus != CifsNew))); 890 (ses->server->tcpStatus != CifsNew)));
864 891
865 /* Were we interrupted by a signal ? */ 892 /* Were we interrupted by a signal ? */
866 if ((rc == -ERESTARTSYS) && 893 if ((rc == -ERESTARTSYS) &&
867 (midQ->midState == MID_REQUEST_SUBMITTED) && 894 (midQ->mid_state == MID_REQUEST_SUBMITTED) &&
868 ((ses->server->tcpStatus == CifsGood) || 895 ((ses->server->tcpStatus == CifsGood) ||
869 (ses->server->tcpStatus == CifsNew))) { 896 (ses->server->tcpStatus == CifsNew))) {
870 897
@@ -894,7 +921,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
894 if (rc) { 921 if (rc) {
895 send_nt_cancel(ses->server, in_buf, midQ); 922 send_nt_cancel(ses->server, in_buf, midQ);
896 spin_lock(&GlobalMid_Lock); 923 spin_lock(&GlobalMid_Lock);
897 if (midQ->midState == MID_REQUEST_SUBMITTED) { 924 if (midQ->mid_state == MID_REQUEST_SUBMITTED) {
898 /* no longer considered to be "in-flight" */ 925 /* no longer considered to be "in-flight" */
899 midQ->callback = DeleteMidQEntry; 926 midQ->callback = DeleteMidQEntry;
900 spin_unlock(&GlobalMid_Lock); 927 spin_unlock(&GlobalMid_Lock);
@@ -912,13 +939,13 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
912 return rc; 939 return rc;
913 940
914 /* rcvd frame is ok */ 941 /* rcvd frame is ok */
915 if (out_buf == NULL || midQ->midState != MID_RESPONSE_RECEIVED) { 942 if (out_buf == NULL || midQ->mid_state != MID_RESPONSE_RECEIVED) {
916 rc = -EIO; 943 rc = -EIO;
917 cERROR(1, "Bad MID state?"); 944 cERROR(1, "Bad MID state?");
918 goto out; 945 goto out;
919 } 946 }
920 947
921 *pbytes_returned = be32_to_cpu(midQ->resp_buf->smb_buf_length); 948 *pbytes_returned = get_rfc1002_length(midQ->resp_buf);
922 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); 949 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4);
923 rc = cifs_check_receive(midQ, ses->server, 0); 950 rc = cifs_check_receive(midQ, ses->server, 0);
924out: 951out: