cifs_debug.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. /*
  2. * fs/cifs_debug.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2000,2005
  5. *
  6. * Modified by Steve French (sfrench@us.ibm.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  16. * the GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/fs.h>
  23. #include <linux/string.h>
  24. #include <linux/ctype.h>
  25. #include <linux/module.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/uaccess.h>
  28. #include "cifspdu.h"
  29. #include "cifsglob.h"
  30. #include "cifsproto.h"
  31. #include "cifs_debug.h"
  32. #include "cifsfs.h"
  33. #ifdef CONFIG_CIFS_SMB_DIRECT
  34. #include "smbdirect.h"
  35. #endif
  36. void
  37. cifs_dump_mem(char *label, void *data, int length)
  38. {
  39. pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
  40. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
  41. data, length, true);
  42. }
  43. void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
  44. {
  45. #ifdef CONFIG_CIFS_DEBUG2
  46. struct smb_hdr *smb = (struct smb_hdr *)buf;
  47. cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
  48. smb->Command, smb->Status.CifsError,
  49. smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
  50. cifs_dbg(VFS, "smb buf %p len %u\n", smb,
  51. server->ops->calc_smb_size(smb, server));
  52. #endif /* CONFIG_CIFS_DEBUG2 */
  53. }
  54. void cifs_dump_mids(struct TCP_Server_Info *server)
  55. {
  56. #ifdef CONFIG_CIFS_DEBUG2
  57. struct list_head *tmp;
  58. struct mid_q_entry *mid_entry;
  59. if (server == NULL)
  60. return;
  61. cifs_dbg(VFS, "Dump pending requests:\n");
  62. spin_lock(&GlobalMid_Lock);
  63. list_for_each(tmp, &server->pending_mid_q) {
  64. mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
  65. cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
  66. mid_entry->mid_state,
  67. le16_to_cpu(mid_entry->command),
  68. mid_entry->pid,
  69. mid_entry->callback_data,
  70. mid_entry->mid);
  71. #ifdef CONFIG_CIFS_STATS2
  72. cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
  73. mid_entry->large_buf,
  74. mid_entry->resp_buf,
  75. mid_entry->when_received,
  76. jiffies);
  77. #endif /* STATS2 */
  78. cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
  79. mid_entry->multiRsp, mid_entry->multiEnd);
  80. if (mid_entry->resp_buf) {
  81. cifs_dump_detail(mid_entry->resp_buf, server);
  82. cifs_dump_mem("existing buf: ",
  83. mid_entry->resp_buf, 62);
  84. }
  85. }
  86. spin_unlock(&GlobalMid_Lock);
  87. #endif /* CONFIG_CIFS_DEBUG2 */
  88. }
  89. #ifdef CONFIG_PROC_FS
  90. static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
  91. {
  92. __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  93. seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count);
  94. if (tcon->nativeFileSystem)
  95. seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
  96. seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
  97. le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  98. le32_to_cpu(tcon->fsAttrInfo.Attributes),
  99. le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  100. tcon->tidStatus);
  101. if (dev_type == FILE_DEVICE_DISK)
  102. seq_puts(m, " type: DISK ");
  103. else if (dev_type == FILE_DEVICE_CD_ROM)
  104. seq_puts(m, " type: CDROM ");
  105. else
  106. seq_printf(m, " type: %d ", dev_type);
  107. if (tcon->seal)
  108. seq_printf(m, " Encrypted");
  109. if (tcon->nocase)
  110. seq_printf(m, " nocase");
  111. if (tcon->unix_ext)
  112. seq_printf(m, " POSIX Extensions");
  113. if (tcon->ses->server->ops->dump_share_caps)
  114. tcon->ses->server->ops->dump_share_caps(m, tcon);
  115. if (tcon->need_reconnect)
  116. seq_puts(m, "\tDISCONNECTED ");
  117. seq_putc(m, '\n');
  118. }
  119. static void
  120. cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
  121. {
  122. struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
  123. struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
  124. seq_printf(m, "\t\tSpeed: %zu bps\n", iface->speed);
  125. seq_puts(m, "\t\tCapabilities: ");
  126. if (iface->rdma_capable)
  127. seq_puts(m, "rdma ");
  128. if (iface->rss_capable)
  129. seq_puts(m, "rss ");
  130. seq_putc(m, '\n');
  131. if (iface->sockaddr.ss_family == AF_INET)
  132. seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
  133. else if (iface->sockaddr.ss_family == AF_INET6)
  134. seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
  135. }
  136. static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
  137. {
  138. struct list_head *tmp1, *tmp2, *tmp3;
  139. struct mid_q_entry *mid_entry;
  140. struct TCP_Server_Info *server;
  141. struct cifs_ses *ses;
  142. struct cifs_tcon *tcon;
  143. int i, j;
  144. seq_puts(m,
  145. "Display Internal CIFS Data Structures for Debugging\n"
  146. "---------------------------------------------------\n");
  147. seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
  148. seq_printf(m, "Features:");
  149. #ifdef CONFIG_CIFS_DFS_UPCALL
  150. seq_printf(m, " dfs");
  151. #endif
  152. #ifdef CONFIG_CIFS_FSCACHE
  153. seq_printf(m, " fscache");
  154. #endif
  155. #ifdef CONFIG_CIFS_WEAK_PW_HASH
  156. seq_printf(m, " lanman");
  157. #endif
  158. #ifdef CONFIG_CIFS_POSIX
  159. seq_printf(m, " posix");
  160. #endif
  161. #ifdef CONFIG_CIFS_UPCALL
  162. seq_printf(m, " spnego");
  163. #endif
  164. #ifdef CONFIG_CIFS_XATTR
  165. seq_printf(m, " xattr");
  166. #endif
  167. #ifdef CONFIG_CIFS_ACL
  168. seq_printf(m, " acl");
  169. #endif
  170. seq_putc(m, '\n');
  171. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  172. seq_printf(m, "Servers:");
  173. i = 0;
  174. spin_lock(&cifs_tcp_ses_lock);
  175. list_for_each(tmp1, &cifs_tcp_ses_list) {
  176. server = list_entry(tmp1, struct TCP_Server_Info,
  177. tcp_ses_list);
  178. #ifdef CONFIG_CIFS_SMB_DIRECT
  179. if (!server->rdma)
  180. goto skip_rdma;
  181. seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
  182. "transport status: %x",
  183. server->smbd_conn->protocol,
  184. server->smbd_conn->transport_status);
  185. seq_printf(m, "\nConn receive_credit_max: %x "
  186. "send_credit_target: %x max_send_size: %x",
  187. server->smbd_conn->receive_credit_max,
  188. server->smbd_conn->send_credit_target,
  189. server->smbd_conn->max_send_size);
  190. seq_printf(m, "\nConn max_fragmented_recv_size: %x "
  191. "max_fragmented_send_size: %x max_receive_size:%x",
  192. server->smbd_conn->max_fragmented_recv_size,
  193. server->smbd_conn->max_fragmented_send_size,
  194. server->smbd_conn->max_receive_size);
  195. seq_printf(m, "\nConn keep_alive_interval: %x "
  196. "max_readwrite_size: %x rdma_readwrite_threshold: %x",
  197. server->smbd_conn->keep_alive_interval,
  198. server->smbd_conn->max_readwrite_size,
  199. server->smbd_conn->rdma_readwrite_threshold);
  200. seq_printf(m, "\nDebug count_get_receive_buffer: %x "
  201. "count_put_receive_buffer: %x count_send_empty: %x",
  202. server->smbd_conn->count_get_receive_buffer,
  203. server->smbd_conn->count_put_receive_buffer,
  204. server->smbd_conn->count_send_empty);
  205. seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
  206. "count_enqueue_reassembly_queue: %x "
  207. "count_dequeue_reassembly_queue: %x "
  208. "fragment_reassembly_remaining: %x "
  209. "reassembly_data_length: %x "
  210. "reassembly_queue_length: %x",
  211. server->smbd_conn->count_reassembly_queue,
  212. server->smbd_conn->count_enqueue_reassembly_queue,
  213. server->smbd_conn->count_dequeue_reassembly_queue,
  214. server->smbd_conn->fragment_reassembly_remaining,
  215. server->smbd_conn->reassembly_data_length,
  216. server->smbd_conn->reassembly_queue_length);
  217. seq_printf(m, "\nCurrent Credits send_credits: %x "
  218. "receive_credits: %x receive_credit_target: %x",
  219. atomic_read(&server->smbd_conn->send_credits),
  220. atomic_read(&server->smbd_conn->receive_credits),
  221. server->smbd_conn->receive_credit_target);
  222. seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
  223. " %x smbd_send_pending: %x smbd_recv_pending: %x",
  224. atomic_read(&server->smbd_conn->send_pending),
  225. atomic_read(&server->smbd_conn->send_payload_pending),
  226. server->smbd_conn->smbd_send_pending,
  227. server->smbd_conn->smbd_recv_pending);
  228. seq_printf(m, "\nReceive buffers count_receive_queue: %x "
  229. "count_empty_packet_queue: %x",
  230. server->smbd_conn->count_receive_queue,
  231. server->smbd_conn->count_empty_packet_queue);
  232. seq_printf(m, "\nMR responder_resources: %x "
  233. "max_frmr_depth: %x mr_type: %x",
  234. server->smbd_conn->responder_resources,
  235. server->smbd_conn->max_frmr_depth,
  236. server->smbd_conn->mr_type);
  237. seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
  238. atomic_read(&server->smbd_conn->mr_ready_count),
  239. atomic_read(&server->smbd_conn->mr_used_count));
  240. skip_rdma:
  241. #endif
  242. seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
  243. server->credits, server->dialect);
  244. if (server->sign)
  245. seq_printf(m, " signed");
  246. #ifdef CONFIG_CIFS_SMB311
  247. if (server->posix_ext_supported)
  248. seq_printf(m, " posix");
  249. #endif /* 3.1.1 */
  250. i++;
  251. list_for_each(tmp2, &server->smb_ses_list) {
  252. ses = list_entry(tmp2, struct cifs_ses,
  253. smb_ses_list);
  254. if ((ses->serverDomain == NULL) ||
  255. (ses->serverOS == NULL) ||
  256. (ses->serverNOS == NULL)) {
  257. seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d\t",
  258. i, ses->serverName, ses->ses_count,
  259. ses->capabilities, ses->status);
  260. if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
  261. seq_printf(m, "Guest\t");
  262. else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
  263. seq_printf(m, "Anonymous\t");
  264. } else {
  265. seq_printf(m,
  266. "\n%d) Name: %s Domain: %s Uses: %d OS:"
  267. " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  268. " session status: %d\t",
  269. i, ses->serverName, ses->serverDomain,
  270. ses->ses_count, ses->serverOS, ses->serverNOS,
  271. ses->capabilities, ses->status);
  272. }
  273. if (server->rdma)
  274. seq_printf(m, "RDMA\n\t");
  275. seq_printf(m, "TCP status: %d\n\tLocal Users To "
  276. "Server: %d SecMode: 0x%x Req On Wire: %d",
  277. server->tcpStatus, server->srv_count,
  278. server->sec_mode, in_flight(server));
  279. #ifdef CONFIG_CIFS_STATS2
  280. seq_printf(m, " In Send: %d In MaxReq Wait: %d",
  281. atomic_read(&server->in_send),
  282. atomic_read(&server->num_waiters));
  283. #endif
  284. seq_puts(m, "\n\tShares:");
  285. j = 0;
  286. seq_printf(m, "\n\t%d) IPC: ", j);
  287. if (ses->tcon_ipc)
  288. cifs_debug_tcon(m, ses->tcon_ipc);
  289. else
  290. seq_puts(m, "none\n");
  291. list_for_each(tmp3, &ses->tcon_list) {
  292. tcon = list_entry(tmp3, struct cifs_tcon,
  293. tcon_list);
  294. ++j;
  295. seq_printf(m, "\n\t%d) ", j);
  296. cifs_debug_tcon(m, tcon);
  297. }
  298. seq_puts(m, "\n\tMIDs:\n");
  299. spin_lock(&GlobalMid_Lock);
  300. list_for_each(tmp3, &server->pending_mid_q) {
  301. mid_entry = list_entry(tmp3, struct mid_q_entry,
  302. qhead);
  303. seq_printf(m, "\tState: %d com: %d pid:"
  304. " %d cbdata: %p mid %llu\n",
  305. mid_entry->mid_state,
  306. le16_to_cpu(mid_entry->command),
  307. mid_entry->pid,
  308. mid_entry->callback_data,
  309. mid_entry->mid);
  310. }
  311. spin_unlock(&GlobalMid_Lock);
  312. spin_lock(&ses->iface_lock);
  313. if (ses->iface_count)
  314. seq_printf(m, "\n\tServer interfaces: %zu\n",
  315. ses->iface_count);
  316. for (j = 0; j < ses->iface_count; j++) {
  317. seq_printf(m, "\t%d)\n", j);
  318. cifs_dump_iface(m, &ses->iface_list[j]);
  319. }
  320. spin_unlock(&ses->iface_lock);
  321. }
  322. }
  323. spin_unlock(&cifs_tcp_ses_lock);
  324. seq_putc(m, '\n');
  325. /* BB add code to dump additional info such as TCP session info now */
  326. return 0;
  327. }
  328. #ifdef CONFIG_CIFS_STATS
  329. static ssize_t cifs_stats_proc_write(struct file *file,
  330. const char __user *buffer, size_t count, loff_t *ppos)
  331. {
  332. bool bv;
  333. int rc;
  334. struct list_head *tmp1, *tmp2, *tmp3;
  335. struct TCP_Server_Info *server;
  336. struct cifs_ses *ses;
  337. struct cifs_tcon *tcon;
  338. rc = kstrtobool_from_user(buffer, count, &bv);
  339. if (rc == 0) {
  340. #ifdef CONFIG_CIFS_STATS2
  341. atomic_set(&totBufAllocCount, 0);
  342. atomic_set(&totSmBufAllocCount, 0);
  343. #endif /* CONFIG_CIFS_STATS2 */
  344. spin_lock(&cifs_tcp_ses_lock);
  345. list_for_each(tmp1, &cifs_tcp_ses_list) {
  346. server = list_entry(tmp1, struct TCP_Server_Info,
  347. tcp_ses_list);
  348. list_for_each(tmp2, &server->smb_ses_list) {
  349. ses = list_entry(tmp2, struct cifs_ses,
  350. smb_ses_list);
  351. list_for_each(tmp3, &ses->tcon_list) {
  352. tcon = list_entry(tmp3,
  353. struct cifs_tcon,
  354. tcon_list);
  355. atomic_set(&tcon->num_smbs_sent, 0);
  356. if (server->ops->clear_stats)
  357. server->ops->clear_stats(tcon);
  358. }
  359. }
  360. }
  361. spin_unlock(&cifs_tcp_ses_lock);
  362. } else {
  363. return rc;
  364. }
  365. return count;
  366. }
  367. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  368. {
  369. int i;
  370. struct list_head *tmp1, *tmp2, *tmp3;
  371. struct TCP_Server_Info *server;
  372. struct cifs_ses *ses;
  373. struct cifs_tcon *tcon;
  374. seq_printf(m,
  375. "Resources in use\nCIFS Session: %d\n",
  376. sesInfoAllocCount.counter);
  377. seq_printf(m, "Share (unique mount targets): %d\n",
  378. tconInfoAllocCount.counter);
  379. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  380. bufAllocCount.counter,
  381. cifs_min_rcv + tcpSesAllocCount.counter);
  382. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  383. smBufAllocCount.counter, cifs_min_small);
  384. #ifdef CONFIG_CIFS_STATS2
  385. seq_printf(m, "Total Large %d Small %d Allocations\n",
  386. atomic_read(&totBufAllocCount),
  387. atomic_read(&totSmBufAllocCount));
  388. #endif /* CONFIG_CIFS_STATS2 */
  389. seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
  390. seq_printf(m,
  391. "\n%d session %d share reconnects\n",
  392. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  393. seq_printf(m,
  394. "Total vfs operations: %d maximum at one time: %d\n",
  395. GlobalCurrentXid, GlobalMaxActiveXid);
  396. i = 0;
  397. spin_lock(&cifs_tcp_ses_lock);
  398. list_for_each(tmp1, &cifs_tcp_ses_list) {
  399. server = list_entry(tmp1, struct TCP_Server_Info,
  400. tcp_ses_list);
  401. list_for_each(tmp2, &server->smb_ses_list) {
  402. ses = list_entry(tmp2, struct cifs_ses,
  403. smb_ses_list);
  404. list_for_each(tmp3, &ses->tcon_list) {
  405. tcon = list_entry(tmp3,
  406. struct cifs_tcon,
  407. tcon_list);
  408. i++;
  409. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  410. if (tcon->need_reconnect)
  411. seq_puts(m, "\tDISCONNECTED ");
  412. seq_printf(m, "\nSMBs: %d",
  413. atomic_read(&tcon->num_smbs_sent));
  414. if (server->ops->print_stats)
  415. server->ops->print_stats(m, tcon);
  416. }
  417. }
  418. }
  419. spin_unlock(&cifs_tcp_ses_lock);
  420. seq_putc(m, '\n');
  421. return 0;
  422. }
  423. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  424. {
  425. return single_open(file, cifs_stats_proc_show, NULL);
  426. }
  427. static const struct file_operations cifs_stats_proc_fops = {
  428. .open = cifs_stats_proc_open,
  429. .read = seq_read,
  430. .llseek = seq_lseek,
  431. .release = single_release,
  432. .write = cifs_stats_proc_write,
  433. };
  434. #endif /* STATS */
  435. #ifdef CONFIG_CIFS_SMB_DIRECT
  436. #define PROC_FILE_DEFINE(name) \
  437. static ssize_t name##_write(struct file *file, const char __user *buffer, \
  438. size_t count, loff_t *ppos) \
  439. { \
  440. int rc; \
  441. rc = kstrtoint_from_user(buffer, count, 10, & name); \
  442. if (rc) \
  443. return rc; \
  444. return count; \
  445. } \
  446. static int name##_proc_show(struct seq_file *m, void *v) \
  447. { \
  448. seq_printf(m, "%d\n", name ); \
  449. return 0; \
  450. } \
  451. static int name##_open(struct inode *inode, struct file *file) \
  452. { \
  453. return single_open(file, name##_proc_show, NULL); \
  454. } \
  455. \
  456. static const struct file_operations cifs_##name##_proc_fops = { \
  457. .open = name##_open, \
  458. .read = seq_read, \
  459. .llseek = seq_lseek, \
  460. .release = single_release, \
  461. .write = name##_write, \
  462. }
  463. PROC_FILE_DEFINE(rdma_readwrite_threshold);
  464. PROC_FILE_DEFINE(smbd_max_frmr_depth);
  465. PROC_FILE_DEFINE(smbd_keep_alive_interval);
  466. PROC_FILE_DEFINE(smbd_max_receive_size);
  467. PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
  468. PROC_FILE_DEFINE(smbd_max_send_size);
  469. PROC_FILE_DEFINE(smbd_send_credit_target);
  470. PROC_FILE_DEFINE(smbd_receive_credit_max);
  471. #endif
  472. static struct proc_dir_entry *proc_fs_cifs;
  473. static const struct file_operations cifsFYI_proc_fops;
  474. static const struct file_operations cifs_lookup_cache_proc_fops;
  475. static const struct file_operations traceSMB_proc_fops;
  476. static const struct file_operations cifs_security_flags_proc_fops;
  477. static const struct file_operations cifs_linux_ext_proc_fops;
  478. void
  479. cifs_proc_init(void)
  480. {
  481. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  482. if (proc_fs_cifs == NULL)
  483. return;
  484. proc_create_single("DebugData", 0, proc_fs_cifs,
  485. cifs_debug_data_proc_show);
  486. #ifdef CONFIG_CIFS_STATS
  487. proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
  488. #endif /* STATS */
  489. proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
  490. proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
  491. proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
  492. &cifs_linux_ext_proc_fops);
  493. proc_create("SecurityFlags", 0644, proc_fs_cifs,
  494. &cifs_security_flags_proc_fops);
  495. proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
  496. &cifs_lookup_cache_proc_fops);
  497. #ifdef CONFIG_CIFS_SMB_DIRECT
  498. proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
  499. &cifs_rdma_readwrite_threshold_proc_fops);
  500. proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
  501. &cifs_smbd_max_frmr_depth_proc_fops);
  502. proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
  503. &cifs_smbd_keep_alive_interval_proc_fops);
  504. proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
  505. &cifs_smbd_max_receive_size_proc_fops);
  506. proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
  507. &cifs_smbd_max_fragmented_recv_size_proc_fops);
  508. proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
  509. &cifs_smbd_max_send_size_proc_fops);
  510. proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
  511. &cifs_smbd_send_credit_target_proc_fops);
  512. proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
  513. &cifs_smbd_receive_credit_max_proc_fops);
  514. #endif
  515. }
  516. void
  517. cifs_proc_clean(void)
  518. {
  519. if (proc_fs_cifs == NULL)
  520. return;
  521. remove_proc_entry("DebugData", proc_fs_cifs);
  522. remove_proc_entry("cifsFYI", proc_fs_cifs);
  523. remove_proc_entry("traceSMB", proc_fs_cifs);
  524. #ifdef CONFIG_CIFS_STATS
  525. remove_proc_entry("Stats", proc_fs_cifs);
  526. #endif
  527. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  528. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  529. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  530. #ifdef CONFIG_CIFS_SMB_DIRECT
  531. remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
  532. remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
  533. remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
  534. remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
  535. remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
  536. remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
  537. remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
  538. remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
  539. #endif
  540. remove_proc_entry("fs/cifs", NULL);
  541. }
  542. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  543. {
  544. seq_printf(m, "%d\n", cifsFYI);
  545. return 0;
  546. }
  547. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  548. {
  549. return single_open(file, cifsFYI_proc_show, NULL);
  550. }
  551. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  552. size_t count, loff_t *ppos)
  553. {
  554. char c[2] = { '\0' };
  555. bool bv;
  556. int rc;
  557. rc = get_user(c[0], buffer);
  558. if (rc)
  559. return rc;
  560. if (strtobool(c, &bv) == 0)
  561. cifsFYI = bv;
  562. else if ((c[0] > '1') && (c[0] <= '9'))
  563. cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
  564. else
  565. return -EINVAL;
  566. return count;
  567. }
  568. static const struct file_operations cifsFYI_proc_fops = {
  569. .open = cifsFYI_proc_open,
  570. .read = seq_read,
  571. .llseek = seq_lseek,
  572. .release = single_release,
  573. .write = cifsFYI_proc_write,
  574. };
  575. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  576. {
  577. seq_printf(m, "%d\n", linuxExtEnabled);
  578. return 0;
  579. }
  580. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  581. {
  582. return single_open(file, cifs_linux_ext_proc_show, NULL);
  583. }
  584. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  585. const char __user *buffer, size_t count, loff_t *ppos)
  586. {
  587. int rc;
  588. rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
  589. if (rc)
  590. return rc;
  591. return count;
  592. }
  593. static const struct file_operations cifs_linux_ext_proc_fops = {
  594. .open = cifs_linux_ext_proc_open,
  595. .read = seq_read,
  596. .llseek = seq_lseek,
  597. .release = single_release,
  598. .write = cifs_linux_ext_proc_write,
  599. };
  600. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  601. {
  602. seq_printf(m, "%d\n", lookupCacheEnabled);
  603. return 0;
  604. }
  605. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  606. {
  607. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  608. }
  609. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  610. const char __user *buffer, size_t count, loff_t *ppos)
  611. {
  612. int rc;
  613. rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
  614. if (rc)
  615. return rc;
  616. return count;
  617. }
  618. static const struct file_operations cifs_lookup_cache_proc_fops = {
  619. .open = cifs_lookup_cache_proc_open,
  620. .read = seq_read,
  621. .llseek = seq_lseek,
  622. .release = single_release,
  623. .write = cifs_lookup_cache_proc_write,
  624. };
  625. static int traceSMB_proc_show(struct seq_file *m, void *v)
  626. {
  627. seq_printf(m, "%d\n", traceSMB);
  628. return 0;
  629. }
  630. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  631. {
  632. return single_open(file, traceSMB_proc_show, NULL);
  633. }
  634. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  635. size_t count, loff_t *ppos)
  636. {
  637. int rc;
  638. rc = kstrtobool_from_user(buffer, count, &traceSMB);
  639. if (rc)
  640. return rc;
  641. return count;
  642. }
  643. static const struct file_operations traceSMB_proc_fops = {
  644. .open = traceSMB_proc_open,
  645. .read = seq_read,
  646. .llseek = seq_lseek,
  647. .release = single_release,
  648. .write = traceSMB_proc_write,
  649. };
  650. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  651. {
  652. seq_printf(m, "0x%x\n", global_secflags);
  653. return 0;
  654. }
  655. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  656. {
  657. return single_open(file, cifs_security_flags_proc_show, NULL);
  658. }
  659. /*
  660. * Ensure that if someone sets a MUST flag, that we disable all other MAY
  661. * flags except for the ones corresponding to the given MUST flag. If there are
  662. * multiple MUST flags, then try to prefer more secure ones.
  663. */
  664. static void
  665. cifs_security_flags_handle_must_flags(unsigned int *flags)
  666. {
  667. unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
  668. if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
  669. *flags = CIFSSEC_MUST_KRB5;
  670. else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
  671. *flags = CIFSSEC_MUST_NTLMSSP;
  672. else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
  673. *flags = CIFSSEC_MUST_NTLMV2;
  674. else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
  675. *flags = CIFSSEC_MUST_NTLM;
  676. else if (CIFSSEC_MUST_LANMAN &&
  677. (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
  678. *flags = CIFSSEC_MUST_LANMAN;
  679. else if (CIFSSEC_MUST_PLNTXT &&
  680. (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
  681. *flags = CIFSSEC_MUST_PLNTXT;
  682. *flags |= signflags;
  683. }
  684. static ssize_t cifs_security_flags_proc_write(struct file *file,
  685. const char __user *buffer, size_t count, loff_t *ppos)
  686. {
  687. int rc;
  688. unsigned int flags;
  689. char flags_string[12];
  690. bool bv;
  691. if ((count < 1) || (count > 11))
  692. return -EINVAL;
  693. memset(flags_string, 0, 12);
  694. if (copy_from_user(flags_string, buffer, count))
  695. return -EFAULT;
  696. if (count < 3) {
  697. /* single char or single char followed by null */
  698. if (strtobool(flags_string, &bv) == 0) {
  699. global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
  700. return count;
  701. } else if (!isdigit(flags_string[0])) {
  702. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
  703. flags_string);
  704. return -EINVAL;
  705. }
  706. }
  707. /* else we have a number */
  708. rc = kstrtouint(flags_string, 0, &flags);
  709. if (rc) {
  710. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
  711. flags_string);
  712. return rc;
  713. }
  714. cifs_dbg(FYI, "sec flags 0x%x\n", flags);
  715. if (flags == 0) {
  716. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
  717. return -EINVAL;
  718. }
  719. if (flags & ~CIFSSEC_MASK) {
  720. cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
  721. flags & ~CIFSSEC_MASK);
  722. return -EINVAL;
  723. }
  724. cifs_security_flags_handle_must_flags(&flags);
  725. /* flags look ok - update the global security flags for cifs module */
  726. global_secflags = flags;
  727. if (global_secflags & CIFSSEC_MUST_SIGN) {
  728. /* requiring signing implies signing is allowed */
  729. global_secflags |= CIFSSEC_MAY_SIGN;
  730. cifs_dbg(FYI, "packet signing now required\n");
  731. } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
  732. cifs_dbg(FYI, "packet signing disabled\n");
  733. }
  734. /* BB should we turn on MAY flags for other MUST options? */
  735. return count;
  736. }
  737. static const struct file_operations cifs_security_flags_proc_fops = {
  738. .open = cifs_security_flags_proc_open,
  739. .read = seq_read,
  740. .llseek = seq_lseek,
  741. .release = single_release,
  742. .write = cifs_security_flags_proc_write,
  743. };
  744. #else
  745. inline void cifs_proc_init(void)
  746. {
  747. }
  748. inline void cifs_proc_clean(void)
  749. {
  750. }
  751. #endif /* PROC_FS */