From: "Derrick, Jonathan" <jonathan.derrick@intel.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"zub@linux.fjfi.cvut.cz" <zub@linux.fjfi.cvut.cz>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"sbauer@plzdonthack.me" <sbauer@plzdonthack.me>,
"axboe@kernel.dk" <axboe@kernel.dk>
Cc: "jonas.rabenstein@studium.uni-erlangen.de"
<jonas.rabenstein@studium.uni-erlangen.de>
Subject: Re: [PATCH 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array
Date: Thu, 28 Mar 2019 15:44:57 +0000 [thread overview]
Message-ID: <4419d15d7931a5c52315305fd95f3a740efd1273.camel@intel.com> (raw)
In-Reply-To: <1550103368-4605-16-git-send-email-zub@linux.fjfi.cvut.cz>
[-- Attachment #1: Type: text/plain, Size: 8898 bytes --]
Acked-by: Jon Derrick <jonathan.derrick@intel.com>
On Thu, 2019-02-14 at 01:16 +0100, David Kozub wrote:
> Originally each of the opal functions that call next include
> opal_discovery0 in the array of steps. This is superfluous and
> can be done always inside next.
>
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> ---
> block/sed-opal.c | 75 +++++++++++++++++++++++++++-------------------
> --
> 1 file changed, 42 insertions(+), 33 deletions(-)
>
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index f027c0cb682e..b947efd6d4d9 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -216,6 +216,7 @@ static const u8 opalmethod[][OPAL_METHOD_LENGTH]
> = {
> };
>
> static int end_opal_session_error(struct opal_dev *dev);
> +static int opal_discovery0_step(struct opal_dev *dev);
>
> struct opal_suspend_data {
> struct opal_lock_unlock unlk;
> @@ -381,17 +382,33 @@ static void check_geometry(struct opal_dev
> *dev, const void *data)
> dev->lowest_lba = geo->lowest_aligned_lba;
> }
>
> +static int execute_step(struct opal_dev *dev,
> + const struct opal_step *step, size_t stepIndex)
> +{
> + int error = step->fn(dev, step->data);
> +
> + if (error) {
> + pr_debug("Step %zu (%pS) failed with error %d: %s\n",
> + stepIndex, step->fn, error,
> + opal_error_to_human(error));
> + }
> +
> + return error;
> +}
> +
> static int next(struct opal_dev *dev, const struct opal_step *steps,
> size_t n_steps)
> {
> - const struct opal_step *step;
> - size_t state;
> - int error = 0;
> + size_t state = 0;
> + int error;
>
> - for (state = 0; state < n_steps; state++) {
> - step = &steps[state];
> + /* first do a discovery0 */
> + error = opal_discovery0_step(dev);
> + if (error)
> + return error;
>
> - error = step->fn(dev, step->data);
> + for (state = 0; state < n_steps; state++) {
> + error = execute_step(dev, &steps[state], state);
> if (error)
> goto out_error;
> }
> @@ -400,14 +417,14 @@ static int next(struct opal_dev *dev, const
> struct opal_step *steps,
>
> out_error:
> /*
> - * For each OPAL command the first step in steps does a
> discovery0
> - * and the second step starts some sort of session. If an error
> occurred
> - * in the first two steps (and thus stopping the loop with
> state <= 1)
> - * then there was an error before or during the attempt to
> start a
> - * session. Therefore we shouldn't attempt to terminate a
> session, as
> - * one has not yet been created.
> + * For each OPAL command the first step in steps starts some
> sort of
> + * session. If an error occurred in the initial discovery0 or
> if an
> + * error occurred in the first step (and thus stopping the loop
> with
> + * state == 0) then there was an error before or during the
> attempt to
> + * start a session. Therefore we shouldn't attempt to terminate
> a
> + * session, as one has not yet been created.
> */
> - if (state > 1)
> + if (state > 0)
> end_opal_session_error(dev);
>
> return error;
> @@ -506,6 +523,14 @@ static int opal_discovery0(struct opal_dev *dev,
> void *data)
> return opal_discovery0_end(dev);
> }
>
> +static int opal_discovery0_step(struct opal_dev *dev)
> +{
> + const struct opal_step discovery0_step = {
> + opal_discovery0,
> + };
> + return execute_step(dev, &discovery0_step, 0);
> +}
> +
> static bool can_add(int *err, struct opal_dev *cmd, size_t len)
> {
> if (*err)
> @@ -1831,10 +1856,10 @@ static int end_opal_session(struct opal_dev
> *dev, void *data)
>
> static int end_opal_session_error(struct opal_dev *dev)
> {
> - const struct opal_step error_end_session[] = {
> - { end_opal_session, }
> + const struct opal_step error_end_session = {
> + end_opal_session,
> };
> - return next(dev, error_end_session,
> ARRAY_SIZE(error_end_session));
> + return execute_step(dev, &error_end_session, 0);
> }
>
> static inline void setup_opal_dev(struct opal_dev *dev)
> @@ -1846,14 +1871,11 @@ static inline void setup_opal_dev(struct
> opal_dev *dev)
>
> static int check_opal_support(struct opal_dev *dev)
> {
> - const struct opal_step steps[] = {
> - { opal_discovery0, }
> - };
> int ret;
>
> mutex_lock(&dev->dev_lock);
> setup_opal_dev(dev);
> - ret = next(dev, steps, ARRAY_SIZE(steps));
> + ret = opal_discovery0_step(dev);
> dev->supported = !ret;
> mutex_unlock(&dev->dev_lock);
> return ret;
> @@ -1906,7 +1928,6 @@ static int
> opal_secure_erase_locking_range(struct opal_dev *dev,
> struct opal_session_info
> *opal_session)
> {
> const struct opal_step erase_steps[] = {
> - { opal_discovery0, },
> { start_auth_opal_session, opal_session },
> { get_active_key, &opal_session->opal_key.lr },
> { gen_key, },
> @@ -1925,7 +1946,6 @@ static int opal_erase_locking_range(struct
> opal_dev *dev,
> struct opal_session_info
> *opal_session)
> {
> const struct opal_step erase_steps[] = {
> - { opal_discovery0, },
> { start_auth_opal_session, opal_session },
> { erase_locking_range, opal_session },
> { end_opal_session, }
> @@ -1946,7 +1966,6 @@ static int
> opal_enable_disable_shadow_mbr(struct opal_dev *dev,
> OPAL_TRUE : OPAL_FALSE;
>
> const struct opal_step mbr_steps[] = {
> - { opal_discovery0, },
> { start_admin1LSP_opal_session, &opal_mbr->key },
> { set_mbr_done, &enable_disable },
> { end_opal_session, },
> @@ -1989,7 +2008,6 @@ static int opal_add_user_to_lr(struct opal_dev
> *dev,
> struct opal_lock_unlock *lk_unlk)
> {
> const struct opal_step steps[] = {
> - { opal_discovery0, },
> { start_admin1LSP_opal_session, &lk_unlk-
> >session.opal_key },
> { add_user_to_lr, lk_unlk },
> { end_opal_session, }
> @@ -2023,7 +2041,6 @@ static int opal_add_user_to_lr(struct opal_dev
> *dev,
> static int opal_reverttper(struct opal_dev *dev, struct opal_key
> *opal)
> {
> const struct opal_step revert_steps[] = {
> - { opal_discovery0, },
> { start_SIDASP_opal_session, opal },
> { revert_tper, } /* controller will terminate session
> */
> };
> @@ -2048,13 +2065,11 @@ static int __opal_lock_unlock(struct opal_dev
> *dev,
> struct opal_lock_unlock *lk_unlk)
> {
> const struct opal_step unlock_steps[] = {
> - { opal_discovery0, },
> { start_auth_opal_session, &lk_unlk->session },
> { lock_unlock_locking_range, lk_unlk },
> { end_opal_session, }
> };
> const struct opal_step unlock_sum_steps[] = {
> - { opal_discovery0, },
> { start_auth_opal_session, &lk_unlk->session },
> { lock_unlock_locking_range_sum, lk_unlk },
> { end_opal_session, }
> @@ -2071,7 +2086,6 @@ static int __opal_set_mbr_done(struct opal_dev
> *dev, struct opal_key *key)
> {
> u8 mbr_done_tf = OPAL_TRUE;
> const struct opal_step mbrdone_step[] = {
> - { opal_discovery0, },
> { start_admin1LSP_opal_session, key },
> { set_mbr_done, &mbr_done_tf },
> { end_opal_session, }
> @@ -2098,7 +2112,6 @@ static int opal_lock_unlock(struct opal_dev
> *dev,
> static int opal_take_ownership(struct opal_dev *dev, struct opal_key
> *opal)
> {
> const struct opal_step owner_steps[] = {
> - { opal_discovery0, },
> { start_anybodyASP_opal_session, },
> { get_msid_cpin_pin, },
> { end_opal_session, },
> @@ -2122,7 +2135,6 @@ static int opal_activate_lsp(struct opal_dev
> *dev,
> struct opal_lr_act *opal_lr_act)
> {
> const struct opal_step active_steps[] = {
> - { opal_discovery0, },
> { start_SIDASP_opal_session, &opal_lr_act->key },
> { get_lsp_lifecycle, },
> { activate_lsp, opal_lr_act },
> @@ -2144,7 +2156,6 @@ static int opal_setup_locking_range(struct
> opal_dev *dev,
> struct opal_user_lr_setup
> *opal_lrs)
> {
> const struct opal_step lr_steps[] = {
> - { opal_discovery0, },
> { start_auth_opal_session, &opal_lrs->session },
> { setup_locking_range, opal_lrs },
> { end_opal_session, }
> @@ -2161,7 +2172,6 @@ static int opal_setup_locking_range(struct
> opal_dev *dev,
> static int opal_set_new_pw(struct opal_dev *dev, struct opal_new_pw
> *opal_pw)
> {
> const struct opal_step pw_steps[] = {
> - { opal_discovery0, },
> { start_auth_opal_session, &opal_pw->session },
> { set_new_pw, &opal_pw->new_user_pw },
> { end_opal_session, }
> @@ -2185,7 +2195,6 @@ static int opal_activate_user(struct opal_dev
> *dev,
> struct opal_session_info *opal_session)
> {
> const struct opal_step act_steps[] = {
> - { opal_discovery0, },
> { start_admin1LSP_opal_session, &opal_session->opal_key
> },
> { internal_activate_user, opal_session },
> { end_opal_session, }
> --
> 2.20.1
>
[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]
next prev parent reply other threads:[~2019-03-28 15:45 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-14 0:15 [PATCH 00/16] sed-opal: fix shadow MBR enable/disable and clean up code David Kozub
2019-02-14 0:15 ` [PATCH 01/16] block: sed-opal: fix IOC_OPAL_ENABLE_DISABLE_MBR David Kozub
2019-03-28 17:04 ` Christoph Hellwig
2019-04-06 15:15 ` Scott Bauer
2019-02-14 0:15 ` [PATCH 02/16] block: sed-opal: fix typos and formatting David Kozub
2019-03-28 17:05 ` Christoph Hellwig
2019-02-14 0:15 ` [PATCH 03/16] block: sed-opal: use correct macro for method length David Kozub
2019-02-14 0:15 ` [PATCH 04/16] block: sed-opal: unify space check in add_token_* David Kozub
2019-03-28 15:43 ` Derrick, Jonathan
2019-03-28 17:05 ` Christoph Hellwig
2019-04-06 15:18 ` Scott Bauer
2019-04-06 15:19 ` Scott Bauer
2019-02-14 0:15 ` [PATCH 05/16] block: sed-opal: close parameter list in cmd_finalize David Kozub
2019-02-14 0:15 ` [PATCH 06/16] block: sed-opal: unify cmd start David Kozub
2019-02-14 0:15 ` [PATCH 07/16] block: sed-opal: unify error handling of responses David Kozub
2019-02-14 0:16 ` [PATCH 08/16] block: sed-opal: reuse response_get_token to decrease code duplication David Kozub
2019-02-14 0:16 ` [PATCH 09/16] block: sed-opal: print failed function address David Kozub
2019-02-14 0:16 ` [PATCH 10/16] block: sed-opal: split generation of bytestring header and content David Kozub
2019-02-14 0:16 ` [PATCH 11/16] block: sed-opal: add token for OPAL_LIFECYCLE David Kozub
2019-03-28 15:43 ` Derrick, Jonathan
2019-03-28 17:06 ` Christoph Hellwig
2019-04-06 15:19 ` Scott Bauer
2019-02-14 0:16 ` [PATCH 12/16] block: sed-opal: unify retrieval of table columns David Kozub
2019-02-14 0:16 ` [PATCH 13/16] block: sed-opal: use named Opal tokens instead of integer literals David Kozub
2019-03-28 15:44 ` Derrick, Jonathan
2019-03-28 17:06 ` Christoph Hellwig
2019-04-06 15:20 ` Scott Bauer
2019-02-14 0:16 ` [PATCH 14/16] block: sed-opal: pass steps via argument rather than via opal_dev David Kozub
2019-03-28 15:44 ` Derrick, Jonathan
2019-03-28 17:07 ` Christoph Hellwig
2019-04-06 15:20 ` Scott Bauer
2019-02-14 0:16 ` [PATCH 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array David Kozub
2019-03-28 15:44 ` Derrick, Jonathan [this message]
2019-03-28 17:09 ` Christoph Hellwig
2019-04-06 15:22 ` Scott Bauer
2019-02-14 0:16 ` [PATCH 16/16] block: sed-opal: rename next to execute_steps David Kozub
2019-04-06 15:26 ` [PATCH 00/16] sed-opal: fix shadow MBR enable/disable and clean up code Scott Bauer
2019-04-06 17:09 ` Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2019-01-03 22:58 [PATCH 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array David Kozub
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4419d15d7931a5c52315305fd95f3a740efd1273.camel@intel.com \
--to=jonathan.derrick@intel.com \
--cc=axboe@kernel.dk \
--cc=jonas.rabenstein@studium.uni-erlangen.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sbauer@plzdonthack.me \
--cc=zub@linux.fjfi.cvut.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®