• 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 
20 #define CLOUD_SYNC_FAULT_REPORT(...) \
21     CloudFile::CloudFileFaultEvent::CloudSyncFaultReport(__FUNCTION__, __LINE__, ##__VA_ARGS__)
22 #define CLOUD_FILE_FAULT_REPORT(...) \
23     CloudFile::CloudFileFaultEvent::CloudFileFaultReport(__FUNCTION__, __LINE__, ##__VA_ARGS__)
24 
25 namespace OHOS {
26 namespace FileManagement {
27 namespace CloudFile {
28 
29 #ifndef CLOUD_SYNC_SYS_EVENT
30 #define CLOUD_SYNC_SYS_EVENT(eventName, type, ...)                                  \
31     HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, eventName, type, \
32                     ##__VA_ARGS__)
33 #endif
34 
35 #define MINIMUM_FAULT_REPORT_INTERVAL 3600
36 
37 enum class FaultScenarioCode {
38     CLOUD_FULL_SYNC = 100,
39     CLOUD_INC_SYNC = 200,
40     CLOUD_CHECK_SYNC = 300,
41     CLOUD_SWITCH_CLOSE = 400,
42     CLOUD_LOAD_VIDEO_CACHE = 500,
43     CLOUD_DOWNLOAD_FILE = 600,
44     CLOUD_DOWNLOAD_THUM = 700,
45     CLOUD_OPTIMMIZE_STORAGE = 800,
46     CLOUD_PROCESS_EXIT_START = 900,
47     CLOUD_ACCOUNT_EXIT = 1000
48 };
49 
50 enum class FaultOperation {
51     LOOKUP = 100,
52     FORGET = 200,
53     GETATTR = 300,
54     OPEN = 400,
55     READ = 500,
56     READDIR = 600,
57     RELEASE = 700,
58     FORGETMULTI = 800,
59     IOCTL = 900,
60     UNLINK = 1000,
61     SETATTR = 1100
62 };
63 
64 enum class FaultType {
65     /* file fault type */
66     FILE = 10000000,
67     DENTRY_FILE = 10000001,
68     INODE_FILE = 10000002,
69 
70     /* driverkit fault type */
71     DRIVERKIT = 20000000,
72     DRIVERKIT_NETWORK = 20000001,
73     DRIVERKIT_SERVER = 20000002,
74     DRIVERKIT_LOCAL = 20000003,
75     DRIVERKIT_DATABASE = 20000004,
76     DRIVERKIT_READSESSION = 20000005,
77 
78     /* timeout fault type */
79     TIMEOUT = 30000000,
80     OPEN_CLOUD_FILE_TIMEOUT = 30000001,
81     CLOUD_READ_FILE_TIMEOUT = 30000002,
82     CLOUD_FILE_LOOKUP_TIMEOUT = 30000003,
83     CLOUD_FILE_FORGET_TIMEOUT = 30000004,
84 
85     /* temperature fault type */
86     TEMPERATURE = 40000000,
87 
88     /* database fault type */
89     DATABASE = 50000000,
90     QUERY_DATABASE = 50000001,
91     INSERT_DATABASE = 50000002,
92     DELETE_DATABASE = 50000003,
93     MODIFY_DATABASE = 50000004,
94 
95     /* consistency fault type */
96     CONSISTENCY = 60000000,
97     FILE_CONSISTENCY = 60000001,
98     META_CONSISTENCY = 60000002,
99 
100     /* process fault type */
101     PROCESS = 70000000,
102 
103     /* cloud sync error */
104     CLOUD_SYNC_ERROR = 80000000,
105 
106     /* inner error */
107     INNER_ERROR = 90000000
108 };
109 
110 struct CloudSyncFaultInfo {
111     std::string bundleName_;
112     FaultScenarioCode faultScenario_;
113     FaultType faultType_;
114     int32_t faultErrorCode_;
115     std::string message_;
116 };
117 
118 struct CloudFileFaultInfo {
119     std::string bundleName_;
120     FaultOperation faultOperation_;
121     FaultType faultType_;
122     int32_t faultErrorCode_;
123     std::string message_;
124 };
125 
126 const std::vector<FaultType> PERIODIC_REPORT_FAULT_TYPE = { FaultType::OPEN_CLOUD_FILE_TIMEOUT,
127                                                             FaultType::CLOUD_READ_FILE_TIMEOUT,
128                                                             FaultType::CLOUD_FILE_LOOKUP_TIMEOUT,
129                                                             FaultType::CLOUD_FILE_FORGET_TIMEOUT };
130 
131 class CloudFaultReportStatus {
132 public:
133     static CloudFaultReportStatus &GetInstance();
134 
135     bool IsAllowToReport(const FaultType &faultType);
136 
137 private:
138     CloudFaultReportStatus();
139 
140     CloudFaultReportStatus(const CloudFaultReportStatus&) = delete;
141 
142     CloudFaultReportStatus& operator=(const CloudFaultReportStatus&) = delete;
143 
144     std::mutex timeMapLock_;
145     std::unordered_map<FaultType, int64_t> lastTimeMap_;
146 } ;
147 
148 class CloudFileFaultEvent {
149 public:
150     static int32_t CloudSyncFaultReport(const std::string &funcName,
151                                         const int lineNum,
152                                         const CloudSyncFaultInfo &event);
153 
154     static int32_t CloudFileFaultReport(const std::string &funcName,
155                                         const int lineNum,
156                                         const CloudFileFaultInfo &event);
157 };
158 } // namespace CloudFile
159 } // namespace FileManagement
160 } // namespace OHOS
161 
162 #endif // OHOS_CLOUD_SYNC_SERVICE_CLOUD_FILE_FAULT_EVENT_H