Uploaded image for project: 'Lustre'
  1. Lustre
  2. LU-15743

"lfs find" is missing "-xattr" support

Details

    • 9223372036854775807

    Description

      It would be useful if "lfs find" could check/match xattrs on files.

      This should use "--xattr <name>" to match files that have a <name> xattr, and "--xattr-match <name>=<value>", where <name> and <value> are shell patterns that can match arbitrary text strings in the xattr. The output would be printed in plain text with escaped control characters.

      Attachments

        Issue Links

          Activity

            [LU-15743] "lfs find" is missing "-xattr" support
            adilger Andreas Dilger made changes -
            Link New: This issue is related to LU-18889 [ LU-18889 ]
            pjones Peter Jones made changes -
            Fix Version/s New: Lustre 2.16.0 [ 15190 ]
            Resolution New: Fixed [ 1 ]
            Status Original: Open [ 1 ] New: Resolved [ 5 ]
            pjones Peter Jones added a comment -

            Landed for 2.16

            pjones Peter Jones added a comment - Landed for 2.16

            "Oleg Drokin <green@whamcloud.com>" merged in patch https://review.whamcloud.com/c/fs/lustre-release/+/52804/
            Subject: LU-15743 utils: add --xattr option to lfs find
            Project: fs/lustre-release
            Branch: master
            Current Patch Set:
            Commit: 978ff35d39e3f640a2bfc766b97982012ce07a80

            gerrit Gerrit Updater added a comment - "Oleg Drokin <green@whamcloud.com>" merged in patch https://review.whamcloud.com/c/fs/lustre-release/+/52804/ Subject: LU-15743 utils: add --xattr option to lfs find Project: fs/lustre-release Branch: master Current Patch Set: Commit: 978ff35d39e3f640a2bfc766b97982012ce07a80
            adilger Andreas Dilger made changes -
            Assignee Original: WC Triage [ wc-triage ] New: Thomas Bertschinger [ bertschinger ]

            I had suggested to use regex_comp(..., REG_NOSUB), but I think the pmatch option is best. I think it is non-intuitive to make the user specify '^' or '$' to terminate the regexp.

            adilger Andreas Dilger added a comment - I had suggested to use regex_comp(..., REG_NOSUB) , but I think the pmatch option is best. I think it is non-intuitive to make the user specify ' ^ ' or ' $ ' to terminate the regexp.
            bertschinger Thomas Bertschinger added a comment - - edited

            Andreas, adding a question here instead of on the Gerrit review about the regex matching issue, since it's more of a user interface / design question.

            I'm not really thrilled that the regex is implicitly matching only part of the string for both the name and value, rather than explicitly requiring a wildcard for the remainder.  That makes it harder to match names/values that are subsets of each other, like "system.acl" "system.acl_default" or whatever.
            I would have assumed that it needs a regex "trusted.*" to explicitly match the name of all "trusted.*" xattrs.  Otherwise, it will be harder to match substrings in the xattr name.  I see that this is how getfattr works for "-m", but conversely "find -regex f" does not return all files with "f" in them (not for any regextype), only when "find -regex '.*f.*'" or "find -path '*f*'" is used does that happen.

            It looks like GNU find uses a non-POSIX regex interface from Gnulib, and its matching function re_match returns the number of chars matched. So GNU find accomplishes this with basically

            if (re_match(..., path, ...) == strlen(path))
            ...

            It should be possible to achieve the same result with the POSIX regex interface using the pmatch[] argument to regexec, like this:

            regmatch_t pmatch[1];
            
            regexec(re, input, 1, pmatch, 0);
            if (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == strlen(input)) {
                    /* matched entire input string */
            }

            Alternatively, with the current behavior, matching the entire string could be accomplished by the user with anchors: 

            lfs find --xattr "^user.*$ /mnt/lustre

            This could be documented/suggested in the man page to make it clear to the user if they want this behavior.

            A final option could be to use the Gnulib regex instead of POSIX regex for lfs find, but I'm not sure if that really makes sense.

            What do you think is the best option?

            bertschinger Thomas Bertschinger added a comment - - edited Andreas, adding a question here instead of on the Gerrit review about the regex matching issue, since it's more of a user interface / design question. I'm not really thrilled that the regex is implicitly matching only part of the string for both the name and value, rather than explicitly requiring a wildcard for the remainder.  That makes it harder to match names/values that are subsets of each other, like "system.acl" "system.acl_default" or whatever. I would have assumed that it needs a regex "trusted.*" to explicitly match the name of all "trusted.*" xattrs.  Otherwise, it will be harder to match substrings in the xattr name.  I see that this is how getfattr works for "-m", but conversely "find -regex f" does not return all files with "f" in them (not for any regextype), only when " find -regex '.*f.*' " or " find -path '*f*' " is used does that happen. It looks like GNU find uses a non-POSIX regex interface from Gnulib, and its matching function re_match returns the number of chars matched. So GNU find accomplishes this with basically if (re_match(..., path, ...) == strlen(path)) ... It should be possible to achieve the same result with the POSIX regex interface using the pmatch[] argument to regexec, like this: regmatch_t pmatch[1]; regexec(re, input, 1, pmatch, 0); if (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == strlen(input)) { /* matched entire input string */ } Alternatively, with the current behavior, matching the entire string could be accomplished by the user with anchors:  lfs find --xattr "^user.*$ /mnt/lustre This could be documented/suggested in the man page to make it clear to the user if they want this behavior. A final option could be to use the Gnulib regex instead of POSIX regex for lfs find, but I'm not sure if that really makes sense. What do you think is the best option?

            There is a prototype patch for "GNU find" at https://gitlab.com/mweetman/findutils that adds "-xattr" support. According to the find.1 man page in that patch, the "-xattr PATTERN" option takes a regular expression for PATTERN by default, but it also allows the "-regextype TYPE" option to change the regular expression type to one of emacs, posix-awk, posix-basic, posix-egrep, and posix-extended. I don't think there is any urgent need for this, since "lfs find" implements neither the "-path" or "-regex" tests.

            adilger Andreas Dilger added a comment - There is a prototype patch for "GNU find" at https://gitlab.com/mweetman/findutils that adds " -xattr " support. According to the find.1 man page in that patch, the " -xattr PATTERN " option takes a regular expression for PATTERN by default, but it also allows the " -regextype TYPE " option to change the regular expression type to one of emacs , posix-awk , posix-basic , posix-egrep , and posix-extended . I don't think there is any urgent need for this, since " lfs find " implements neither the " -path " or " -regex " tests.
            bertschinger Thomas Bertschinger made changes -
            Link New: This issue is related to LU-17219 [ LU-17219 ]

            "Thomas Bertschinger <bertschinger@lanl.gov>" uploaded a new patch: https://review.whamcloud.com/c/fs/lustre-release/+/52804
            Subject: LU-15743 utils: add --xattr option to lfs find
            Project: fs/lustre-release
            Branch: master
            Current Patch Set: 1
            Commit: ab05f6780984bf74487cb284ec85bfcf31991d60

            gerrit Gerrit Updater added a comment - "Thomas Bertschinger <bertschinger@lanl.gov>" uploaded a new patch: https://review.whamcloud.com/c/fs/lustre-release/+/52804 Subject: LU-15743 utils: add --xattr option to lfs find Project: fs/lustre-release Branch: master Current Patch Set: 1 Commit: ab05f6780984bf74487cb284ec85bfcf31991d60

            People

              bertschinger Thomas Bertschinger
              adilger Andreas Dilger
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: