structuring of protocol

* isolated 'protocol.h' and transport.h from libglusterfs/* and
  glusterfsd/*

Signed-off-by: Amar Tumballi <amar@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>

BUG: 875 (Implement a new protocol to provide proper backward/forward compatibility)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=875
This commit is contained in:
Amar Tumballi 2010-05-04 00:35:59 +00:00 committed by Anand V. Avati
parent 72ca9bdf90
commit 7504b0e623
7 changed files with 101 additions and 108 deletions

View File

@ -30,7 +30,6 @@
#include "glusterfs.h"
#include "stack.h"
#include "dict.h"
#include "transport.h"
#include "event.h"
#include "defaults.h"

View File

@ -59,7 +59,6 @@
#include "compat.h"
#include "logging.h"
#include "dict.h"
#include "protocol.h"
#include "list.h"
#include "timer.h"
#include "glusterfsd.h"

View File

@ -29,25 +29,6 @@
#include <stdint.h>
#include "compat.h"
#include "xlator.h"
#include "byte-order.h"
#include "protocol.h"
struct gf_dirent_nb {
uint64_t d_ino;
uint64_t d_off;
uint32_t d_len;
uint32_t d_type;
struct gf_stat d_stat;
char d_name[0];
} __attribute__((packed));
int
gf_dirent_nb_size (gf_dirent_t *entries)
{
return (sizeof (struct gf_dirent_nb) + strlen (entries->d_name) + 1);
}
gf_dirent_t *
gf_dirent_for_namelen (int len)
@ -111,80 +92,3 @@ gf_dirent_free (gf_dirent_t *entries)
}
int
gf_dirent_serialize (gf_dirent_t *entries, char *buf, size_t buf_size)
{
struct gf_dirent_nb *entry_nb = NULL;
gf_dirent_t *entry = NULL;
int size = 0;
int entry_size = 0;
list_for_each_entry (entry, &entries->list, list) {
entry_size = gf_dirent_nb_size (entry);
if (buf && (size + entry_size <= buf_size)) {
entry_nb = (void *) (buf + size);
entry_nb->d_ino = hton64 (entry->d_ino);
entry_nb->d_off = hton64 (entry->d_off);
entry_nb->d_len = hton32 (entry->d_len);
entry_nb->d_type = hton32 (entry->d_type);
gf_stat_from_iatt (&entry_nb->d_stat, &entry->d_stat);
strcpy (entry_nb->d_name, entry->d_name);
}
size += entry_size;
}
return size;
}
int
gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t buf_size)
{
struct gf_dirent_nb *entry_nb = NULL;
int remaining_size = 0;
int least_dirent_size = 0;
int count = 0;
gf_dirent_t *entry = NULL;
int entry_strlen = 0;
int entry_len = 0;
remaining_size = buf_size;
least_dirent_size = (sizeof (struct gf_dirent_nb) + 2);
while (remaining_size >= least_dirent_size) {
entry_nb = (void *)(buf + (buf_size - remaining_size));
entry_strlen = strnlen (entry_nb->d_name, remaining_size);
if (entry_strlen == remaining_size) {
break;
}
entry_len = sizeof (gf_dirent_t) + entry_strlen + 1;
entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t);
if (!entry) {
break;
}
entry->d_ino = ntoh64 (entry_nb->d_ino);
entry->d_off = ntoh64 (entry_nb->d_off);
entry->d_len = ntoh32 (entry_nb->d_len);
entry->d_type = ntoh32 (entry_nb->d_type);
gf_stat_to_iatt (&entry_nb->d_stat, &entry->d_stat);
strcpy (entry->d_name, entry_nb->d_name);
list_add_tail (&entry->list, &entries->list);
remaining_size -= (sizeof (*entry_nb) + entry_strlen + 1);
count++;
}
return count;
}

View File

@ -57,8 +57,6 @@ struct _gf_dirent_t {
gf_dirent_t *gf_dirent_for_name (const char *name);
void gf_dirent_free (gf_dirent_t *entries);
int gf_dirent_serialize (gf_dirent_t *entries, char *buf, size_t size);
int gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t size);
gf_dirent_t * gf_dirent_for_namelen (int len);
#endif /* _GF_DIRENT_H */

View File

@ -20,6 +20,12 @@
#ifndef _GLOBALS_H
#define _GLOBALS_H
/* This corresponds to the max 16 number of group IDs that are sent through an
* RPC request. Since NFS is the only one going to set this, we can be safe
* in keeping this size hardcoded.
*/
#define GF_REQUEST_MAXGROUPS 16
#include "glusterfs.h"
#include "xlator.h"

View File

@ -952,12 +952,6 @@ typedef struct {
typedef struct { } __attribute__((packed)) gf_cbk_forget_rsp_t;
/* This corresponds to the max 16 number of group IDs that are sent through an
* RPC request. Since NFS is the only one going to set this, we can be safe
* in keeping this size hardcoded.
*/
#define GF_REQUEST_MAXGROUPS 16
typedef struct {
uint32_t pid;
uint32_t uid;
@ -1022,4 +1016,99 @@ gf_param (gf_hdr_common_t *hdr)
return ((void *)hdr) + sizeof (*hdr);
}
struct gf_dirent_nb {
uint64_t d_ino;
uint64_t d_off;
uint32_t d_len;
uint32_t d_type;
struct gf_stat d_stat;
char d_name[0];
} __attribute__((packed));
static inline int
gf_dirent_nb_size (gf_dirent_t *entries)
{
return (sizeof (struct gf_dirent_nb) + strlen (entries->d_name) + 1);
}
static inline int
gf_dirent_serialize (gf_dirent_t *entries, char *buf, size_t buf_size)
{
struct gf_dirent_nb *entry_nb = NULL;
gf_dirent_t *entry = NULL;
int size = 0;
int entry_size = 0;
list_for_each_entry (entry, &entries->list, list) {
entry_size = gf_dirent_nb_size (entry);
if (buf && (size + entry_size <= buf_size)) {
entry_nb = (void *) (buf + size);
entry_nb->d_ino = hton64 (entry->d_ino);
entry_nb->d_off = hton64 (entry->d_off);
entry_nb->d_len = hton32 (entry->d_len);
entry_nb->d_type = hton32 (entry->d_type);
gf_stat_from_iatt (&entry_nb->d_stat, &entry->d_stat);
strcpy (entry_nb->d_name, entry->d_name);
}
size += entry_size;
}
return size;
}
static inline int
gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t buf_size)
{
struct gf_dirent_nb *entry_nb = NULL;
int remaining_size = 0;
int least_dirent_size = 0;
int count = 0;
gf_dirent_t *entry = NULL;
int entry_strlen = 0;
int entry_len = 0;
remaining_size = buf_size;
least_dirent_size = (sizeof (struct gf_dirent_nb) + 2);
while (remaining_size >= least_dirent_size) {
entry_nb = (void *)(buf + (buf_size - remaining_size));
entry_strlen = strnlen (entry_nb->d_name, remaining_size);
if (entry_strlen == remaining_size) {
break;
}
entry_len = sizeof (gf_dirent_t) + entry_strlen + 1;
entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t);
if (!entry) {
break;
}
entry->d_ino = ntoh64 (entry_nb->d_ino);
entry->d_off = ntoh64 (entry_nb->d_off);
entry->d_len = ntoh32 (entry_nb->d_len);
entry->d_type = ntoh32 (entry_nb->d_type);
gf_stat_to_iatt (&entry_nb->d_stat, &entry->d_stat);
strcpy (entry->d_name, entry_nb->d_name);
list_add_tail (&entry->list, &entries->list);
remaining_size -= (sizeof (*entry_nb) + entry_strlen + 1);
count++;
}
return count;
}
#endif

View File

@ -44,8 +44,6 @@ typedef struct _call_pool_t call_pool_t;
#include "list.h"
#include "common-utils.h"
#include "globals.h"
#include "protocol.h"
typedef int32_t (*ret_fn_t) (call_frame_t *frame,
call_frame_t *prev_frame,