]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
- Fix file descriptor leak in path_to_fshandle. It now caches
authorBill Kendall <wkendall@sgi.com>
Thu, 15 Apr 2004 19:42:58 +0000 (19:42 +0000)
committerBill Kendall <wkendall@sgi.com>
Thu, 15 Apr 2004 19:42:58 +0000 (19:42 +0000)
one descriptor per filesystem.
- In xfsrestore, always allocate a fs handle during content_init.
This allows us to not have to call path_to_fshandle before attempting
every open_by_handle.
- Change open_by_fshandle to open_by_handle is cases where we are
passing a file handle (instead of a fshandle).
path_to_fshandle was opening a file and never closing it. We now close it
unless the descriptor is to be used in the descriptor cache. One descriptor
is cached for each unique filesystem that path_to_fshandle is called on.

VERSION
doc/CHANGES
libhandle/handle.c

diff --git a/VERSION b/VERSION
index 4fedc4dde9e1080f1a9c1daa391ebc16fa0eb7b2..bff762b5eea8f51842216eb40ff5a29020bc517c 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -3,5 +3,5 @@
 #
 PKG_MAJOR=2
 PKG_MINOR=6
-PKG_REVISION=10
+PKG_REVISION=11
 PKG_BUILD=1
index b8aa080c722c4f5fd52f9a5b5b66ccdb3ce2c0e1..aab83e034b6ef59b8619817fbcda40facd8d6322 100644 (file)
@@ -1,4 +1,10 @@
-xfsprogs-2.6.10 (05 April 2003)
+xfsprogs-2.6.11 (15 April 2004)
+       - Fix file descriptor leak in path_to_fshandle. A file
+         was being opened but never closed, regardless of
+         whether that descriptor was being cached. Now close
+         the file on error or if it is not being cached.
+
+xfsprogs-2.6.10 (05 April 2004)
        - Fix botch in recent addition of new superblock field
          (features2) which could result in filesystems with v2
          logs being created with invalid superblock fields.
@@ -9,10 +15,10 @@ xfsprogs-2.6.10 (05 April 2003)
          duplicate filesystem (the log is duplicated too now in
          that case, whereas previously a fresh log was created).
 
-xfsprogs-2.6.9 (26 March 2003)
+xfsprogs-2.6.9 (26 March 2004)
        - Update HFILES in xfsprogs/io/Makefile to package io/io.h
 
-xfsprogs-2.6.8 (25 March 2003)
+xfsprogs-2.6.8 (25 March 2004)
        - Fix xfs_db when dumping v2 dirs larger than the fsb size.
        - Several xfs_io additions - support for memory mapped areas,
          multiple open files, expert mode (freeze, shutdown, error
@@ -21,7 +27,7 @@ xfsprogs-2.6.8 (25 March 2003)
        - Fix xfs_bmap verbose mode stripe alignment information.
        - Fix typo on xfs(5) man page.
 
-xfsprogs-2.6.7 (19 March 2003)
+xfsprogs-2.6.7 (19 March 2004)
        - Fix up UUID library checks again, previous fix didn't work
          for older versions of autconf.
        - Allow for future extensions to the XFS ondisk structure by
@@ -35,7 +41,7 @@ xfsprogs-2.6.7 (19 March 2003)
          the device blocksize, this generates an error when target
          filesystem is mounted readonly.
 
-xfsprogs-2.6.6 (03 March 2003)
+xfsprogs-2.6.6 (03 March 2004)
        - mkfs now opens the devices it's operating on with the
          O_EXCL flag set, which is used by the Linux 2.6 block
          layer to ensure concurrent access does not happen.
@@ -44,17 +50,17 @@ xfsprogs-2.6.6 (03 March 2003)
        - Fix configure scripts to also search for a UUID library
          in /usr/lib64 which is its home on AMD64/x86_64.
 
-xfsprogs-2.6.5 (20 February 2003)
+xfsprogs-2.6.5 (20 February 2004)
        - Fix up mkfs to ensure that the log size is a multiple of
          the v2 log stripe size even if the log happens to be aligned
          on a log stripe boundary (always check it).
 
-xfsprogs-2.6.4 (17 February 2003)
+xfsprogs-2.6.4 (17 February 2004)
        - Fix a few more libxfs/repair leaks.
        - Fix up some libhandle routines, add the open_by_fshandle
          routine required by recent versions of xfsdump.
 
-xfsprogs-2.6.3 (19 January 2003)
+xfsprogs-2.6.3 (19 January 2004)
        - Merge Steve Langasek's work on the Debian installer
          support for xfsprogs.
        - Add knowledge to xfs_db about the security namespace in
index 3b5f8ea61cec5085a4cfb7255e6cc3802ad9d151..f93ac2f4c6340800bdca8064e4b211f21adf8fb8 100644 (file)
@@ -75,7 +75,7 @@ struct fdhash {
        char    fspath[MAXPATHLEN];
 };
 
-static struct fdhash *fdhash_head;
+static struct fdhash *fdhash_head = NULL;
 
 int
 path_to_fshandle(
@@ -87,7 +87,7 @@ path_to_fshandle(
        int             fd;
        comarg_t        obj;
        struct fdhash   *fdhp;
-       struct fdhash   *tmphp=NULL;
+       char            *tmppath;
 
        fd = open(path, O_RDONLY);
        if (fd < 0)
@@ -96,7 +96,16 @@ path_to_fshandle(
        obj.path = path;
        result = obj_to_handle(path, fd, XFS_IOC_PATH_TO_FSHANDLE,
                                obj, fshanp, fshlen);
-       if (result >= 0) {
+       if (result < 0) {
+               close(fd);
+               return result;
+       }
+               
+       if (handle_to_fsfd(*fshanp, &tmppath) >= 0) {
+               /* this filesystem is already in the cache */
+               close(fd);
+       } else {
+               /* new filesystem. add it to the cache */
                fdhp = malloc(sizeof(struct fdhash));
                if (fdhp == NULL) {
                        errno = ENOMEM;
@@ -104,24 +113,11 @@ path_to_fshandle(
                }
 
                fdhp->fsfd = fd;
-               fdhp->fnxt = NULL;
                strncpy(fdhp->fspath, path, sizeof(fdhp->fspath));
                memcpy(fdhp->fsh, *fshanp, FSIDSIZE);
 
-               if (fdhash_head) {
-                       for( tmphp=fdhash_head; tmphp; tmphp=tmphp->fnxt ) {
-                               if ( fdhp->fsfd == tmphp->fsfd ) {
-                                       free (fdhp);     /* already in hash */
-                                       break;
-                               }
-                       }
-                       if (tmphp == NULL) {     /* not in hash, add it now */
-                               fdhp->fnxt = fdhash_head;
-                               fdhash_head = fdhp;
-                       }
-               } else {
-                       fdhash_head = fdhp;
-               }
+               fdhp->fnxt = fdhash_head;
+               fdhash_head = fdhp;
        }
 
        return result;
@@ -155,11 +151,15 @@ handle_to_fshandle(
        void            **fshanp,
        size_t          *fshlen)
 {
-       if (hlen < FSIDSIZE)
-               return EINVAL;
+       if (hlen < FSIDSIZE) {
+               errno = EINVAL;
+               return -1;
+       }
        *fshanp = malloc(FSIDSIZE);
-       if (*fshanp == NULL)
-               return ENOMEM;
+       if (*fshanp == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
        *fshlen = FSIDSIZE;
        memcpy(*fshanp, hanp, FSIDSIZE);
        return 0;