Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: chromeos/disks/disk_mount_manager.cc

Issue 2451603002: Add a method to remount all removable devices in DiskMountManager. (Closed)
Patch Set: Fix comment. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/disks/disk_mount_manager.h" 5 #include "chromeos/disks/disk_mount_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 callback, 105 callback,
106 true, 106 true,
107 mount_path), 107 mount_path),
108 base::Bind(&DiskMountManagerImpl::OnUnmountPath, 108 base::Bind(&DiskMountManagerImpl::OnUnmountPath,
109 weak_ptr_factory_.GetWeakPtr(), 109 weak_ptr_factory_.GetWeakPtr(),
110 callback, 110 callback,
111 false, 111 false,
112 mount_path)); 112 mount_path));
113 } 113 }
114 114
115 void RemountAllRemovableDrives(MountAccessMode mode) override {
116 // TODO(yamaguchi): Retry for tentative remount failures.
satorux1 2016/10/31 05:36:00 file a bug and add a crbug.com link here?
yamaguchi 2016/11/02 07:29:51 Done.
117 for (const auto& device_path_and_disk : disks_) {
118 const Disk& disk = *device_path_and_disk.second;
119 if (disk.is_read_only_hardware()) {
120 // Read-only devices can be mounted in RO mode only. No need to remount.
121 continue;
122 }
123 if (disk.mount_path().empty()) {
satorux1 2016/10/31 05:36:00 checking mount path string looks rather strange. w
yamaguchi 2016/11/02 07:29:51 Done.
124 // Not mounted yet.
125 continue;
126 }
127 RemountRemovableDrive(disk, mode);
128 }
129 }
130
115 // DiskMountManager override. 131 // DiskMountManager override.
116 void FormatMountedDevice(const std::string& mount_path) override { 132 void FormatMountedDevice(const std::string& mount_path) override {
117 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path); 133 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path);
118 if (mount_point == mount_points_.end()) { 134 if (mount_point == mount_points_.end()) {
119 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found."; 135 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found.";
120 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, mount_path); 136 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, mount_path);
121 return; 137 return;
122 } 138 }
123 139
124 std::string device_path = mount_point->second.source_path; 140 std::string device_path = mount_point->second.source_path;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 const UnmountDeviceRecursivelyCallbackType& in_callback, 289 const UnmountDeviceRecursivelyCallbackType& in_callback,
274 int in_num_pending_callbacks) 290 int in_num_pending_callbacks)
275 : callback(in_callback), 291 : callback(in_callback),
276 num_pending_callbacks(in_num_pending_callbacks) { 292 num_pending_callbacks(in_num_pending_callbacks) {
277 } 293 }
278 294
279 const UnmountDeviceRecursivelyCallbackType callback; 295 const UnmountDeviceRecursivelyCallbackType callback;
280 size_t num_pending_callbacks; 296 size_t num_pending_callbacks;
281 }; 297 };
282 298
299 void RemountRemovableDrive(const Disk& disk,
300 MountAccessMode access_mode) {
301 const std::string& mount_path = disk.mount_path();
302 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path);
303 if (mount_point == mount_points_.end()) {
304 // Not in mount_points_. This happens when the mount_points ans disks_ are
305 // inconsistent.
306 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found.";
307 OnMountCompleted(
308 MountEntry(MOUNT_ERROR_PATH_NOT_MOUNTED, disk.device_path(),
309 MOUNT_TYPE_DEVICE, mount_path));
310 return;
311 }
312 const std::string& source_path = mount_point->second.source_path;
313
314 // Update the access mode option passed to CrosDisks.
315 // This is needed because CrosDisks service methods doesn't return the info
316 // via DBus, and must be updated before issuing Mount command as it'll be
317 // read by the handler of MountCompleted signal.
318 access_modes_[source_path] = access_mode;
319
320 cros_disks_client_->Mount(
321 mount_point->second.source_path, std::string(), std::string(),
322 access_mode, REMOUNT_OPTION_REMOUNT_EXISTING_DEVICE,
323 // When succeeds, OnMountCompleted will be called by
324 // "MountCompleted" signal instead.
325 base::Bind(&base::DoNothing),
326 base::Bind(&DiskMountManagerImpl::OnMountCompleted,
327 weak_ptr_factory_.GetWeakPtr(),
328 MountEntry(MOUNT_ERROR_INTERNAL, source_path,
329 mount_point->second.mount_type, "")));
330 }
331
283 // Unmounts all mount points whose source path is transitively parented by 332 // Unmounts all mount points whose source path is transitively parented by
284 // |mount_path|. 333 // |mount_path|.
285 void UnmountChildMounts(const std::string& mount_path_in) { 334 void UnmountChildMounts(const std::string& mount_path_in) {
286 std::string mount_path = mount_path_in; 335 std::string mount_path = mount_path_in;
287 // Let's make sure mount path has trailing slash. 336 // Let's make sure mount path has trailing slash.
288 if (mount_path.back() != '/') 337 if (mount_path.back() != '/')
289 mount_path += '/'; 338 mount_path += '/';
290 339
291 for (MountPointMap::iterator it = mount_points_.begin(); 340 for (MountPointMap::iterator it = mount_points_.begin();
292 it != mount_points_.end(); 341 it != mount_points_.end();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 400
352 if ((entry.error_code() == MOUNT_ERROR_NONE || 401 if ((entry.error_code() == MOUNT_ERROR_NONE ||
353 mount_info.mount_condition) && 402 mount_info.mount_condition) &&
354 mount_info.mount_type == MOUNT_TYPE_DEVICE && 403 mount_info.mount_type == MOUNT_TYPE_DEVICE &&
355 !mount_info.source_path.empty() && 404 !mount_info.source_path.empty() &&
356 !mount_info.mount_path.empty()) { 405 !mount_info.mount_path.empty()) {
357 DiskMap::iterator iter = disks_.find(mount_info.source_path); 406 DiskMap::iterator iter = disks_.find(mount_info.source_path);
358 if (iter != disks_.end()) { // disk might have been removed by now? 407 if (iter != disks_.end()) { // disk might have been removed by now?
359 Disk* disk = iter->second.get(); 408 Disk* disk = iter->second.get();
360 DCHECK(disk); 409 DCHECK(disk);
361 // The is_read_only field in *disk may be incorrect when this is called 410 // Currently the MountCompleted signal doesn't tell whether the device
362 // from CrosDisksClientImpl::OnMountCompleted. 411 // is mounted in read-only mode or not. Instead use the mount option
363 // The disk should be treated as read-only when: 412 // recorded by DiskMountManagerImpl::MountPath().
364 // - the read-only option was passed when issuing mount command
365 // - or the device hardware is read-only.
366 // |source_path| should be same as |disk->device_path| because 413 // |source_path| should be same as |disk->device_path| because
367 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a 414 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a
368 // source path when mounting a device. 415 // source path when mounting a device.
369 AccessModeMap::iterator it = access_modes_.find(entry.source_path()); 416 AccessModeMap::iterator it = access_modes_.find(entry.source_path());
370 if (it != access_modes_.end() && 417
371 it->second == chromeos::MOUNT_ACCESS_MODE_READ_ONLY) { 418 // Store whether the disk was mounted in read-only mode due to a policy.
372 disk->set_write_disabled_by_policy(true); 419 disk->set_write_disabled_by_policy(
373 } 420 it != access_modes_.end() && !disk->is_read_only_hardware()
421 && it->second == MOUNT_ACCESS_MODE_READ_ONLY);
374 disk->set_mount_path(mount_info.mount_path); 422 disk->set_mount_path(mount_info.mount_path);
375 } 423 }
376 } 424 }
377 // Observers may read the values of disks_. So notify them after tweaking 425 // Observers may read the values of disks_. So notify them after tweaking
378 // values of disks_. 426 // values of disks_.
379 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info); 427 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info);
380 } 428 }
381 429
382 // Callback for UnmountPath. 430 // Callback for UnmountPath.
383 void OnUnmountPath(const UnmountPathCallback& callback, 431 void OnUnmountPath(const UnmountPathCallback& callback,
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 VLOG(1) << "DiskMountManager Shutdown completed"; 845 VLOG(1) << "DiskMountManager Shutdown completed";
798 } 846 }
799 847
800 // static 848 // static
801 DiskMountManager* DiskMountManager::GetInstance() { 849 DiskMountManager* DiskMountManager::GetInstance() {
802 return g_disk_mount_manager; 850 return g_disk_mount_manager;
803 } 851 }
804 852
805 } // namespace disks 853 } // namespace disks
806 } // namespace chromeos 854 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698