• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef OHOS_CLOUD_SYNC_SERVICE_CLOUD_FILE_FAULT_EVENT_H
16 #define OHOS_CLOUD_SYNC_SERVICE_CLOUD_FILE_FAULT_EVENT_H
17 
18 #include "hisysevent.h"
19 #include <map>
20 
21 #define CLOUD_SYNC_FAULT_REPORT(...) \
22     CloudFile::CloudFileFaultEvent::CloudSyncFaultReport(__FUNCTION__, __LINE__, ##__VA_ARGS__)
23 #define CLOUD_FILE_FAULT_REPORT(...) \
24     CloudFile::CloudFileFaultEvent::CloudFileFaultReport(__FUNCTION__, __LINE__, ##__VA_ARGS__)
25 #define CLOUD_SYNC_CACHE_REPORT(...) \
26     CloudFile::CloudFileFaultEvent::CloudSyncCacheReport(__FUNCTION__, __LINE__, ##__VA_ARGS__)
27 
28 namespace OHOS {
29 namespace FileManagement {
30 namespace CloudFile {
31 
32 #ifndef CLOUD_SYNC_SYS_EVENT
33 #define CLOUD_SYNC_SYS_EVENT(eventName, type, ...)                                  \
34     HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, eventName, type, \
35                     ##__VA_ARGS__)
36 #endif
37 
38 #define MINIMUM_FAULT_REPORT_INTERVAL 3600
39 
40 enum class FaultScenarioCode {
41     CLOUD_INIT = 000,
42     CLOUD_FULL_SYNC = 100,
43     CLOUD_INC_SYNC = 200,
44     CLOUD_CHECK_SYNC = 300,
45     CLOUD_SWITCH_CLOSE = 400,
46     CLOUD_LOAD_VIDEO_CACHE = 500,
47     CLOUD_DOWNLOAD_FILE = 600,
48     CLOUD_DOWNLOAD_THUM = 700,
49     CLOUD_OPTIMMIZE_STORAGE = 800,
50     CLOUD_PROCESS_EXIT_START = 900,
51     CLOUD_ACCOUNT_EXIT = 1000
52 };
53 
54 enum class FaultOperation {
55     LOOKUP = 100,
56     FORGET = 200,
57     GETATTR = 300,
58     OPEN = 400,
59     READ = 500,
60     READDIR = 600,
61     RELEASE = 700,
62     FORGETMULTI = 800,
63     IOCTL = 900,
64     UNLINK = 1000,
65     SETATTR = 1100,
66     SETEXTATTR = 1200,
67     MKNOD = 1300,
68     MKDIR = 1400,
69     GETEXTATTR = 1500,
70     CREATE = 1600,
71     WRITE = 1700,
72     RENAME = 1800,
73     RMDIR = 1900,
74     SESSION = 2000,
75     DOWNLOAD = 2100
76 };
77 
78 enum class FaultType {
79     /* file fault type */
80     FILE = 10000000,
81     DENTRY_FILE = 10000001,
82     INODE_FILE = 10000002,
83 
84     /* driverkit fault type */
85     DRIVERKIT = 20000000,
86     DRIVERKIT_NETWORK = 20000001,
87     DRIVERKIT_SERVER = 20000002,
88     DRIVERKIT_LOCAL = 20000003,
89     DRIVERKIT_DATABASE = 20000004,
90     DRIVERKIT_READSESSION = 20000005,
91 
92     /* timeout fault type */
93     TIMEOUT = 30000000,
94     OPEN_CLOUD_FILE_TIMEOUT = 30000001,
95     CLOUD_READ_FILE_TIMEOUT = 30000002,
96     CLOUD_FILE_LOOKUP_TIMEOUT = 30000003,
97     CLOUD_FILE_FORGET_TIMEOUT = 30000004,
98 
99     /* temperature fault type */
100     TEMPERATURE = 40000000,
101 
102     /* database fault type */
103     DATABASE = 50000000,
104     QUERY_DATABASE = 50000001,
105     INSERT_DATABASE = 50000002,
106     DELETE_DATABASE = 50000003,
107     MODIFY_DATABASE = 50000004,
108 
109     /* consistency fault type */
110     CONSISTENCY = 60000000,
111     FILE_CONSISTENCY = 60000001,
112     META_CONSISTENCY = 60000002,
113 
114     /* process fault type */
115     PROCESS = 70000000,
116 
117     /* cloud sync error */
118     CLOUD_SYNC_ERROR = 80000000,
119 
120     /* inner error */
121     INNER_ERROR = 90000000,
122 
123     /* warning */
124     WARNING = 100000000
125 };
126 
127 struct CloudSyncFaultInfo {
128     std::string bundleName_;
129     FaultScenarioCode faultScenario_;
130     FaultType faultType_;
131     int32_t faultErrorCode_;
132     std::string message_;
133 };
134 
135 struct CloudFileFaultInfo {
136     std::string bundleName_;
137     FaultOperation faultOperation_;
138     FaultType faultType_;
139     int32_t faultErrorCode_;
140     std::string message_;
141 };
142 
143 struct CloudCacheFaultInfo {
144     std::string bundleName_;
145     FaultType faultType_;
146     int32_t faultErrorCode_;
147     std::string message_;
148     bool terminate_ = false;
149 };
150 
151 const std::vector<FaultType> PERIODIC_REPORT_FAULT_TYPE = { FaultType::WARNING,
152                                                             FaultType::TIMEOUT,
153                                                             FaultType::OPEN_CLOUD_FILE_TIMEOUT,
154                                                             FaultType::CLOUD_READ_FILE_TIMEOUT,
155                                                             FaultType::CLOUD_FILE_LOOKUP_TIMEOUT,
156                                                             FaultType::CLOUD_FILE_FORGET_TIMEOUT };
157 
158 class CloudFaultReportStatus {
159 public:
160     static CloudFaultReportStatus &GetInstance();
161 
162     bool IsAllowToReport(const FaultType &faultType);
163 
164 private:
165     CloudFaultReportStatus();
166 
167     CloudFaultReportStatus(const CloudFaultReportStatus&) = delete;
168 
169     CloudFaultReportStatus& operator=(const CloudFaultReportStatus&) = delete;
170 
171     std::mutex timeMapLock_;
172     std::unordered_map<FaultType, int64_t> lastTimeMap_;
173 } ;
174 
175 class CloudFileFaultEvent {
176 public:
177     static int32_t CloudSyncFaultReport(const std::string &funcName,
178                                         const int lineNum,
179                                         const CloudSyncFaultInfo &event);
180 
181     static int32_t CloudFileFaultReport(const std::string &funcName,
182                                         const int lineNum,
183                                         const CloudFileFaultInfo &event);
184 
185     static int32_t CloudSyncCacheReport(const std::string &funcName,
186                                         const int lineNum,
187                                         const CloudCacheFaultInfo &event);
188 };
189 
190 } // namespace CloudFile
191 } // namespace FileManagement
192 } // namespace OHOS
193 
194 #endif // OHOS_CLOUD_SYNC_SERVICE_CLOUD_FILE_FAULT_EVENT_H
195