linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Emanuele Giuseppe Esposito <eesposit@redhat.com>
Subject: [PATCH v3 3/7] libfs: introduce new_inode_current_time
Date: Mon,  4 May 2020 11:00:28 +0200	[thread overview]
Message-ID: <20200504090032.10367-4-eesposit@redhat.com> (raw)
In-Reply-To: <20200504090032.10367-1-eesposit@redhat.com>

It is a common special case for new_inode to initialize the
time to the current time and the inode to get_next_ino().
Introduce a core function that does it.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 fs/libfs.c         | 20 ++++++++++++++++++++
 include/linux/fs.h |  1 +
 2 files changed, 21 insertions(+)

diff --git a/fs/libfs.c b/fs/libfs.c
index 54e07ae986ca..3fa0cd27ab06 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -594,6 +594,26 @@ int simple_write_end(struct file *file, struct address_space *mapping,
 }
 EXPORT_SYMBOL(simple_write_end);
 
+/**
+ * new_inode_current_time - create new inode by initializing the
+ * time to the current time and the inode to get_next_ino()
+ * @sb: pointer to super block of the file system
+ *
+ * Returns an inode pointer on success, NULL on failure.
+ */
+struct inode *new_inode_current_time(struct super_block *sb)
+{
+	struct inode *inode = new_inode(sb);
+
+	if (inode) {
+		inode->i_ino = get_next_ino();
+		inode->i_atime = inode->i_mtime =
+			inode->i_ctime = current_time(inode);
+	}
+	return inode;
+}
+EXPORT_SYMBOL(new_inode_current_time);
+
 /*
  * the inodes created here are not hashed. If you use iunique to generate
  * unique inode values later for this filesystem, then you must take care
diff --git a/include/linux/fs.h b/include/linux/fs.h
index a3691c132b3a..de2577df30ae 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3088,6 +3088,7 @@ extern void clear_inode(struct inode *);
 extern void __destroy_inode(struct inode *);
 extern struct inode *new_inode_pseudo(struct super_block *sb);
 extern struct inode *new_inode(struct super_block *sb);
+extern struct inode *new_inode_current_time(struct super_block *sb);
 extern void free_inode_nonrcu(struct inode *inode);
 extern int should_remove_suid(struct dentry *);
 extern int file_remove_privs(struct file *);
-- 
2.25.2


  parent reply	other threads:[~2020-05-04  9:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04  9:00 [PATCH v3 0/7] libfs: group and simplify linux fs code Emanuele Giuseppe Esposito
2020-05-04  9:00 ` [PATCH v3 1/7] apparmor: just use vfs_kern_mount to make .null Emanuele Giuseppe Esposito
2020-05-04  9:00 ` [PATCH v3 2/7] libfs: wrap simple_pin_fs/simple_release_fs arguments in a struct Emanuele Giuseppe Esposito
2020-05-04  9:00 ` Emanuele Giuseppe Esposito [this message]
2020-05-04  9:00 ` [PATCH v3 4/7] libfs: add alloc_anon_inode wrapper Emanuele Giuseppe Esposito
2020-05-04  9:00 ` [PATCH v3 5/7] libfs: add file creation functions Emanuele Giuseppe Esposito
2020-05-04  9:00 ` [PATCH v3 6/7] debugfs: switch to simplefs inode creation API Emanuele Giuseppe Esposito
2020-05-04  9:00 ` [PATCH v3 7/7] tracefs: " Emanuele Giuseppe Esposito
2020-05-07  0:10   ` Steven Rostedt
2020-06-17 21:00 ` [PATCH v3 0/7] libfs: group and simplify linux fs code Steven Rostedt
2020-06-19 12:38   ` Paolo Bonzini

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=20200504090032.10367-4-eesposit@redhat.com \
    --to=eesposit@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).