Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp907771imm; Fri, 28 Sep 2018 08:43:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV610A0KeCNbXXCVjjRjUmhCxLr012HKK4qPvXMwS5j3WuNDcuHzwI8p/xjo0rFnmQJEquA7d X-Received: by 2002:a17:902:6a4:: with SMTP id 33-v6mr9767510plh.11.1538149413631; Fri, 28 Sep 2018 08:43:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538149413; cv=none; d=google.com; s=arc-20160816; b=gb69AOH2EMv7dfSrsFztuYEJX2b5tmXTID6lInh0wePUyoV9I39hwKeIHEZRP3VEcA gUEptYGsU2pNoGYWFQRx4vHIHxnwZXqwoovkrcGUxI5pXrASGAKRze025vIgPaVV2tqT dvEQM+BXRGj0AYDhvM/0rHjxKUKhYT4qWAxFnd+jmp3Snci5FuT6Lf1QdSbOtOco0y6L p31SnJrmtJGZGVPra25v7MYMrJN6mnDc1WXLt3LW5VD0vKubRtdla5+sZPd496Gj1+iC cu9fAlt9ceQyRYDlbGMIsPJxAmZVHcrxZP++W9slFEzGDe7ZJ2AbMeag0Z3kMrZNtuIq bF1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=VkQge49IGWrDW7K/E4CFUpAZEAY3ZcQMKOdIIHysoO8=; b=IFFrfZnNC/3xzkyN7MzGTt4IEi1A8e1BaJ3oBXnYbmkQPHUuEsMKVWgkGGkwVW5j2n 5SwWgsWVS3fFEt4GJsSb9zPiF9XW+l2H+aHN45fF3wwzLh0y/hTSry0Rt+9pYjkODppm +OJjEZJGsW9k6BXwvmawllDG16oTJPC0JIq/TCfwVpQv298l+HxHSmXvDZL3pehH4giU qYNAvMIy13bLP4gUbzo1haVkRDr2gX9Qgc8Yc/XCZkTUugU37tJiC7IJHQJJ84h5RnSe SANsGhLdbT0hbsbGIU7EkHV8m7fLyuwFyNH0eF2Lu7jc0WiuFE5p9U/fiyfZeAQXauMy udLA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n34-v6si5084331pld.311.2018.09.28.08.43.18; Fri, 28 Sep 2018 08:43: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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729699AbeI1WHP (ORCPT + 99 others); Fri, 28 Sep 2018 18:07:15 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33320 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729623AbeI1WHN (ORCPT ); Fri, 28 Sep 2018 18:07:13 -0400 Received: by mail-wr1-f66.google.com with SMTP id f10-v6so6919648wrs.0 for ; Fri, 28 Sep 2018 08:42:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VkQge49IGWrDW7K/E4CFUpAZEAY3ZcQMKOdIIHysoO8=; b=eGp0fhFHtwIpbmaiGqrTItfRAPHvsS6bEUboIMIrmKqJDc4Ektg6q4KlYe0ozfI15R I7NKAHC/WO2+AtsxVCcySRb0b1w4XQPg4F2y+NFz1TYxL6Z5QDjpHwu14nomCqdJ05am PUwdn7y+ZEkjgrlf83rCrhRF819GwPVMLMjETKfzswULW1HoXK3FoFZeB2H935ishuAB Wrx9zXHNraLDvq9ZUBaOK0MUP94oIGV/5KtGL5QYlbKPQyRbZ225teMygSSGq9SjagQD IQgn7Anvh63YM7MBGuFwVKRpXjtGBavtjTCVRjwZ3A7nZnY/+wU6CcqX0M/n4LajU1Yb bHpw== X-Gm-Message-State: ABuFfogfNpd/d/jhTnVlNivcAlVKf7Aq0YwFdEHyw+dFzzqhop4MO0dD w+/Hq8a6cvee0aOAan4j5ooNujtv61I= X-Received: by 2002:adf:db45:: with SMTP id f5-v6mr1845025wrj.237.1538149371606; Fri, 28 Sep 2018 08:42:51 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id v2-v6sm2009877wme.36.2018.09.28.08.42.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 08:42:50 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 9/9] fuse: reduce size of struct fuse_inode Date: Fri, 28 Sep 2018 17:42:34 +0200 Message-Id: <20180928154234.19270-10-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180928154234.19270-1-mszeredi@redhat.com> References: <20180928154234.19270-1-mszeredi@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do this by grouping fields used for cached writes and putting them into a union with fileds used for cached readdir (with obviously no overlap, since we don't have hybrid objects). Signed-off-by: Miklos Szeredi --- fs/fuse/dir.c | 13 +++++++++++- fs/fuse/file.c | 8 ++++++++ fs/fuse/fuse_i.h | 62 +++++++++++++++++++++++++++++++------------------------- fs/fuse/inode.c | 16 ++++----------- 4 files changed, 58 insertions(+), 41 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 6800fdc3e730..d1b2f42d746e 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1414,8 +1414,11 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, file = NULL; } - if (attr->ia_valid & ATTR_SIZE) + if (attr->ia_valid & ATTR_SIZE) { + if (WARN_ON(!S_ISREG(inode->i_mode))) + return -EIO; is_truncate = true; + } if (is_truncate) { fuse_set_nowrite(inode); @@ -1619,8 +1622,16 @@ void fuse_init_common(struct inode *inode) void fuse_init_dir(struct inode *inode) { + struct fuse_inode *fi = get_fuse_inode(inode); + inode->i_op = &fuse_dir_inode_operations; inode->i_fop = &fuse_dir_operations; + + spin_lock_init(&fi->rdc.lock); + fi->rdc.cached = false; + fi->rdc.size = 0; + fi->rdc.pos = 0; + fi->rdc.version = 0; } void fuse_init_symlink(struct inode *inode) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 101e64897b5f..1ca3fe5be3e4 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3064,6 +3064,14 @@ static const struct address_space_operations fuse_file_aops = { void fuse_init_file_inode(struct inode *inode) { + struct fuse_inode *fi = get_fuse_inode(inode); + inode->i_fop = &fuse_file_operations; inode->i_data.a_ops = &fuse_file_aops; + + INIT_LIST_HEAD(&fi->write_files); + INIT_LIST_HEAD(&fi->queued_writes); + fi->writectr = 0; + init_waitqueue_head(&fi->page_waitq); + INIT_LIST_HEAD(&fi->writepages); } diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 1e8d20e86760..41cc9fb33d02 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -87,45 +87,51 @@ struct fuse_inode { /** Version of last attribute change */ u64 attr_version; - /** Files usable in writepage. Protected by fc->lock */ - struct list_head write_files; + union { + /* Write related fields (regular file only) */ + struct { + /** Files usable in writepage. Protected by fc->lock */ + struct list_head write_files; - /** Writepages pending on truncate or fsync */ - struct list_head queued_writes; + /** Writepages pending on truncate or fsync */ + struct list_head queued_writes; - /** Number of sent writes, a negative bias (FUSE_NOWRITE) - * means more writes are blocked */ - int writectr; + /** Number of sent writes, a negative bias + * (FUSE_NOWRITE) means more writes are blocked */ + int writectr; - /** Waitq for writepage completion */ - wait_queue_head_t page_waitq; + /** Waitq for writepage completion */ + wait_queue_head_t page_waitq; - /** List of writepage requestst (pending or sent) */ - struct list_head writepages; + /** List of writepage requestst (pending or sent) */ + struct list_head writepages; + }; - /** readdir cache */ - struct { - /** true if fully cached */ - bool cached; + /** readdir cache (directory only) */ + struct { + /** true if fully cached */ + bool cached; - /** size of cache */ - loff_t size; + /** size of cache */ + loff_t size; - /** position at end of cache (position of next entry) */ - loff_t pos; + /** position at end of cache (position of next entry) */ + loff_t pos; - /** version of the cache */ - u64 version; + /** version of the cache */ + u64 version; - /** modification time of directory when cache was started */ - struct timespec64 mtime; + /** modification time of directory when cache was + * started */ + struct timespec64 mtime; - /** iversion of directory when cache was started */ - u64 iversion; + /** iversion of directory when cache was started */ + u64 iversion; - /** protects above fields */ - spinlock_t lock; - } rdc; + /** protects above fields */ + spinlock_t lock; + } rdc; + }; /** Miscellaneous bits describing inode state */ unsigned long state; diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 6d0a87308f86..bd58ab7e1858 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -93,18 +93,8 @@ static struct inode *fuse_alloc_inode(struct super_block *sb) fi->nodeid = 0; fi->nlookup = 0; fi->attr_version = 0; - fi->writectr = 0; fi->orig_ino = 0; fi->state = 0; - INIT_LIST_HEAD(&fi->write_files); - INIT_LIST_HEAD(&fi->queued_writes); - INIT_LIST_HEAD(&fi->writepages); - init_waitqueue_head(&fi->page_waitq); - spin_lock_init(&fi->rdc.lock); - fi->rdc.cached = false; - fi->rdc.size = 0; - fi->rdc.pos = 0; - fi->rdc.version = 0; mutex_init(&fi->mutex); fi->forget = fuse_alloc_forget(); if (!fi->forget) { @@ -124,8 +114,10 @@ static void fuse_i_callback(struct rcu_head *head) static void fuse_destroy_inode(struct inode *inode) { struct fuse_inode *fi = get_fuse_inode(inode); - BUG_ON(!list_empty(&fi->write_files)); - BUG_ON(!list_empty(&fi->queued_writes)); + if (S_ISREG(inode->i_mode)) { + WARN_ON(!list_empty(&fi->write_files)); + WARN_ON(!list_empty(&fi->queued_writes)); + } mutex_destroy(&fi->mutex); kfree(fi->forget); call_rcu(&inode->i_rcu, fuse_i_callback); -- 2.14.3