diff --git a/OpenEuler(version_20.09)_documentation_supplement/.keep b/OpenEuler(version_20.09)_documentation_supplement/.keep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git "a/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_20.09_documentation_supplement/appletalk.txt" "b/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_20.09_documentation_supplement/appletalk.txt" new file mode 100644 index 0000000000000000000000000000000000000000..4a7b2413a4df37ce5a6e495ff1792ee9e35ed0ac --- /dev/null +++ "b/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_20.09_documentation_supplement/appletalk.txt" @@ -0,0 +1,40 @@ +Kernel AppleTalk Layer Implementation Overview + +File Structure +Kernel/net/appletalk +├── Makefile +├── aarp.c +├── atalk_proc.c +├── ddp.c +├── dev.c +└── sysctl_net_atalk.c + +Makefile +obj-$(CONFIG_ATALK) += appletalk.o +appletalk-y := aarp.o ddp.o dev.o +appletalk-$(CONFIG_PROC_FS) += atalk_proc.o +appletalk-$(CONFIG_SYSCTL) += sysctl_net_atalk.o + +AARP Implementation +·The file aarp.c implements the AppleTalk Address Resolution Protocol (AARP), including neighbor discovery mechanisms, retransmission handling, Token Ring support, and more. Additionally, it supports proc filesystem integration for configuration and is released under the GPL license. +·Management of AARP entry lists, including parsing and processing AARP packets and maintaining timers for purging expired entries. +·Listening for network device events, such as removing relevant AARP entries when a device goes down. +·Providing proc filesystem interfaces for viewing AARP table entries, including entry statuses and expiration times. + +DDP Implementation +·The file ddp.c contains the implementation of the Datagram Delivery Protocol (DDP), including socket creation, initialization of socket addresses, and setting socket states. +·Provides a checksum calculation function atalk_checksum for calculating the checksum of DDP packets. +The ddp_proto structure defines basic information about the DDP protocol, such as name and owner. + +Device Interface +·The file dev.c defines the implementation of AppleTalk network device interfaces, including operations when a device comes up or goes down. +System Control +·The file sysctl_net_atalk.c provides system control interfaces, allowing users to adjust AppleTalk-related system parameters via the sysctl command. + +AARP Functionality Implementation +·Allocation and deallocation of AARP entries are managed by the functions aarp_alloc() and __aarp_expire(). +·Finding and updating AARP entries are handled by the functions __aarp_find_entry() and __aarp_expire_device(). +·A timer aarp_timer is used to periodically purge expired AARP entries, processed by the aarp_expire_timeout() function. +·When a network device's state changes, the aarp_device_event() function acts as part of the network device notification chain to update AARP tables accordingly. +·Sending AARP probe requests and handling proxy AARP network probes are performed by the functions aarp_send_probe() and aarp_proxy_probe_network(). +·Responses to AARP are sent by the aarp_send_reply() function. \ No newline at end of file diff --git "a/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_20.09_documentation_supplement/ceph.txt" "b/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_20.09_documentation_supplement/ceph.txt" new file mode 100644 index 0000000000000000000000000000000000000000..162aa071307fef2d852efccaea616ee5e365805b --- /dev/null +++ "b/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_20.09_documentation_supplement/ceph.txt" @@ -0,0 +1,153 @@ +Ceph Core Library Implementation + +Overview: Ceph is a distributed storage system, and its kernel module implements core functionalities for data storage and retrieval. + +Features: +·Provides generic functionalities such as module compatibility checks, supported feature queries, message type name conversion, etc. +·Implements internal cluster messaging mechanisms. +·Offers methods for client interactions with Object Storage Devices (OSDs). +·Manages client sessions and handles OSD request processing logic. + +General Functionality + +Module Compatibility Check +Description: The libceph_compatible function determines if libceph is compatible with the caller. +Implementation: + +bool libceph_compatible(void *data) +{ + return true; +} +EXPORT_SYMBOL(libceph_compatible); + + + +Supported Features Query +Description: The supported_features parameter allows users to query the features supported by Ceph. +Implementation: + +static int param_get_supported_features(char *buffer, + const struct kernel_param *kp) +{ + return sprintf(buffer, "0x%llx", CEPH_FEATURES_SUPPORTED_DEFAULT); +} +static const struct kernel_param_ops param_ops_supported_features = { + .get = param_get_supported_features, +}; +module_param_cb(supported_features, ¶m_ops_supported_features, NULL, 0444); + + +Message Type Name Conversion +Description: The ceph_msg_type_name function returns the message type name corresponding to a message type ID. +Implementation: +const char *ceph_msg_type_name(int type) +{ + switch (type) { + case CEPH_MSG_SHUTDOWN: return "shutdown"; + case CEPH_MSG_PING: return "ping"; + case CEPH_MSG_AUTH: return "auth"; + case CEPH_MSG_AUTH_REPLY: return "auth_reply"; + case CEPH_MSG_MON_MAP: return "mon_map"; + case CEPH_MSG_MON_GET_MAP: return "mon_get_map"; + case CEPH_MSG_MON_SUBSCRIBE: return "mon_subscribe"; + case CEPH_MSG_MON_SUBSCRIBE_ACK: return "mon_subscribe_ack"; + case CEPH_MSG_STATFS: return "statfs"; + case CEPH_MSG_STATFS_REPLY: return "statfs_reply"; + // More types... + default: return "unknown"; + } +} + + + + + +Client and OSD Interaction + +Creating a New Request +Description: The ceph_osdc_new_request function is used to create a new request. +Implementation +struct ceph_osd_request *ceph_osdc_new_request( + struct ceph_osd_client *osdc, struct ceph_file_layout *layout, + struct ceph_vino vino, u64 off, u64 *plen, unsigned int which, + int num_ops, int opcode, int flags, struct ceph_snap_context *snapc, + u32 truncate_seq, u64 truncate_size, bool use_mempool) +{ + // Logic for creating a new request + return NULL; +} + + +Initializing an OSD Request Operation +Description: The _osd_req_op_init function initializes an OSD request operation. +Implementation +void _osd_req_op_init(struct ceph_osd_request *osd_req, + unsigned int which, u16 opcode, u32 flags) +{ + // Logic for initializing an OSD request operation +} + + + +Client Session Management + +Opening a Session +Description: The ceph_open_session function is used to establish a connection between the client and Monitors (Mon) and Object Storage Devices (OSDs), and wait for the latest Monitor Map (mon map) and Object Storage Device Map (osd map). + +Implementation +int ceph_open_session(struct ceph_client *client) +{ + int ret; + unsigned long started = jiffies; /* Record the start time */ + dout("open_session start\n"); + mutex_lock(&client->mount_mutex); + ret = __ceph_open_session(client, started); + mutex_unlock(&client->mount_mutex); + return ret; +} +EXPORT_SYMBOL(ceph_open_session); + + +Connection Management + +Closing a Connection +Description: The ceph_con_close function marks the peer as unavailable and discards any open connections. +Implementation: +void ceph_con_close(struct ceph_connection *con) +{ + mutex_lock(&con->mutex); + dout("con_close %p peer %s\n", con, + ceph_pr_addr(&con->peer_addr.in_addr)); + con->state = CON_STATE_CLOSED; + con_flag_clear(con, CON_FLAG_LOSSYTX); /* So we retry the next connection */ + con_flag_clear(con, CON_FLAG_KEEPALIVE_PENDING); + con_flag_clear(con, CON_FLAG_WRITE_PENDING); + con_flag_clear(con, CON_FLAG_BACKOFF); + reset_connection(con); + con->peer_global_seq = 0; + cancel_con(con); + con_close_socket(con); + mutex_unlock(&con->mutex); +} +EXPORT_SYMBOL(ceph_con_close); + + +Reopening a Connection +Description: The ceph_con_open function is used to reopen a closed connection with a new peer address. +Implementation: +void ceph_con_open(struct ceph_connection *con, + __u8 entity_type, __u64 entity_num, + struct ceph_entity_addr *addr) +{ + mutex_lock(&con->mutex); + dout("con_open %p %s\n", con, ceph_pr_addr(&addr->in_addr)); + WARN_ON(con->state != CON_STATE_CLOSED); + con->state = CON_STATE_PREOPEN; + con->peer_name.type = (__u8) entity_type; + con->peer_name.num = cpu_to_le64(entity_num); + memcpy(&con->peer_addr, addr, sizeof(*addr)); + con->delay = 0; /* Reset backoff memory */ + mutex_unlock(&con->mutex); + queue_con(con); +} +EXPORT_SYMBOL(ceph_con_open); \ No newline at end of file diff --git "a/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_20.09_documentation_supplement/ipv4.txt" "b/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_20.09_documentation_supplement/ipv4.txt" new file mode 100644 index 0000000000000000000000000000000000000000..00600f2e3d8cd1cb3017c49ea597ad44f34c220f --- /dev/null +++ "b/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_20.09_documentation_supplement/ipv4.txt" @@ -0,0 +1,53 @@ +Available IPv4 Module Parameters + +Available IPv4 module parameters and their description: + +1. IP_MULTICAST +Description: Enables multicasting, allowing the addressing of multiple networked computers simultaneously, increasing the kernel size by approximately 2 KB. Multicasting is necessary if you intend to participate in multicast applications. For most users, it is safe to select "N". +Possible Values: +y: Enable multicasting. +n: Disable multicasting. + +2. IP_ADVANCED_ROUTER +Description: If you intend to use your Linux system primarily as a router, i.e., a device that forwards and redistributes network packets, enable this option. Enabling this option allows for more precise control over the routing process. However, selecting "N" will simply skip the questions related to advanced routing. +Possible Values: +y: Enable advanced router features. +n: Disable advanced router features. + +3. IP FORWARDING +Description: Enables IP forwarding, which is necessary for a system to act as a router. To enable IP forwarding, ensure that "/proc filesystem support" and "Sysctl support" are enabled in the kernel, and execute echo "1" > /proc/sys/net/ipv4/ip_forward after mounting the /proc filesystem during boot. +Possible Values: +1: Enable IP forwarding. +0: Disable IP forwarding. + +4. RP_FILTER +Description: When IP forwarding is enabled, consider enabling RP_FILTER, which automatically rejects incoming packets if the routing table entry for their source address does not match the network interface they arrive on. This has security advantages as it prevents IP spoofing attacks. However, it can pose issues with asymmetric routing or hosts with multiple IP addresses on different interfaces. +Possible Values: +1: Enable RP_FILTER. +0: Disable RP_FILTER. + +5. FIB TRIE STATISTICS +Description: Enables tracking of statistics for the FIB TRIE structure, which is mainly useful for testing and measuring the performance of the TRIE. +Usage: Only relevant if IP_ADVANCED_ROUTER is enabled. +Possible Values: +y: Enable FIB TRIE statistics. +n: Disable FIB TRIE statistics. + +6. IP_POLICY_ROUTING +Description: Enables policy routing, which allows for routing decisions based on different policies. +Usage: Only relevant if IP_ADVANCED_ROUTER is enabled. +Possible Values: +y: Enable policy routing. +n: Disable policy routing. + +7. TCP_CONGESTION_CONTROL +Description: Allows setting the default congestion control algorithm for TCP connections. +Usage: You can choose different congestion control algorithms such as Cubic, Bic, Htcp, Hybla, Vegas, Westwood, Veno, Reno, Dctcp, Cdg, Bbr. +Possible Values: Various congestion control algorithms. + +8. TCP_MD5SIG +Description: Enables support for TCP MD5 signature options, which are primarily used to secure BGP sessions between core routers. +Usage: If unsure, select "N". +Possible Values: +y: Enable MD5 signature support. +n: Disable MD5 signature support. diff --git "a/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_22.03-LTS-SP1_documentation_supplement/appletalk.rst" "b/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_22.03-LTS-SP1_documentation_supplement/appletalk.rst" new file mode 100644 index 0000000000000000000000000000000000000000..61961712da57b3b13281e336b89f26fa6203a8ad --- /dev/null +++ "b/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_22.03-LTS-SP1_documentation_supplement/appletalk.rst" @@ -0,0 +1,164 @@ +# SPDX-License-Identifier: GPL-2.0 + +AppleTalk Protocol Suite Implementation +======================================== + +This document describes the implementation of the AppleTalk protocol suite, including the AppleTalk Address Resolution Protocol (AARP), Datagram Delivery Protocol (DDP), device interface, and system control interfaces. + +AARP (AppleTalk Address Resolution Protocol) +-------------------------------------------- + +**Function Description** + +The ``aarp.c`` file implements the AppleTalk Address Resolution Protocol (AARP) for Ethernet networks, specifically for Ethernet Local Area Protocol (ELAP). Key functionalities include: + +- **AARP Entry Structure**: The ``aarp_entry`` structure encapsulates details about each AARP entry, such as the last transmission time (``last_sent``), a queue of packets awaiting resolution (``packet_queue``), status (``status``), expiration time (``expires_at``), target AppleTalk address (``target_addr``), associated network device (``dev``), hardware address (``hwaddr``), transmission count (``xmit_count``), and a pointer to the next entry in the chain (``next``). + +- **Hash Tables Management**: Three hash tables (``resolved``, ``unresolved``, and ``proxies``) manage entries based on their resolution status. + +- **Lock Protection**: A read-write lock (``aarp_lock``) is defined to protect the entire AARP structure from concurrent access issues. + +- **Timer**: The ``aarp_timer`` is utilized to periodically traverse the list and purge expired entries or perform other necessary operations. + +**Source Code** + +.. code-block:: c + + // AARP: An implementation of the AppleTalk AARP protocol for + // Ethernet 'ELAP'. + ... + struct aarp_entry { + /* These first two are only used for unresolved entries */ + unsigned long last_sent; + struct sk_buff_head packet_queue; + int status; + unsigned long expires_at; + struct atalk_addr target_addr; + struct net_device *dev; + char hwaddr[ETH_ALEN]; + unsigned short xmit_count; + struct aarp_entry *next; + }; + ... + static struct aarp_entry *resolved[AARP_HASH_SIZE]; + static struct aarp_entry *unresolved[AARP_HASH_SIZE]; + static struct aarp_entry *proxies[AARP_HASH_SIZE]; + static int unresolved_count; + /* One lock protects it all. */ + static DEFINE_RWLOCK(aarp_lock); + /* Used to walk the list and purge/kick entries. */ + static struct timer_list aarp_timer; + +DDP (Datagram Delivery Protocol) +-------------------------------- + +**Function Description** + +The ``ddp.c`` file implements the Datagram Delivery Protocol (DDP) for AppleTalk, which is responsible for the delivery of datagrams. Its key features include: + +- **Socket Management**: The ``atalk_sockets`` hash chain stores all AppleTalk sockets, and the ``atalk_sockets_lock`` lock ensures thread safety during insertion and removal operations. + +- **Insertion and Removal of Sockets**: Functions like ``__atalk_insert_socket`` and ``atalk_remove_socket`` are used to add or remove sockets from the list, respectively. + +- **Socket Search**: ``atalk_search_socket`` is employed to find a socket based on the specified destination address within the socket list. + +**Source Code** + +.. code-block:: c + + // DDPE: An implementation of the AppleTalk DDP protocol for + // Ethernet 'ELAP'. + ... + struct datalink_proto *ddp_dl, *aarp_dl; + static const struct proto_ops atalk_dgram_ops; + ... + static inline void __atalk_insert_socket(struct sock *sk) + { + sk_add_node(sk, &atalk_sockets); + } + static inline void atalk_remove_socket(struct sock *sk) + { + write_lock_bh(&atalk_sockets_lock); + sk_del_node_init(sk); + write_unlock_bh(&atalk_sockets_lock); + } + static struct sock *atalk_search_socket(struct sockaddr_at *to, + struct atalk_iface *atif) + { + struct sock *s; + read_lock_bh(&atalk_sockets_lock); + sk_for_each(s, &atalk_sockets) { + ... + } + } + +Device Interface +---------------- + +**Function Description** + +The ``dev.c`` file defines the implementation of the AppleTalk network device interface, particularly focusing on actions performed when a device is brought up or taken down. + +- **Initialization of LocalTalk Device**: The ``ltalk_setup`` function fills in the device structure with LocalTalk-specific values. + +- **Allocation of LocalTalk Device**: The ``alloc_ltalkdev`` function allocates memory for a LocalTalk device and calls ``ltalk_setup`` to initialize it. + +**Source Code** + +.. code-block:: c + + // Moved here from drivers/net/net_init.c, which is: + // Written 1993,1994,1995 by Donald Becker. + ... + static void ltalk_setup(struct net_device *dev) + { + /* Fill in the fields of the device structure with localtalk-generic values. */ + dev->type = ARPHRD_LOCALTLK; + dev->hard_header_len = LTALK_HLEN; + dev->mtu = LTALK_MTU; + dev->addr_len = LTALK_ALEN; + dev->tx_queue_len = 10; + dev->broadcast[0] = 0xFF; + dev->flags = IFF_BROADCAST|IFF_MULTICAST|IFF_NOARP; + } + ... + struct net_device *alloc_ltalkdev(int sizeof_priv) + { + return alloc_netdev(sizeof_priv, "lt%d", NET_NAME_UNKNOWN, + ltalk_setup); + } + +System Control +-------------- + +**Function Description** + +The ``sysctl_net_atalk.c`` file provides system control interfaces, enabling users to adjust AppleTalk-related system parameters through the ``sysctl`` command. + +- **Sysctl Table Entries**: The ``atalk_table`` array defines several kernel parameters that can be modified or queried by user-space programs, such as the AARP expiry time and tick time. + +**Source Code** + +.. code-block:: c + + // sysctl_net_atalk.c: sysctl interface to net AppleTalk subsystem. + ... + static struct ctl_table atalk_table[] = { + { + .procname = "aarp-expiry-time", + .data = &sysctl_aarp_expiry_time, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_jiffies, + }, + { + .procname = "aarp-tick-time", + .data = &sysctl_aarp_tick_time, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_jiffies, + }, + ... + } + +This document provides a structured overview of the functionalities in the AppleTalk protocol suite, detailing the AARP, DDP, device interface, and system control interfaces, along with relevant source code excerpts. \ No newline at end of file diff --git "a/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_22.03-LTS-SP1_documentation_supplement/ceph.rst" "b/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_22.03-LTS-SP1_documentation_supplement/ceph.rst" new file mode 100644 index 0000000000000000000000000000000000000000..9cdd2e2d7d7daac0f794e72fdb91f82f5afc2c44 --- /dev/null +++ "b/OpenEuler(version_20.09\357\274\21422.03-LTS-SP1)_documentation_supplement/version_22.03-LTS-SP1_documentation_supplement/ceph.rst" @@ -0,0 +1,369 @@ +# SPDX-License-Identifier: GPL-2.0 + +Ceph Code Explanation +===================== + +This document provides a detailed breakdown of the functionalities in the provided source code snippets, covering various aspects of Ceph including CRUSH algorithm, authentication mechanisms, buffer management, hash functions, messaging protocols, monitor client session management, key management, and message handling. + +CRUSH Module +------------ + +**Function Description** + +CRUSH (Controlled Replication Under Scalable Hashing) is a core algorithm in Ceph used for data distribution and redundancy strategies. The ``crush_get_bucket_item_weight`` function retrieves the weight of an item within a bucket. It calculates and returns the weight of an item within a bucket based on the bucket type (uniform, list, tree, straw, or improved straw). + + +.. code-block:: c + + /** + * crush_get_bucket_item_weight - Get weight of an item in given bucket + * @b: bucket pointer + * @p: item index in bucket + */ + int crush_get_bucket_item_weight(const struct crush_bucket *b, int p) + { + if ((__u32)p >= b->size) + return 0; + switch (b->alg) { + case CRUSH_BUCKET_UNIFORM: + return ((struct crush_bucket_uniform *)b)->item_weight; + case CRUSH_BUCKET_LIST: + return ((struct crush_bucket_list *)b)->item_weights[p]; + case CRUSH_BUCKET_TREE: + return ((struct crush_bucket_tree *)b)->node_weights[crush_calc_tree_node(p)]; + case CRUSH_BUCKET_STRAW: + return ((struct crush_bucket_straw *)b)->item_weights[p]; + case CRUSH_BUCKET_STRAW2: + return ((struct crush_bucket_straw2 *)b)->item_weights[p]; + } + return 0; + } + + void crush_destroy_bucket_uniform(struct crush_bucket_uniform *b) + { + kfree(b->h.items); + kfree(b); + } + + void crush_destroy_bucket_list(struct crush_bucket_list *b) + { + kfree(b->item_weights); + kfree(b->sum_weights); + kfree(b->h.items); + kfree(b); + } + + void crush_destroy_bucket_tree(struct crush_bucket_tree *b) + { + kfree(b->h.items); + kfree(b->node_weights); + kfree(b); + } + + void crush_destroy_bucket_straw(struct crush_bucket_straw *b) + { + kfree(b->straws); + kfree(b->item_weights); + kfree(b->h.items); + kfree(b); + } + + void crush_destroy_bucket_straw2(struct crush_bucket_straw2 *b) + { + kfree(b->item_weights); + kfree(b->h.items); + kfree(b); + } + + +Authentication Module +--------------------- + +**Function Description** + +The authentication module provides a mechanism to verify a client's identity, ensuring only authorized users can access storage resources. The ``ceph_auth_init_protocol`` function initializes a specific protocol's authentication handler. The ``ceph_auth_init`` function sets up the initial work for authenticating clients, including allocating memory and initializing mutexes. + + +.. code-block:: c + + static u32 supported_protocols[] = { + CEPH_AUTH_NONE, + CEPH_AUTH_CEPHX + }; + + static int ceph_auth_init_protocol(struct ceph_auth_client *ac, int protocol) + { + switch (protocol) { + case CEPH_AUTH_NONE: + return ceph_auth_none_init(ac); + case CEPH_AUTH_CEPHX: + return ceph_x_init(ac); + default: + return -ENOENT; + } + } + + struct ceph_auth_client *ceph_auth_init(const char *name, const struct ceph_crypto_key *key) + { + struct ceph_auth_client *ac; + int ret; + dout("auth_init name '%s'\n", name); + ret = -ENOMEM; + ac = kzalloc(sizeof(*ac), GFP_NOFS); + if (!ac) + goto out; + mutex_init(&ac->mutex); + ac->negotiating = true; + if (name) + ac->name = name; + else + ac->name = CEPH_AUTH_NAME_DEFAULT; + dout("auth_init name %s\n", ac->name); + ac->key = key; + return ac; + out: + return ERR_PTR(ret); + } + + +Buffer Management Module +------------------------ + +**Function Description** + +The buffer management module provides functions for creating, releasing, and decoding memory buffers, ensuring efficient data transmission over the network. The ``ceph_buffer_new`` function creates a new buffer, while ``ceph_buffer_release`` releases a buffer resource. + + +.. code-block:: c + + struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp) + { + struct ceph_buffer *b; + b = kmalloc(sizeof(*b), gfp); + if (!b) + return NULL; + b->vec.iov_base = ceph_kvmalloc(len, gfp); + if (!b->vec.iov_base) { + kfree(b); + return NULL; + } + kref_init(&b->kref); + b->alloc_len = len; + b->vec.iov_len = len; + dout("buffer_new %p\n", b); + return b; + } + + void ceph_buffer_release(struct kref *kref) + { + struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref); + dout("buffer_release %p\n", b); + kvfree(b->vec.iov_base); + kfree(b); + } + + +Ceph Hash Functions +------------------- + +**Function Description** + +Ceph uses hash functions to process strings, where ``ceph_str_hash`` returns the hash value of a string based on the specified hash type. + + +.. code-block:: c + + unsigned int ceph_str_hash(int type, const char *s, unsigned int len) + { + switch (type) { + case CEPH_STR_HASH_LINUX: + return ceph_str_hash_linux(s, len); + case CEPH_STR_HASH_RJENKINS: + return ceph_str_hash_rjenkins(s, len); + default: + return -1; + } + } + + const char *ceph_str_hash_name(int type) + { + switch (type) { + case CEPH_STR_HASH_LINUX: + return "linux"; + case CEPH_STR_HASH_RJENKINS: + return "rjenkins"; + default: + return "unknown"; + } + } + + +Messenger Module +---------------- + +**Function Description** + +The messaging module is responsible for sending and receiving messages between Ceph components. The ``osd_sign_message`` function is used to sign a message, while ``osd_check_message_signature`` verifies a message's signature. + + +.. code-block:: c + + static int osd_sign_message(struct ceph_msg *msg) + { + struct ceph_osd *o = msg->con->private; + struct ceph_auth_handshake *auth = &o->o_auth; + return ceph_auth_sign_message(auth, msg); + } + + static int osd_check_message_signature(struct ceph_msg *msg) + { + struct ceph_osd *o = msg->con->private; + struct ceph_auth_handshake *auth = &o->o_auth; + return ceph_auth_check_message_signature(auth, msg); + } + + +Mon Client Module +----------------- + +**Function Description** + +The Ceph monitor client maintains an active session with a monitor at all times to receive timely MDS map updates. If the connection breaks, the client will randomly search for a new monitor and resend any outstanding requests. + + +.. code-block:: c + + // Code related to maintaining an active session with the monitor + // ... + We maintain an open, active session with a monitor at all times in order to + receive timely MDSMap updates. We periodically send a keepalive byte on the + TCP socket to ensure we detect a failure. If the connection does break, we + randomly hunt for a new monitor. Once the connection is reestablished, we + resend any outstanding requests. + + +Key Management +-------------- + +**Function Description** + +The key management module handles operations such as loading, pre-parsing, and destroying keys. + + +.. code-block:: c + + static int ceph_key_preparse(struct key_preparsed_payload *prep) + { + struct ceph_crypto_key *ckey; + size_t datalen = prep->datalen; + int ret; + void *p; + ret = -EINVAL; + if (datalen <= 0 || datalen > 32767 || !prep->data) + goto err; + ret = -ENOMEM; + ckey = kmalloc(sizeof(*ckey), GFP_KERNEL); + if (!ckey) + goto err; + /* TODO ceph_crypto_key_decode should really take const input */ + p = (void *)prep->data; + ret = ceph_crypto_key_decode(ckey, &p, (char*)prep->data+datalen); + if (ret < 0) + goto err_ckey; + prep->payload.data[0] = ckey; + prep->quotalen = datalen; + return 0; + err_ckey: + kfree(ckey); + err: + return ret; + } + + static void ceph_key_free_preparse(struct key_preparsed_payload *prep) + { + struct ceph_crypto_key *ckey = prep->payload.data[0]; + ceph_crypto_key_destroy(ckey); + kfree(ckey); + } + + static void ceph_key_destroy(struct key *key) + { + struct ceph_crypto_key *ckey = key->payload.data[0]; + ceph_crypto_key_destroy(ckey); + kfree(ckey); + } + + +Message Handling +---------------- + +**Function Description** + +The message handling mechanism ensures secure message transmission, including preparing messages, reading messages, and processing messages. + + +.. code-block:: c + + static void prepare_write_message(struct ceph_connection *con) + { + struct ceph_msg *m; + u32 crc; + con_out_kvec_reset(con); + con->out_msg_done = false; + /* Sneak an ack in there first? If we can get it into the same + TCP packet that's a good thing. */ + if (con->in_seq > con->in_seq_acked) { + con->in_seq_acked = con->in_seq; + con_out_kvec_add(con, sizeof (tag_ack), &tag_ack); + con->out_temp_ack = cpu_to_le64(con->in_seq_acked); + con_out_kvec_add(con, sizeof (con->out_temp_ack), + &con->out_temp_ack); + } + BUG_ON(list_empty(&con->out_queue)); + m = list_first_entry(&con->out_queue, struct ceph_msg, list_head); + con->out_msg = m; + BUG_ON(m->con != con); + /* put message on sent list */ + ceph_msg_get(m); + list_move_tail(&m->list_head, &con->out_sent); + /* + * only assign outgoing seq # if we haven't sent this message + * yet. if it is requeued, resend with its original seq. + */ + if (m->needs_out_seq) { + m->hdr.seq = cpu_to_le64(++con->out_seq); + m->needs_out_seq = false; + if (con->ops->reencode_message) + con->ops->reencode_message(m); + } + dout("prepare_write_message %p seq %lld type %d len %d+%d+%zd\n", + m, con->out_seq, le16_to_cpu(m->hdr.type), + le32_to_cpu(m->hdr.front_len), le32_to_cpu(m->hdr.middle_len), + m->data_length); + WARN_ON(m->front.iov_len != le32_to_cpu(m->hdr.front_len)); + WARN_ON(m->data_length != le32_to_cpu(m->hdr.data_len)); + /* tag + hdr + front + middle */ + con_out_kvec_add(con, sizeof (tag_msg), &tag_msg); + con_out_kvec_add(con, sizeof(con->out_hdr), &con->out_hdr); + con_out_kvec_add(con, m->front.iov_len, m->front.iov_base); + if (m->middle) + con_out_kvec_add(con, m->middle->vec.iov_len, + m->middle->vec.iov_base); + /* fill in hdr crc and finalize hdr */ + crc = crc32c(0, &m->hdr, offsetof(struct ceph_msg_header, crc)); + con->out_msg->hdr.crc = cpu_to_le32(crc); + memcpy(&con->out_hdr, &con->out_msg->hdr, sizeof(con->out_hdr)); + /* fill in front and middle crc, footer */ + crc = crc32c(0, m->front.iov_base, m->front.iov_len); + con->out_msg->footer.front_crc = cpu_to_le32(crc); + if (m->middle) { + crc = crc32c(0, m->middle->vec.iov_base, + m->middle->vec.iov_len); + con->out_msg->footer.middle_crc = cpu_to_le32(crc); + } else + con->out_msg->footer.middle_crc = 0; + dout("%s front_crc %u middle_crc %u\n", __func__, + le32_to_cpu(con->out_msg->footer.front_crc), + le32_to_cpu(con->out_msg->footer.middle_crc)); + con->out_msg->footer.flags = 0; + } \ No newline at end of file