Commit 785315a0 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Add a MOUNT_TYPE_NETWORK_SOURCE to match MOUNT_SOURCE_NETWORK_SOURCE.

The cros-disks equivalent for MountType (MountSourceType) has a third
option (MOUNT_SOURCE_NETWORK_STORAGE) without a matching enumerator in
MountType; this value is now used for generic fuse mounts. VolumeManager
falls-through switches due to the unexpected value.

Add MOUNT_TYPE_NETWORK_SOURCE on the chrome side to avoid this problem.
Since this is currently a catch-all value for all generic fuse mount
types, VolumeManager isn't capable of handling their mounts reasonably.
Instead, ignore mount events with type MOUNT_TYPE_NETWORK_SOURCE in
VolumeManager; the mounters will handle their mount events individually.

Bug: 829274,832507
Change-Id: I18dc0b5b68120c94da2ebbe05ee863a6f471b81c
Reviewed-on: https://chromium-review.googlesource.com/1053621Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558169}
parent 738768f5
......@@ -93,6 +93,10 @@ VolumeType MountTypeToVolumeType(chromeos::MountType type) {
return VOLUME_TYPE_REMOVABLE_DISK_PARTITION;
case chromeos::MOUNT_TYPE_ARCHIVE:
return VOLUME_TYPE_MOUNTED_ARCHIVE_FILE;
case chromeos::MOUNT_TYPE_NETWORK_STORAGE:
// Network storage mounts are handled by their mounters so
// MOUNT_TYPE_NETWORK_STORAGE should never need to be handled here.
break;
}
NOTREACHED();
......@@ -620,40 +624,53 @@ void VolumeManager::OnMountEvent(
chromeos::MountError error_code,
const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK_NE(chromeos::MOUNT_TYPE_INVALID, mount_info.mount_type);
if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
// If the file is not mounted now, tell it to drive file system so that
// it can handle file caching correctly.
// Note that drive file system knows if the file is managed by drive file
// system or not, so here we report all paths.
if ((event == chromeos::disks::DiskMountManager::MOUNTING &&
error_code != chromeos::MOUNT_ERROR_NONE) ||
(event == chromeos::disks::DiskMountManager::UNMOUNTING &&
error_code == chromeos::MOUNT_ERROR_NONE)) {
drive::FileSystemInterface* const file_system =
drive::util::GetFileSystemByProfile(profile_);
if (file_system) {
file_system->MarkCacheFileAsUnmounted(
base::FilePath(mount_info.source_path), base::DoNothing());
switch (mount_info.mount_type) {
case chromeos::MOUNT_TYPE_ARCHIVE: {
// If the file is not mounted now, tell it to drive file system so that
// it can handle file caching correctly.
// Note that drive file system knows if the file is managed by drive file
// system or not, so here we report all paths.
if ((event == chromeos::disks::DiskMountManager::MOUNTING &&
error_code != chromeos::MOUNT_ERROR_NONE) ||
(event == chromeos::disks::DiskMountManager::UNMOUNTING &&
error_code == chromeos::MOUNT_ERROR_NONE)) {
drive::FileSystemInterface* const file_system =
drive::util::GetFileSystemByProfile(profile_);
if (file_system) {
file_system->MarkCacheFileAsUnmounted(
base::FilePath(mount_info.source_path), base::DoNothing());
}
}
FALLTHROUGH;
}
case chromeos::MOUNT_TYPE_DEVICE: {
// Notify a mounting/unmounting event to observers.
const chromeos::disks::DiskMountManager::Disk* const disk =
disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path);
std::unique_ptr<Volume> volume =
Volume::CreateForRemovable(mount_info, disk);
switch (event) {
case chromeos::disks::DiskMountManager::MOUNTING: {
DoMountEvent(error_code, std::move(volume));
return;
}
case chromeos::disks::DiskMountManager::UNMOUNTING:
DoUnmountEvent(error_code, *volume);
return;
}
NOTREACHED();
}
}
// Notify a mounting/unmounting event to observers.
const chromeos::disks::DiskMountManager::Disk* const disk =
disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path);
std::unique_ptr<Volume> volume = Volume::CreateForRemovable(mount_info, disk);
switch (event) {
case chromeos::disks::DiskMountManager::MOUNTING: {
DoMountEvent(error_code, std::move(volume));
return;
// Network storage is responsible for doing its own mounting.
case chromeos::MOUNT_TYPE_NETWORK_STORAGE: {
break;
}
case chromeos::MOUNT_TYPE_INVALID: {
NOTREACHED();
break;
}
case chromeos::disks::DiskMountManager::UNMOUNTING:
DoUnmountEvent(error_code, *volume);
return;
}
NOTREACHED();
}
void VolumeManager::OnFormatEvent(
......@@ -955,19 +972,29 @@ void VolumeManager::OnDiskMountManagerRefreshed(bool success) {
const chromeos::disks::DiskMountManager::MountPointMap& mount_points =
disk_mount_manager_->mount_points();
for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it =
mount_points.begin();
it != mount_points.end();
++it) {
if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
// Archives are mounted after other types of volume. See below.
archives.push_back(Volume::CreateForRemovable(it->second, nullptr));
continue;
for (const auto& mount_point : mount_points) {
switch (mount_point.second.mount_type) {
case chromeos::MOUNT_TYPE_ARCHIVE: {
// Archives are mounted after other types of volume. See below.
archives.push_back(
Volume::CreateForRemovable(mount_point.second, nullptr));
break;
}
case chromeos::MOUNT_TYPE_DEVICE: {
DoMountEvent(
chromeos::MOUNT_ERROR_NONE,
Volume::CreateForRemovable(
mount_point.second, disk_mount_manager_->FindDiskBySourcePath(
mount_point.second.source_path)));
break;
}
case chromeos::MOUNT_TYPE_NETWORK_STORAGE: {
break;
}
case chromeos::MOUNT_TYPE_INVALID: {
NOTREACHED();
}
}
DoMountEvent(chromeos::MOUNT_ERROR_NONE,
Volume::CreateForRemovable(
it->second, disk_mount_manager_->FindDiskBySourcePath(
it->second.source_path)));
}
// We mount archives only if they are opened from currently mounted volumes.
......
......@@ -85,10 +85,8 @@ class DriveFsHost::MountState : public mojom::DriveFsDelegate,
.Append(host_->account_id_.GetAccountIdKey())
.value()});
// TODO(sammc): Switch the mount type once a more appropriate mount type
// exists.
chromeos::disks::DiskMountManager::GetInstance()->MountPath(
source_path_, "", "", {}, chromeos::MOUNT_TYPE_ARCHIVE,
source_path_, "", "", {}, chromeos::MOUNT_TYPE_NETWORK_STORAGE,
chromeos::MOUNT_ACCESS_MODE_READ_WRITE);
auto bootstrap =
......@@ -136,7 +134,8 @@ class DriveFsHost::MountState : public mojom::DriveFsDelegate,
chromeos::MountError error_code,
const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) {
DCHECK_CALLED_ON_VALID_SEQUENCE(host_->sequence_checker_);
if (mount_info.source_path != source_path_ ||
if (mount_info.mount_type != chromeos::MOUNT_TYPE_NETWORK_STORAGE ||
mount_info.source_path != source_path_ ||
event != chromeos::disks::DiskMountManager::MOUNTING) {
return true;
}
......
......@@ -275,7 +275,7 @@ class DriveFsHostTest : public ::testing::Test,
{base::StrCat({"drivefs://", token,
"@/path/to/profile/GCache/v2/g-ID"}),
"/media/drivefsroot/g-ID",
chromeos::MOUNT_TYPE_ARCHIVE,
chromeos::MOUNT_TYPE_NETWORK_STORAGE,
{}});
}
......@@ -418,7 +418,7 @@ TEST_F(DriveFsHostTest, ObserveOtherMount) {
chromeos::disks::DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE,
{base::StrCat({"drivefs://", token, "@/path/to/profile/GCache/v2/g-ID"}),
"/media/drivefsroot/g-ID",
chromeos::MOUNT_TYPE_ARCHIVE,
chromeos::MOUNT_TYPE_NETWORK_STORAGE,
{}});
EXPECT_FALSE(host_->IsMounted());
host_->Unmount();
......@@ -433,7 +433,7 @@ TEST_F(DriveFsHostTest, MountError) {
chromeos::MOUNT_ERROR_DIRECTORY_CREATION_FAILED,
{base::StrCat({"drivefs://", token, "@/path/to/profile/GCache/v2/g-ID"}),
"/media/drivefsroot/g-ID",
chromeos::MOUNT_TYPE_ARCHIVE,
chromeos::MOUNT_TYPE_NETWORK_STORAGE,
{}});
EXPECT_FALSE(host_->IsMounted());
EXPECT_FALSE(PendingConnectionManager::Get().OpenIpcChannel(token, {}));
......
......@@ -36,6 +36,7 @@ enum MountType {
MOUNT_TYPE_INVALID,
MOUNT_TYPE_DEVICE,
MOUNT_TYPE_ARCHIVE,
MOUNT_TYPE_NETWORK_STORAGE,
};
// Type of device.
......
......@@ -88,6 +88,10 @@ void FakeCrosDisksClient::Mount(const std::string& source_path,
mounted_path = GetRemovableDiskMountPoint().Append(
base::FilePath::FromUTF8Unsafe(mount_label));
break;
case MOUNT_TYPE_NETWORK_STORAGE:
// TODO(sammc): Support mounting fake network storage.
NOTREACHED();
return;
case MOUNT_TYPE_INVALID:
NOTREACHED();
return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment