coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "ls -l": Avoid unnecessary getxattr() overhead


From: Pádraig Brady
Subject: Re: "ls -l": Avoid unnecessary getxattr() overhead
Date: Fri, 17 Feb 2012 11:26:30 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110816 Thunderbird/6.0

On 02/16/2012 07:39 PM, Jim Meyering wrote:

> diff --git a/src/ls.c b/src/ls.c

> +/* st_dev of the most recently processed device for which
> +   we've found that getfilecon or lgetfilecon fails with
> +   e.g., ENOTSUP or EOPNOTSUPP.  */
> +static dev_t selinux_challenged_device;
> +
> +/* Cache getfilecon failure, when it's trivial to do.
> +   Like getfilecon, but when F's st_dev says it's on a known-
> +   SELinux-challenged file system, fail with ENOTSUP immediately.  */
> +static int
> +getfilecon_cache (char const *file, struct fileinfo *f)
> +{
> +  if (f->stat.st_dev == selinux_challenged_device)
> +    {
> +      errno = ENOTSUP;
> +      return -1;
> +    }
> +  int r = getfilecon (file, &f->scontext);
> +  if (r < 0 && errno_unsupported (errno))
> +    selinux_challenged_device = f->stat.st_dev;
> +  return r;
> +}
> +
> +/* Cache lgetfilecon failure, when it's trivial to do.
> +   Like lgetfilecon, but when F's st_dev says it's on a known-
> +   SELinux-challenged file system, fail with ENOTSUP immediately.  */
> +static int
> +lgetfilecon_cache (char const *file, struct fileinfo *f)
> +{
> +  if (f->stat.st_dev == selinux_challenged_device)
> +    {
> +      errno = ENOTSUP;
> +      return -1;
> +    }
> +  int r = lgetfilecon (file, &f->scontext);
> +  if (r < 0 && errno_unsupported (errno))
> +    selinux_challenged_device = f->stat.st_dev;
> +  return r;
> +}

I'd be inclined to refactor the above 2 functions to one like:

static int
getfilecon_cache (char const *file, struct fileinfo *f, bool do_deref)
{
  /* st_dev of the most recently processed device for which we've
     found that [l]getfilecon fails indicating lack of support.  */
  static dev_t unsupported_device;

  if (f->stat.st_dev == unsupported_device)
    {
      errno = ENOTSUP;
      return -1;
    }
  int r = (do_deref ? getfilecon : lgetfilecon) (file, &f->scontext);
  if (r < 0 && errno_unsupported (errno))
    unsupported_device = f->stat.st_dev;
  return r;
}

>>From 796b05173ad9d34a3403e2201152a1a81fd973a1 Mon Sep 17 00:00:00 2001
> From: Jim Meyering <address@hidden>
> Date: Mon, 13 Feb 2012 12:05:40 +0100
> Subject: [PATCH 2/3] ls: also cache ACL- and CAP-querying syscall failures

patch series are not apparent in git shortlog summaries etc.,
so I'd s/also//

looks good!

cheers,
Pádraig.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]