Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *
0004  *   Copyright (C) International Business Machines  Corp., 2000,2005
0005  *
0006  *   Modified by Steve French (sfrench@us.ibm.com)
0007  */
0008 #include <linux/fs.h>
0009 #include <linux/string.h>
0010 #include <linux/ctype.h>
0011 #include <linux/module.h>
0012 #include <linux/proc_fs.h>
0013 #include <linux/uaccess.h>
0014 #include "cifspdu.h"
0015 #include "cifsglob.h"
0016 #include "cifsproto.h"
0017 #include "cifs_debug.h"
0018 #include "cifsfs.h"
0019 #include "fs_context.h"
0020 #ifdef CONFIG_CIFS_DFS_UPCALL
0021 #include "dfs_cache.h"
0022 #endif
0023 #ifdef CONFIG_CIFS_SMB_DIRECT
0024 #include "smbdirect.h"
0025 #endif
0026 #include "cifs_swn.h"
0027 
0028 void
0029 cifs_dump_mem(char *label, void *data, int length)
0030 {
0031     pr_debug("%s: dump of %d bytes of data at 0x%p\n", label, length, data);
0032     print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
0033                data, length, true);
0034 }
0035 
0036 void cifs_dump_detail(void *buf, struct TCP_Server_Info *server)
0037 {
0038 #ifdef CONFIG_CIFS_DEBUG2
0039     struct smb_hdr *smb = buf;
0040 
0041     cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
0042          smb->Command, smb->Status.CifsError,
0043          smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
0044     cifs_dbg(VFS, "smb buf %p len %u\n", smb,
0045          server->ops->calc_smb_size(smb));
0046 #endif /* CONFIG_CIFS_DEBUG2 */
0047 }
0048 
0049 void cifs_dump_mids(struct TCP_Server_Info *server)
0050 {
0051 #ifdef CONFIG_CIFS_DEBUG2
0052     struct mid_q_entry *mid_entry;
0053 
0054     if (server == NULL)
0055         return;
0056 
0057     cifs_dbg(VFS, "Dump pending requests:\n");
0058     spin_lock(&server->mid_lock);
0059     list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
0060         cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
0061              mid_entry->mid_state,
0062              le16_to_cpu(mid_entry->command),
0063              mid_entry->pid,
0064              mid_entry->callback_data,
0065              mid_entry->mid);
0066 #ifdef CONFIG_CIFS_STATS2
0067         cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
0068              mid_entry->large_buf,
0069              mid_entry->resp_buf,
0070              mid_entry->when_received,
0071              jiffies);
0072 #endif /* STATS2 */
0073         cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
0074              mid_entry->multiRsp, mid_entry->multiEnd);
0075         if (mid_entry->resp_buf) {
0076             cifs_dump_detail(mid_entry->resp_buf, server);
0077             cifs_dump_mem("existing buf: ",
0078                 mid_entry->resp_buf, 62);
0079         }
0080     }
0081     spin_unlock(&server->mid_lock);
0082 #endif /* CONFIG_CIFS_DEBUG2 */
0083 }
0084 
0085 #ifdef CONFIG_PROC_FS
0086 static void cifs_debug_tcon(struct seq_file *m, struct cifs_tcon *tcon)
0087 {
0088     __u32 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
0089 
0090     seq_printf(m, "%s Mounts: %d ", tcon->treeName, tcon->tc_count);
0091     if (tcon->nativeFileSystem)
0092         seq_printf(m, "Type: %s ", tcon->nativeFileSystem);
0093     seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x\n\tPathComponentMax: %d Status: %d",
0094            le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
0095            le32_to_cpu(tcon->fsAttrInfo.Attributes),
0096            le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
0097            tcon->status);
0098     if (dev_type == FILE_DEVICE_DISK)
0099         seq_puts(m, " type: DISK ");
0100     else if (dev_type == FILE_DEVICE_CD_ROM)
0101         seq_puts(m, " type: CDROM ");
0102     else
0103         seq_printf(m, " type: %d ", dev_type);
0104 
0105     seq_printf(m, "Serial Number: 0x%x", tcon->vol_serial_number);
0106 
0107     if ((tcon->seal) ||
0108         (tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
0109         (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
0110         seq_printf(m, " Encrypted");
0111     if (tcon->nocase)
0112         seq_printf(m, " nocase");
0113     if (tcon->unix_ext)
0114         seq_printf(m, " POSIX Extensions");
0115     if (tcon->ses->server->ops->dump_share_caps)
0116         tcon->ses->server->ops->dump_share_caps(m, tcon);
0117     if (tcon->use_witness)
0118         seq_puts(m, " Witness");
0119     if (tcon->broken_sparse_sup)
0120         seq_puts(m, " nosparse");
0121     if (tcon->need_reconnect)
0122         seq_puts(m, "\tDISCONNECTED ");
0123     seq_putc(m, '\n');
0124 }
0125 
0126 static void
0127 cifs_dump_channel(struct seq_file *m, int i, struct cifs_chan *chan)
0128 {
0129     struct TCP_Server_Info *server = chan->server;
0130 
0131     seq_printf(m, "\n\n\t\tChannel: %d ConnectionId: 0x%llx"
0132            "\n\t\tNumber of credits: %d Dialect 0x%x"
0133            "\n\t\tTCP status: %d Instance: %d"
0134            "\n\t\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d"
0135            "\n\t\tIn Send: %d In MaxReq Wait: %d",
0136            i+1, server->conn_id,
0137            server->credits,
0138            server->dialect,
0139            server->tcpStatus,
0140            server->reconnect_instance,
0141            server->srv_count,
0142            server->sec_mode,
0143            in_flight(server),
0144            atomic_read(&server->in_send),
0145            atomic_read(&server->num_waiters));
0146 }
0147 
0148 static void
0149 cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
0150 {
0151     struct sockaddr_in *ipv4 = (struct sockaddr_in *)&iface->sockaddr;
0152     struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&iface->sockaddr;
0153 
0154     seq_printf(m, "\tSpeed: %zu bps\n", iface->speed);
0155     seq_puts(m, "\t\tCapabilities: ");
0156     if (iface->rdma_capable)
0157         seq_puts(m, "rdma ");
0158     if (iface->rss_capable)
0159         seq_puts(m, "rss ");
0160     seq_putc(m, '\n');
0161     if (iface->sockaddr.ss_family == AF_INET)
0162         seq_printf(m, "\t\tIPv4: %pI4\n", &ipv4->sin_addr);
0163     else if (iface->sockaddr.ss_family == AF_INET6)
0164         seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
0165     if (!iface->is_active)
0166         seq_puts(m, "\t\t[for-cleanup]\n");
0167 }
0168 
0169 static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
0170 {
0171     struct TCP_Server_Info *server;
0172     struct cifs_ses *ses;
0173     struct cifs_tcon *tcon;
0174     struct cifsFileInfo *cfile;
0175 
0176     seq_puts(m, "# Version:1\n");
0177     seq_puts(m, "# Format:\n");
0178     seq_puts(m, "# <tree id> <persistent fid> <flags> <count> <pid> <uid>");
0179 #ifdef CONFIG_CIFS_DEBUG2
0180     seq_printf(m, " <filename> <mid>\n");
0181 #else
0182     seq_printf(m, " <filename>\n");
0183 #endif /* CIFS_DEBUG2 */
0184     spin_lock(&cifs_tcp_ses_lock);
0185     list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
0186         list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
0187             list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
0188                 spin_lock(&tcon->open_file_lock);
0189                 list_for_each_entry(cfile, &tcon->openFileList, tlist) {
0190                     seq_printf(m,
0191                         "0x%x 0x%llx 0x%x %d %d %d %pd",
0192                         tcon->tid,
0193                         cfile->fid.persistent_fid,
0194                         cfile->f_flags,
0195                         cfile->count,
0196                         cfile->pid,
0197                         from_kuid(&init_user_ns, cfile->uid),
0198                         cfile->dentry);
0199 #ifdef CONFIG_CIFS_DEBUG2
0200                     seq_printf(m, " %llu\n", cfile->fid.mid);
0201 #else
0202                     seq_printf(m, "\n");
0203 #endif /* CIFS_DEBUG2 */
0204                 }
0205                 spin_unlock(&tcon->open_file_lock);
0206             }
0207         }
0208     }
0209     spin_unlock(&cifs_tcp_ses_lock);
0210     seq_putc(m, '\n');
0211     return 0;
0212 }
0213 
0214 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
0215 {
0216     struct mid_q_entry *mid_entry;
0217     struct TCP_Server_Info *server;
0218     struct cifs_ses *ses;
0219     struct cifs_tcon *tcon;
0220     struct cifs_server_iface *iface;
0221     int c, i, j;
0222 
0223     seq_puts(m,
0224             "Display Internal CIFS Data Structures for Debugging\n"
0225             "---------------------------------------------------\n");
0226     seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
0227     seq_printf(m, "Features:");
0228 #ifdef CONFIG_CIFS_DFS_UPCALL
0229     seq_printf(m, " DFS");
0230 #endif
0231 #ifdef CONFIG_CIFS_FSCACHE
0232     seq_printf(m, ",FSCACHE");
0233 #endif
0234 #ifdef CONFIG_CIFS_SMB_DIRECT
0235     seq_printf(m, ",SMB_DIRECT");
0236 #endif
0237 #ifdef CONFIG_CIFS_STATS2
0238     seq_printf(m, ",STATS2");
0239 #else
0240     seq_printf(m, ",STATS");
0241 #endif
0242 #ifdef CONFIG_CIFS_DEBUG2
0243     seq_printf(m, ",DEBUG2");
0244 #elif defined(CONFIG_CIFS_DEBUG)
0245     seq_printf(m, ",DEBUG");
0246 #endif
0247 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
0248     seq_printf(m, ",ALLOW_INSECURE_LEGACY");
0249 #endif
0250 #ifdef CONFIG_CIFS_POSIX
0251     seq_printf(m, ",CIFS_POSIX");
0252 #endif
0253 #ifdef CONFIG_CIFS_UPCALL
0254     seq_printf(m, ",UPCALL(SPNEGO)");
0255 #endif
0256 #ifdef CONFIG_CIFS_XATTR
0257     seq_printf(m, ",XATTR");
0258 #endif
0259     seq_printf(m, ",ACL");
0260 #ifdef CONFIG_CIFS_SWN_UPCALL
0261     seq_puts(m, ",WITNESS");
0262 #endif
0263     seq_putc(m, '\n');
0264     seq_printf(m, "CIFSMaxBufSize: %d\n", CIFSMaxBufSize);
0265     seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
0266 
0267     seq_printf(m, "\nServers: ");
0268 
0269     c = 0;
0270     spin_lock(&cifs_tcp_ses_lock);
0271     list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
0272         /* channel info will be printed as a part of sessions below */
0273         if (CIFS_SERVER_IS_CHAN(server))
0274             continue;
0275 
0276         c++;
0277         seq_printf(m, "\n%d) ConnectionId: 0x%llx ",
0278             c, server->conn_id);
0279 
0280         if (server->hostname)
0281             seq_printf(m, "Hostname: %s ", server->hostname);
0282 #ifdef CONFIG_CIFS_SMB_DIRECT
0283         if (!server->rdma)
0284             goto skip_rdma;
0285 
0286         if (!server->smbd_conn) {
0287             seq_printf(m, "\nSMBDirect transport not available");
0288             goto skip_rdma;
0289         }
0290 
0291         seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
0292             "transport status: %x",
0293             server->smbd_conn->protocol,
0294             server->smbd_conn->transport_status);
0295         seq_printf(m, "\nConn receive_credit_max: %x "
0296             "send_credit_target: %x max_send_size: %x",
0297             server->smbd_conn->receive_credit_max,
0298             server->smbd_conn->send_credit_target,
0299             server->smbd_conn->max_send_size);
0300         seq_printf(m, "\nConn max_fragmented_recv_size: %x "
0301             "max_fragmented_send_size: %x max_receive_size:%x",
0302             server->smbd_conn->max_fragmented_recv_size,
0303             server->smbd_conn->max_fragmented_send_size,
0304             server->smbd_conn->max_receive_size);
0305         seq_printf(m, "\nConn keep_alive_interval: %x "
0306             "max_readwrite_size: %x rdma_readwrite_threshold: %x",
0307             server->smbd_conn->keep_alive_interval,
0308             server->smbd_conn->max_readwrite_size,
0309             server->smbd_conn->rdma_readwrite_threshold);
0310         seq_printf(m, "\nDebug count_get_receive_buffer: %x "
0311             "count_put_receive_buffer: %x count_send_empty: %x",
0312             server->smbd_conn->count_get_receive_buffer,
0313             server->smbd_conn->count_put_receive_buffer,
0314             server->smbd_conn->count_send_empty);
0315         seq_printf(m, "\nRead Queue count_reassembly_queue: %x "
0316             "count_enqueue_reassembly_queue: %x "
0317             "count_dequeue_reassembly_queue: %x "
0318             "fragment_reassembly_remaining: %x "
0319             "reassembly_data_length: %x "
0320             "reassembly_queue_length: %x",
0321             server->smbd_conn->count_reassembly_queue,
0322             server->smbd_conn->count_enqueue_reassembly_queue,
0323             server->smbd_conn->count_dequeue_reassembly_queue,
0324             server->smbd_conn->fragment_reassembly_remaining,
0325             server->smbd_conn->reassembly_data_length,
0326             server->smbd_conn->reassembly_queue_length);
0327         seq_printf(m, "\nCurrent Credits send_credits: %x "
0328             "receive_credits: %x receive_credit_target: %x",
0329             atomic_read(&server->smbd_conn->send_credits),
0330             atomic_read(&server->smbd_conn->receive_credits),
0331             server->smbd_conn->receive_credit_target);
0332         seq_printf(m, "\nPending send_pending: %x ",
0333             atomic_read(&server->smbd_conn->send_pending));
0334         seq_printf(m, "\nReceive buffers count_receive_queue: %x "
0335             "count_empty_packet_queue: %x",
0336             server->smbd_conn->count_receive_queue,
0337             server->smbd_conn->count_empty_packet_queue);
0338         seq_printf(m, "\nMR responder_resources: %x "
0339             "max_frmr_depth: %x mr_type: %x",
0340             server->smbd_conn->responder_resources,
0341             server->smbd_conn->max_frmr_depth,
0342             server->smbd_conn->mr_type);
0343         seq_printf(m, "\nMR mr_ready_count: %x mr_used_count: %x",
0344             atomic_read(&server->smbd_conn->mr_ready_count),
0345             atomic_read(&server->smbd_conn->mr_used_count));
0346 skip_rdma:
0347 #endif
0348         seq_printf(m, "\nNumber of credits: %d Dialect 0x%x",
0349             server->credits,  server->dialect);
0350         if (server->compress_algorithm == SMB3_COMPRESS_LZNT1)
0351             seq_printf(m, " COMPRESS_LZNT1");
0352         else if (server->compress_algorithm == SMB3_COMPRESS_LZ77)
0353             seq_printf(m, " COMPRESS_LZ77");
0354         else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF)
0355             seq_printf(m, " COMPRESS_LZ77_HUFF");
0356         if (server->sign)
0357             seq_printf(m, " signed");
0358         if (server->posix_ext_supported)
0359             seq_printf(m, " posix");
0360         if (server->nosharesock)
0361             seq_printf(m, " nosharesock");
0362 
0363         if (server->rdma)
0364             seq_printf(m, "\nRDMA ");
0365         seq_printf(m, "\nTCP status: %d Instance: %d"
0366                 "\nLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
0367                 server->tcpStatus,
0368                 server->reconnect_instance,
0369                 server->srv_count,
0370                 server->sec_mode, in_flight(server));
0371 
0372         seq_printf(m, "\nIn Send: %d In MaxReq Wait: %d",
0373                 atomic_read(&server->in_send),
0374                 atomic_read(&server->num_waiters));
0375 
0376         seq_printf(m, "\n\n\tSessions: ");
0377         i = 0;
0378         list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
0379             i++;
0380             if ((ses->serverDomain == NULL) ||
0381                 (ses->serverOS == NULL) ||
0382                 (ses->serverNOS == NULL)) {
0383                 seq_printf(m, "\n\t%d) Address: %s Uses: %d Capability: 0x%x\tSession Status: %d ",
0384                     i, ses->ip_addr, ses->ses_count,
0385                     ses->capabilities, ses->ses_status);
0386                 if (ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
0387                     seq_printf(m, "Guest ");
0388                 else if (ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
0389                     seq_printf(m, "Anonymous ");
0390             } else {
0391                 seq_printf(m,
0392                     "\n\t%d) Name: %s  Domain: %s Uses: %d OS: %s "
0393                     "\n\tNOS: %s\tCapability: 0x%x"
0394                     "\n\tSMB session status: %d ",
0395                 i, ses->ip_addr, ses->serverDomain,
0396                 ses->ses_count, ses->serverOS, ses->serverNOS,
0397                 ses->capabilities, ses->ses_status);
0398             }
0399 
0400             seq_printf(m, "\n\tSecurity type: %s ",
0401                 get_security_type_str(server->ops->select_sectype(server, ses->sectype)));
0402 
0403             /* dump session id helpful for use with network trace */
0404             seq_printf(m, " SessionId: 0x%llx", ses->Suid);
0405             if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
0406                 seq_puts(m, " encrypted");
0407             if (ses->sign)
0408                 seq_puts(m, " signed");
0409 
0410             seq_printf(m, "\n\tUser: %d Cred User: %d",
0411                    from_kuid(&init_user_ns, ses->linux_uid),
0412                    from_kuid(&init_user_ns, ses->cred_uid));
0413 
0414             spin_lock(&ses->chan_lock);
0415             if (CIFS_CHAN_NEEDS_RECONNECT(ses, 0))
0416                 seq_puts(m, "\tPrimary channel: DISCONNECTED ");
0417             if (CIFS_CHAN_IN_RECONNECT(ses, 0))
0418                 seq_puts(m, "\t[RECONNECTING] ");
0419 
0420             if (ses->chan_count > 1) {
0421                 seq_printf(m, "\n\n\tExtra Channels: %zu ",
0422                        ses->chan_count-1);
0423                 for (j = 1; j < ses->chan_count; j++) {
0424                     cifs_dump_channel(m, j, &ses->chans[j]);
0425                     if (CIFS_CHAN_NEEDS_RECONNECT(ses, j))
0426                         seq_puts(m, "\tDISCONNECTED ");
0427                     if (CIFS_CHAN_IN_RECONNECT(ses, j))
0428                         seq_puts(m, "\t[RECONNECTING] ");
0429                 }
0430             }
0431             spin_unlock(&ses->chan_lock);
0432 
0433             seq_puts(m, "\n\n\tShares: ");
0434             j = 0;
0435 
0436             seq_printf(m, "\n\t%d) IPC: ", j);
0437             if (ses->tcon_ipc)
0438                 cifs_debug_tcon(m, ses->tcon_ipc);
0439             else
0440                 seq_puts(m, "none\n");
0441 
0442             list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
0443                 ++j;
0444                 seq_printf(m, "\n\t%d) ", j);
0445                 cifs_debug_tcon(m, tcon);
0446             }
0447 
0448             spin_lock(&ses->iface_lock);
0449             if (ses->iface_count)
0450                 seq_printf(m, "\n\n\tServer interfaces: %zu",
0451                        ses->iface_count);
0452             j = 0;
0453             list_for_each_entry(iface, &ses->iface_list,
0454                          iface_head) {
0455                 seq_printf(m, "\n\t%d)", ++j);
0456                 cifs_dump_iface(m, iface);
0457                 if (is_ses_using_iface(ses, iface))
0458                     seq_puts(m, "\t\t[CONNECTED]\n");
0459             }
0460             spin_unlock(&ses->iface_lock);
0461         }
0462         if (i == 0)
0463             seq_printf(m, "\n\t\t[NONE]");
0464 
0465         seq_puts(m, "\n\n\tMIDs: ");
0466         spin_lock(&server->mid_lock);
0467         list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
0468             seq_printf(m, "\n\tState: %d com: %d pid:"
0469                     " %d cbdata: %p mid %llu\n",
0470                     mid_entry->mid_state,
0471                     le16_to_cpu(mid_entry->command),
0472                     mid_entry->pid,
0473                     mid_entry->callback_data,
0474                     mid_entry->mid);
0475         }
0476         spin_unlock(&server->mid_lock);
0477         seq_printf(m, "\n--\n");
0478     }
0479     if (c == 0)
0480         seq_printf(m, "\n\t[NONE]");
0481 
0482     spin_unlock(&cifs_tcp_ses_lock);
0483     seq_putc(m, '\n');
0484     cifs_swn_dump(m);
0485 
0486     /* BB add code to dump additional info such as TCP session info now */
0487     return 0;
0488 }
0489 
0490 static ssize_t cifs_stats_proc_write(struct file *file,
0491         const char __user *buffer, size_t count, loff_t *ppos)
0492 {
0493     bool bv;
0494     int rc;
0495     struct TCP_Server_Info *server;
0496     struct cifs_ses *ses;
0497     struct cifs_tcon *tcon;
0498 
0499     rc = kstrtobool_from_user(buffer, count, &bv);
0500     if (rc == 0) {
0501 #ifdef CONFIG_CIFS_STATS2
0502         int i;
0503 
0504         atomic_set(&total_buf_alloc_count, 0);
0505         atomic_set(&total_small_buf_alloc_count, 0);
0506 #endif /* CONFIG_CIFS_STATS2 */
0507         atomic_set(&tcpSesReconnectCount, 0);
0508         atomic_set(&tconInfoReconnectCount, 0);
0509 
0510         spin_lock(&GlobalMid_Lock);
0511         GlobalMaxActiveXid = 0;
0512         GlobalCurrentXid = 0;
0513         spin_unlock(&GlobalMid_Lock);
0514         spin_lock(&cifs_tcp_ses_lock);
0515         list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
0516             server->max_in_flight = 0;
0517 #ifdef CONFIG_CIFS_STATS2
0518             for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
0519                 atomic_set(&server->num_cmds[i], 0);
0520                 atomic_set(&server->smb2slowcmd[i], 0);
0521                 server->time_per_cmd[i] = 0;
0522                 server->slowest_cmd[i] = 0;
0523                 server->fastest_cmd[0] = 0;
0524             }
0525 #endif /* CONFIG_CIFS_STATS2 */
0526             list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
0527                 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
0528                     atomic_set(&tcon->num_smbs_sent, 0);
0529                     spin_lock(&tcon->stat_lock);
0530                     tcon->bytes_read = 0;
0531                     tcon->bytes_written = 0;
0532                     spin_unlock(&tcon->stat_lock);
0533                     if (server->ops->clear_stats)
0534                         server->ops->clear_stats(tcon);
0535                 }
0536             }
0537         }
0538         spin_unlock(&cifs_tcp_ses_lock);
0539     } else {
0540         return rc;
0541     }
0542 
0543     return count;
0544 }
0545 
0546 static int cifs_stats_proc_show(struct seq_file *m, void *v)
0547 {
0548     int i;
0549 #ifdef CONFIG_CIFS_STATS2
0550     int j;
0551 #endif /* STATS2 */
0552     struct TCP_Server_Info *server;
0553     struct cifs_ses *ses;
0554     struct cifs_tcon *tcon;
0555 
0556     seq_printf(m, "Resources in use\nCIFS Session: %d\n",
0557             sesInfoAllocCount.counter);
0558     seq_printf(m, "Share (unique mount targets): %d\n",
0559             tconInfoAllocCount.counter);
0560     seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
0561             buf_alloc_count.counter,
0562             cifs_min_rcv + tcpSesAllocCount.counter);
0563     seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
0564             small_buf_alloc_count.counter, cifs_min_small);
0565 #ifdef CONFIG_CIFS_STATS2
0566     seq_printf(m, "Total Large %d Small %d Allocations\n",
0567                 atomic_read(&total_buf_alloc_count),
0568                 atomic_read(&total_small_buf_alloc_count));
0569 #endif /* CONFIG_CIFS_STATS2 */
0570 
0571     seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&mid_count));
0572     seq_printf(m,
0573         "\n%d session %d share reconnects\n",
0574         tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
0575 
0576     seq_printf(m,
0577         "Total vfs operations: %d maximum at one time: %d\n",
0578         GlobalCurrentXid, GlobalMaxActiveXid);
0579 
0580     i = 0;
0581     spin_lock(&cifs_tcp_ses_lock);
0582     list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
0583         seq_printf(m, "\nMax requests in flight: %d", server->max_in_flight);
0584 #ifdef CONFIG_CIFS_STATS2
0585         seq_puts(m, "\nTotal time spent processing by command. Time ");
0586         seq_printf(m, "units are jiffies (%d per second)\n", HZ);
0587         seq_puts(m, "  SMB3 CMD\tNumber\tTotal Time\tFastest\tSlowest\n");
0588         seq_puts(m, "  --------\t------\t----------\t-------\t-------\n");
0589         for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
0590             seq_printf(m, "  %d\t\t%d\t%llu\t\t%u\t%u\n", j,
0591                 atomic_read(&server->num_cmds[j]),
0592                 server->time_per_cmd[j],
0593                 server->fastest_cmd[j],
0594                 server->slowest_cmd[j]);
0595         for (j = 0; j < NUMBER_OF_SMB2_COMMANDS; j++)
0596             if (atomic_read(&server->smb2slowcmd[j]))
0597                 seq_printf(m, "  %d slow responses from %s for command %d\n",
0598                     atomic_read(&server->smb2slowcmd[j]),
0599                     server->hostname, j);
0600 #endif /* STATS2 */
0601         list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
0602             list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
0603                 i++;
0604                 seq_printf(m, "\n%d) %s", i, tcon->treeName);
0605                 if (tcon->need_reconnect)
0606                     seq_puts(m, "\tDISCONNECTED ");
0607                 seq_printf(m, "\nSMBs: %d",
0608                        atomic_read(&tcon->num_smbs_sent));
0609                 if (server->ops->print_stats)
0610                     server->ops->print_stats(m, tcon);
0611             }
0612         }
0613     }
0614     spin_unlock(&cifs_tcp_ses_lock);
0615 
0616     seq_putc(m, '\n');
0617     return 0;
0618 }
0619 
0620 static int cifs_stats_proc_open(struct inode *inode, struct file *file)
0621 {
0622     return single_open(file, cifs_stats_proc_show, NULL);
0623 }
0624 
0625 static const struct proc_ops cifs_stats_proc_ops = {
0626     .proc_open  = cifs_stats_proc_open,
0627     .proc_read  = seq_read,
0628     .proc_lseek = seq_lseek,
0629     .proc_release   = single_release,
0630     .proc_write = cifs_stats_proc_write,
0631 };
0632 
0633 #ifdef CONFIG_CIFS_SMB_DIRECT
0634 #define PROC_FILE_DEFINE(name) \
0635 static ssize_t name##_write(struct file *file, const char __user *buffer, \
0636     size_t count, loff_t *ppos) \
0637 { \
0638     int rc; \
0639     rc = kstrtoint_from_user(buffer, count, 10, & name); \
0640     if (rc) \
0641         return rc; \
0642     return count; \
0643 } \
0644 static int name##_proc_show(struct seq_file *m, void *v) \
0645 { \
0646     seq_printf(m, "%d\n", name ); \
0647     return 0; \
0648 } \
0649 static int name##_open(struct inode *inode, struct file *file) \
0650 { \
0651     return single_open(file, name##_proc_show, NULL); \
0652 } \
0653 \
0654 static const struct proc_ops cifs_##name##_proc_fops = { \
0655     .proc_open  = name##_open, \
0656     .proc_read  = seq_read, \
0657     .proc_lseek = seq_lseek, \
0658     .proc_release   = single_release, \
0659     .proc_write = name##_write, \
0660 }
0661 
0662 PROC_FILE_DEFINE(rdma_readwrite_threshold);
0663 PROC_FILE_DEFINE(smbd_max_frmr_depth);
0664 PROC_FILE_DEFINE(smbd_keep_alive_interval);
0665 PROC_FILE_DEFINE(smbd_max_receive_size);
0666 PROC_FILE_DEFINE(smbd_max_fragmented_recv_size);
0667 PROC_FILE_DEFINE(smbd_max_send_size);
0668 PROC_FILE_DEFINE(smbd_send_credit_target);
0669 PROC_FILE_DEFINE(smbd_receive_credit_max);
0670 #endif
0671 
0672 static struct proc_dir_entry *proc_fs_cifs;
0673 static const struct proc_ops cifsFYI_proc_ops;
0674 static const struct proc_ops cifs_lookup_cache_proc_ops;
0675 static const struct proc_ops traceSMB_proc_ops;
0676 static const struct proc_ops cifs_security_flags_proc_ops;
0677 static const struct proc_ops cifs_linux_ext_proc_ops;
0678 static const struct proc_ops cifs_mount_params_proc_ops;
0679 
0680 void
0681 cifs_proc_init(void)
0682 {
0683     proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
0684     if (proc_fs_cifs == NULL)
0685         return;
0686 
0687     proc_create_single("DebugData", 0, proc_fs_cifs,
0688             cifs_debug_data_proc_show);
0689 
0690     proc_create_single("open_files", 0400, proc_fs_cifs,
0691             cifs_debug_files_proc_show);
0692 
0693     proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
0694     proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
0695     proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);
0696     proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs,
0697             &cifs_linux_ext_proc_ops);
0698     proc_create("SecurityFlags", 0644, proc_fs_cifs,
0699             &cifs_security_flags_proc_ops);
0700     proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
0701             &cifs_lookup_cache_proc_ops);
0702 
0703     proc_create("mount_params", 0444, proc_fs_cifs, &cifs_mount_params_proc_ops);
0704 
0705 #ifdef CONFIG_CIFS_DFS_UPCALL
0706     proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_ops);
0707 #endif
0708 
0709 #ifdef CONFIG_CIFS_SMB_DIRECT
0710     proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
0711         &cifs_rdma_readwrite_threshold_proc_fops);
0712     proc_create("smbd_max_frmr_depth", 0644, proc_fs_cifs,
0713         &cifs_smbd_max_frmr_depth_proc_fops);
0714     proc_create("smbd_keep_alive_interval", 0644, proc_fs_cifs,
0715         &cifs_smbd_keep_alive_interval_proc_fops);
0716     proc_create("smbd_max_receive_size", 0644, proc_fs_cifs,
0717         &cifs_smbd_max_receive_size_proc_fops);
0718     proc_create("smbd_max_fragmented_recv_size", 0644, proc_fs_cifs,
0719         &cifs_smbd_max_fragmented_recv_size_proc_fops);
0720     proc_create("smbd_max_send_size", 0644, proc_fs_cifs,
0721         &cifs_smbd_max_send_size_proc_fops);
0722     proc_create("smbd_send_credit_target", 0644, proc_fs_cifs,
0723         &cifs_smbd_send_credit_target_proc_fops);
0724     proc_create("smbd_receive_credit_max", 0644, proc_fs_cifs,
0725         &cifs_smbd_receive_credit_max_proc_fops);
0726 #endif
0727 }
0728 
0729 void
0730 cifs_proc_clean(void)
0731 {
0732     if (proc_fs_cifs == NULL)
0733         return;
0734 
0735     remove_proc_entry("DebugData", proc_fs_cifs);
0736     remove_proc_entry("open_files", proc_fs_cifs);
0737     remove_proc_entry("cifsFYI", proc_fs_cifs);
0738     remove_proc_entry("traceSMB", proc_fs_cifs);
0739     remove_proc_entry("Stats", proc_fs_cifs);
0740     remove_proc_entry("SecurityFlags", proc_fs_cifs);
0741     remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
0742     remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
0743     remove_proc_entry("mount_params", proc_fs_cifs);
0744 
0745 #ifdef CONFIG_CIFS_DFS_UPCALL
0746     remove_proc_entry("dfscache", proc_fs_cifs);
0747 #endif
0748 #ifdef CONFIG_CIFS_SMB_DIRECT
0749     remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
0750     remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);
0751     remove_proc_entry("smbd_keep_alive_interval", proc_fs_cifs);
0752     remove_proc_entry("smbd_max_receive_size", proc_fs_cifs);
0753     remove_proc_entry("smbd_max_fragmented_recv_size", proc_fs_cifs);
0754     remove_proc_entry("smbd_max_send_size", proc_fs_cifs);
0755     remove_proc_entry("smbd_send_credit_target", proc_fs_cifs);
0756     remove_proc_entry("smbd_receive_credit_max", proc_fs_cifs);
0757 #endif
0758     remove_proc_entry("fs/cifs", NULL);
0759 }
0760 
0761 static int cifsFYI_proc_show(struct seq_file *m, void *v)
0762 {
0763     seq_printf(m, "%d\n", cifsFYI);
0764     return 0;
0765 }
0766 
0767 static int cifsFYI_proc_open(struct inode *inode, struct file *file)
0768 {
0769     return single_open(file, cifsFYI_proc_show, NULL);
0770 }
0771 
0772 static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
0773         size_t count, loff_t *ppos)
0774 {
0775     char c[2] = { '\0' };
0776     bool bv;
0777     int rc;
0778 
0779     rc = get_user(c[0], buffer);
0780     if (rc)
0781         return rc;
0782     if (strtobool(c, &bv) == 0)
0783         cifsFYI = bv;
0784     else if ((c[0] > '1') && (c[0] <= '9'))
0785         cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
0786     else
0787         return -EINVAL;
0788 
0789     return count;
0790 }
0791 
0792 static const struct proc_ops cifsFYI_proc_ops = {
0793     .proc_open  = cifsFYI_proc_open,
0794     .proc_read  = seq_read,
0795     .proc_lseek = seq_lseek,
0796     .proc_release   = single_release,
0797     .proc_write = cifsFYI_proc_write,
0798 };
0799 
0800 static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
0801 {
0802     seq_printf(m, "%d\n", linuxExtEnabled);
0803     return 0;
0804 }
0805 
0806 static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
0807 {
0808     return single_open(file, cifs_linux_ext_proc_show, NULL);
0809 }
0810 
0811 static ssize_t cifs_linux_ext_proc_write(struct file *file,
0812         const char __user *buffer, size_t count, loff_t *ppos)
0813 {
0814     int rc;
0815 
0816     rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
0817     if (rc)
0818         return rc;
0819 
0820     return count;
0821 }
0822 
0823 static const struct proc_ops cifs_linux_ext_proc_ops = {
0824     .proc_open  = cifs_linux_ext_proc_open,
0825     .proc_read  = seq_read,
0826     .proc_lseek = seq_lseek,
0827     .proc_release   = single_release,
0828     .proc_write = cifs_linux_ext_proc_write,
0829 };
0830 
0831 static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
0832 {
0833     seq_printf(m, "%d\n", lookupCacheEnabled);
0834     return 0;
0835 }
0836 
0837 static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
0838 {
0839     return single_open(file, cifs_lookup_cache_proc_show, NULL);
0840 }
0841 
0842 static ssize_t cifs_lookup_cache_proc_write(struct file *file,
0843         const char __user *buffer, size_t count, loff_t *ppos)
0844 {
0845     int rc;
0846 
0847     rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
0848     if (rc)
0849         return rc;
0850 
0851     return count;
0852 }
0853 
0854 static const struct proc_ops cifs_lookup_cache_proc_ops = {
0855     .proc_open  = cifs_lookup_cache_proc_open,
0856     .proc_read  = seq_read,
0857     .proc_lseek = seq_lseek,
0858     .proc_release   = single_release,
0859     .proc_write = cifs_lookup_cache_proc_write,
0860 };
0861 
0862 static int traceSMB_proc_show(struct seq_file *m, void *v)
0863 {
0864     seq_printf(m, "%d\n", traceSMB);
0865     return 0;
0866 }
0867 
0868 static int traceSMB_proc_open(struct inode *inode, struct file *file)
0869 {
0870     return single_open(file, traceSMB_proc_show, NULL);
0871 }
0872 
0873 static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
0874         size_t count, loff_t *ppos)
0875 {
0876     int rc;
0877 
0878     rc = kstrtobool_from_user(buffer, count, &traceSMB);
0879     if (rc)
0880         return rc;
0881 
0882     return count;
0883 }
0884 
0885 static const struct proc_ops traceSMB_proc_ops = {
0886     .proc_open  = traceSMB_proc_open,
0887     .proc_read  = seq_read,
0888     .proc_lseek = seq_lseek,
0889     .proc_release   = single_release,
0890     .proc_write = traceSMB_proc_write,
0891 };
0892 
0893 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
0894 {
0895     seq_printf(m, "0x%x\n", global_secflags);
0896     return 0;
0897 }
0898 
0899 static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
0900 {
0901     return single_open(file, cifs_security_flags_proc_show, NULL);
0902 }
0903 
0904 /*
0905  * Ensure that if someone sets a MUST flag, that we disable all other MAY
0906  * flags except for the ones corresponding to the given MUST flag. If there are
0907  * multiple MUST flags, then try to prefer more secure ones.
0908  */
0909 static void
0910 cifs_security_flags_handle_must_flags(unsigned int *flags)
0911 {
0912     unsigned int signflags = *flags & CIFSSEC_MUST_SIGN;
0913 
0914     if ((*flags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
0915         *flags = CIFSSEC_MUST_KRB5;
0916     else if ((*flags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
0917         *flags = CIFSSEC_MUST_NTLMSSP;
0918     else if ((*flags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
0919         *flags = CIFSSEC_MUST_NTLMV2;
0920 
0921     *flags |= signflags;
0922 }
0923 
0924 static ssize_t cifs_security_flags_proc_write(struct file *file,
0925         const char __user *buffer, size_t count, loff_t *ppos)
0926 {
0927     int rc;
0928     unsigned int flags;
0929     char flags_string[12];
0930     bool bv;
0931 
0932     if ((count < 1) || (count > 11))
0933         return -EINVAL;
0934 
0935     memset(flags_string, 0, 12);
0936 
0937     if (copy_from_user(flags_string, buffer, count))
0938         return -EFAULT;
0939 
0940     if (count < 3) {
0941         /* single char or single char followed by null */
0942         if (strtobool(flags_string, &bv) == 0) {
0943             global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
0944             return count;
0945         } else if (!isdigit(flags_string[0])) {
0946             cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
0947                     flags_string);
0948             return -EINVAL;
0949         }
0950     }
0951 
0952     /* else we have a number */
0953     rc = kstrtouint(flags_string, 0, &flags);
0954     if (rc) {
0955         cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
0956                 flags_string);
0957         return rc;
0958     }
0959 
0960     cifs_dbg(FYI, "sec flags 0x%x\n", flags);
0961 
0962     if (flags == 0)  {
0963         cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", flags_string);
0964         return -EINVAL;
0965     }
0966 
0967     if (flags & ~CIFSSEC_MASK) {
0968         cifs_dbg(VFS, "Unsupported security flags: 0x%x\n",
0969              flags & ~CIFSSEC_MASK);
0970         return -EINVAL;
0971     }
0972 
0973     cifs_security_flags_handle_must_flags(&flags);
0974 
0975     /* flags look ok - update the global security flags for cifs module */
0976     global_secflags = flags;
0977     if (global_secflags & CIFSSEC_MUST_SIGN) {
0978         /* requiring signing implies signing is allowed */
0979         global_secflags |= CIFSSEC_MAY_SIGN;
0980         cifs_dbg(FYI, "packet signing now required\n");
0981     } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
0982         cifs_dbg(FYI, "packet signing disabled\n");
0983     }
0984     /* BB should we turn on MAY flags for other MUST options? */
0985     return count;
0986 }
0987 
0988 static const struct proc_ops cifs_security_flags_proc_ops = {
0989     .proc_open  = cifs_security_flags_proc_open,
0990     .proc_read  = seq_read,
0991     .proc_lseek = seq_lseek,
0992     .proc_release   = single_release,
0993     .proc_write = cifs_security_flags_proc_write,
0994 };
0995 
0996 /* To make it easier to debug, can help to show mount params */
0997 static int cifs_mount_params_proc_show(struct seq_file *m, void *v)
0998 {
0999     const struct fs_parameter_spec *p;
1000     const char *type;
1001 
1002     for (p = smb3_fs_parameters; p->name; p++) {
1003         /* cannot use switch with pointers... */
1004         if (!p->type) {
1005             if (p->flags == fs_param_neg_with_no)
1006                 type = "noflag";
1007             else
1008                 type = "flag";
1009         } else if (p->type == fs_param_is_bool)
1010             type = "bool";
1011         else if (p->type == fs_param_is_u32)
1012             type = "u32";
1013         else if (p->type == fs_param_is_u64)
1014             type = "u64";
1015         else if (p->type == fs_param_is_string)
1016             type = "string";
1017         else
1018             type = "unknown";
1019 
1020         seq_printf(m, "%s:%s\n", p->name, type);
1021     }
1022 
1023     return 0;
1024 }
1025 
1026 static int cifs_mount_params_proc_open(struct inode *inode, struct file *file)
1027 {
1028     return single_open(file, cifs_mount_params_proc_show, NULL);
1029 }
1030 
1031 static const struct proc_ops cifs_mount_params_proc_ops = {
1032     .proc_open  = cifs_mount_params_proc_open,
1033     .proc_read  = seq_read,
1034     .proc_lseek = seq_lseek,
1035     .proc_release   = single_release,
1036     /* No need for write for now */
1037     /* .proc_write  = cifs_mount_params_proc_write, */
1038 };
1039 
1040 #else
1041 inline void cifs_proc_init(void)
1042 {
1043 }
1044 
1045 inline void cifs_proc_clean(void)
1046 {
1047 }
1048 #endif /* PROC_FS */