int traverse (dirscan_t *d, dirscan_entry_t *entry) { omfs_inode_t *ino, *tmp; dirscan_entry_t *enew; int res; d->visit_error = d->visit(d, entry, d->user_data); ino = entry->inode; /* push next sibling all then all children */ if (ino->i_sibling != ~0) { tmp = omfs_get_inode(d->omfs_info, swap_be64(ino->i_sibling)); if (!tmp) { res = -1; goto out; } enew = _create_entry(tmp, entry->level, entry->hindex, entry->parent, swap_be64(ino->i_sibling)); traverse(d, enew); } if (ino->i_type == OMFS_DIR) { int i; u64 *ptr = (u64*) ((u8*) ino + OMFS_DIR_START); int num_entries = (swap_be32(ino->i_head.h_body_size) + sizeof(omfs_header_t) - OMFS_DIR_START) / 8; for (i=0; i<num_entries; i++, ptr++) { u64 inum = swap_be64(*ptr); if (inum != ~0) { tmp = omfs_get_inode(d->omfs_info, inum); if (!tmp) { res = -1; goto out; } enew = _create_entry(tmp, entry->level+1, i, entry->block, inum); traverse(d, enew); } } } out: dirscan_release_entry(entry); return res; }
/* * updown_event_metric_update * * updown event module metric_update function. Store results the * updown cache appropriately. */ static int updown_event_metric_update(const char *nodename, const char *metric_name, unsigned int metric_value_type, unsigned int metric_value_len, void *metric_value, struct cerebro_event **event) { int *state = NULL; int rv = 0; /* If the node isn't recorded, it's the first notification * that it's down. */ if (!(state = hash_find(node_states, nodename))) { if (!(state = _create_entry(nodename))) return -1; } if (*state == UPDOWN_EVENT_STATE_DOWN) { struct cerebro_event *eventPtr = NULL; if ((eventPtr = _create_event(nodename, UPDOWN_EVENT_STATE_UP))) { *event = eventPtr; rv = 1; } } *state = UPDOWN_EVENT_STATE_UP; return rv; }
int dirscan_begin(omfs_info_t *info, int (*visit)(dirscan_t *, dirscan_entry_t*, void*), void *user_data) { omfs_inode_t *root_ino; int res; dirscan_t *d = calloc(sizeof(dirscan_t), 1); if (!d) goto error; d->omfs_info = info; d->visit = visit; d->user_data = user_data; root_ino = omfs_get_inode(info, swap_be64(info->root->r_root_dir)); if (!root_ino) goto error; res = traverse(d, _create_entry(root_ino, 0, 0, ~0, swap_be64(info->root->r_root_dir))); dirscan_end(d); return !d->visit_error; error: if (d) free(d); return -1; }
/* * updown_event_node_timeout * * updown event module node_timeout function */ static int updown_event_node_timeout(const char *nodename, struct cerebro_event **event) { int *state = NULL; int rv = 0; /* If the node isn't recorded, it's the first notification * that it's down. */ if (!(state = hash_find(node_states, nodename))) { if (!(state = _create_entry(nodename))) return -1; } #if 0 /* For debugging */ if (*state == UPDOWN_EVENT_STATE_INIT) { struct cerebro_event *eventPtr = NULL; if ((eventPtr = _create_event(nodename, UPDOWN_EVENT_STATE_DOWN))) { *event = eventPtr; rv = 1; } } #endif if (*state == UPDOWN_EVENT_STATE_UP) { struct cerebro_event *eventPtr = NULL; if ((eventPtr = _create_event(nodename, UPDOWN_EVENT_STATE_DOWN))) { *event = eventPtr; rv = 1; } } *state = UPDOWN_EVENT_STATE_DOWN; return rv; }