📄 lustre_lib.h
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com> * * This file is part of Lustre, http://www.lustre.org. * * Lustre is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. * * Lustre is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Lustre; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Basic Lustre library routines. * */#ifndef _LUSTRE_LIB_H#define _LUSTRE_LIB_H#include <libcfs/kp30.h>#include <lustre/lustre_idl.h>#include <lustre_ver.h>#include <lustre_cfg.h>#if defined(__linux__)#include <linux/lustre_lib.h>#elif defined(__APPLE__)#include <darwin/lustre_lib.h>#elif defined(__WINNT__)#include <winnt/lustre_lib.h>#else#error Unsupported operating system.#endif/* prng.c */unsigned int ll_rand(void); /* returns a random 32-bit integer */void ll_srand(unsigned int, unsigned int); /* seed the generator */void ll_get_random_bytes(void *buf, int size);/* target.c */struct ptlrpc_request;struct recovd_data;struct recovd_obd;struct obd_export;#include <lustre_ha.h>#include <lustre_net.h>#include <lvfs.h>void target_client_add_cb(struct obd_device *obd, __u64 transno, void *cb_data, int error);int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler);int target_handle_disconnect(struct ptlrpc_request *req);void target_destroy_export(struct obd_export *exp);int target_handle_reconnect(struct lustre_handle *conn, struct obd_export *exp, struct obd_uuid *cluuid);int target_handle_ping(struct ptlrpc_request *req);int target_pack_pool_reply(struct ptlrpc_request *req);void target_committed_to_req(struct ptlrpc_request *req);#ifdef HAVE_QUOTA_SUPPORT/* quotacheck callback, dqacq/dqrel callback handler */int target_handle_qc_callback(struct ptlrpc_request *req);int target_handle_dqacq_callback(struct ptlrpc_request *req);#else#define target_handle_dqacq_callback(req) ldlm_callback_reply(req, -ENOTSUPP)#define target_handle_qc_callback(req) (0)#endifvoid target_cancel_recovery_timer(struct obd_device *obd);void target_abort_recovery(void *data);void target_cleanup_recovery(struct obd_device *obd);int target_queue_recovery_request(struct ptlrpc_request *req, struct obd_device *obd);int target_queue_last_replay_reply(struct ptlrpc_request *req, int rc);void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id);/* client.c */int client_sanobd_setup(struct obd_device *obddev, obd_count len, void *buf);struct client_obd *client_conn2cli(struct lustre_handle *conn);struct mdc_open_data;struct obd_client_handle { struct lustre_handle och_fh; struct llog_cookie och_cookie; struct mdc_open_data *och_mod; __u32 och_magic;};#define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed/* statfs_pack.c */void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);/* l_lock.c */struct lustre_lock { int l_depth; cfs_task_t *l_owner; struct semaphore l_sem; spinlock_t l_spin;};void l_lock_init(struct lustre_lock *);void l_lock(struct lustre_lock *);void l_unlock(struct lustre_lock *);int l_has_lock(struct lustre_lock *);/* * OBD IOCTLS */#define OBD_IOCTL_VERSION 0x00010004struct obd_ioctl_data { __u32 ioc_len; __u32 ioc_version; __u64 ioc_cookie; __u32 ioc_conn1; __u32 ioc_conn2; struct obdo ioc_obdo1; struct obdo ioc_obdo2; obd_size ioc_count; obd_off ioc_offset; __u32 ioc_dev; __u32 ioc_command; __u64 ioc_nid; __u32 ioc_nal; __u32 ioc_type; /* buffers the kernel will treat as user pointers */ __u32 ioc_plen1; char *ioc_pbuf1; __u32 ioc_plen2; char *ioc_pbuf2; /* inline buffers for various arguments */ __u32 ioc_inllen1; char *ioc_inlbuf1; __u32 ioc_inllen2; char *ioc_inlbuf2; __u32 ioc_inllen3; char *ioc_inlbuf3; __u32 ioc_inllen4; char *ioc_inlbuf4; char ioc_bulk[0];};struct obd_ioctl_hdr { __u32 ioc_len; __u32 ioc_version;};static inline int obd_ioctl_packlen(struct obd_ioctl_data *data){ int len = size_round(sizeof(struct obd_ioctl_data)); len += size_round(data->ioc_inllen1); len += size_round(data->ioc_inllen2); len += size_round(data->ioc_inllen3); len += size_round(data->ioc_inllen4); return len;}static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data){ if (data->ioc_len > (1<<30)) { CERROR("OBD ioctl: ioc_len larger than 1<<30\n"); return 1; } if (data->ioc_inllen1 > (1<<30)) { CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n"); return 1; } if (data->ioc_inllen2 > (1<<30)) { CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n"); return 1; } if (data->ioc_inllen3 > (1<<30)) { CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n"); return 1; } if (data->ioc_inllen4 > (1<<30)) { CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n"); return 1; } if (data->ioc_inlbuf1 && !data->ioc_inllen1) { CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n"); return 1; } if (data->ioc_inlbuf2 && !data->ioc_inllen2) { CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n"); return 1; } if (data->ioc_inlbuf3 && !data->ioc_inllen3) { CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n"); return 1; } if (data->ioc_inlbuf4 && !data->ioc_inllen4) { CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n"); return 1; } if (data->ioc_pbuf1 && !data->ioc_plen1) { CERROR("OBD ioctl: pbuf1 pointer but 0 length\n"); return 1; } if (data->ioc_pbuf2 && !data->ioc_plen2) { CERROR("OBD ioctl: pbuf2 pointer but 0 length\n"); return 1; } if (data->ioc_plen1 && !data->ioc_pbuf1) { CERROR("OBD ioctl: plen1 set but NULL pointer\n"); return 1; } if (data->ioc_plen2 && !data->ioc_pbuf2) { CERROR("OBD ioctl: plen2 set but NULL pointer\n"); return 1; } if (obd_ioctl_packlen(data) > data->ioc_len) { CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n", obd_ioctl_packlen(data), data->ioc_len); return 1; } return 0;}#ifndef __KERNEL__static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max){ char *ptr; struct obd_ioctl_data *overlay; data->ioc_len = obd_ioctl_packlen(data); data->ioc_version = OBD_IOCTL_VERSION; if (*pbuf && data->ioc_len > max) return -EINVAL; if (*pbuf == NULL) { *pbuf = malloc(data->ioc_len); } if (!*pbuf) return -ENOMEM; overlay = (struct obd_ioctl_data *)*pbuf; memcpy(*pbuf, data, sizeof(*data));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -