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

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: Do not pass mount path as mount_label because it causes test failure on some platforms. 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.
117 for (auto it = disks_.begin(); it != disks_.end(); ++it) {
hashimoto 2016/10/26 06:05:12 How about using range-based for? for (const auto
yamaguchi 2016/10/27 06:34:55 Done.
118 RemountRemovableDrive(it->second->mount_path(), mode);
119 }
120 }
121
122 void RemountRemovableDrive(const std::string& mount_path,
hashimoto 2016/10/26 06:05:12 This method should be private.
yamaguchi 2016/10/27 06:34:55 Done.
123 MountAccessMode access_mode) {
124 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path);
125 if (mount_point == mount_points_.end()) {
126 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found.";
hashimoto 2016/10/26 06:05:12 Don't we need to call OnMountCompleted with an err
yamaguchi 2016/10/27 06:34:55 Done.
127 return;
128 }
129
130 std::string device_path = mount_point->second.source_path;
hashimoto 2016/10/26 06:05:12 const std::string&?
yamaguchi 2016/10/27 06:34:55 Done.
131 DiskMap::const_iterator disk = disks_.find(device_path);
hashimoto 2016/10/26 06:05:12 In RemountAllRemovableDrives(), we already know wh
yamaguchi 2016/10/27 06:34:55 That's right. Fixed.
132 if (disk == disks_.end()) {
133 LOG(ERROR) << "Device with path \"" << device_path << "\" not found.";
134 return;
135 }
136 if (disk->second->is_read_only_hardware()) {
137 // A read-only device can be mounted in RO mode only. No need to remount.
138 return;
139 }
140
141 const std::string& source_path = mount_point->second.source_path;
142
143 // Update the access mode option passed to CrosDisks.
144 // This is needed because CrosDisks service methods doesn't return the info
145 // via DBus, and must be updated before issuing Mount command as it'll be
146 // read by the handler of MountCompleted signal.
147 access_modes_[source_path] = access_mode;
hashimoto 2016/10/26 06:05:12 I'm not familiar with this access mode management
yamaguchi 2016/10/27 06:34:55 Yes, storing to access_modes_ here is a tentative
hashimoto 2016/10/27 08:31:52 Seems the said patch was already submitted. What e
yamaguchi 2016/10/27 09:52:40 Sorry for confusing you. That change is part of it
hashimoto 2016/10/28 08:55:37 The said change should be made as early as possibl
148
149 cros_disks_client_->Mount(
150 mount_point->second.source_path, std::string(), std::string(),
151 access_mode, REMOUNT_OPTION_REMOUNT_EXISTING_DEVICE,
152 // When succeeds, OnMountCompleted will be called by
153 // "MountCompleted" signal instead.
154 base::Bind(&base::DoNothing),
155 base::Bind(&DiskMountManagerImpl::OnMountCompleted,
156 weak_ptr_factory_.GetWeakPtr(),
157 MountEntry(MOUNT_ERROR_INTERNAL, source_path,
158 mount_point->second.mount_type, "")));
159 }
160
115 // DiskMountManager override. 161 // DiskMountManager override.
116 void FormatMountedDevice(const std::string& mount_path) override { 162 void FormatMountedDevice(const std::string& mount_path) override {
117 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path); 163 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path);
118 if (mount_point == mount_points_.end()) { 164 if (mount_point == mount_points_.end()) {
119 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found."; 165 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found.";
120 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, mount_path); 166 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, mount_path);
121 return; 167 return;
122 } 168 }
123 169
124 std::string device_path = mount_point->second.source_path; 170 std::string device_path = mount_point->second.source_path;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 397
352 if ((entry.error_code() == MOUNT_ERROR_NONE || 398 if ((entry.error_code() == MOUNT_ERROR_NONE ||
353 mount_info.mount_condition) && 399 mount_info.mount_condition) &&
354 mount_info.mount_type == MOUNT_TYPE_DEVICE && 400 mount_info.mount_type == MOUNT_TYPE_DEVICE &&
355 !mount_info.source_path.empty() && 401 !mount_info.source_path.empty() &&
356 !mount_info.mount_path.empty()) { 402 !mount_info.mount_path.empty()) {
357 DiskMap::iterator iter = disks_.find(mount_info.source_path); 403 DiskMap::iterator iter = disks_.find(mount_info.source_path);
358 if (iter != disks_.end()) { // disk might have been removed by now? 404 if (iter != disks_.end()) { // disk might have been removed by now?
359 Disk* disk = iter->second.get(); 405 Disk* disk = iter->second.get();
360 DCHECK(disk); 406 DCHECK(disk);
361 // The is_read_only field in *disk may be incorrect when this is called 407 // Lookup the mount option passed when invoking Mount() by source path.
hashimoto 2016/10/26 06:05:12 I couldn't understand what this comment means. Wha
yamaguchi 2016/10/27 06:34:55 Revised the comments. Hope it makes more sense now
362 // from CrosDisksClientImpl::OnMountCompleted.
363 // The disk should be treated as read-only when:
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 408 // |source_path| should be same as |disk->device_path| because
367 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a 409 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a
368 // source path when mounting a device. 410 // source path when mounting a device.
369 AccessModeMap::iterator it = access_modes_.find(entry.source_path()); 411 AccessModeMap::iterator it = access_modes_.find(entry.source_path());
370 if (it != access_modes_.end() && 412 if (it != access_modes_.end() && !disk->is_read_only_hardware()) {
hashimoto 2016/10/26 06:05:12 It's not clear to me what this change is doing (an
yamaguchi 2016/10/27 06:34:55 This mechanism to update the Disk object is revise
371 it->second == chromeos::MOUNT_ACCESS_MODE_READ_ONLY) { 413 disk->set_write_disabled_by_policy(it->second ==
372 disk->set_write_disabled_by_policy(true); 414 MOUNT_ACCESS_MODE_READ_ONLY);
373 } 415 }
374 disk->set_mount_path(mount_info.mount_path); 416 disk->set_mount_path(mount_info.mount_path);
375 } 417 }
376 } 418 }
377 // Observers may read the values of disks_. So notify them after tweaking 419 // Observers may read the values of disks_. So notify them after tweaking
378 // values of disks_. 420 // values of disks_.
379 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info); 421 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info);
380 } 422 }
381 423
382 // Callback for UnmountPath. 424 // Callback for UnmountPath.
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 VLOG(1) << "DiskMountManager Shutdown completed"; 839 VLOG(1) << "DiskMountManager Shutdown completed";
798 } 840 }
799 841
800 // static 842 // static
801 DiskMountManager* DiskMountManager::GetInstance() { 843 DiskMountManager* DiskMountManager::GetInstance() {
802 return g_disk_mount_manager; 844 return g_disk_mount_manager;
803 } 845 }
804 846
805 } // namespace disks 847 } // namespace disks
806 } // namespace chromeos 848 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698