static void unlink_object(const char *path)
{
-//qqq should rename and do a recursive delete here in a child
-//qqq to handle when this is a directory tree
- unlink(path);
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+ char *cmd;
+ int ret;
+
+ cmd = talloc_asprintf(mem_ctx, "rm -rf %s", path);
+ ret = system(cmd);
+ if (ret != 0) {
+ DEBUG(DEBUG_DEBUG,("%s failed with ret:%d\n", cmd, ret));
+ }
+ talloc_free(mem_ctx);
}
return cache_fd;
}
+int unlink_parent_dir_cache(TALLOC_CTX *mem_ctx, const char *path)
+{
+ char *ppath;
+ char *sptr;
+ char *cache_path;
+ int ret;
+
+ ppath = talloc_strdup(mem_ctx, path);
+ sptr = rindex(ppath, '/');
+ if (sptr == NULL) {
+ return -1;
+ }
+ *sptr = 0;
+ if (ppath[0] == 0) {
+ return -1;
+ }
+
+ cache_path = talloc_asprintf(mem_ctx, "%s/%s", ppath, CACHE_DIR_NAME);
+
+ ret = unlink(cache_path);
+ DEBUG(DEBUG_DEBUG,("unlink_parent_dir_cache(%s) == %d\n", cache_path, ret));
+ return ret;
+}
+
+
int lookup_attribute_in_parent(TALLOC_CTX *mem_ctx, const char *path, struct stat *st)
{
int cache_fd = -1;
char *old_path = NULL;
int ret;
- DEBUG(DEBUG_DEBUG, (__location__ " STATFS called\n"));
+//qqq DEBUG(DEBUG_DEBUG, (__location__ " STATFS called\n"));
old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
ret = statvfs(old_path, buf);
if (ret == -1) {
*/
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
*/
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
*/
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
goto finished;
}
-
+ /* unlink the file on the remote site */
ret = unlink(old_path);
if (ret != 0) {
DEBUG(DEBUG_DEBUG,(__location__ " UNLINK %s failed with errno:%u\n", old_path, errno));
}
/* if the unlink was successful we try to delete any local cached
- entries for this name
+ entries for this name and remove the cache for this directory
*/
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
*/
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
*/
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
ret = creat(old_path, mode);
- if (ret != 0) {
+ if (ret == -1) {
DEBUG(DEBUG_DEBUG,(__location__ " CREATE %s mode %o failed with errno:%u\n", old_path, mode, errno));
ret = -errno;
goto finished;
/* if the creat was successful we try to delete any local cached
entries for this name
*/
+ ret = 0;
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
*/
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
*/
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
*/
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
*/
switch_back_to_root();
unlink_object(new_path);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
*/
switch_back_to_root();
unlink_object(new_newpath);
+ unlink_parent_dir_cache(mem_ctx, new_newpath);
finished:
switch_back_to_root();
*/
switch_back_to_root();
unlink_object(new_newpath);
+ unlink_parent_dir_cache(mem_ctx, new_newpath);
finished:
switch_back_to_root();
entries for this name
*/
switch_back_to_root();
+ unlink_object(new_path);
unlink_object(new_newpath);
+ unlink_parent_dir_cache(mem_ctx, new_path);
finished:
switch_back_to_root();
}
+static int remote_cache_lock(const char *path, struct fuse_file_info *ffi, int cmd, struct flock *fl)
+{
+ int fd;
+ int ret;
+
+ if (!read_write) {
+ return -EROFS;
+ }
+
+ DEBUG(DEBUG_DEBUG, ("LOCK %s cmd:%s(%d)\n", path, cmd==F_GETLK?"F_GETLK":cmd==F_SETLKW?"F_SETLKW":cmd==F_SETLK?"F_SETLK":"unknown", cmd));
+
+ ret = switch_to_real_user();
+ if (ret != 0) {
+ DEBUG(DEBUG_ERR, (__location__ " SETEUID failed\n"));
+ goto finished;
+ }
+
+ fd = *((int *)(&ffi->fh));
+ if (fd == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " ERROR file to lock is not open %s\n", path));
+ ret = -errno;
+ goto finished;
+ }
+
+ ret = fcntl(fd, cmd, fl);
+ if (ret == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " FCNTL lock failed with errno:%d for fd:%d for file %s\n", errno, fd, path));
+ ret = -errno;
+ goto finished;
+ }
+
+finished:
+ switch_back_to_root();
+ return ret;
+}
+
+
+static int remote_cache_open(const char *path, struct fuse_file_info *ffi)
+{
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+ char *old_path = NULL;
+ int ret = 0;
+ int fd;
+
+ old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+
+ ret = switch_to_real_user();
+ if (ret != 0) {
+ DEBUG(DEBUG_ERR, (__location__ " SETEUID failed\n"));
+ goto finished;
+ }
+
+ fd = open(old_path, O_RDWR);
+ if (fd == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to OPEN file %s errno:%d\n", old_path, errno));
+ ret = -errno;
+ }
+ *((int *)(&ffi->fh)) = fd;
+
+ DEBUG(DEBUG_DEBUG,("OPEN: %s fd:%d\n",old_path, fd));
+
+finished:
+ switch_back_to_root();
+ talloc_free(mem_ctx);
+ return ret;
+}
+static int remote_cache_release(const char *path, struct fuse_file_info *ffi)
+{
+ int fd;
+
+ fd = *((int *)(&ffi->fh));
+
+ DEBUG(DEBUG_DEBUG,("RELEASE: %s close fd:%d\n",path, fd));
+
+ if (fd != -1) {
+ close(fd);
+ }
+
+ return 0;
+}
static struct fuse_operations remote_cache_ops = {
.getattr = remote_cache_getattr,
.read = remote_cache_read,
-
+ .unlink = remote_cache_unlink,
+ .create = remote_cache_create,
.mknod = remote_cache_mknod,
.mkdir = remote_cache_mkdir,
.rmdir = remote_cache_rmdir,
- .unlink = remote_cache_unlink,
+ .rename = remote_cache_rename,
.chmod = remote_cache_chmod,
.chown = remote_cache_chown,
- .create = remote_cache_create,
.utime = remote_cache_utime,
.write = remote_cache_write,
.truncate = remote_cache_truncate,
.ftruncate = remote_cache_ftruncate,
- .link = remote_cache_link,
.symlink = remote_cache_symlink,
- .rename = remote_cache_rename,
+ .link = remote_cache_link,
+
+
+
+ .open = remote_cache_open,
+ .release = remote_cache_release,
+ .lock = remote_cache_lock,
+
-// .open = migrate_open,
// .flush = migrate_flush,
-// .release = migrate_release,
// .fsync = migrate_fsync,
// .setxattr = migrate_setxattr,
// .getxattr = migrate_getxattr,
// .releasedir = migrate_releasedir,
// .fsyncdir = migrate_fsyncdir,
// .fgetattr = migrate_fgetattr,
-// .lock = migrate_lock,
// .utimens = migrate_utimens,
};