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

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: Add is_mounted() method. 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
« no previous file with comments | « chromeos/disks/disk_mount_manager.h ('k') | chromeos/disks/disk_mount_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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. crbug.com/661455
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.is_mounted()) {
124 continue;
125 }
126 RemountRemovableDrive(disk, mode);
127 }
128 }
129
115 // DiskMountManager override. 130 // DiskMountManager override.
116 void FormatMountedDevice(const std::string& mount_path) override { 131 void FormatMountedDevice(const std::string& mount_path) override {
117 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path); 132 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path);
118 if (mount_point == mount_points_.end()) { 133 if (mount_point == mount_points_.end()) {
119 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found."; 134 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found.";
120 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, mount_path); 135 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, mount_path);
121 return; 136 return;
122 } 137 }
123 138
124 std::string device_path = mount_point->second.source_path; 139 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, 288 const UnmountDeviceRecursivelyCallbackType& in_callback,
274 int in_num_pending_callbacks) 289 int in_num_pending_callbacks)
275 : callback(in_callback), 290 : callback(in_callback),
276 num_pending_callbacks(in_num_pending_callbacks) { 291 num_pending_callbacks(in_num_pending_callbacks) {
277 } 292 }
278 293
279 const UnmountDeviceRecursivelyCallbackType callback; 294 const UnmountDeviceRecursivelyCallbackType callback;
280 size_t num_pending_callbacks; 295 size_t num_pending_callbacks;
281 }; 296 };
282 297
298 void RemountRemovableDrive(const Disk& disk,
299 MountAccessMode access_mode) {
300 const std::string& mount_path = disk.mount_path();
301 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path);
302 if (mount_point == mount_points_.end()) {
303 // Not in mount_points_. This happens when the mount_points ans disks_ are
304 // inconsistent.
305 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found.";
306 OnMountCompleted(
307 MountEntry(MOUNT_ERROR_PATH_NOT_MOUNTED, disk.device_path(),
308 MOUNT_TYPE_DEVICE, mount_path));
309 return;
310 }
311 const std::string& source_path = mount_point->second.source_path;
312
313 // Update the access mode option passed to CrosDisks.
314 // This is needed because CrosDisks service methods doesn't return the info
315 // via DBus, and must be updated before issuing Mount command as it'll be
316 // read by the handler of MountCompleted signal.
317 access_modes_[source_path] = access_mode;
318
319 cros_disks_client_->Mount(
320 mount_point->second.source_path, std::string(), std::string(),
321 access_mode, REMOUNT_OPTION_REMOUNT_EXISTING_DEVICE,
322 // When succeeds, OnMountCompleted will be called by
323 // "MountCompleted" signal instead.
324 base::Bind(&base::DoNothing),
325 base::Bind(&DiskMountManagerImpl::OnMountCompleted,
326 weak_ptr_factory_.GetWeakPtr(),
327 MountEntry(MOUNT_ERROR_INTERNAL, source_path,
328 mount_point->second.mount_type, "")));
329 }
330
283 // Unmounts all mount points whose source path is transitively parented by 331 // Unmounts all mount points whose source path is transitively parented by
284 // |mount_path|. 332 // |mount_path|.
285 void UnmountChildMounts(const std::string& mount_path_in) { 333 void UnmountChildMounts(const std::string& mount_path_in) {
286 std::string mount_path = mount_path_in; 334 std::string mount_path = mount_path_in;
287 // Let's make sure mount path has trailing slash. 335 // Let's make sure mount path has trailing slash.
288 if (mount_path.back() != '/') 336 if (mount_path.back() != '/')
289 mount_path += '/'; 337 mount_path += '/';
290 338
291 for (MountPointMap::iterator it = mount_points_.begin(); 339 for (MountPointMap::iterator it = mount_points_.begin();
292 it != mount_points_.end(); 340 it != mount_points_.end();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 399
352 if ((entry.error_code() == MOUNT_ERROR_NONE || 400 if ((entry.error_code() == MOUNT_ERROR_NONE ||
353 mount_info.mount_condition) && 401 mount_info.mount_condition) &&
354 mount_info.mount_type == MOUNT_TYPE_DEVICE && 402 mount_info.mount_type == MOUNT_TYPE_DEVICE &&
355 !mount_info.source_path.empty() && 403 !mount_info.source_path.empty() &&
356 !mount_info.mount_path.empty()) { 404 !mount_info.mount_path.empty()) {
357 DiskMap::iterator iter = disks_.find(mount_info.source_path); 405 DiskMap::iterator iter = disks_.find(mount_info.source_path);
358 if (iter != disks_.end()) { // disk might have been removed by now? 406 if (iter != disks_.end()) { // disk might have been removed by now?
359 Disk* disk = iter->second.get(); 407 Disk* disk = iter->second.get();
360 DCHECK(disk); 408 DCHECK(disk);
361 // The is_read_only field in *disk may be incorrect when this is called 409 // Currently the MountCompleted signal doesn't tell whether the device
362 // from CrosDisksClientImpl::OnMountCompleted. 410 // is mounted in read-only mode or not. Instead use the mount option
363 // The disk should be treated as read-only when: 411 // 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 412 // |source_path| should be same as |disk->device_path| because
367 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a 413 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a
368 // source path when mounting a device. 414 // source path when mounting a device.
369 AccessModeMap::iterator it = access_modes_.find(entry.source_path()); 415 AccessModeMap::iterator it = access_modes_.find(entry.source_path());
370 if (it != access_modes_.end() && 416
371 it->second == chromeos::MOUNT_ACCESS_MODE_READ_ONLY) { 417 // Store whether the disk was mounted in read-only mode due to a policy.
372 disk->set_write_disabled_by_policy(true); 418 disk->set_write_disabled_by_policy(
373 } 419 it != access_modes_.end() && !disk->is_read_only_hardware()
420 && it->second == MOUNT_ACCESS_MODE_READ_ONLY);
374 disk->set_mount_path(mount_info.mount_path); 421 disk->set_mount_path(mount_info.mount_path);
375 } 422 }
376 } 423 }
377 // Observers may read the values of disks_. So notify them after tweaking 424 // Observers may read the values of disks_. So notify them after tweaking
378 // values of disks_. 425 // values of disks_.
379 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info); 426 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info);
380 } 427 }
381 428
382 // Callback for UnmountPath. 429 // Callback for UnmountPath.
383 void OnUnmountPath(const UnmountPathCallback& callback, 430 void OnUnmountPath(const UnmountPathCallback& callback,
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 VLOG(1) << "DiskMountManager Shutdown completed"; 844 VLOG(1) << "DiskMountManager Shutdown completed";
798 } 845 }
799 846
800 // static 847 // static
801 DiskMountManager* DiskMountManager::GetInstance() { 848 DiskMountManager* DiskMountManager::GetInstance() {
802 return g_disk_mount_manager; 849 return g_disk_mount_manager;
803 } 850 }
804 851
805 } // namespace disks 852 } // namespace disks
806 } // namespace chromeos 853 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/disks/disk_mount_manager.h ('k') | chromeos/disks/disk_mount_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698