[vhffs-dev] [1641] Actually the fix to the max open file issue is not that simple, the

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1641
Author:   gradator
Date:     2010-11-18 23:28:06 +0100 (Thu, 18 Nov 2010)
Log Message:
-----------
Actually the fix to the max open file issue is not that simple, the 
early open() on files was here in case directories are moved.

A new design with threads may be required to handle inotify events 
faster than now, to prevent miss due to late notification in tree 
changes.
	

Modified Paths:
--------------
    trunk/vhffs-fssync/vhffsfssync_master.c
    trunk/vhffs-fssync/vhffsfssync_slave.c

Modified: trunk/vhffs-fssync/vhffsfssync_master.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_master.c	2010-11-18 20:50:48 UTC (rev 1640)
+++ trunk/vhffs-fssync/vhffsfssync_master.c	2010-11-18 22:28:06 UTC (rev 1641)
@@ -475,6 +475,7 @@
 vhffsfssync_net_file *vhffsfssync_net_file_open(const char *pathname)  {
 	vhffsfssync_net_file *file;
 	struct stat st;
+	int fd;
 
 	if(!pathname)
 		return NULL;
@@ -496,8 +497,14 @@
 		return NULL;
 	}
 
+	fd = open(pathname, O_RDONLY);
+	if(fd < 0) {
+		fprintf(stderr, "open() failed on %s: %s\n", pathname, strerror(errno));
+		return NULL;
+	}
+
 	file = malloc(sizeof(vhffsfssync_net_file));
-	file->file_fd = -1;
+	file->file_fd = fd;
 	file->file_pathname = strdup(pathname);
 	memcpy(&file->file_stat, &st, sizeof(struct stat));
 	file->ref = 1;
@@ -639,7 +646,7 @@
 #if DEBUG_NET
 				printf("      %ld bytes written on %ld bytes\n", (long int)written, (long int)lentowrite);
 #endif
-				/* the buffer is not empty yet (but the SendQ into the kernel is) */
+				/* the buffer is not empty yet (but the SendQ into the kernel is full) */
 				if(written < lentowrite) {
 					full = TRUE;
 				}
@@ -659,14 +666,14 @@
 			filemsg = (vhffsfssync_net_message_file*)msg;
 
 			// we need to open the file
-			if(filemsg->file->file_fd < 0) {
+/*			if(filemsg->file->file_fd < 0) {
 				filemsg->file->file_fd = open(filemsg->file->file_pathname, O_RDONLY);
 				if(filemsg->file->file_fd < 0) {
 					fprintf(stderr, "open() failed on %s: %s\n", filemsg->file->file_pathname, strerror(errno));
 					vhffsfssync_net_destroy_file(conn, filemsg);
 					continue;
 				}
-			}
+			} */
 #if DEBUG_NET
 			printf("    file: %s, offset = %lld, size = %lld\n", filemsg->file->file_pathname, (long long int)filemsg->file_offset, (long long int)filemsg->file_stat.st_size);
 #endif
@@ -719,8 +726,15 @@
 
 				/* the chunk is sent */
 				else if(written == lentowrite) {
+					uint32_t maxprio = -1;  // 4294967295
+
 					filemsg->file_chunksize = -1;
 					filemsg->file_chunkcur = 0;
+
+					// reschedule this file to a nicer priority
+					msg->msg_priority = MAX(MIN(filemsg->file->file_stat.st_size - filemsg->file_offset, maxprio), 1000);
+					conn->messages = g_list_remove(conn->messages, msg);
+					conn->messages = g_list_insert_sorted(conn->messages, msg, vhffsfssync_net_message_insert_compare);
 				}
 			}
 		}

Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c	2010-11-18 20:50:48 UTC (rev 1640)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c	2010-11-18 22:28:06 UTC (rev 1641)
@@ -236,9 +236,7 @@
 				while( (dir = readdir(d)) )  {
 					if( strcmp(dir->d_name, ".") && strcmp(dir->d_name, "..") )  {
 						char *path;
-						char *sep = "/";
-						if( pathname[strlen(pathname)-1] == '/' ) sep = "";
-						path = g_strdup_printf("%s%s%s", pathname, sep, dir->d_name);
+						path = g_strdup_printf("%s/%s", pathname, dir->d_name);
 						vhffsfssync_remove(path);
 						free(path);
 					}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/