libuafs-updates-20081229
authorAndrew Deason <adeason@sinenomine.net>
Mon, 29 Dec 2008 21:26:00 +0000 (21:26 +0000)
committerDerrick Brashear <shadow@dementia.org>
Mon, 29 Dec 2008 21:26:00 +0000 (21:26 +0000)
LICENSE IPL10
FIXES 124072

adds ATTR_* constants for UKERNEL code, and makes use
of them. Without this in some cases updating file metadata will also
update unrelated metadata (e.g. truncating a file changes the mode
bits).

adds threadsafe positional i/o calls to
afs_usrops.c: uafs_pwrite and uafs_pread, allowing for threadsafe
libuafs i/o.

changes the types of some fs-related
variables to be more "correct", I think (off_t for offsets, mode_t for
file mode, etc), it fixes a bug where nDaemons is not correctly set from
the uafs_Init parameter, fixes a segfault in uafs_open when O_CREAT is
specified, initializes a couple of static vars, "#if 0"s out code that
copies tokens from kernel-space to user-space (doesn't seem to work from
what I've seen, and the current code crashes on clientless Solaris
machines from being killed by SIGSYS)

src/afs/UKERNEL/afs_usrops.c
src/afs/UKERNEL/afs_usrops.h
src/afs/UKERNEL/sysincludes.h
src/afs/VNOPS/afs_vnop_attrs.c
src/afs/VNOPS/afs_vnop_create.c

index 0352b94..7ae78e9 100644 (file)
@@ -56,7 +56,7 @@ char afs_LclCellName[64];
 
 struct usr_vnode *afs_FileTable[MAX_OSI_FILES];
 int afs_FileFlags[MAX_OSI_FILES];
-int afs_FileOffsets[MAX_OSI_FILES];
+off_t afs_FileOffsets[MAX_OSI_FILES];
 
 #define MAX_CACHE_LOOPS 4
 
@@ -107,8 +107,8 @@ int usr_udpcksum = 0;
 
 usr_key_t afs_global_u_key;
 
-struct usr_proc *afs_global_procp;
-struct usr_ucred *afs_global_ucredp;
+struct usr_proc *afs_global_procp = NULL;
+struct usr_ucred *afs_global_ucredp = NULL;
 struct usr_sysent usr_sysent[200];
 
 #ifdef AFS_USR_OSF_ENV
@@ -1561,7 +1561,7 @@ uafs_Init(char *rn, char *mountDirParam, char *confDirParam,
        cacheStatEntries = cacheStatEntriesParam;
     }
     strcpy(cacheBaseDir, cacheBaseDirParam);
-    if (nDaemons != 0) {
+    if (nDaemonsParam != 0) {
        nDaemons = nDaemonsParam;
     } else {
        nDaemons = 3;
@@ -1846,7 +1846,11 @@ uafs_Init(char *rn, char *mountDirParam, char *confDirParam,
                         (long)pathname_for_V[currVFile], 0, 0, 0);
        }
     /*end for */
-#ifndef NETSCAPE_NSAPI
+/*#ifndef NETSCAPE_NSAPI*/
+#if 0
+/* this breaks solaris if the kernel-mode client has never been installed,
+ * and it doesn't seem to work now anyway, so just disable it */
+
     /*
      * Copy our tokens from the kernel to the user space client
      */
@@ -2691,6 +2695,7 @@ uafs_open_r(char *path, int flags, int mode)
                errno = code;
                return -1;
            }
+           fileP = AFSTOV(vc);
        } else {
            fileP = NULL;
            code = uafs_LookupName(nameP, dirP, &fileP, 1, 0);
@@ -2763,6 +2768,7 @@ uafs_open_r(char *path, int flags, int mode)
      */
     if ((flags & O_TRUNC) && (attrs.va_size != 0)) {
        usr_vattr_null(&attrs);
+       attrs.va_mask = ATTR_SIZE;
        attrs.va_size = 0;
        code = afs_setattr(VTOAFS(fileP), &attrs, u.u_cred);
        if (code != 0) {
@@ -2834,13 +2840,23 @@ uafs_write(int fd, char *buf, int len)
 {
     int retval;
     AFS_GLOCK();
-    retval = uafs_write_r(fd, buf, len);
+    retval = uafs_pwrite_r(fd, buf, len, afs_FileOffsets[fd]);
+    AFS_GUNLOCK();
+    return retval;
+}
+
+int
+uafs_pwrite(int fd, char *buf, int len, off_t offset)
+{
+    int retval;
+    AFS_GLOCK();
+    retval = uafs_pwrite_r(fd, buf, len, offset);
     AFS_GUNLOCK();
     return retval;
 }
 
 int
-uafs_write_r(int fd, char *buf, int len)
+uafs_pwrite_r(int fd, char *buf, int len, off_t offset)
 {
     int code;
     struct usr_uio uio;
@@ -2863,7 +2879,7 @@ uafs_write_r(int fd, char *buf, int len)
     iov[0].iov_len = len;
     uio.uio_iov = &iov[0];
     uio.uio_iovcnt = 1;
-    uio.uio_offset = afs_FileOffsets[fd];
+    uio.uio_offset = offset;
     uio.uio_segflg = 0;
     uio.uio_fmode = FWRITE;
     uio.uio_resid = len;
@@ -2890,13 +2906,23 @@ uafs_read(int fd, char *buf, int len)
 {
     int retval;
     AFS_GLOCK();
-    retval = uafs_read_r(fd, buf, len);
+    retval = uafs_pread_r(fd, buf, len, afs_FileOffsets[fd]);
+    AFS_GUNLOCK();
+    return retval;
+}
+
+int
+uafs_pread(int fd, char *buf, int len, off_t offset)
+{
+    int retval;
+    AFS_GLOCK();
+    retval = uafs_pread_r(fd, buf, len, offset);
     AFS_GUNLOCK();
     return retval;
 }
 
 int
-uafs_read_r(int fd, char *buf, int len)
+uafs_pread_r(int fd, char *buf, int len, off_t offset)
 {
     int code;
     struct usr_uio uio;
@@ -2920,7 +2946,7 @@ uafs_read_r(int fd, char *buf, int len)
     iov[0].iov_len = len;
     uio.uio_iov = &iov[0];
     uio.uio_iovcnt = 1;
-    uio.uio_offset = afs_FileOffsets[fd];
+    uio.uio_offset = offset;
     uio.uio_segflg = 0;
     uio.uio_fmode = FREAD;
     uio.uio_resid = len;
@@ -3104,6 +3130,7 @@ uafs_chmod_r(char *path, int mode)
        return -1;
     }
     usr_vattr_null(&attrs);
+    attrs.va_mask = ATTR_MODE;
     attrs.va_mode = mode;
     code = afs_setattr(VTOAFS(vp), &attrs, u.u_cred);
     VN_RELE(vp);
@@ -3140,6 +3167,7 @@ uafs_fchmod_r(int fd, int mode)
        return -1;
     }
     usr_vattr_null(&attrs);
+    attrs.va_mask = ATTR_MODE;
     attrs.va_mode = mode;
     code = afs_setattr(VTOAFS(vp), &attrs, u.u_cred);
     if (code != 0) {
@@ -3175,6 +3203,7 @@ uafs_truncate_r(char *path, int length)
        return -1;
     }
     usr_vattr_null(&attrs);
+    attrs.va_mask = ATTR_SIZE;
     attrs.va_size = length;
     code = afs_setattr(VTOAFS(vp), &attrs, u.u_cred);
     VN_RELE(vp);
@@ -3211,6 +3240,7 @@ uafs_ftruncate_r(int fd, int length)
        return -1;
     }
     usr_vattr_null(&attrs);
+    attrs.va_mask = ATTR_SIZE;
     attrs.va_size = length;
     code = afs_setattr(VTOAFS(vp), &attrs, u.u_cred);
     if (code != 0) {
index a806e5a..d475fe5 100644 (file)
@@ -61,7 +61,7 @@ extern struct usr_vnode *afs_RootVnode;
 extern struct usr_vnode *afs_CurrentDir;
 extern struct usr_vnode *afs_FileTable[];
 extern int afs_FileFlags[];
-extern int afs_FileOffsets[];
+extern off_t afs_FileOffsets[];
 
 extern char afs_mountDir[];
 extern int afs_mountDirLen;
@@ -90,9 +90,11 @@ extern int uafs_open_r(char *path, int flags, int mode);
 extern int uafs_creat(char *path, int mode);
 extern int uafs_creat_r(char *path, int mode);
 extern int uafs_write(int fd, char *buf, int len);
-extern int uafs_write_r(int fd, char *buf, int len);
+extern int uafs_pwrite(int fd, char *buf, int len, off_t offset);
+extern int uafs_pwrite_r(int fd, char *buf, int len, off_t offset);
 extern int uafs_read(int fd, char *buf, int len);
-extern int uafs_read_r(int fd, char *buf, int len);
+extern int uafs_pread(int fd, char *buf, int leni, off_t offset);
+extern int uafs_pread_r(int fd, char *buf, int len, off_t offset);
 extern int uafs_fsync(int fd);
 extern int uafs_fsync_r(int fd);
 extern int uafs_close(int fd);
index 7a1e118..499d1e3 100644 (file)
@@ -1017,22 +1017,28 @@ struct usr_statfs {
     unsigned long f_files;
 };
 
+#define ATTR_MODE      (1 << 0)
+#define ATTR_UID       (1 << 1)
+#define ATTR_GID       (1 << 2)
+#define ATTR_MTIME     (1 << 3)
+#define ATTR_SIZE      (1 << 4)
+
 struct usr_vattr {
-    long va_mask;
+    int va_mask;       /* bitmask of ATTR_* values above */
     usr_vtype_t va_type;
-    unsigned short va_mode;
-    long va_uid;
-    long va_gid;
-    unsigned long va_fsid;
-    unsigned long va_nodeid;
-    unsigned long va_nlink;
-    unsigned long va_size;
+    mode_t va_mode;
+    uid_t va_uid;
+    gid_t va_gid;
+    int va_fsid;
+    ino_t va_nodeid;
+    nlink_t va_nlink;
+    afs_size_t va_size;
     struct timeval va_atime;
     struct timeval va_mtime;
     struct timeval va_ctime;
-    unsigned long va_rdev;
+    dev_t va_rdev;
     unsigned long va_blocksize;
-    unsigned long va_blocks;
+    blkcnt_t va_blocks;
     unsigned long va_vcode;
 };
 
index cd0ddb9..36606aa 100644 (file)
@@ -352,7 +352,7 @@ afs_VAttrToAS(register struct vcache *avc, register struct vattr *av,
 #elif  defined(AFS_AIX_ENV)
 /* Boy, was this machine dependent bogosity hard to swallow????.... */
     if (av->va_mode != -1) {
-#elif  defined(AFS_LINUX22_ENV)
+#elif  defined(AFS_LINUX22_ENV) || defined(UKERNEL)
     if (av->va_mask & ATTR_MODE) {
 #elif  defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
     if (av->va_mask & AT_MODE) {
@@ -371,7 +371,7 @@ afs_VAttrToAS(register struct vcache *avc, register struct vattr *av,
     }
 #if     defined(AFS_DARWIN80_ENV)
     if (VATTR_IS_ACTIVE(av, va_gid)) {
-#elif defined(AFS_LINUX22_ENV)
+#elif defined(AFS_LINUX22_ENV) || defined(UKERNEL)
     if (av->va_mask & ATTR_GID) {
 #elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
     if (av->va_mask & AT_GID) {
@@ -391,7 +391,7 @@ afs_VAttrToAS(register struct vcache *avc, register struct vattr *av,
     }
 #if     defined(AFS_DARWIN80_ENV)
     if (VATTR_IS_ACTIVE(av, va_uid)) {
-#elif defined(AFS_LINUX22_ENV)
+#elif defined(AFS_LINUX22_ENV) || defined(UKERNEL)
     if (av->va_mask & ATTR_UID) {
 #elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
     if (av->va_mask & AT_UID) {
@@ -411,7 +411,7 @@ afs_VAttrToAS(register struct vcache *avc, register struct vattr *av,
     }
 #if     defined(AFS_DARWIN80_ENV)
     if (VATTR_IS_ACTIVE(av, va_modify_time)) {
-#elif  defined(AFS_LINUX22_ENV)
+#elif  defined(AFS_LINUX22_ENV) || defined(UKERNEL)
     if (av->va_mask & ATTR_MTIME) {
 #elif  defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
     if (av->va_mask & AT_MTIME) {
@@ -492,7 +492,7 @@ afs_setattr(OSI_VC_DECL(avc), register struct vattr *attrs,
      */
 #if    defined(AFS_DARWIN80_ENV)
     if (VATTR_IS_ACTIVE(attrs, va_data_size)) {
-#elif  defined(AFS_LINUX22_ENV)
+#elif  defined(AFS_LINUX22_ENV) || defined(UKERNEL)
     if (attrs->va_mask & ATTR_SIZE) {
 #elif  defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
     if (attrs->va_mask & AT_SIZE) {
@@ -530,14 +530,16 @@ afs_setattr(OSI_VC_DECL(avc), register struct vattr *attrs,
 #endif
 #if    defined(AFS_DARWIN80_ENV)
     if (VATTR_IS_ACTIVE(attrs, va_data_size)) {
-#elif  defined(AFS_LINUX22_ENV)
+#elif  defined(AFS_LINUX22_ENV) || defined(UKERNEL)
     if (attrs->va_mask & ATTR_SIZE) {
 #elif  defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
     if (attrs->va_mask & AT_SIZE) {
 #elif  defined(AFS_OSF_ENV) || defined(AFS_XBSD_ENV)
     if (attrs->va_size != VNOVAL) {
-#else
+#elif  defined(AFS_AIX41_ENV)
     if (attrs->va_size != -1) {
+#else
+    if (attrs->va_size != ~0) {
 #endif
        afs_size_t tsize = attrs->va_size;
        ObtainWriteLock(&avc->lock, 128);
index 1f97465..5602e0d 100644 (file)
@@ -224,6 +224,8 @@ afs_create(OSI_VC_DECL(adp), char *aname, struct vattr *attrs,
                    VATTR_INIT(attrs);
                    VATTR_SET_SUPPORTED(attrs, va_data_size);
                    VATTR_SET_ACTIVE(attrs, va_data_size);
+#elif defined(UKERNEL)
+                   attrs->va_mask = ATTR_SIZE;
 #elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
                    attrs->va_mask = AT_SIZE;
 #else