void delete_stat_cache_entry(const char *path) { if(foreground) cout << " delete_stat_cache_entry[path=" << path << "]" << endl; pthread_mutex_lock(&stat_cache_lock); stat_cache_t::iterator iter = stat_cache.find(path); if(iter != stat_cache.end()) stat_cache.erase(iter); pthread_mutex_unlock(&stat_cache_lock); }
void truncate_stat_cache() { string path_to_delete; unsigned int hit_count = 0; unsigned int lowest_hit_count = 0; pthread_mutex_lock(&stat_cache_lock); stat_cache_t::iterator iter; for(iter = stat_cache.begin(); iter != stat_cache.end(); iter++) { hit_count = (* iter).second.hit_count; if(!lowest_hit_count) lowest_hit_count = hit_count; if(lowest_hit_count > hit_count) path_to_delete = (* iter).first; } stat_cache.erase(path_to_delete); pthread_mutex_unlock(&stat_cache_lock); cout << " purged " << path_to_delete << " from the stat cache" << endl; }
static int s3fs_getattr(const char *path, struct stat *stbuf) { cout << "getattr[path=" << path << "]" << endl; memset(stbuf, 0, sizeof(struct stat)); if (strcmp(path, "/") == 0) { stbuf->st_nlink = 1; // see fuse faq stbuf->st_mode = root_mode | S_IFDIR; return 0; } { auto_lock lock(stat_cache_lock); stat_cache_t::iterator iter = stat_cache.find(path); if (iter != stat_cache.end()) { *stbuf = (*iter).second; stat_cache.erase(path); return 0; } } string resource = urlEncode(service_path +bucket + path); string url = host + resource; auto_curl curl; curl_easy_setopt(curl, CURLOPT_FAILONERROR, true); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true); curl_easy_setopt(curl, CURLOPT_NOBODY, true); // HEAD curl_easy_setopt(curl, CURLOPT_FILETIME, true); // Last-Modified headers_t responseHeaders; curl_easy_setopt(curl, CURLOPT_HEADERDATA, &responseHeaders); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback); auto_curl_slist headers; string date = get_date(); headers.append("Date: "+date); headers.append("Content-Type: "); headers.append("Authorization: AWS "+AWSAccessKeyId+":"+calc_signature("HEAD", "", date, headers.get(), resource)); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.get()); string my_url = prepare_url(url.c_str()); curl_easy_setopt(curl, CURLOPT_URL, my_url.c_str()); VERIFY(my_curl_easy_perform(curl.get())); stbuf->st_nlink = 1; // see fuse faq stbuf->st_mtime = strtoul(responseHeaders["x-amz-meta-mtime"].c_str(), (char **)NULL, 10); if (stbuf->st_mtime == 0) { long LastModified; if (curl_easy_getinfo(curl, CURLINFO_FILETIME, &LastModified) == 0) stbuf->st_mtime = LastModified; } stbuf->st_mode = strtoul(responseHeaders["x-amz-meta-mode"].c_str(), (char **)NULL, 10); char* ContentType = 0; if (curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ContentType) == 0) { if (ContentType) stbuf->st_mode |= strcmp(ContentType, "application/x-directory") == 0 ? S_IFDIR : S_IFREG; } double ContentLength; if (curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &ContentLength) == 0) stbuf->st_size = static_cast<off_t>(ContentLength); if (S_ISREG(stbuf->st_mode)) stbuf->st_blocks = stbuf->st_size / 512 + 1; stbuf->st_uid = strtoul(responseHeaders["x-amz-meta-uid"].c_str(), (char **)NULL, 10); stbuf->st_gid = strtoul(responseHeaders["x-amz-meta-gid"].c_str(), (char **)NULL, 10); return 0; }