Check-in [f1d16a3958]
Overview
Comment:Improved server mode to register all of //xvfs:/
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f1d16a395838a54ef57088a86c2d4a0542a41ea79a1904067f6f0e8c54f68e69
User & Date: rkeene on 2019-09-17 01:53:07
Other Links: manifest | tags
Context
2019-09-17
01:55
xvfs_perror -> xvfs_strerror, which is what it should have been named check-in: cf56967f97 user: rkeene tags: trunk
01:53
Improved server mode to register all of //xvfs:/ check-in: f1d16a3958 user: rkeene tags: trunk
2019-09-16
22:22
First implementation of the Server mode of XVFS check-in: 0e05b2a8c7 user: rkeene tags: trunk
Changes

Modified Makefile from [d1e12905cd] to [ba72f8ca71].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
example.o: example.c xvfs-core.h xvfs-core.c Makefile
	$(CC) $(CPPFLAGS) -DXVFS_MODE_FLEXIBLE $(CFLAGS) -o example.o -c example.c

example.so: example.o Makefile
	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o example.so example.o $(LIBS)

example-client.o: example.c xvfs-core.h Makefile
	$(CC) $(CPPFLAGS) -DXVFS_MODE_CLIENT $(CFLAGS) -o example-client.o -c example.c

example-server.o: xvfs-core.h xvfs-core.c Makefile
	$(CC) $(CPPFLAGS) -DXVFS_MODE_SERVER $(CFLAGS) -o example-server.o -c xvfs-core.c

example-client-server.so: example-client.o example-server.o Makefile
	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o example-client-server.so example-client.o example-server.o $(LIBS)








|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
example.o: example.c xvfs-core.h xvfs-core.c Makefile
	$(CC) $(CPPFLAGS) -DXVFS_MODE_FLEXIBLE $(CFLAGS) -o example.o -c example.c

example.so: example.o Makefile
	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o example.so example.o $(LIBS)

example-client.o: example.c xvfs-core.h Makefile
	$(CC) $(CPPFLAGS) -DXVFS_MODE_FLEXIBLE $(CFLAGS) -o example-client.o -c example.c

example-server.o: xvfs-core.h xvfs-core.c Makefile
	$(CC) $(CPPFLAGS) -DXVFS_MODE_SERVER $(CFLAGS) -o example-server.o -c xvfs-core.c

example-client-server.so: example-client.o example-server.o Makefile
	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o example-client-server.so example-client.o example-server.o $(LIBS)

Modified xvfs-core.c from [15909aa1a5] to [9a0cfd6536].

515
516
517
518
519
520
521



522
523
524
525
526
527
528
	path = xvfs_absolutePath(path);

	pathStr = xvfs_relativePath(path, instanceInfo);

	retval = instanceInfo->fsInfo->getStatProc(pathStr, statBuf);
	if (retval < 0) {
		XVFS_DEBUG_PRINTF("... failed: %s", xvfs_perror(retval));



		retval = -1;
	} else {
		XVFS_DEBUG_PUTS("... ok");
	}

	Tcl_DecrRefCount(path);








>
>
>







515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
	path = xvfs_absolutePath(path);

	pathStr = xvfs_relativePath(path, instanceInfo);

	retval = instanceInfo->fsInfo->getStatProc(pathStr, statBuf);
	if (retval < 0) {
		XVFS_DEBUG_PRINTF("... failed: %s", xvfs_perror(retval));

		Tcl_SetErrno(xvfs_errorToErrno(retval));

		retval = -1;
	} else {
		XVFS_DEBUG_PUTS("... ok");
	}

	Tcl_DecrRefCount(path);

930
931
932
933
934
935
936


937
938
939
940
941


942
943
944
945
946
947
948
949


950
951
952
953
954


955
956
957
958
959
960
961
962
963
964

965
966


967
968
969
970
971
972
973
974

975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000





















1001
1002



1003
1004
1005
1006
1007
1008
1009
#if defined(XVFS_MODE_FLEXIBLE)
static int xvfs_flexible_register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
	ClientData fsHandlerDataRaw;
	struct xvfs_tclfs_server_info *fsHandlerData;
	const Tcl_Filesystem *fsHandler;
	int (*xvfs_register)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
	Tcl_Obj *rootPathObj;



	xvfs_register = &xvfs_standalone_register;

	rootPathObj = Tcl_NewStringObj(XVFS_ROOT_MOUNTPOINT, -1);
	if (!rootPathObj) {


		return(xvfs_register(interp, fsInfo));
	}

	Tcl_IncrRefCount(rootPathObj);
	fsHandler = Tcl_FSGetFileSystemForPath(rootPathObj);
	Tcl_DecrRefCount(rootPathObj);

	if (!fsHandler) {


		return(xvfs_register(interp, fsInfo));
	}

	fsHandlerDataRaw = Tcl_FSData(fsHandler);
	if (!fsHandlerDataRaw) {


		return(xvfs_register(interp, fsInfo));
	}

	fsHandlerData = (struct xvfs_tclfs_server_info *) fsHandlerDataRaw;

	/*
	 * XXX:TODO: What is the chance that the handler for //xvfs:/ hold
	 * client data smaller than XVFS_INTERNAL_SERVER_MAGIC_LEN ?
	 */
	if (memcmp(fsHandlerData->magic, XVFS_INTERNAL_SERVER_MAGIC, sizeof(fsHandlerData->magic)) == 0) {

		xvfs_register = fsHandlerData->registerProc;
	}



	return(xvfs_register(interp, fsInfo));
}
#endif /* XVFS_MODE_FLEXIBLE */

#if defined(XVFS_MODE_SERVER)
static Tcl_Filesystem xvfs_tclfs_dispatch_fs;
static Tcl_HashTable xvfs_tclfs_dispatch_map;


static struct xvfs_tclfs_instance_info *xvfs_tclfs_dispatch_pathToInstanceInfo(Tcl_Obj *path) {
	Tcl_HashEntry *mapEntry;
	struct xvfs_tclfs_instance_info *retval;
	const char *pathStr, *rootStr;
	char *fsName, *fsNameEnds, origSep;
	int pathLen, rootLen;

	XVFS_DEBUG_ENTER;

	XVFS_DEBUG_PRINTF("Looking up path \"%s\" ...", Tcl_GetString(path));
	
	rootStr = XVFS_ROOT_MOUNTPOINT;
	rootLen = strlen(XVFS_ROOT_MOUNTPOINT);

	pathStr = Tcl_GetStringFromObj(path, &pathLen);

	if (pathLen < rootLen) {
		XVFS_DEBUG_PUTS("... failed (length too short)");
		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	if (memcmp(pathStr, rootStr, rootLen) != 0) {
		XVFS_DEBUG_PUTS("... failed (incorrect prefix)");
		XVFS_DEBUG_LEAVE;





















		return(NULL);
	}




	fsName = ((char *) pathStr) + rootLen;

	fsNameEnds = strchr(fsName, '/');
	if (fsNameEnds) {
		origSep = *fsNameEnds;
		*fsNameEnds = '\0';







>
>





>
>








>
>





>
>










>


>
>








>

|
<
<

<




|









|





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
>







933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991


992

993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
#if defined(XVFS_MODE_FLEXIBLE)
static int xvfs_flexible_register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
	ClientData fsHandlerDataRaw;
	struct xvfs_tclfs_server_info *fsHandlerData;
	const Tcl_Filesystem *fsHandler;
	int (*xvfs_register)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
	Tcl_Obj *rootPathObj;

	XVFS_DEBUG_ENTER;

	xvfs_register = &xvfs_standalone_register;

	rootPathObj = Tcl_NewStringObj(XVFS_ROOT_MOUNTPOINT, -1);
	if (!rootPathObj) {
		XVFS_DEBUG_LEAVE;

		return(xvfs_register(interp, fsInfo));
	}

	Tcl_IncrRefCount(rootPathObj);
	fsHandler = Tcl_FSGetFileSystemForPath(rootPathObj);
	Tcl_DecrRefCount(rootPathObj);

	if (!fsHandler) {
		XVFS_DEBUG_LEAVE;

		return(xvfs_register(interp, fsInfo));
	}

	fsHandlerDataRaw = Tcl_FSData(fsHandler);
	if (!fsHandlerDataRaw) {
		XVFS_DEBUG_LEAVE;

		return(xvfs_register(interp, fsInfo));
	}

	fsHandlerData = (struct xvfs_tclfs_server_info *) fsHandlerDataRaw;

	/*
	 * XXX:TODO: What is the chance that the handler for //xvfs:/ hold
	 * client data smaller than XVFS_INTERNAL_SERVER_MAGIC_LEN ?
	 */
	if (memcmp(fsHandlerData->magic, XVFS_INTERNAL_SERVER_MAGIC, sizeof(fsHandlerData->magic)) == 0) {
		XVFS_DEBUG_PUTS("Found a server handler");
		xvfs_register = fsHandlerData->registerProc;
	}

	XVFS_DEBUG_LEAVE;

	return(xvfs_register(interp, fsInfo));
}
#endif /* XVFS_MODE_FLEXIBLE */

#if defined(XVFS_MODE_SERVER)
static Tcl_Filesystem xvfs_tclfs_dispatch_fs;
static Tcl_HashTable xvfs_tclfs_dispatch_map;
static struct xvfs_tclfs_server_info xvfs_tclfs_dispatch_fsdata;

static int xvfs_tclfs_dispatch_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr) {


	const char *pathStr, *rootStr;

	int pathLen, rootLen;

	XVFS_DEBUG_ENTER;

	XVFS_DEBUG_PRINTF("Verifying that \"%s\" belongs in XVFS ...", Tcl_GetString(path));
	
	rootStr = XVFS_ROOT_MOUNTPOINT;
	rootLen = strlen(XVFS_ROOT_MOUNTPOINT);

	pathStr = Tcl_GetStringFromObj(path, &pathLen);

	if (pathLen < rootLen) {
		XVFS_DEBUG_PUTS("... failed (length too short)");
		XVFS_DEBUG_LEAVE;
		return(-1);
	}

	if (memcmp(pathStr, rootStr, rootLen) != 0) {
		XVFS_DEBUG_PUTS("... failed (incorrect prefix)");
		XVFS_DEBUG_LEAVE;
		return(-1);
	}

	XVFS_DEBUG_PUTS("... yes");

	XVFS_DEBUG_LEAVE;

	return(TCL_OK);
}

static struct xvfs_tclfs_instance_info *xvfs_tclfs_dispatch_pathToInfo(Tcl_Obj *path) {
	Tcl_HashEntry *mapEntry;
	struct xvfs_tclfs_instance_info *retval;
	int rootLen;
	char *pathStr, *fsName, *fsNameEnds, origSep;

	XVFS_DEBUG_ENTER;

	if (xvfs_tclfs_dispatch_pathInFilesystem(path, NULL) != TCL_OK) {
		XVFS_DEBUG_LEAVE;

		return(NULL);
	}

	rootLen = strlen(XVFS_ROOT_MOUNTPOINT);
	pathStr = Tcl_GetString(path);

	fsName = ((char *) pathStr) + rootLen;

	fsNameEnds = strchr(fsName, '/');
	if (fsNameEnds) {
		origSep = *fsNameEnds;
		*fsNameEnds = '\0';
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047


1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
		XVFS_DEBUG_PUTS("... found no registered filesystem.");
	}

	XVFS_DEBUG_LEAVE;
	return(retval);
}

static int xvfs_tclfs_dispatch_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr) {
	static struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInstanceInfo(path);
	if (!instanceInfo) {
		return(-1);
	}

	return(xvfs_tclfs_pathInFilesystem(path, dataPtr, instanceInfo));
}

static int xvfs_tclfs_dispatch_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf) {
	struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInstanceInfo(path);
	if (!instanceInfo) {


		return(0);
	}

	return(xvfs_tclfs_stat(path, statBuf, instanceInfo));
}

static int xvfs_tclfs_dispatch_access(Tcl_Obj *path, int mode) {
	struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInstanceInfo(path);
	if (!instanceInfo) {
		return(-1);
	}

	return(xvfs_tclfs_access(path, mode, instanceInfo));
}

static Tcl_Channel xvfs_tclfs_dispatch_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions) {
	struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInstanceInfo(path);
	if (!instanceInfo) {
		return(NULL);
	}

	return(xvfs_tclfs_openFileChannel(interp, path, mode, permissions, instanceInfo));
}

static int xvfs_tclfs_dispatch_matchInDir(Tcl_Interp *interp, Tcl_Obj *resultPtr, Tcl_Obj *pathPtr, const char *pattern, Tcl_GlobTypeData *types) {
	struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInstanceInfo(pathPtr);
	if (!instanceInfo) {
		return(TCL_ERROR);
	}

	return(xvfs_tclfs_matchInDir(interp, resultPtr, pathPtr, pattern, types, instanceInfo));
}

static int xvfs_tclfs_dispatch_init(Tcl_Interp *interp) {
	static int registered = 0;
	int tclRet;

	/* XXX:TODO: Make this thread-safe */
	if (registered) {
		return(TCL_OK);
	}







<
<
<
<
<
<
<
<
<
<
<



|

>
>
|








|










|










|







|







1061
1062
1063
1064
1065
1066
1067











1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
		XVFS_DEBUG_PUTS("... found no registered filesystem.");
	}

	XVFS_DEBUG_LEAVE;
	return(retval);
}












static int xvfs_tclfs_dispatch_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf) {
	struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInfo(path);
	if (!instanceInfo) {
		Tcl_SetErrno(xvfs_errorToErrno(XVFS_RV_ERR_ENOENT));

		return(-1);
	}

	return(xvfs_tclfs_stat(path, statBuf, instanceInfo));
}

static int xvfs_tclfs_dispatch_access(Tcl_Obj *path, int mode) {
	struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInfo(path);
	if (!instanceInfo) {
		return(-1);
	}

	return(xvfs_tclfs_access(path, mode, instanceInfo));
}

static Tcl_Channel xvfs_tclfs_dispatch_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions) {
	struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInfo(path);
	if (!instanceInfo) {
		return(NULL);
	}

	return(xvfs_tclfs_openFileChannel(interp, path, mode, permissions, instanceInfo));
}

static int xvfs_tclfs_dispatch_matchInDir(Tcl_Interp *interp, Tcl_Obj *resultPtr, Tcl_Obj *pathPtr, const char *pattern, Tcl_GlobTypeData *types) {
	struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInfo(pathPtr);
	if (!instanceInfo) {
		return(TCL_ERROR);
	}

	return(xvfs_tclfs_matchInDir(interp, resultPtr, pathPtr, pattern, types, instanceInfo));
}

int Xvfs_Init(Tcl_Interp *interp) {
	static int registered = 0;
	int tclRet;

	/* XXX:TODO: Make this thread-safe */
	if (registered) {
		return(TCL_OK);
	}
1122
1123
1124
1125
1126
1127
1128

1129


1130
1131
1132
1133
1134
1135
1136
	xvfs_tclfs_dispatch_fs.renameFileProc             = NULL;
	xvfs_tclfs_dispatch_fs.copyDirectoryProc          = NULL;
	xvfs_tclfs_dispatch_fs.lstatProc                  = NULL;
	xvfs_tclfs_dispatch_fs.loadFileProc               = NULL;
	xvfs_tclfs_dispatch_fs.getCwdProc                 = NULL;
	xvfs_tclfs_dispatch_fs.chdirProc                  = NULL;


	tclRet = Tcl_FSRegister(NULL, &xvfs_tclfs_dispatch_fs);


	if (tclRet != TCL_OK) {
		if (interp) {
			Tcl_SetResult(interp, "Tcl_FSRegister() failed", NULL);
		}

		return(tclRet);
	}







>
|
>
>







1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
	xvfs_tclfs_dispatch_fs.renameFileProc             = NULL;
	xvfs_tclfs_dispatch_fs.copyDirectoryProc          = NULL;
	xvfs_tclfs_dispatch_fs.lstatProc                  = NULL;
	xvfs_tclfs_dispatch_fs.loadFileProc               = NULL;
	xvfs_tclfs_dispatch_fs.getCwdProc                 = NULL;
	xvfs_tclfs_dispatch_fs.chdirProc                  = NULL;

	memcpy(xvfs_tclfs_dispatch_fsdata.magic, XVFS_INTERNAL_SERVER_MAGIC, XVFS_INTERNAL_SERVER_MAGIC_LEN);
	xvfs_tclfs_dispatch_fsdata.registerProc = Xvfs_Register;

	tclRet = Tcl_FSRegister((ClientData) &xvfs_tclfs_dispatch_fsdata, &xvfs_tclfs_dispatch_fs);
	if (tclRet != TCL_OK) {
		if (interp) {
			Tcl_SetResult(interp, "Tcl_FSRegister() failed", NULL);
		}

		return(tclRet);
	}
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165

int Xvfs_Register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
	Tcl_HashEntry *mapEntry;
	struct xvfs_tclfs_instance_info *instanceInfo;
	int dispatchInitRet;
	int new;

	dispatchInitRet = xvfs_tclfs_dispatch_init(interp);
	if (dispatchInitRet != TCL_OK) {
		return(dispatchInitRet);
	}

	/*
	 * Verify this is for a protocol we support
	 */







|







1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195

int Xvfs_Register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
	Tcl_HashEntry *mapEntry;
	struct xvfs_tclfs_instance_info *instanceInfo;
	int dispatchInitRet;
	int new;

	dispatchInitRet = Xvfs_Init(interp);
	if (dispatchInitRet != TCL_OK) {
		return(dispatchInitRet);
	}

	/*
	 * Verify this is for a protocol we support
	 */

Modified xvfs-core.h from [d0f2e4af12] to [b57f187c12].

66
67
68
69
70
71
72

73
74
75
76
77
78
79

#elif defined(XVFS_MODE_SERVER)
/*
 * In server mode we are going to implementing Xvfs_Register()
 * for flexible/client modes, just forward declare it
 */
XVFS_REGISTER_INTERFACE(Xvfs_Register)


#else
#  error Unsupported XVFS_MODE
#endif

/*
 * In flexible or standalone mode, directly include what







>







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

#elif defined(XVFS_MODE_SERVER)
/*
 * In server mode we are going to implementing Xvfs_Register()
 * for flexible/client modes, just forward declare it
 */
XVFS_REGISTER_INTERFACE(Xvfs_Register)
int Xvfs_Init(Tcl_Interp *interp);

#else
#  error Unsupported XVFS_MODE
#endif

/*
 * In flexible or standalone mode, directly include what