Re: [f2fs-dev] [PATCH v2] f2fs_io: add list/setattr command

2023-11-14 Thread Chao Yu

On 2023/10/20 10:39, Jaegeuk Kim wrote:

Let's add list/set/removexattrs commands.


It looks it missed to add related description in man/f2fs_io.8.

Thanks,



Signed-off-by: Jaegeuk Kim 
---

  - add removexattrs

  tools/f2fs_io/f2fs_io.c | 107 
  1 file changed, 107 insertions(+)

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index c812aa1458a2..e7d286a67939 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -35,6 +35,7 @@
  #include 
  #include 
  #include 
+#include 
  
  #ifdef HAVE_CONFIG_H

  #include 
@@ -1526,6 +1527,109 @@ static void do_gc_range(int argc, char **argv, const 
struct cmd_desc *cmd)
exit(0);
  }
  
+#define listxattr_desc "listxattr"

+#define listxattr_help "f2fs_io listxattr [file_path]\n\n"
+
+static void do_listxattr(int argc, char **argv, const struct cmd_desc *cmd)
+{
+   char *buf, *key, *val;
+   ssize_t buflen, vallen, keylen;
+
+   if (argc != 2) {
+   fputs("Excess arguments\n\n", stderr);
+   fputs(cmd->cmd_help, stderr);
+   exit(1);
+   }
+
+   buflen = listxattr(argv[1], NULL, 0);
+   if (buflen == -1) {
+   perror("listxattr");
+   exit(1);
+   }
+   if (buflen == 0) {
+   printf("%s has no attributes.\n", argv[1]);
+   exit(0);
+   }
+   buf = xmalloc(buflen);
+   buflen = listxattr(argv[1], buf, buflen);
+   if (buflen == -1) {
+   perror("listxattr");
+   exit(1);
+   }
+
+   key = buf;
+   while (buflen > 0) {
+   printf("%s: ", key);
+   vallen = getxattr(argv[1], key, NULL, 0);
+   if (vallen == -1) {
+   perror("getxattr");
+   exit(1);
+   }
+   if (vallen == 0) {
+   printf("");
+   } else {
+   val = xmalloc(vallen + 1);
+   vallen = getxattr(argv[1], key, val, vallen);
+   if (vallen == -1) {
+   perror("getxattr");
+   exit(1);
+   }
+   val[vallen] = 0;
+   printf("%s", val);
+   free(val);
+   }
+   printf("\n");
+   keylen = strlen(key) + 1;
+   buflen -= keylen;
+   key += keylen;
+   }
+   exit(0);
+}
+
+#define setxattr_desc "setxattr"
+#define setxattr_help "f2fs_io setxattr [name] [value] [file_path]\n\n"
+
+static void do_setxattr(int argc, char **argv, const struct cmd_desc *cmd)
+{
+   int ret;
+
+   if (argc != 4) {
+   fputs("Excess arguments\n\n", stderr);
+   fputs(cmd->cmd_help, stderr);
+   exit(1);
+   }
+
+   ret = setxattr(argv[3], argv[1], argv[2], strlen(argv[2]), 
XATTR_CREATE);
+   printf("setxattr %s CREATE: name: %s, value: %s: ret=%d\n",
+   argv[3], argv[1], argv[2], ret);
+   if (ret < 0 && errno == EEXIST) {
+   ret = setxattr(argv[3], argv[1], argv[2], strlen(argv[2]), 
XATTR_REPLACE);
+   printf("setxattr %s REPLACE: name: %s, value: %s: ret=%d\n",
+   argv[3], argv[1], argv[2], ret);
+   }
+   if (ret < 0)
+   perror("setxattr");
+   exit(0);
+}
+
+#define removexattr_desc "removexattr"
+#define removexattr_help "f2fs_io removexattr [name] [file_path]\n\n"
+
+static void do_removexattr(int argc, char **argv, const struct cmd_desc *cmd)
+{
+   int ret;
+
+   if (argc != 3) {
+   fputs("Excess arguments\n\n", stderr);
+   fputs(cmd->cmd_help, stderr);
+   exit(1);
+   }
+
+   ret = removexattr(argv[2], argv[1]);
+   printf("removexattr %s REMOVE: name: %s: ret=%d\n", argv[1], argv[2], 
ret);
+   exit(0);
+}
+
  #define CMD_HIDDEN0x0001
  #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
  #define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -1564,6 +1668,9 @@ const struct cmd_desc cmd_list[] = {
CMD(precache_extents),
CMD(move_range),
CMD(gc_range),
+   CMD(listxattr),
+   CMD(setxattr),
+   CMD(removexattr),
{ NULL, NULL, NULL, NULL, 0 }
  };
  



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 2/2] fsck.f2fs: fix cache offset for multiple partitions

2023-11-14 Thread Chao Yu

On 2023/10/17 5:58, Jaegeuk Kim wrote:

The cache offset should have been considered multiple partitions per fd.
Let's fix.

Signed-off-by: Jaegeuk Kim 


Reviewed-by: Chao Yu 

Thanks,


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 1/2] Revert "f2fs-tools: do not support user-space cache"

2023-11-14 Thread Chao Yu

On 2023/10/17 5:58, Jaegeuk Kim wrote:

This reverts commit 2835107ae3908576b41ff5f6a4e63ba7ec9a6246.

There's a report that the impact was true.

Signed-off-by: Jaegeuk Kim 


Sorry for delay reply, feel free to add:

Reviewed-by: Chao Yu 

Thanks,


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] f2fs: skip adding a discard command if exists

2023-11-14 Thread Chao Yu

On 2023/11/15 10:45, Jaegeuk Kim wrote:

On 11/15, Chao Yu wrote:

On 2023/11/15 5:24, Jaegeuk Kim wrote:

When recovering zoned UFS, sometimes we add the same zone to discard multiple
times. Simple workaround is to bypass adding it.


What about skipping f2fs_bug_on() just for zoned UFS case? so that the check
condition can still be used for non-zoned UFS case.


Hmm, I've never seen this bug_on before, but even this really happens, it does


I've never seen it was been triggered as well.


not make sense to move forward to create duplicate commands resulting in a loop.


Agreed.

It looks those codes were copied from extent_cache code base, do we need to fix
all cases to avoid loop?



So, the question is, do we really need to check this? Have we hit this before?

Not sure, just be worry about that flaw of newly developed feature can make
code run into that branch.

Thanks,





Thanks,



Signed-off-by: Jaegeuk Kim 
---
   fs/f2fs/segment.c | 3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 727d016318f9..f4ffd64b44b2 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1380,7 +1380,8 @@ static void __insert_discard_cmd(struct f2fs_sb_info *sbi,
p = &(*p)->rb_right;
leftmost = false;
} else {
-   f2fs_bug_on(sbi, 1);
+   /* Let's skip to add, if exists */
+   return;
}
}



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] f2fs: skip adding a discard command if exists

2023-11-14 Thread Jaegeuk Kim
On 11/15, Chao Yu wrote:
> On 2023/11/15 5:24, Jaegeuk Kim wrote:
> > When recovering zoned UFS, sometimes we add the same zone to discard 
> > multiple
> > times. Simple workaround is to bypass adding it.
> 
> What about skipping f2fs_bug_on() just for zoned UFS case? so that the check
> condition can still be used for non-zoned UFS case.

Hmm, I've never seen this bug_on before, but even this really happens, it does
not make sense to move forward to create duplicate commands resulting in a loop.

So, the question is, do we really need to check this? Have we hit this before?

> 
> Thanks,
> 
> > 
> > Signed-off-by: Jaegeuk Kim 
> > ---
> >   fs/f2fs/segment.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> > index 727d016318f9..f4ffd64b44b2 100644
> > --- a/fs/f2fs/segment.c
> > +++ b/fs/f2fs/segment.c
> > @@ -1380,7 +1380,8 @@ static void __insert_discard_cmd(struct f2fs_sb_info 
> > *sbi,
> > p = &(*p)->rb_right;
> > leftmost = false;
> > } else {
> > -   f2fs_bug_on(sbi, 1);
> > +   /* Let's skip to add, if exists */
> > +   return;
> > }
> > }


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] f2fs: skip adding a discard command if exists

2023-11-14 Thread Chao Yu

On 2023/11/15 5:24, Jaegeuk Kim wrote:

When recovering zoned UFS, sometimes we add the same zone to discard multiple
times. Simple workaround is to bypass adding it.


What about skipping f2fs_bug_on() just for zoned UFS case? so that the check
condition can still be used for non-zoned UFS case.

Thanks,



Signed-off-by: Jaegeuk Kim 
---
  fs/f2fs/segment.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 727d016318f9..f4ffd64b44b2 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1380,7 +1380,8 @@ static void __insert_discard_cmd(struct f2fs_sb_info *sbi,
p = &(*p)->rb_right;
leftmost = false;
} else {
-   f2fs_bug_on(sbi, 1);
+   /* Let's skip to add, if exists */
+   return;
}
}
  



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH] f2fs: skip adding a discard command if exists

2023-11-14 Thread Jaegeuk Kim
When recovering zoned UFS, sometimes we add the same zone to discard multiple
times. Simple workaround is to bypass adding it.

Signed-off-by: Jaegeuk Kim 
---
 fs/f2fs/segment.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 727d016318f9..f4ffd64b44b2 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1380,7 +1380,8 @@ static void __insert_discard_cmd(struct f2fs_sb_info *sbi,
p = &(*p)->rb_right;
leftmost = false;
} else {
-   f2fs_bug_on(sbi, 1);
+   /* Let's skip to add, if exists */
+   return;
}
}
 
-- 
2.43.0.rc0.421.g78406f8d94-goog



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel