#define VICE_ALWAYSATTACH_FILE "AlwaysAttach"
#endif
-#ifdef AFS_DEMAND_ATTACH_FS
-
/**
* abstraction for files used for file-locking.
*/
struct VLockFile {
FD_t fd; /**< fd holding the lock(s) */
char *path; /**< path to the lock file */
+ int refcount; /**< how many locks we have on the file */
+#ifdef AFS_PTHREAD_ENV
pthread_mutex_t mutex; /**< lock for the VLockFile struct */
- int refcount; /**< how many locks we have on the file */
+#endif /* AFS_PTHREAD_ENV */
};
+#ifdef AFS_DEMAND_ATTACH_FS
/*
* flag bits for 'flags' in struct VDiskLock.
*/
char **namep);
extern char *vol_DevName(dev_t adev, char *wpath);
+struct VLockFile;
+extern void VLockFileInit(struct VLockFile *lf, const char *path);
+extern int VLockFileLock(struct VLockFile *lf, afs_uint32 offset,
+ int locktype, int nonblock);
+extern void VLockFileUnlock(struct VLockFile *lf, afs_uint32 offset);
+
#ifdef AFS_DEMAND_ATTACH_FS
extern Volume *VPreAttachVolumeByName(Error * ec, char *partition, char *name);
extern Volume *VPreAttachVolumeByName_r(Error * ec, char *partition, char *name);
extern int VChildProcReconnectFS_r(void);
extern void VOfflineForVolOp_r(Error *ec, Volume *vp, char *message);
-struct VLockFile;
-extern void VLockFileInit(struct VLockFile *lf, const char *path);
-extern int VLockFileLock(struct VLockFile *lf, afs_uint32 offset,
- int locktype, int nonblock);
-extern void VLockFileUnlock(struct VLockFile *lf, afs_uint32 offset);
-
struct VDiskLock;
extern void VDiskLockInit(struct VDiskLock *dl, struct VLockFile *lf,
afs_uint32 offset);
return code;
}
-#ifdef AFS_DEMAND_ATTACH_FS
+#ifdef AFS_PTHREAD_ENV
+# define AFS_LF_LOCK(lf) assert(pthread_mutex_lock(&((lf)->mutex)) == 0)
+# define AFS_LF_UNLOCK(lf) assert(pthread_mutex_unlock(&((lf)->mutex)) == 0)
+#else
+# define AFS_LF_LOCK(lf)
+# define AFS_LF_UNLOCK(lf)
+#endif /* AFS_PTHREAD_ENV */
/**
* initialize a struct VLockFile.
memset(lf, 0, sizeof(*lf));
lf->path = strdup(path);
lf->fd = INVALID_FD;
+#ifdef AFS_PTHREAD_ENV
assert(pthread_mutex_init(&lf->mutex, NULL) == 0);
+#endif /* AFS_PTHREAD_ENV */
}
-# ifdef AFS_NT40_ENV
+#ifdef AFS_NT40_ENV
static_inline FD_t
_VOpenPath(const char *path)
{
CloseHandle(lf->fd);
}
-# else /* !AFS_NT40_ENV */
+#else /* !AFS_NT40_ENV */
/**
* open a file on the local filesystem suitable for locking
"fd %d\n", errno, fd);
}
}
-# endif /* !AFS_NT40_ENV */
+#endif /* !AFS_NT40_ENV */
/**
* lock a file on disk for the process.
{
int code;
- assert(pthread_mutex_lock(&lf->mutex) == 0);
+ AFS_LF_LOCK(lf);
if (lf->fd == INVALID_FD) {
lf->fd = _VOpenPath(lf->path);
if (lf->fd == INVALID_FD) {
- assert(pthread_mutex_unlock(&lf->mutex) == 0);
+ AFS_LF_UNLOCK(lf);
return EIO;
}
}
lf->refcount++;
- assert(pthread_mutex_unlock(&lf->mutex) == 0);
+ AFS_LF_UNLOCK(lf);
code = _VLockFd(lf->fd, offset, locktype, nonblock);
if (code) {
- assert(pthread_mutex_lock(&lf->mutex) == 0);
+ AFS_LF_LOCK(lf);
if (--lf->refcount < 1) {
_VCloseFd(lf->fd);
lf->fd = INVALID_FD;
}
- assert(pthread_mutex_unlock(&lf->mutex) == 0);
+ AFS_LF_UNLOCK(lf);
}
return code;
void
VLockFileUnlock(struct VLockFile *lf, afs_uint32 offset)
{
- assert(pthread_mutex_lock(&lf->mutex) == 0);
+ AFS_LF_LOCK(lf);
if (--lf->refcount < 1) {
_VCloseFd(lf->fd);
_VUnlockFd(lf->fd, offset);
}
- assert(pthread_mutex_unlock(&lf->mutex) == 0);
+ AFS_LF_UNLOCK(lf);
}
+#ifdef AFS_DEMAND_ATTACH_FS
+
/**
* initialize a struct VDiskLock.
*