Check-in [1e2435553a]
Overview
Comment:Fixed inode lookup and determination of a file being packaged or not
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:1e2435553a4cdb1c2e2d07cf0d2fe706cbc062a8
User & Date: rkeene on 2015-07-31 03:02:37
Other Links: manifest | tags
Context
2015-10-14
17:47
Changed mount options to remove "direct_io", which breaks mmap and performed additional cleanups check-in: 1c47ca9097 user: rkeene tags: trunk
2015-07-31
03:02
Fixed inode lookup and determination of a file being packaged or not check-in: 1e2435553a user: rkeene tags: trunk
2015-05-26
15:46
Post-release version increment check-in: f90c4863fb user: rkeene tags: trunk
Changes

Modified appfsd.c from [388927f9ca] to [647fdab61a].

   646    646   	}
   647    647   
   648    648   	if (uid >= 0) {
   649    649   		retval += uid;
   650    650   		retval++;
   651    651   	}
   652    652   
          653  +	APPFS_DEBUG("Looked up inode number for path=%s,uid=%i: %u", path, uid, retval);
          654  +
   653    655   	return(retval);
   654    656   }
   655    657   
   656    658   /*
   657    659    * Cache Get Path Info lookups for speed
   658    660    */
   659    661   static int appfs_get_path_info_cache_get(const char *path, uid_t uid, struct appfs_pathinfo *pathinfo) {
................................................................................
   665    667   
   666    668   	pthread_ret = pthread_mutex_lock(&appfs_path_info_cache_mutex);
   667    669   	if (pthread_ret != 0) {
   668    670   		APPFS_DEBUG("Unable to lock path_info cache mutex !");
   669    671   
   670    672   		return(-1);
   671    673   	}
          674  +
          675  +	APPFS_DEBUG("Looking up cache entry for path=%s,uid=%lli...", path, (long long) uid);
   672    676   
   673    677   	if (appfs_path_info_cache != NULL) {
   674    678   		hash_idx = (appfs_get_path_inode(path, uid)) % appfs_path_info_cache_size;
   675    679   
   676    680   		if (appfs_path_info_cache[hash_idx]._cache_path != NULL) {
   677    681   			if (strcmp(appfs_path_info_cache[hash_idx]._cache_path, path) == 0 && appfs_path_info_cache[hash_idx]._cache_uid == uid) {
   678    682   				retval = 0;
................................................................................
   687    691   	if (pthread_ret != 0) {
   688    692   		APPFS_DEBUG("Unable to unlock path_info cache mutex !");
   689    693   
   690    694   		return(-1);
   691    695   	}
   692    696   
   693    697   	if (retval == 0) {
   694         -		APPFS_DEBUG("Cache hit on %s", path);
          698  +		APPFS_DEBUG("Cache hit on path=%s,uid=%lli", path, (long long) uid);
   695    699   	} else {
   696         -		APPFS_DEBUG("Cache miss on %s", path);
          700  +		APPFS_DEBUG("Cache miss on path=%s,uid=%lli", path, (long long) uid);
   697    701   	}
   698    702   
   699    703   	return(retval);
   700    704   }
   701    705   
   702    706   static void appfs_get_path_info_cache_add(const char *path, uid_t uid, struct appfs_pathinfo *pathinfo) {
   703    707   	unsigned int hash_idx;
................................................................................
  1019   1023   
  1020   1024   	if (pathinfo->packaged) {
  1021   1025   		pathinfo->inode = appfs_get_path_inode(path, -1);
  1022   1026   	} else {
  1023   1027   		pathinfo->inode = appfs_get_path_inode(path, fsuid);
  1024   1028   	}
  1025   1029   
         1030  +	APPFS_DEBUG("Caching inode for path=%s,uid=%lli as %llu (packaged = %i)", path, (long long) fsuid, pathinfo->inode, pathinfo->packaged);
         1031  +
  1026   1032   	if (retval == 0) {
  1027   1033   		appfs_get_path_info_cache_add(path, fsuid, pathinfo);
  1028   1034   	} else {
  1029   1035   		APPFS_DEBUG("error: Invalid type for \"%s\" from Tcl", path);
  1030   1036   	}
  1031   1037   
  1032   1038   	return(retval);
................................................................................
  1211   1217   		case APPFS_PATHTYPE_FILE:
  1212   1218   			stbuf->st_mode = S_IFREG | 0444;
  1213   1219   
  1214   1220   			if (pathinfo.typeinfo.file.executable) {
  1215   1221   				stbuf->st_mode |= 0111;
  1216   1222   			}
  1217   1223   
         1224  +			if (pathinfo.packaged) {
  1218   1225   			if (pathinfo.typeinfo.file.suidRoot) {
  1219   1226   				changeOwnerToUserIfPackaged = 0;
  1220   1227   
  1221   1228   				stbuf->st_mode |= 04000;
  1222   1229   			}
         1230  +			}
  1223   1231   
  1224   1232   			if (pathinfo.typeinfo.file.worldaccessible) {
  1225   1233   				stbuf->st_mode &= ~077;
  1226   1234   			}
  1227   1235   
  1228   1236   			stbuf->st_nlink = 1;
  1229   1237   			stbuf->st_size = pathinfo.typeinfo.file.size;
................................................................................
  1250   1258   			break;
  1251   1259   		case APPFS_PATHTYPE_INVALID:
  1252   1260   			retval = -EIO;
  1253   1261   
  1254   1262   			break;
  1255   1263   	}
  1256   1264   
  1257         -	if (pathinfo.packaged && changeOwnerToUserIfPackaged) {
         1265  +	if ((pathinfo.packaged && changeOwnerToUserIfPackaged) || (!pathinfo.packaged)) {
  1258   1266   		stbuf->st_uid   = appfs_get_fsuid();
  1259   1267   		stbuf->st_gid   = appfs_get_fsgid();
  1260   1268   		stbuf->st_mode |= 0200;
  1261   1269   	}
  1262   1270   
  1263   1271   	return(retval);
  1264   1272   }
................................................................................
  2016   2024   #else
  2017   2025   	appfs_threaded_tcl = 0;
  2018   2026   #endif
  2019   2027   
  2020   2028   	/**
  2021   2029   	 ** Add FUSE arguments which we always supply
  2022   2030   	 **/
  2023         -	fuse_opt_add_arg(args, "-odefault_permissions,fsname=appfs,subtype=appfsd,use_ino,kernel_cache,entry_timeout=0,attr_timeout=0,big_writes,intr,hard_remove");
         2031  +	fuse_opt_add_arg(args, "-odefault_permissions,fsname=appfs,subtype=appfsd,use_ino,direct_io,entry_timeout=0,attr_timeout=0,big_writes,intr,hard_remove");
  2024   2032   
  2025   2033   	if (getuid() == 0) {
  2026   2034   		fuse_opt_parse(args, NULL, NULL, NULL);
  2027   2035   		fuse_opt_add_arg(args, "-oallow_other");
  2028   2036   
  2029   2037   		/*
  2030   2038   		 * This should generally be avoided, but if there are security

Modified appfsd.tcl from [a394650d8e] to [e7e131fd9c].

   675    675   		array set retval [list]
   676    676   
   677    677   		catch {
   678    678   			::appfs::getindex $pathinfo(hostname)
   679    679   			::appfs::getpkgmanifest $pathinfo(hostname) $pathinfo(package_sha1)
   680    680   		}
   681    681   
          682  +		set retval(path_type) $pathinfo(_type)
          683  +
   682    684   		switch -- $pathinfo(_type) {
   683    685   			"toplevel" {
   684    686   				set retval(type) directory
   685    687   				set retval(childcount) [llength [getchildren $path]]
   686    688   			}
   687    689   			"sites" {
   688    690   				set check [::appfs::db onecolumn {SELECT 1 FROM packages WHERE hostname = $pathinfo(hostname);}]
................................................................................
   752    754   							file lstat $localpath localpathinfo
   753    755   						}
   754    756   					}
   755    757   				}
   756    758   
   757    759   				if {$localpath != "" && [info exists localpathinfo]} {
   758    760   					set retval(is_localfile) 1
          761  +					unset retval(packaged)
   759    762   					catch {
   760    763   						set retval(time) $localpathinfo(mtime)
   761    764   
   762    765   						switch -- $localpathinfo(type) {
   763    766   							"directory" {
   764    767   								set retval(type) "directory"
   765    768   								set retval(childcount) [llength [getchildren $path]]
................................................................................
   837    840   		return [array get retval]
   838    841   	}
   839    842   
   840    843   	proc openpath {path mode} {
   841    844   		array set pathinfo [_parsepath $path]
   842    845   
   843    846   		if {$pathinfo(_type) != "files"} {
   844         -			return -code error "invalid type"
          847  +			return -code error "invalid path type: Got \"$pathinfo(_type)\", need \"files\""
   845    848   		}
   846    849   
   847    850   		set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
   848    851   
   849    852   		if {$mode == "create"} {
   850    853   			if {$localpath == ""} {
   851    854   				return -code error "Asked to create, but no home directory."
................................................................................
   901    904   		return $localcachefile
   902    905   	}
   903    906   
   904    907   	proc localpath {path} {
   905    908   		array set pathinfo [_parsepath $path]
   906    909   
   907    910   		if {$pathinfo(_type) != "files"} {
   908         -			return -code error "invalid type"
          911  +			return -code error "invalid path type: Got \"$pathinfo(_type)\", need \"files\""
   909    912   		}
   910    913   
   911    914   		set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
   912    915   
   913    916   		return $localpath
   914    917   	}
   915    918   
................................................................................
   950    953   
   951    954   		return $filename
   952    955   	}
   953    956   
   954    957   	proc unlinkpath {path} {
   955    958   		array set pathattrs [exists $path]
   956    959   
   957         -		if {![info exists pathattrs(packaged)]} {
   958         -			return -code error "invalid type"
          960  +		if {$pathattrs(path_type) != "files"} {
          961  +			return -code error "invalid path type: can only delete type \"files\" this is type \"$pathattrs(path_type)\""
   959    962   		}
   960    963   
   961    964   		set localpath $pathattrs(localpath)
   962    965   
   963    966   		if {$localpath == ""} {
   964    967   			return -code error "Asked to delete, but no home directory."
   965    968   		}