cifs_debug.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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. #ifdef CONFIG_CIFS_DEBUG2
  58. void cifs_dump_detail(struct smb_hdr *smb)
  59. {
  60. cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
  61. smb->Command, smb->Status.CifsError,
  62. smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
  63. cERROR(1, "smb buf %p len %d", smb, smbCalcSize_LE(smb));
  64. }
  65. void cifs_dump_mids(struct TCP_Server_Info *server)
  66. {
  67. struct list_head *tmp;
  68. struct mid_q_entry *mid_entry;
  69. if (server == NULL)
  70. return;
  71. cERROR(1, "Dump pending requests:");
  72. spin_lock(&GlobalMid_Lock);
  73. list_for_each(tmp, &server->pending_mid_q) {
  74. mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
  75. cERROR(1, "State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
  76. mid_entry->midState,
  77. (int)mid_entry->command,
  78. mid_entry->pid,
  79. mid_entry->tsk,
  80. mid_entry->mid);
  81. #ifdef CONFIG_CIFS_STATS2
  82. cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld",
  83. mid_entry->largeBuf,
  84. mid_entry->resp_buf,
  85. mid_entry->when_received,
  86. jiffies);
  87. #endif /* STATS2 */
  88. cERROR(1, "IsMult: %d IsEnd: %d", mid_entry->multiRsp,
  89. mid_entry->multiEnd);
  90. if (mid_entry->resp_buf) {
  91. cifs_dump_detail(mid_entry->resp_buf);
  92. cifs_dump_mem("existing buf: ",
  93. mid_entry->resp_buf, 62);
  94. }
  95. }
  96. spin_unlock(&GlobalMid_Lock);
  97. }
  98. #endif /* CONFIG_CIFS_DEBUG2 */
  99. #ifdef CONFIG_PROC_FS
  100. static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
  101. {
  102. struct list_head *tmp1, *tmp2, *tmp3;
  103. struct mid_q_entry *mid_entry;
  104. struct TCP_Server_Info *server;
  105. struct cifsSesInfo *ses;
  106. struct cifsTconInfo *tcon;
  107. int i, j;
  108. __u32 dev_type;
  109. seq_puts(m,
  110. "Display Internal CIFS Data Structures for Debugging\n"
  111. "---------------------------------------------------\n");
  112. seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
  113. seq_printf(m, "Features: ");
  114. #ifdef CONFIG_CIFS_DFS_UPCALL
  115. seq_printf(m, "dfs");
  116. seq_putc(m, ' ');
  117. #endif
  118. #ifdef CONFIG_CIFS_FSCACHE
  119. seq_printf(m, "fscache");
  120. seq_putc(m, ' ');
  121. #endif
  122. #ifdef CONFIG_CIFS_WEAK_PW_HASH
  123. seq_printf(m, "lanman");
  124. seq_putc(m, ' ');
  125. #endif
  126. #ifdef CONFIG_CIFS_POSIX
  127. seq_printf(m, "posix");
  128. seq_putc(m, ' ');
  129. #endif
  130. #ifdef CONFIG_CIFS_UPCALL
  131. seq_printf(m, "spnego");
  132. seq_putc(m, ' ');
  133. #endif
  134. #ifdef CONFIG_CIFS_XATTR
  135. seq_printf(m, "xattr");
  136. #endif
  137. seq_putc(m, '\n');
  138. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  139. seq_printf(m, "Servers:");
  140. i = 0;
  141. read_lock(&cifs_tcp_ses_lock);
  142. list_for_each(tmp1, &cifs_tcp_ses_list) {
  143. server = list_entry(tmp1, struct TCP_Server_Info,
  144. tcp_ses_list);
  145. i++;
  146. list_for_each(tmp2, &server->smb_ses_list) {
  147. ses = list_entry(tmp2, struct cifsSesInfo,
  148. smb_ses_list);
  149. if ((ses->serverDomain == NULL) ||
  150. (ses->serverOS == NULL) ||
  151. (ses->serverNOS == NULL)) {
  152. seq_printf(m, "\n%d) entry for %s not fully "
  153. "displayed\n\t", i, ses->serverName);
  154. } else {
  155. seq_printf(m,
  156. "\n%d) Name: %s Domain: %s Uses: %d OS:"
  157. " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  158. " session status: %d\t",
  159. i, ses->serverName, ses->serverDomain,
  160. ses->ses_count, ses->serverOS, ses->serverNOS,
  161. ses->capabilities, ses->status);
  162. }
  163. seq_printf(m, "TCP status: %d\n\tLocal Users To "
  164. "Server: %d SecMode: 0x%x Req On Wire: %d",
  165. server->tcpStatus, server->srv_count,
  166. server->secMode,
  167. atomic_read(&server->inFlight));
  168. #ifdef CONFIG_CIFS_STATS2
  169. seq_printf(m, " In Send: %d In MaxReq Wait: %d",
  170. atomic_read(&server->inSend),
  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 cifsTconInfo,
  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 tsk: %p mid %d\n",
  209. mid_entry->midState,
  210. (int)mid_entry->command,
  211. mid_entry->pid,
  212. mid_entry->tsk,
  213. mid_entry->mid);
  214. }
  215. spin_unlock(&GlobalMid_Lock);
  216. }
  217. }
  218. read_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 cifsSesInfo *ses;
  243. struct cifsTconInfo *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. read_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 cifsSesInfo,
  258. smb_ses_list);
  259. list_for_each(tmp3, &ses->tcon_list) {
  260. tcon = list_entry(tmp3,
  261. struct cifsTconInfo,
  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. read_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 cifsSesInfo *ses;
  295. struct cifsTconInfo *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", midCount.counter);
  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. read_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 cifsSesInfo,
  325. smb_ses_list);
  326. list_for_each(tmp3, &ses->tcon_list) {
  327. tcon = list_entry(tmp3,
  328. struct cifsTconInfo,
  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. read_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_oplock_proc_fops;
  393. static const struct file_operations cifs_lookup_cache_proc_fops;
  394. static const struct file_operations traceSMB_proc_fops;
  395. static const struct file_operations cifs_multiuser_mount_proc_fops;
  396. static const struct file_operations cifs_security_flags_proc_fops;
  397. static const struct file_operations cifs_experimental_proc_fops;
  398. static const struct file_operations cifs_linux_ext_proc_fops;
  399. void
  400. cifs_proc_init(void)
  401. {
  402. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  403. if (proc_fs_cifs == NULL)
  404. return;
  405. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  406. #ifdef CONFIG_CIFS_STATS
  407. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  408. #endif /* STATS */
  409. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  410. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  411. proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops);
  412. proc_create("Experimental", 0, proc_fs_cifs,
  413. &cifs_experimental_proc_fops);
  414. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  415. &cifs_linux_ext_proc_fops);
  416. proc_create("MultiuserMount", 0, proc_fs_cifs,
  417. &cifs_multiuser_mount_proc_fops);
  418. proc_create("SecurityFlags", 0, proc_fs_cifs,
  419. &cifs_security_flags_proc_fops);
  420. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  421. &cifs_lookup_cache_proc_fops);
  422. }
  423. void
  424. cifs_proc_clean(void)
  425. {
  426. if (proc_fs_cifs == NULL)
  427. return;
  428. remove_proc_entry("DebugData", proc_fs_cifs);
  429. remove_proc_entry("cifsFYI", proc_fs_cifs);
  430. remove_proc_entry("traceSMB", proc_fs_cifs);
  431. #ifdef CONFIG_CIFS_STATS
  432. remove_proc_entry("Stats", proc_fs_cifs);
  433. #endif
  434. remove_proc_entry("MultiuserMount", proc_fs_cifs);
  435. remove_proc_entry("OplockEnabled", proc_fs_cifs);
  436. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  437. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  438. remove_proc_entry("Experimental", proc_fs_cifs);
  439. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  440. remove_proc_entry("fs/cifs", NULL);
  441. }
  442. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  443. {
  444. seq_printf(m, "%d\n", cifsFYI);
  445. return 0;
  446. }
  447. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  448. {
  449. return single_open(file, cifsFYI_proc_show, NULL);
  450. }
  451. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  452. size_t count, loff_t *ppos)
  453. {
  454. char c;
  455. int rc;
  456. rc = get_user(c, buffer);
  457. if (rc)
  458. return rc;
  459. if (c == '0' || c == 'n' || c == 'N')
  460. cifsFYI = 0;
  461. else if (c == '1' || c == 'y' || c == 'Y')
  462. cifsFYI = 1;
  463. else if ((c > '1') && (c <= '9'))
  464. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  465. return count;
  466. }
  467. static const struct file_operations cifsFYI_proc_fops = {
  468. .owner = THIS_MODULE,
  469. .open = cifsFYI_proc_open,
  470. .read = seq_read,
  471. .llseek = seq_lseek,
  472. .release = single_release,
  473. .write = cifsFYI_proc_write,
  474. };
  475. static int cifs_oplock_proc_show(struct seq_file *m, void *v)
  476. {
  477. seq_printf(m, "%d\n", oplockEnabled);
  478. return 0;
  479. }
  480. static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
  481. {
  482. return single_open(file, cifs_oplock_proc_show, NULL);
  483. }
  484. static ssize_t cifs_oplock_proc_write(struct file *file,
  485. const char __user *buffer, size_t count, loff_t *ppos)
  486. {
  487. char c;
  488. int rc;
  489. rc = get_user(c, buffer);
  490. if (rc)
  491. return rc;
  492. if (c == '0' || c == 'n' || c == 'N')
  493. oplockEnabled = 0;
  494. else if (c == '1' || c == 'y' || c == 'Y')
  495. oplockEnabled = 1;
  496. return count;
  497. }
  498. static const struct file_operations cifs_oplock_proc_fops = {
  499. .owner = THIS_MODULE,
  500. .open = cifs_oplock_proc_open,
  501. .read = seq_read,
  502. .llseek = seq_lseek,
  503. .release = single_release,
  504. .write = cifs_oplock_proc_write,
  505. };
  506. static int cifs_experimental_proc_show(struct seq_file *m, void *v)
  507. {
  508. seq_printf(m, "%d\n", experimEnabled);
  509. return 0;
  510. }
  511. static int cifs_experimental_proc_open(struct inode *inode, struct file *file)
  512. {
  513. return single_open(file, cifs_experimental_proc_show, NULL);
  514. }
  515. static ssize_t cifs_experimental_proc_write(struct file *file,
  516. const char __user *buffer, size_t count, loff_t *ppos)
  517. {
  518. char c;
  519. int rc;
  520. rc = get_user(c, buffer);
  521. if (rc)
  522. return rc;
  523. if (c == '0' || c == 'n' || c == 'N')
  524. experimEnabled = 0;
  525. else if (c == '1' || c == 'y' || c == 'Y')
  526. experimEnabled = 1;
  527. else if (c == '2')
  528. experimEnabled = 2;
  529. return count;
  530. }
  531. static const struct file_operations cifs_experimental_proc_fops = {
  532. .owner = THIS_MODULE,
  533. .open = cifs_experimental_proc_open,
  534. .read = seq_read,
  535. .llseek = seq_lseek,
  536. .release = single_release,
  537. .write = cifs_experimental_proc_write,
  538. };
  539. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  540. {
  541. seq_printf(m, "%d\n", linuxExtEnabled);
  542. return 0;
  543. }
  544. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  545. {
  546. return single_open(file, cifs_linux_ext_proc_show, NULL);
  547. }
  548. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  549. const char __user *buffer, size_t count, loff_t *ppos)
  550. {
  551. char c;
  552. int rc;
  553. rc = get_user(c, buffer);
  554. if (rc)
  555. return rc;
  556. if (c == '0' || c == 'n' || c == 'N')
  557. linuxExtEnabled = 0;
  558. else if (c == '1' || c == 'y' || c == 'Y')
  559. linuxExtEnabled = 1;
  560. return count;
  561. }
  562. static const struct file_operations cifs_linux_ext_proc_fops = {
  563. .owner = THIS_MODULE,
  564. .open = cifs_linux_ext_proc_open,
  565. .read = seq_read,
  566. .llseek = seq_lseek,
  567. .release = single_release,
  568. .write = cifs_linux_ext_proc_write,
  569. };
  570. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  571. {
  572. seq_printf(m, "%d\n", lookupCacheEnabled);
  573. return 0;
  574. }
  575. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  576. {
  577. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  578. }
  579. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  580. const char __user *buffer, size_t count, loff_t *ppos)
  581. {
  582. char c;
  583. int rc;
  584. rc = get_user(c, buffer);
  585. if (rc)
  586. return rc;
  587. if (c == '0' || c == 'n' || c == 'N')
  588. lookupCacheEnabled = 0;
  589. else if (c == '1' || c == 'y' || c == 'Y')
  590. lookupCacheEnabled = 1;
  591. return count;
  592. }
  593. static const struct file_operations cifs_lookup_cache_proc_fops = {
  594. .owner = THIS_MODULE,
  595. .open = cifs_lookup_cache_proc_open,
  596. .read = seq_read,
  597. .llseek = seq_lseek,
  598. .release = single_release,
  599. .write = cifs_lookup_cache_proc_write,
  600. };
  601. static int traceSMB_proc_show(struct seq_file *m, void *v)
  602. {
  603. seq_printf(m, "%d\n", traceSMB);
  604. return 0;
  605. }
  606. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  607. {
  608. return single_open(file, traceSMB_proc_show, NULL);
  609. }
  610. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  611. size_t count, loff_t *ppos)
  612. {
  613. char c;
  614. int rc;
  615. rc = get_user(c, buffer);
  616. if (rc)
  617. return rc;
  618. if (c == '0' || c == 'n' || c == 'N')
  619. traceSMB = 0;
  620. else if (c == '1' || c == 'y' || c == 'Y')
  621. traceSMB = 1;
  622. return count;
  623. }
  624. static const struct file_operations traceSMB_proc_fops = {
  625. .owner = THIS_MODULE,
  626. .open = traceSMB_proc_open,
  627. .read = seq_read,
  628. .llseek = seq_lseek,
  629. .release = single_release,
  630. .write = traceSMB_proc_write,
  631. };
  632. static int cifs_multiuser_mount_proc_show(struct seq_file *m, void *v)
  633. {
  634. seq_printf(m, "%d\n", multiuser_mount);
  635. return 0;
  636. }
  637. static int cifs_multiuser_mount_proc_open(struct inode *inode, struct file *fh)
  638. {
  639. return single_open(fh, cifs_multiuser_mount_proc_show, NULL);
  640. }
  641. static ssize_t cifs_multiuser_mount_proc_write(struct file *file,
  642. const char __user *buffer, size_t count, loff_t *ppos)
  643. {
  644. char c;
  645. int rc;
  646. rc = get_user(c, buffer);
  647. if (rc)
  648. return rc;
  649. if (c == '0' || c == 'n' || c == 'N')
  650. multiuser_mount = 0;
  651. else if (c == '1' || c == 'y' || c == 'Y')
  652. multiuser_mount = 1;
  653. return count;
  654. }
  655. static const struct file_operations cifs_multiuser_mount_proc_fops = {
  656. .owner = THIS_MODULE,
  657. .open = cifs_multiuser_mount_proc_open,
  658. .read = seq_read,
  659. .llseek = seq_lseek,
  660. .release = single_release,
  661. .write = cifs_multiuser_mount_proc_write,
  662. };
  663. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  664. {
  665. seq_printf(m, "0x%x\n", global_secflags);
  666. return 0;
  667. }
  668. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  669. {
  670. return single_open(file, cifs_security_flags_proc_show, NULL);
  671. }
  672. static ssize_t cifs_security_flags_proc_write(struct file *file,
  673. const char __user *buffer, size_t count, loff_t *ppos)
  674. {
  675. unsigned int flags;
  676. char flags_string[12];
  677. char c;
  678. if ((count < 1) || (count > 11))
  679. return -EINVAL;
  680. memset(flags_string, 0, 12);
  681. if (copy_from_user(flags_string, buffer, count))
  682. return -EFAULT;
  683. if (count < 3) {
  684. /* single char or single char followed by null */
  685. c = flags_string[0];
  686. if (c == '0' || c == 'n' || c == 'N') {
  687. global_secflags = CIFSSEC_DEF; /* default */
  688. return count;
  689. } else if (c == '1' || c == 'y' || c == 'Y') {
  690. global_secflags = CIFSSEC_MAX;
  691. return count;
  692. } else if (!isdigit(c)) {
  693. cERROR(1, "invalid flag %c", c);
  694. return -EINVAL;
  695. }
  696. }
  697. /* else we have a number */
  698. flags = simple_strtoul(flags_string, NULL, 0);
  699. cFYI(1, "sec flags 0x%x", flags);
  700. if (flags <= 0) {
  701. cERROR(1, "invalid security flags %s", flags_string);
  702. return -EINVAL;
  703. }
  704. if (flags & ~CIFSSEC_MASK) {
  705. cERROR(1, "attempt to set unsupported security flags 0x%x",
  706. flags & ~CIFSSEC_MASK);
  707. return -EINVAL;
  708. }
  709. /* flags look ok - update the global security flags for cifs module */
  710. global_secflags = flags;
  711. if (global_secflags & CIFSSEC_MUST_SIGN) {
  712. /* requiring signing implies signing is allowed */
  713. global_secflags |= CIFSSEC_MAY_SIGN;
  714. cFYI(1, "packet signing now required");
  715. } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
  716. cFYI(1, "packet signing disabled");
  717. }
  718. /* BB should we turn on MAY flags for other MUST options? */
  719. return count;
  720. }
  721. static const struct file_operations cifs_security_flags_proc_fops = {
  722. .owner = THIS_MODULE,
  723. .open = cifs_security_flags_proc_open,
  724. .read = seq_read,
  725. .llseek = seq_lseek,
  726. .release = single_release,
  727. .write = cifs_security_flags_proc_write,
  728. };
  729. #else
  730. inline void cifs_proc_init(void)
  731. {
  732. }
  733. inline void cifs_proc_clean(void)
  734. {
  735. }
  736. #endif /* PROC_FS */