root/fs/cifs/cifs_debug.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cifs_dump_mem
  2. cifs_dump_detail
  3. cifs_dump_mids
  4. cifs_debug_tcon
  5. cifs_dump_iface
  6. cifs_debug_files_proc_show
  7. cifs_debug_data_proc_show
  8. cifs_stats_proc_write
  9. cifs_stats_proc_show
  10. cifs_stats_proc_open
  11. cifs_proc_init
  12. cifs_proc_clean
  13. cifsFYI_proc_show
  14. cifsFYI_proc_open
  15. cifsFYI_proc_write
  16. cifs_linux_ext_proc_show
  17. cifs_linux_ext_proc_open
  18. cifs_linux_ext_proc_write
  19. cifs_lookup_cache_proc_show
  20. cifs_lookup_cache_proc_open
  21. cifs_lookup_cache_proc_write
  22. traceSMB_proc_show
  23. traceSMB_proc_open
  24. traceSMB_proc_write
  25. cifs_security_flags_proc_show
  26. cifs_security_flags_proc_open
  27. cifs_security_flags_handle_must_flags
  28. cifs_security_flags_proc_write
  29. cifs_proc_init
  30. cifs_proc_clean

   1 // SPDX-License-Identifier: GPL-2.0-or-later
   2 /*
   3  *   fs/cifs_debug.c
   4  *
   5  *   Copyright (C) International Business Machines  Corp., 2000,2005
   6  *
   7  *   Modified by Steve French (sfrench@us.ibm.com)
   8  */
   9 #include <linux/fs.h>
  10 #include <linux/string.h>
  11 #include <linux/ctype.h>
  12 #include <linux/module.h>
  13 #include <linux/proc_fs.h>
  14 #include <linux/uaccess.h>
  15 #include "cifspdu.h"
  16 #include "cifsglob.h"
  17 #include "cifsproto.h"
  18 #include "cifs_debug.h"
  19 #include "cifsfs.h"
  20 #ifdef CONFIG_CIFS_DFS_UPCALL
  21 #include "dfs_cache.h"
  22 #endif
  23 #ifdef CONFIG_CIFS_SMB_DIRECT
  24 #include "smbdirect.h"
  25 #endif
  26 
  27 void
  28 cifs_dump_mem(char *label, void *data, int length)
  29 {
  30         pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
  31         print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
  32                        data, length, true);
  33 }
  34 
  35 void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
  36 {
  37 #ifdef CONFIG_CIFS_DEBUG2
  38         struct smb_hdr *smb = (struct smb_hdr *)buf;
  39 
  40         cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
  41                  smb->Command, smb->Status.CifsError,
  42                  smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
  43         cifs_dbg(VFS, "smb buf %p len %u\n", smb,
  44                  server->ops->calc_smb_size(smb, server));
  45 #endif /* CONFIG_CIFS_DEBUG2 */
  46 }
  47 
  48 void cifs_dump_mids(struct TCP_Server_Info *server)
  49 {
  50 #ifdef CONFIG_CIFS_DEBUG2
  51         struct list_head *tmp;
  52         struct mid_q_entry *mid_entry;
  53 
  54         if (server == NULL)
  55                 return;
  56 
  57         cifs_dbg(VFS, "Dump pending requests:\n");
  58         spin_lock(&GlobalMid_Lock);
  59         list_for_each(tmp, &server->pending_mid_q) {
  60                 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
  61                 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
  62                          mid_entry->mid_state,
  63                          le16_to_cpu(mid_entry->command),
  64                          mid_entry->pid,
  65                          mid_entry->callback_data,
  66                          mid_entry->mid);
  67 #ifdef CONFIG_CIFS_STATS2
  68                 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
  69                          mid_entry->large_buf,
  70                          mid_entry->resp_buf,
  71                          mid_entry->when_received,
  72                          jiffies);
  73 #endif /* STATS2 */
  74                 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
  75                          mid_entry->multiRsp, mid_entry->multiEnd);
  76                 if (mid_entry->resp_buf) {
  77                         cifs_dump_detail(mid_entry->resp_buf, server);
  78                         cifs_dump_mem("existing buf: ",
  79                                 mid_entry->resp_buf, 62);
  80                 }
  81         }
  82         spin_unlock(&GlobalMid_Lock);
  83 #endif /* CONFIG_CIFS_DEBUG2 */
  84 }
  85 
  86 #ifdef CONFIG_PROC_FS
  87 static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
  88 {
  89         __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  90 
  91         seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count);
  92         if (tcon->nativeFileSystem)
  93                 seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
  94         seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
  95                    le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  96                    le32_to_cpu(tcon->fsAttrInfo.Attributes),
  97                    le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  98                    tcon->tidStatus);
  99         if (dev_type == FILE_DEVICE_DISK)
 100                 seq_puts(m, " type: DISK ");
 101         else if (dev_type == FILE_DEVICE_CD_ROM)
 102                 seq_puts(m, " type: CDROM ");
 103         else
 104                 seq_printf(m, " type: %d ", dev_type);
 105 
 106         seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
 107 
 108         if ((tcon->seal) ||
 109             (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
 110             (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
 111                 seq_printf(m, " Encrypted");
 112         if (tcon->nocase)
 113                 seq_printf(m, " nocase");
 114         if (tcon->unix_ext)
 115                 seq_printf(m, " POSIX Extensions");
 116         if (tcon->ses->server->ops->dump_share_caps)
 117                 tcon->ses->server->ops->dump_share_caps(m, tcon);
 118 
 119         if (tcon->need_reconnect)
 120                 seq_puts(m, "\tDISCONNECTED ");
 121         seq_putc(m, '\n');
 122 }
 123 
 124 static void
 125 cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
 126 {
 127         struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
 128         struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
 129 
 130         seq_printf(m, "\tSpeed: %zu bps\n", iface->speed);
 131         seq_puts(m, "\t\tCapabilities: ");
 132         if (iface->rdma_capable)
 133                 seq_puts(m, "rdma ");
 134         if (iface->rss_capable)
 135                 seq_puts(m, "rss ");
 136         seq_putc(m, '\n');
 137         if (iface->sockaddr.ss_family == AF_INET)
 138                 seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
 139         else if (iface->sockaddr.ss_family == AF_INET6)
 140                 seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
 141 }
 142 
 143 static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
 144 {
 145         struct list_head *stmp, *tmp, *tmp1, *tmp2;
 146         struct TCP_Server_Info *server;
 147         struct cifs_ses *ses;
 148         struct cifs_tcon *tcon;
 149         struct cifsFileInfo *cfile;
 150 
 151         seq_puts(m, "# Version:1\n");
 152         seq_puts(m, "# Format:\n");
 153         seq_puts(m, "# <tree id> <persistent fid> <flags> <count> <pid> <uid>");
 154 #ifdef CONFIG_CIFS_DEBUG2
 155         seq_printf(m, " <filename> <mid>\n");
 156 #else
 157         seq_printf(m, " <filename>\n");
 158 #endif /* CIFS_DEBUG2 */
 159         spin_lock(&cifs_tcp_ses_lock);
 160         list_for_each(stmp, &cifs_tcp_ses_list) {
 161                 server = list_entry(stmp, struct TCP_Server_Info,
 162                                     tcp_ses_list);
 163                 list_for_each(tmp, &server->smb_ses_list) {
 164                         ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
 165                         list_for_each(tmp1, &ses->tcon_list) {
 166                                 tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
 167                                 spin_lock(&tcon->open_file_lock);
 168                                 list_for_each(tmp2, &tcon->openFileList) {
 169                                         cfile = list_entry(tmp2, struct cifsFileInfo,
 170                                                      tlist);
 171                                         seq_printf(m,
 172                                                 "0x%x 0x%llx 0x%x %d %d %d %s",
 173                                                 tcon->tid,
 174                                                 cfile->fid.persistent_fid,
 175                                                 cfile->f_flags,
 176                                                 cfile->count,
 177                                                 cfile->pid,
 178                                                 from_kuid(&init_user_ns, cfile->uid),
 179                                                 cfile->dentry->d_name.name);
 180 #ifdef CONFIG_CIFS_DEBUG2
 181                                         seq_printf(m, " 0x%llx\n", cfile->fid.mid);
 182 #else
 183                                         seq_printf(m, "\n");
 184 #endif /* CIFS_DEBUG2 */
 185                                 }
 186                                 spin_unlock(&tcon->open_file_lock);
 187                         }
 188                 }
 189         }
 190         spin_unlock(&cifs_tcp_ses_lock);
 191         seq_putc(m, '\n');
 192         return 0;
 193 }
 194 
 195 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
 196 {
 197         struct list_head *tmp1, *tmp2, *tmp3;
 198         struct mid_q_entry *mid_entry;
 199         struct TCP_Server_Info *server;
 200         struct cifs_ses *ses;
 201         struct cifs_tcon *tcon;
 202         int i, j;
 203 
 204         seq_puts(m,
 205                     "Display Internal CIFS Data Structures for Debugging\n"
 206                     "---------------------------------------------------\n");
 207         seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
 208         seq_printf(m, "Features:");
 209 #ifdef CONFIG_CIFS_DFS_UPCALL
 210         seq_printf(m, " DFS");
 211 #endif
 212 #ifdef CONFIG_CIFS_FSCACHE
 213         seq_printf(m, ",FSCACHE");
 214 #endif
 215 #ifdef CONFIG_CIFS_SMB_DIRECT
 216         seq_printf(m, ",SMB_DIRECT");
 217 #endif
 218 #ifdef CONFIG_CIFS_STATS2
 219         seq_printf(m, ",STATS2");
 220 #else
 221         seq_printf(m, ",STATS");
 222 #endif
 223 #ifdef CONFIG_CIFS_DEBUG2
 224         seq_printf(m, ",DEBUG2");
 225 #elif defined(CONFIG_CIFS_DEBUG)
 226         seq_printf(m, ",DEBUG");
 227 #endif
 228 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
 229         seq_printf(m, ",ALLOW_INSECURE_LEGACY");
 230 #endif
 231 #ifdef CONFIG_CIFS_WEAK_PW_HASH
 232         seq_printf(m, ",WEAK_PW_HASH");
 233 #endif
 234 #ifdef CONFIG_CIFS_POSIX
 235         seq_printf(m, ",CIFS_POSIX");
 236 #endif
 237 #ifdef CONFIG_CIFS_UPCALL
 238         seq_printf(m, ",UPCALL(SPNEGO)");
 239 #endif
 240 #ifdef CONFIG_CIFS_XATTR
 241         seq_printf(m, ",XATTR");
 242 #endif
 243         seq_printf(m, ",ACL");
 244         seq_putc(m, '\n');
 245         seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
 246         seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
 247         seq_printf(m, "Servers:");
 248 
 249         i = 0;
 250         spin_lock(&cifs_tcp_ses_lock);
 251         list_for_each(tmp1, &cifs_tcp_ses_list) {
 252                 server = list_entry(tmp1, struct TCP_Server_Info,
 253                                     tcp_ses_list);
 254 
 255 #ifdef CONFIG_CIFS_SMB_DIRECT
 256                 if (!server->rdma)
 257                         goto skip_rdma;
 258 
 259                 if (!server->smbd_conn) {
 260                         seq_printf(m, "\nSMBDirect transport not available");
 261                         goto skip_rdma;
 262                 }
 263 
 264                 seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
 265                         "transport status: %x",
 266                         server->smbd_conn->protocol,
 267                         server->smbd_conn->transport_status);
 268                 seq_printf(m, "\nConn receive_credit_max: %x "
 269                         "send_credit_target: %x max_send_size: %x",
 270                         server->smbd_conn->receive_credit_max,
 271                         server->smbd_conn->send_credit_target,
 272                         server->smbd_conn->max_send_size);
 273                 seq_printf(m, "\nConn max_fragmented_recv_size: %x "
 274                         "max_fragmented_send_size: %x max_receive_size:%x",
 275                         server->smbd_conn->max_fragmented_recv_size,
 276                         server->smbd_conn->max_fragmented_send_size,
 277                         server->smbd_conn->max_receive_size);
 278                 seq_printf(m, "\nConn keep_alive_interval: %x "
 279                         "max_readwrite_size: %x rdma_readwrite_threshold: %x",
 280                         server->smbd_conn->keep_alive_interval,
 281                         server->smbd_conn->max_readwrite_size,
 282                         server->smbd_conn->rdma_readwrite_threshold);
 283                 seq_printf(m, "\nDebug count_get_receive_buffer: %x "
 284                         "count_put_receive_buffer: %x count_send_empty: %x",
 285                         server->smbd_conn->count_get_receive_buffer,
 286                         server->smbd_conn->count_put_receive_buffer,
 287                         server->smbd_conn->count_send_empty);
 288                 seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
 289                         "count_enqueue_reassembly_queue: %x "
 290                         "count_dequeue_reassembly_queue: %x "
 291                         "fragment_reassembly_remaining: %x "
 292                         "reassembly_data_length: %x "
 293                         "reassembly_queue_length: %x",
 294                         server->smbd_conn->count_reassembly_queue,
 295                         server->smbd_conn->count_enqueue_reassembly_queue,
 296                         server->smbd_conn->count_dequeue_reassembly_queue,
 297                         server->smbd_conn->fragment_reassembly_remaining,
 298                         server->smbd_conn->reassembly_data_length,
 299                         server->smbd_conn->reassembly_queue_length);
 300                 seq_printf(m, "\nCurrent Credits send_credits: %x "
 301                         "receive_credits: %x receive_credit_target: %x",
 302                         atomic_read(&server->smbd_conn->send_credits),
 303                         atomic_read(&server->smbd_conn->receive_credits),
 304                         server->smbd_conn->receive_credit_target);
 305                 seq_printf(m, "\nPending send_pending: %x "
 306                         "send_payload_pending: %x",
 307                         atomic_read(&server->smbd_conn->send_pending),
 308                         atomic_read(&server->smbd_conn->send_payload_pending));
 309                 seq_printf(m, "\nReceive buffers count_receive_queue: %x "
 310                         "count_empty_packet_queue: %x",
 311                         server->smbd_conn->count_receive_queue,
 312                         server->smbd_conn->count_empty_packet_queue);
 313                 seq_printf(m, "\nMR responder_resources: %x "
 314                         "max_frmr_depth: %x mr_type: %x",
 315                         server->smbd_conn->responder_resources,
 316                         server->smbd_conn->max_frmr_depth,
 317                         server->smbd_conn->mr_type);
 318                 seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
 319                         atomic_read(&server->smbd_conn->mr_ready_count),
 320                         atomic_read(&server->smbd_conn->mr_used_count));
 321 skip_rdma:
 322 #endif
 323                 seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
 324                         server->credits,  server->dialect);
 325                 if (server->compress_algorithm == SMB3_COMPRESS_LZNT1)
 326                         seq_printf(m, " COMPRESS_LZNT1");
 327                 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77)
 328                         seq_printf(m, " COMPRESS_LZ77");
 329                 else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF)
 330                         seq_printf(m, " COMPRESS_LZ77_HUFF");
 331                 if (server->sign)
 332                         seq_printf(m, " signed");
 333                 if (server->posix_ext_supported)
 334                         seq_printf(m, " posix");
 335 
 336                 i++;
 337                 list_for_each(tmp2, &server->smb_ses_list) {
 338                         ses = list_entry(tmp2, struct cifs_ses,
 339                                          smb_ses_list);
 340                         if ((ses->serverDomain == NULL) ||
 341                                 (ses->serverOS == NULL) ||
 342                                 (ses->serverNOS == NULL)) {
 343                                 seq_printf(m, "\n%d) Name: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
 344                                         i, ses->serverName, ses->ses_count,
 345                                         ses->capabilities, ses->status);
 346                                 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
 347                                         seq_printf(m, "Guest\t");
 348                                 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
 349                                         seq_printf(m, "Anonymous\t");
 350                         } else {
 351                                 seq_printf(m,
 352                                     "\n%d) Name: %s  Domain: %s Uses: %d OS:"
 353                                     " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
 354                                     " session status: %d ",
 355                                 i, ses->serverName, ses->serverDomain,
 356                                 ses->ses_count, ses->serverOS, ses->serverNOS,
 357                                 ses->capabilities, ses->status);
 358                         }
 359                         if (server->rdma)
 360                                 seq_printf(m, "RDMA\n\t");
 361                         seq_printf(m, "TCP status: %d Instance: %d\n\tLocal Users To "
 362                                    "Server: %d SecMode: 0x%x Req On Wire: %d",
 363                                    server->tcpStatus,
 364                                    server->reconnect_instance,
 365                                    server->srv_count,
 366                                    server->sec_mode, in_flight(server));
 367 
 368 #ifdef CONFIG_CIFS_STATS2
 369                         seq_printf(m, " In Send: %d In MaxReq Wait: %d",
 370                                 atomic_read(&server->in_send),
 371                                 atomic_read(&server->num_waiters));
 372 #endif
 373                         /* dump session id helpful for use with network trace */
 374                         seq_printf(m, " SessionId: 0x%llx", ses->Suid);
 375                         if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
 376                                 seq_puts(m, " encrypted");
 377                         if (ses->sign)
 378                                 seq_puts(m, " signed");
 379 
 380                         seq_puts(m, "\n\tShares:");
 381                         j = 0;
 382 
 383                         seq_printf(m, "\n\t%d) IPC: ", j);
 384                         if (ses->tcon_ipc)
 385                                 cifs_debug_tcon(m, ses->tcon_ipc);
 386                         else
 387                                 seq_puts(m, "none\n");
 388 
 389                         list_for_each(tmp3, &ses->tcon_list) {
 390                                 tcon = list_entry(tmp3, struct cifs_tcon,
 391                                                   tcon_list);
 392                                 ++j;
 393                                 seq_printf(m, "\n\t%d) ", j);
 394                                 cifs_debug_tcon(m, tcon);
 395                         }
 396 
 397                         seq_puts(m, "\n\tMIDs:\n");
 398 
 399                         spin_lock(&GlobalMid_Lock);
 400                         list_for_each(tmp3, &server->pending_mid_q) {
 401                                 mid_entry = list_entry(tmp3, struct mid_q_entry,
 402                                         qhead);
 403                                 seq_printf(m, "\tState: %d com: %d pid:"
 404                                               " %d cbdata: %p mid %llu\n",
 405                                               mid_entry->mid_state,
 406                                               le16_to_cpu(mid_entry->command),
 407                                               mid_entry->pid,
 408                                               mid_entry->callback_data,
 409                                               mid_entry->mid);
 410                         }
 411                         spin_unlock(&GlobalMid_Lock);
 412 
 413                         spin_lock(&ses->iface_lock);
 414                         if (ses->iface_count)
 415                                 seq_printf(m, "\n\tServer interfaces: %zu\n",
 416                                            ses->iface_count);
 417                         for (j = 0; j < ses->iface_count; j++) {
 418                                 seq_printf(m, "\t%d)", j);
 419                                 cifs_dump_iface(m, &ses->iface_list[j]);
 420                         }
 421                         spin_unlock(&ses->iface_lock);
 422                 }
 423         }
 424         spin_unlock(&cifs_tcp_ses_lock);
 425         seq_putc(m, '\n');
 426 
 427         /* BB add code to dump additional info such as TCP session info now */
 428         return 0;
 429 }
 430 
 431 static ssize_t cifs_stats_proc_write(struct file *file,
 432                 const char __user *buffer, size_t count, loff_t *ppos)
 433 {
 434         bool bv;
 435         int rc;
 436         struct list_head *tmp1, *tmp2, *tmp3;
 437         struct TCP_Server_Info *server;
 438         struct cifs_ses *ses;
 439         struct cifs_tcon *tcon;
 440 
 441         rc = kstrtobool_from_user(buffer, count, &bv);
 442         if (rc == 0) {
 443 #ifdef CONFIG_CIFS_STATS2
 444                 int i;
 445 
 446                 atomic_set(&totBufAllocCount, 0);
 447                 atomic_set(&totSmBufAllocCount, 0);
 448 #endif /* CONFIG_CIFS_STATS2 */
 449                 atomic_set(&tcpSesReconnectCount, 0);
 450                 atomic_set(&tconInfoReconnectCount, 0);
 451 
 452                 spin_lock(&GlobalMid_Lock);
 453                 GlobalMaxActiveXid = 0;
 454                 GlobalCurrentXid = 0;
 455                 spin_unlock(&GlobalMid_Lock);
 456                 spin_lock(&cifs_tcp_ses_lock);
 457                 list_for_each(tmp1, &cifs_tcp_ses_list) {
 458                         server = list_entry(tmp1, struct TCP_Server_Info,
 459                                             tcp_ses_list);
 460                         server->max_in_flight = 0;
 461 #ifdef CONFIG_CIFS_STATS2
 462                         for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
 463                                 atomic_set(&server->num_cmds[i], 0);
 464                                 atomic_set(&server->smb2slowcmd[i], 0);
 465                                 server->time_per_cmd[i] = 0;
 466                                 server->slowest_cmd[i] = 0;
 467                                 server->fastest_cmd[0] = 0;
 468                         }
 469 #endif /* CONFIG_CIFS_STATS2 */
 470                         list_for_each(tmp2, &server->smb_ses_list) {
 471                                 ses = list_entry(tmp2, struct cifs_ses,
 472                                                  smb_ses_list);
 473                                 list_for_each(tmp3, &ses->tcon_list) {
 474                                         tcon = list_entry(tmp3,
 475                                                           struct cifs_tcon,
 476                                                           tcon_list);
 477                                         atomic_set(&tcon->num_smbs_sent, 0);
 478                                         spin_lock(&tcon->stat_lock);
 479                                         tcon->bytes_read = 0;
 480                                         tcon->bytes_written = 0;
 481                                         spin_unlock(&tcon->stat_lock);
 482                                         if (server->ops->clear_stats)
 483                                                 server->ops->clear_stats(tcon);
 484                                 }
 485                         }
 486                 }
 487                 spin_unlock(&cifs_tcp_ses_lock);
 488         } else {
 489                 return rc;
 490         }
 491 
 492         return count;
 493 }
 494 
 495 static int cifs_stats_proc_show(struct seq_file *m, void *v)
 496 {
 497         int i;
 498 #ifdef CONFIG_CIFS_STATS2
 499         int j;
 500 #endif /* STATS2 */
 501         struct list_head *tmp1, *tmp2, *tmp3;
 502         struct TCP_Server_Info *server;
 503         struct cifs_ses *ses;
 504         struct cifs_tcon *tcon;
 505 
 506         seq_printf(m, "Resources in use\nCIFS Session: %d\n",
 507                         sesInfoAllocCount.counter);
 508         seq_printf(m, "Share (unique mount targets): %d\n",
 509                         tconInfoAllocCount.counter);
 510         seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
 511                         bufAllocCount.counter,
 512                         cifs_min_rcv + tcpSesAllocCount.counter);
 513         seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
 514                         smBufAllocCount.counter, cifs_min_small);
 515 #ifdef CONFIG_CIFS_STATS2
 516         seq_printf(m, "Total Large %d Small %d Allocations\n",
 517                                 atomic_read(&totBufAllocCount),
 518                                 atomic_read(&totSmBufAllocCount));
 519 #endif /* CONFIG_CIFS_STATS2 */
 520 
 521         seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
 522         seq_printf(m,
 523                 "\n%d session %d share reconnects\n",
 524                 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
 525 
 526         seq_printf(m,
 527                 "Total vfs operations: %d maximum at one time: %d\n",
 528                 GlobalCurrentXid, GlobalMaxActiveXid);
 529 
 530         i = 0;
 531         spin_lock(&cifs_tcp_ses_lock);
 532         list_for_each(tmp1, &cifs_tcp_ses_list) {
 533                 server = list_entry(tmp1, struct TCP_Server_Info,
 534                                     tcp_ses_list);
 535                 seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight);
 536 #ifdef CONFIG_CIFS_STATS2
 537                 seq_puts(m, "\nTotal time spent processing by command. Time ");
 538                 seq_printf(m, "units are jiffies (%d per second)\n", HZ);
 539                 seq_puts(m, "  SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
 540                 seq_puts(m, "  --------\t------\t----------\t-------\t-------\n");
 541                 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
 542                         seq_printf(m, "  %d\t\t%d\t%llu\t\t%u\t%u\n", j,
 543                                 atomic_read(&server->num_cmds[j]),
 544                                 server->time_per_cmd[j],
 545                                 server->fastest_cmd[j],
 546                                 server->slowest_cmd[j]);
 547                 for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
 548                         if (atomic_read(&server->smb2slowcmd[j]))
 549                                 seq_printf(m, "  %d slow responses from %s for command %d\n",
 550                                         atomic_read(&server->smb2slowcmd[j]),
 551                                         server->hostname, j);
 552 #endif /* STATS2 */
 553                 list_for_each(tmp2, &server->smb_ses_list) {
 554                         ses = list_entry(tmp2, struct cifs_ses,
 555                                          smb_ses_list);
 556                         list_for_each(tmp3, &ses->tcon_list) {
 557                                 tcon = list_entry(tmp3,
 558                                                   struct cifs_tcon,
 559                                                   tcon_list);
 560                                 i++;
 561                                 seq_printf(m, "\n%d) %s", i, tcon->treeName);
 562                                 if (tcon->need_reconnect)
 563                                         seq_puts(m, "\tDISCONNECTED ");
 564                                 seq_printf(m, "\nSMBs: %d",
 565                                            atomic_read(&tcon->num_smbs_sent));
 566                                 if (server->ops->print_stats)
 567                                         server->ops->print_stats(m, tcon);
 568                         }
 569                 }
 570         }
 571         spin_unlock(&cifs_tcp_ses_lock);
 572 
 573         seq_putc(m, '\n');
 574         return 0;
 575 }
 576 
 577 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
 578 {
 579         return single_open(file, cifs_stats_proc_show, NULL);
 580 }
 581 
 582 static const struct file_operations cifs_stats_proc_fops = {
 583         .open           = cifs_stats_proc_open,
 584         .read           = seq_read,
 585         .llseek         = seq_lseek,
 586         .release        = single_release,
 587         .write          = cifs_stats_proc_write,
 588 };
 589 
 590 #ifdef CONFIG_CIFS_SMB_DIRECT
 591 #define PROC_FILE_DEFINE(name) \
 592 static ssize_t name##_write(struct file *file, const char __user *buffer, \
 593         size_t count, loff_t *ppos) \
 594 { \
 595         int rc; \
 596         rc = kstrtoint_from_user(buffer, count, 10, & name); \
 597         if (rc) \
 598                 return rc; \
 599         return count; \
 600 } \
 601 static int name##_proc_show(struct seq_file *m, void *v) \
 602 { \
 603         seq_printf(m, "%d\n", name ); \
 604         return 0; \
 605 } \
 606 static int name##_open(struct inode *inode, struct file *file) \
 607 { \
 608         return single_open(file, name##_proc_show, NULL); \
 609 } \
 610 \
 611 static const struct file_operations cifs_##name##_proc_fops = { \
 612         .open           = name##_open, \
 613         .read           = seq_read, \
 614         .llseek         = seq_lseek, \
 615         .release        = single_release, \
 616         .write          = name##_write, \
 617 }
 618 
 619 PROC_FILE_DEFINE(rdma_readwrite_threshold);
 620 PROC_FILE_DEFINE(smbd_max_frmr_depth);
 621 PROC_FILE_DEFINE(smbd_keep_alive_interval);
 622 PROC_FILE_DEFINE(smbd_max_receive_size);
 623 PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
 624 PROC_FILE_DEFINE(smbd_max_send_size);
 625 PROC_FILE_DEFINE(smbd_send_credit_target);
 626 PROC_FILE_DEFINE(smbd_receive_credit_max);
 627 #endif
 628 
 629 static struct proc_dir_entry *proc_fs_cifs;
 630 static const struct file_operations cifsFYI_proc_fops;
 631 static const struct file_operations cifs_lookup_cache_proc_fops;
 632 static const struct file_operations traceSMB_proc_fops;
 633 static const struct file_operations cifs_security_flags_proc_fops;
 634 static const struct file_operations cifs_linux_ext_proc_fops;
 635 
 636 void
 637 cifs_proc_init(void)
 638 {
 639         proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
 640         if (proc_fs_cifs == NULL)
 641                 return;
 642 
 643         proc_create_single("DebugData", 0, proc_fs_cifs,
 644                         cifs_debug_data_proc_show);
 645 
 646         proc_create_single("open_files", 0400, proc_fs_cifs,
 647                         cifs_debug_files_proc_show);
 648 
 649         proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
 650         proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
 651         proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
 652         proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
 653                     &cifs_linux_ext_proc_fops);
 654         proc_create("SecurityFlags", 0644, proc_fs_cifs,
 655                     &cifs_security_flags_proc_fops);
 656         proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
 657                     &cifs_lookup_cache_proc_fops);
 658 
 659 #ifdef CONFIG_CIFS_DFS_UPCALL
 660         proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_fops);
 661 #endif
 662 
 663 #ifdef CONFIG_CIFS_SMB_DIRECT
 664         proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
 665                 &cifs_rdma_readwrite_threshold_proc_fops);
 666         proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
 667                 &cifs_smbd_max_frmr_depth_proc_fops);
 668         proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
 669                 &cifs_smbd_keep_alive_interval_proc_fops);
 670         proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
 671                 &cifs_smbd_max_receive_size_proc_fops);
 672         proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
 673                 &cifs_smbd_max_fragmented_recv_size_proc_fops);
 674         proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
 675                 &cifs_smbd_max_send_size_proc_fops);
 676         proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
 677                 &cifs_smbd_send_credit_target_proc_fops);
 678         proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
 679                 &cifs_smbd_receive_credit_max_proc_fops);
 680 #endif
 681 }
 682 
 683 void
 684 cifs_proc_clean(void)
 685 {
 686         if (proc_fs_cifs == NULL)
 687                 return;
 688 
 689         remove_proc_entry("DebugData", proc_fs_cifs);
 690         remove_proc_entry("open_files", proc_fs_cifs);
 691         remove_proc_entry("cifsFYI", proc_fs_cifs);
 692         remove_proc_entry("traceSMB", proc_fs_cifs);
 693         remove_proc_entry("Stats", proc_fs_cifs);
 694         remove_proc_entry("SecurityFlags", proc_fs_cifs);
 695         remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
 696         remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
 697 
 698 #ifdef CONFIG_CIFS_DFS_UPCALL
 699         remove_proc_entry("dfscache", proc_fs_cifs);
 700 #endif
 701 #ifdef CONFIG_CIFS_SMB_DIRECT
 702         remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
 703         remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
 704         remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
 705         remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
 706         remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
 707         remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
 708         remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
 709         remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
 710 #endif
 711         remove_proc_entry("fs/cifs", NULL);
 712 }
 713 
 714 static int cifsFYI_proc_show(struct seq_file *m, void *v)
 715 {
 716         seq_printf(m, "%d\n", cifsFYI);
 717         return 0;
 718 }
 719 
 720 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
 721 {
 722         return single_open(file, cifsFYI_proc_show, NULL);
 723 }
 724 
 725 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
 726                 size_t count, loff_t *ppos)
 727 {
 728         char c[2] = { '\0' };
 729         bool bv;
 730         int rc;
 731 
 732         rc = get_user(c[0], buffer);
 733         if (rc)
 734                 return rc;
 735         if (strtobool(c, &bv) == 0)
 736                 cifsFYI = bv;
 737         else if ((c[0] > '1') && (c[0] <= '9'))
 738                 cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
 739         else
 740                 return -EINVAL;
 741 
 742         return count;
 743 }
 744 
 745 static const struct file_operations cifsFYI_proc_fops = {
 746         .open           = cifsFYI_proc_open,
 747         .read           = seq_read,
 748         .llseek         = seq_lseek,
 749         .release        = single_release,
 750         .write          = cifsFYI_proc_write,
 751 };
 752 
 753 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
 754 {
 755         seq_printf(m, "%d\n", linuxExtEnabled);
 756         return 0;
 757 }
 758 
 759 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
 760 {
 761         return single_open(file, cifs_linux_ext_proc_show, NULL);
 762 }
 763 
 764 static ssize_t cifs_linux_ext_proc_write(struct file *file,
 765                 const char __user *buffer, size_t count, loff_t *ppos)
 766 {
 767         int rc;
 768 
 769         rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
 770         if (rc)
 771                 return rc;
 772 
 773         return count;
 774 }
 775 
 776 static const struct file_operations cifs_linux_ext_proc_fops = {
 777         .open           = cifs_linux_ext_proc_open,
 778         .read           = seq_read,
 779         .llseek         = seq_lseek,
 780         .release        = single_release,
 781         .write          = cifs_linux_ext_proc_write,
 782 };
 783 
 784 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
 785 {
 786         seq_printf(m, "%d\n", lookupCacheEnabled);
 787         return 0;
 788 }
 789 
 790 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
 791 {
 792         return single_open(file, cifs_lookup_cache_proc_show, NULL);
 793 }
 794 
 795 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
 796                 const char __user *buffer, size_t count, loff_t *ppos)
 797 {
 798         int rc;
 799 
 800         rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
 801         if (rc)
 802                 return rc;
 803 
 804         return count;
 805 }
 806 
 807 static const struct file_operations cifs_lookup_cache_proc_fops = {
 808         .open           = cifs_lookup_cache_proc_open,
 809         .read           = seq_read,
 810         .llseek         = seq_lseek,
 811         .release        = single_release,
 812         .write          = cifs_lookup_cache_proc_write,
 813 };
 814 
 815 static int traceSMB_proc_show(struct seq_file *m, void *v)
 816 {
 817         seq_printf(m, "%d\n", traceSMB);
 818         return 0;
 819 }
 820 
 821 static int traceSMB_proc_open(struct inode *inode, struct file *file)
 822 {
 823         return single_open(file, traceSMB_proc_show, NULL);
 824 }
 825 
 826 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
 827                 size_t count, loff_t *ppos)
 828 {
 829         int rc;
 830 
 831         rc = kstrtobool_from_user(buffer, count, &traceSMB);
 832         if (rc)
 833                 return rc;
 834 
 835         return count;
 836 }
 837 
 838 static const struct file_operations traceSMB_proc_fops = {
 839         .open           = traceSMB_proc_open,
 840         .read           = seq_read,
 841         .llseek         = seq_lseek,
 842         .release        = single_release,
 843         .write          = traceSMB_proc_write,
 844 };
 845 
 846 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
 847 {
 848         seq_printf(m, "0x%x\n", global_secflags);
 849         return 0;
 850 }
 851 
 852 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
 853 {
 854         return single_open(file, cifs_security_flags_proc_show, NULL);
 855 }
 856 
 857 /*
 858  * Ensure that if someone sets a MUST flag, that we disable all other MAY
 859  * flags except for the ones corresponding to the given MUST flag. If there are
 860  * multiple MUST flags, then try to prefer more secure ones.
 861  */
 862 static void
 863 cifs_security_flags_handle_must_flags(unsigned int *flags)
 864 {
 865         unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
 866 
 867         if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
 868                 *flags = CIFSSEC_MUST_KRB5;
 869         else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
 870                 *flags = CIFSSEC_MUST_NTLMSSP;
 871         else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
 872                 *flags = CIFSSEC_MUST_NTLMV2;
 873         else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
 874                 *flags = CIFSSEC_MUST_NTLM;
 875         else if (CIFSSEC_MUST_LANMAN &&
 876                  (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
 877                 *flags = CIFSSEC_MUST_LANMAN;
 878         else if (CIFSSEC_MUST_PLNTXT &&
 879                  (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
 880                 *flags = CIFSSEC_MUST_PLNTXT;
 881 
 882         *flags |= signflags;
 883 }
 884 
 885 static ssize_t cifs_security_flags_proc_write(struct file *file,
 886                 const char __user *buffer, size_t count, loff_t *ppos)
 887 {
 888         int rc;
 889         unsigned int flags;
 890         char flags_string[12];
 891         bool bv;
 892 
 893         if ((count < 1) || (count > 11))
 894                 return -EINVAL;
 895 
 896         memset(flags_string, 0, 12);
 897 
 898         if (copy_from_user(flags_string, buffer, count))
 899                 return -EFAULT;
 900 
 901         if (count < 3) {
 902                 /* single char or single char followed by null */
 903                 if (strtobool(flags_string, &bv) == 0) {
 904                         global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
 905                         return count;
 906                 } else if (!isdigit(flags_string[0])) {
 907                         cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
 908                                         flags_string);
 909                         return -EINVAL;
 910                 }
 911         }
 912 
 913         /* else we have a number */
 914         rc = kstrtouint(flags_string, 0, &flags);
 915         if (rc) {
 916                 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
 917                                 flags_string);
 918                 return rc;
 919         }
 920 
 921         cifs_dbg(FYI, "sec flags 0x%x\n", flags);
 922 
 923         if (flags == 0)  {
 924                 cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
 925                 return -EINVAL;
 926         }
 927 
 928         if (flags & ~CIFSSEC_MASK) {
 929                 cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
 930                          flags & ~CIFSSEC_MASK);
 931                 return -EINVAL;
 932         }
 933 
 934         cifs_security_flags_handle_must_flags(&flags);
 935 
 936         /* flags look ok - update the global security flags for cifs module */
 937         global_secflags = flags;
 938         if (global_secflags & CIFSSEC_MUST_SIGN) {
 939                 /* requiring signing implies signing is allowed */
 940                 global_secflags |= CIFSSEC_MAY_SIGN;
 941                 cifs_dbg(FYI, "packet signing now required\n");
 942         } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
 943                 cifs_dbg(FYI, "packet signing disabled\n");
 944         }
 945         /* BB should we turn on MAY flags for other MUST options? */
 946         return count;
 947 }
 948 
 949 static const struct file_operations cifs_security_flags_proc_fops = {
 950         .open           = cifs_security_flags_proc_open,
 951         .read           = seq_read,
 952         .llseek         = seq_lseek,
 953         .release        = single_release,
 954         .write          = cifs_security_flags_proc_write,
 955 };
 956 #else
 957 inline void cifs_proc_init(void)
 958 {
 959 }
 960 
 961 inline void cifs_proc_clean(void)
 962 {
 963 }
 964 #endif /* PROC_FS */

/* [<][>][^][v][top][bottom][index][help] */