Skip to content

Commit

Permalink
Add SO_GET_CLUSTER_OBJECT_INFO to read queue status
Browse files Browse the repository at this point in the history
  • Loading branch information
cardigliano committed Dec 19, 2024
1 parent e9252b6 commit ce0f113
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kernel/linux/pf_ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
#define SO_GET_DEV_TX_TIME 188
#define SO_GET_DEV_STATS 189
#define SO_SELECT_ZC_DEVICE 190
#define SO_GET_CLUSTER_OBJECT_INFO 191

/* Error codes */
#define PF_RING_ERROR_GENERIC -1
Expand Down Expand Up @@ -1085,7 +1086,7 @@ struct lock_cluster_object_info {
u_int32_t object_type;
u_int32_t object_id;
u_int32_t lock_mask;
u_int32_t reserved;
u_int32_t locked_mask; /* out */
} __attribute__((packed));

/* ************************************************* */
Expand Down
77 changes: 77 additions & 0 deletions kernel/pf_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -5123,6 +5123,8 @@ static int create_cluster_referee(struct pf_ring_socket *pfr, u_int32_t cluster_
return 0;
}

/* *********************************************** */

static void remove_cluster_referee(struct pf_ring_socket *pfr)
{
struct list_head *ptr, *tmp_ptr;
Expand Down Expand Up @@ -5168,6 +5170,8 @@ static void remove_cluster_referee(struct pf_ring_socket *pfr)
pfr->cluster_referee = NULL;
}

/* *********************************************** */

static int publish_cluster_object(struct pf_ring_socket *pfr, u_int32_t cluster_id,
u_int32_t object_type, u_int32_t object_id)
{
Expand Down Expand Up @@ -5224,6 +5228,60 @@ static int publish_cluster_object(struct pf_ring_socket *pfr, u_int32_t cluster_
return rc;
}

/* *********************************************** */

static int get_cluster_object_info(struct pf_ring_socket *pfr, u_int32_t cluster_id,
u_int32_t object_type, u_int32_t object_id, u_int32_t *locked_mask)
{
struct list_head *ptr, *tmp_ptr;
struct cluster_referee *entry, *cr = NULL;
struct list_head *obj_ptr, *obj_tmp_ptr;
cluster_object *obj_entry, *c_obj = NULL;
int rc = -1;

*locked_mask = 0;

mutex_lock(&cluster_referee_lock);

list_for_each_safe(ptr, tmp_ptr, &cluster_referee_list) {
entry = list_entry(ptr, struct cluster_referee, list);
if(entry->id == cluster_id) {
cr = entry;
break;
}
}

if(cr == NULL) {
debug_printk(2, "cluster %u not found\n", cluster_id);
goto unlock;
}

/* adding locked objects to the cluster */
list_for_each_safe(obj_ptr, obj_tmp_ptr, &cr->objects_list) {
obj_entry = list_entry(obj_ptr, cluster_object, list);

if(obj_entry->object_type == object_type && obj_entry->object_id == object_id) {
c_obj = obj_entry;
*locked_mask = c_obj->lock_bitmap;
break;
}
}

if(c_obj == NULL) {
debug_printk(2, "object %u.%u not in the public list of cluster %u\n", object_type, object_id, cluster_id);
goto unlock;
}

rc = 0;

unlock:
mutex_unlock(&cluster_referee_lock);

return rc;
}

/* *********************************************** */

static int lock_cluster_object(struct pf_ring_socket *pfr, u_int32_t cluster_id,
u_int32_t object_type, u_int32_t object_id, u_int32_t lock_mask)
{
Expand Down Expand Up @@ -8388,6 +8446,25 @@ static int ring_getsockopt(struct socket *sock,
}
break;

case SO_GET_CLUSTER_OBJECT_INFO:
{
struct lock_cluster_object_info lcoi;

if(len < sizeof(lcoi))
return(-EINVAL);

if(copy_from_user(&lcoi, optval, sizeof(lcoi)))
return(-EFAULT);

if(get_cluster_object_info(pfr, lcoi.cluster_id, lcoi.object_type, lcoi.object_id, &lcoi.locked_mask) < 0)
return(-EINVAL);

if(copy_to_user(optval, &lcoi, sizeof(lcoi))) {
return(-EFAULT);
}
}
break;

default:
return -ENOPROTOOPT;
}
Expand Down

0 comments on commit ce0f113

Please sign in to comment.