next up previous
Next: Get Up: Classes Previous: Classes


The graft function on a class is used to attach a new queuing discipline to a class. As mentioned in the previous section, the default queuing discipline attached to a class when it is created, is a FIFO queue. To change this queuing discipline, a graft operation is performed on the class. As an example, let us take a look at the cbq_graft function in net/sched/sch_cbq.c.

static int cbq_graft(struct Qdisc *sch, unsigned long arg, 
struct Qdisc *new, struct Qdisc **old)
 struct cbq_class *cl = (struct cbq_class*)arg;

 if (cl) {
  if (new == NULL) {
   if ((new = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops))==NULL)
      return -ENOBUFS;
   new->classid = cl->classid;
  if ((*old = xchg(&cl->q, new)) != NULL)
  return 0;
 return -ENOENT;

As shown above, the cbq_graft function is called with the new queuing discipline. By default, if no queuing discipline is specified, a FIFO queuing discipline is attached to the class. If the new queuing discipline is specified, then the class is attached to it. That is, when a packet to be enqueued is classified to this class, the enqueue function of the queuing discipline attached to this class is called. The old queuing discipline that was attached to the class is returned in the "old" variable.

The qdisc_graft function in net/sched/sch_api.c is another example for the graft function. This function is called from the tc_ctl_qdisc function in the same file. The tc_ctl_qdisc function is invoked whenever an attempt is made to create, delete, change or get a queuing discipline.

next up previous
Next: Get Up: Classes Previous: Classes
Saravanan Radhakrishnan