xfs
[Top] [All Lists]

Re: [PATCH 12/14 v2] xfsprogs: make fsr use mntinfo when there is no mnt

To: Jan Tulak <jtulak@xxxxxxxxxx>
Subject: Re: [PATCH 12/14 v2] xfsprogs: make fsr use mntinfo when there is no mntent
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Tue, 13 Oct 2015 15:54:42 +1100
Cc: xfs@xxxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1443542653-10525-1-git-send-email-jtulak@xxxxxxxxxx>
References: <1442311164-12921-13-git-send-email-jtulak@xxxxxxxxxx> <1443542653-10525-1-git-send-email-jtulak@xxxxxxxxxx>
User-agent: Mutt/1.5.21 (2010-09-15)
On Tue, Sep 29, 2015 at 06:04:13PM +0200, Jan Tulak wrote:
> UPDATE:
> - refactor ifdefs to platform_ functions
> 
> For what fsr needs, mntinfo can be used instead of mntent on some
> platforms. Exctract the platform-specific code to platform headers.
> 
> Signed-off-by: Jan Tulak <jtulak@xxxxxxxxxx>

I haven't commited this patch - I think it still needs some work
to clean up....

>  static void
>  initallfs(char *mtab)
>  {
> -     FILE *fp;
>       struct mntent *mp;
>       int mi;
>       char *cp;
>       struct stat64 sb;
>  
> -     fp = setmntent(mtab, "r");
> -     if (fp == NULL) {
> -             fsrprintf(_("could not open mtab file: %s\n"), mtab);
> -             exit(1);
> -     }
> -
>       /* malloc a number of descriptors, increased later if needed */
>       if (!(fsbase = (fsdesc_t *)malloc(fsbufsize * sizeof(fsdesc_t)))) {
>               fsrprintf(_("out of memory: %s\n"), strerror(errno));
> @@ -427,7 +425,36 @@ initallfs(char *mtab)
>       /* find all rw xfs file systems */
>       mi = 0;
>       fs = fsbase;
> +
> +#if defined(HAVE_GETMNTENT)
> +     FILE *fp;
> +     fp = setmntent(mtab, "r");
> +     if (fp == NULL) {
> +             fsrprintf(_("could not open mtab file: %s\n"), mtab);
> +             exit(1);
> +     }
> +
>       while ((mp = getmntent(fp))) {
> +#elif defined(HAVE_GETMNTINFO)
> +     struct statfs   *stats;
> +     int error, i, count;
> +     // because "t" is a pointer, but we don't need to use
> +     // malloc for this usage
> +     struct mntent mp_tmp;
> +     mp = &mp_tmp;
> +     error = 0;
> +     if ((count = getmntinfo(&stats, 0)) < 0) {
> +             fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
> +                             progname, strerror(errno));
> +             exit(1);
> +     }
> +
> +     for (i = 0; i < count; i++) {
> +             mntinfo2mntent(&stats[i], mp);
> +#else
> +# error "How do I extract info about mounted filesystems on this platform?"
> +#endif

this stuff here. This iteration should be able to be done via the
cursor abstraction, such as by keeping the iteration information
within the cursor...

Cheers,

Dave.
-- 
Dave Chinner
david@xxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>