+2006-07-30 Miklos Szeredi <miklos@szeredi.hu>
+
+ * fusermount: if selinux is active, restore the original file's
+ security context in unmount_rename(). Redhat bugzilla id 188561.
+ Patch from Yves Perrenoud
+
+ * Add POSIX file locking operation to high level library
+
+2006-07-14 Miklos Szeredi <miklos@szeredi.hu>
+
+ * Multiple release() calls can race with each other, resulting in
+ the hidden file being deleted before the last release finishes.
+ Bug found and patch tested by Mark Huijgen
+
2006-07-05 Miklos Szeredi <miklos@szeredi.hu>
- * fusermount: if /dev/fuse doesn't exist, suggest moddprobing
- fuse; this makes sense on systems using udev. Reported by
- Szakacsits Szabolcs
+ * fusermount: if /dev/fuse doesn't exist, suggest modprobing fuse;
+ this makes sense on systems using udev. Reported by Szakacsits
+ Szabolcs
2006-06-29 Miklos Szeredi <miklos@szeredi.hu>
char *path;
int err;
- (void) owner;
err = -ENOENT;
pthread_rwlock_rdlock(&f->tree_lock);
path = get_path(f, ino);
err = f->op.flush(path, fi);
free(path);
}
+ if (f->op.lock) {
+ struct flock lock;
+ memset(&lock, 0, sizeof(lock));
+ lock.l_type = F_UNLCK;
+ lock.l_whence = SEEK_SET;
+ f->op.lock(path, fi, F_SETLK, &lock, owner);
+ if (err == -ENOSYS)
+ err = 0;
+ }
pthread_rwlock_unlock(&f->tree_lock);
reply_err(req, err);
}
int unlink_hidden;
pthread_rwlock_rdlock(&f->tree_lock);
- pthread_mutex_lock(&f->lock);
- node = get_node(f, ino);
- assert(node->open_count > 0);
- --node->open_count;
- unlink_hidden = (node->is_hidden && !node->open_count);
- pthread_mutex_unlock(&f->lock);
-
path = get_path(f, ino);
if (f->conf.debug) {
printf("RELEASE[%llu] flags: 0x%x\n", (unsigned long long) fi->fh,
if (f->op.release)
fuse_do_release(f, path, fi);
+ pthread_mutex_lock(&f->lock);
+ node = get_node(f, ino);
+ assert(node->open_count > 0);
+ --node->open_count;
+ unlink_hidden = (node->is_hidden && !node->open_count);
+ pthread_mutex_unlock(&f->lock);
+
if(unlink_hidden && path)
f->op.unlink(path);
reply_err(req, err);
}
+static int fuse_lock_common(fuse_req_t req, fuse_ino_t ino,
+ struct fuse_file_info *fi, struct flock *lock,
+ uint64_t owner, int cmd)
+{
+ struct fuse *f = req_fuse_prepare(req);
+ char *path;
+ int err;
+
+ err = -ENOENT;
+ pthread_rwlock_rdlock(&f->tree_lock);
+ path = get_path(f, ino);
+ if (path != NULL) {
+ err = f->op.lock(path, fi, cmd, lock, owner);
+ free(path);
+ }
+ pthread_rwlock_unlock(&f->tree_lock);
+ return err;
+}
+
+static void fuse_getlk(fuse_req_t req, fuse_ino_t ino,
+ struct fuse_file_info *fi, struct flock *lock,
+ uint64_t owner)
+{
+ int err = fuse_lock_common(req, ino, fi, lock, owner, F_GETLK);
+ if (!err)
+ fuse_reply_lock(req, lock);
+ else
+ reply_err(req, err);
+}
+
+static void fuse_setlk(fuse_req_t req, fuse_ino_t ino,
+ struct fuse_file_info *fi, struct flock *lock,
+ uint64_t owner, int sleep)
+{
+ reply_err(req, fuse_lock_common(req, ino, fi, lock, owner,
+ sleep ? F_SETLKW : F_SETLK));
+}
+
static struct fuse_lowlevel_ops fuse_path_ops = {
.init = fuse_data_init,
.destroy = fuse_data_destroy,
.getxattr = fuse_getxattr,
.listxattr = fuse_listxattr,
.removexattr = fuse_removexattr,
+ .getlk = fuse_getlk,
+ .setlk = fuse_setlk,
};
static void free_cmd(struct fuse_cmd *cmd)
{
struct fuse *f;
struct node *root;
+ struct fuse_lowlevel_ops llop = fuse_path_ops;
if (sizeof(struct fuse_operations) < op_size) {
fprintf(stderr, "fuse: warning: library too old, some operations may not not work\n");
goto out_free;
}
- f->se = fuse_lowlevel_new_common(args, &fuse_path_ops,
- sizeof(fuse_path_ops), f);
+ memcpy(&f->op, op, op_size);
+ if (!f->op.lock) {
+ llop.getlk = NULL;
+ llop.setlk = NULL;
+ }
+
+ f->se = fuse_lowlevel_new_common(args, &llop,sizeof(llop), f);
if (f->se == NULL)
goto out_free;
mutex_init(&f->lock);
pthread_rwlock_init(&f->tree_lock, NULL);
- memcpy(&f->op, op, op_size);
f->compat = compat;
root = (struct node *) calloc(1, sizeof(struct node));
#include <sys/utsname.h>
#include <sys/sysmacros.h>
+#ifdef HAVE_SELINUX_SELINUX_H
+#include <selinux/selinux.h>
+#endif
+
#define FUSE_COMMFD_ENV "_FUSE_COMMFD"
#define FUSE_DEV_OLD "/proc/fs/fuse/dev"
if (stat(mtab, &sbuf) == 0)
chown(mtab_new, sbuf.st_uid, sbuf.st_gid);
+#ifdef HAVE_LIBSELINUX
+ {
+ security_context_t filecon;
+
+ if (getfilecon(mtab, &filecon) > 0) {
+ setfilecon(mtab_new, filecon);
+ if (filecon != NULL)
+ freecon(filecon);
+ }
+ }
+#endif
+
res = rename(mtab_new, mtab);
if (res == -1) {
fprintf(stderr, "%s: failed to rename %s to %s: %s\n", progname,