All of lore.kernel.org
 help / color / mirror / Atom feed
From: majianpeng <majianpeng@gmail.com>
To: viro <viro@zeniv.linux.org.uk>
Cc: jbacik <jbacik@fusionio.com>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] inode: For readonly filesystem, func file_update_time should return -EROFS rather than zero.
Date: Tue, 15 Oct 2013 11:26:00 +0800	[thread overview]
Message-ID: <201310151125581359520@gmail.com> (raw)

For ext2 mounted with errors=remount-ro, if write a file and because the
harddisk error, the fs became ro.But the following test can't return.

int main()
{
	int ret;
	int i = 0;
	char buff[SIZE];
	int fd = open("/opt/test", O_WRONLY|O_TRUNC|O_CREAT);

	if (fd < 0) {
		printf("open error %s\n", strerror(errno));
		return errno;
	}

	ret = write(fd, buff, SIZE);
	lseek(fd, 0, 0);

	while (1) {
		ret = write(fd, buff, SIZE);
		if (ret < 0) {
			printf("write error %s\n", strerror(errno));
			break;
		}
		lseek(fd, 0, 0);
		i++;
	}
	printf("write count=%d\n", i);
	close(fd);

	return 0;
}

For ext3/ext4, because jbd the test can return. But for ext2, because no
jbd and not reading bitmap from harddisk, the test continue.

So we should add check readonly-fs on write-path. Func file_update_time
already check the readonly flag,but it can't return -EROFS.
For readonly-fs, it can't update a/c/m time of file,it should return
-EROFS rather than zero.

Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
---
 fs/inode.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index b33ba8e..65302c1 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1644,8 +1644,9 @@ int file_update_time(struct file *file)
 		return 0;
 
 	/* Finally allowed to write? Takes lock. */
-	if (__mnt_want_write_file(file))
-		return 0;
+	ret = __mnt_want_write_file(file);
+	if (ret)
+		return ret;
 
 	ret = update_time(inode, &now, sync_it);
 	__mnt_drop_write_file(file);
-- 
1.8.4

WARNING: multiple messages have this Message-ID (diff)
From: majianpeng <majianpeng@gmail.com>
To: viro <viro@zeniv.linux.org.uk>
Cc: jbacik <jbacik@fusionio.com>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] inode: For readonly filesystem, func file_update_time should return -EROFS rather than zero.
Date: Tue, 15 Oct 2013 11:26:00 +0800	[thread overview]
Message-ID: <201310151125581359520@gmail.com> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 1663 bytes --]

For ext2 mounted with errors=remount-ro, if write a file and because the
harddisk error, the fs became ro.But the following test can't return.

int main()
{
	int ret;
	int i = 0;
	char buff[SIZE];
	int fd = open("/opt/test", O_WRONLY|O_TRUNC|O_CREAT);

	if (fd < 0) {
		printf("open error %s\n", strerror(errno));
		return errno;
	}

	ret = write(fd, buff, SIZE);
	lseek(fd, 0, 0);

	while (1) {
		ret = write(fd, buff, SIZE);
		if (ret < 0) {
			printf("write error %s\n", strerror(errno));
			break;
		}
		lseek(fd, 0, 0);
		i++;
	}
	printf("write count=%d\n", i);
	close(fd);

	return 0;
}

For ext3/ext4, because jbd the test can return. But for ext2, because no
jbd and not reading bitmap from harddisk, the test continue.

So we should add check readonly-fs on write-path. Func file_update_time
already check the readonly flag,but it can't return -EROFS.
For readonly-fs, it can't update a/c/m time of file,it should return
-EROFS rather than zero.

Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
---
 fs/inode.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index b33ba8e..65302c1 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1644,8 +1644,9 @@ int file_update_time(struct file *file)
 		return 0;
 
 	/* Finally allowed to write? Takes lock. */
-	if (__mnt_want_write_file(file))
-		return 0;
+	ret = __mnt_want_write_file(file);
+	if (ret)
+		return ret;
 
 	ret = update_time(inode, &now, sync_it);
 	__mnt_drop_write_file(file);
-- 
1.8.4
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

             reply	other threads:[~2013-10-15  3:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-15  3:26 majianpeng [this message]
2013-10-15  3:26 ` [PATCH] inode: For readonly filesystem, func file_update_time should return -EROFS rather than zero majianpeng
2013-10-15 13:46 ` Jan Kara

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=201310151125581359520@gmail.com \
    --to=majianpeng@gmail.com \
    --cc=jbacik@fusionio.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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.