11 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
e3d0be2885
storage: Use privileged decorator for actions
Tests:

- SKIPPED: Functional tests work
- DONE: Initial setup works
  - DONE: Root partition is expanded when space is available
- DONE: When there is free space for root partition it shows up in the interface
- DONE: Expand partition from user interface works
- DONE: Getting storage usage information works
  - DONE: Disks and free space shown in app page
  - DONE: Showing share mounts in samba works
  - DONE: Backups add repository form shows disk choices
  - DONE: Samba shows proper list of mounted shares and unavailable shares
- DONE: Directory validator works
  - DONE: In deluge and transmission
- DONE: Auto-mounting a device works
- DONE: Ejecting a mounted disk from UI works
  - DONE: Error are graciously handled

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:53:50 -04:00
Veiko Aasa
41a3148d3a
storage: Fix enumerating partitions without mount points
Fixes an issue where accessing Storage and Samba app pages throws a
HTTP error 500 when there are disk partitions without mount points.

Fixes #1904 #2245

Tested when an USB stick with Debian installer image is attached to
Freedombox board - both Storage and Samba apps work.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
2022-08-13 15:59:57 -07:00
Sunil Mohan Adapa
d3b5143ed6
storage: Allow ejecting any device not in fstab or crypttab
Allow any disk including SATA disks to be ejected.

Helps: #1597.

Tests performed:

- Attach SATA disk to VirtualBox. Create two partitions and filesystem in it.
FreedomBox will auto-mount the filesystems. Eject button is shown on both the
partitions. Without the patch, this is not shown.

- Eject button is not shown against '/' as it is part of fstab.

- Add a device into /etc/fstab. Eject button will not be shown against the
device.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:37 -04:00
Sunil Mohan Adapa
426cef4c2c
storage: Don't auto-mount loopback devices except in develop mode
In the event containers are being used on the server with images, attempting to
auto-mounting loop devices could interfere with their operation. We currently
don't have a use case where a user would want to auto-mount loop devices.
Initially suggested in
https://salsa.debian.org/freedombox-team/freedombox/-/issues/1854

Tests performed:

- Add a loopback device as follows and observe that is automatically mounted.

  dd if=/dev/zero of=/tmp/test_disk bs=1M count=100
  mkfs.ext4 /tmp/test_disk
  losetup loop0 /tmp/test_disk
  umount /dev/loop0
  losetup -d /dev/loop0

- Add a loopback device as follows and observe that both partitions are mounted.

  dd if=/dev/zero of=/tmp/test_disk bs=1M count=100
  parted /tmp/test_disk
  mklabel gpt
  mkpart Part1 ext4 0% 50%
  mkpart Part2 ext4 50% 100%
  kpartx -avs /tmp/test_disk
  mkfs.ext4 /dev/mapper/loop0p1
  mkfs.ext4 /dev/mapper/loop0p2
  umount /dev/mapper/loop0p1
  umount /dev/mapper/loop0p2
  kpartx -dvs /tmp/test_disk

- When --develop is removed or when code is modified to negate the not
  condition, the partitions are not auto-mounted in the above cases.

Reported-by: James Valleroy <jvalleroy@mailbox.org>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:35 -04:00
Sunil Mohan Adapa
8c05fb0722
storage: Remove rule to not automount system disks with no paritions
This rule imported originally from udiskie's defaults seems somewhat arbitrary.
We attach a SATA drive with partitions, it mounts them. However, if the entire
drive is a file system, it does not auto-mount.

Tests performed:

- In VirtualBox, attach a SATA drive. Create two partitions and filesystems in
them. Both filesystems are auto-mounted.

- In VirtualBox, attach a SATA drive. Format the entire drive as a filesystem.
The filesystem is auto-mounted.

- Same behavior is observed with loop devices.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:33 -04:00
Sunil Mohan Adapa
10b46f1968
storage: Use UDisks information as primary source
Rename get_disks() to get_mounts() and use it in for backups and samba shares.

Create a new get_disks() similar to get_mounts() but use df information only for
showing free space. This inverts the importance of 'df' and UDisks. Use UDisks
as primary source of information for showing list of disks and then use df to
fill in the free space information.

- Retrieve all the mount points of a device and return them as part of
get_disks() in an extra 'mount_points' property.

- For storage listing, this fixes showing up of /.snapshots as separate disk and
showing of vboxsf, network mounts etc. Only shows mounts that are related to
block devices.

- Update various uses of get_disks() within storage module to use
'mounts_points' instead of 'mount_point' to be accurate in cases where there are
multiple mounts for a given device. Use get_mounts() where appropriate instead.

- Display all the mount points against a devices in multiple lines.

- Also show devices that are not currently mounted.

Tests performed:

- Filling up a disk shows a disk space warning properly. Warning contains the
  free disk space correctly.

- Calling get_root_device(get_disks()) return the correct root device.

- In Deluge, the download directory contains a list of all samba current shares.
  If a disk with samba share is unmouted, it does not show up in the list.

- In the Samba app page, all disks are shown properly. Root disk is shown as
  'disk'. All other mount points such as .snapshots and /vagrant also show up.

- In the Samba app page, unavailable shares list shows up when a disk with a
  share is unmounted.

- Upload a backup, warning on the form shows available disk space properly.

- When adding a backup location. The list includes all mount points. Duplicated
  mount points are not shown. Root disk is not shown in the list. When all the
  disks are used up for backup location, a warning that no additional disks are
  available is shown.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:29 -04:00
Sunil Mohan Adapa
225d86e344
storage: Use DBus directly for listing disks
Bring us closer to avoiding the use of two different methods to access UDisks
DBus API: UDisks2 client library and direct DBus access with GDBus.

Perform formatting of the bytes outside of udisks2 module to avoid depending on
Django.

Tests performed:

- Visit the storage page. Disks are listed properly.

- Sizes are formatted to be human readable.

- Filesystem type is show properly: ext4, btrfs

- Labels for disks are shown as set by tune2fs etc.

- Device paths are shown properly.

- Mount point is shown properly.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-24 07:23:24 -04:00
Sunil Mohan Adapa
e51d027618
storage: Auto-mount disks, notify of failing disks
- Remove freedombox-udiskie.service file. Don't run udiskie anymore. Use our own
implementation of auto-mounting.

- Schedule disk failure checking to 3 seconds after application initialization.
Also perform auto-mounting at that time.

- Listen to new filesystems added and auto-mount them.

- Listen to disk failing attribute and report to user via a notification.

- Add rules to polkit-1 to allow plinth user to mount drives.

- Add simple abstractions over DBusProxy objects make accessing properties
simpler.

- Replicate udiskie's approach to mounting disks.

- Mount as root user for now using command line instead of DBus API. This is to
keep compatibility with older code that mounted under /media/root with relaxed
permissions.

Udiskie analysis:

  - On device added, media added, perform auto_add
  - On device changed and is addable and old state is not addable or removeable
  - Automount condition:
    - Matches configuration
    - Not ignored
    - is_filesystem and not mounted -> mount
    - crypto device -> try unlock -> if success, mount
    - is partition table
      - Get all non-ignored devices, if partition then mount
  - Mount condition:
    - Is not ignored
    - Is filesystem
    - Find device with path
    - Get options from configuration
    - Is ntfs and executable ntfs-3g is not available
    - Call mount
  - No support for udisks1
  - Built-in rules
    - {'symlinks': '/dev/mapper/docker-*', 'ignore': True}
    - {'symlinks': '/dev/disk/by-id/dm-name-docker-*', 'ignore': True}
    - {'is_loop': True, 'is_ignored': False, 'loop_file': '/*', 'ignore': False}
    - {'is_block': False, 'ignore': True}
    - {'is_external': False, 'is_toplevel': True, 'ignore': True}
    - {'is_ignored': True, 'ignore': True}

Tests performed:
  - Create a CDROM in VM, inject media. Disk should get mounted.
  - Create a temp file. mkfs.ext4 it at top level. losetup it. It should not get
    auto mounted as it is a top level internal device.
  - Create a temp file. Create two partitions and format the partitions. kpartx
    -a on it. Both the file systems should get mounted.
  - Create a temp file. luksformat it. Create a filesystem. luksopen the file.
    It should get auto mounted.
  - Checking for disk space repeatedly happens every 3 minutes.
  - Drives are checked for healthy status only once, 3 seconds after FreedomBox is started.
  - FreedomBox is able to mount disks while running as 'plinth' user with
    policykit-1 version 0.105-26.
  - FreedomBox is able to mount disks while running as 'plinth' user with
    policykit-1 version 0.116-2 from experimental.
  - Temporarily flip the is_failing condition in report_failing_drive. When
    FreedomBox is restarted, notification about drives failing show up. When the
    condition is reverted to normal, the notification is withdrawn.
  - Build new Debian package and upgrade system with 20.8 installed. Two files
    should be removed:
    /var/lib/systemd/deb-systemd-helper-enabled/freedombox-udiskie.service.dsh-also
    /etc/systemd/system/multi-user.target.wants/freedombox-udiskie.service .
    systemctl status freedombox-udiskie.service should report no such unit.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-05-16 11:42:23 +03:00
Joseph Nuthalapati
d8942eec6f
udiskie: Finish merging udiskie into storage
Fixes #1370

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-12-07 11:20:38 -05:00
Joseph Nuthalapati
ed09028fcd
udiskie: unmount drive as superuser
Since storage devices are auto-mounted as root, they also need to be unmounted
as root.

The assumption here is that this wouldn't have any impact on being able to
write to the devices.

Fixes #1411

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-11-05 18:07:29 -08:00
Joseph Nuthalapati
a307476634
udiskie: Merge into storage module
udiskie is now an essential module that will be installed along with storage.

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-09-24 18:04:50 -04:00