1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <stdlib.h> 20 21 #include <lib/tipc/tipc.h> 22 #include <lk/compiler.h> 23 24 #include "block_device_tipc.h" 25 26 __BEGIN_CDECLS 27 28 #if STORAGE_AIDL_ENABLED 29 30 struct storage_service_aidl_context_inner; 31 32 struct storage_service_aidl_context { 33 struct storage_service_aidl_context_inner* inner; 34 }; 35 36 #define STORAGE_SERVICE_AIDL_CONTEXT_INITIAL_VALUE(self) \ 37 (struct storage_service_aidl_context) { \ 38 .inner = NULL \ 39 } 40 41 /** 42 * storage_aidl_create_service() - Initialize a storage aidl service 43 * @self: Out-param. Will contain the created &struct 44 * storage_service_aidl_context, which must be cleaned up by passing it to 45 * storage_aidl_destroy_service(). 46 * @hset: The handle set the service will run on. 47 */ 48 int storage_aidl_create_service(struct storage_service_aidl_context* self, 49 struct tipc_hset* hset); 50 51 /** 52 * storage_aidl_destroy_service() - Delete a storage aidl service 53 * @self: The &struct storage_service_aidl_context to delete. When called, there 54 * must not be any remaining AIDL objects created from @self that are still 55 * callable (including remotely). 56 */ 57 void storage_aidl_destroy_service(struct storage_service_aidl_context* self); 58 59 /** 60 * storage_aidl_enable() - Connect the storage aidl service to backing 61 * filesystems. 62 * @self: The &struct storage_service_aidl_context to modify. 63 * @block_devices: Context holding the filesystems to connect to. 64 * 65 * Callers must not connect a second time without calling storage_aidl_disable() 66 * first. 67 */ 68 void storage_aidl_enable(struct storage_service_aidl_context* self, 69 struct block_device_tipc* block_devices); 70 71 /** 72 * storage_aidl_disable() - Disconnect the storage aidl service from backing 73 * filesystems. 74 * @self: The &struct storage_service_aidl_context to modify. 75 * 76 * Callers must only disable a service that has been previously enabled (with 77 * storage_aidl_enable()), and must not disable an already-disabled service. 78 */ 79 void storage_aidl_disable(struct storage_service_aidl_context* self); 80 81 #else 82 83 struct storage_service_aidl_context {}; 84 85 #define STORAGE_SERVICE_AIDL_CONTEXT_INITIAL_VALUE(self) \ 86 (struct storage_service_aidl_context) {} 87 88 static inline int storage_aidl_create_service( 89 struct storage_service_aidl_context* self, 90 struct tipc_hset* hset) { 91 *self = STORAGE_SERVICE_AIDL_CONTEXT_INITIAL_VALUE(*self); 92 return EXIT_SUCCESS; 93 } 94 95 static inline void storage_aidl_destroy_service( 96 struct storage_service_aidl_context* self) {} 97 98 static inline void storage_aidl_enable( 99 struct storage_service_aidl_context* self, 100 struct block_device_tipc* block_devices) {} 101 102 static inline void storage_aidl_disable( 103 struct storage_service_aidl_context* self) {} 104 105 #endif 106 107 __END_CDECLS 108