Commit 494b1ba8 authored by Rafal Stefanowski's avatar Rafal Stefanowski Committed by Tomasz Zawadzki
Browse files

ocf/rpc: Add RPC method to manage sequential cutoff



Introduce bdev_ocf_set_seqcutoff RPC method for
changing OCF sequential cutoff policy and parameters.

Signed-off-by: default avatarRafal Stefanowski <rafal.stefanowski@intel.com>
Change-Id: I509644115402c00c4a026c1c37e887c8fc90289f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8459


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent dd574327
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -2572,6 +2572,48 @@ Example response:
}
~~~

### bdev_ocf_set_seqcutoff {#rpc_bdev_ocf_set_seqcutoff}

Set sequential cutoff parameters on all cores for the given OCF cache device.
A brief description of this functionality can be found in [OpenCAS documentation](https://open-cas.github.io/guide_tool_details.html#seq-cutoff).

#### Parameters

Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
name                    | Required | string      | Bdev name
policy                  | Required | string      | Sequential cutoff policy: always, full, never
threshold               | Optional | int         | Activation threshold in KiB
promotion_count         | Optional | int         | Promotion request count

#### Example

Example request:

~~~json
{
  "params": {
    "name": "ocf0",
    "policy": "full",
    "threshold": 4,
    "promotion_count": 2
  },
  "jsonrpc": "2.0",
  "method": "bdev_ocf_set_seqcutoff",
  "id": 1
}
~~~

Example response:

~~~json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
~~~

### bdev_malloc_create {#rpc_bdev_malloc_create}

Construct @ref bdev_config_malloc
+20 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
 */

#include "spdk/stdinc.h"
#include "spdk/log.h"

#include "utils.h"
#include "vbdev_ocf.h"
@@ -45,6 +46,12 @@ static char *cache_modes[ocf_cache_mode_max] = {
	[ocf_cache_mode_wo] = "wo",
};

static char *seqcutoff_policies[ocf_seq_cutoff_policy_max] = {
	[ocf_seq_cutoff_policy_always] = "always",
	[ocf_seq_cutoff_policy_full] = "full",
	[ocf_seq_cutoff_policy_never] = "never",
};

ocf_cache_mode_t
ocf_get_cache_mode(const char *cache_mode)
{
@@ -75,6 +82,19 @@ ocf_get_cache_line_size(ocf_cache_t cache)
	return ocf_cache_get_line_size(cache) / KiB;
}

ocf_seq_cutoff_policy
ocf_get_seqcutoff_policy(const char *policy_name)
{
	int policy;

	for (policy = 0; policy < ocf_seq_cutoff_policy_max; policy++)
		if (!strcmp(policy_name, seqcutoff_policies[policy])) {
			return policy;
		}

	return ocf_seq_cutoff_policy_max;
}

int
vbdev_ocf_mngt_start(struct vbdev_ocf *vbdev, vbdev_ocf_mngt_fn *path,
		     vbdev_ocf_mngt_callback cb, void *cb_arg)
+3 −0
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@ const char *ocf_get_cache_modename(ocf_cache_mode_t mode);
/* Get cache line size in KiB units */
int ocf_get_cache_line_size(ocf_cache_t cache);

/* Get sequential cutoff policy by name */
ocf_seq_cutoff_policy ocf_get_seqcutoff_policy(const char *policy_name);

/* Initiate management operation
 * Receives NULL terminated array of functions (path)
 * and callback (cb)
+46 −0
Original line number Diff line number Diff line
@@ -1518,6 +1518,52 @@ vbdev_ocf_set_cache_mode(struct vbdev_ocf *vbdev,
	cb(rc, vbdev, cb_arg);
}

/* Set sequential cutoff parameters on OCF cache */
void
vbdev_ocf_set_seqcutoff(struct vbdev_ocf *vbdev, const char *policy_name, uint32_t threshold,
			uint32_t promotion_count, void (*cb)(int, void *), void *cb_arg)
{
	ocf_cache_t cache;
	ocf_seq_cutoff_policy policy;
	int rc;

	cache = vbdev->ocf_cache;

	policy = ocf_get_seqcutoff_policy(policy_name);
	if (policy == ocf_seq_cutoff_policy_max) {
		cb(OCF_ERR_INVAL, cb_arg);
		return;
	}

	rc = ocf_mngt_cache_trylock(cache);
	if (rc) {
		cb(rc, cb_arg);
		return;
	}

	rc = ocf_mngt_core_set_seq_cutoff_policy_all(cache, policy);
	if (rc) {
		goto end;
	}

	if (threshold) {
		threshold = threshold * KiB;

		rc = ocf_mngt_core_set_seq_cutoff_threshold_all(cache, threshold);
		if (rc) {
			goto end;
		}
	}

	if (promotion_count) {
		rc = ocf_mngt_core_set_seq_cutoff_promotion_count_all(cache, promotion_count);
	}

end:
	ocf_mngt_cache_unlock(cache);
	cb(rc, cb_arg);
}

/* This called if new device is created in SPDK application
 * If that device named as one of base bdevs of OCF vbdev,
 * claim and open them */
+9 −0
Original line number Diff line number Diff line
@@ -210,6 +210,15 @@ void vbdev_ocf_set_cache_mode(
	void (*cb)(int, struct vbdev_ocf *, void *),
	void *cb_arg);

/* Set sequential cutoff parameters on OCF cache */
void vbdev_ocf_set_seqcutoff(
	struct vbdev_ocf *vbdev,
	const char *policy_name,
	uint32_t threshold,
	uint32_t promotion_count,
	void (*cb)(int, void *),
	void *cb_arg);

typedef void (*vbdev_ocf_foreach_fn)(struct vbdev_ocf *, void *);

/* Execute fn for each OCF device that is online or waits for base devices */
Loading