From: Kazuya Mio <k-mio@sx.jp.nec.com>
To: ext4 <linux-ext4@vger.kernel.org>
Cc: Theodore Tso <tytso@mit.edu>, Andreas Dilger <adilger@dilger.ca>
Subject: [PATCH v3 07/11] e4defrag: Allow user who can use reserved blocks to defrag
Date: Mon, 14 Nov 2011 15:24:49 +0900 [thread overview]
Message-ID: <4EC0B431.20802@sx.jp.nec.com> (raw)
Fix free blocks check for general users to use the reserved blocks because
they can use reserved blocks in the following cases:
- the users are specified by mount option resuid/resgid
- e4defrag has CAP_SYS_RESOURCE capability
Signed-off-by: Kazuya Mio <k-mio@sx.jp.nec.com>
---
misc/e4defrag.c | 37 +++++++------------------------------
1 file changed, 7 insertions(+), 30 deletions(-)
diff --git a/misc/e4defrag.c b/misc/e4defrag.c
index effd774..45e9b72 100644
--- a/misc/e4defrag.c
+++ b/misc/e4defrag.c
@@ -471,12 +471,15 @@ static int defrag_fadvise(int fd, struct move_extent defrag_data,
* @fd: defrag target file's descriptor.
* @file: file name.
* @blk_count: file blocks.
+ *
+ * Note that the users who cannot use the reserved blocks might pass this
+ * free space check though there is no free blocks except for reserved blocks.
+ * In this case, they can catch ENOSPC when donor file is created by fallocate
+ * in file_defrag(). So, it's no problem.
*/
static int check_free_size(int fd, const char *file, ext4_fsblk_t blk_count)
{
- ext4_fsblk_t free_blk_count;
struct statfs64 fsbuf;
- uid_t current_uid = getuid();
if (fstatfs64(fd, &fsbuf) < 0) {
if (mode_flag & DETAIL) {
@@ -487,16 +490,7 @@ static int check_free_size(int fd, const char *file, ext4_fsblk_t blk_count)
return -1;
}
- /* Compute free space for root and normal user separately */
- if (current_uid == ROOT_UID)
- free_blk_count = fsbuf.f_bfree;
- else
- free_blk_count = fsbuf.f_bavail;
-
- if (free_blk_count >= blk_count)
- return 0;
-
- return -ENOSPC;
+ return (fsbuf.f_bfree >= blk_count) ? 0 : -ENOSPC;
}
/*
@@ -768,23 +762,6 @@ static int get_exts_count(struct fiemap_extent_list *ext_list_head)
return ret;
}
-/* get_file_blocks() - Get total file blocks.
- *
- * @ext_list_head: the extent list head of the target file
- */
-static ext4_fsblk_t get_file_blocks(struct fiemap_extent_list *ext_list_head)
-{
- ext4_fsblk_t blk_count = 0;
- struct fiemap_extent_list *ext_list_tmp = ext_list_head;
-
- do {
- blk_count += ext_list_tmp->data.len;
- ext_list_tmp = ext_list_tmp->next;
- } while (ext_list_tmp != ext_list_head);
-
- return blk_count;
-}
reply other threads:[~2011-11-14 6:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4EC0B431.20802@sx.jp.nec.com \
--to=k-mio@sx.jp.nec.com \
--cc=adilger@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.