Skip to content

Commit

Permalink
Merge branch 'master' into logdir_dyn
Browse files Browse the repository at this point in the history
  • Loading branch information
lxbsz committed May 4, 2018
2 parents 29c68f1 + 8847f90 commit d14d22d
Show file tree
Hide file tree
Showing 23 changed files with 460 additions and 196 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ cscope.*
ncscope.*
tcmu.conf_install.cmake
core.*
extra/rpmbuild
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ target_link_libraries(tcmu
${LIBNL_GENL_LIB}
${GLIB_LIBRARIES}
)
install(TARGETS tcmu LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS tcmu LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} NAMELINK_SKIP)

# Stuff for building the static library
add_library(tcmu_static
Expand Down Expand Up @@ -179,7 +179,7 @@ set_target_properties(handler_file_zbc
target_include_directories(handler_file_zbc
PUBLIC ${PROJECT_SOURCE_DIR}/ccan
)

install(TARGETS handler_file_zbc DESTINATION ${CMAKE_INSTALL_LIBDIR}/tcmu-runner)

# The minimal library consumer
add_executable(consumer
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ We encourage pull requests and issues tracking via Github, and the [target-devel
##### Building tcmu-runner

1. Clone this repo.
1. Type `./install_dep.sh` to install development packages for dependencies, or you can do it manually:
1. Type `./extra/install_dep.sh` to install development packages for dependencies, or you can do it manually:
* *Note:* Install cmake and other packages which usually ending with "-devel" or "-dev": libnl3, libglib2 (or glib2-devel on Fedora), libpthread, libdl, libkmod, libgfapi (Gluster), librbd1 (Ceph), zlib.
1. Type `cd tcmu-runner/`
1. Type `cmake .`
* *Note:* tcmu-runner can be compiled without the Gluster or qcow handlers using the `-Dwith-glfs=false` and `-Dwith-qcow=false` cmake parameters respectively.
* *Note:* If using systemd, `-DSUPPORT_SYSTEMD=ON -DCMAKE_INSTALL_PREFIX=/usr` should be passed to cmake, so files are installed to the correct location.
Expand Down
18 changes: 17 additions & 1 deletion api.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ uint64_t tcmu_get_lba(uint8_t *cdb)
return be64toh(*((u_int64_t *)&cdb[2]));
default:
assert_perror(EINVAL);
return 0; /* not reached */
}
}

Expand All @@ -99,6 +100,7 @@ uint32_t tcmu_get_xfer_length(uint8_t *cdb)
return be32toh(*((u_int32_t *)&cdb[10]));
default:
assert_perror(EINVAL);
return 0; /* not reached */
}
}

Expand Down Expand Up @@ -145,19 +147,33 @@ off_t tcmu_compare_with_iovec(void *mem, struct iovec *iovec, size_t size)
/*
* Consume an iovec. Count must not exceed the total iovec[] size.
*/
void tcmu_seek_in_iovec(struct iovec *iovec, size_t count)
size_t tcmu_seek_in_iovec(struct iovec *iovec, size_t count)
{
size_t consumed = 0;

while (count) {
if (count >= iovec->iov_len) {
count -= iovec->iov_len;
iovec->iov_len = 0;
iovec++;
consumed++;
} else {
iovec->iov_base += count;
iovec->iov_len -= count;
count = 0;
}
}

return consumed;
}

/*
* Consume an iovec. Count must not exceed the total iovec[] size.
* iove count should be updated.
*/
void tcmu_seek_in_cmd_iovec(struct tcmulib_cmd *cmd, size_t count)
{
cmd->iov_cnt -= tcmu_seek_in_iovec(cmd->iovec, count);
}

size_t tcmu_iovec_length(struct iovec *iovec, size_t iov_cnt)
Expand Down
49 changes: 47 additions & 2 deletions configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ int tcmu_get_attribute(struct tcmu_device *dev, const char *name)
return tcmu_get_cfgfs_int(path);
}

int tcmu_set_control(struct tcmu_device *dev, const char *key, unsigned long val)
{
char path[PATH_MAX];
char buf[CFGFS_BUF_SIZE];

snprintf(path, sizeof(path), CFGFS_CORE"/%s/%s/control",
dev->tcm_hba_name, dev->tcm_dev_name);
snprintf(buf, sizeof(buf), "%s=%lu", key, val);

return tcmu_set_cfgfs_str(path, buf, strlen(buf) + 1);
}

/*
* Return a string that contains the device's WWN, or NULL.
Expand Down Expand Up @@ -115,7 +126,16 @@ char *tcmu_get_wwn(struct tcmu_device *dev)
return ret_buf;
}

long long tcmu_get_device_size(struct tcmu_device *dev)
int tcmu_set_dev_size(struct tcmu_device *dev)
{
long long dev_size;

dev_size = tcmu_get_dev_num_lbas(dev) * tcmu_get_dev_block_size(dev);

return tcmu_set_control(dev, "dev_size", dev_size);
}

long long tcmu_get_dev_size(struct tcmu_device *dev)
{
int fd;
char path[PATH_MAX];
Expand Down Expand Up @@ -162,7 +182,7 @@ long long tcmu_get_device_size(struct tcmu_device *dev)

char *tcmu_get_cfgfs_str(const char *path)
{
int fd;
int fd, n;
char buf[CFGFS_BUF_SIZE];
ssize_t ret;
char *val;
Expand All @@ -186,6 +206,18 @@ char *tcmu_get_cfgfs_str(const char *path)
if (ret == 0)
return NULL;

/*
* Some files like members will terminate each member/line with a null
* char. Except for the last one, replace it with '\n' so parsers will
* just see an empty member.
*/
if (ret != strlen(buf)) {
do {
n = strlen(buf);
buf[n] = '\n';
} while (n < ret);
}

/*
* Some files like members ends with a null char, but other files like
* the alua ones end with a newline.
Expand Down Expand Up @@ -247,6 +279,19 @@ int tcmu_set_cfgfs_ul(const char *path, unsigned long val)
return tcmu_set_cfgfs_str(path, buf, strlen(buf) + 1);
}

bool tcmu_cfgfs_file_is_supported(struct tcmu_device *dev, const char *name)
{
char path[PATH_MAX];

snprintf(path, sizeof(path), CFGFS_CORE"/%s/%s/%s",
dev->tcm_hba_name, dev->tcm_dev_name, name);

if (access(path, F_OK) == -1)
return false;

return true;
}

int tcmu_exec_cfgfs_dev_action(struct tcmu_device *dev, const char *name,
unsigned long val)
{
Expand Down
2 changes: 1 addition & 1 deletion file_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct file_state {
int fd;
};

static int file_open(struct tcmu_device *dev)
static int file_open(struct tcmu_device *dev, bool reopen)
{
struct file_state *state;
char *config;
Expand Down
4 changes: 2 additions & 2 deletions file_optical.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static void fbo_report_op_change(struct tcmu_device *dev, uint8_t code)
}

/* Note: this is called per lun, not per mapping */
static int fbo_open(struct tcmu_device *dev)
static int fbo_open(struct tcmu_device *dev, bool reopen)
{
struct fbo_state *state;
int64_t size;
Expand Down Expand Up @@ -124,7 +124,7 @@ static int fbo_open(struct tcmu_device *dev)
tcmu_set_dev_block_size(dev, state->block_size);
#endif

size = tcmu_get_device_size(dev);
size = tcmu_get_dev_size(dev);
if (size == -1) {
tcmu_err("Could not get device size\n");
goto err;
Expand Down
Loading

0 comments on commit d14d22d

Please sign in to comment.