// remove file gboolean dir_tree_file_remove (DirTree *dtree, fuse_ino_t ino, DirTree_file_remove_cb file_remove_cb, fuse_req_t req) { DirEntry *en; FileRemoveData *data; LOG_debug (DIR_TREE_LOG, "Removing inode %"INO_FMT, ino); en = g_hash_table_lookup (dtree->h_inodes, GUINT_TO_POINTER (ino)); // if entry does not exist // or it's not a directory type ? if (!en) { LOG_err (DIR_TREE_LOG, "Entry (ino = %"INO_FMT") not found !", ino); file_remove_cb (req, FALSE); return FALSE; } if (en->type != DET_file) { LOG_err (DIR_TREE_LOG, "Entry (ino = %"INO_FMT") is not a file !", ino); file_remove_cb (req, FALSE); return FALSE; } data = g_new0 (FileRemoveData, 1); data->dtree = dtree; data->ino = ino; data->en = en; data->file_remove_cb = file_remove_cb; data->req = req; s3client_pool_get_client (application_get_ops_client_pool (dtree->app), dir_tree_file_remove_on_http_client_cb, data); return TRUE; }
// return directory buffer from the cache // or regenerate directory cache void dir_tree_fill_dir_buf (DirTree *dtree, fuse_ino_t ino, size_t size, off_t off, dir_tree_readdir_cb readdir_cb, fuse_req_t req) { DirEntry *en; DirTreeFillDirData *dir_fill_data; time_t t; LOG_debug (DIR_TREE_LOG, "Requesting directory buffer for dir ino %"INO_FMT", size: %zd, off: %"OFF_FMT, ino, size, off); en = g_hash_table_lookup (dtree->h_inodes, GUINT_TO_POINTER (ino)); // if directory does not exist // or it's not a directory type ? if (!en || en->type != DET_dir) { LOG_msg (DIR_TREE_LOG, "Directory (ino = %"INO_FMT") not found !", ino); readdir_cb (req, FALSE, size, off, NULL, 0); return; } t = time (NULL); // already have directory buffer in the cache if (en->dir_cache_size && t >= en->dir_cache_created && t - en->dir_cache_created <= dtree->dir_cache_max_time) { LOG_debug (DIR_TREE_LOG, "Sending directory buffer (ino = %"INO_FMT") from cache !", ino); readdir_cb (req, TRUE, size, off, en->dir_cache, en->dir_cache_size); return; } LOG_debug (DIR_TREE_LOG, "cache time: %ld now: %ld", en->dir_cache_created, t); // reset dir cache if (en->dir_cache) g_free (en->dir_cache); en->dir_cache_size = 0; en->dir_cache_created = 0; dir_fill_data = g_new0 (DirTreeFillDirData, 1); dir_fill_data->dtree = dtree; dir_fill_data->ino = ino; dir_fill_data->size = size; dir_fill_data->off = off; dir_fill_data->readdir_cb = readdir_cb; dir_fill_data->req = req; dir_fill_data->en = en; if (!s3client_pool_get_client (application_get_ops_client_pool (dtree->app), dir_tree_fill_dir_on_http_ready, dir_fill_data)) { LOG_err (DIR_TREE_LOG, "Failed to get HTTP client !"); readdir_cb (req, FALSE, size, off, NULL, 0); g_free (dir_fill_data); } }
static void stat_srv_on_stats_cb (struct evhttp_request *req, void *ctx) { StatSrv *stat_srv = (StatSrv *) ctx; struct evbuffer *evb = NULL; gint ref = 0; GString *str; struct evhttp_uri *uri; guint32 total_inodes, file_num, dir_num; guint64 read_ops, write_ops, readdir_ops, lookup_ops; guint32 cache_entries; guint64 total_cache_size, cache_hits, cache_miss; struct tm *cur_p; struct tm cur; time_t now; char ts[50]; uri = evhttp_uri_parse (evhttp_request_get_uri (req)); LOG_debug (STAT_LOG, "Incoming request: %s from %s:%d", evhttp_request_get_uri (req), req->remote_host, req->remote_port); if (uri) { const gchar *query; query = evhttp_uri_get_query (uri); if (query) { const gchar *refresh = NULL; struct evkeyvalq q_params; TAILQ_INIT (&q_params); evhttp_parse_query_str (query, &q_params); refresh = http_find_header (&q_params, "refresh"); if (refresh) ref = atoi (refresh); evhttp_clear_headers (&q_params); } evhttp_uri_free (uri); } str = g_string_new (NULL); now = time (NULL); localtime_r (&now, &cur); cur_p = &cur; if (!strftime (ts, sizeof (ts), "%H:%M:%S", cur_p)) ts[0] = '\0'; g_string_append_printf (str, "RioFS version: %s Uptime: %u sec, Now: %s, Log level: %d, Dir cache time: %u sec<BR>", VERSION, (guint32)(now - stat_srv->boot_time), ts, log_level, conf_get_uint (application_get_conf (stat_srv->app), "filesystem.dir_cache_max_time")); // DirTree dir_tree_get_stats (application_get_dir_tree (stat_srv->app), &total_inodes, &file_num, &dir_num); g_string_append_printf (str, "<BR>DirTree: <BR>-Total inodes: %u, Total files: %u, Total directories: %u<BR>", total_inodes, file_num, dir_num); // Fuse rfuse_get_stats (application_get_rfuse (stat_srv->app), &read_ops, &write_ops, &readdir_ops, &lookup_ops); g_string_append_printf (str, "<BR>Fuse: <BR>-Read ops: %"G_GUINT64_FORMAT", Write ops: %"G_GUINT64_FORMAT ", Readdir ops: %"G_GUINT64_FORMAT", Lookup ops: %"G_GUINT64_FORMAT"<BR>", read_ops, write_ops, readdir_ops, lookup_ops); // CacheMng cache_mng_get_stats (application_get_cache_mng (stat_srv->app), &cache_entries, &total_cache_size, &cache_hits, &cache_miss); g_string_append_printf (str, "<BR>CacheMng: <BR>-Total entries: %"G_GUINT32_FORMAT", Total cache size: %"G_GUINT64_FORMAT " bytes, Cache hits: %"G_GUINT64_FORMAT", Cache misses: %"G_GUINT64_FORMAT" <BR>", cache_entries, total_cache_size, cache_hits, cache_miss); g_string_append_printf (str, "<BR>Read workers (%d): <BR>", client_pool_get_client_count (application_get_read_client_pool (stat_srv->app))); client_pool_get_client_stats_info (application_get_read_client_pool (stat_srv->app), str, &print_format_http); g_string_append_printf (str, "<BR>Write workers (%d): <BR>", client_pool_get_client_count (application_get_write_client_pool (stat_srv->app))); client_pool_get_client_stats_info (application_get_write_client_pool (stat_srv->app), str, &print_format_http); g_string_append_printf (str, "<BR>Op workers (%d): <BR>", client_pool_get_client_count (application_get_ops_client_pool (stat_srv->app))); client_pool_get_client_stats_info (application_get_ops_client_pool (stat_srv->app), str, &print_format_http); g_string_append_printf (str, "<BR><BR>Operation history (%u max items): <BR>", conf_get_uint (application_get_conf (stat_srv->app), "statistics.history_size")); g_queue_foreach (stat_srv->q_op_history, (GFunc) stat_srv_print_history_item, str); evb = evbuffer_new (); evbuffer_add_printf (evb, "<HTTP>"); if (ref) { evbuffer_add_printf (evb, "<HEAD><meta http-equiv=\"refresh\" content=\"%d\"></HEAD>", ref); } evbuffer_add_printf (evb, "<BODY>"); evbuffer_add (evb, str->str, str->len); evbuffer_add_printf (evb, "</BODY></HTTP>"); evhttp_send_reply (req, HTTP_OK, "OK", evb); evbuffer_free (evb); g_string_free (str, TRUE); }