linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: bugzilla-daemon@kernel.org
To: linux-scsi@vger.kernel.org
Subject: [Bug 151631] "Synchronizing SCSI cache" fails during(and delays) reboot/shutdown
Date: Mon, 22 Jan 2024 08:40:40 +0000	[thread overview]
Message-ID: <bug-151631-11613-nIYdLOok7r@https.bugzilla.kernel.org/> (raw)
In-Reply-To: <bug-151631-11613@https.bugzilla.kernel.org/>

https://bugzilla.kernel.org/show_bug.cgi?id=151631

--- Comment #12 from Jesse Stone (fatalfeel@hotmail.com) ---
//if under linux 4.12 (include 4.12) add this patch
void __scsi_remove_device(struct scsi_device *sdev)
{
    struct device *dev = &sdev->sdev_gendev;
    int res;
    int ret;

    /*
     * This cleanup path is not reentrant and while it is impossible
     * to get a new reference with scsi_device_get() someone can still
     * hold a previously acquired one.
     */
    if (sdev->sdev_state == SDEV_DEL)
        return;

    if (sdev->is_visible) {
        /*
         * If scsi_internal_target_block() is running concurrently,
         * wait until it has finished before changing the device state.
         */
        mutex_lock(&sdev->state_mutex);
        /*
         * If blocked, we go straight to DEL and restart the queue so
         * any commands issued during driver shutdown (like sync
         * cache) are errored immediately.
         */
        res = scsi_device_set_state(sdev, SDEV_CANCEL);
        //if (res != 0) {
        ret = scsi_device_set_state(sdev, SDEV_DEL);
        if ( !ret )
        {
            scsi_start_queue(sdev);
        }
        //}
        mutex_unlock(&sdev->state_mutex);

        if (res != 0)
            return;

        bsg_unregister_queue(sdev->request_queue);
        device_unregister(&sdev->sdev_dev);
        transport_remove_device(dev);
        scsi_dh_remove_device(sdev);
        device_del(dev);
    } else {
        put_device(&sdev->sdev_dev);
    }

    /*
     * Stop accepting new requests and wait until all queuecommand() and
     * scsi_run_queue() invocations have finished before tearing down the
     * device.
     */
    mutex_lock(&sdev->state_mutex);
    scsi_device_set_state(sdev, SDEV_DEL);
    mutex_unlock(&sdev->state_mutex);

    blk_cleanup_queue(sdev->request_queue);
    cancel_work_sync(&sdev->requeue_work);

    if (sdev->host->hostt->slave_destroy)
    {
        sdev->host->hostt->slave_destroy(sdev);
    }

    transport_destroy_device(dev);

    /*
     * Paired with the kref_get() in scsi_sysfs_initialize().  We have
     * remoed sysfs visibility from the device, so make the target
     * invisible if this was the last device underneath it.
     */
    scsi_target_reap(scsi_target(sdev));

    put_device(dev);
}

//if above linux 4.13 (include 4.13)
void __scsi_remove_device(struct scsi_device *sdev)
{
        struct device *dev = &sdev->sdev_gendev;
        int res;
#ifdef MY_PATCH 
        int ret;
#endif  

        /*
         * This cleanup path is not reentrant and while it is impossible
         * to get a new reference with scsi_device_get() someone can still
         * hold a previously acquired one.
         */
        if (sdev->sdev_state == SDEV_DEL)
                return;

        if (sdev->is_visible) {
                /*
                 * If scsi_internal_target_block() is running concurrently,
                 * wait until it has finished before changing the device state.
                 */
                mutex_lock(&sdev->state_mutex);
                /*
                 * If blocked, we go straight to DEL and restart the queue so
                 * any commands issued during driver shutdown (like sync
                 * cache) are errored immediately.
                 */
                res = scsi_device_set_state(sdev, SDEV_CANCEL);
#ifdef MY_PATCH
                ret = scsi_device_set_state(sdev, SDEV_DEL);
                if ( !ret )
                        scsi_start_queue(sdev);
#else
                if (res != 0) {
                        res = scsi_device_set_state(sdev, SDEV_DEL);
                        if (res == 0)
                                scsi_start_queue(sdev);
                }
#endif          
                mutex_unlock(&sdev->state_mutex);

                if (res != 0)
                        return;

                if (sdev->host->hostt->sdev_groups)
                        sysfs_remove_groups(&sdev->sdev_gendev.kobj,
                                        sdev->host->hostt->sdev_groups);

                bsg_unregister_queue(sdev->request_queue);
                device_unregister(&sdev->sdev_dev);
                transport_remove_device(dev);
                device_del(dev);
        } else
                put_device(&sdev->sdev_dev);

        /*
         * Stop accepting new requests and wait until all queuecommand() and
         * scsi_run_queue() invocations have finished before tearing down the
         * device.
         */
        mutex_lock(&sdev->state_mutex);
        scsi_device_set_state(sdev, SDEV_DEL);
        mutex_unlock(&sdev->state_mutex);

        blk_cleanup_queue(sdev->request_queue);
        cancel_work_sync(&sdev->requeue_work);

        if (sdev->host->hostt->slave_destroy)
                sdev->host->hostt->slave_destroy(sdev);
        transport_destroy_device(dev);

        /*
         * Paired with the kref_get() in scsi_sysfs_initialize().  We have
         * removed sysfs visibility from the device, so make the target
         * invisible if this was the last device underneath it.
         */
        scsi_target_reap(scsi_target(sdev));

        put_device(dev);
}

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are the assignee for the bug.

      parent reply	other threads:[~2024-01-22  8:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-06 17:17 [Bug 151631] New: "Synchronizing SCSI cache" fails during(and delays) reboot/shutdown bugzilla-daemon
2016-08-06 19:20 ` [Bug 151631] " bugzilla-daemon
2016-08-06 19:57 ` bugzilla-daemon
2016-08-07  0:29 ` bugzilla-daemon
2016-08-07 15:06 ` bugzilla-daemon
2016-08-07 15:06 ` bugzilla-daemon
2016-11-08  8:11 ` bugzilla-daemon
2016-11-10  6:54 ` bugzilla-daemon
2016-12-04 20:22 ` bugzilla-daemon
2016-12-04 20:26 ` bugzilla-daemon
2017-01-17 20:29 ` bugzilla-daemon
2017-01-17 20:56 ` bugzilla-daemon
2024-01-04 11:45 ` bugzilla-daemon
2024-01-22  8:40 ` bugzilla-daemon [this message]

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=bug-151631-11613-nIYdLOok7r@https.bugzilla.kernel.org/ \
    --to=bugzilla-daemon@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).