summaryrefslogtreecommitdiffstats
path: root/python_pgms/INFO
diff options
context:
space:
mode:
Diffstat (limited to 'python_pgms/INFO')
0 files changed, 0 insertions, 0 deletions
if (entry->d_stat.ia_type == IA_IFDIR) { child_loc.inode = inode_ref (entry->inode); gf_uuid_copy (child_loc.gfid, entry->inode->gfid); ret = syncop_ftw (subvol, &child_loc, pid, data, fn); loc_wipe (&child_loc); if (ret) break; } } gf_dirent_free (&entries); if (ret) break; } out: if (fd) fd_unref (fd); return ret; } /** * Syncop_ftw_throttle can be used in a configurable way to control * the speed at which crawling is done. It takes 2 more arguments * compared to syncop_ftw. * After @count entries are finished in a directory (to be * precise, @count files) sleep for @sleep_time seconds. * If either @count or @sleep_time is <=0, then it behaves similar to * syncop_ftw. */ int syncop_ftw_throttle (xlator_t *subvol, loc_t *loc, int pid, void *data, int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, void *data), int count, int sleep_time) { loc_t child_loc = {0, }; fd_t *fd = NULL; uint64_t offset = 0; gf_dirent_t *entry = NULL; int ret = 0; gf_dirent_t entries; int tmp = 0; if (sleep_time <= 0) { ret = syncop_ftw (subvol, loc, pid, data, fn); goto out; } ret = syncop_dirfd (subvol, loc, &fd, pid); if (ret) goto out; INIT_LIST_HEAD (&entries.list); while ((ret = syncop_readdirp (subvol, fd, 131072, offset, &entries, NULL, NULL))) { if (ret < 0) break; if (ret > 0) { /* If the entries are only '.', and '..' then ret * value will be non-zero. so set it to zero here. */ ret = 0; } tmp = 0; list_for_each_entry (entry, &entries.list, list) { offset = entry->d_off; if (!strcmp (entry->d_name, ".") || !strcmp (entry->d_name, "..")) continue; if (++tmp >= count) { tmp = 0; sleep (sleep_time); } gf_link_inode_from_dirent (NULL, fd->inode, entry); ret = fn (subvol, entry, loc, data); if (ret) continue; if (entry->d_stat.ia_type == IA_IFDIR) { child_loc.inode = inode_ref (entry->inode); gf_uuid_copy (child_loc.gfid, entry->inode->gfid); ret = syncop_ftw_throttle (subvol, &child_loc, pid, data, fn, count, sleep_time); loc_wipe (&child_loc); if (ret) continue; } } gf_dirent_free (&entries); if (ret) break; } out: if (fd) fd_unref (fd); return ret; } static void _scan_data_destroy (struct syncop_dir_scan_data *data) { GF_FREE (data); } static int _dir_scan_job_fn_cbk (int ret, call_frame_t *frame, void *opaque) { struct syncop_dir_scan_data *scan_data = opaque; _scan_data_destroy (scan_data); return 0; } static int _dir_scan_job_fn (void *data) { struct syncop_dir_scan_data *scan_data = data; gf_dirent_t *entry = NULL; int ret = 0; entry = scan_data->entry; scan_data->entry = NULL; do { ret = scan_data->fn (scan_data->subvol, entry, scan_data->parent, scan_data->data); gf_dirent_entry_free (entry); entry = NULL; pthread_mutex_lock (scan_data->mut); { if (ret) *scan_data->retval |= ret; if (list_empty (&scan_data->q->list)) { (*scan_data->jobs_running)--; pthread_cond_broadcast (scan_data->cond); } else { entry = list_first_entry (&scan_data->q->list, typeof (*scan_data->q), list); list_del_init (&entry->list); (*scan_data->qlen)--; } } pthread_mutex_unlock (scan_data->mut); } while (entry); return ret; } static int _run_dir_scan_task (call_frame_t *frame, xlator_t *subvol, loc_t *parent, gf_dirent_t *q, gf_dirent_t *entry, int *retval, pthread_mutex_t *mut, pthread_cond_t *cond, uint32_t *jobs_running, uint32_t *qlen, syncop_dir_scan_fn_t fn, void *data) { int ret = 0; struct syncop_dir_scan_data *scan_data = NULL; scan_data = GF_CALLOC (1, sizeof (struct syncop_dir_scan_data), gf_common_mt_scan_data); if (!scan_data) { ret = -ENOMEM; goto out; } scan_data->subvol = subvol; scan_data->parent = parent; scan_data->data = data; scan_data->mut = mut; scan_data->cond = cond; scan_data->fn = fn; scan_data->jobs_running = jobs_running; scan_data->entry = entry; scan_data->q = q; scan_data->qlen = qlen; scan_data->retval = retval; ret = synctask_new (subvol->ctx->env, _dir_scan_job_fn, _dir_scan_job_fn_cbk, frame, scan_data); out: if (ret < 0) { gf_dirent_entry_free (entry); _scan_data_destroy (scan_data); pthread_mutex_lock (mut); { *jobs_running = *jobs_running - 1; } pthread_mutex_unlock (mut); /*No need to cond-broadcast*/ } return ret; } int syncop_mt_dir_scan (call_frame_t *frame, xlator_t *subvol, loc_t *loc, int pid, void *data, syncop_dir_scan_fn_t fn, dict_t *xdata, uint32_t max_jobs, uint32_t max_qlen) { fd_t *fd = NULL; uint64_t offset = 0; gf_dirent_t *last = NULL; int ret = 0; int retval = 0; gf_dirent_t q; gf_dirent_t *entry = NULL; gf_dirent_t *tmp = NULL; uint32_t jobs_running = 0; uint32_t qlen = 0; pthread_cond_t cond; pthread_mutex_t mut; gf_boolean_t cond_init = _gf_false; gf_boolean_t mut_init = _gf_fal