linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Akira Fujita <a-fujita@rs.jp.nec.com>
To: Duncan Simpson <dps@simpson.demon.co.uk>
Cc: linux-ext4@vger.kernel.org
Subject: Re: ext 4 online defragment bug report+patch
Date: Tue, 27 Jan 2009 17:32:45 +0900	[thread overview]
Message-ID: <497EC6AD.9050604@rs.jp.nec.com> (raw)
In-Reply-To: <497E6389.40302@simpson.demon.co.uk>

Hi Duncan,

Thanks for looking at the e4defrag.

Duncan Simpson wrote:
> The version of the ext 4 defragment command linked to by wikipedia has a
> serious bug: it opens named pipes and sockets even when somebody is not
> listening to them.
> 
> This causes blocking the until the defragment process is killed. It never
> gets to the code which discovers the object is not a regular file and
> should not be defragemented. The patch below fixes this by checking that 
> the
> object is a regular file *before* openning it, thereby avoiding the 
> problem.

You are right, open for non support file is waste and harmful.
But the e4defrag has already checked the target file type
before open it in the main function as follows.

int main(int argc, char *argv[])
{
<snip>
                 if (lstat64(argv[i], &buf) < 0) {
                         perror(NGMSG_FILE_INFO);
                         PRINT_FILE_NAME(argv[i]);
                         continue;
                 }

                 /* Only regular file is acceptalbe with force defrag mode */
                 if (force_flag && !S_ISREG(buf.st_mode)) {
                         printf("Inappropriate file type\n");
                         goto out;
                 }

                 if (S_ISBLK(buf.st_mode)) {
                         /* Block device */
                         if (get_mount_point(argv[i], dir_name, PATH_MAX)
                                                         == RETURN_NG)
                                 continue;
                         arg_type = DEVNAME;
                         printf("ext4 defragmentation for device(%s)\n",
                                 argv[i]);
                 } else if (S_ISDIR(buf.st_mode)) {
                         /* Directory */
                         if (access(argv[i], R_OK) < 0) {
                                 perror(argv[i]);
                                 continue;
                         }
                         arg_type = DIRNAME;
                         strcpy(dir_name, argv[i]);
                 } else if (S_ISREG(buf.st_mode)) {
                         /* Regular file */
                         arg_type = FILENAME;
*               } else {
*                       /* Irregular file */
*                       PRINT_ERR_MSG(NGMSG_FILE_UNREG);
*                       PRINT_FILE_NAME(argv[i]);
*                       continue;
                 }

<snip>

Te above "else" handles non support files (e.g. socket and pipe) correctly.
Therefore e4defrag will print error message and skip them without file open.

Thanks,
Akira Fujita


> You may want to leave the check after the object has been opened in place
> to avoid problems due to race conditions.
> 
> Duncan (-:
> 
> --- e4defrag.c.dist     2009-01-27 01:19:07.605937764 +0000
> +++ e4defrag.c  2009-01-27 01:18:32.505937083 +0000
> @@ -631,6 +633,16 @@
>                 return FTW_CONT;
>         }
> 
> +       /* Openning a pipe or socket can block, so bypass non-regular files
> +        * before openning them. */
> +       if (S_ISREG(buf->st_mode)==0) {
> +               if (detail_flag) {
> +                       PRINT_FILE_NAME(file);
> +                       IN_FTW_PRINT_ERR_MSG(NGMSG_FILE_UNREG);
> +               }
> +               goto out;
> +       }
> +
>         fd = open64(file, O_RDONLY);
>         if (fd < 0) {
>                 if (detail_flag) {
> 



           reply	other threads:[~2009-01-27  8:33 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <497E6389.40302@simpson.demon.co.uk>]

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=497EC6AD.9050604@rs.jp.nec.com \
    --to=a-fujita@rs.jp.nec.com \
    --cc=dps@simpson.demon.co.uk \
    --cc=linux-ext4@vger.kernel.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).