After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 765924 - Improve external drives detection
Improve external drives detection
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
Federico Mena Quintero
Depends on: 765457 765900
Blocks:
 
 
Reported: 2016-05-03 07:14 UTC by Ondrej Holy
Modified: 2016-09-06 07:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtkplacessidebar: Improve external drives detection (1.57 KB, patch)
2016-05-03 07:14 UTC, Ondrej Holy
none Details | Review
Improve external drives detection (2.09 KB, patch)
2016-05-10 10:13 UTC, Ondrej Holy
committed Details | Review

Description Ondrej Holy 2016-05-03 07:14:28 UTC
Created attachment 327195 [details] [review]
gtkplacessidebar: Improve external drives detection

Use recenlty added g_drive_is_removable for external drives detection. Current heuristic fails in some cases (e.g. when removable drive is attached before login), see Bug 765457.
Comment 1 Matthias Clasen 2016-05-03 10:59:17 UTC
Review of attachment 327195 [details] [review]:

So, we have removable drives that can't be stopped, ejected, or have their media removed ? Isn't that going to be a problem for deciding what we can do with them ?
Comment 2 Emmanuele Bassi (:ebassi) 2016-05-03 12:48:35 UTC
udisks seems to be detecting them appropriately, and tagging them, but the tag is not relayed to the upper layers in the stack. The existing heuristics, on the other hand, fail to detect some of them — e.g. if I have a USB device attached to a hub and I make the mistake of booting my laptop up with the hub plugged in.
Comment 3 Ondrej Holy 2016-05-04 07:41:00 UTC
(In reply to Matthias Clasen from comment #1)
> Review of attachment 327195 [details] [review] [review]:
> 
> So, we have removable drives that can't be stopped, ejected, or have their
> media removed ?

You can see such drive using GIO if you connect external usb disk and then restart the computer with the disk connected. The problem is that g_drive_can_stop != udisks_drive_get_can_power_off, because of the following code from udisks2 volume monitor:

    if (!drive->is_media_removable && !drive->coldplug)
      {
        if (udisks_drive_get_can_power_off (drive->udisks_drive))
          {
            drive->can_stop = TRUE;
          }
      }

I am not really sure if external drive may have udisks_drive_get_can_power_off() == false and can't be ejected, or don't have removable media...

So maybe it may be enough to just remove !drive->coldplug from the condition above, but I am not really sure it is good idea, because of the following comment:

     * Note that this heuristic has the nice
     * side-effect that USB-attached hard disks that are plugged in
     * when the computer starts up will not be powered off when the
     * user clicks the "eject" icon.

That's why I proposed g_drive_is_removable...

> Isn't that going to be a problem for deciding what we can do
> with them ?

We can still mount/unmount their volumes/mounts... though I didn't test the gtkplacessidebar if it handle such drives properly...
Comment 4 Ondrej Holy 2016-05-04 08:29:19 UTC
(In reply to Ondrej Holy from comment #3)
> ...
> So maybe it may be enough to just remove !drive->coldplug from the condition

I meant use udisks_drive_get_removable instead of !drive->coldplug, though it seems that udisks do it internally already...
Comment 5 Ondrej Holy 2016-05-05 11:32:25 UTC
(In reply to Ondrej Holy from comment #3)
> (In reply to Matthias Clasen from comment #1)
> > Review of attachment 327195 [details] [review] [review] [review]:
> > 
> > So, we have removable drives that can't be stopped, ejected, or have their
> > media removed ?
> 
> You can see such drive using GIO if you connect external usb disk and then
> restart the computer with the disk connected. The problem is that
> g_drive_can_stop != udisks_drive_get_can_power_off, because of the following
> code from udisks2 volume monitor:
> 
>     if (!drive->is_media_removable && !drive->coldplug)
>       {
>         if (udisks_drive_get_can_power_off (drive->udisks_drive))
>           {
>             drive->can_stop = TRUE;
>           }
>       }
> 
> I am not really sure if external drive may have
> udisks_drive_get_can_power_off() == false and can't be ejected, or don't
> have removable media...

Hmm I discussed it again with Peter Hatina from storaged. He thinks that there are no such drives, where:
CanPowerOff==MediaRemovable==Ejectable==false && Removable==true

> So maybe it may be enough to just remove !drive->coldplug from the condition

He thinks that Removable is reliable for external devices detection and also doesn't see any reasons, why we should block can_stop for coldplug devices if Removable is true...

So do you agree with the gvfs modification for can_stop instead of changes for glib/gtk?
Comment 6 Matthias Clasen 2016-05-05 12:09:11 UTC
(In reply to Ondrej Holy from comment #3)

> So maybe it may be enough to just remove !drive->coldplug from the condition
> above, but I am not really sure it is good idea, because of the following
> comment:
> 
>      * Note that this heuristic has the nice
>      * side-effect that USB-attached hard disks that are plugged in
>      * when the computer starts up will not be powered off when the
>      * user clicks the "eject" icon.
> 

I think the reboot-with-disk attached scenario shows that this heuristic is flawed. But now that you've explained the situation, using the simpler check in GTK+ is probably an ok solution, if you make sure that the rest of the code can handle such drives.
Comment 7 Ondrej Holy 2016-05-10 10:13:22 UTC
Created attachment 327569 [details] [review]
Improve external drives detection

I realized that same change is necessary also for gtkplacesview.c.

It works correctly for me. Sidebar is in sync with "Other Locations" view. It is possible to mount/unmount such volumes. External hard drive is shown even after restart...
Comment 8 Matthias Clasen 2016-05-12 04:03:05 UTC
Review of attachment 327569 [details] [review]:

ok
Comment 9 Ondrej Holy 2016-05-12 08:45:24 UTC
(In reply to Matthias Clasen from comment #8)
> Review of attachment 327569 [details] [review] [review]:
> 
> ok

Maybe I confused you by the patch description, where I wrote about recently added g_drive_is_removable, however this function is not there yet and Bug 765900 and Bug 765900 needs to be solved first, can you please take a look at them also?
Comment 10 Ondrej Holy 2016-05-20 08:55:48 UTC
Comment on attachment 327569 [details] [review]
Improve external drives detection

commit 55751fc
Comment 11 Colin Walters 2016-05-23 14:44:50 UTC
Ah, so this was the cause of the periodic smoketest failures in Continuous.
Comment 12 Carlos Soriano 2016-09-06 07:55:49 UTC
*** Bug 770923 has been marked as a duplicate of this bug. ***