pnfs: simplified logic for calculating next stripe unit
added stripe_next_unit() in pnfs_io.c, removed pnfs_file_device_io_unit() from pnfs_device.c moved get_sparse_fh()/get_dense_fh() to pnfs_io.c, now only called once on pattern_init() Signed-off-by: Casey Bodley <cbodley@citi.umich.edu>
This commit is contained in:
parent
91609640df
commit
904cae13f0
3 changed files with 152 additions and 148 deletions
|
|
@ -324,106 +324,6 @@ out:
|
|||
}
|
||||
|
||||
|
||||
/* 13.4.2. Interpreting the File Layout Using Sparse Packing
|
||||
* http://tools.ietf.org/html/rfc5661#section-13.4.2 */
|
||||
|
||||
static enum pnfs_status get_sparse_fh(
|
||||
IN pnfs_io_pattern *pattern,
|
||||
IN uint32_t stripeid,
|
||||
OUT nfs41_path_fh **file_out)
|
||||
{
|
||||
pnfs_file_layout *layout = pattern->layout;
|
||||
const uint32_t filehandle_count = layout->filehandles.count;
|
||||
const uint32_t server_count = layout->device->servers.count;
|
||||
enum pnfs_status status = PNFS_SUCCESS;
|
||||
|
||||
if (filehandle_count == server_count) {
|
||||
const uint32_t serverid = data_server_index(layout->device, stripeid);
|
||||
*file_out = &layout->filehandles.arr[serverid];
|
||||
} else if (filehandle_count == 1) {
|
||||
*file_out = &layout->filehandles.arr[0];
|
||||
} else if (filehandle_count == 0) {
|
||||
*file_out = pattern->meta_file;
|
||||
} else {
|
||||
eprintf("invalid sparse layout! has %u file handles "
|
||||
"and %u servers\n", filehandle_count, server_count);
|
||||
status = PNFSERR_INVALID_FH_LIST;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/* 13.4.3. Interpreting the File Layout Using Dense Packing
|
||||
* http://tools.ietf.org/html/rfc5661#section-13.4.3 */
|
||||
|
||||
static enum pnfs_status get_dense_fh(
|
||||
IN pnfs_io_pattern *pattern,
|
||||
IN uint32_t stripeid,
|
||||
OUT nfs41_path_fh **file_out)
|
||||
{
|
||||
pnfs_file_layout *layout = pattern->layout;
|
||||
const uint32_t filehandle_count = layout->filehandles.count;
|
||||
const uint32_t stripe_count = layout->device->stripes.count;
|
||||
enum pnfs_status status = PNFS_SUCCESS;
|
||||
|
||||
if (filehandle_count == stripe_count) {
|
||||
*file_out = &layout->filehandles.arr[stripeid];
|
||||
} else {
|
||||
eprintf("invalid dense layout! has %u file handles "
|
||||
"and %u stripes\n", filehandle_count, stripe_count);
|
||||
status = PNFSERR_INVALID_FH_LIST;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static __inline uint64_t positive_remainder(
|
||||
IN uint64_t dividend,
|
||||
IN uint32_t divisor)
|
||||
{
|
||||
const uint64_t remainder = dividend % divisor;
|
||||
return remainder < divisor ? remainder : remainder + divisor;
|
||||
}
|
||||
|
||||
/* 13.4.4. Sparse and Dense Stripe Unit Packing
|
||||
* http://tools.ietf.org/html/rfc5661#section-13.4.4 */
|
||||
|
||||
enum pnfs_status pnfs_file_device_io_unit(
|
||||
IN pnfs_io_pattern *pattern,
|
||||
IN uint64_t offset,
|
||||
OUT pnfs_io_unit *io)
|
||||
{
|
||||
pnfs_file_layout *layout = pattern->layout;
|
||||
enum pnfs_status status = PNFS_SUCCESS;
|
||||
|
||||
const uint32_t unit_size = layout_unit_size(layout);
|
||||
const uint32_t stripe_count = layout->device->stripes.count;
|
||||
const uint64_t sui = stripe_unit_number(layout, offset, unit_size);
|
||||
const uint64_t offset_end = layout->pattern_offset + unit_size * (sui + 1);
|
||||
|
||||
io->stripeid = stripe_index(layout, sui, stripe_count);
|
||||
io->serverid = data_server_index(layout->device, io->stripeid);
|
||||
|
||||
if (is_dense(layout)) {
|
||||
const uint64_t rel_offset = offset - layout->pattern_offset;
|
||||
const uint64_t remainder = positive_remainder(rel_offset, unit_size);
|
||||
const uint32_t stride = unit_size * stripe_count;
|
||||
|
||||
io->offset = (rel_offset / stride) * unit_size + remainder;
|
||||
|
||||
status = get_dense_fh(pattern, io->stripeid, &io->file);
|
||||
} else {
|
||||
io->offset = offset;
|
||||
|
||||
status = get_sparse_fh(pattern, io->stripeid, &io->file);
|
||||
}
|
||||
|
||||
io->buffer = pattern->buffer + offset - pattern->offset_start;
|
||||
io->length = offset_end - offset;
|
||||
if (offset + io->length > pattern->offset_end)
|
||||
io->length = pattern->offset_end - offset;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/* CB_NOTIFY_DEVICEID */
|
||||
enum pnfs_status pnfs_file_device_notify(
|
||||
IN struct pnfs_file_device_list *devices,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue