Skip to content

Commit

Permalink
Move tcmu_get_runner_handler
Browse files Browse the repository at this point in the history
tcmu_get_runner_handler does not belong in scsi.c. Put it in runner and
add a get/set helper to check if unmap is enabled on a device so we do
not even need to have scsi.c call the get runner handler function.
  • Loading branch information
Mike Christie committed Dec 5, 2018
1 parent 4e92768 commit 5bf04d0
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 11 deletions.
10 changes: 10 additions & 0 deletions libtcmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,16 @@ bool tcmu_dev_get_solid_state_media(struct tcmu_device *dev)
return dev->solid_state_media;
}

void tcmu_dev_set_unmap_enabled(struct tcmu_device *dev, bool enabled)
{
dev->unmap_enabled = enabled;
}

bool tcmu_dev_get_unmap_enabled(struct tcmu_device *dev)
{
return dev->unmap_enabled;
}

int tcmu_dev_get_fd(struct tcmu_device *dev)
{
return dev->fd;
Expand Down
2 changes: 2 additions & 0 deletions libtcmu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ void tcmu_dev_set_write_cache_enabled(struct tcmu_device *dev, bool enabled);
bool tcmu_dev_get_write_cache_enabled(struct tcmu_device *dev);
void tcmu_dev_set_solid_state_media(struct tcmu_device *dev, bool solid_state);
bool tcmu_dev_get_solid_state_media(struct tcmu_device *dev);
void tcmu_dev_set_unmap_enabled(struct tcmu_device *dev, bool enabled);
bool tcmu_dev_get_unmap_enabled(struct tcmu_device *dev);
struct tcmulib_handler *tcmu_dev_get_handler(struct tcmu_device *dev);
void tcmu_dev_flush_ring(struct tcmu_device *dev);

Expand Down
1 change: 1 addition & 0 deletions libtcmu_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct tcmu_device {
uint32_t unmap_gran_align;
unsigned int write_cache_enabled:1;
unsigned int solid_state_media:1;
unsigned int unmap_enabled:1;

char dev_name[16]; /* e.g. "uio14" */
char tcm_hba_name[16]; /* e.g. "user_8" */
Expand Down
10 changes: 10 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ static struct tcmu_config *tcmu_cfg;

darray(struct tcmur_handler *) g_runner_handlers = darray_new();

struct tcmur_handler *tcmu_get_runner_handler(struct tcmu_device *dev)
{
struct tcmulib_handler *handler = tcmu_dev_get_handler(dev);

return handler->hm_private;
}

int tcmur_register_handler(struct tcmur_handler *handler)
{
struct tcmur_handler *h;
Expand Down Expand Up @@ -776,6 +783,9 @@ static int dev_added(struct tcmu_device *dev)
*/
tcmu_dev_set_opt_xcopy_rw_len(dev, max_sectors);

if (rhandler->unmap)
tcmu_dev_set_unmap_enabled(dev, true);

tcmu_dev_dbg(dev, "Got block_size %d, size in bytes %"PRId64"\n",
block_size, dev_size);

Expand Down
13 changes: 2 additions & 11 deletions scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,13 @@ bool char_to_hex(unsigned char *val, char c)
return false;
}

struct tcmur_handler *tcmu_get_runner_handler(struct tcmu_device *dev)
{
struct tcmulib_handler *handler = tcmu_dev_get_handler(dev);

return handler->hm_private;
}

int tcmu_emulate_evpd_inquiry(
struct tcmu_device *dev,
struct tgt_port *port,
uint8_t *cdb,
struct iovec *iovec,
size_t iov_cnt)
{
struct tcmur_handler *rhandler = tcmu_get_runner_handler(dev);

switch (cdb[2]) {
case 0x0: /* Supported VPD pages */
{
Expand Down Expand Up @@ -370,7 +361,7 @@ int tcmu_emulate_evpd_inquiry(
/* Optimal xfer length */
memcpy(&data[12], &val32, 4);

if (rhandler->unmap) {
if (tcmu_dev_get_unmap_enabled(dev)) {
/* MAXIMUM UNMAP LBA COUNT */
val32 = htobe32(VPD_MAX_UNMAP_LBA_COUNT);
memcpy(&data[20], &val32, 4);
Expand Down Expand Up @@ -467,7 +458,7 @@ int tcmu_emulate_evpd_inquiry(
* This will enable the UNMAP command for the device server and write
* same(10|16) command.
*/
if (rhandler->unmap)
if (tcmu_dev_get_unmap_enabled(dev))
data[5] |= 0xe0;

tcmu_memcpy_into_iovec(iovec, iov_cnt, data, sizeof(data));
Expand Down
22 changes: 22 additions & 0 deletions tcmu_runner_priv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2018 Red Hat, Inc.
*
* This file is licensed to you under your choice of the GNU Lesser
* General Public License, version 2.1 or any later version (LGPLv2.1 or
* later), or the Apache License 2.0.
*/

/*
* This header defines structures private to tcmu-runner, and should not
* be used by anyone else.
*/

#ifndef __TCMU_RUNNER_PRIV_H
#define __TCMU_RUNNER_PRIV_H

struct tcmu_device;
struct tcmur_handler;

struct tcmur_handler *tcmu_get_runner_handler(struct tcmu_device *dev);

#endif
1 change: 1 addition & 0 deletions tcmur_aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "libtcmu_priv.h"
#include "tcmur_device.h"
#include "tcmur_aio.h"
#include "tcmu_runner_priv.h"
#include "tcmu-runner.h"

struct tcmu_work {
Expand Down
1 change: 1 addition & 0 deletions tcmur_cmd_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "tcmur_aio.h"
#include "tcmur_device.h"
#include "tcmu-runner.h"
#include "tcmu_runner_priv.h"
#include "tcmur_cmd_handler.h"
#include "alua.h"

Expand Down
1 change: 1 addition & 0 deletions tcmur_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "tcmu-runner.h"
#include "tcmur_device.h"
#include "tcmur_cmd_handler.h"
#include "tcmu_runner_priv.h"
#include "target.h"

bool tcmu_dev_in_recovery(struct tcmu_device *dev)
Expand Down

0 comments on commit 5bf04d0

Please sign in to comment.