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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/kernel_object.cc

Issue 349703003: [NaCl SDK] Add some more logging to nacl_io. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix linux host build Created 6 years, 6 months 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 | Annotate | Revision Log
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 "nacl_io/kernel_object.h" 5 #include "nacl_io/kernel_object.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <pthread.h> 10 #include <pthread.h>
11 11
12 #include <algorithm> 12 #include <algorithm>
13 #include <map> 13 #include <map>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "nacl_io/filesystem.h" 17 #include "nacl_io/filesystem.h"
18 #include "nacl_io/kernel_handle.h" 18 #include "nacl_io/kernel_handle.h"
19 #include "nacl_io/log.h"
19 #include "nacl_io/node.h" 20 #include "nacl_io/node.h"
20 21
21 #include "sdk_util/auto_lock.h" 22 #include "sdk_util/auto_lock.h"
22 #include "sdk_util/ref_object.h" 23 #include "sdk_util/ref_object.h"
23 #include "sdk_util/scoped_ref.h" 24 #include "sdk_util/scoped_ref.h"
24 25
25 namespace nacl_io { 26 namespace nacl_io {
26 27
27 KernelObject::KernelObject() { 28 KernelObject::KernelObject() {
28 cwd_ = "/"; 29 cwd_ = "/";
29 } 30 }
30 31
31 KernelObject::~KernelObject() {}; 32 KernelObject::~KernelObject() {};
32 33
33 Error KernelObject::AttachFsAtPath(const ScopedFilesystem& fs, 34 Error KernelObject::AttachFsAtPath(const ScopedFilesystem& fs,
34 const std::string& path) { 35 const std::string& path) {
35 std::string abs_path = GetAbsParts(path).Join(); 36 std::string abs_path = GetAbsParts(path).Join();
36 37
37 AUTO_LOCK(fs_lock_); 38 AUTO_LOCK(fs_lock_);
38 if (filesystems_.find(abs_path) != filesystems_.end()) 39 if (filesystems_.find(abs_path) != filesystems_.end()) {
40 LOG_ERROR("Can't mount at %s, it is already mounted.", path.c_str());
39 return EBUSY; 41 return EBUSY;
42 }
40 43
41 filesystems_[abs_path] = fs; 44 filesystems_[abs_path] = fs;
42 return 0; 45 return 0;
43 } 46 }
44 47
45 Error KernelObject::DetachFsAtPath(const std::string& path, 48 Error KernelObject::DetachFsAtPath(const std::string& path,
46 ScopedFilesystem* out_fs) { 49 ScopedFilesystem* out_fs) {
47 std::string abs_path = GetAbsParts(path).Join(); 50 std::string abs_path = GetAbsParts(path).Join();
48 51
49 AUTO_LOCK(fs_lock_); 52 AUTO_LOCK(fs_lock_);
50 FsMap_t::iterator it = filesystems_.find(abs_path); 53 FsMap_t::iterator it = filesystems_.find(abs_path);
51 if (filesystems_.end() == it) 54 if (filesystems_.end() == it) {
55 LOG_TRACE("Can't unmount at %s, nothing is mounted.", path.c_str());
52 return EINVAL; 56 return EINVAL;
57 }
53 58
54 // It is only legal to unmount if there are no open references 59 // It is only legal to unmount if there are no open references
55 if (it->second->RefCount() != 1) 60 if (it->second->RefCount() != 1) {
61 LOG_TRACE("Can't unmount at %s, refcount is != 1.", path.c_str());
56 return EBUSY; 62 return EBUSY;
63 }
57 64
58 *out_fs = it->second; 65 *out_fs = it->second;
59 66
60 filesystems_.erase(it); 67 filesystems_.erase(it);
61 return 0; 68 return 0;
62 } 69 }
63 70
64 // Uses longest prefix to find the filesystem for the give path, then 71 // Uses longest prefix to find the filesystem for the give path, then
65 // acquires the filesystem and returns it with a relative path. 72 // acquires the filesystem and returns it with a relative path.
66 Error KernelObject::AcquireFsAndRelPath(const std::string& path, 73 Error KernelObject::AcquireFsAndRelPath(const std::string& path,
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 AUTO_LOCK(handle_lock_); 254 AUTO_LOCK(handle_lock_);
248 255
249 handle_map_[fd].handle.reset(NULL); 256 handle_map_[fd].handle.reset(NULL);
250 free_fds_.push_back(fd); 257 free_fds_.push_back(fd);
251 258
252 // Force lower numbered FD to be available first. 259 // Force lower numbered FD to be available first.
253 std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>()); 260 std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>());
254 } 261 }
255 262
256 } // namespace nacl_io 263 } // namespace nacl_io
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/kernel_handle.cc ('k') | native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698