From a3cbe7cd0c768c5744ae89ca9c348de6c1eabdc2 Mon Sep 17 00:00:00 2001 From: Mandy Kirkconnell Date: Fri, 13 Feb 2004 19:12:27 +0000 Subject: [PATCH] Some of the libhandle routines were not clear whether they were working on fshandles or file handles. This mod renames open_by_handle() to open_by_fshandle() and updates any calling applications to now call open_by_fshandle() instead. A new open_by_handle() has been created. path_to_fshandle() was trying to maintain a hash of fshandles but the hash was only storing a max of 2 fshandles at a time. This has been fixed so the hash can hold multiple fs handles. define open_by_fshandle() --- include/handle.h | 3 ++- libhandle/handle.c | 64 +++++++++++++++++++++++++++++++++++++--------- libhandle/jdm.c | 4 +-- 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/include/handle.h b/include/handle.h index 91357d278..51839a9a6 100644 --- a/include/handle.h +++ b/include/handle.h @@ -41,10 +41,11 @@ struct fsdmidata; struct attrlist_cursor; extern int path_to_handle (char *__path, void **__hanp, size_t *__hlen); -extern int path_to_fshandle (char *__path, void **__hanp, size_t *__hlen); +extern int path_to_fshandle (char *__path, void **__fshanp, size_t *__fshlen); extern int handle_to_fshandle (void *__hanp, size_t __hlen, void **__fshanp, size_t *__fshlen); extern void free_handle (void *__hanp, size_t __hlen); +extern int open_by_fshandle (void *__fshanp, size_t __fshlen, int __rw); extern int open_by_handle (void *__hanp, size_t __hlen, int __rw); extern int readlink_by_handle (void *__hanp, size_t __hlen, void *__buf, size_t __bs); diff --git a/libhandle/handle.c b/libhandle/handle.c index dd6949bec..3b5f8ea61 100644 --- a/libhandle/handle.c +++ b/libhandle/handle.c @@ -80,13 +80,14 @@ static struct fdhash *fdhash_head; int path_to_fshandle( char *path, /* input, path to convert */ - void **hanp, /* output, pointer to data */ - size_t *hlen) /* output, size of returned data */ + void **fshanp, /* output, pointer to data */ + size_t *fshlen) /* output, size of returned data */ { int result; int fd; comarg_t obj; struct fdhash *fdhp; + struct fdhash *tmphp=NULL; fd = open(path, O_RDONLY); if (fd < 0) @@ -94,7 +95,7 @@ path_to_fshandle( obj.path = path; result = obj_to_handle(path, fd, XFS_IOC_PATH_TO_FSHANDLE, - obj, hanp, hlen); + obj, fshanp, fshlen); if (result >= 0) { fdhp = malloc(sizeof(struct fdhash)); if (fdhp == NULL) { @@ -105,12 +106,22 @@ path_to_fshandle( fdhp->fsfd = fd; fdhp->fnxt = NULL; strncpy(fdhp->fspath, path, sizeof(fdhp->fspath)); - memcpy(fdhp->fsh, *hanp, FSIDSIZE); - - if (fdhash_head) - fdhash_head->fnxt = fdhp; - else - fdhash_head = fdhp; + 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; + } } return result; @@ -210,17 +221,46 @@ obj_to_handle( return 0; } +int +open_by_fshandle( + void *fshanp, + size_t fshlen, + int rw) +{ + int fsfd; + char *path; + xfs_fsop_handlereq_t hreq; + + if ((fsfd = handle_to_fsfd(fshanp, &path)) < 0) + return -1; + + hreq.fd = 0; + hreq.path = NULL; + hreq.oflags = rw | O_LARGEFILE; + hreq.ihandle = fshanp; + hreq.ihandlen = fshlen; + hreq.ohandle = NULL; + hreq.ohandlen = NULL; + + return xfsctl(path, fsfd, XFS_IOC_OPEN_BY_HANDLE, &hreq); +} + int open_by_handle( void *hanp, size_t hlen, int rw) { - int fd; + int fsfd; char *path; + void *fshanp; + size_t fshlen; xfs_fsop_handlereq_t hreq; - if ((fd = handle_to_fsfd(hanp, &path)) < 0) + if (handle_to_fshandle(hanp, hlen, &fshanp, &fshlen) != 0) + return -1; + + if ((fsfd = handle_to_fsfd(fshanp, &path)) < 0) return -1; hreq.fd = 0; @@ -231,7 +271,7 @@ open_by_handle( hreq.ohandle = NULL; hreq.ohandlen = NULL; - return xfsctl(path, fd, XFS_IOC_OPEN_BY_HANDLE, &hreq); + return xfsctl(path, fsfd, XFS_IOC_OPEN_BY_HANDLE, &hreq); } int diff --git a/libhandle/jdm.c b/libhandle/jdm.c index c93a3988d..7a6f14ed4 100644 --- a/libhandle/jdm.c +++ b/libhandle/jdm.c @@ -45,7 +45,7 @@ typedef struct fshandle { char fsh_space[FSHANDLE_SZ]; } fshandle_t; -/* private file handle - for use by open_by_handle */ +/* private file handle - for use by open_by_fshandle */ #define FILEHANDLE_SZ 24 #define FILEHANDLE_SZ_FOLLOWING 14 #define FILEHANDLE_SZ_PAD 2 @@ -134,7 +134,7 @@ jdm_open( jdm_fshandle_t *fshp, xfs_bstat_t *statp, intgen_t oflags ) intgen_t fd; jdm_fill_filehandle( &filehandle, fshandlep, statp ); - fd = open_by_handle( ( void * )&filehandle, + fd = open_by_fshandle( ( void * )&filehandle, sizeof( filehandle ), oflags ); return fd; -- 2.47.2