public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chester Lin <clin@suse.com>
To: rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org
Cc: jlee@suse.com, mhocko@suse.com, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org, Chester Lin <clin@suse.com>
Subject: [PATCH 3/3] ACPI / device_sysfs: Add eject show attr to monitor eject status
Date: Fri, 31 May 2019 14:56:42 +0800	[thread overview]
Message-ID: <20190531065642.13254-4-clin@suse.com> (raw)
In-Reply-To: <20190531065642.13254-1-clin@suse.com>

An acpi_eject_show attribute for users to monitor current status because
sometimes it might take time to finish an ejection so we need to know
whether it is still in progress or not.

Signed-off-by: Chester Lin <clin@suse.com>
---
 drivers/acpi/device_sysfs.c | 20 +++++++++++++++++++-
 drivers/acpi/internal.h     |  1 +
 drivers/acpi/scan.c         | 27 +++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c
index 78c2653bf020..70b22eec6bbc 100644
--- a/drivers/acpi/device_sysfs.c
+++ b/drivers/acpi/device_sysfs.c
@@ -403,7 +403,25 @@ acpi_eject_store(struct device *d, struct device_attribute *attr,
 	return status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN;
 }
 
-static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
+static ssize_t acpi_eject_show(struct device *d,
+				struct device_attribute *attr, char *buf)
+{
+	struct acpi_device *acpi_device = to_acpi_device(d);
+	acpi_object_type not_used;
+	acpi_status status;
+
+	if ((!acpi_device->handler || !acpi_device->handler->hotplug.enabled)
+	    && !acpi_device->driver)
+		return -ENODEV;
+
+	status = acpi_get_type(acpi_device->handle, &not_used);
+	if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable)
+		return -ENODEV;
+
+	return sprintf(buf, "%s\n", acpi_eject_status_string(acpi_device));
+}
+
+static DEVICE_ATTR(eject, 0644, acpi_eject_show, acpi_eject_store);
 
 static ssize_t
 acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf)
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 0dcec4243b23..e7037d68c3d9 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -293,5 +293,6 @@ struct eject_data {
 };
 
 void acpi_eject_retry(struct acpi_device *adev);
+char *acpi_eject_status_string(struct acpi_device *adev);
 
 #endif /* _ACPI_INTERNAL_H_ */
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index c60110db1cd6..27c4c1148879 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -370,6 +370,33 @@ static int acpi_scan_offline_check(struct acpi_device *device)
 	return ret;
 }
 
+char *acpi_eject_status_string(struct acpi_device *adev)
+{
+	struct eject_data *eject_obj;
+	char *status_string = "none";
+
+	mutex_lock(&acpi_scan_lock);
+	eject_obj = (struct eject_data *) adev->eject_stat;
+
+	if (eject_obj) {
+		switch (eject_obj->status) {
+		case ACPI_EJECT_STATUS_NONE:
+			break;
+		case ACPI_EJECT_STATUS_GOING_OFFLINE:
+			status_string = "going offline";
+			break;
+		case ACPI_EJECT_STATUS_FAIL:
+			status_string = "failure";
+			break;
+		default:
+			status_string = "(unknown)";
+		}
+	}
+
+	mutex_unlock(&acpi_scan_lock);
+	return status_string;
+}
+
 static int acpi_scan_hot_remove(struct acpi_device *device)
 {
 	acpi_handle handle = device->handle;
-- 
2.20.1


  parent reply	other threads:[~2019-05-31  6:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31  6:56 [PATCH 0/3] ACPI: New eject flow to remove devices cautiously Chester Lin
2019-05-31  6:56 ` [PATCH 1/3] ACPI / hotplug: Send change events for offline/online requests when eject is triggered Chester Lin
2019-05-31  6:56 ` [PATCH 2/3] ACPI / hotplug: Eject status trace and auto-remove approach Chester Lin
2019-05-31  6:56 ` Chester Lin [this message]
2019-05-31 13:38   ` [PATCH 3/3] ACPI / device_sysfs: Add eject show attr to monitor eject status Greg KH
2019-06-03  2:48     ` Chester Lin

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=20190531065642.13254-4-clin@suse.com \
    --to=clin@suse.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jlee@suse.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.com \
    --cc=rjw@rjwysocki.net \
    /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