From: Huajun Li <huajun.li.lee@gmail.com>
To: jaegeuk.kim@samsung.com, linux-f2fs-devel@lists.sourceforge.net
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Huajun Li <huajun.li@intel.com>,
Haicheng Li <haicheng.li@linux.intel.com>,
Weihong Xu <weihong.xu@intel.com>
Subject: [f2fs-dev 4/5] f2fs: Key functions to handle inline data
Date: Sat, 26 Oct 2013 00:01:58 +0800 [thread overview]
Message-ID: <1382716919-23345-5-git-send-email-huajun.li.lee@gmail.com> (raw)
In-Reply-To: <1382716919-23345-1-git-send-email-huajun.li.lee@gmail.com>
From: Huajun Li <huajun.li@intel.com>
Functions to implement inline data read/write, and move inline data to
normal data block when file size exceeds inline data limitation.
Signed-off-by: Huajun Li <huajun.li@intel.com>
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Signed-off-by: Weihong Xu <weihong.xu@intel.com>
---
fs/f2fs/Makefile | 2 +-
fs/f2fs/f2fs.h | 7 +++
fs/f2fs/inline.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 152 insertions(+), 1 deletion(-)
create mode 100644 fs/f2fs/inline.c
diff --git a/fs/f2fs/Makefile b/fs/f2fs/Makefile
index 27a0820..2e35da1 100644
--- a/fs/f2fs/Makefile
+++ b/fs/f2fs/Makefile
@@ -1,6 +1,6 @@
obj-$(CONFIG_F2FS_FS) += f2fs.o
-f2fs-y := dir.o file.o inode.o namei.o hash.o super.o
+f2fs-y := dir.o file.o inode.o namei.o hash.o super.o inline.o
f2fs-y += checkpoint.o gc.o data.o node.o segment.o recovery.o
f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o
f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 4f34330..904ae3d 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1246,4 +1246,11 @@ extern const struct inode_operations f2fs_dir_inode_operations;
extern const struct inode_operations f2fs_symlink_inode_operations;
extern const struct inode_operations f2fs_special_inode_operations;
+/*
+ * inline.c
+ */
+inline int f2fs_has_inline_data(struct inode *);
+int f2fs_read_inline_data(struct inode *, struct page *);
+int f2fs_convert_inline_data(struct inode *, struct page *, unsigned);
+int f2fs_write_inline_data(struct inode *, struct page *, unsigned int);
#endif
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
new file mode 100644
index 0000000..ec0d00c
--- /dev/null
+++ b/fs/f2fs/inline.c
@@ -0,0 +1,144 @@
+/*
+ * fs/f2fs/inline.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/fs.h>
+#include <linux/f2fs_fs.h>
+
+#include "f2fs.h"
+
+inline int f2fs_has_inline_data(struct inode *inode)
+{
+ return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
+}
+
+int f2fs_read_inline_data(struct inode *inode, struct page *page)
+{
+ struct page *ipage;
+ void *src_addr, *dst_addr;
+
+ BUG_ON(page->index);
+ ipage = get_node_page(F2FS_SB(inode->i_sb), inode->i_ino);
+ if (IS_ERR(ipage))
+ return PTR_ERR(ipage);
+
+ src_addr = inline_data_addr(ipage);
+ dst_addr = page_address(page);
+
+ zero_user_segment(page, INLINE_DATA_OFFSET,
+ INLINE_DATA_OFFSET + MAX_INLINE_DATA);
+ /* Copy the whole inline data block */
+ memcpy(dst_addr, src_addr, MAX_INLINE_DATA);
+ f2fs_put_page(ipage, 1);
+
+ SetPageUptodate(page);
+ unlock_page(page);
+
+ return 0;
+}
+
+static int __f2fs_convert_inline_data(struct inode *inode, struct page *page)
+{
+ int err;
+ struct page *ipage;
+ struct dnode_of_data dn;
+ void *src_addr, *dst_addr;
+ struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
+
+ ipage = get_node_page(sbi, inode->i_ino);
+ if (IS_ERR(ipage))
+ return PTR_ERR(ipage);
+
+ f2fs_lock_op(sbi);
+ /* i_addr[0] is not used for inline data,
+ * so reserving new block will not destroy inline data */
+ err = f2fs_reserve_block(inode, &dn, 0);
+ if (err) {
+ f2fs_put_page(ipage, 1);
+ f2fs_unlock_op(sbi);
+ return err;
+ }
+ f2fs_unlock_op(sbi);
+
+ src_addr = inline_data_addr(ipage);
+ dst_addr = page_address(page);
+ zero_user_segment(page, 0, PAGE_CACHE_SIZE);
+ /* Copy the whole inline data block */
+ memcpy(dst_addr, src_addr, MAX_INLINE_DATA);
+ zero_user_segment(ipage, INLINE_DATA_OFFSET,
+ INLINE_DATA_OFFSET + MAX_INLINE_DATA);
+ clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
+ set_raw_inline(F2FS_I(inode),
+ (struct f2fs_inode *)page_address(ipage));
+
+ set_page_dirty(ipage);
+ f2fs_put_page(ipage, 1);
+ set_page_dirty(page);
+
+ return 0;
+}
+
+int f2fs_convert_inline_data(struct inode *inode,
+ struct page *p, unsigned flags)
+{
+ int err;
+ struct page *page;
+
+ if (p && !p->index) {
+ page = p;
+ } else {
+ page = grab_cache_page_write_begin(inode->i_mapping, 0, flags);
+ if (IS_ERR(page))
+ return PTR_ERR(page);
+ }
+
+ err = __f2fs_convert_inline_data(inode, page);
+
+ if (p && !p->index)
+ f2fs_put_page(page, 1);
+
+ return err;
+}
+
+int f2fs_write_inline_data(struct inode *inode,
+ struct page *page, unsigned size)
+{
+ void *src_addr, *dst_addr;
+ struct page *ipage;
+ struct dnode_of_data dn;
+ int err;
+
+ set_new_dnode(&dn, inode, NULL, NULL, 0);
+ err = get_dnode_of_data(&dn, 0, LOOKUP_NODE);
+ if (err)
+ return err;
+ ipage = dn.inode_page;
+
+ src_addr = page_address(page);
+ dst_addr = inline_data_addr(ipage);
+
+ zero_user_segment(ipage, INLINE_DATA_OFFSET,
+ INLINE_DATA_OFFSET + MAX_INLINE_DATA);
+ memcpy(dst_addr, src_addr, size);
+ if (!f2fs_has_inline_data(inode))
+ set_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
+ set_raw_inline(F2FS_I(inode),
+ (struct f2fs_inode *)page_address(ipage));
+ set_page_dirty(ipage);
+
+ if ((F2FS_I(inode)->i_xattr_nid && inode->i_blocks == 2) ||
+ (!F2FS_I(inode)->i_xattr_nid && inode->i_blocks == 1)) {
+ f2fs_put_dnode(&dn);
+ return 0;
+ }
+
+ /* Release the first data block if it is allocated */
+ truncate_data_blocks_range(&dn, 1);
+ f2fs_put_dnode(&dn);
+
+ return 0;
+}
--
1.7.9.5
next prev parent reply other threads:[~2013-10-25 16:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-25 16:01 [f2fs-dev 0/5] f2fs: Enable f2fs support inline data Huajun Li
2013-10-25 16:01 ` [f2fs-dev 1/5] f2fs: Add flags and helpers to " Huajun Li
2013-10-25 16:01 ` [f2fs-dev 2/5] f2fs: Add a new mount option: inline_data Huajun Li
2013-10-25 16:01 ` [f2fs-dev 3/5] f2fs: Add a new function: f2fs_reserve_block() Huajun Li
[not found] ` <1382962607.992.104.camel@kjgkr>
2013-10-28 12:28 ` Jaegeuk Kim
2013-10-28 16:53 ` Huajun Li
2013-10-29 0:56 ` Jaegeuk Kim
2013-10-29 15:27 ` Huajun Li
2013-10-25 16:01 ` Huajun Li [this message]
2013-10-28 12:43 ` [f2fs-dev 4/5] f2fs: Key functions to handle inline data Jaegeuk Kim
2013-10-28 17:20 ` Huajun Li
2013-10-29 1:06 ` Jaegeuk Kim
2013-10-29 15:33 ` Huajun Li
2013-10-25 16:01 ` [f2fs-dev 5/5] f2fs: Handle inline data operations Huajun Li
2013-10-28 12:44 ` Jaegeuk Kim
2013-10-28 16:56 ` Huajun Li
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=1382716919-23345-5-git-send-email-huajun.li.lee@gmail.com \
--to=huajun.li.lee@gmail.com \
--cc=haicheng.li@linux.intel.com \
--cc=huajun.li@intel.com \
--cc=jaegeuk.kim@samsung.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=weihong.xu@intel.com \
/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).