Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge git://git.samba.org/sfrench/cifs-2.6

Pull cifs fixes from Steve French.

* git://git.samba.org/sfrench/cifs-2.6:
[CIFS] Update CIFS version number to 1.77
CIFS: Add missed forcemand mount option
[CIFS] Fix trivial sparse warning with asyn i/o patch
cifs: handle "sloppy" option appropriately
cifs: use standard token parser for mount options
cifs: remove /proc/fs/cifs/OplockEnabled
cifs: convert cifs_iovec_write to use async writes
cifs: call cifs_update_eof with i_lock held
cifs: abstract out function to marshal up the iovec array for async writes
cifs: fix up get_numpages
cifs: make cifsFileInfo_get return the cifsFileInfo pointer
cifs: fix allocation in cifs_write_allocate_pages
cifs: allow caller to specify completion op when allocating writedata
cifs: add pid field to cifs_writedata
cifs: add new cifsiod_wq workqueue
CIFS: Change mid_q_entry structure fields
CIFS: Expand CurrentMid field
CIFS: Separate protocol-specific code from cifs_readv_receive code
CIFS: Separate protocol-specific code from demultiplex code
CIFS: Separate protocol-specific code from transport routines

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