Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp945846rwi; Wed, 19 Oct 2022 05:04:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM49v4w9iPkyKbjPNUOGrFOu+7P4Y+pRckn5Ij/z9gADVpIr+Hkd8g6FvrvW96t1pRsJ/wFD X-Received: by 2002:a05:6402:ca:b0:45c:dbdd:8143 with SMTP id i10-20020a05640200ca00b0045cdbdd8143mr7092974edu.213.1666181083845; Wed, 19 Oct 2022 05:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666181083; cv=none; d=google.com; s=arc-20160816; b=urZLQIQzL9wMjP3Qp7Efnw3C54kNV84vZiSEUVBnrt/fOGSkm9ej7fyflLrXz3rwOy Lr8/g0SwBC4sLYzjZJhPe+A0DwoTa+uXP+PJ6WEy6FdXEP4LiK1GblT09Sw5LpnRRWuL tTFpLzV3xgodPXdtCW7IqqHix3QuIRaUuRcQRxJ9p3rt2tlWhAl8uTwyaUJNJ0MsTOuo qg79WGjBJRpsCh1fyCrYBRK3LrgwSs9RlsFfmOszO/yrydyHGRguOo4kAfTjhV6KJ5se 1dHl0R+jDatAtSHnkorewTzVkWCgjqJwN/to9ejkjKR9YXGtlw/ye35UYLNKytRyCopP 8C7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Z1fMPdNDRTHPs2yNcmd+P8KKjuGvgNkbX2eaDg7M/a0=; b=UNDfypqDvrUQTM5zonIIC+QkQ8sRtPfqaZpb1vb+2opM5jNEU9dL7unKh5oMI7k0u5 H19RTgTXIIHiAZM7tWYR87Yx+4ih2gwfPzWhum2fE8/uJjqHh/dQUHK/vVV5qZFhqkJt QxbiVSOFrJ4bj6vlJTTAW6eUq9VD4ynwRTxSBU0oBowgtCittmjKufDc2C30AeKuw9Yu eKPMRbUzScSqd8IV1lgMUUb/QIQJAwufFgX51bHTeSPvAP3YoBmo6okqN1hfY5SCg4Rb zy6ij1D919LiRBZ121Rnx6POg21fe6KPr4erwlH5p+zxPzQZr8XW3XD3+RCD3Xxa6z+t mJXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XO46avwz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp31-20020a1709073e1f00b007877f3132d9si15754898ejc.438.2022.10.19.05.04.16; Wed, 19 Oct 2022 05:04:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XO46avwz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231629AbiJSLwd (ORCPT + 99 others); Wed, 19 Oct 2022 07:52:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231623AbiJSLwQ (ORCPT ); Wed, 19 Oct 2022 07:52:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED3314EC59 for ; Wed, 19 Oct 2022 04:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666178924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Z1fMPdNDRTHPs2yNcmd+P8KKjuGvgNkbX2eaDg7M/a0=; b=XO46avwzM17ftxe6Bp3SJvKiNfCPJDsYDlLOEjOwvqeVt+W0mY0sPd1Z+R+g3tmuqUf7nK wg/xk/q9qHno0LBPFTac6F4Ph0+zenfafnHjZfCfM7sd6BGwzfd7ptO6rXwcld4QOfuaCd 7pMiGxvnXHXmztjSmh9/qtR+gOOKDwk= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-475-A7hC7b0wPmm39QxeCIiiHQ-1; Wed, 19 Oct 2022 07:28:42 -0400 X-MC-Unique: A7hC7b0wPmm39QxeCIiiHQ-1 Received: by mail-qk1-f198.google.com with SMTP id u6-20020a05620a430600b006e47fa02576so14715712qko.22 for ; Wed, 19 Oct 2022 04:28:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Z1fMPdNDRTHPs2yNcmd+P8KKjuGvgNkbX2eaDg7M/a0=; b=39I3lA0fii86VUpUBlO5DU3S4ZYkZibQt6TOmD9BXJ/biVdZpHR6sH6WgOVeLSy97r PScyuCbOjdIQGn/VDF4uA+XlAoBoOzAYLcMIWk4xi3OViZk8q+bbdnGj2+KtX7rt3L52 8w6xNkUZreuZHmNuffEzIfAhPl9W1tH/8brBhIeoZKjwBNeUTXyshshNsIuKTNrGUsuh TCqMqDPYB6mX3+7HfysrHEs3KGF9ehJwrVW/WT8pfnVnaz7lgY+nvunJcczc01sjQcOA W9VNvl/7W+JPR2dcpxD4ogplE3m3o7WEhrRkau089J8F9ntbl60586RkAUoQMmiWOx8I h6Mw== X-Gm-Message-State: ACrzQf37LQpDrueZcjaRSbywdGB9TjejrFlVWgWFSrmR6S9MfrTa9Un0 HlH7i22XamfeYfc909+gIQJXsCMdGPrZx/AoJXmX9lnPf8J6IU9skIf7mP/baM+9qHAKuOaNz4H Wesg9u9Lc4DxbfbmN892mlN4+ X-Received: by 2002:a05:620a:1f3:b0:6e9:e33d:3bb6 with SMTP id x19-20020a05620a01f300b006e9e33d3bb6mr5124976qkn.115.1666178922490; Wed, 19 Oct 2022 04:28:42 -0700 (PDT) X-Received: by 2002:a05:620a:1f3:b0:6e9:e33d:3bb6 with SMTP id x19-20020a05620a01f300b006e9e33d3bb6mr5124966qkn.115.1666178922282; Wed, 19 Oct 2022 04:28:42 -0700 (PDT) Received: from bfoster (c-24-61-119-116.hsd1.ma.comcast.net. [24.61.119.116]) by smtp.gmail.com with ESMTPSA id i15-20020a05620a404f00b006ee91ab3538sm5121173qko.36.2022.10.19.04.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 04:28:41 -0700 (PDT) Date: Wed, 19 Oct 2022 07:28:45 -0400 From: Brian Foster To: Ivan Babrou Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@cloudflare.com, Alexey Dobriyan , Al Viro , Theodore Ts'o , David Laight , Jonathan Corbet , Andrew Morton , David Hildenbrand , Johannes Weiner , Christoph Anton Mitterer , Mike Rapoport , Paul Gortmaker , Kalesh Singh Subject: Re: [PATCH v3] proc: report open files as size in stat() for /proc/pid/fd Message-ID: References: <20221018045844.37697-1-ivan@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 18, 2022 at 11:51:02AM -0700, Ivan Babrou wrote: > On Tue, Oct 18, 2022 at 11:16 AM Brian Foster wrote: > > > +static int proc_readfd_count(struct inode *inode) > > > +{ > > > + struct task_struct *p = get_proc_task(inode); > > > + struct fdtable *fdt; > > > + unsigned int open_fds = 0; > > > + > > > + if (!p) > > > + return -ENOENT; > > > > Maybe this shouldn't happen, but do you mean to assign the error code to > > stat->size in the caller? Otherwise this seems reasonable to me. > > You are right. As unlikely as it is to happen, we shouldn't return > negative size. > > What's the idiomatic way to make this work? My two options are: > > 1. Pass &stat->size into proc_readfd_count: > > if (S_ISDIR(inode->i_mode)) { > rv = proc_readfd_count(inode, &stat->size); > if (rv < 0) > goto out; > } > > out: > return rv; > > OR without a goto: > > if (S_ISDIR(inode->i_mode)) { > rv = proc_readfd_count(inode, &stat->size)); > if (rv < 0) > return rv; > } > > return rv; > > 2. Return negative count as error (as we don't expect negative amount > of files open): > > if (S_ISDIR(inode->i_mode)) { > size = proc_readfd_count(inode); > if (size < 0) > return size; > stat->size = size; > } > I suppose the latter is less of a change to the original patch..? Either way seems reasonable to me. I have no strong preference FWIW. Brian