cifs_debug.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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_SMB_DIRECT
  156. seq_printf(m, ",SMB_DIRECT");
  157. #endif
  158. #ifdef CONFIG_CIFS_STATS2
  159. seq_printf(m, ",STATS2");
  160. #else
  161. seq_printf(m, ",STATS");
  162. #endif
  163. #ifdef CONFIG_CIFS_DEBUG2
  164. seq_printf(m, ",DEBUG2");
  165. #elif defined(CONFIG_CIFS_DEBUG)
  166. seq_printf(m, ",DEBUG");
  167. #endif
  168. #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
  169. seq_printf(m, ",ALLOW_INSECURE_LEGACY");
  170. #endif
  171. #ifdef CONFIG_CIFS_WEAK_PW_HASH
  172. seq_printf(m, ",WEAK_PW_HASH");
  173. #endif
  174. #ifdef CONFIG_CIFS_POSIX
  175. seq_printf(m, ",CIFS_POSIX");
  176. #endif
  177. #ifdef CONFIG_CIFS_UPCALL
  178. seq_printf(m, ",UPCALL(SPNEGO)");
  179. #endif
  180. #ifdef CONFIG_CIFS_XATTR
  181. seq_printf(m, ",XATTR");
  182. #endif
  183. #ifdef CONFIG_CIFS_ACL
  184. seq_printf(m, ",ACL");
  185. #endif
  186. seq_putc(m, '\n');
  187. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  188. seq_printf(m, "Servers:");
  189. i = 0;
  190. spin_lock(&cifs_tcp_ses_lock);
  191. list_for_each(tmp1, &cifs_tcp_ses_list) {
  192. server = list_entry(tmp1, struct TCP_Server_Info,
  193. tcp_ses_list);
  194. #ifdef CONFIG_CIFS_SMB_DIRECT
  195. if (!server->rdma)
  196. goto skip_rdma;
  197. if (!server->smbd_conn) {
  198. seq_printf(m, "\nSMBDirect transport not available");
  199. goto skip_rdma;
  200. }
  201. seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
  202. "transport status: %x",
  203. server->smbd_conn->protocol,
  204. server->smbd_conn->transport_status);
  205. seq_printf(m, "\nConn receive_credit_max: %x "
  206. "send_credit_target: %x max_send_size: %x",
  207. server->smbd_conn->receive_credit_max,
  208. server->smbd_conn->send_credit_target,
  209. server->smbd_conn->max_send_size);
  210. seq_printf(m, "\nConn max_fragmented_recv_size: %x "
  211. "max_fragmented_send_size: %x max_receive_size:%x",
  212. server->smbd_conn->max_fragmented_recv_size,
  213. server->smbd_conn->max_fragmented_send_size,
  214. server->smbd_conn->max_receive_size);
  215. seq_printf(m, "\nConn keep_alive_interval: %x "
  216. "max_readwrite_size: %x rdma_readwrite_threshold: %x",
  217. server->smbd_conn->keep_alive_interval,
  218. server->smbd_conn->max_readwrite_size,
  219. server->smbd_conn->rdma_readwrite_threshold);
  220. seq_printf(m, "\nDebug count_get_receive_buffer: %x "
  221. "count_put_receive_buffer: %x count_send_empty: %x",
  222. server->smbd_conn->count_get_receive_buffer,
  223. server->smbd_conn->count_put_receive_buffer,
  224. server->smbd_conn->count_send_empty);
  225. seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
  226. "count_enqueue_reassembly_queue: %x "
  227. "count_dequeue_reassembly_queue: %x "
  228. "fragment_reassembly_remaining: %x "
  229. "reassembly_data_length: %x "
  230. "reassembly_queue_length: %x",
  231. server->smbd_conn->count_reassembly_queue,
  232. server->smbd_conn->count_enqueue_reassembly_queue,
  233. server->smbd_conn->count_dequeue_reassembly_queue,
  234. server->smbd_conn->fragment_reassembly_remaining,
  235. server->smbd_conn->reassembly_data_length,
  236. server->smbd_conn->reassembly_queue_length);
  237. seq_printf(m, "\nCurrent Credits send_credits: %x "
  238. "receive_credits: %x receive_credit_target: %x",
  239. atomic_read(&server->smbd_conn->send_credits),
  240. atomic_read(&server->smbd_conn->receive_credits),
  241. server->smbd_conn->receive_credit_target);
  242. seq_printf(m, "\nPending send_pending: %x send_payload_pending:"
  243. " %x smbd_send_pending: %x smbd_recv_pending: %x",
  244. atomic_read(&server->smbd_conn->send_pending),
  245. atomic_read(&server->smbd_conn->send_payload_pending),
  246. server->smbd_conn->smbd_send_pending,
  247. server->smbd_conn->smbd_recv_pending);
  248. seq_printf(m, "\nReceive buffers count_receive_queue: %x "
  249. "count_empty_packet_queue: %x",
  250. server->smbd_conn->count_receive_queue,
  251. server->smbd_conn->count_empty_packet_queue);
  252. seq_printf(m, "\nMR responder_resources: %x "
  253. "max_frmr_depth: %x mr_type: %x",
  254. server->smbd_conn->responder_resources,
  255. server->smbd_conn->max_frmr_depth,
  256. server->smbd_conn->mr_type);
  257. seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
  258. atomic_read(&server->smbd_conn->mr_ready_count),
  259. atomic_read(&server->smbd_conn->mr_used_count));
  260. skip_rdma:
  261. #endif
  262. seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
  263. server->credits, server->dialect);
  264. if (server->sign)
  265. seq_printf(m, " signed");
  266. if (server->posix_ext_supported)
  267. seq_printf(m, " posix");
  268. i++;
  269. list_for_each(tmp2, &server->smb_ses_list) {
  270. ses = list_entry(tmp2, struct cifs_ses,
  271. smb_ses_list);
  272. if ((ses->serverDomain == NULL) ||
  273. (ses->serverOS == NULL) ||
  274. (ses->serverNOS == NULL)) {
  275. seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d\t",
  276. i, ses->serverName, ses->ses_count,
  277. ses->capabilities, ses->status);
  278. if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
  279. seq_printf(m, "Guest\t");
  280. else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
  281. seq_printf(m, "Anonymous\t");
  282. } else {
  283. seq_printf(m,
  284. "\n%d) Name: %s Domain: %s Uses: %d OS:"
  285. " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  286. " session status: %d\t",
  287. i, ses->serverName, ses->serverDomain,
  288. ses->ses_count, ses->serverOS, ses->serverNOS,
  289. ses->capabilities, ses->status);
  290. }
  291. if (server->rdma)
  292. seq_printf(m, "RDMA\n\t");
  293. seq_printf(m, "TCP status: %d\n\tLocal Users To "
  294. "Server: %d SecMode: 0x%x Req On Wire: %d",
  295. server->tcpStatus, server->srv_count,
  296. server->sec_mode, in_flight(server));
  297. #ifdef CONFIG_CIFS_STATS2
  298. seq_printf(m, " In Send: %d In MaxReq Wait: %d",
  299. atomic_read(&server->in_send),
  300. atomic_read(&server->num_waiters));
  301. #endif
  302. seq_puts(m, "\n\tShares:");
  303. j = 0;
  304. seq_printf(m, "\n\t%d) IPC: ", j);
  305. if (ses->tcon_ipc)
  306. cifs_debug_tcon(m, ses->tcon_ipc);
  307. else
  308. seq_puts(m, "none\n");
  309. list_for_each(tmp3, &ses->tcon_list) {
  310. tcon = list_entry(tmp3, struct cifs_tcon,
  311. tcon_list);
  312. ++j;
  313. seq_printf(m, "\n\t%d) ", j);
  314. cifs_debug_tcon(m, tcon);
  315. }
  316. seq_puts(m, "\n\tMIDs:\n");
  317. spin_lock(&GlobalMid_Lock);
  318. list_for_each(tmp3, &server->pending_mid_q) {
  319. mid_entry = list_entry(tmp3, struct mid_q_entry,
  320. qhead);
  321. seq_printf(m, "\tState: %d com: %d pid:"
  322. " %d cbdata: %p mid %llu\n",
  323. mid_entry->mid_state,
  324. le16_to_cpu(mid_entry->command),
  325. mid_entry->pid,
  326. mid_entry->callback_data,
  327. mid_entry->mid);
  328. }
  329. spin_unlock(&GlobalMid_Lock);
  330. spin_lock(&ses->iface_lock);
  331. if (ses->iface_count)
  332. seq_printf(m, "\n\tServer interfaces: %zu\n",
  333. ses->iface_count);
  334. for (j = 0; j < ses->iface_count; j++) {
  335. seq_printf(m, "\t%d)\n", j);
  336. cifs_dump_iface(m, &ses->iface_list[j]);
  337. }
  338. spin_unlock(&ses->iface_lock);
  339. }
  340. }
  341. spin_unlock(&cifs_tcp_ses_lock);
  342. seq_putc(m, '\n');
  343. /* BB add code to dump additional info such as TCP session info now */
  344. return 0;
  345. }
  346. static ssize_t cifs_stats_proc_write(struct file *file,
  347. const char __user *buffer, size_t count, loff_t *ppos)
  348. {
  349. bool bv;
  350. int rc;
  351. struct list_head *tmp1, *tmp2, *tmp3;
  352. struct TCP_Server_Info *server;
  353. struct cifs_ses *ses;
  354. struct cifs_tcon *tcon;
  355. rc = kstrtobool_from_user(buffer, count, &bv);
  356. if (rc == 0) {
  357. #ifdef CONFIG_CIFS_STATS2
  358. int i;
  359. atomic_set(&totBufAllocCount, 0);
  360. atomic_set(&totSmBufAllocCount, 0);
  361. #endif /* CONFIG_CIFS_STATS2 */
  362. atomic_set(&tcpSesReconnectCount, 0);
  363. atomic_set(&tconInfoReconnectCount, 0);
  364. spin_lock(&GlobalMid_Lock);
  365. GlobalMaxActiveXid = 0;
  366. GlobalCurrentXid = 0;
  367. spin_unlock(&GlobalMid_Lock);
  368. spin_lock(&cifs_tcp_ses_lock);
  369. list_for_each(tmp1, &cifs_tcp_ses_list) {
  370. server = list_entry(tmp1, struct TCP_Server_Info,
  371. tcp_ses_list);
  372. #ifdef CONFIG_CIFS_STATS2
  373. for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++)
  374. atomic_set(&server->smb2slowcmd[i], 0);
  375. #endif /* CONFIG_CIFS_STATS2 */
  376. list_for_each(tmp2, &server->smb_ses_list) {
  377. ses = list_entry(tmp2, struct cifs_ses,
  378. smb_ses_list);
  379. list_for_each(tmp3, &ses->tcon_list) {
  380. tcon = list_entry(tmp3,
  381. struct cifs_tcon,
  382. tcon_list);
  383. atomic_set(&tcon->num_smbs_sent, 0);
  384. spin_lock(&tcon->stat_lock);
  385. tcon->bytes_read = 0;
  386. tcon->bytes_written = 0;
  387. spin_unlock(&tcon->stat_lock);
  388. if (server->ops->clear_stats)
  389. server->ops->clear_stats(tcon);
  390. }
  391. }
  392. }
  393. spin_unlock(&cifs_tcp_ses_lock);
  394. } else {
  395. return rc;
  396. }
  397. return count;
  398. }
  399. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  400. {
  401. int i;
  402. #ifdef CONFIG_CIFS_STATS2
  403. int j;
  404. #endif /* STATS2 */
  405. struct list_head *tmp1, *tmp2, *tmp3;
  406. struct TCP_Server_Info *server;
  407. struct cifs_ses *ses;
  408. struct cifs_tcon *tcon;
  409. seq_printf(m, "Resources in use\nCIFS Session: %d\n",
  410. sesInfoAllocCount.counter);
  411. seq_printf(m, "Share (unique mount targets): %d\n",
  412. tconInfoAllocCount.counter);
  413. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  414. bufAllocCount.counter,
  415. cifs_min_rcv + tcpSesAllocCount.counter);
  416. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  417. smBufAllocCount.counter, cifs_min_small);
  418. #ifdef CONFIG_CIFS_STATS2
  419. seq_printf(m, "Total Large %d Small %d Allocations\n",
  420. atomic_read(&totBufAllocCount),
  421. atomic_read(&totSmBufAllocCount));
  422. #endif /* CONFIG_CIFS_STATS2 */
  423. seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
  424. seq_printf(m,
  425. "\n%d session %d share reconnects\n",
  426. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  427. seq_printf(m,
  428. "Total vfs operations: %d maximum at one time: %d\n",
  429. GlobalCurrentXid, GlobalMaxActiveXid);
  430. i = 0;
  431. spin_lock(&cifs_tcp_ses_lock);
  432. list_for_each(tmp1, &cifs_tcp_ses_list) {
  433. server = list_entry(tmp1, struct TCP_Server_Info,
  434. tcp_ses_list);
  435. #ifdef CONFIG_CIFS_STATS2
  436. for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
  437. if (atomic_read(&server->smb2slowcmd[j]))
  438. seq_printf(m, "%d slow responses from %s for command %d\n",
  439. atomic_read(&server->smb2slowcmd[j]),
  440. server->hostname, j);
  441. #endif /* STATS2 */
  442. list_for_each(tmp2, &server->smb_ses_list) {
  443. ses = list_entry(tmp2, struct cifs_ses,
  444. smb_ses_list);
  445. list_for_each(tmp3, &ses->tcon_list) {
  446. tcon = list_entry(tmp3,
  447. struct cifs_tcon,
  448. tcon_list);
  449. i++;
  450. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  451. if (tcon->need_reconnect)
  452. seq_puts(m, "\tDISCONNECTED ");
  453. seq_printf(m, "\nSMBs: %d",
  454. atomic_read(&tcon->num_smbs_sent));
  455. if (server->ops->print_stats)
  456. server->ops->print_stats(m, tcon);
  457. }
  458. }
  459. }
  460. spin_unlock(&cifs_tcp_ses_lock);
  461. seq_putc(m, '\n');
  462. return 0;
  463. }
  464. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  465. {
  466. return single_open(file, cifs_stats_proc_show, NULL);
  467. }
  468. static const struct file_operations cifs_stats_proc_fops = {
  469. .open = cifs_stats_proc_open,
  470. .read = seq_read,
  471. .llseek = seq_lseek,
  472. .release = single_release,
  473. .write = cifs_stats_proc_write,
  474. };
  475. #ifdef CONFIG_CIFS_SMB_DIRECT
  476. #define PROC_FILE_DEFINE(name) \
  477. static ssize_t name##_write(struct file *file, const char __user *buffer, \
  478. size_t count, loff_t *ppos) \
  479. { \
  480. int rc; \
  481. rc = kstrtoint_from_user(buffer, count, 10, & name); \
  482. if (rc) \
  483. return rc; \
  484. return count; \
  485. } \
  486. static int name##_proc_show(struct seq_file *m, void *v) \
  487. { \
  488. seq_printf(m, "%d\n", name ); \
  489. return 0; \
  490. } \
  491. static int name##_open(struct inode *inode, struct file *file) \
  492. { \
  493. return single_open(file, name##_proc_show, NULL); \
  494. } \
  495. \
  496. static const struct file_operations cifs_##name##_proc_fops = { \
  497. .open = name##_open, \
  498. .read = seq_read, \
  499. .llseek = seq_lseek, \
  500. .release = single_release, \
  501. .write = name##_write, \
  502. }
  503. PROC_FILE_DEFINE(rdma_readwrite_threshold);
  504. PROC_FILE_DEFINE(smbd_max_frmr_depth);
  505. PROC_FILE_DEFINE(smbd_keep_alive_interval);
  506. PROC_FILE_DEFINE(smbd_max_receive_size);
  507. PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
  508. PROC_FILE_DEFINE(smbd_max_send_size);
  509. PROC_FILE_DEFINE(smbd_send_credit_target);
  510. PROC_FILE_DEFINE(smbd_receive_credit_max);
  511. #endif
  512. static struct proc_dir_entry *proc_fs_cifs;
  513. static const struct file_operations cifsFYI_proc_fops;
  514. static const struct file_operations cifs_lookup_cache_proc_fops;
  515. static const struct file_operations traceSMB_proc_fops;
  516. static const struct file_operations cifs_security_flags_proc_fops;
  517. static const struct file_operations cifs_linux_ext_proc_fops;
  518. void
  519. cifs_proc_init(void)
  520. {
  521. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  522. if (proc_fs_cifs == NULL)
  523. return;
  524. proc_create_single("DebugData", 0, proc_fs_cifs,
  525. cifs_debug_data_proc_show);
  526. proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
  527. proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
  528. proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
  529. proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
  530. &cifs_linux_ext_proc_fops);
  531. proc_create("SecurityFlags", 0644, proc_fs_cifs,
  532. &cifs_security_flags_proc_fops);
  533. proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
  534. &cifs_lookup_cache_proc_fops);
  535. #ifdef CONFIG_CIFS_SMB_DIRECT
  536. proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
  537. &cifs_rdma_readwrite_threshold_proc_fops);
  538. proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
  539. &cifs_smbd_max_frmr_depth_proc_fops);
  540. proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
  541. &cifs_smbd_keep_alive_interval_proc_fops);
  542. proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
  543. &cifs_smbd_max_receive_size_proc_fops);
  544. proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
  545. &cifs_smbd_max_fragmented_recv_size_proc_fops);
  546. proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
  547. &cifs_smbd_max_send_size_proc_fops);
  548. proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
  549. &cifs_smbd_send_credit_target_proc_fops);
  550. proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
  551. &cifs_smbd_receive_credit_max_proc_fops);
  552. #endif
  553. }
  554. void
  555. cifs_proc_clean(void)
  556. {
  557. if (proc_fs_cifs == NULL)
  558. return;
  559. remove_proc_entry("DebugData", proc_fs_cifs);
  560. remove_proc_entry("cifsFYI", proc_fs_cifs);
  561. remove_proc_entry("traceSMB", proc_fs_cifs);
  562. remove_proc_entry("Stats", proc_fs_cifs);
  563. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  564. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  565. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  566. #ifdef CONFIG_CIFS_SMB_DIRECT
  567. remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
  568. remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
  569. remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
  570. remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
  571. remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
  572. remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
  573. remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
  574. remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
  575. #endif
  576. remove_proc_entry("fs/cifs", NULL);
  577. }
  578. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  579. {
  580. seq_printf(m, "%d\n", cifsFYI);
  581. return 0;
  582. }
  583. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  584. {
  585. return single_open(file, cifsFYI_proc_show, NULL);
  586. }
  587. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  588. size_t count, loff_t *ppos)
  589. {
  590. char c[2] = { '\0' };
  591. bool bv;
  592. int rc;
  593. rc = get_user(c[0], buffer);
  594. if (rc)
  595. return rc;
  596. if (strtobool(c, &bv) == 0)
  597. cifsFYI = bv;
  598. else if ((c[0] > '1') && (c[0] <= '9'))
  599. cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
  600. else
  601. return -EINVAL;
  602. return count;
  603. }
  604. static const struct file_operations cifsFYI_proc_fops = {
  605. .open = cifsFYI_proc_open,
  606. .read = seq_read,
  607. .llseek = seq_lseek,
  608. .release = single_release,
  609. .write = cifsFYI_proc_write,
  610. };
  611. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  612. {
  613. seq_printf(m, "%d\n", linuxExtEnabled);
  614. return 0;
  615. }
  616. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  617. {
  618. return single_open(file, cifs_linux_ext_proc_show, NULL);
  619. }
  620. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  621. const char __user *buffer, size_t count, loff_t *ppos)
  622. {
  623. int rc;
  624. rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
  625. if (rc)
  626. return rc;
  627. return count;
  628. }
  629. static const struct file_operations cifs_linux_ext_proc_fops = {
  630. .open = cifs_linux_ext_proc_open,
  631. .read = seq_read,
  632. .llseek = seq_lseek,
  633. .release = single_release,
  634. .write = cifs_linux_ext_proc_write,
  635. };
  636. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  637. {
  638. seq_printf(m, "%d\n", lookupCacheEnabled);
  639. return 0;
  640. }
  641. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  642. {
  643. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  644. }
  645. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  646. const char __user *buffer, size_t count, loff_t *ppos)
  647. {
  648. int rc;
  649. rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
  650. if (rc)
  651. return rc;
  652. return count;
  653. }
  654. static const struct file_operations cifs_lookup_cache_proc_fops = {
  655. .open = cifs_lookup_cache_proc_open,
  656. .read = seq_read,
  657. .llseek = seq_lseek,
  658. .release = single_release,
  659. .write = cifs_lookup_cache_proc_write,
  660. };
  661. static int traceSMB_proc_show(struct seq_file *m, void *v)
  662. {
  663. seq_printf(m, "%d\n", traceSMB);
  664. return 0;
  665. }
  666. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  667. {
  668. return single_open(file, traceSMB_proc_show, NULL);
  669. }
  670. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  671. size_t count, loff_t *ppos)
  672. {
  673. int rc;
  674. rc = kstrtobool_from_user(buffer, count, &traceSMB);
  675. if (rc)
  676. return rc;
  677. return count;
  678. }
  679. static const struct file_operations traceSMB_proc_fops = {
  680. .open = traceSMB_proc_open,
  681. .read = seq_read,
  682. .llseek = seq_lseek,
  683. .release = single_release,
  684. .write = traceSMB_proc_write,
  685. };
  686. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  687. {
  688. seq_printf(m, "0x%x\n", global_secflags);
  689. return 0;
  690. }
  691. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  692. {
  693. return single_open(file, cifs_security_flags_proc_show, NULL);
  694. }
  695. /*
  696. * Ensure that if someone sets a MUST flag, that we disable all other MAY
  697. * flags except for the ones corresponding to the given MUST flag. If there are
  698. * multiple MUST flags, then try to prefer more secure ones.
  699. */
  700. static void
  701. cifs_security_flags_handle_must_flags(unsigned int *flags)
  702. {
  703. unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
  704. if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
  705. *flags = CIFSSEC_MUST_KRB5;
  706. else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
  707. *flags = CIFSSEC_MUST_NTLMSSP;
  708. else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
  709. *flags = CIFSSEC_MUST_NTLMV2;
  710. else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
  711. *flags = CIFSSEC_MUST_NTLM;
  712. else if (CIFSSEC_MUST_LANMAN &&
  713. (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
  714. *flags = CIFSSEC_MUST_LANMAN;
  715. else if (CIFSSEC_MUST_PLNTXT &&
  716. (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
  717. *flags = CIFSSEC_MUST_PLNTXT;
  718. *flags |= signflags;
  719. }
  720. static ssize_t cifs_security_flags_proc_write(struct file *file,
  721. const char __user *buffer, size_t count, loff_t *ppos)
  722. {
  723. int rc;
  724. unsigned int flags;
  725. char flags_string[12];
  726. bool bv;
  727. if ((count < 1) || (count > 11))
  728. return -EINVAL;
  729. memset(flags_string, 0, 12);
  730. if (copy_from_user(flags_string, buffer, count))
  731. return -EFAULT;
  732. if (count < 3) {
  733. /* single char or single char followed by null */
  734. if (strtobool(flags_string, &bv) == 0) {
  735. global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
  736. return count;
  737. } else if (!isdigit(flags_string[0])) {
  738. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
  739. flags_string);
  740. return -EINVAL;
  741. }
  742. }
  743. /* else we have a number */
  744. rc = kstrtouint(flags_string, 0, &flags);
  745. if (rc) {
  746. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
  747. flags_string);
  748. return rc;
  749. }
  750. cifs_dbg(FYI, "sec flags 0x%x\n", flags);
  751. if (flags == 0) {
  752. cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
  753. return -EINVAL;
  754. }
  755. if (flags & ~CIFSSEC_MASK) {
  756. cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
  757. flags & ~CIFSSEC_MASK);
  758. return -EINVAL;
  759. }
  760. cifs_security_flags_handle_must_flags(&flags);
  761. /* flags look ok - update the global security flags for cifs module */
  762. global_secflags = flags;
  763. if (global_secflags & CIFSSEC_MUST_SIGN) {
  764. /* requiring signing implies signing is allowed */
  765. global_secflags |= CIFSSEC_MAY_SIGN;
  766. cifs_dbg(FYI, "packet signing now required\n");
  767. } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
  768. cifs_dbg(FYI, "packet signing disabled\n");
  769. }
  770. /* BB should we turn on MAY flags for other MUST options? */
  771. return count;
  772. }
  773. static const struct file_operations cifs_security_flags_proc_fops = {
  774. .open = cifs_security_flags_proc_open,
  775. .read = seq_read,
  776. .llseek = seq_lseek,
  777. .release = single_release,
  778. .write = cifs_security_flags_proc_write,
  779. };
  780. #else
  781. inline void cifs_proc_init(void)
  782. {
  783. }
  784. inline void cifs_proc_clean(void)
  785. {
  786. }
  787. #endif /* PROC_FS */