Ó²ÅÌÊý¾Ý»Ö¸´µ¼º½
RAIDÊý¾Ý»Ö¸´µ¼º½
 | ÍøÕ¾Ê×Ò³ | Êý¾Ý»Ö¸´×ÊÁÏ | Êý¾Ý»Ö¸´Èí¼þ | ×ÉѯÁôÑÔ | Êý¾Ý»Ö¸´²©¿Í | Êý¾Ý»Ö¸´ÂÛ̳ | 
Êý¾Ý»Ö¸´Èí¼þÏÂÔØ
¹«Ë¾¼ò½é Êý¾Ý»Ö¸´³É¹¦°¸Àý Êý¾Ý»Ö¸´±¨¼Û Êý¾Ý»Ö¸´Åàѵ Êý¾Ý»Ö¸´¼¼ÊõÎÄÕ Êý¾Ý»Ö¸´¿Í·þÖÐÐÄ Êý¾Ý»Ö¸´·þÎñÁªÏµ·½Ê½
ÄúÏÖÔÚµÄλÖ㺠±±ÑÇÊý¾Ý»Ö¸´¼¼ÊõÕ¾ >> Êý¾Ý»Ö¸´×ÊÁÏ >> UNIX¼°LINUXÎÄÀ¸ >> ÎÄÕÂÕýÎÄ
[ÍƼö]LinuxÊý¾Ý´«Êä¼¼ÊõRelayµÄÔ­Àí¼°ÊµÀý £¨2£©            ¡¾×ÖÌ壺С ´ó¡¿
LinuxÊý¾Ý´«Êä¼¼ÊõRelayµÄÔ­Àí¼°ÊµÀý £¨2£©
×÷ÕߣºÎ´Öª    ÎÄÕÂÀ´Ô´£ºÍøÂç    µã»÷Êý£º    ¸üÐÂʱ¼ä£º2009-3-25

ÃæÏòÄں˿ռäµÄ API

ÕâЩAPI½Ó¿ÚÏòλÓÚÄں˿ռäµÄÓû§ÌṩÁ˹ÜÀírelayͨµÀ¡¢Êý¾ÝдÈëµÈ¹¦ÄÜ¡£ÏÂÃæ½éÉÜÆäÖÐÖ÷ÒªµÄ²¿·Ö£¬

ÍêÕûµÄAPI½Ó¿ÚÁбíÇë²Î¼ûÕâÀï¡£

¡ñrelay_open() - ´´½¨Ò»¸örelayͨµÀ£¬°üÀ¨´´½¨Ã¿¸öCPU¶ÔÓ¦µÄrelay»º³åÇø¡£

¡ñrelay_close() - ¹Ø±ÕÒ»¸örelayͨµÀ£¬°üÀ¨ÊÍ·ÅËùÓеÄrelay»º³åÇø£¬ÔÚ´Ë֮ǰ»áµ÷ÓÃrelay_switch()

À´´¦ÀíÕâЩrelay»º³åÇøÒÔ±£Ö¤ÒѶÁÈ¡µ«ÊÇδÂúµÄÊý¾Ý²»»á¶ªÊ§

¡ñrelay_write() - ½«Êý¾ÝдÈëµ½µ±Ç°CPU¶ÔÓ¦µÄrelay»º³åÇøÄÚ¡£ÓÉÓÚËüʹÓÃÁËlocal_irqsave()±£»¤£¬

Òò´ËÒ²¿ÉÒÔÔÚÖжÏÉÏÏÂÎÄÖÐʹÓá£

¡ñrelay_reserve() - ÔÚrelayͨµÀÖб£ÁôÒ»¿éÁ¬ÐøµÄÇøÓòÀ´Áô¸øδÀ´µÄдÈë²Ù×÷¡£Õâͨ³£ÓÃÓÚÄÇЩϣÍû

Ö±½ÓдÈëµ½relay»º³åÇøµÄÓû§¡£¿¼Âǵ½ÐÔÄÜ»òÕßÆäËüÒòËØ£¬ÕâЩÓû§²»Ï£ÍûÏÈ°ÑÊý¾Ýдµ½Ò»¸öÁÙʱ»º³å

ÇøÖУ¬È»ºóÔÙͨ¹ýrelay_write()½øÐÐдÈë¡£

RelayµÄÀý×Ó

ÎÒÃÇÓÃÒ»¸ö×î¼òµ¥µÄÀý×ÓÀ´½éÉÜÔõôʹÓÃRelay¡£Õâ¸öÀý×ÓÓÉÁ½²¿·Ö×é³É£ºÒ»²¿·ÖÊÇλÓÚÄں˿ռ佫Êý¾Ý

дÈërelayÎļþµÄ³ÌÐò£¬Ê¹ÓÃʱÐèÒª×÷Ϊһ¸öÄÚºËÄ£¿é±»¼ÓÔØ£»ÁíÒ»²¿·ÖÊÇλÓÚÓû§¿Õ¼ä´ÓrelayÎļþÖжÁ

È¡Êý¾ÝµÄ³ÌÐò£¬Ê¹ÓÃʱ×÷ΪÆÕͨÓû§Ì¬³ÌÐòÔËÐС£

Äں˿ռäµÄ³ÌÐòÖ÷Òª²Ù×÷ÊÇ£º

¼ÓÔØÄ£¿éʱ£¬´ò¿ªÒ»¸örelayͨµÀ£¬²¢ÇÒÍù´ò¿ªµÄrelayͨµÀÖÐдÈëÏûÏ¢£»

жÔØÄ£¿éʱ£¬¹Ø±ÕrelayͨµÀ¡£

³ÌÐòÄÚÈÝ£º

 

 


/*
 * hello-mod.c
 * a kernel-space client example of relayfs filesystem
 */
#include
#include
static struct rchan *hello_rchan;
int init_module(void)
{
        const char *msg="Hello world\n";
        hello_rchan = relay_open("cpu", NULL, 8192, 2, NULL);
        if(!hello_rchan){
                printk("relay_open() failed.\n");
                return -ENOMEM;
        }
        relay_write(hello_rchan, msg, strlen(msg));
        return 0;
}
void cleanup_module(void)
{
        if(hello_rchan) {
                relay_close(hello_rchan);
                hello_rchan = NULL;
        }
        return;
}
MODULE_LICENSE ("GPL");
MODULE_DESCRIPTION ("Simple example of Relay");


 


Óû§¿Õ¼äµÄº¯ÊýÖ÷Òª²Ù×÷ÊÇ£º

¡ñÈç¹ûrelayfsÎļþϵͳ»¹Ã»Óб»mount£¬Ôò½«Æämountµ½Ä¿Â¼/mnt/relayÉÏ£»

¡ñ±éÀúÿһ¸öCPU¶ÔÓ¦µÄ»º³åÎļþ£»

¡ñ´ò¿ªÎļþ£»

¡ñ¶ÁÈ¡ËùÓÐÎļþÄÚÈÝ£»

¡ñ¹Ø±ÕÎļþ£»

¡ñ×îºó£¬umountµôrelayÎļþϵͳ¡£

³ÌÐòÄÚÈÝ£º

 

/*
 * audience.c
 * a user-space client example of relayfs filesystem
 */
#include
#include
#include
#include
#include
#include
#include
#define MAX_BUFLEN 256
const char filename_base[]="/mnt/relay/cpu";
// implement your own get_cputotal() before compilation
static int get_cputotal(void);
int main(void)
{
        char filename[128]={0};
        char buf[MAX_BUFLEN];
        int fd, c, i, bytesread, cputotal = 0;
        if(mount("relayfs", "/mnt/relay", "relayfs", 0, NULL)
                        && (errno != EBUSY)) {
                printf("mount() failed: %s\n", strerror(errno));
                return 1;
        }
        cputotal = get_cputotal();
        if(cputotal <= 0) {
                printf("invalid cputotal value: %d\n", cputotal);
                return 1;
        }
        for(i=0; i                // open per-cpu file
                sprintf(filename, "%s%d", filename_base, i);
                fd = open(filename, O_RDONLY);
                if (fd < 0) {
                        printf("fopen() failed: %s\n", strerror(errno));
                        return 1;
                }
                // read per-cpu file
                bytesread = read(fd, buf, MAX_BUFLEN);
                while(bytesread > 0) {
                        buf[bytesread] = '\0';
                        puts(buf);
                        bytesread = read(fd, buf, MAX_BUFLEN);
                };
                // close per-cpu file
                if(fd > 0) {
                        close(fd);
                        fd = 0;
                }
        }
        if(umount("/mnt/relay") && (errno != EINVAL)) {
                printf("umount() failed: %s\n", strerror(errno));
                return 1;
        }
        return 0;
}

 

ÉÏÃæÕâ¸öÀý×Ó¸ø³öÁËʹÓÃrelayµÄÒ»¸ö×î¼òµ¥µÄÇéÐΣ¬²¢Ã»ÓÐʵ¼ÊÓô¦£¬µ«ÊÇÐÎÏóÃèÊöÁË´ÓÓû§¿Õ¼äºÍÄÚ

ºË¿Õ¼äÁ½¸ö·½ÃæʹÓÃrelayµÄ»ù±¾Á÷³Ì¡£Êµ¼ÊÓ¦ÓÃÖжÔrelayµÄʹÓõ±È»Òª±ÈÕ⸴Ôӵöࡣ

ÎÄÕ¼È룺a    ÔðÈα༭£ºa 
  • ÉÏһƪÎÄÕ£º

  • ÏÂһƪÎÄÕ£º ûÓÐÁË
  • ¡¾·¢±íÆÀÂÛ¡¿¡¾¼ÓÈëÊղء¿¡¾¸æËߺÃÓÑ¡¿¡¾´òÓ¡´ËÎÄ¡¿¡¾¹Ø±Õ´°¿Ú¡¿
    ÍøÓÑÆÀÂÛ£º£¨Ö»ÏÔʾ×îÐÂ10Ìõ¡£ÆÀÂÛÄÚÈÝÖ»´ú±íÍøÓѹ۵㣬Óë±¾Õ¾Á¢³¡Î޹أ¡£©
    ¹ØÓÚÎÒÃÇ | RAIDÊý¾Ý»Ö¸´ | ÓÑÇéÁ´½Ó | RSSÉú³É | XMLÉú³É | ÎÄÕÂHTMLµØͼ | ÏÂÔØHTMLµØͼ

    °æȨËùÓÐ ±±ÑÇÊý¾Ý»Ö¸´ÖÐÐÄ
    È«¹úͳһ¿Í·þµç»°:4006-505-808
    ±±¾©Êк£µíÇøÓÀ·á»ùµØ·á»ÛÖз7ºÅвÄÁÏ´´Òµ´óÏÃB×ù205ÊÒ
    ¾©ICP±¸05011939
    <bt Ä