[gvfs/f19] Fix mtp crashes during unmount (#957162)
Ondrej Holy
oholy at fedoraproject.org
Fri Nov 29 13:35:04 UTC 2013
commit cf3708a5d2e806a949b8a7197208eef39731f841
Author: Ondrej Holy <oholy at redhat.com>
Date: Fri Nov 29 14:33:43 2013 +0100
Fix mtp crashes during unmount (#957162)
...-Fail-fast-if-in-the-middle-of-an-unmount.patch | 133 ++++++++++++++++++++
gvfs.spec | 10 ++-
2 files changed, 142 insertions(+), 1 deletions(-)
---
diff --git a/0001-MTP-Fail-fast-if-in-the-middle-of-an-unmount.patch b/0001-MTP-Fail-fast-if-in-the-middle-of-an-unmount.patch
new file mode 100644
index 0000000..666c6c9
--- /dev/null
+++ b/0001-MTP-Fail-fast-if-in-the-middle-of-an-unmount.patch
@@ -0,0 +1,133 @@
+From 62dd53b7854ce65e9121b2283a6aa9a01e5281b4 Mon Sep 17 00:00:00 2001
+From: Philip Langdale <philipl at overt.org>
+Date: Sun, 24 Nov 2013 09:12:37 -0800
+Subject: [PATCH] MTP: Fail fast if in the middle of an unmount
+
+I've seen a ton of bug reports where the backend crashes due to
+operations executing after an unmount begins. I think it's a
+sufficient solution to check the unmount flag that we already have
+and then immediately abort the operation.
+
+Generally, this is only seen with operations that are initiated
+implicitly like do_query_info or do_enumerate, but I've added the
+protection to all operations for consistency.
+---
+ daemon/gvfsbackendmtp.c | 32 ++++++++++++++++++++++++++++++++
+ 1 file changed, 32 insertions(+)
+
+diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c
+index b5e4b90..02059eb 100644
+--- a/daemon/gvfsbackendmtp.c
++++ b/daemon/gvfsbackendmtp.c
+@@ -105,6 +105,18 @@ DEBUG_ENUMERATE (const gchar *message, ...)
+ #define PTP_ST_RemovableRAM 0x0004
+
+
++#define FAIL_DURING_UNMOUNT() \
++ if (g_atomic_int_get (&G_VFS_BACKEND_MTP(backend)->unmount_started)) { \
++ DEBUG ("(I) aborting due to unmount"); \
++ g_vfs_job_failed_literal (G_VFS_JOB (job), \
++ G_IO_ERROR, G_IO_ERROR_CLOSED, \
++ _("The connection is closed")); \
++ goto exit; \
++ }
++
++
++
++
+ /************************************************
+ * Initialization
+ ************************************************/
+@@ -834,6 +846,8 @@ do_enumerate (GVfsBackend *backend,
+
+ g_mutex_lock (&G_VFS_BACKEND_MTP (backend)->mutex);
+
++ FAIL_DURING_UNMOUNT();
++
+ LIBMTP_mtpdevice_t *device;
+ device = op_backend->device;
+
+@@ -989,6 +1003,8 @@ do_query_info (GVfsBackend *backend,
+ DEBUG ("(I) do_query_info (filename = %s) ", filename);
+ g_mutex_lock (&G_VFS_BACKEND_MTP (backend)->mutex);
+
++ FAIL_DURING_UNMOUNT();
++
+ gchar **elements = g_strsplit_set (filename, "/", -1);
+ unsigned int ne = g_strv_length (elements);
+
+@@ -1065,6 +1081,8 @@ do_query_fs_info (GVfsBackend *backend,
+ gchar **elements = g_strsplit_set (filename, "/", -1);
+ unsigned int ne = g_strv_length (elements);
+
++ FAIL_DURING_UNMOUNT();
++
+ LIBMTP_mtpdevice_t *device;
+ device = G_VFS_BACKEND_MTP (backend)->device;
+
+@@ -1132,6 +1150,8 @@ do_make_directory (GVfsBackend *backend,
+ gchar **elements = g_strsplit_set (filename, "/", -1);
+ unsigned int ne = g_strv_length (elements);
+
++ FAIL_DURING_UNMOUNT();
++
+ if (ne < 3) {
+ g_vfs_job_failed_literal (G_VFS_JOB (job),
+ G_IO_ERROR, G_IO_ERROR_FAILED,
+@@ -1188,6 +1208,8 @@ do_pull (GVfsBackend *backend,
+ gchar **elements = g_strsplit_set (source, "/", -1);
+ unsigned int ne = g_strv_length (elements);
+
++ FAIL_DURING_UNMOUNT();
++
+ if (ne < 3) {
+ g_vfs_job_failed_literal (G_VFS_JOB (job),
+ G_IO_ERROR, G_IO_ERROR_NOT_REGULAR_FILE,
+@@ -1263,6 +1285,8 @@ do_push (GVfsBackend *backend,
+ gchar **elements = g_strsplit_set (destination, "/", -1);
+ unsigned int ne = g_strv_length (elements);
+
++ FAIL_DURING_UNMOUNT();
++
+ if (ne < 3) {
+ g_vfs_job_failed_literal (G_VFS_JOB (job),
+ G_IO_ERROR, G_IO_ERROR_NOT_REGULAR_FILE,
+@@ -1361,6 +1385,8 @@ do_delete (GVfsBackend *backend,
+ gchar **elements = g_strsplit_set (filename, "/", -1);
+ unsigned int ne = g_strv_length (elements);
+
++ FAIL_DURING_UNMOUNT();
++
+ if (ne < 3) {
+ g_vfs_job_failed_literal (G_VFS_JOB (job),
+ G_IO_ERROR, G_IO_ERROR_FAILED,
+@@ -1399,6 +1425,8 @@ do_set_display_name (GVfsBackend *backend,
+ DEBUG ("(I) do_set_display_name '%s' --> '%s' ", filename, display_name);
+ g_mutex_lock (&G_VFS_BACKEND_MTP (backend)->mutex);
+
++ FAIL_DURING_UNMOUNT();
++
+ gchar **elements = g_strsplit_set (filename, "/", -1);
+ unsigned int ne = g_strv_length (elements);
+
+@@ -1444,6 +1472,8 @@ do_open_icon_for_read (GVfsBackend *backend,
+ DEBUG ("(I) do_open_icon_for_read (%s)", icon_id);
+ g_mutex_lock (&G_VFS_BACKEND_MTP (backend)->mutex);
+
++ FAIL_DURING_UNMOUNT();
++
+ guint id = strtol (icon_id, NULL, 10);
+
+ if (id > 0) {
+@@ -1487,6 +1517,8 @@ do_open_icon_for_read (GVfsBackend *backend,
+ _("Malformed icon identifier '%s'"),
+ icon_id);
+ }
++
++ exit:
+ g_mutex_unlock (&G_VFS_BACKEND_MTP (backend)->mutex);
+
+ DEBUG ("(I) do_open_icon_for_read done.");
+--
+1.8.4.2
+
diff --git a/gvfs.spec b/gvfs.spec
index 0a1bb14..026fa02 100644
--- a/gvfs.spec
+++ b/gvfs.spec
@@ -1,7 +1,7 @@
Summary: Backends for the gio framework in GLib
Name: gvfs
Version: 1.16.4
-Release: 1%{?dist}
+Release: 2%{?dist}
License: GPLv3 and LGPLv2+
Group: System Environment/Libraries
URL: http://www.gtk.org
@@ -39,6 +39,10 @@ BuildRequires: libtool
# http://bugzilla.gnome.org/show_bug.cgi?id=567235
Patch0: gvfs-archive-integration.patch
+# Upstream patch to fix mtp crashes during unmount
+# https://bugzilla.gnome.org/show_bug.cgi?id=715119
+Patch1: 0001-MTP-Fail-fast-if-in-the-middle-of-an-unmount.patch
+
Obsoletes: gnome-mount <= 0.8
Obsoletes: gnome-mount-nautilus-properties <= 0.8
@@ -174,6 +178,7 @@ file services.
%prep
%setup -q
%patch0 -p1 -b .archive-integration
+%patch1 -p1 -b .fix-mtp-crashes
%build
# Needed for gvfs-0.2.1-archive-integration.patch
@@ -375,6 +380,9 @@ update-desktop-database >&/dev/null || :
%{_datadir}/gvfs/remote-volume-monitors/goa.monitor
%changelog
+* Fri Nov 29 2013 Ondrej Holy <oholy at redhat.com> - 1.18.4-2
+- Fix mtp crashes during unmount (#957162)
+
* Fri Nov 29 2013 Ondrej Holy <oholy at redhat.com> - 1.18.4-1
- Update to 1.16.4
More information about the scm-commits
mailing list