All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Robottom Reis <kiko@acm.org>
To: NFS List <linux-nfs@vger.kernel.org>
Subject: Re: Finding and breaking client locks
Date: Mon, 21 Mar 2016 21:58:13 -0300	[thread overview]
Message-ID: <20160322005813.GA3378@anthem.async.com.br> (raw)
In-Reply-To: <20160321143914.GA6397@anthem.async.com.br>

[-- Attachment #1: Type: text/plain, Size: 909 bytes --]

On Mon, Mar 21, 2016 at 11:39:14AM -0300, Christian Robottom Reis wrote:
> indeed does not return any information pertaining NFS client locks, and
> I'm not clear whether /proc/locks (on the server side obviously) does or
> not.

Somewhat OT, but I find it a PITA that /proc/locks gives inode numbers
that then need to be looked up individually. I have often been surprised
no tool exists to parse that and give you back a report of filenames, so
I just put together a small tool that just offloads the work to debugfs.

I've attached it in case others might find it useful.

(Interestingly, in a network of Ubuntu desktops, the long-term remote lock
holders are basically Spotify, Firefox and Zeitgeist, of which the
latter two are essentially sqlite.)
-- 
Christian Robottom Reis | [+55 16] 3376 0125   | http://async.com.br/~kiko
                        | [+55 16] 991 126 430 | http://launchpad.net/~kiko

[-- Attachment #2: parselocks.py --]
[-- Type: text/x-python, Size: 1448 bytes --]

#!/usr/bin/env python3
import os
import sys
import subprocess
import io

locksdb = open("/proc/locks")
device_inodes = {}
for lockline in locksdb:
    lock_inode_raw = lockline.split()[5]
    lock_inode = lock_inode_raw.split(":")
    if len(lock_inode) < 3:
        #print("Ignoring %s" % lock_inode)
        continue
    device = tuple(map(int,lock_inode[0:2]))
    try:
        target_device = os.readlink("/sys/dev/block/%s:%s" % device)
        target_device = target_device.split("/")[-1]
    except OSError:
        #print("Device %s:%s not found" % device)
        continue
    inode = lock_inode[2]
    if not device_inodes.get(target_device):
            device_inodes[target_device] = []
    device_inodes[target_device].append(inode)

for device in device_inodes:
    print("-> Inodes on %s" % device)
    inode_input = []
    for inode in device_inodes[device]:
        inode_input.append("ncheck %s" % inode)
    debugfs = subprocess.Popen(['debugfs', '/dev/%s' % device],
                     stdin=subprocess.PIPE,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.PIPE)
    debugfs_input = "\n".join(inode_input)
    out, err = debugfs.communicate(input=debugfs_input.encode())
    debugfs_output = out.decode()
    for line in debugfs_output.split("\n"):
        if line.startswith("debugfs:"):
            continue
        if line.startswith("Inode"):
            continue
        print(line)



  parent reply	other threads:[~2016-03-22  0:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-21 14:39 Finding and breaking client locks Christian Robottom Reis
2016-03-21 17:19 ` Jeff Layton
2016-03-21 17:55   ` Christian Robottom Reis
2016-03-21 20:56     ` Christian Robottom Reis
2016-03-21 21:27       ` Jeff Layton
2016-03-22  0:09         ` Christian Robottom Reis
2016-03-22  0:30           ` J. Bruce Fields
2016-03-31  5:11         ` NeilBrown
2016-03-31 20:52           ` Frank Filz
2016-03-22  0:58 ` Christian Robottom Reis [this message]
2016-03-31  5:07   ` NeilBrown
2016-03-31 13:34     ` Trond Myklebust
2016-03-31 22:40       ` NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160322005813.GA3378@anthem.async.com.br \
    --to=kiko@acm.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.