Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp364364pxf; Thu, 11 Mar 2021 05:56:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFzqB6r2sKFkLvumpmzwa5W+8ZQZ6s3HOyR+Vtsrbtrmv96iHT7M74B8FHcfLlmtk9G6CX X-Received: by 2002:a17:906:304a:: with SMTP id d10mr3123452ejd.507.1615470974474; Thu, 11 Mar 2021 05:56:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615470974; cv=none; d=google.com; s=arc-20160816; b=cAD8CKPZAToJJsATFNYdpCMK3HkkYrF+52H2mu0p3GdBV8MrB5ybgCGhsZGaEq+jnZ KDYgxUrEZeM9gCIsGQKS/XBViiNkJvu+d89/6W6YN/l4z6JVh4ItYMxHJrDsfgd1TRoP xqCey6HeDgcqDP3NQg3IAbwdL9JxRexfTL7xN8BIc1xN0RYDtcbWOKT7iZx+Nhw6TzD0 K0fj/zejC8zPvtSWnT8lZxhNklR4GXDMzyB7M3Rb1/o+9dKkL8/Vk4Mo60Avt5ZHK/St qC0pDHspOjpVKCmIf9ncnJgGn7AQ2IExlWDCXdFV9tv2iwgSwoJULKp8jSWq2JOBB7Qs TLsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=RV9tXopGIjMcFgujBy8HFFam8a/kiLQRWNYsw40A1+s=; b=tKT3lFzA8tbokQ3WHLl7K+XzXSLhdDmRjq3tNRa5wDyz2VSV5IUc+ArQFcwxLq4mdD lOitp0vujZZoMuUkMYhSSSNfAzJo1B7Hhw24GV5f63UXwtn1P0puWiJvEHW/EmmXQfFb HiORrNsNm7zmeVzRF76xixMjta/Z6Le/cIKxlBXBn11D8WRh2fDBLi2GeOPpE20va4ay k3Ta+Y1MH3BYVAhFVlJIkNmYsgdZJcc54Cci5ZuhQC3UegZbvia6lag1pYsOa8OUj/9A w8jsFJtsm7TRGa8GdmJcK50Y9AI+//esU1lvh55RcnK01mgaG9jOSZKTSfl209GroiFu 3Hpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l6f2QfXm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e15si1782208edz.11.2021.03.11.05.55.50; Thu, 11 Mar 2021 05:56:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l6f2QfXm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233790AbhCKNwt (ORCPT + 99 others); Thu, 11 Mar 2021 08:52:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:48456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233722AbhCKNw3 (ORCPT ); Thu, 11 Mar 2021 08:52:29 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9768364F9A; Thu, 11 Mar 2021 13:52:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615470749; bh=R9H3mIcTDgW/Lz4wvs/Cih1NsNMa6sUb08lf3mjM1s0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=l6f2QfXm8MzB1c/HIO2ODiV4wXgEodLa+ZRQBgY+5tCw8ofsnKjbwbrI3jhPEp9V8 qH+Ud5zX3uXKX82Pi9Py/Oa26iNo9kzbs70LOI0ULIaa+AhhWgTxMwpXoOBqLbDwFf Dm+/CnOJ1kXlV1KuGfms7gqyzjDKQ71mK3GCCy45TZAlgCS+5Z37mDc+3wax6iGTV0 8NHFDFzP7uzYcI1t0XIhYO89/kkQ8pzKa5wg7go9RLUY1f4iCS4QKYR9yfbNAnLMpr OnLthv4p2SXgnNADPUZlpGzpHtjSYxOy0UxaRzf/J558jVb4rss1FFBzu5LsygEDZw wCZnZvajVbZDQ== Message-ID: <923d0102b720657e748178c5ca4dd95fc8f81d2f.camel@kernel.org> Subject: Re: [PATCH v3] fs/locks: print full locks information From: Jeff Layton To: Luo Longjun , viro@zeniv.linux.org.uk, bfields@fieldses.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, sangyan@huawei.com, luchunhua@huawei.com Date: Thu, 11 Mar 2021 08:52:27 -0500 In-Reply-To: <649fa593-d534-a23d-4442-2462778662df@huawei.com> References: <20210221201024.GB15975@fieldses.org> <685386c2840b76c49b060bf7dcea1fefacf18176.1614322182.git.luolongjun@huawei.com> <649fa593-d534-a23d-4442-2462778662df@huawei.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2021-03-11 at 11:45 +0800, Luo Longjun wrote: > 在 2021/3/9 21:37, Jeff Layton 写道: > > On Thu, 2021-02-25 at 22:58 -0500, Luo Longjun wrote: > > > Commit fd7732e033e3 ("fs/locks: create a tree of dependent requests.") > > > has put blocked locks into a tree. > > > > > > So, with a for loop, we can't check all locks information. > > > > > > To solve this problem, we should traverse the tree. > > > > > > Signed-off-by: Luo Longjun > > > --- > > >   fs/locks.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++-------- > > >   1 file changed, 56 insertions(+), 9 deletions(-) > > > > > > diff --git a/fs/locks.c b/fs/locks.c > > > index 99ca97e81b7a..ecaecd1f1b58 100644 > > > --- a/fs/locks.c > > > +++ b/fs/locks.c > > > @@ -2828,7 +2828,7 @@ struct locks_iterator { > > >   }; > > >    > > > > > > > > > > > > > > > > > > > > >   static void lock_get_status(struct seq_file *f, struct file_lock *fl, > > > - loff_t id, char *pfx) > > > + loff_t id, char *pfx, int repeat) > > >   { > > >    struct inode *inode = NULL; > > >    unsigned int fl_pid; > > > @@ -2844,7 +2844,11 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl, > > >    if (fl->fl_file != NULL) > > >    inode = locks_inode(fl->fl_file); > > >    > > > > > > > > > > > > > > > > > > > > > - seq_printf(f, "%lld:%s ", id, pfx); > > > + seq_printf(f, "%lld: ", id); > > > + > > > + if (repeat) > > > + seq_printf(f, "%*s", repeat - 1 + (int)strlen(pfx), pfx); > > Shouldn't that be "%.*s" ? > > > > Also, isn't this likely to end up walking past the end of "pfx" (or even > > ending up at an address before the buffer)? You have this below: > > > >      lock_get_status(f, fl, *id, "", 0); > > > > ...so the "length" value you're passing into the format there is going > > to be -1. It also seems like if you get a large "level" value in > > locks_show, then you'll end up with a length that is much longer than > > the actual string. > > In my understanding, the difference of "%*s" and "%.*s" is that, "%*s" > specifies the minimal filed width while "%.*s" specifies the precision > of the string. > Oh, right. I always forget about the first usage. > Here, I use "%*s", because I want to print locks information in the > follwing format: > > 2: FLOCK  ADVISORY  WRITE 110 00:02:493 0 EOF > 2: -> FLOCK  ADVISORY  WRITE 111 00:02:493 0 EOF > 2:  -> FLOCK  ADVISORY  WRITE 112 00:02:493 0 EOF > 2:   -> FLOCK  ADVISORY  WRITE 113 00:02:493 0 EOF > 2:    -> FLOCK  ADVISORY  WRITE 114 00:02:493 0 EOF > > And also, there is another way to show there information, in the format > like: > > 60: FLOCK  ADVISORY  WRITE 23350 08:02:4456514 0 EOF > 60: -> FLOCK  ADVISORY  WRITE 23356 08:02:4456514 0 EOF > 60: -> FLOCK  ADVISORY  WRITE 24217 08:02:4456514 0 EOF > 60: -> FLOCK  ADVISORY  WRITE 24239 08:02:4456514 0 EOF > > I think both formats are acceptable, but the first format shows > competition relationships between these locks. > We might as well go with the one this patch implements. I like seeing the chain of waiters as well, and it doesn't seem to break lslocks (which is, to my knowledge, the only real programmatic consumer of this file). > In the following code: > > > lock_get_status(f, fl, *id, "", 0); > > repeat is 0, and in the function: > > + if (repeat) > + seq_printf(f, "%*s", repeat - 1 + (int)strlen(pfx), pfx); > > The if branch will not take effect, so it could not be -1. > Good point. Ok, I'll go ahead and put this one in linux-next for now. Assuming there are no problems, it should make v5.13. Thanks! -- Jeff Layton