diff --git a/DBConfig b/DBConfig new file mode 100644 index 0000000..6183742 --- /dev/null +++ b/DBConfig @@ -0,0 +1 @@ +leaf/leaf_cache_pq2@192.168.83.108 diff --git a/client.py b/client.py index 7582b7d..8323d27 100644 --- a/client.py +++ b/client.py @@ -13,6 +13,8 @@ from concurrent.futures import ThreadPoolExecutor import tornado.iostream from tornado.escape import utf8 from tornado.log import gen_log +from ctypes import * +import os #import time,datat readchunky = False @@ -190,7 +192,12 @@ def writer(host,filepath,targetdir,uid,gid,pos,size): print("total bytes downloaded was", total_downloaded) if total_downloaded==FILESIZE: tornado.ioloop.IOLoop.instance().stop() - + lib=cdll.LoadLibrary('./libpycall.so') + print("start") + func=lib.update_bitmap + func.argtypes=(c_int,c_int,c_char_p) + func=lib.update_bitmap(int(pos),int(size),filepath.encode("utf-8")) + print("finish") @gen.coroutine def upload(host,filepath,targetpath,pos,size): diff --git a/libpycall.so b/libpycall.so new file mode 100755 index 0000000..07f245e Binary files /dev/null and b/libpycall.so differ diff --git a/pycall.c b/pycall.c new file mode 100644 index 0000000..3af7915 --- /dev/null +++ b/pycall.c @@ -0,0 +1,112 @@ +#include +#include +#include +#include + +int splitname(char *path, char *basename){ + char *p; + if (*path == 0 || *path != '/') { + return (-1); + } + /* silently remove trailing slashes */ + p = path + strlen (path) - 1; + while (*p == '/' && p != path) + *p = '\0'; + if ((p = strrchr (path, '/')) == NULL) + p = path - 1; + strcpy (basename, (*(p + 1)) ? p + 1 : "/"); + if (p <= path) /* path in the form abc or /abc */ + p++; + *p = '\0'; + return (0); +} + +int update_bitmap(int ini_bit, int size, char *filename) +{ + int pro_bit=ini_bit/10; + int size_bit=size/10; + int i; + printf("Data block start at %dMB, size is %dMB (Block unit is 10MB)\n",ini_bit,size); + if(size%10!=0){ + size_bit++; + } + char *bitmap=(char *)malloc(pro_bit+size_bit+1); + if(bitmap==NULL){ + exit(1); + } + memset(bitmap,'0',sizeof(char)*(pro_bit+size_bit)); + for(i=pro_bit;i=5&&(p_u=strtok(buf,"/\n"))&&(p_p=strtok(NULL,"@\n"))&&(p_s=strtok(NULL,"\n"))){ + printf("%s %s %s\n",p_s, p_u, p_p); + fclose(cf); + MYSQL *t_mysql; + MYSQL_ROW row; + MYSQL_RES *result; + unsigned long *length; + char *check="select bitmap from Cns_file_transform_metadata where path='%s' and name='%s'"; + char *bitmap_update="update Cns_file_transform_metadata set bitmap='%s' where path='%s' and name='%s'"; + char sql_check[1024]; + char sql_update[1024]; + sprintf(sql_check,check,filename,name); + printf("sql_check is %s\n",sql_check); + t_mysql=mysql_init(NULL); + if(t_mysql==NULL){ + printf("mysql connection inition failed\n"); + exit(1); + } + if(NULL==mysql_real_connect(t_mysql,p_s,p_u,p_p,"cns_db",0,NULL,0)){ + printf("mysql connection failed\n"); + exit(1); + }else + printf("mysql connect successfully\n"); + mysql_real_query(t_mysql,sql_check,strlen(sql_check)); + result=mysql_store_result(t_mysql); + row=mysql_fetch_row(result); + length=mysql_fetch_lengths(result); + if(length[0]!=0){ + int max=strlen(bitmap)>length[0]?strlen(bitmap):length[0]; + int temp; + char *bitmap_new=(char *)malloc(max+1); + for(temp=0;temp