cifs_debug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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 <asm/uaccess.h>
  28. #include "cifspdu.h"
  29. #include "cifsglob.h"
  30. #include "cifsproto.h"
  31. #include "cifs_debug.h"
  32. #include "cifsfs.h"
  33. void
  34. cifs_dump_mem(char *label, void *data, int length)
  35. {
  36. int i, j;
  37. int *intptr = data;
  38. char *charptr = data;
  39. char buf[10], line[80];
  40. printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
  41. label, length, data);
  42. for (i = 0; i < length; i += 16) {
  43. line[0] = 0;
  44. for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
  45. sprintf(buf, " %08x", intptr[i / 4 + j]);
  46. strcat(line, buf);
  47. }
  48. buf[0] = ' ';
  49. buf[2] = 0;
  50. for (j = 0; (j < 16) && (i + j < length); j++) {
  51. buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
  52. strcat(line, buf);
  53. }
  54. printk(KERN_DEBUG "%s\n", line);
  55. }
  56. }
  57. void cifs_dump_detail(void *buf)
  58. {
  59. #ifdef CONFIG_CIFS_DEBUG2
  60. struct smb_hdr *smb = (struct smb_hdr *)buf;
  61. cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
  62. smb->Command, smb->Status.CifsError,
  63. smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
  64. cERROR(1, "smb buf %p len %d", smb, smbCalcSize(smb));
  65. #endif /* CONFIG_CIFS_DEBUG2 */
  66. }
  67. void cifs_dump_mids(struct TCP_Server_Info *server)
  68. {
  69. #ifdef CONFIG_CIFS_DEBUG2
  70. struct list_head *tmp;
  71. struct mid_q_entry *mid_entry;
  72. if (server == NULL)
  73. return;
  74. cERROR(1, "Dump pending requests:");
  75. spin_lock(&GlobalMid_Lock);
  76. list_for_each(tmp, &server->pending_mid_q) {
  77. mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
  78. cERROR(1, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu",
  79. mid_entry->mid_state,
  80. le16_to_cpu(mid_entry->command),
  81. mid_entry->pid,
  82. mid_entry->callback_data,
  83. mid_entry->mid);
  84. #ifdef CONFIG_CIFS_STATS2
  85. cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld",
  86. mid_entry->large_buf,
  87. mid_entry->resp_buf,
  88. mid_entry->when_received,
  89. jiffies);
  90. #endif /* STATS2 */
  91. cERROR(1, "IsMult: %d IsEnd: %d", mid_entry->multiRsp,
  92. mid_entry->multiEnd);
  93. if (mid_entry->resp_buf) {
  94. cifs_dump_detail(mid_entry->resp_buf);
  95. cifs_dump_mem("existing buf: ",
  96. mid_entry->resp_buf, 62);
  97. }
  98. }
  99. spin_unlock(&GlobalMid_Lock);
  100. #endif /* CONFIG_CIFS_DEBUG2 */
  101. }
  102. #ifdef CONFIG_PROC_FS
  103. static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
  104. {
  105. struct list_head *tmp1, *tmp2, *tmp3;
  106. struct mid_q_entry *mid_entry;
  107. struct TCP_Server_Info *server;
  108. struct cifs_ses *ses;
  109. struct cifs_tcon *tcon;
  110. int i, j;
  111. __u32 dev_type;
  112. seq_puts(m,
  113. "Display Internal CIFS Data Structures for Debugging\n"
  114. "---------------------------------------------------\n");
  115. seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
  116. seq_printf(m, "Features:");
  117. #ifdef CONFIG_CIFS_DFS_UPCALL
  118. seq_printf(m, " dfs");
  119. #endif
  120. #ifdef CONFIG_CIFS_FSCACHE
  121. seq_printf(m, " fscache");
  122. #endif
  123. #ifdef CONFIG_CIFS_WEAK_PW_HASH
  124. seq_printf(m, " lanman");
  125. #endif
  126. #ifdef CONFIG_CIFS_POSIX
  127. seq_printf(m, " posix");
  128. #endif
  129. #ifdef CONFIG_CIFS_UPCALL
  130. seq_printf(m, " spnego");
  131. #endif
  132. #ifdef CONFIG_CIFS_XATTR
  133. seq_printf(m, " xattr");
  134. #endif
  135. #ifdef CONFIG_CIFS_ACL
  136. seq_printf(m, " acl");
  137. #endif
  138. seq_putc(m, '\n');
  139. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  140. seq_printf(m, "Servers:");
  141. i = 0;
  142. spin_lock(&cifs_tcp_ses_lock);
  143. list_for_each(tmp1, &cifs_tcp_ses_list) {
  144. server = list_entry(tmp1, struct TCP_Server_Info,
  145. tcp_ses_list);
  146. i++;
  147. list_for_each(tmp2, &server->smb_ses_list) {
  148. ses = list_entry(tmp2, struct cifs_ses,
  149. smb_ses_list);
  150. if ((ses->serverDomain == NULL) ||
  151. (ses->serverOS == NULL) ||
  152. (ses->serverNOS == NULL)) {
  153. seq_printf(m, "\n%d) entry for %s not fully "
  154. "displayed\n\t", i, ses->serverName);
  155. } else {
  156. seq_printf(m,
  157. "\n%d) Name: %s Domain: %s Uses: %d OS:"
  158. " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  159. " session status: %d\t",
  160. i, ses->serverName, ses->serverDomain,
  161. ses->ses_count, ses->serverOS, ses->serverNOS,
  162. ses->capabilities, ses->status);
  163. }
  164. seq_printf(m, "TCP status: %d\n\tLocal Users To "
  165. "Server: %d SecMode: 0x%x Req On Wire: %d",
  166. server->tcpStatus, server->srv_count,
  167. server->sec_mode, in_flight(server));
  168. #ifdef CONFIG_CIFS_STATS2
  169. seq_printf(m, " In Send: %d In MaxReq Wait: %d",
  170. atomic_read(&server->in_send),
  171. atomic_read(&server->num_waiters));
  172. #endif
  173. seq_puts(m, "\n\tShares:");
  174. j = 0;
  175. list_for_each(tmp3, &ses->tcon_list) {
  176. tcon = list_entry(tmp3, struct cifs_tcon,
  177. tcon_list);
  178. ++j;
  179. dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  180. seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
  181. tcon->treeName, tcon->tc_count);
  182. if (tcon->nativeFileSystem) {
  183. seq_printf(m, "Type: %s ",
  184. tcon->nativeFileSystem);
  185. }
  186. seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
  187. "\nPathComponentMax: %d Status: 0x%d",
  188. le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  189. le32_to_cpu(tcon->fsAttrInfo.Attributes),
  190. le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  191. tcon->tidStatus);
  192. if (dev_type == FILE_DEVICE_DISK)
  193. seq_puts(m, " type: DISK ");
  194. else if (dev_type == FILE_DEVICE_CD_ROM)
  195. seq_puts(m, " type: CDROM ");
  196. else
  197. seq_printf(m, " type: %d ", dev_type);
  198. if (tcon->need_reconnect)
  199. seq_puts(m, "\tDISCONNECTED ");
  200. seq_putc(m, '\n');
  201. }
  202. seq_puts(m, "\n\tMIDs:\n");
  203. spin_lock(&GlobalMid_Lock);
  204. list_for_each(tmp3, &server->pending_mid_q) {
  205. mid_entry = list_entry(tmp3, struct mid_q_entry,
  206. qhead);
  207. seq_printf(m, "\tState: %d com: %d pid:"
  208. " %d cbdata: %p mid %llu\n",
  209. mid_entry->mid_state,
  210. le16_to_cpu(mid_entry->command),
  211. mid_entry->pid,
  212. mid_entry->callback_data,
  213. mid_entry->mid);
  214. }
  215. spin_unlock(&GlobalMid_Lock);
  216. }
  217. }
  218. spin_unlock(&cifs_tcp_ses_lock);
  219. seq_putc(m, '\n');
  220. /* BB add code to dump additional info such as TCP session info now */
  221. return 0;
  222. }
  223. static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
  224. {
  225. return single_open(file, cifs_debug_data_proc_show, NULL);
  226. }
  227. static const struct file_operations cifs_debug_data_proc_fops = {
  228. .owner = THIS_MODULE,
  229. .open = cifs_debug_data_proc_open,
  230. .read = seq_read,
  231. .llseek = seq_lseek,
  232. .release = single_release,
  233. };
  234. #ifdef CONFIG_CIFS_STATS
  235. static ssize_t cifs_stats_proc_write(struct file *file,
  236. const char __user *buffer, size_t count, loff_t *ppos)
  237. {
  238. char c;
  239. int rc;
  240. struct list_head *tmp1, *tmp2, *tmp3;
  241. struct TCP_Server_Info *server;
  242. struct cifs_ses *ses;
  243. struct cifs_tcon *tcon;
  244. rc = get_user(c, buffer);
  245. if (rc)
  246. return rc;
  247. if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
  248. #ifdef CONFIG_CIFS_STATS2
  249. atomic_set(&totBufAllocCount, 0);
  250. atomic_set(&totSmBufAllocCount, 0);
  251. #endif /* CONFIG_CIFS_STATS2 */
  252. spin_lock(&cifs_tcp_ses_lock);
  253. list_for_each(tmp1, &cifs_tcp_ses_list) {
  254. server = list_entry(tmp1, struct TCP_Server_Info,
  255. tcp_ses_list);
  256. list_for_each(tmp2, &server->smb_ses_list) {
  257. ses = list_entry(tmp2, struct cifs_ses,
  258. smb_ses_list);
  259. list_for_each(tmp3, &ses->tcon_list) {
  260. tcon = list_entry(tmp3,
  261. struct cifs_tcon,
  262. tcon_list);
  263. atomic_set(&tcon->num_smbs_sent, 0);
  264. atomic_set(&tcon->num_writes, 0);
  265. atomic_set(&tcon->num_reads, 0);
  266. atomic_set(&tcon->num_oplock_brks, 0);
  267. atomic_set(&tcon->num_opens, 0);
  268. atomic_set(&tcon->num_posixopens, 0);
  269. atomic_set(&tcon->num_posixmkdirs, 0);
  270. atomic_set(&tcon->num_closes, 0);
  271. atomic_set(&tcon->num_deletes, 0);
  272. atomic_set(&tcon->num_mkdirs, 0);
  273. atomic_set(&tcon->num_rmdirs, 0);
  274. atomic_set(&tcon->num_renames, 0);
  275. atomic_set(&tcon->num_t2renames, 0);
  276. atomic_set(&tcon->num_ffirst, 0);
  277. atomic_set(&tcon->num_fnext, 0);
  278. atomic_set(&tcon->num_fclose, 0);
  279. atomic_set(&tcon->num_hardlinks, 0);
  280. atomic_set(&tcon->num_symlinks, 0);
  281. atomic_set(&tcon->num_locks, 0);
  282. }
  283. }
  284. }
  285. spin_unlock(&cifs_tcp_ses_lock);
  286. }
  287. return count;
  288. }
  289. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  290. {
  291. int i;
  292. struct list_head *tmp1, *tmp2, *tmp3;
  293. struct TCP_Server_Info *server;
  294. struct cifs_ses *ses;
  295. struct cifs_tcon *tcon;
  296. seq_printf(m,
  297. "Resources in use\nCIFS Session: %d\n",
  298. sesInfoAllocCount.counter);
  299. seq_printf(m, "Share (unique mount targets): %d\n",
  300. tconInfoAllocCount.counter);
  301. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  302. bufAllocCount.counter,
  303. cifs_min_rcv + tcpSesAllocCount.counter);
  304. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  305. smBufAllocCount.counter, cifs_min_small);
  306. #ifdef CONFIG_CIFS_STATS2
  307. seq_printf(m, "Total Large %d Small %d Allocations\n",
  308. atomic_read(&totBufAllocCount),
  309. atomic_read(&totSmBufAllocCount));
  310. #endif /* CONFIG_CIFS_STATS2 */
  311. seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
  312. seq_printf(m,
  313. "\n%d session %d share reconnects\n",
  314. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  315. seq_printf(m,
  316. "Total vfs operations: %d maximum at one time: %d\n",
  317. GlobalCurrentXid, GlobalMaxActiveXid);
  318. i = 0;
  319. spin_lock(&cifs_tcp_ses_lock);
  320. list_for_each(tmp1, &cifs_tcp_ses_list) {
  321. server = list_entry(tmp1, struct TCP_Server_Info,
  322. tcp_ses_list);
  323. list_for_each(tmp2, &server->smb_ses_list) {
  324. ses = list_entry(tmp2, struct cifs_ses,
  325. smb_ses_list);
  326. list_for_each(tmp3, &ses->tcon_list) {
  327. tcon = list_entry(tmp3,
  328. struct cifs_tcon,
  329. tcon_list);
  330. i++;
  331. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  332. if (tcon->need_reconnect)
  333. seq_puts(m, "\tDISCONNECTED ");
  334. seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
  335. atomic_read(&tcon->num_smbs_sent),
  336. atomic_read(&tcon->num_oplock_brks));
  337. seq_printf(m, "\nReads: %d Bytes: %lld",
  338. atomic_read(&tcon->num_reads),
  339. (long long)(tcon->bytes_read));
  340. seq_printf(m, "\nWrites: %d Bytes: %lld",
  341. atomic_read(&tcon->num_writes),
  342. (long long)(tcon->bytes_written));
  343. seq_printf(m, "\nFlushes: %d",
  344. atomic_read(&tcon->num_flushes));
  345. seq_printf(m, "\nLocks: %d HardLinks: %d "
  346. "Symlinks: %d",
  347. atomic_read(&tcon->num_locks),
  348. atomic_read(&tcon->num_hardlinks),
  349. atomic_read(&tcon->num_symlinks));
  350. seq_printf(m, "\nOpens: %d Closes: %d "
  351. "Deletes: %d",
  352. atomic_read(&tcon->num_opens),
  353. atomic_read(&tcon->num_closes),
  354. atomic_read(&tcon->num_deletes));
  355. seq_printf(m, "\nPosix Opens: %d "
  356. "Posix Mkdirs: %d",
  357. atomic_read(&tcon->num_posixopens),
  358. atomic_read(&tcon->num_posixmkdirs));
  359. seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
  360. atomic_read(&tcon->num_mkdirs),
  361. atomic_read(&tcon->num_rmdirs));
  362. seq_printf(m, "\nRenames: %d T2 Renames %d",
  363. atomic_read(&tcon->num_renames),
  364. atomic_read(&tcon->num_t2renames));
  365. seq_printf(m, "\nFindFirst: %d FNext %d "
  366. "FClose %d",
  367. atomic_read(&tcon->num_ffirst),
  368. atomic_read(&tcon->num_fnext),
  369. atomic_read(&tcon->num_fclose));
  370. }
  371. }
  372. }
  373. spin_unlock(&cifs_tcp_ses_lock);
  374. seq_putc(m, '\n');
  375. return 0;
  376. }
  377. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  378. {
  379. return single_open(file, cifs_stats_proc_show, NULL);
  380. }
  381. static const struct file_operations cifs_stats_proc_fops = {
  382. .owner = THIS_MODULE,
  383. .open = cifs_stats_proc_open,
  384. .read = seq_read,
  385. .llseek = seq_lseek,
  386. .release = single_release,
  387. .write = cifs_stats_proc_write,
  388. };
  389. #endif /* STATS */
  390. static struct proc_dir_entry *proc_fs_cifs;
  391. static const struct file_operations cifsFYI_proc_fops;
  392. static const struct file_operations cifs_lookup_cache_proc_fops;
  393. static const struct file_operations traceSMB_proc_fops;
  394. static const struct file_operations cifs_security_flags_proc_fops;
  395. static const struct file_operations cifs_linux_ext_proc_fops;
  396. void
  397. cifs_proc_init(void)
  398. {
  399. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  400. if (proc_fs_cifs == NULL)
  401. return;
  402. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  403. #ifdef CONFIG_CIFS_STATS
  404. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  405. #endif /* STATS */
  406. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  407. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  408. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  409. &cifs_linux_ext_proc_fops);
  410. proc_create("SecurityFlags", 0, proc_fs_cifs,
  411. &cifs_security_flags_proc_fops);
  412. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  413. &cifs_lookup_cache_proc_fops);
  414. }
  415. void
  416. cifs_proc_clean(void)
  417. {
  418. if (proc_fs_cifs == NULL)
  419. return;
  420. remove_proc_entry("DebugData", proc_fs_cifs);
  421. remove_proc_entry("cifsFYI", proc_fs_cifs);
  422. remove_proc_entry("traceSMB", proc_fs_cifs);
  423. #ifdef CONFIG_CIFS_STATS
  424. remove_proc_entry("Stats", proc_fs_cifs);
  425. #endif
  426. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  427. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  428. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  429. remove_proc_entry("fs/cifs", NULL);
  430. }
  431. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  432. {
  433. seq_printf(m, "%d\n", cifsFYI);
  434. return 0;
  435. }
  436. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  437. {
  438. return single_open(file, cifsFYI_proc_show, NULL);
  439. }
  440. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  441. size_t count, loff_t *ppos)
  442. {
  443. char c;
  444. int rc;
  445. rc = get_user(c, buffer);
  446. if (rc)
  447. return rc;
  448. if (c == '0' || c == 'n' || c == 'N')
  449. cifsFYI = 0;
  450. else if (c == '1' || c == 'y' || c == 'Y')
  451. cifsFYI = 1;
  452. else if ((c > '1') && (c <= '9'))
  453. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  454. return count;
  455. }
  456. static const struct file_operations cifsFYI_proc_fops = {
  457. .owner = THIS_MODULE,
  458. .open = cifsFYI_proc_open,
  459. .read = seq_read,
  460. .llseek = seq_lseek,
  461. .release = single_release,
  462. .write = cifsFYI_proc_write,
  463. };
  464. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  465. {
  466. seq_printf(m, "%d\n", linuxExtEnabled);
  467. return 0;
  468. }
  469. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  470. {
  471. return single_open(file, cifs_linux_ext_proc_show, NULL);
  472. }
  473. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  474. const char __user *buffer, size_t count, loff_t *ppos)
  475. {
  476. char c;
  477. int rc;
  478. rc = get_user(c, buffer);
  479. if (rc)
  480. return rc;
  481. if (c == '0' || c == 'n' || c == 'N')
  482. linuxExtEnabled = 0;
  483. else if (c == '1' || c == 'y' || c == 'Y')
  484. linuxExtEnabled = 1;
  485. return count;
  486. }
  487. static const struct file_operations cifs_linux_ext_proc_fops = {
  488. .owner = THIS_MODULE,
  489. .open = cifs_linux_ext_proc_open,
  490. .read = seq_read,
  491. .llseek = seq_lseek,
  492. .release = single_release,
  493. .write = cifs_linux_ext_proc_write,
  494. };
  495. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  496. {
  497. seq_printf(m, "%d\n", lookupCacheEnabled);
  498. return 0;
  499. }
  500. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  501. {
  502. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  503. }
  504. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  505. const char __user *buffer, size_t count, loff_t *ppos)
  506. {
  507. char c;
  508. int rc;
  509. rc = get_user(c, buffer);
  510. if (rc)
  511. return rc;
  512. if (c == '0' || c == 'n' || c == 'N')
  513. lookupCacheEnabled = 0;
  514. else if (c == '1' || c == 'y' || c == 'Y')
  515. lookupCacheEnabled = 1;
  516. return count;
  517. }
  518. static const struct file_operations cifs_lookup_cache_proc_fops = {
  519. .owner = THIS_MODULE,
  520. .open = cifs_lookup_cache_proc_open,
  521. .read = seq_read,
  522. .llseek = seq_lseek,
  523. .release = single_release,
  524. .write = cifs_lookup_cache_proc_write,
  525. };
  526. static int traceSMB_proc_show(struct seq_file *m, void *v)
  527. {
  528. seq_printf(m, "%d\n", traceSMB);
  529. return 0;
  530. }
  531. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  532. {
  533. return single_open(file, traceSMB_proc_show, NULL);
  534. }
  535. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  536. size_t count, loff_t *ppos)
  537. {
  538. char c;
  539. int rc;
  540. rc = get_user(c, buffer);
  541. if (rc)
  542. return rc;
  543. if (c == '0' || c == 'n' || c == 'N')
  544. traceSMB = 0;
  545. else if (c == '1' || c == 'y' || c == 'Y')
  546. traceSMB = 1;
  547. return count;
  548. }
  549. static const struct file_operations traceSMB_proc_fops = {
  550. .owner = THIS_MODULE,
  551. .open = traceSMB_proc_open,
  552. .read = seq_read,
  553. .llseek = seq_lseek,
  554. .release = single_release,
  555. .write = traceSMB_proc_write,
  556. };
  557. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  558. {
  559. seq_printf(m, "0x%x\n", global_secflags);
  560. return 0;
  561. }
  562. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  563. {
  564. return single_open(file, cifs_security_flags_proc_show, NULL);
  565. }
  566. static ssize_t cifs_security_flags_proc_write(struct file *file,
  567. const char __user *buffer, size_t count, loff_t *ppos)
  568. {
  569. unsigned int flags;
  570. char flags_string[12];
  571. char c;
  572. if ((count < 1) || (count > 11))
  573. return -EINVAL;
  574. memset(flags_string, 0, 12);
  575. if (copy_from_user(flags_string, buffer, count))
  576. return -EFAULT;
  577. if (count < 3) {
  578. /* single char or single char followed by null */
  579. c = flags_string[0];
  580. if (c == '0' || c == 'n' || c == 'N') {
  581. global_secflags = CIFSSEC_DEF; /* default */
  582. return count;
  583. } else if (c == '1' || c == 'y' || c == 'Y') {
  584. global_secflags = CIFSSEC_MAX;
  585. return count;
  586. } else if (!isdigit(c)) {
  587. cERROR(1, "invalid flag %c", c);
  588. return -EINVAL;
  589. }
  590. }
  591. /* else we have a number */
  592. flags = simple_strtoul(flags_string, NULL, 0);
  593. cFYI(1, "sec flags 0x%x", flags);
  594. if (flags <= 0) {
  595. cERROR(1, "invalid security flags %s", flags_string);
  596. return -EINVAL;
  597. }
  598. if (flags & ~CIFSSEC_MASK) {
  599. cERROR(1, "attempt to set unsupported security flags 0x%x",
  600. flags & ~CIFSSEC_MASK);
  601. return -EINVAL;
  602. }
  603. /* flags look ok - update the global security flags for cifs module */
  604. global_secflags = flags;
  605. if (global_secflags & CIFSSEC_MUST_SIGN) {
  606. /* requiring signing implies signing is allowed */
  607. global_secflags |= CIFSSEC_MAY_SIGN;
  608. cFYI(1, "packet signing now required");
  609. } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
  610. cFYI(1, "packet signing disabled");
  611. }
  612. /* BB should we turn on MAY flags for other MUST options? */
  613. return count;
  614. }
  615. static const struct file_operations cifs_security_flags_proc_fops = {
  616. .owner = THIS_MODULE,
  617. .open = cifs_security_flags_proc_open,
  618. .read = seq_read,
  619. .llseek = seq_lseek,
  620. .release = single_release,
  621. .write = cifs_security_flags_proc_write,
  622. };
  623. #else
  624. inline void cifs_proc_init(void)
  625. {
  626. }
  627. inline void cifs_proc_clean(void)
  628. {
  629. }
  630. #endif /* PROC_FS */