light: allow remote deletion of directories

This commit is contained in:
Thomas Schoebel-Theuer 2013-06-26 15:18:32 +02:00
parent c917bc239b
commit 3346daf959
3 changed files with 30 additions and 3 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;