Skip to content

Commit 3b660bb

Browse files
author
Ivan Stoev
committed
Merge branch 'master' of gitlab.pcloud.com:pcloud/synclib
2 parents b630a97 + aa93362 commit 3b660bb

File tree

5 files changed

+76
-13
lines changed

5 files changed

+76
-13
lines changed

pfs.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3018,6 +3018,20 @@ char *psync_fs_get_path_by_folderid(psync_folderid_t folderid){
30183018
return ret;
30193019
}
30203020

3021+
#if IS_DEBUG
3022+
3023+
static void psync_fs_dump_internals() {
3024+
psync_openfile_t *of;
3025+
debug(D_NOTICE, "dumping internal state");
3026+
psync_sql_rdlock();
3027+
psync_tree_for_each_element(of, openfiles, psync_openfile_t, tree)
3028+
debug(D_NOTICE, "open file %s fileid %ld folderid %ld", of->currentname, (long)of->fileid, (long)of->currentfolder->folderid);
3029+
psync_fstask_dump_state();
3030+
psync_sql_rdunlock();
3031+
}
3032+
3033+
#endif
3034+
30213035
static void psync_fs_do_stop(void){
30223036
struct timespec ts;
30233037
debug(D_NOTICE, "stopping");
@@ -3040,6 +3054,9 @@ static void psync_fs_do_stop(void){
30403054
debug(D_NOTICE, "timeouted waiting for fuse to exit");
30413055
else
30423056
debug(D_NOTICE, "waited for fuse to exit");
3057+
#if IS_DEBUG
3058+
psync_fs_dump_internals();
3059+
#endif
30433060
}
30443061
pthread_mutex_unlock(&start_mutex);
30453062
}
@@ -3051,11 +3068,18 @@ void psync_fs_stop(){
30513068
#if defined(P_OS_POSIX)
30523069

30533070
static void psync_signal_handler(int sig){
3054-
debug(D_NOTICE, "got signal %d\n", sig);
3071+
debug(D_NOTICE, "got signal %d", sig);
30553072
psync_fs_do_stop();
30563073
exit(1);
30573074
}
30583075

3076+
#if IS_DEBUG
3077+
static void psync_usr1_handler(int sig){
3078+
// debug(D_NOTICE, "got signal %d", sig);
3079+
psync_run_thread("dump signal", psync_fs_dump_internals);
3080+
}
3081+
#endif
3082+
30593083
static void psync_set_signal(int sig, void (*handler)(int)){
30603084
struct sigaction sa;
30613085

@@ -3075,6 +3099,9 @@ static void psync_setup_signals(){
30753099
psync_set_signal(SIGTERM, psync_signal_handler);
30763100
psync_set_signal(SIGINT, psync_signal_handler);
30773101
psync_set_signal(SIGHUP, psync_signal_handler);
3102+
#if IS_DEBUG
3103+
psync_set_signal(SIGUSR1, psync_usr1_handler);
3104+
#endif
30783105
}
30793106

30803107
#endif
@@ -3138,6 +3165,7 @@ static int psync_fs_do_start(){
31383165
// fuse_opt_add_arg(&args, "-ouse_ino");
31393166
fuse_opt_add_arg(&args, "-ofsname="DEFAULT_FUSE_MOUNT_POINT".fs");
31403167
fuse_opt_add_arg(&args, "-ononempty");
3168+
fuse_opt_add_arg(&args, "-ohard_remove");
31413169
#endif
31423170
#if defined(P_OS_MACOSX)
31433171
fuse_opt_add_arg(&args, "argv");
@@ -3147,6 +3175,7 @@ static int psync_fs_do_start(){
31473175
if (psync_user_is_admin())
31483176
fuse_opt_add_arg(&args, "-oallow_root");
31493177
fuse_opt_add_arg(&args, "-onolocalcaches");
3178+
fuse_opt_add_arg(&args, "-ohard_remove");
31503179
#endif
31513180

31523181
memset(&psync_oper, 0, sizeof(psync_oper));

pfstasks.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
#include <stddef.h>
4141
#include <stdio.h>
4242

43-
#define FOLDER_HASH 256
44-
4543
typedef struct {
4644
psync_folderid_t folderid;
4745
char name[];
@@ -50,10 +48,6 @@ typedef struct {
5048
static psync_tree *folders=PSYNC_TREE_EMPTY;
5149
static uint64_t psync_local_taskid=UINT64_MAX;
5250

53-
psync_uint_t folder_hash(psync_fsfolderid_t folderid){
54-
return ((uint64_t)folderid)%FOLDER_HASH;
55-
}
56-
5751
psync_fstask_folder_t *psync_fstask_get_or_create_folder_tasks(psync_fsfolderid_t folderid){
5852
psync_fstask_folder_t *folder;
5953
psync_sql_lock();
@@ -880,10 +874,11 @@ int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name){
880874
psync_sql_run_free(res);
881875
}
882876
else{
883-
res=psync_sql_prep_statement("INSERT INTO fstask (type, status, folderid, fileid, text1) VALUES ("NTO_STR(PSYNC_FS_TASK_UNLINK)", 0, ?, ?, ?)");
884-
psync_sql_bind_int(res, 1, folderid);
885-
psync_sql_bind_int(res, 2, fileid);
886-
psync_sql_bind_lstring(res, 3, name, len);
877+
res=psync_sql_prep_statement("INSERT INTO fstask (type, status, folderid, fileid, text1) VALUES ("NTO_STR(PSYNC_FS_TASK_UNLINK)", ?, ?, ?, ?)");
878+
psync_sql_bind_int(res, 1, fileid<0?11:0);
879+
psync_sql_bind_int(res, 2, folderid);
880+
psync_sql_bind_int(res, 3, fileid);
881+
psync_sql_bind_lstring(res, 4, name, len);
887882
psync_sql_run_free(res);
888883
}
889884
taskid=psync_sql_insertid();
@@ -1842,3 +1837,38 @@ void psync_fstask_init(){
18421837
psync_sql_free_result(res);
18431838
psync_fsupload_init();
18441839
}
1840+
1841+
#if IS_DEBUG
1842+
1843+
void psync_fstask_dump_state(){
1844+
psync_fstask_folder_t *folder;
1845+
psync_fstask_mkdir_t *mk;
1846+
psync_fstask_rmdir_t *rm;
1847+
psync_fstask_creat_t *cr;
1848+
psync_fstask_unlink_t *un;
1849+
uint32_t cnt;
1850+
psync_tree_for_each_element(folder, folders, psync_fstask_folder_t, tree){
1851+
debug(D_NOTICE, "open folderid %ld taskcnt %u refcnt %u", (long)folder->folderid, (unsigned)folder->taskscnt, (unsigned)folder->refcnt);
1852+
cnt=0;
1853+
psync_tree_for_each_element(mk, folder->mkdirs, psync_fstask_mkdir_t, tree){
1854+
debug(D_NOTICE, " mkdir %s folderid %ld taskid %lu", mk->name, (long)mk->folderid, (unsigned long)mk->taskid);
1855+
cnt++;
1856+
}
1857+
psync_tree_for_each_element(rm, folder->rmdirs, psync_fstask_rmdir_t, tree){
1858+
debug(D_NOTICE, " mkdir %s folderid %ld taskid %lu", rm->name, (long)rm->folderid, (unsigned long)rm->taskid);
1859+
cnt++;
1860+
}
1861+
psync_tree_for_each_element(cr, folder->creats, psync_fstask_creat_t, tree){
1862+
debug(D_NOTICE, " creat %s fileid %ld taskid %lu", cr->name, (long)cr->fileid, (unsigned long)cr->taskid);
1863+
cnt++;
1864+
}
1865+
psync_tree_for_each_element(un, folder->unlinks, psync_fstask_unlink_t, tree){
1866+
debug(D_NOTICE, " unlink %s fileid %ld taskid %lu", un->name, (long)un->fileid, (unsigned long)un->taskid);
1867+
cnt++;
1868+
}
1869+
if (cnt!=folder->taskscnt)
1870+
debug(D_ERROR, "inconsistency found, counted taskcnt %u != taskcnt %u", (unsigned)cnt, (unsigned)folder->taskscnt);
1871+
}
1872+
}
1873+
1874+
#endif

pfstasks.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "pfsfolder.h"
3232
#include "ptree.h"
3333
#include "psynclib.h"
34+
#include "plibs.h"
3435
#include <time.h>
3536
#include <stddef.h>
3637
#include <string.h>
@@ -157,4 +158,8 @@ void psync_fstask_clean();
157158

158159
void psync_fstask_add_banned_folders();
159160

161+
#if IS_DEBUG
162+
void psync_fstask_dump_state();
163+
#endif
164+
160165
#endif

pfsupload.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ static int psync_cancel_task_modify(fsupload_task_t *task){
13481348

13491349
static int psync_cancel_task_unlink(fsupload_task_t *task){
13501350
psync_sql_res *res;
1351-
if (unlikely_log(task->fileid>0)){
1351+
if (unlikely_log((psync_fsfileid_t)task->fileid>0)){
13521352
res=psync_sql_prep_statement("UPDATE fstask SET status=0 WHERE id=?");
13531353
psync_sql_bind_uint(res, 1, task->id);
13541354
upload_wakes++;

psynclib.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,6 @@ static int psync_upload_params(binparam *params, size_t paramcnt, const void *da
15671567
} while (++tries<=PSYNC_RETRY_REQUEST);
15681568
psync_timer_notify_exception();
15691569
return -1;
1570-
15711570
}
15721571

15731572
int psync_upload_data(psync_folderid_t folderid, const char *remote_filename, const void *data, size_t length, psync_fileid_t *fileid){

0 commit comments

Comments
 (0)