From patchwork Fri Oct 19 22:23:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 10650205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92D0B13B0 for ; Fri, 19 Oct 2018 22:24:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 720C0284F9 for ; Fri, 19 Oct 2018 22:24:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 659E028509; Fri, 19 Oct 2018 22:24:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9548F284F9 for ; Fri, 19 Oct 2018 22:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726495AbeJTGcF (ORCPT ); Sat, 20 Oct 2018 02:32:05 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45393 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726282AbeJTGcF (ORCPT ); Sat, 20 Oct 2018 02:32:05 -0400 Received: by mail-pg1-f195.google.com with SMTP id s3-v6so3116045pga.12 for ; Fri, 19 Oct 2018 15:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Fjf1l12+WA7li5sPdQi0I6dCvP9UAW4SIW7Gt9Kn8nk=; b=ojQPBhq2/V031+d8yBMUa3R43CMMhRtMuxIpG7xK1RzmYPVoDaYCK+LHtbLjWu5y2a y9Tr44cAnL7a5HVsRFDvUhF8C1WGqRYMFG8kXFJOuKXu03j3oUnE7jHK3jIFstyYbrzL A+eloZ98+HQZZzelza4CNwTZZW3gDQasFo2aF56xZPbbcuadWsTP0yOI+G0hjozprbRd fruywH559ecdEwtlGx4VygJPyg6Ei/RfoS1hZi+I+S1Oq+RU9CJ7kx4F0sIuoDH7Whmp LTSc0ciIAXkd2WZbUQhbqB8weY/0PLUu4iOKMQ/stuMfrZJHusmdqqfMmqKKyBk9IBiK ZNEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Fjf1l12+WA7li5sPdQi0I6dCvP9UAW4SIW7Gt9Kn8nk=; b=WA9YFxcugH5VHeHjZDGNA/5gzXvWvfHcBgMSxU5CsupGwCeHR4lYd9tvD8E9PW2E0g KW3BYM+qnre745PgQiBmAsEea06H+f/MuIc+AlHv19/9Duuf8ONPqj4HpltrITp00DoB uyqz26KhMIF4E/rcXDfbOjRsGe3CQMuvUNyp3vBYIPw33De0G8nTKVbWDUn0zY5ghzRd qN2b5qhJa/ySvQvy1maZUWS3xHidaRPaw/gOo39daJrapeQfdYdhd2baqg0D3gHgooHB TA/c6fugMcwBvChexokgp+Y+Qu1sREi1izgUI4/1RyPQ5y1Wt0oCPSBnPuV64VSDi5gv rLkg== X-Gm-Message-State: ABuFfohRBTNnsxguMyyfkyShsjxaJKEP7ROL1IdSzYh2eycrogmhojna cRorF5Z4K7q8N8X4HZd9RNEdX+jiYRXxWtMx+14ruSCK X-Google-Smtp-Source: ACcGV62dbSQR2SyoaiL04ZWzCMzgG+625nVHaTLjst+h0Eitzji1jLGqQCnt4kBbUnBhFx1+CtEEwcT7hm7CpYOLrjw= X-Received: by 2002:a62:ca4d:: with SMTP id n74-v6mr35671997pfg.10.1539987845668; Fri, 19 Oct 2018 15:24:05 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Fri, 19 Oct 2018 17:23:53 -0500 Message-ID: Subject: [PATCH] smb3: show number of current open files in /proc/fs/cifs/Stats To: CIFS Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To allow better debugging (for example applications with handle leaks, or complex reconnect scenarios) display the number of open files (on the client) and number of open server file handles for each tcon in /proc/fs/cifs/Stats. Note that open files on server is one larger than local due to handle caching (in this case of the root of the share). In this example there are two local open files, and three (two file and one directory handle) open on the server. A followon patch will allow querying information about the locally open file which corresponds with the file open on the server (ie matching the SMB3 persistent file id with the information on the local file handle to allow better debugging of misbehaving applications) Sample output: $ cat /proc/fs/cifs/Stats Resources in use CIFS Session: 1 Share (unique mount targets): 2 SMB Request/Response Buffer: 1 Pool size: 5 SMB Small Req/Resp Buffer: 1 Pool size: 30 Operations (MIDs): 0 0 session 0 share reconnects Total vfs operations: 36 maximum at one time: 2 1) \\localhost\test SMBs: 69 Bytes read: 27 Bytes written: 0 Open files: 2 total (local), 3 open on server TreeConnects: 1 total 0 failed TreeDisconnects: 0 total 0 failed Creates: 19 total 0 failed Closes: 16 total 0 failed ... Signed-off-by: Steve French --- fs/cifs/cifsglob.h | 2 ++ fs/cifs/file.c | 2 ++ fs/cifs/misc.c | 2 ++ fs/cifs/smb2ops.c | 3 +++ fs/cifs/smb2pdu.c | 5 ++++- 5 files changed, 13 insertions(+), 1 deletion(-) if (rc) { @@ -2303,6 +2303,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, ses->Suid, oparms->create_options, oparms->desired_access); + atomic_inc(&tcon->num_remote_opens); oparms->fid->persistent_fid = rsp->PersistentFileId; oparms->fid->volatile_fid = rsp->VolatileFileId; @@ -2577,6 +2578,8 @@ SMB2_close_flags(const unsigned int xid, struct cifs_tcon *tcon, goto close_exit; } + atomic_dec(&tcon->num_remote_opens); + /* BB FIXME - decode close response, update inode for caching */ close_exit: From 201353755c2989b5328cbee493774a3544608e74 Mon Sep 17 00:00:00 2001 From: Steve French Date: Fri, 19 Oct 2018 17:14:32 -0500 Subject: [PATCH] smb3: show number of current open files in /proc/fs/cifs/Stats To allow better debugging (for example applications with handle leaks, or complex reconnect scenarios) display the number of open files (on the client) and number of open server file handles for each tcon in /proc/fs/cifs/Stats. Note that open files on server is one larger than local due to handle caching (in this case of the root of the share). In this example there are two local open files, and three (two file and one directory handle) open on the server. Sample output: $ cat /proc/fs/cifs/Stats Resources in use CIFS Session: 1 Share (unique mount targets): 2 SMB Request/Response Buffer: 1 Pool size: 5 SMB Small Req/Resp Buffer: 1 Pool size: 30 Operations (MIDs): 0 0 session 0 share reconnects Total vfs operations: 36 maximum at one time: 2 1) \\localhost\test SMBs: 69 Bytes read: 27 Bytes written: 0 Open files: 2 total (local), 3 open on server TreeConnects: 1 total 0 failed TreeDisconnects: 0 total 0 failed Creates: 19 total 0 failed Closes: 16 total 0 failed ... Signed-off-by: Steve French --- fs/cifs/cifsglob.h | 2 ++ fs/cifs/file.c | 2 ++ fs/cifs/misc.c | 2 ++ fs/cifs/smb2ops.c | 3 +++ fs/cifs/smb2pdu.c | 5 ++++- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 26f497bd97df..ed1e0fcb69e3 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -932,6 +932,8 @@ struct cifs_tcon { struct list_head tcon_list; int tc_count; struct list_head rlist; /* reconnect list */ + atomic_t num_local_opens; /* num of all opens including disconnected */ + atomic_t num_remote_opens; /* num of all network opens on server */ struct list_head openFileList; spinlock_t open_file_lock; /* protects list above */ struct cifs_ses *ses; /* pointer to session associated with */ diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 84477e995246..c620d4b5d5d4 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -334,6 +334,7 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, server->ops->set_fid(cfile, fid, oplock); list_add(&cfile->tlist, &tcon->openFileList); + atomic_inc(&tcon->num_local_opens); /* if readable file instance put first in list*/ if (file->f_mode & FMODE_READ) @@ -395,6 +396,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) /* remove it from the lists */ list_del(&cifs_file->flist); list_del(&cifs_file->tlist); + atomic_dec(&tcon->num_local_opens); if (list_empty(&cifsi->openFileList)) { cifs_dbg(FYI, "closing last open instance for inode %p\n", diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index 6926685e513c..fc43d5d25d1d 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c @@ -123,6 +123,8 @@ tconInfoAlloc(void) ret_buf->crfid.fid = kzalloc(sizeof(struct cifs_fid), GFP_KERNEL); spin_lock_init(&ret_buf->stat_lock); + atomic_set(&ret_buf->num_local_opens, 0); + atomic_set(&ret_buf->num_remote_opens, 0); } return ret_buf; } diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index e35a753eca20..f85fc5aa2710 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1023,6 +1023,9 @@ smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) seq_printf(m, "\nBytes read: %llu Bytes written: %llu", (long long)(tcon->bytes_read), (long long)(tcon->bytes_written)); + seq_printf(m, "\nOpen files: %d total (local), %d open on server", + atomic_read(&tcon->num_local_opens), + atomic_read(&tcon->num_remote_opens)); seq_printf(m, "\nTreeConnects: %d total %d failed", atomic_read(&sent[SMB2_TREE_CONNECT_HE]), atomic_read(&failed[SMB2_TREE_CONNECT_HE])); diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 1310bb355e32..5a08c8f6a322 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -1478,7 +1478,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, /* SMB2 TREE_CONNECT request must be called with TreeId == 0 */ tcon->tid = 0; - + atomic_set(&tcon->num_remote_opens, 0); rc = smb2_plain_req_init(SMB2_TREE_CONNECT, tcon, (void **) &req, &total_len); if (rc) { @@ -2303,6 +2303,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, ses->Suid, oparms->create_options, oparms->desired_access); + atomic_inc(&tcon->num_remote_opens); oparms->fid->persistent_fid = rsp->PersistentFileId; oparms->fid->volatile_fid = rsp->VolatileFileId; @@ -2577,6 +2578,8 @@ SMB2_close_flags(const unsigned int xid, struct cifs_tcon *tcon, goto close_exit; } + atomic_dec(&tcon->num_remote_opens); + /* BB FIXME - decode close response, update inode for caching */ close_exit: -- 2.17.1