Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp73771imm; Mon, 21 May 2018 02:28:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoGtEW+wW7hzkcQgbgf4P41sy6Rk43RvB+TiNlEdGheDCWP+c7+u43rJCWvd3VHBMCdpSwl X-Received: by 2002:a65:4dca:: with SMTP id q10-v6mr15178588pgt.22.1526894913477; Mon, 21 May 2018 02:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526894913; cv=none; d=google.com; s=arc-20160816; b=bbDj326uh2xewhTp+bFCxscwLCqp4ZtxBMlNskU/XP9gN33So0lgtJQa3BCK1KUgfh qXFWnFGt/TyfYhwpPrI8TObI0vz+waL5CQwNB1NFp8/nPY6YlNT+AN6P8uM15OA6iQQr K/Kq+Tny3K66FMKdS4E5C4LvmBgmbQTk+ZCMssGaRQAJ31I6rgU905JL4TzGSV4T20e4 kpghnDujRypFaIdLKG7Nyh4naQowuAuors0EXqmpW3kzZ4yb4Pow/bnX3Zv3U8OpLu6B 3gshcPMZncLzkbP+6fg13+dirTY+aVv9grlhdtPlat4LgsyNuc9TqUlneYJwP6VocObA wHLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=5GYbo4gu18M+Laa++TNVKadvCcV1MafS4JprV1TlYfM=; b=iJXAKVm23RndSNyHFtecJJBeFVa4chXcqGjj6IPbRZcbXQlLQ8zfT3jzQ/Uhhs38M8 fD0gmLwq6hTsiYpSawKroLvALlnJLM2xhJAqW5NebjZboTko2bn67obgq9qpmYVlUk0C WLE0aYzcLq+8QFZc9Dwq6QcU1mFb3eKA/dD8XsRKZr6Acmb//b7ceeVZ6JVNYo9fcLCW PMpXVOBNNQt3uX6bKjO3LMBN3R77PvG3Zrb5AiAFTokr/vAOSLf96ObeBkmrVSqHGXnJ YgPXB1RYg+WCUajzWS61sNBCFMRc8/vVILLWYC61sBMvsJ8B/EcwaFjDFtmyaBDRuFPS op9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5-v6si6888117pgs.181.2018.05.21.02.28.19; Mon, 21 May 2018 02:28:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751280AbeEUJ0y (ORCPT + 99 others); Mon, 21 May 2018 05:26:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:43565 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750922AbeEUJ0v (ORCPT ); Mon, 21 May 2018 05:26:51 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D6650AD7A; Mon, 21 May 2018 09:26:49 +0000 (UTC) From: Luis Henriques To: "Yan, Zheng" , Sage Weil , Ilya Dryomov Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Henriques Subject: [PATCH] ceph: fix st_nlink stat for directories Date: Mon, 21 May 2018 10:27:29 +0100 Message-Id: <20180521092729.17470-1-lhenriques@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, calling stat on a cephfs directory returns 1 for st_nlink. This behaviour has recently changed in the fuse client, as some applications seem to expect this value to be either 0 (if it's unlinked) or 2 + number of subdirectories. This behaviour was changed in the fuse client with commit 67c7e4619188 ("client: use common interp of st_nlink for dirs"). This patch modifies the kernel client to have a similar behaviour. Link: https://tracker.ceph.com/issues/23873 Signed-off-by: Luis Henriques --- fs/ceph/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index aa7c5a4ff137..6ad66ef8fd66 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -2288,6 +2288,14 @@ int ceph_getattr(const struct path *path, struct kstat *stat, stat->size = ci->i_files + ci->i_subdirs; stat->blocks = 0; stat->blksize = 65536; + /* + * Some applications rely on the number of st_nlink + * value on directories to be either 0 (if unlinked) + * or 2 + number of subdirectories. + */ + if (stat->nlink == 1) + /* '.' + '..' + subdirs */ + stat->nlink = 1 + 1 + ci->i_subdirs; } } return err;