router_proc.c

来自「lustre 1.6.5 source code」· C语言 代码 · 共 1,096 行 · 第 1/2 页

C
1,096
字号
        lnet_peer_seq_iterator_t *lpsi;        int                        rc;        LIBCFS_ALLOC(lpsi, sizeof(*lpsi));        if (lpsi == NULL)                return NULL;        lpsi->lpsi_idx = 0;        lpsi->lpsi_peer = NULL;        rc = lnet_peer_seq_seek(lpsi, *pos);        if (rc == 0)                return lpsi;        LIBCFS_FREE(lpsi, sizeof(*lpsi));        return NULL;}static voidlnet_peer_seq_stop (struct seq_file *s, void *iter){        lnet_peer_seq_iterator_t  *lpsi = iter;        if (lpsi != NULL)                LIBCFS_FREE(lpsi, sizeof(*lpsi));}static void *lnet_peer_seq_next (struct seq_file *s, void *iter, loff_t *pos){        lnet_peer_seq_iterator_t *lpsi = iter;        int                       rc;        loff_t                    next = *pos + 1;        rc = lnet_peer_seq_seek(lpsi, next);        if (rc != 0) {                LIBCFS_FREE(lpsi, sizeof(*lpsi));                return NULL;        }        *pos = next;        return lpsi;}static intlnet_peer_seq_show (struct seq_file *s, void *iter){        lnet_peer_seq_iterator_t *lpsi = iter;        lnet_peer_t              *lp;        lnet_nid_t                nid;        int                       maxcr;        int                       mintxcr;        int                       txcr;        int                       minrtrcr;        int                       rtrcr;        int                       alive;        int                       rtr;        int                       txqnob;        int                       nrefs;        if (lpsi->lpsi_off == 0) {                seq_printf(s, "%-24s %4s %5s %5s %5s %5s %5s %5s %s\n",                           "nid", "refs", "state", "max",                           "rtr", "min", "tx", "min", "queue");                return 0;        }        LASSERT (lpsi->lpsi_peer != NULL);        LNET_LOCK();        if (lpsi->lpsi_version != the_lnet.ln_peertable_version) {                LNET_UNLOCK();                return -ESTALE;        }        lp = lpsi->lpsi_peer;        nid      = lp->lp_nid;        maxcr    = lp->lp_ni->ni_peertxcredits;        txcr     = lp->lp_txcredits;        mintxcr  = lp->lp_mintxcredits;        rtrcr    = lp->lp_rtrcredits;        minrtrcr = lp->lp_minrtrcredits;        rtr      = lnet_isrouter(lp);        alive    = lp->lp_alive;        txqnob   = lp->lp_txqnob;        nrefs    = lp->lp_refcount;        LNET_UNLOCK();        seq_printf(s, "%-24s %4d %5s %5d %5d %5d %5d %5d %d\n",                   libcfs_nid2str(nid), nrefs,                    !rtr ? "~rtr" : (alive ? "up" : "down"),                   maxcr, rtrcr, minrtrcr, txcr, mintxcr, txqnob);        return 0;}static struct seq_operations lnet_peer_sops = {        .start = lnet_peer_seq_start,        .stop  = lnet_peer_seq_stop,        .next  = lnet_peer_seq_next,        .show  = lnet_peer_seq_show,};static intlnet_peer_seq_open(struct inode *inode, struct file *file){        struct proc_dir_entry *dp = PDE(inode);        struct seq_file       *sf;        int                    rc;        rc = seq_open(file, &lnet_peer_sops);        if (rc == 0) {                sf = file->private_data;                sf->private = dp->data;        }        return rc;}static struct file_operations lnet_peer_fops = {        .owner   = THIS_MODULE,        .open    = lnet_peer_seq_open,        .read    = seq_read,        .llseek  = seq_lseek,        .release = seq_release,};typedef struct {        int                  lbsi_idx;        loff_t               lbsi_off;} lnet_buffer_seq_iterator_t;intlnet_buffer_seq_seek (lnet_buffer_seq_iterator_t *lbsi, loff_t off){        int                idx;        loff_t             here;        int                rc;        if (off == 0) {                lbsi->lbsi_idx = -1;                lbsi->lbsi_off = 0;                return 0;        }        LNET_LOCK();        if (lbsi->lbsi_idx < 0 ||            lbsi->lbsi_off > off) {                /* search from start */                idx = 0;                here = 1;        } else {                /* continue search */                idx = lbsi->lbsi_idx;                here = lbsi->lbsi_off;        }        lbsi->lbsi_off     = off;        while (idx < LNET_NRBPOOLS) {                if (here == off) {                        lbsi->lbsi_idx = idx;                        rc = 0;                        goto out;                }                here++;                idx++;        }        lbsi->lbsi_idx  = -1;        rc              = -ENOENT; out:        LNET_UNLOCK();        return rc;}static void *lnet_buffer_seq_start (struct seq_file *s, loff_t *pos){        lnet_buffer_seq_iterator_t *lbsi;        int                        rc;        LIBCFS_ALLOC(lbsi, sizeof(*lbsi));        if (lbsi == NULL)                return NULL;        lbsi->lbsi_idx = -1;        rc = lnet_buffer_seq_seek(lbsi, *pos);        if (rc == 0)                return lbsi;        LIBCFS_FREE(lbsi, sizeof(*lbsi));        return NULL;}static voidlnet_buffer_seq_stop (struct seq_file *s, void *iter){        lnet_buffer_seq_iterator_t  *lbsi = iter;        if (lbsi != NULL)                LIBCFS_FREE(lbsi, sizeof(*lbsi));}static void *lnet_buffer_seq_next (struct seq_file *s, void *iter, loff_t *pos){        lnet_buffer_seq_iterator_t *lbsi = iter;        int                         rc;        loff_t                      next = *pos + 1;        rc = lnet_buffer_seq_seek(lbsi, next);        if (rc != 0) {                LIBCFS_FREE(lbsi, sizeof(*lbsi));                return NULL;        }        *pos = next;        return lbsi;}static intlnet_buffer_seq_show (struct seq_file *s, void *iter){        lnet_buffer_seq_iterator_t *lbsi = iter;        lnet_rtrbufpool_t          *rbp;        int                         npages;        int                         nbuf;        int                         cr;        int                         mincr;        if (lbsi->lbsi_off == 0) {                seq_printf(s, "%5s %5s %7s %7s\n",                           "pages", "count", "credits", "min");                return 0;        }        LASSERT (lbsi->lbsi_idx >= 0 && lbsi->lbsi_idx < LNET_NRBPOOLS);        LNET_LOCK();        rbp = &the_lnet.ln_rtrpools[lbsi->lbsi_idx];        npages = rbp->rbp_npages;        nbuf   = rbp->rbp_nbuffers;        cr     = rbp->rbp_credits;        mincr  = rbp->rbp_mincredits;        LNET_UNLOCK();        seq_printf(s, "%5d %5d %7d %7d\n",                   npages, nbuf, cr, mincr);        return 0;}static struct seq_operations lnet_buffer_sops = {        .start = lnet_buffer_seq_start,        .stop  = lnet_buffer_seq_stop,        .next  = lnet_buffer_seq_next,        .show  = lnet_buffer_seq_show,};static intlnet_buffer_seq_open(struct inode *inode, struct file *file){        struct proc_dir_entry *dp = PDE(inode);        struct seq_file       *sf;        int                    rc;        rc = seq_open(file, &lnet_buffer_sops);        if (rc == 0) {                sf = file->private_data;                sf->private = dp->data;        }        return rc;}static struct file_operations lnet_buffers_fops = {        .owner   = THIS_MODULE,        .open    = lnet_buffer_seq_open,        .read    = seq_read,        .llseek  = seq_lseek,        .release = seq_release,};typedef struct {        lnet_ni_t           *lnsi_ni;        loff_t               lnsi_off;} lnet_ni_seq_iterator_t;intlnet_ni_seq_seek (lnet_ni_seq_iterator_t *lnsi, loff_t off){        struct list_head  *n;        loff_t             here;        int                rc;        if (off == 0) {                lnsi->lnsi_ni = NULL;                lnsi->lnsi_off = 0;                return 0;        }        LNET_LOCK();        if (lnsi->lnsi_ni == NULL ||            lnsi->lnsi_off > off) {                /* search from start */                n = NULL;                here = 1;        } else {                /* continue search */                n = &lnsi->lnsi_ni->ni_list;                here = lnsi->lnsi_off;        }        lnsi->lnsi_off = off;        if (n == NULL)                n = the_lnet.ln_nis.next;        while (n != &the_lnet.ln_nis) {                if (here == off) {                        lnsi->lnsi_ni = list_entry(n, lnet_ni_t, ni_list);                        rc = 0;                        goto out;                }                here++;                n = n->next;        }        lnsi->lnsi_ni  = NULL;        rc             = -ENOENT; out:        LNET_UNLOCK();        return rc;}static void *lnet_ni_seq_start (struct seq_file *s, loff_t *pos){        lnet_ni_seq_iterator_t *lnsi;        int                     rc;        LIBCFS_ALLOC(lnsi, sizeof(*lnsi));        if (lnsi == NULL)                return NULL;        lnsi->lnsi_ni = NULL;        rc = lnet_ni_seq_seek(lnsi, *pos);        if (rc == 0)                return lnsi;        LIBCFS_FREE(lnsi, sizeof(*lnsi));        return NULL;}static voidlnet_ni_seq_stop (struct seq_file *s, void *iter){        lnet_ni_seq_iterator_t  *lnsi = iter;        if (lnsi != NULL)                LIBCFS_FREE(lnsi, sizeof(*lnsi));}static void *lnet_ni_seq_next (struct seq_file *s, void *iter, loff_t *pos){        lnet_ni_seq_iterator_t *lnsi = iter;        int                     rc;        loff_t                  next = *pos + 1;        rc = lnet_ni_seq_seek(lnsi, next);        if (rc != 0) {                LIBCFS_FREE(lnsi, sizeof(*lnsi));                return NULL;        }        *pos = next;        return lnsi;}static intlnet_ni_seq_show (struct seq_file *s, void *iter){        lnet_ni_seq_iterator_t *lnsi = iter;        lnet_ni_t              *ni;        int                     maxtxcr;        int                     txcr;        int                     mintxcr;        int                     npeertxcr;        lnet_nid_t              nid;        int                     nref;        if (lnsi->lnsi_off == 0) {                seq_printf(s, "%-24s %4s %4s %5s %5s %5s\n",                           "nid", "refs", "peer", "max", "tx", "min");                return 0;        }        LASSERT (lnsi->lnsi_ni != NULL);        LNET_LOCK();        ni = lnsi->lnsi_ni;        maxtxcr   = ni->ni_maxtxcredits;        txcr      = ni->ni_txcredits;        mintxcr   = ni->ni_mintxcredits;        npeertxcr = ni->ni_peertxcredits;        nid       = ni->ni_nid;        nref      = ni->ni_refcount;        LNET_UNLOCK();        seq_printf(s, "%-24s %4d %4d %5d %5d %5d\n",                   libcfs_nid2str(nid), nref,                   npeertxcr, maxtxcr, txcr, mintxcr);        return 0;}static struct seq_operations lnet_ni_sops = {        .start = lnet_ni_seq_start,        .stop  = lnet_ni_seq_stop,        .next  = lnet_ni_seq_next,        .show  = lnet_ni_seq_show,};static intlnet_ni_seq_open(struct inode *inode, struct file *file){        struct proc_dir_entry *dp = PDE(inode);        struct seq_file       *sf;        int                    rc;        rc = seq_open(file, &lnet_ni_sops);        if (rc == 0) {                sf = file->private_data;                sf->private = dp->data;        }        return rc;}static struct file_operations lnet_ni_fops = {        .owner   = THIS_MODULE,        .open    = lnet_ni_seq_open,        .read    = seq_read,        .llseek  = seq_lseek,        .release = seq_release,};voidlnet_proc_init(void){        struct proc_dir_entry *pde;        /* Initialize LNET_PROC_STATS */        pde = create_proc_entry (LNET_PROC_STATS, 0644, NULL);        if (pde == NULL) {                CERROR("couldn't create proc entry %s\n", LNET_PROC_STATS);                return;        }        pde->data = NULL;        pde->read_proc = lnet_router_proc_stats_read;        pde->write_proc = lnet_router_proc_stats_write;        /* Initialize LNET_PROC_ROUTES */        pde = create_proc_entry (LNET_PROC_ROUTES, 0444, NULL);        if (pde == NULL) {                CERROR("couldn't create proc entry %s\n", LNET_PROC_ROUTES);                return;        }        pde->proc_fops = &lnet_routes_fops;        pde->data = NULL;        /* Initialize LNET_PROC_ROUTERS */        pde = create_proc_entry (LNET_PROC_ROUTERS, 0444, NULL);        if (pde == NULL) {                CERROR("couldn't create proc entry %s\n", LNET_PROC_ROUTERS);                return;        }        pde->proc_fops = &lnet_routers_fops;        pde->data = NULL;        /* Initialize LNET_PROC_PEERS */        pde = create_proc_entry (LNET_PROC_PEERS, 0444, NULL);        if (pde == NULL) {                CERROR("couldn't create proc entry %s\n", LNET_PROC_PEERS);                return;        }        pde->proc_fops = &lnet_peer_fops;        pde->data = NULL;        /* Initialize LNET_PROC_BUFFERS */        pde = create_proc_entry (LNET_PROC_BUFFERS, 0444, NULL);        if (pde == NULL) {                CERROR("couldn't create proc entry %s\n", LNET_PROC_BUFFERS);                return;        }        pde->proc_fops = &lnet_buffers_fops;        pde->data = NULL;        /* Initialize LNET_PROC_NIS */        pde = create_proc_entry (LNET_PROC_NIS, 0444, NULL);        if (pde == NULL) {                CERROR("couldn't create proc entry %s\n", LNET_PROC_NIS);                return;        }        pde->proc_fops = &lnet_ni_fops;        pde->data = NULL;}voidlnet_proc_fini(void){        remove_proc_entry(LNET_PROC_STATS, 0);        remove_proc_entry(LNET_PROC_ROUTES, 0);        remove_proc_entry(LNET_PROC_ROUTERS, 0);        remove_proc_entry(LNET_PROC_PEERS, 0);        remove_proc_entry(LNET_PROC_BUFFERS, 0);        remove_proc_entry(LNET_PROC_NIS, 0);}#elsevoidlnet_proc_init(void){}voidlnet_proc_fini(void){}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?