~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to lib/clplumbing/ocf_ipc.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2010-02-17 21:59:18 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100217215918-06paxph5do4saw8v
Tags: 3.0.2-0ubuntu1
* New upstream release
* Drop hard dep on pacemaker for heartbet; moved to Recommends
* debian/heartbeat.install:
  - follow upstream changes
* debian/control:
  - added docbook-xsl and xsltproc to build depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *
3
 
 * ocf_ipc.c: IPC abstraction implementation.
4
 
 *
5
 
 *
6
 
 * Copyright (c) 2002 Xiaoxiang Liu <xiliu@ncsa.uiuc.edu>
7
 
 *
8
 
 * This library is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU Lesser General Public
10
 
 * License as published by the Free Software Foundation; either
11
 
 * version 2.1 of the License, or (at your option) any later version.
12
 
 * 
13
 
 * This library is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 * Lesser General Public License for more details.
17
 
 * 
18
 
 * You should have received a copy of the GNU Lesser General Public
19
 
 * License along with this library; if not, write to the Free Software
20
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
 
 *
22
 
 */
23
 
#include <lha_internal.h>
24
 
#include <clplumbing/ipc.h>
25
 
#include <stdio.h>
26
 
#include <stdlib.h>
27
 
#include <string.h>
28
 
#include <sys/poll.h>
29
 
#include <clplumbing/cl_log.h>
30
 
#include <sys/types.h>
31
 
#include <unistd.h>
32
 
#include <ctype.h>
33
 
#include <pwd.h>
34
 
#include <grp.h>
35
 
 
36
 
static int num_pool_allocated = 0;
37
 
static int num_pool_freed = 0;
38
 
 
39
 
#ifdef IPC_TIME_DEBUG
40
 
struct ha_msg;
41
 
void cl_log_message (int log_level, const struct ha_msg *m);
42
 
int  timediff(longclock_t t1, longclock_t t2);
43
 
void   ha_msg_del(struct ha_msg* msg);
44
 
void    ipc_time_debug(IPC_Channel* ch, IPC_Message* ipcmsg, int whichpos);
45
 
 
46
 
#endif
47
 
 
48
 
struct IPC_WAIT_CONNECTION * socket_wait_conn_new(GHashTable* ch_attrs);
49
 
struct IPC_CHANNEL * socket_client_channel_new(GHashTable* ch_attrs);
50
 
 
51
 
int (*ipc_pollfunc_ptr)(struct pollfd*, unsigned int, int)
52
 
=       (int (*)(struct pollfd*, unsigned int, int)) poll;
53
 
 
54
 
/* Set the IPC poll function to the given function */
55
 
void
56
 
ipc_set_pollfunc(int (*pf)(struct pollfd*, unsigned int, int))
57
 
{
58
 
        ipc_pollfunc_ptr = pf;
59
 
}
60
 
 
61
 
struct IPC_WAIT_CONNECTION * 
62
 
ipc_wait_conn_constructor(const char * ch_type, GHashTable* ch_attrs)
63
 
{
64
 
  if (strcmp(ch_type, "domain_socket") == 0
65
 
  ||    strcmp(ch_type, IPC_ANYTYPE) == 0
66
 
  ||    strcmp(ch_type, IPC_DOMAIN_SOCKET) == 0) {
67
 
    return socket_wait_conn_new(ch_attrs);
68
 
  }
69
 
  return NULL;
70
 
}
71
 
 
72
 
struct IPC_CHANNEL * 
73
 
ipc_channel_constructor(const char * ch_type, GHashTable* ch_attrs)
74
 
{
75
 
  if    (strcmp(ch_type, "domain_socket") == 0
76
 
  ||    strcmp(ch_type, IPC_ANYTYPE) == 0
77
 
  ||    strcmp(ch_type, IPC_DOMAIN_SOCKET) == 0) {
78
 
 
79
 
        return socket_client_channel_new(ch_attrs);
80
 
  }
81
 
  return NULL;
82
 
}
83
 
static int
84
 
gnametonum(const char * gname, int gnlen)
85
 
{
86
 
        char    grpname[64];
87
 
        struct group*   grp;
88
 
 
89
 
        if (isdigit((int) gname[0])) {
90
 
                return atoi(gname);
91
 
        }
92
 
        if (gnlen >= (int)sizeof(grpname)) {
93
 
                return -1;
94
 
        }
95
 
        strncpy(grpname, gname, gnlen);
96
 
        grpname[gnlen] = EOS;
97
 
        if ((grp = getgrnam(grpname)) == NULL) {
98
 
                cl_log(LOG_ERR 
99
 
                ,       "Invalid group name [%s]", grpname);
100
 
                return -1;
101
 
        }
102
 
        return (int)grp->gr_gid;
103
 
}
104
 
 
105
 
static int
106
 
unametonum(const char * lname, int llen)
107
 
{
108
 
        char    loginname[64];
109
 
        struct passwd*  pwd;
110
 
 
111
 
        if (llen >= (int)sizeof(loginname)) {
112
 
                cl_log(LOG_ERR 
113
 
                ,       "user id name [%s] is too long", loginname);
114
 
                return -1;
115
 
        }
116
 
        strncpy(loginname, lname, llen);
117
 
        loginname[llen] = EOS;
118
 
 
119
 
        if (isdigit((int) loginname[0])) {
120
 
                return atoi(loginname);
121
 
        }
122
 
        if ((pwd = getpwnam(loginname)) == NULL) {
123
 
                cl_log(LOG_ERR 
124
 
                ,       "Invalid user id name [%s]", loginname);
125
 
                return -1;
126
 
        }
127
 
        return (int)pwd->pw_uid;
128
 
}
129
 
 
130
 
static GHashTable*
131
 
make_id_table(const char * list, int listlen, int (*map)(const char *, int))
132
 
{
133
 
        GHashTable*     ret;
134
 
        const char *    id;
135
 
        const char *    lastid = list + listlen;
136
 
        int             idlen;
137
 
        int             idval;
138
 
        static int      one = 1;
139
 
 
140
 
        ret = g_hash_table_new(g_direct_hash, g_direct_equal);
141
 
 
142
 
        id = list;
143
 
        while (id < lastid && *id != EOS) {
144
 
                idlen = strcspn(id, ",");
145
 
                if (id+idlen >= lastid) {
146
 
                        idlen = (lastid - id);
147
 
                }
148
 
                idval = map(id, idlen);
149
 
                if (idval < 0) {
150
 
                        g_hash_table_destroy(ret);
151
 
                        return NULL;
152
 
                }
153
 
#if 0
154
 
                cl_log(LOG_DEBUG
155
 
                ,       "Adding [ug]id %*s [%d] to authorization g_hash_table"
156
 
                ,       idlen, id, idval);
157
 
#endif
158
 
                g_hash_table_insert(ret, GUINT_TO_POINTER(idval), &one);
159
 
                id += idlen;
160
 
                if (id < lastid) {
161
 
                        id += strspn(id, ",");
162
 
                }
163
 
        }
164
 
        return ret;
165
 
}
166
 
 
167
 
 
168
 
 
169
 
struct IPC_AUTH*
170
 
ipc_str_to_auth(const char* uidlist, int uidlen, const char* gidlist, int gidlen)
171
 
{
172
 
        struct IPC_AUTH* auth;
173
 
        
174
 
        auth = malloc(sizeof(struct IPC_AUTH));
175
 
        if (auth == NULL) {
176
 
                cl_log(LOG_ERR, "Out of memory for IPC_AUTH");
177
 
                return NULL;
178
 
        }
179
 
        
180
 
        memset(auth, 0, sizeof(*auth));
181
 
        
182
 
        if (uidlist) {
183
 
                auth->uid = make_id_table(uidlist, uidlen, unametonum);
184
 
                if (auth->uid == NULL) {
185
 
                        cl_log(LOG_ERR,
186
 
                               "Bad uid list [%*s]",
187
 
                               uidlen, uidlist);
188
 
                        goto errout;
189
 
                }
190
 
        }
191
 
        if (gidlist) {
192
 
                auth->gid = make_id_table(gidlist, gidlen, gnametonum);
193
 
                if (auth->gid == NULL) {
194
 
                        cl_log(LOG_ERR ,
195
 
                               "Bad gid list [%*s]",
196
 
                               gidlen, gidlist);
197
 
                        goto errout;
198
 
                }
199
 
        }
200
 
        
201
 
        
202
 
        return auth;
203
 
        
204
 
 errout:
205
 
        if (auth->uid){
206
 
                g_hash_table_destroy(auth->uid);
207
 
                auth->uid = NULL;       
208
 
        }
209
 
        
210
 
        if (auth->gid){
211
 
                g_hash_table_destroy(auth->gid);
212
 
                auth->gid = NULL;               
213
 
        }
214
 
        
215
 
        free(auth);
216
 
        auth = NULL;
217
 
        return NULL;
218
 
        
219
 
}
220
 
 
221
 
struct IPC_AUTH * 
222
 
ipc_set_auth(uid_t * a_uid, gid_t * a_gid, int num_uid, int num_gid)
223
 
{
224
 
  struct IPC_AUTH *temp_auth;
225
 
  int i;
226
 
  static int v = 1;
227
 
 
228
 
  temp_auth = malloc(sizeof(struct IPC_AUTH));
229
 
  if (temp_auth == NULL){
230
 
          cl_log(LOG_ERR, "%s: memory allocation failed",__FUNCTION__);
231
 
          return NULL;
232
 
  }
233
 
  temp_auth->uid = g_hash_table_new(g_direct_hash, g_direct_equal);
234
 
  temp_auth->gid = g_hash_table_new(g_direct_hash, g_direct_equal);
235
 
 
236
 
  if (num_uid > 0) {
237
 
    for (i=0; i<num_uid; i++) {
238
 
      g_hash_table_insert(temp_auth->uid, GINT_TO_POINTER((gint)a_uid[i])
239
 
      ,         &v);
240
 
    }
241
 
  }
242
 
 
243
 
  if (num_gid > 0) {
244
 
    for (i=0; i<num_gid; i++) {
245
 
      g_hash_table_insert(temp_auth->gid, GINT_TO_POINTER((gint)a_gid[i])
246
 
      ,         &v);
247
 
    }
248
 
  }
249
 
 
250
 
  return temp_auth;
251
 
}
252
 
 
253
 
void
254
 
ipc_destroy_auth(struct IPC_AUTH *auth)
255
 
{
256
 
        if (auth != NULL) {
257
 
                if (auth->uid) {
258
 
                        g_hash_table_destroy(auth->uid);
259
 
                }
260
 
                if (auth->gid) {
261
 
                        g_hash_table_destroy(auth->gid);
262
 
                }
263
 
                free((void *)auth);
264
 
        }
265
 
}
266
 
 
267
 
static void 
268
 
ipc_bufpool_display(struct ipc_bufpool* pool)
269
 
{
270
 
        
271
 
        if (pool == NULL){
272
 
                cl_log(LOG_ERR, "pool is NULL");                
273
 
                return;
274
 
        }
275
 
 
276
 
 
277
 
        cl_log(LOG_INFO, "pool: refcount=%d, startpos=%p, currpos=%p,"
278
 
               "consumepos=%p, endpos=%p, size=%d", 
279
 
               pool->refcount,
280
 
               pool->startpos,
281
 
               pool->currpos,
282
 
               pool->consumepos,
283
 
               pool->endpos,
284
 
               pool->size);
285
 
}
286
 
 
287
 
void ipc_bufpool_dump_stats(void);
288
 
void
289
 
ipc_bufpool_dump_stats(void)
290
 
{
291
 
        cl_log(LOG_INFO, "num_pool_allocated=%d, num_pool_freed=%d, diff=%d", 
292
 
               num_pool_allocated, 
293
 
               num_pool_freed, 
294
 
               num_pool_allocated - num_pool_freed);
295
 
        return;
296
 
               
297
 
}
298
 
 
299
 
struct ipc_bufpool*
300
 
ipc_bufpool_new(int size)
301
 
{
302
 
        struct ipc_bufpool* pool;
303
 
        int     totalsize;
304
 
        
305
 
        
306
 
        /* there are memories for two struct SOCKET_MSG_HEAD
307
 
         * one for the big message, the other one for the next
308
 
         * message. This code prevents allocating 
309
 
         *      <big memory> <4k> <big memory><4k> ... 
310
 
         * from happening when a client sends big messages
311
 
         * constantly*/
312
 
 
313
 
        totalsize = size + sizeof(struct ipc_bufpool) 
314
 
                + sizeof(struct SOCKET_MSG_HEAD) * 2 ;          
315
 
        
316
 
        if (totalsize < POOL_SIZE){
317
 
                totalsize = POOL_SIZE;
318
 
        }
319
 
        
320
 
        if (totalsize > MAXMSG){
321
 
                cl_log(LOG_INFO, "ipc_bufpool_new: "
322
 
                       "asking for buffer with size %d"
323
 
                       "corrupted data len???", totalsize);
324
 
                return NULL;
325
 
        }
326
 
        
327
 
        pool = (struct ipc_bufpool*)malloc(totalsize+1);
328
 
        if (pool == NULL){
329
 
                cl_log(LOG_ERR, "%s: memory allocation failed", __FUNCTION__);
330
 
                return NULL;
331
 
        }
332
 
        memset(pool, 0, totalsize);
333
 
        pool->refcount = 1;
334
 
        pool->startpos = pool->currpos = pool->consumepos =
335
 
                ((char*)pool) + sizeof(struct ipc_bufpool); 
336
 
        
337
 
        pool->endpos = ((char*)pool)  + totalsize;
338
 
        pool->size = totalsize;
339
 
        
340
 
        num_pool_allocated ++ ;
341
 
        
342
 
        return pool;
343
 
}
344
 
 
345
 
void
346
 
ipc_bufpool_del(struct ipc_bufpool* pool)
347
 
{
348
 
        
349
 
        if (pool == NULL){
350
 
                return;
351
 
        }
352
 
        
353
 
        if (pool->refcount > 0){
354
 
                cl_log(LOG_ERR," ipc_bufpool_del:"
355
 
                       " IPC buffer pool reference count"
356
 
                       " > 0");
357
 
                return;
358
 
        }
359
 
        
360
 
        memset(pool, 0, pool->size);
361
 
        free(pool);     
362
 
        num_pool_freed ++ ;
363
 
        return;
364
 
}
365
 
 
366
 
int
367
 
ipc_bufpool_spaceleft(struct ipc_bufpool* pool)
368
 
{
369
 
 
370
 
        if( pool == NULL){
371
 
                cl_log(LOG_ERR, "ipc_bufpool_spacelft:"
372
 
                       "invalid input argument");
373
 
                return 0;               
374
 
        }
375
 
        
376
 
        return pool->endpos - pool->currpos;
377
 
}
378
 
 
379
 
 
380
 
 
381
 
 
382
 
/* brief free the memory space allocated to msg and destroy msg. */
383
 
 
384
 
static void
385
 
ipc_bufpool_msg_done(struct IPC_MESSAGE * msg) {
386
 
        
387
 
        struct ipc_bufpool* pool;
388
 
        
389
 
        if (msg == NULL){
390
 
                cl_log(LOG_ERR, "ipc_bufpool_msg_done:"
391
 
                       "invalid input");
392
 
                return;
393
 
        }
394
 
        
395
 
        pool = (struct ipc_bufpool*)msg->msg_private;
396
 
        
397
 
        ipc_bufpool_unref(pool);
398
 
        free(msg);
399
 
        
400
 
}
401
 
 
402
 
static struct IPC_MESSAGE*
403
 
ipc_bufpool_msg_new(void)
404
 
{
405
 
        struct IPC_MESSAGE * temp_msg;
406
 
        
407
 
        temp_msg = malloc(sizeof(struct IPC_MESSAGE));
408
 
        if (temp_msg == NULL){
409
 
                cl_log(LOG_ERR, "ipc_bufpool_msg_new:"
410
 
                       "allocating new msg failed");
411
 
                return NULL;
412
 
        }
413
 
        
414
 
        memset(temp_msg, 0, sizeof(struct IPC_MESSAGE));
415
 
 
416
 
        return temp_msg;
417
 
}
418
 
 
419
 
 
420
 
static void
421
 
ipcmsg_display(IPC_Message* ipcmsg)
422
 
{
423
 
        if (ipcmsg == NULL){
424
 
                cl_log(LOG_ERR, "ipcmsg is NULL");
425
 
                return;
426
 
        }
427
 
        
428
 
        cl_log(LOG_INFO, "ipcmsg: msg_len=%lu, msg_buf=%p, msg_body=%p,"
429
 
               "msg_done=%p, msg_private=%p, msg_ch=%p",
430
 
               (unsigned long)ipcmsg->msg_len,
431
 
               ipcmsg->msg_buf, 
432
 
               ipcmsg->msg_body,
433
 
               ipcmsg->msg_done,
434
 
               ipcmsg->msg_private,
435
 
               ipcmsg->msg_ch);
436
 
              
437
 
        return;
438
 
        
439
 
}
440
 
 
441
 
/* after a recv call, we have new data
442
 
 * in the pool buf, we need to update our
443
 
 * pool struct to consume it
444
 
 *
445
 
 */
446
 
 
447
 
int
448
 
ipc_bufpool_update(struct ipc_bufpool* pool,
449
 
                   struct IPC_CHANNEL * ch,
450
 
                   int msg_len,
451
 
                   IPC_Queue* rqueue)
452
 
{
453
 
        IPC_Message*                    ipcmsg;
454
 
        struct SOCKET_MSG_HEAD          localhead;
455
 
        struct SOCKET_MSG_HEAD*         head = &localhead;
456
 
        int                             nmsgs = 0 ;
457
 
        
458
 
 
459
 
        if (rqueue == NULL){
460
 
                cl_log(LOG_ERR, "ipc_update_bufpool:"
461
 
                       "invalid input");
462
 
                return 0;
463
 
        }
464
 
        
465
 
        pool->currpos += msg_len;
466
 
        
467
 
        while(TRUE){
468
 
                /*not enough data for head*/
469
 
                if ((int)(pool->currpos - pool->consumepos) < (int)ch->msgpad){
470
 
                        break;
471
 
                }
472
 
                
473
 
                memcpy(head, pool->consumepos, sizeof(struct SOCKET_MSG_HEAD));
474
 
                
475
 
                if (head->magic != HEADMAGIC){
476
 
                        GList* last = g_list_last(rqueue->queue);
477
 
                        cl_log(LOG_ERR, "ipc_bufpool_update: "
478
 
                               "magic number in head does not match."
479
 
                               "Something very bad happened, abort now, farside pid =%d",
480
 
                               ch->farside_pid);
481
 
                        cl_log(LOG_ERR, "magic=%x, expected value=%x", head->magic, HEADMAGIC);
482
 
                        ipc_bufpool_display(pool);
483
 
                        cl_log(LOG_INFO, "nmsgs=%d", nmsgs);
484
 
                        /*print out the last message in queue*/
485
 
                        if (last){
486
 
                                IPC_Message* m = (IPC_Message*)last;
487
 
                                ipcmsg_display(m);
488
 
                        }
489
 
                        abort();
490
 
                }
491
 
 
492
 
                if ( head->msg_len > MAXMSG){
493
 
                        cl_log(LOG_ERR, "ipc_update_bufpool:"
494
 
                               "msg length is corruptted(%d)",
495
 
                               head->msg_len);
496
 
                        break;
497
 
                }
498
 
                
499
 
                if (pool->consumepos + ch->msgpad + head->msg_len
500
 
                    > pool->currpos){
501
 
                        break;                  
502
 
                }
503
 
                
504
 
                ipcmsg = ipc_bufpool_msg_new();
505
 
                if (ipcmsg == NULL){
506
 
                        cl_log(LOG_ERR, "ipc_update_bufpool:"
507
 
                               "allocating memory for new ipcmsg failed");
508
 
                        break;
509
 
                        
510
 
                }
511
 
                ipcmsg->msg_buf = pool->consumepos;
512
 
                ipcmsg->msg_body = pool->consumepos + ch->msgpad;
513
 
                ipcmsg->msg_len = head->msg_len;
514
 
                ipcmsg->msg_private = pool;
515
 
                ipcmsg->msg_done = ipc_bufpool_msg_done;
516
 
                
517
 
#ifdef IPC_TIME_DEBUG                           
518
 
                ipc_time_debug(ch,ipcmsg, MSGPOS_RECV);
519
 
#endif                          
520
 
 
521
 
 
522
 
                rqueue->queue = g_list_append(rqueue->queue, ipcmsg);
523
 
                rqueue->current_qlen ++;
524
 
                nmsgs++;
525
 
                
526
 
                pool->consumepos += ch->msgpad + head->msg_len;
527
 
                ipc_bufpool_ref(pool);
528
 
        }
529
 
        
530
 
        return nmsgs;
531
 
}
532
 
 
533
 
 
534
 
 
535
 
 
536
 
 
537
 
 
538
 
gboolean
539
 
ipc_bufpool_full(struct ipc_bufpool* pool, 
540
 
                 struct IPC_CHANNEL* ch, 
541
 
                 int* dataspaceneeded)
542
 
{
543
 
        
544
 
        struct SOCKET_MSG_HEAD  localhead;
545
 
        struct SOCKET_MSG_HEAD* head = &localhead;
546
 
 
547
 
        *dataspaceneeded = 0;
548
 
        /* not enough space for head */
549
 
        if ((int)(pool->endpos - pool->consumepos) < (int)ch->msgpad){
550
 
                return TRUE;
551
 
        }
552
 
        
553
 
        /*enough space for head*/
554
 
        if ((int)(pool->currpos - pool->consumepos) >= (int)ch->msgpad){
555
 
                memcpy(head, pool->consumepos, sizeof(struct SOCKET_MSG_HEAD));
556
 
                
557
 
                /* not enough space for data*/
558
 
                if ( pool->consumepos + ch->msgpad + head->msg_len >= pool->endpos){
559
 
                        *dataspaceneeded = head->msg_len;
560
 
                        return TRUE;
561
 
                }
562
 
        }
563
 
        
564
 
        
565
 
        /* Either we are sure we have enough space 
566
 
         * or we cannot tell because we have not received
567
 
         * head yet. But we are sure we have enough space
568
 
         * for head
569
 
         */
570
 
        return FALSE;
571
 
 
572
 
 
573
 
        
574
 
}
575
 
 
576
 
 
577
 
int 
578
 
ipc_bufpool_partial_copy(struct ipc_bufpool* dstpool,
579
 
                              struct ipc_bufpool* srcpool)
580
 
{
581
 
        struct SOCKET_MSG_HEAD  localhead;
582
 
        struct SOCKET_MSG_HEAD *head = &localhead;
583
 
        int space_needed;
584
 
        int nbytes;
585
 
        
586
 
        if (dstpool == NULL
587
 
            || srcpool == NULL){
588
 
                cl_log(LOG_ERR, "ipc_bufpool_partial_ipcmsg_cp:"
589
 
                       "invalid input");                
590
 
                return IPC_FAIL;
591
 
        }
592
 
        
593
 
        if (srcpool->currpos - srcpool->consumepos >=
594
 
            (ssize_t)sizeof(struct SOCKET_MSG_HEAD)){
595
 
                
596
 
                memcpy(head, srcpool->consumepos, sizeof(struct SOCKET_MSG_HEAD));
597
 
                space_needed = head->msg_len + sizeof(*head);
598
 
                
599
 
                if (space_needed >  ipc_bufpool_spaceleft(dstpool)){
600
 
                        cl_log(LOG_ERR, "ipc_bufpool_partial_ipcmsg_cp:"
601
 
                               " not enough space left in dst pool,spaced needed=%d",
602
 
                               space_needed);
603
 
                        return IPC_FAIL;        
604
 
                }       
605
 
        }
606
 
        
607
 
        nbytes = srcpool->currpos - srcpool->consumepos;
608
 
        memcpy(dstpool->consumepos, srcpool->consumepos,nbytes);
609
 
        
610
 
        
611
 
        srcpool->currpos = srcpool->consumepos;
612
 
        dstpool->currpos = dstpool->consumepos + nbytes;
613
 
        
614
 
        return IPC_OK;
615
 
}
616
 
 
617
 
 
618
 
void
619
 
ipc_bufpool_ref(struct ipc_bufpool* pool)
620
 
{
621
 
        if (pool == NULL){
622
 
                cl_log(LOG_ERR, "ref_pool:"
623
 
                       " invalid input");
624
 
                return;         
625
 
        }
626
 
        
627
 
        pool->refcount ++;
628
 
        
629
 
}
630
 
 
631
 
void
632
 
ipc_bufpool_unref(struct ipc_bufpool* pool){
633
 
        
634
 
        if (pool == NULL){
635
 
                cl_log(LOG_ERR, "unref_pool:"
636
 
                       " invalid input");
637
 
                return;         
638
 
        }
639
 
        
640
 
        pool->refcount --;
641
 
 
642
 
        if (pool->refcount <= 0){
643
 
                ipc_bufpool_del(pool);
644
 
        }
645
 
        
646
 
        return;
647
 
}