Skip to content

Commit

Permalink
Make minimum/maximum blocksize writing a capability.
Browse files Browse the repository at this point in the history
Instead of only allowing minumum/maximum blocksize writing a tape
specific operation make it generic by using a capability setting which
is enable by default on tape devices but also on elasto devices.
  • Loading branch information
Marco van Wieringen committed Aug 20, 2015
1 parent e73f315 commit 6682949
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/stored/backends/elasto_device.c
Expand Up @@ -386,6 +386,7 @@ elasto_device::elasto_device()
m_insecure_http = false;
m_efh = NULL;
m_virtual_filename = get_pool_memory(PM_FNAME);
set_cap(CAP_ADJWRITESIZE); /* Adjust write size to min/max */
}

#ifdef HAVE_DYNAMIC_SD_BACKENDS
Expand Down
1 change: 1 addition & 0 deletions src/stored/backends/unix_tape_device.c
Expand Up @@ -42,6 +42,7 @@ unix_tape_device::~unix_tape_device()

unix_tape_device::unix_tape_device()
{
set_cap(CAP_ADJWRITESIZE); /* Adjust write size to min/max */
}

#ifdef HAVE_DYNAMIC_SD_BACKENDS
Expand Down
41 changes: 20 additions & 21 deletions src/stored/block.c
Expand Up @@ -473,60 +473,58 @@ bool DCR::write_block_to_dev()

/*
* Clear to the end of the buffer if it is not full,
* and on tape devices, apply min and fixed blocking.
* and on devices with CAP_ADJWRITESIZE set, apply min and fixed blocking.
*/
if (wlen != block->buf_len) {
uint32_t blen; /* current buffer length */

Dmsg2(250, "binbuf=%d buf_len=%d\n", block->binbuf, block->buf_len);
blen = wlen;

/*
* Adjust write size to min/max for tapes only
*/
if (dev->is_tape()) {
/*
* Check for fixed block size
*/
if (dev->has_cap(CAP_ADJWRITESIZE)) {
if (dev->min_block_size == dev->max_block_size) {
/*
* Fixed block size
*/
wlen = block->buf_len; /* fixed block size already rounded */
/*
* Check for min block size
*/
} else if (wlen < dev->min_block_size) {
/*
* Min block size
*/
wlen = ((dev->min_block_size + TAPE_BSIZE - 1) / TAPE_BSIZE) * TAPE_BSIZE;
/*
* Ensure size is rounded
*/
} else {
/*
* Ensure size is rounded
*/
wlen = ((wlen + TAPE_BSIZE - 1) / TAPE_BSIZE) * TAPE_BSIZE;
}
}

Dmsg4(400, "writing block of size %d to dev=%s with max_block_size %d and min_block_size %d\n",
wlen, dev->print_name(), dev->max_block_size, dev->min_block_size);
wlen, dev->print_name(), dev->max_block_size, dev->min_block_size);

if (wlen-blen > 0) {
memset(block->bufp, 0, wlen-blen); /* clear garbage */
if (wlen - blen > 0) {
memset(block->bufp, 0, wlen - blen); /* clear garbage */
}
}

Dmsg4(400, "writing block of size %d to dev=%s with max_block_size %d and min_block_size %d\n",
wlen, dev->print_name(), dev->max_block_size, dev->min_block_size);

wlen, dev->print_name(), dev->max_block_size, dev->min_block_size);

checksum = ser_block_header(block, dev->do_checksum());

/*
* Limit maximum Volume size to value specified by user
*/
hit_max1 = (dev->max_volume_size > 0) &&
((dev->VolCatInfo.VolCatBytes + block->binbuf)) >= dev->max_volume_size;
((dev->VolCatInfo.VolCatBytes + block->binbuf)) >= dev->max_volume_size;
hit_max2 = (dev->VolCatInfo.VolCatMaxBytes > 0) &&
((dev->VolCatInfo.VolCatBytes + block->binbuf)) >= dev->VolCatInfo.VolCatMaxBytes;
((dev->VolCatInfo.VolCatBytes + block->binbuf)) >= dev->VolCatInfo.VolCatMaxBytes;

if (hit_max1 || hit_max2) {
char ed1[50];
uint64_t max_cap;

Dmsg0(100, "==== Output bytes Triggered medium max capacity.\n");
if (hit_max1) {
max_cap = dev->max_volume_size;
Expand All @@ -538,6 +536,7 @@ bool DCR::write_block_to_dev()
terminate_writing_volume(dcr);
reread_last_block(dcr); /* DEBUG */
dev->dev_errno = ENOSPC;

return false;
}

Expand Down
5 changes: 3 additions & 2 deletions src/stored/dev.h
Expand Up @@ -162,13 +162,14 @@ enum {
CAP_CHECKLABELS = 22, /* Check for ANSI/IBM labels */
CAP_BLOCKCHECKSUM = 23, /* Create/test block checksum */
CAP_IOERRATEOM = 24, /* IOError at EOM */
CAP_IBMLINTAPE = 25 /* Using IBM lin_tape driver */
CAP_IBMLINTAPE = 25, /* Using IBM lin_tape driver */
CAP_ADJWRITESIZE = 26 /* Adjust write size to min/max */
};

/*
* Keep this set to the last entry in the enum.
*/
#define CAP_MAX CAP_IBMLINTAPE
#define CAP_MAX CAP_ADJWRITESIZE

/*
* Make sure you have enough bits to store all above bit fields.
Expand Down
1 change: 1 addition & 0 deletions src/win32/stored/backends/win32_tape_device.c
Expand Up @@ -1072,4 +1072,5 @@ win32_tape_device::~win32_tape_device()

win32_tape_device::win32_tape_device()
{
set_cap(CAP_ADJWRITESIZE); /* Adjust write size to min/max */
}

0 comments on commit 6682949

Please sign in to comment.