From 3346daf9593f28ec86f84941a976922bbfb9b3b4 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Wed, 26 Jun 2013 15:18:32 +0200 Subject: [PATCH] light: allow remote deletion of directories --- kernel/sy_old/mars_light.c | 18 +++++++++++++++--- kernel/sy_old/strategy.h | 1 + kernel/sy_old/sy_generic.c | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/kernel/sy_old/mars_light.c b/kernel/sy_old/mars_light.c index 0824b590..d91c24e2 100644 --- a/kernel/sy_old/mars_light.c +++ b/kernel/sy_old/mars_light.c @@ -3533,12 +3533,14 @@ done: static int prepare_delete(void *buf, struct mars_dent *dent) { + struct kstat stat; struct mars_global *global = buf; struct mars_dent *target; struct mars_dent *response; const char *response_path = NULL; struct mars_brick *brick; int max_serial = 0; + int status; if (!global || !dent || !dent->new_link || !dent->d_path) { goto done; @@ -3550,12 +3552,22 @@ static int prepare_delete(void *buf, struct mars_dent *dent) goto done; } + status = -EAGAIN; target = _mars_find_dent(global, dent->new_link); if (target) { - mars_unlink(dent->new_link); + status = mars_unlink(dent->new_link); target->d_killme = true; - MARS_DBG("target '%s' deleted and marked for removal\n", dent->new_link); - } else { + MARS_DBG("target '%s' deleted (status = %d) and marked for removal\n", dent->new_link, status); + } else if (mars_stat(dent->new_link, &stat, true) >= 0) { + if (S_ISDIR(stat.mode)) { + status = mars_rmdir(dent->new_link); + MARS_DBG("rmdir '%s', status = %d\n", dent->new_link, status); + } else { + status = mars_unlink(dent->new_link); + MARS_DBG("unlink '%s', status = %d\n", dent->new_link, status); + } + } + if (status < 0) { MARS_DBG("target '%s' does no longer exist\n", dent->new_link); if (dent->d_serial <= global->deleted_border) { MARS_DBG("removing deletion symlink '%s'\n", dent->d_path); diff --git a/kernel/sy_old/strategy.h b/kernel/sy_old/strategy.h index a69ae372..3ff8d734 100644 --- a/kernel/sy_old/strategy.h +++ b/kernel/sy_old/strategy.h @@ -141,6 +141,7 @@ extern struct mars_brick *make_brick_all( */ extern int mars_stat(const char *path, struct kstat *stat, bool use_lstat); extern int mars_mkdir(const char *path); +extern int mars_rmdir(const char *path); extern int mars_unlink(const char *path); extern int mars_symlink(const char *oldpath, const char *newpath, const struct timespec *stamp, uid_t uid); extern char *mars_readlink(const char *newpath); diff --git a/kernel/sy_old/sy_generic.c b/kernel/sy_old/sy_generic.c index d0179df7..c6b90467 100644 --- a/kernel/sy_old/sy_generic.c +++ b/kernel/sy_old/sy_generic.c @@ -103,6 +103,20 @@ int mars_mkdir(const char *path) } EXPORT_SYMBOL_GPL(mars_mkdir); +int mars_rmdir(const char *path) +{ + mm_segment_t oldfs; + int status; + + oldfs = get_fs(); + set_fs(get_ds()); + status = sys_rmdir(path); + set_fs(oldfs); + + return status; +} +EXPORT_SYMBOL_GPL(mars_rmdir); + int mars_unlink(const char *path) { mm_segment_t oldfs;