/* * Routine to get the next character from the input stream. If we're reading * from the real terminal, force a screen update before we get the char. * Otherwise, we must be re-executing the command string, so just return the * next character. */ static int get_char(void) { int c; /* A place to get a character */ /* See if we're re-executing: */ if (cmd_reexecute >= 0 && (cmd_reexecute + 1) <= (int) itb_length(cmd_buff)) { c = itb_values(cmd_buff)[cmd_reexecute++]; } else { /* We're not re-executing (or aren't any more). Try for a real char */ cmd_reexecute = -1; /* Say we're in real mode again */ (void) update(FALSE); /* Pretty up the screen */ c = keystroke8(); /* Get the next character */ itb_append(&cmd_buff, c); } return (c); /* Return the character */ }
/* racer create a new thread and access the metadata/itb file randomizely */ void *racer(void *arg) { struct itb *itb; struct fdhash_entry *fde; struct itb_info ii; u64 duuid = (u64)arg; struct mmap_args ma = {0, }; range_t *range; int len, range_begin, range_end, err, counter = 0; itb = xmalloc(sizeof(*itb) + ITB_SIZE * sizeof(struct ite)); if (!itb) { hvfs_err(mdsl, "xmalloc ITB failed\n"); racer_stop = 1; } range_begin = sizeof(itb->h); range_end = sizeof(*itb) + ITB_SIZE * sizeof(struct ite); while (!racer_stop) { xsleep(lib_random(0xffff)); /* try to append more itb to the itb file */ len = lib_random(range_end - range_begin) + range_begin; atomic_set(&itb->h.len, len); itb->h.itbid = lib_random(0xfff); itb->h.puuid = duuid; err = itb_append(itb, &ii, hmo.site_id, 0); if (err) { hvfs_err(mdsl, "Append itb <> to disk file failed w/ %d\n", err); continue; } else { hvfs_info(mdsl, "Append (%d) itb %ld len %d to itb file %ld\n", (++counter), itb->h.itbid, atomic_read(&itb->h.len), ii.master); } /* open the md file and try to update the ranges */ fde = mdsl_storage_fd_lookup_create(duuid, MDSL_STORAGE_MD, 0); if (IS_ERR(fde)) { hvfs_err(mdsl, "lookup create MD file failed w/ %ld\n", PTR_ERR(fde)); continue; } if (ii.master < fde->mdisk.itb_master) { hvfs_info(mdsl, "Drop obsolete itb %ld appending %ld\n", itb->h.itbid, ii.location); goto put_fde; } ma.win = MDSL_STORAGE_DEFAULT_RANGE_SIZE; relookup: xlock_lock(&fde->lock); err = __mdisk_lookup_nolock(fde, MDSL_MDISK_RANGE, itb->h.itbid, &range); if (err == -ENOENT) { /* create a new range now */ u64 i; i = MDSL_STORAGE_idx2range(itb->h.itbid); __mdisk_add_range_nolock(fde, i * MDSL_STORAGE_RANGE_SLOTS, (i + 1) * MDSL_STORAGE_RANGE_SLOTS - 1, fde->mdisk.range_aid++); __mdisk_range_sort(fde->mdisk.new_range, fde->mdisk.new_size); xlock_unlock(&fde->lock); goto relookup; } else if (err) { hvfs_err(mdsl, "mdisk_lookup_nolock failed w/ %d\n", err); xlock_unlock(&fde->lock); goto put_fde; } xlock_unlock(&fde->lock); ma.foffset = 0; ma.range_id = range->range_id; ma.range_begin = range->begin; ma.flag = MA_OFFICIAL; err = __range_write(duuid, itb->h.itbid, &ma, ii.location); if (err) { hvfs_err(mdsl, "range write failed w/ %d\n", err); goto put_fde; } err = __mdisk_write(fde, NULL); if (err) { hvfs_err(mdsl, "sync md file failed w/ %d\n", err); } put_fde: mdsl_storage_fd_put(fde); } pthread_exit(0); }